2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 2000-2003 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
16 * This work was initially developed by Pierangelo Masarati for
17 * inclusion in OpenLDAP Software.
22 #include <ac/stdlib.h>
23 #include <ac/string.h>
24 #include <ac/syslog.h>
26 #include <ac/socket.h>
27 #include <ac/unistd.h>
29 #include <ac/string.h>
36 int ldap_syslog_level;
41 const char *rewriteContext,
45 struct rewrite_info *info;
46 char *string, *sep, *result = NULL;
50 info = rewrite_info_init( REWRITE_MODE_ERR );
52 if ( rewrite_read( fin, info ) != 0 ) {
56 rewrite_param_set( info, "prog", "rewrite" );
58 rewrite_session_init( info, cookie );
60 string = strdup( arg );
61 for ( sep = strchr( rewriteContext, ',' );
62 rewriteContext != NULL;
64 sep ? sep = strchr( rewriteContext, ',' ) : NULL ) {
69 /* rc = rewrite( info, rewriteContext, string, &result ); */
70 rc = rewrite_session( info, rewriteContext, string,
73 fprintf( stdout, "%s -> %s\n", string,
74 ( result ? result : "unwilling to perform" ) );
75 if ( result == NULL ) {
84 rewrite_session_delete( info, cookie );
86 rewrite_info_delete( &info );
92 main( int argc, char *argv[] )
95 char *rewriteContext = REWRITE_DEFAULT_CONTEXT;
98 int opt = getopt( argc, argv, "f:hr:" );
106 fin = fopen( optarg, "r" );
108 fprintf( stderr, "unable to open file '%s'\n",
110 exit( EXIT_FAILURE );
116 "usage: rewrite [options] string\n"
118 "\t\t-f file\t\tconfiguration file\n"
119 "\t\t-r rule[s]\tlist of comma-separated rules\n"
122 "\t\trewriteEngine\t{on|off}\n"
123 "\t\trewriteContext\tcontextName [alias aliasedContextName]\n"
124 "\t\trewriteRule\tpattern subst [flags]\n"
127 exit( EXIT_SUCCESS );
130 rewriteContext = optarg;
135 if ( optind >= argc ) {
139 apply( ( fin ? fin : stdin ), rewriteContext, argv[ optind ] );