#include <stdio.h>
#include <string.h>
#include "vars.h"

int redirect(int section)
{
 int j;

 // Action
 if(redir[section]->action==1)
  {
   pass();
  }
 else
 {
   // print new_url
   for(j=0;j<redir[section]->new_url_count;j++)
      {
       printf("%s",redir[section]->new_url[j]);
       switch(redir[section]->new_url_inset[j])
       {
        case 1: printf("%s",input_url); break;
	case 2: printf("%d.%d.%d.%d",(unsigned char)input_ip[0],(unsigned char)input_ip[1],(unsigned char)input_ip[2],(unsigned char)input_ip[3]); break;
        case 3: printf("%s",input_ident); break;
	case 4: printf("%s",input_method); break;
	case 5: printf("%s",redir[section]->name); break;
       }
      }
   // print right part
   printf(" %u.%u.%u.%u/%s %s %s\n",(unsigned char)input_ip[0],(unsigned char)input_ip[1],(unsigned char)input_ip[2],(unsigned char)input_ip[3],input_host,input_ident,input_method);
   fflush(stdout);
 }


 if (!redir[section]->log_flag)
  {
    fprintf(change_log,"%s %s: %d.%d.%d.%d %s %s %s %s\n", now(),redir[section]->name,(unsigned char)input_ip[0],(unsigned char)input_ip[1],(unsigned char)input_ip[2],(unsigned char)input_ip[3],(write_hostname_to_log?input_host:""),input_ident_un,input_url,change_reason);
    fflush (change_log);
  }

 return (0);
}
