|
1 /* vim: set noet nosta sw=4 ts=4 ft=c : */ |
|
2 /* Squid docs: |
|
3 --------------------------------------------------------------------------- |
|
4 TAG: url_rewrite_program |
|
5 Specify the location of the executable for the URL rewriter. |
|
6 Since they can perform almost any function there isn't one included. |
|
7 |
|
8 For each requested URL rewriter will receive on line with the format |
|
9 |
|
10 URL <SP> client_ip "/" fqdn <SP> user <SP> method [<SP> kvpairs]<NL> |
|
11 |
|
12 In the future, the rewriter interface will be extended with |
|
13 key=value pairs ("kvpairs" shown above). Rewriter programs |
|
14 should be prepared to receive and possibly ignore additional |
|
15 whitespace-separated tokens on each input line. |
|
16 |
|
17 And the rewriter may return a rewritten URL. The other components of |
|
18 the request line does not need to be returned (ignored if they are). |
|
19 |
|
20 The rewriter can also indicate that a client-side redirect should |
|
21 be performed to the new URL. This is done by prefixing the returned |
|
22 URL with "301:" (moved permanently) or 302: (moved temporarily). |
|
23 |
|
24 By default, a URL rewriter is not used. |
|
25 --------------------------------------------------------------------------- */ |
|
26 |
|
27 /* |
|
28 * TODO |
|
29 * |
|
30 * flush stdout on writes |
|
31 * empty struct not necessary? |
|
32 * inet_pton( AF_INET, *char src, dest ) |
|
33 * |
|
34 */ |
|
35 |
|
36 #include "volta.h" |
|
37 |
|
38 int |
|
39 main( int argc, char *argv[] ) { |
|
40 |
|
41 int opt; |
|
42 |
|
43 /* storage for line received from squid */ |
|
44 char line[ LINE_BUFSIZE ]; |
|
45 |
|
46 while ( (opt = getopt( argc, argv, "a:hv" )) != -1 ) { |
|
47 switch ( opt ) { |
|
48 case 'a': |
|
49 printf( "a -> '%s' (no-op at the moment)\n", optarg ); |
|
50 break; |
|
51 case 'h': |
|
52 usage( argv[0] ); |
|
53 return( 0 ); |
|
54 case 'v': |
|
55 printf( "%s version %s\n", PROG, VERSION ); |
|
56 return( 0 ); |
|
57 case '?': |
|
58 default: |
|
59 break; |
|
60 } |
|
61 } |
|
62 argc -= optind; |
|
63 argv += optind; |
|
64 |
|
65 /* start stdin line loop */ |
|
66 while( fgets( line, LINE_BUFSIZE, stdin ) != NULL ) parse( line ); |
|
67 |
|
68 /* stdin closed */ |
|
69 debug( "End of stream, shutting down.\n" ); |
|
70 return( 0 ); |
|
71 } |
|
72 |
|
73 /* |
|
74 * Basic usage |
|
75 */ |
|
76 void |
|
77 usage( char *prg ) |
|
78 { |
|
79 printf( "%s [-vh] [-a <init>]\n", prg ); |
|
80 printf( " -v Display version\n" ); |
|
81 printf( " -h Usage (you're lookin' at it)\n" ); |
|
82 printf( " -a Perform an action:\n" ); |
|
83 printf( " init: Initialize a new database\n" ); |
|
84 printf( "\n" ); |
|
85 return; |
|
86 } |
|
87 |
|
88 |
|
89 /* |
|
90 * Debug function, only output to stderr if -DDEBUG set |
|
91 */ |
|
92 void |
|
93 debug( const char *fmt, ... ) |
|
94 { |
|
95 va_list args; |
|
96 va_start( args, fmt ); |
|
97 #ifdef DEBUG |
|
98 fprintf( stderr, "%s %d: ", PROG, getpid() ); |
|
99 vfprintf( stderr, fmt, args ); |
|
100 #endif |
|
101 va_end( args ); |
|
102 } |
|
103 |