#include <stdio.h>
#include <pcre.h>
#define DEFAULT_CONFIG "/usr/local/rejik3/redirector.conf"
/*** Print debug info for develop ***/
//#define DEBUG_CFG
//#define DEBUG_CYCLE
//#define DEBUG_MAKE_CACHE
//#define DEBUG_URLS_LOAD
//#define DEBUG_PCRE
//#define DEBUG_PARSE_URL
//#define DEBUG_PRUNE_URLS
//#define DEBUG_CACHE2URL
//#define DEBUG_WRITE_CACHE
//#define DEBUG_LOAD_CACHE
//#define DEBUG_PARSE_UNPUT
//#define DEBUG_CHECK_URLS
//#define DEBUG_URLS_CMP
//#define DEBUG_RUN_MAKE_CACHE
//#define DEBUG_IP
//#define DEBUG_ID
//#define DEBUG_NEW_URL
//#define DEBUG_RAW_CHANGE
//#define DEBUG_PASS
// Uncoment next line for case independent
define CASE_INDEPENDENT - вот здесь раскоментировал
// MAX LENS OF SOME VARS
#define ML_CFG 200
#define ML_FILE_NAME 200
#define ML_ETMP 5512
#define ML_PCRE_VARS 512
#define ML_URL 4095
#define ML_HOST 100
#define ML_IDENT 100
#define ML_METHOD 10
#define ML_PROTOKOL 20
#define ML_DIRS 1024
#define ML_PORT 10
#define ML_2LD 200
#define ML_SUBDOMEN 200
FILE *change_log;
unsigned char *input_ident;
unsigned char *input_ident_un;
unsigned char *input_ip;
unsigned char *input_url;
unsigned char *input_url_un;
#ifdef CASE_INDEPENDENT
unsigned char *input_url_uc;
#endif
unsigned char *input_method;
unsigned char *input_host;
//unsigned int input_separator;
struct p_url *i_url;
unsigned char *change_reason;
/*****************************************************************
*
http://sub.sub.sub.domen2levelname.ru:4 ... r/dir/file *
* | | | | | | *
* protocol | subdomen | twoleveldomen |port| dirs *
*****************************************************************/
struct p_url
{
unsigned char protocol[ML_PROTOKOL];
unsigned char twoleveldomen[ML_2LD];
unsigned char port[ML_PORT];
unsigned char subdomen[ML_SUBDOMEN];
unsigned char dirs[ML_DIRS];
};
//GLOBAL OPTIONS
unsigned char *err_log; // Error log path
unsigned char *chg_log; // Change log path
unsigned char *makecache; // make-cache program
unsigned char *work_ip; //Work ip
unsigned int work_ip_count; //Work ip count
unsigned int work_ip_flag; //Work ip flag
unsigned char *allow_ip; //Allow ip
unsigned int allow_ip_count; //Allow ip count
unsigned char **work_id; //Work id
unsigned int work_id_count; //Work id count
unsigned int work_id_flag; //Work id flag
unsigned char **allow_id; //Allow id
unsigned int allow_id_count; //Allow id count
unsigned char *allow_urls_file; //Allow urls file name
unsigned char **allow_urls; //Allow urls
unsigned int allow_urls_count; //Allow urls count
unsigned char **change_from; //
unsigned char **change_to; // Change data
unsigned int change_count; //
int raw_change_log_flag; //
unsigned int sections_count; //Count of sections in config
//SECTIONS OPTIONS
unsigned int sections_count; //Count of sections in config
struct section
{
unsigned char *name; //Header name
char *ban_dir; //Ban lists dir
char *url; //Url to change
char revers; // revers flag
char **new_url; // Block of urls
char *new_url_inset; // to change with
int new_url_count; // change #*# elements
char log_flag; //Write to log or not
unsigned char *work_ip; //Work ip
unsigned int work_ip_count; //Work ip count
unsigned int work_ip_flag; //Work ip flag
unsigned char *allow_ip; //Allow ip
unsigned int allow_ip_count; //Allow ip count
unsigned char **work_id; //Work id
unsigned int work_id_count; //Work id count
unsigned int work_id_flag; //Work id flag
unsigned char **allow_id; //Allow id
unsigned int allow_id_count; //Allow id count
pcre **ban_pcre; //Ban PCRE patterns
pcre_extra **ban_pcre_s; //Ban PCRE optimization
unsigned int ban_pcre_count; //Ban PCRE patterns count
unsigned char **ban_urls; //Ban urls lists area
unsigned int ban_urls_count; //Counter urls elements
} **redir;
char *now (void);
void err_mes(char*);
void get_opt(char*);
int load_urls(int,char *);
int parse_urls(struct p_url *,char *);
int prune_urls(int);
int cmp_urls(const void *, const void *);
int cache2url(struct p_url *,char *);
int need_cache_update(char*,char*);
int write_cache(int,char*,char*);
int load_cache(unsigned char ***,unsigned int*,unsigned char *);
int load_pcre_file(int);
int check_pcre(int);
int parse_input(unsigned char *);
void init_vars(void);
int check_url(unsigned char**,int count);
int cmp_urls_bs(const void *, const void *);
int cmp_urls_sub(const void *, const void *);
int cmp_urls_dirs(const void *, const void *);
int cmp_urls_port(const void *, const void *);
int run_make_cache(char*);
int add_ip(char *,unsigned char **,unsigned int* );
int check_ip(unsigned char *,unsigned int );
int add_id(char *,unsigned char ***,unsigned int* );
int sort_id(unsigned char ***,unsigned int* );
int check_id(unsigned char **,unsigned int);
int prepare_new_url(int);
int add_new_url (int, char *, int);
int redirect(int);
int raw_change(void);
int pass(void);