process.c
changeset 18 d4ce82194b64
parent 16 e6a640ad2cc2
child 22 822094314703
equal deleted inserted replaced
17:bd746609ba46 18:d4ce82194b64
    45 	/* count lines in debugmode */
    45 	/* count lines in debugmode */
    46 	if ( v.debugmode > 2 ) v.timer.lines++;
    46 	if ( v.debugmode > 2 ) v.timer.lines++;
    47 
    47 
    48 	/* If request parsing failed, return a blank line to squid
    48 	/* If request parsing failed, return a blank line to squid
    49 	   to allow the request to pass through unmolested. */
    49 	   to allow the request to pass through unmolested. */
    50 	if ( p_request == NULL ) {
    50 	if ( p_request == NULL )
    51 		out( "\n" );
    51 		return pass( p_request, rule );
    52 		finish_parsed( p_request );
       
    53 		return;
       
    54 	}
       
    55 
    52 
    56 	/*
    53 	/*
    57 	 * Main rewrite logic.
    54 	 * Main rewrite logic.
    58 	 *
    55 	 *
    59 	 * First, try and match the host exactly.
    56 	 * First, try and match the host exactly.
    76 	 */
    73 	 */
    77 	rule = find_rule( p_request->host, p_request );
    74 	rule = find_rule( p_request->host, p_request );
    78 	if ( rule == NULL ) rule = find_rule( p_request->tld, p_request );
    75 	if ( rule == NULL ) rule = find_rule( p_request->tld, p_request );
    79 	if ( rule == NULL ) rule = find_rule( "*", p_request );
    76 	if ( rule == NULL ) rule = find_rule( "*", p_request );
    80 
    77 
    81 	/* no matching rule still or whitelist rule?  no need to rewrite anything. */
    78 	/* no matching rule still or negated rule?  no need to rewrite anything. */
    82 	if ( rule == NULL || rule->wl ) {
    79 	if ( rule == NULL || rule->negate )
    83 		out( "\n" );
    80 		return pass( p_request, rule );
       
    81 
       
    82 	/* avoid trivial redirect loops */
       
    83 	if (
       
    84 		( rule->redir ) &&
       
    85 		( rule->scheme == NULL || ( strcmp(p_request->scheme, rule->scheme) == 0) ) &&
       
    86 		( rule->path   == NULL || ( strcmp(p_request->path,     rule->path) == 0) ) &&
       
    87 		( strcmp( p_request->host, rule->host) == 0 )
       
    88 	   ) {
       
    89 		debug( 2, LOC, "Potential rewrite loop, skipping rewrite.\n" );
       
    90 		return pass( p_request, rule );
    84 	}
    91 	}
       
    92 
    85 	/* otherwise, perform the rewrite. */
    93 	/* otherwise, perform the rewrite. */
    86 	else {
    94 	rewrite( p_request, rule );
    87 		rewrite( p_request, rule );
       
    88 	}
       
    89 
    95 
    90 	finish_parsed( rule );
    96 	finish_parsed( rule );
    91 	finish_parsed( p_request );
    97 	finish_parsed( p_request );
       
    98 	return;
       
    99 }
       
   100 
       
   101 
       
   102 /*
       
   103  * Allow the request to pass through without being rewritten.
       
   104  *
       
   105  */
       
   106 void
       
   107 pass( parsed *request, parsed *rule )
       
   108 {
       
   109 	finish_parsed( rule );
       
   110 	finish_parsed( request );
       
   111 
       
   112 	if ( v.debugmode >= 5 ) return;
       
   113 
       
   114 	printf( "\n" );
       
   115 	fflush( stdout );
       
   116 
    92 	return;
   117 	return;
    93 }
   118 }
    94 
   119 
    95 
   120 
    96 /*
   121 /*
   107 	if ( rule->port ) printf( ":%s", rule->port );
   132 	if ( rule->port ) printf( ":%s", rule->port );
   108 	printf( "%s", rule->path ? rule->path : request->path );
   133 	printf( "%s", rule->path ? rule->path : request->path );
   109 
   134 
   110 	printf("\n");
   135 	printf("\n");
   111 	fflush( stdout );
   136 	fflush( stdout );
       
   137 
   112 	return;
   138 	return;
   113 }
   139 }
   114 
   140 
   115 
   141 
   116 /*
   142 /*