00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "readconfig.h"
00023
00024 void readconfig(void)
00025 {
00026 FILE *fd;
00027 config_items_count = 0;
00028 config = (struct config_item *)malloc(config_items_count*sizeof(struct config_item));
00029 char *line, *url, *a, *action;
00030 long int frequency;
00031
00032 line = (char *)malloc(BUFSIZ);
00033 url = (char *)malloc(BUFSIZ);
00034 action = (char *)malloc(BUFSIZ);
00035 fd = fopen(configfile, "r");
00036 if (fd == NULL)
00037 return;
00038 while(!feof(fd))
00039 {
00040 if (fgets(line, BUFSIZ, fd))
00041 {
00042 if (sscanf(line, CONFIGFILE_FORMAT "\n", CONFIGFILE_VARS_SCAN) != 3) continue;
00043 a = strchr(strchr(line, '\t')+1, '\t')+1;
00044 strlcpy(action, a, strchr(a, '\n')-a+1);
00045 ++config_items_count;
00046 config = (struct config_item *)realloc(config, config_items_count*sizeof(struct config_item));
00047 config[config_items_count-1].url = (char *)malloc(strlen(url)+1);
00048 strcpy(config[config_items_count-1].url, url);
00049 frequency = (frequency < 0)?(-frequency):(frequency);
00050 frequency = ((frequency < MIN_FREQUENCY)?(MIN_FREQUENCY):(frequency));
00051 config[config_items_count-1].freq = frequency;
00052 if (parse_url(url, &(config[config_items_count-1].host), &(config[config_items_count-1].port), &(config[config_items_count-1].request)) == -1)
00053 {
00054 free(config[config_items_count-1].host); free(config[config_items_count-1].request);
00055 --config_items_count;
00056 config = (struct config_item *)realloc(config, config_items_count*sizeof(struct config_item));
00057 continue;
00058 }
00059 config[config_items_count-1].action = (char *)malloc(strlen(action)+1);
00060 strcpy(config[config_items_count-1].action, action);
00061 config[config_items_count-1].cookies_count = 0;
00062 config[config_items_count-1].cookies = NULL;
00063 }
00064 }
00065 fclose(fd);
00066 free(line); free(url); free(action);
00067 }