"Fossies" - the Fresh Open Source Software Archive

Member "authforce-0.9.9/src/config.c" (13 May 2007, 3564 Bytes) of package /linux/www/old/authforce-0.9.9.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "config.c" see the Fossies "Dox" file reference documentation.

    1 /* $Id: config.c,v 1.3 2001/04/28 20:32:47 kapheine Exp $ */
    2 
    3 #include <config.h>
    4 #include <stdio.h>
    5 #include <stdlib.h>
    6 #include <string.h>
    7 #include <ctype.h>
    8 #include <readline/tilde.h>
    9 #ifdef MEMWATCH
   10 #include "memwatch.h"
   11 #endif /* MEMWATCH */
   12 #include "extern.h"
   13 
   14 #define BUFFER_LEN 82
   15 #define IS_BIT(x) (!strcmp(x, "0") || !strcmp(x, "1"))
   16 
   17 static void process_boolean(char *option, char *value, int *variable) {
   18 
   19     if (!IS_BIT(value)) {
   20         if (!quiet)
   21             printf("process_boolean: %s value %s is not valid\n", option, value);
   22     } else
   23         *variable = atoi(value);
   24 }
   25 
   26 void parse_config(char *config) {
   27     FILE *fp;
   28     char buffer[BUFFER_LEN];
   29 
   30     char *option;                               /* config file option */
   31     char *value;                                /* value for option */
   32 
   33     int line_number = 1;
   34     char *chop;
   35 
   36     /* MEMWATCH: reports this isnt freed, why? */
   37     option = malloc_w(((BUFFER_LEN/2)-1)*sizeof(char));
   38 
   39     config = tilde_expand(config);
   40     fp = fopen(config, "r");
   41 
   42     if (!fp) {
   43             debug(2, "parse_config: error opening %s, skipping\n", config);
   44         return;
   45     }
   46 
   47     while (fgets(buffer, sizeof(buffer), fp)) {
   48         if (buffer[0] == '#' || buffer[0] == ';' || buffer[0] == '\n')
   49             continue;
   50         remove_crud(buffer);
   51         chop = (char*)strstr(buffer, "\n");     /* credits to cgichk */
   52         if (chop) *chop = 0;                    /* and toby deshane  */
   53         value = extract(buffer, '=');
   54         if (!value) {
   55             fprintf(stderr, "parse_config: invalid config file entry, file %s line %i\n", config, line_number);
   56             exit(EXIT_FAILURE);
   57         }
   58         strncpy(option, buffer, ((BUFFER_LEN/2)-1)*sizeof(char));
   59         debug(5, "parse_config: (%s) option: %s, value: %s\n", config, option, value);
   60 
   61         if (!strcmp("beep", option))
   62             process_boolean(option, value, &beep);
   63         else
   64         if (!strcmp("debug", option))
   65             debug_level = atoi(value);
   66 #ifdef USE_DUMMY        
   67         else
   68         if (!strcmp("dummy_file", option))
   69             strncpy(submit_dummy_file, value, sizeof(submit_dummy_file));
   70 #endif /* USE_DUMMY */
   71         else
   72         if (!strcmp("logfile", option))
   73             strncpy(logfile, value, sizeof(logfile));
   74         else
   75         if (!strcmp("resume", option))
   76             if (IS_BIT(value))
   77                 process_boolean(option, value, &save_session);
   78             else {
   79                 strncpy(session_file, value, sizeof(session_file));
   80                 resume_session = 1;
   81             }
   82         else
   83         if (!strcmp("save", option))
   84             if (IS_BIT(value))
   85                 process_boolean(option, value, &save_session);
   86             else {
   87                 strncpy(session_file, value, sizeof(session_file));
   88                 save_session = 1;
   89             }
   90         else
   91         if (!strcmp("max_connects", option))
   92             max_connects = atoi(value);
   93         else
   94         if (!strcmp("max_users", option))
   95             max_users = atoi(value);
   96         else
   97         if (!strcmp("user_agent", option))
   98             strncpy(user_agent, value, sizeof(user_agent));
   99         else
  100         if (!strcmp("pairs_file", option))
  101             strncpy(common_pairs_file, value, sizeof(common_pairs_file));
  102         else
  103         if (!strcmp("password_delay", option))
  104             per_password_delay = atoi(value);
  105         else
  106         if (!strcmp("password_file", option))
  107             strncpy(passwords_file, value, sizeof(passwords_file));
  108         else
  109         if (!strcmp("path", option))
  110             strncpy(pathlist, value, sizeof(pathlist));
  111         else
  112         if (!strcmp("proxy", option))
  113             strncpy(proxy, value, sizeof(proxy));
  114         else
  115         if (!strcmp("quiet", option))
  116             process_boolean(option, value, &quiet);
  117         else
  118         if (!strcmp("user_delay", option))
  119             per_user_delay = atoi(value);
  120         else
  121         if (!strcmp("username_file", option))
  122             strncpy(username_file, value, sizeof(username_file));
  123         else
  124         if (!quiet)
  125             printf("parse_config: option %s is not valid\n", option);
  126 
  127         line_number++;
  128     }
  129 
  130     debug(3, "parse_config: read %s [%i]\n", config, line_number-1);
  131 
  132     free(option);
  133     fclose(fp);
  134 }