Main Page | Class List | File List | Class Members | File Members

readconfig.c

Go to the documentation of this file.
00001 /*
00002  *  $Id: readconfig.c,v 1.17 2006/04/17 22:45:19 ghost666 Exp $
00003  *
00004  *  rssbgr - RSS backgroud reader
00005  *  Copyright (C) 2005, 2006 Piotr 'GhosT' Wydrych
00006  *
00007  *  This program is free software; you can redistribute it and/or modify
00008  *  it under the terms of the GNU General Public License as published by
00009  *  the Free Software Foundation; either version 2 of the License, or
00010  *  (at your option) any later version.
00011  *
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 }

Generated on Fri May 26 08:40:18 2006 for RSSbgr by doxygen 1.3.6