Changeset 65

Show
Ignore:
Timestamp:
04/14/04 19:53:28 (5 years ago)
Author:
alexcv
Message:

Threads fully functional and insert_userclasses() rewritten to fix the
segfault

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wifidog/ChangeLog

    r64 r65  
    11# $Header$ 
     22004-04-14  Alexandre Carmel-Veilleux <acv@acv.ca> 
     3        * Major retooling of insert_userclass(), fixed seg fault. 
     4        * The program now works as advertised. 
     5 
    262004-04-14  Alexandre Carmel-Veilleux <acv@acv.ca> 
    37        * Switched to threads. Alpha quality build, at best 
  • trunk/wifidog/src/auth.c

    r64 r65  
    8888         
    8989        tmp_uc = find_userclasses(profile); 
    90  
     90         
    9191        if (tmp_uc == NULL) { 
    9292                debug(D_LOG_DEBUG, "Profile %d undefined", profile); 
     
    9494                node->fd = 0; 
    9595                return; 
     96        } else { 
     97                debug(D_LOG_DEBUG, "Profile %d UserClasses retrieved", profile); 
    9698        } 
    9799         
  • trunk/wifidog/src/centralserver.c

    r47 r65  
    6262                                sizeof(struct sockaddr)) == -1) { 
    6363                debug(D_LOG_ERR, "connect(): %s", strerror(errno)); 
    64                 exit(1); 
     64                return(-1); /* non-fatal */ 
    6565        } 
    66  
    67         sprintf(buf, "GET %s?ip=%s&mac=%s&token=%s&stats=%ld HTTP/1.1\nHost: " 
    68                 "%s\n\n", config.authserv_path, ip, mac, token, stats, 
    69                 config.authserv_hostname); 
     66        sprintf(buf, "GET %s?ip=%s&mac=%s&token=%s&stats=%ld HTTP/1.1" 
     67                "\nHost: %s\n\n", config.authserv_path, ip, mac, token, 
     68                stats, config.authserv_hostname); 
    7069        send(sockfd, buf, strlen(buf), 0); 
    7170 
  • trunk/wifidog/src/userclasses.c

    r44 r65  
    8787        tmp_uc = class_list; 
    8888 
    89         if (tmp_uc == NULL) { 
     89        /* first */ 
     90        if (class_list == NULL) { 
    9091                class_list = class; 
    91         } else { 
    92                /* Skip to our place in the ordered list, or the end */ 
    93                 while (tmp_uc->profile < class->profile 
    94                                && tmp_uc->next != NULL) 
    95                        tmp_uc = tmp_uc->next; 
    96  
    97                 if (tmp_uc->profile == class->profile) { 
    98                         /* swap in place */ 
    99                        if (tmp_uc->prev != NULL) 
    100                                tmp_uc->prev->next = class
    101  
     92               return; 
     93        } 
     94 
     95        /* duplicate */ 
     96        if ((tmp_uc = find_userclasses(class->profile)) != NULL) { 
     97                if (tmp_uc == class_list) { 
     98                       class_list = class; 
     99                        class->next = tmp_uc->next; 
     100                } else { 
     101                        class->next = tmp_uc->next
     102                        class->prev = tmp_uc->prev; 
    102103                        if (tmp_uc->next != NULL) 
    103104                                tmp_uc->next->prev = class; 
    104                          
    105                         class->prev = tmp_uc->prev; 
    106                         class->next = tmp_uc->next; 
    107                         free_userclasses(tmp_uc); 
    108                 } else if (tmp_uc->next == NULL) { 
    109                         /* last item */ 
    110                         tmp_uc->next = class; 
    111                         class->prev = tmp_uc; 
    112                 } else { 
    113                         /* in between two elements */ 
    114                         class->next = tmp_uc->next; 
    115                         class->prev = tmp_uc; 
    116                         tmp_uc->next = class; 
    117                         class->next->prev = class; 
     105                        tmp_uc->prev->next = class; 
    118106                } 
    119         } 
     107                return; 
     108        } 
     109         
     110        /* new */ 
     111        tmp_uc = class_list; 
     112 
     113        /* new first item */ 
     114        if (tmp_uc->profile > class->profile) { 
     115                class_list = class; 
     116                class->next = tmp_uc; 
     117                tmp_uc->prev = class; 
     118                return; 
     119        } 
     120 
     121        /* seek previous record */ 
     122        while (tmp_uc->next != NULL && tmp_uc->profile < class->profile) 
     123                tmp_uc = tmp_uc->next; 
     124         
     125        /* new last record */ 
     126        if (tmp_uc->next == NULL) { 
     127                tmp_uc->next = class; 
     128                class->prev = tmp_uc; 
     129                return; 
     130        } 
     131 
     132        /* just a normal insertion */ 
     133        class->next = tmp_uc->next; 
     134        class->prev = tmp_uc; 
     135        tmp_uc->next = class; 
     136        class->next->prev = class; 
     137         
     138        return; 
    120139} 
    121140 
     
    134153        if (tmp_uc == NULL) 
    135154                return NULL; 
    136  
     155         
    137156        return tmp_uc; 
    138157}