Changeset 831 for branches/ithildin-1.1


Ignore:
Timestamp:
02/09/09 00:42:56 (3 years ago)
Author:
wd
Message:

Clean up unknown client counting (hopefully fixed) and add some helper
functions for protocol transition.

Location:
branches/ithildin-1.1
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/ithildin-1.1/modules/ircd/client.c

    r822 r831  
    2929    cp->mdext = mdext_alloc(ircd.mdext.client); 
    3030 
     31    /* all new clients are set unknown even if they're remote (this will get 
     32     * handled in register_client so it shouldn't be a big deal */ 
     33    cp->flags |= IRCD_CLIENT_UNKNOWN; 
     34    ircd.stats.serv.unkclients++; 
     35 
    3136    if (conn != NULL) { 
    3237        conn->cli = cp; 
     
    3439        get_socket_address(isock_raddr(conn->sock), cp->ip, IPADDR_MAXLEN + 1, 
    3540                NULL); 
    36         ircd.stats.serv.unkclients++; 
    3741    } else 
    3842        cp->pset = LIST_FIRST(ircd.privileges.sets); 
     
    4953    unsigned char *s; 
    5054 
    51     if (cli->flags & IRCD_CLIENT_HISTORY) { 
     55    if (CLIENT_HISTORY(cli)) { 
    5256        /* just return the memory */ 
    5357        mdext_free(ircd.mdext.client, cli->mdext); 
     
    110114        hash_delete(ircd.hashes.client, cli); 
    111115 
     116    if (CLIENT_UNKNOWN(cli)) 
     117        ircd.stats.serv.unkclients--; 
     118 
    112119    if (cli->conn != NULL) { /* dump it if it's ours */ 
    113         if (!CLIENT_REGISTERED(cli)) 
    114             ircd.stats.serv.unkclients--; 
    115120        cli->conn->cli = NULL; 
    116121 
     
    126131    LIST_REMOVE(cli, lp); 
    127132 
    128     if (!CLIENT_REGISTERED(cli)) { 
     133    if (!CLIENT_HISTORY(cli)) { 
    129134        /* if the client was registered then we need to preserve their client 
    130135         * entry for the history list */ 
     
    189194            returns = hook_event(ircd.events.stage3_connect, cp); 
    190195            while (x < hook_num_returns) { 
    191                 if (returns[x] != NULL) {/* denied, with a reason */ 
     196                if (returns[x] != NULL) { /* denied, with a reason */ 
    192197                    destroy_client(cli, (char *)returns[x]); 
    193                         return IRCD_CONNECTION_CLOSED; /* not successful */ 
     198                    return IRCD_CONNECTION_CLOSED; /* not successful */ 
    194199                } 
    195200                x++; 
     
    199204            LIST_REMOVE(cp, lp); 
    200205            LIST_INSERT_HEAD(ircd.connections.clients, cp, lp); 
    201             ircd.stats.serv.unkclients--; 
    202  
    203206        } 
    204207 
     
    220223 
    221224        /* accounting stuff */ 
     225        if (CLIENT_UNKNOWN(cli)) 
     226        { 
     227            cli->flags &= ~IRCD_CLIENT_UNKNOWN; 
     228            ircd.stats.serv.unkclients--; 
     229        } 
    222230        ircd.stats.serv.curclients++; 
    223231        if (ircd.stats.serv.maxclients < ircd.stats.serv.curclients) 
     
    541549         * overwrite old entries (maybe).  if the client table is larger 
    542550         * than the history table then we also let the history table grow, 
    543          * but if the two are * the same size we need to pop the oldest 
     551         * but if the two are the same size we need to pop the oldest 
    544552         * entry off. */ 
    545553 
     
    548556    } 
    549557 
    550         chp = calloc(1, sizeof(struct client_history)); 
     558    chp = calloc(1, sizeof(struct client_history)); 
    551559 
    552560    /* fill it in ... */ 
     
    558566 
    559567    /* insert it in the hash */ 
    560         hash_insert(ircd.hashes.client_history, chp); 
     568    hash_insert(ircd.hashes.client_history, chp); 
    561569    TAILQ_INSERT_HEAD(ircd.lists.client_history, chp, lp); 
    562570 
     
    579587    free(cli->hist); 
    580588     
    581     if (cli->flags & IRCD_CLIENT_HISTORY) 
     589    if (CLIENT_HISTORY(cli)) 
    582590        destroy_client(cli, NULL); 
    583591    else 
     
    599607    /* if we found it and they signed off at or after the current time minus 
    600608     * the time limit, return the entry. */ 
    601     if (chp != NULL && !(chp->cli->flags & IRCD_CLIENT_HISTORY) && 
     609    if (chp != NULL && !CLIENT_HISTORY(chp->cli) && 
    602610            chp->signoff >= (limit ? me.now - limit : 0)) 
    603611        return chp->cli; 
  • branches/ithildin-1.1/modules/ircd/client.h

    r748 r831  
    2323    char    info[GCOSLEN + 1];      /* gecos/gcos info (ircname) */ 
    2424 
    25 #define IRCD_CLIENT_REGISTERED        0x0001 
    26     /* check to see if the client is registered or not */ 
     25#define IRCD_CLIENT_UNKNOWN         0x0001 
     26#define IRCD_CLIENT_REGISTERED      0x0002 
     27#define IRCD_CLIENT_KILLED          0x0004 
     28#define IRCD_CLIENT_HISTORY         0x0008 
     29 
     30#define CLIENT_UNKNOWN(cli) (cli->flags & IRCD_CLIENT_UNKNOWN) 
    2731#define CLIENT_REGISTERED(cli) (cli->flags & IRCD_CLIENT_REGISTERED) 
    28 #define IRCD_CLIENT_KILLED        0x0002 
    29 #define IRCD_CLIENT_HISTORY        0x0004 
     32#define CLIENT_KILLED(cli) (cli->flags & IRCD_CLIENT_KILLED) 
     33#define CLIENT_HISTORY(cli) (cli->flags & IRCD_CLIENT_HISTORY) 
     34 
    3035    int     flags; 
    3136 
  • branches/ithildin-1.1/modules/ircd/commands/protocol.c

    r818 r831  
    3838    } 
    3939 
    40     cp->proto = proto; 
    41     cp->proto->setup(cp); 
     40    set_connection_protocol(cp, proto); 
    4241 
    4342    return IRCD_PROTOCOL_CHANGED; 
  • branches/ithildin-1.1/modules/ircd/commands/server.c

    r826 r831  
    228228    } 
    229229 
    230     cp = cli->conn; 
    231     cli->conn = NULL; /* save/set client's connection to NULL so destroy_client 
    232                          doesn't nerf the connection in the process */ 
    233     destroy_client(cli, ""); /* cli is no longer valid */ 
    234     cp->cli = NULL; 
    235  
    236230    /* now we mock up a server connection.  joy of joys, our pass should still 
    237231     * have been saved.  we just reset the protocol, and setup the connection, 
    238232     * and then call the server version of the SERVER command.  This is pretty 
    239233     * dirty. :/ */ 
    240     cp->proto = pp; 
    241     cp->proto->setup(cp); 
     234    set_connection_protocol(cp, pp); 
    242235    if ((ret = s_server_cmd(NULL, argc, argv, cp->srv)) != 0) 
    243236        return ret; /* Give them whatever s_server_cmd gave, it will always 
  • branches/ithildin-1.1/modules/ircd/connection.c

    r822 r831  
    2525static void connection_init_lookups(connection_t *); 
    2626 
     27/* set the protocol for a connection, possibly cleaning up if necessary for 
     28 * protocol changes */ 
     29void set_connection_protocol(connection_t *cp, protocol_t *proto) { 
     30 
     31    if (cp->proto != NULL) 
     32        clear_connection_objects(cp); 
     33     
     34    cp->proto = proto; 
     35    cp->proto->setup(cp); 
     36} 
     37 
     38/* safely remove both client and server objects from the connection */ 
     39void clear_connection_objects(connection_t *cp) { 
     40    client_t *cli = cp->cli; 
     41    server_t *srv = cp->srv; 
     42 
     43    if (cli != NULL) { 
     44        cli->conn = NULL; 
     45        cp->cli = NULL; 
     46        destroy_client(cli, ""); 
     47    } 
     48 
     49    if (srv != NULL) { 
     50        srv->conn = NULL; 
     51        cp->srv = NULL; 
     52        destroy_server(srv, ""); 
     53    } 
     54} 
     55 
    2756void destroy_connection(connection_t *c, char *reason) { 
    2857    char msg[512]; 
     
    3463#endif 
    3564    /* destroy_client/server will set the cli/srv entries to NULL, then call us 
    36      * again to really desotry the connection.  this makes it safe to call 
     65     * again to really destroy the connection.  this makes it safe to call 
    3766     * 'destroy_connection' even if you're not sure what kind of connection you 
    3867     * have. */ 
     
    362391 
    363392    /* now stick them in the default protocol */ 
    364     c->proto = ircd.default_proto; 
    365     c->proto->setup(c); 
     393    set_connection_protocol(c, ircd.default_proto); 
    366394    c->last = me.now; 
    367395    /* and monitor them */ 
  • branches/ithildin-1.1/modules/ircd/connection.h

    r828 r831  
    8787}; 
    8888 
     89void set_connection_protocol(connection_t *, protocol_t *); 
     90void clear_connection_objects(connection_t *); 
    8991void destroy_connection(connection_t *, char *); 
    9092int close_unknown_connections(char *); 
  • branches/ithildin-1.1/modules/ircd/doc/conf.txt

    r775 r831  
    659659    protocol "some-protocol"; 
    660660 
    661     // ssl: (optional) 
    662     // this is a boolean flag which specifies whether SSL should be useed to 
    663     // establish a connection to the server.  using SSL will turn off use of 
    664     // password verification as well as the checking of IPs. 
     661    // ssl: (optional) this is a boolean flag which specifies whether 
     662    // SSL should be used to establish a connection to the server. 
     663    // using SSL will turn off use of password verification as well as 
     664    // the checking of IPs. 
    665665    ssl <yes|no>; 
    666666 
  • branches/ithildin-1.1/modules/ircd/server.c

    r824 r831  
    477477    cp->cls = LIST_FIRST(ircd.lists.classes); /* stick them in the default class 
    478478                                            temporarily. */ 
    479     cp->proto = proto; 
    480479    cp->signon = me.now; 
    481480    cp->last = me.now; 
     481    set_connection_protocol(cp, proto); 
    482482 
    483483    /* put it on the stage2 list.  technically it should stay as stage2 until 
    484484     * the negotiation is finished and server_register() is called. */ 
    485485    LIST_INSERT_HEAD(ircd.connections.stage2, cp, lp); 
    486     proto->setup(cp); 
    487486 
    488487    sp = cp->srv; 
  • branches/ithildin-1.1/source/conf.c

    r578 r831  
    498498                    str++; 
    499499                    while (*str) { 
    500                         if (*str == '\\') 
     500                        if (*str == '\\' && *(str + 1) != '\0') 
    501501                            str += 2; 
    502502                        else if (*str == '"') 
     
    561561            } 
    562562             
    563             *str++ = '\0';; 
     563            *str++ = '\0'; 
    564564            continue; 
    565565        } else { 
Note: See TracChangeset for help on using the changeset viewer.