Show
Ignore:
Timestamp:
08/09/04 18:38:03 (9 years ago)
Author:
alexcv
Message:

Added functions to handle the auth servers list.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/src/conf.c

    r176 r178  
    3131#include <syslog.h> 
    3232 
     33#include <pthread.h> 
     34 
    3335#include <string.h> 
    3436 
     
    4345 * Holds the current configuration of the gateway */ 
    4446static s_config config; 
     47 
     48/** @internal 
     49 * Mutex for the configuration file, used by the auth_servers related 
     50 * functions. */ 
     51static pthread_mutex_t config_mutex = PTHREAD_MUTEX_INITIALIZER; 
    4552 
    4653/** @internal 
     
    6168        oGatewayPort, 
    6269        oAuthServer, 
     70        oAuthServMaxTries, 
    6371        oAuthservPath, 
    6472        oAuthservLoginUrl, 
     
    8694        { "gatewayport",        oGatewayPort }, 
    8795        { "authserver",         oAuthServer }, 
     96        { "authservmaxtries",   oAuthServMaxTries }, 
    8897        { "authservpath",       oAuthservPath }, 
    8998        { "authservloginurl",   oAuthservLoginUrl }, 
     
    125134        config.gw_port = DEFAULT_GATEWAYPORT; 
    126135        config.auth_servers = NULL; 
     136        config.authserv_maxtries = DEFAULT_AUTHSERVMAXTRIES; 
    127137        config.authserv_path = strdup(DEFAULT_AUTHSERVPATH); 
    128138        config.authserv_loginurl = NULL; 
     
    251261                                        sscanf(p1, "%d", &config.httpdmaxconn); 
    252262                                        break; 
     263                                case oAuthServMaxTries: 
     264                                        sscanf(p1, "%d", &config.authserv_maxtries); 
     265                                        break; 
    253266                                case oAuthservPath: 
    254267                                        free(config.authserv_path); 
     
    336349/** @internal 
    337350    Register a new auth server. 
     351 
     352    @param host Hostname of the server 
     353    @param port Port of the server 
    338354*/ 
    339355static void 
     
    368384        debug(LOG_DEBUG, "Auth server added"); 
    369385} 
     386 
     387/** 
     388 * This function returns the current (first auth_server) 
     389 */ 
     390t_auth_serv * 
     391get_auth_server(void) 
     392{ 
     393 
     394        /* This is as good as atomic */ 
     395        return config.auth_servers; 
     396} 
     397 
     398/** 
     399 * This function marks the current auth_server, if it matches the argument, 
     400 * as bad. Basically, the "bad" server becomes the last one on the list. 
     401 */ 
     402void 
     403mark_auth_server_bad(t_auth_serv *bad_server) 
     404{ 
     405        t_auth_serv     *tmp; 
     406 
     407        /* lock mutex so two different threads both don't mark the same 
     408         * server as bad */ 
     409        pthread_mutex_lock(&config_mutex); 
     410 
     411        if (config.auth_servers == bad_server) { 
     412                /* Go to the last */ 
     413                for (tmp = config.auth_servers; tmp->next != NULL; tmp = tmp->next); 
     414                /* Set bad server as last */ 
     415                tmp->next = bad_server; 
     416                /* Remove bad server from start of list */ 
     417                config.auth_servers = bad_server->next; 
     418                /* Set the next pointe to NULL in the last element */ 
     419                bad_server->next = NULL; 
     420        } 
     421 
     422        pthread_mutex_unlock(&config_mutex); 
     423}