1 /******************************************************************************
3 * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
6 * Permission is granted to anyone to use this software for any purpose
7 * on any computer system, and to alter it and redistribute it, subject
8 * to the following restrictions:
10 * 1. The author is not responsible for the consequences of use of this
11 * software, no matter how awful, even if they arise from flaws in it.
13 * 2. The origin of this software must not be misrepresented, either by
14 * explicit claim or by omission. Since few users ever read sources,
15 * credits should appear in the documentation.
17 * 3. Altered versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software. Since few users
19 * ever read sources, credits should appear in the documentation.
21 * 4. This notice may not be removed or altered.
23 ******************************************************************************/
27 #include <ac/stdlib.h>
28 #include <ac/string.h>
29 #include <ac/syslog.h>
31 #include <ac/socket.h>
32 #include <ac/unistd.h>
34 #include <ac/string.h>
41 int ldap_syslog_level;
46 const char *rewriteContext,
50 struct rewrite_info *info;
51 char *string, *sep, *result = NULL;
55 info = rewrite_info_init(REWRITE_MODE_ERR);
57 if ( rewrite_read( fin, info ) != 0 ) {
61 rewrite_param_set( info, "prog", "rewrite" );
63 rewrite_session_init( info, cookie );
65 string = strdup( arg );
66 for ( sep = strchr( rewriteContext, ',' );
67 rewriteContext != NULL;
69 sep ? sep = strchr( rewriteContext, ',' ) : NULL ) {
74 /* rc = rewrite( info, rewriteContext, string, &result ); */
75 rc = rewrite_session( info, rewriteContext, string,
78 fprintf( stdout, "%s -> %s\n", string,
79 ( result ? result : "unwilling to perform" ) );
80 if ( result == NULL ) {
87 rewrite_session_delete( info, cookie );
93 main( int argc, char *argv[] )
96 char *rewriteContext = REWRITE_DEFAULT_CONTEXT;
99 int opt = getopt( argc, argv, "f:hr:" );
107 fin = fopen( optarg, "r" );
109 fprintf( stderr, "unable to open file '%s'\n",
111 exit( EXIT_FAILURE );
117 "usage: rewrite [options] string\n"
119 "\t\t-f file\t\tconfiguration file\n"
120 "\t\t-r rule[s]\tlist of comma-separated rules\n"
123 "\t\trewriteEngine\t{on|off}\n"
124 "\t\trewriteContext\tcontextName [alias aliasedContextName]\n"
125 "\t\trewriteRule\tpattern subst [flags]\n"
128 exit( EXIT_SUCCESS );
131 rewriteContext = strdup( optarg );
136 if ( optind >= argc ) {
140 apply( ( fin ? fin : stdin ), rewriteContext, argv[ optind ] );