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>
40 int ldap_syslog_level;
45 struct rewrite_info *info
51 const char *rewriteContext,
55 struct rewrite_info *info;
56 char *string, *sep, *result = NULL;
60 info = rewrite_info_init(REWRITE_MODE_ERR);
62 if ( read_rewrite( fin, info ) != 0 ) {
66 rewrite_param_set( info, "prog", "rewrite" );
68 rewrite_session_init( info, cookie );
70 string = strdup( arg );
71 for ( sep = strchr( rewriteContext, ',' );
72 rewriteContext != NULL;
74 sep ? sep = strchr( rewriteContext, ',' ) : NULL ) {
79 /* rc = rewrite( info, rewriteContext, string, &result ); */
80 rc = rewrite_session( info, rewriteContext, string,
83 fprintf( stdout, "%s -> %s\n", string,
84 ( result ? result : "unwilling to perform" ) );
85 if ( result == NULL ) {
92 rewrite_session_delete( info, cookie );
98 main( int argc, char *argv[] )
101 char *rewriteContext = REWRITE_DEFAULT_CONTEXT;
104 int opt = getopt( argc, argv, "f:hr:" );
112 fin = fopen( optarg, "r" );
114 fprintf( stderr, "unable to open file '%s'\n",
116 exit( EXIT_FAILURE );
122 "usage: rewrite [options] string\n"
124 "\t\t-f file\t\tconfiguration file\n"
125 "\t\t-r rule[s]\tlist of comma-separated rules\n"
128 "\t\trewriteEngine\t{on|off}\n"
129 "\t\trewriteContext\tcontextName [alias aliasedContextName]\n"
130 "\t\trewriteRule\tpattern subst [flags]\n"
133 exit( EXIT_SUCCESS );
136 rewriteContext = strdup( optarg );
141 if ( optind >= argc ) {
145 apply( ( fin ? fin : stdin ), rewriteContext, argv[ optind ] );