Changeset 818 for branches


Ignore:
Timestamp:
09/21/08 22:00:54 (4 years ago)
Author:
wd
Message:
  • Make RFC1459 the default protocol
  • Add PROTOCOL command
  • Add WEBIRC support for Mibbit
Location:
branches/ithildin-1.1/modules/ircd
Files:
2 added
7 edited

Legend:

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

    r778 r818  
    8383    if (mask != NULL && *mask != '\0') { 
    8484        if (!strcasecmp(mask, CGI_IRC_SPECIAL_MASK)) { 
    85             /* Special CGI:IRC hack.  We take the password, if supplied, an 
     85            /* Special CGI:IRC hack.  We take the password, if supplied, and 
    8686             * use it as a hostname (as long as it's valid).  Good stuff. */ 
    8787            if (cli->conn->pass != NULL && *cli->conn->pass != '\0' && 
  • branches/ithildin-1.1/modules/ircd/commands/user.c

    r693 r818  
    5353        strcpy(u, "null"); 
    5454 
    55     /* fill in other stuff */ 
    56     strncpy(cli->host, cp->host, HOSTLEN); 
     55    /* fill in other stuff if it hasn't already been set */ 
     56    if (*cli->host == '\0') 
     57        strncpy(cli->host, cp->host, HOSTLEN); 
    5758    strncpy(cli->info, argv[4], GCOSLEN); 
    5859    cli->server = ircd.me; 
  • branches/ithildin-1.1/modules/ircd/conf/commands.conf

    r579 r818  
    128128    //command pong;        // (required by addons/core) 
    129129 
     130    //command protocol; // allows unregistered clients to change their 
     131                        // protocol (required by proto/rfc1459) 
     132 
    130133    //command quit;        // allows users to sign off the server (required by 
    131134                        // addons/core) 
     
    197200 
    198201    command watch;        // adds 'server-side notify' support. 
     202 
     203    /* 
     204    // This command enables WEBIRC command support (largely for Mibbit). 
     205    // You must specify the correct originating IP and the password you 
     206    // expect sent for authentication purposes. 
     207    command webirc { 
     208        ip 67.207.141.120; 
     209        password "your-mibbit-password"; 
     210    }; 
     211    */ 
    199212 
    200213    command who;        // allows users to get short-form information 
  • branches/ithildin-1.1/modules/ircd/connection.c

    r772 r818  
    362362    /* now stick them in the default protocol */ 
    363363    c->proto = ircd.default_proto; 
     364    c->proto->setup(c); 
    364365    c->last = me.now; 
    365366    /* and monitor them */ 
     
    436437        /* Only flag that we are writeable.  The writer hook takes care of 
    437438         * doing buffered writes for us outside the construct of this loop. 
    438          * I thiml, potentially falsely, that it may be beneficial to batch 
     439         * I think, potentially falsely, that it may be beneficial to batch 
    439440         * writes and reads in this manner. */ 
    440441        c->flags |= IRCD_CONNFL_WRITEABLE; 
  • branches/ithildin-1.1/modules/ircd/ircd.c

    r802 r818  
    383383    ircd.events.started = create_event(EVENT_FL_HOOKONCE); 
    384384 
    385     /* setup our default protocol.  if we didn't save it, then we allocate it 
    386      * fresh, and fill in the name only.  we set up the input no matter what 
    387      * because function addresses may change. */ 
    388     if (!get_module_savedata(savelist, "ircd.default_proto", 
    389                 &ircd.default_proto)) { 
    390         ircd.default_proto = malloc(sizeof(protocol_t)); 
    391         memset(ircd.default_proto, 0, sizeof(protocol_t)); 
    392         ircd.default_proto->name = strdup("default"); 
    393     } 
    394     ircd.default_proto->input = protocol_default_input; 
    395     if (LIST_EMPTY(ircd.lists.protocols)) 
    396         LIST_INSERT_HEAD(ircd.lists.protocols, ircd.default_proto, lp); 
    397  
    398385    /* grab the timer hook to see if connections have timed out */ 
    399386    timer_ref = create_timer(-1, timer_fuzz, ircd_timer_hook, NULL); 
     
    511498    if (!reload && !ircd_parse_conf(conf)) 
    512499        return 0; 
     500 
     501    /* setup our default protocol (rfc1459). */ 
     502#define DEFAULT_PROTOCOL "rfc1459" 
     503    if (find_protocol(DEFAULT_PROTOCOL) == NULL && 
     504        !add_protocol(DEFAULT_PROTOCOL)) { 
     505        log_error("could not load rfc1459 protocol?"); 
     506        return 0; 
     507    } 
     508    ircd.default_proto = find_protocol(DEFAULT_PROTOCOL); 
    513509 
    514510    if (!ircd.started) { 
     
    635631        add_module_savedata(savelist, "ircd.privileges", 
    636632                sizeof(ircd.privileges), &ircd.privileges); 
    637         add_module_savedata(savelist, "ircd.default_proto", 
    638                 sizeof(ircd.default_proto), &ircd.default_proto); 
    639633        add_module_savedata(savelist, "ircd.lists", sizeof(ircd.lists), 
    640634                &ircd.lists); 
  • branches/ithildin-1.1/modules/ircd/protocol.c

    r717 r818  
    1414 
    1515IDSTRING(rcsid, "$Id$"); 
    16  
    17 /* this function, defined below, and the one defined immediately below here are 
    18  * the default packet parsers.  The default packets resemble rfc1459 strongly. 
    19  * The actual packet parser is a bit pickier about what gets passed along, 
    20  * however. */ 
    21 static int protocol_packet_parse(connection_t *cp, char *end); 
    22  
    23 /* Return codes from protocol_packet_parse */ 
    24 #define PROTOCOL_PARSE_PROTOSET 1 
    25 #define PROTOCOL_PARSE_1459STOP 2 
    26  
    27 #define DEFAULT_BUFFER_SIZE 512 
    28 HOOK_FUNCTION(protocol_default_input) { 
    29     isocket_t *sp = (isocket_t *)data; 
    30     connection_t *cp = (connection_t *)sp->udata; 
    31     int ret = 0; 
    32     char *s; 
    33  
    34     if (!(cp->flags & IRCD_CONNFL_STAGE2)) { /* initialize the connection */ 
    35         cp->buf = malloc(DEFAULT_BUFFER_SIZE); 
    36         cp->buflen = 0; 
    37         cp->bufsize = DEFAULT_BUFFER_SIZE; 
    38         cp->flags |= IRCD_CONNFL_STAGE2; 
    39         cp->buf[0] = '\0'; 
    40     } 
    41  
    42     if (cp->buflen < cp->bufsize) 
    43         ret = socket_read(sp, cp->buf + cp->buflen, 
    44                 cp->bufsize - cp->buflen); 
    45     if (ret < 0) 
    46         return (void *)0; /* the error should be picked up by the handler. */ 
    47     else if (ret == 0) 
    48         return (void *)0; /* nothing to do */ 
    49  
    50     cp->buflen += ret; 
    51  
    52     cp->stats.recv += ret; 
    53     /* the rest of this was yanked almost verbatim from proto/rfc1459.c, I had 
    54      * done it a different way, but it ate a flaming bag of acidli when 
    55      * connections to servers were attempted.  Now I've split this into a 
    56      * pretty straightforward rfc1459 packet parser, and a command handler 
    57      * function which lives below */ 
    58  
    59     while (cp->buflen > 0) { 
    60         /* if the buffer is full but no terminating character (\n) is found, we 
    61          * cheat */ 
    62         if (cp->buflen == cp->bufsize) { 
    63             cp->buf[cp->bufsize - 1] = '\n'; 
    64             s = cp->buf + cp->bufsize - 1; 
    65         } else { 
    66             cp->buf[cp->buflen] = '\0'; 
    67             s = strchr(cp->buf, '\n'); 
    68             if (s == NULL) 
    69                 return (void *)0; /* no command terminator found and we're out 
    70                                      of data */ 
    71         } 
    72         /* make a local copy of the packet, then pass it off to the parser. 
    73          * Bump the rest of the contents of 'buf' down if we read more than we 
    74          * have parsed. */ 
    75         /* null-terminate and get rid of the [\r]\n sequence */ 
    76         if (*(s - 1) == '\r') 
    77             *(s - 1) = '\0'; 
    78         else 
    79             *s = '\0'; 
    80  
    81         /* Parse the packet, we must stop parsing immediately if the 
    82          * connection is closed.  Additionally, we stop parsing immediately 
    83          * if we get the 1459 return because the code that returns it 
    84          * modifies our buffer for us.  In that case we return proto changed 
    85          * and let input be call for us above. */ 
    86         if ((ret = protocol_packet_parse(cp, s)) == IRCD_CONNECTION_CLOSED) 
    87             return (void *)ret; /* stop parsing.. */ 
    88         else if (ret == PROTOCOL_PARSE_1459STOP) 
    89             return (void *)IRCD_PROTOCOL_CHANGED; 
    90         s++; /* increment s, now we see if our packet contains more data */ 
    91         if ((size_t)(s - cp->buf) < cp->buflen) { 
    92             cp->buflen -= s - cp->buf; 
    93             memcpy(cp->buf, s, cp->buflen); 
    94         } else { 
    95             cp->buflen = 0; /* all done */ 
    96             *cp->buf = '\0'; /* no leftovers! */ 
    97         } 
    98         if (ret == PROTOCOL_PARSE_PROTOSET) 
    99             return (void *)IRCD_PROTOCOL_CHANGED; 
    100     } 
    101  
    102     return (void *)0; 
    103 } 
    104  
    105 static int protocol_packet_parse(connection_t *cp, char *end) { 
    106     char *s, emsg[128]; 
    107     int rfc1459 = 0; /* this is such a dumb hack */ 
    108  
    109     cp->stats.precv++; /* another packet received.. */ 
    110     s = cp->buf; 
    111     if (*s == ':') /* prefixed command?  ignore it totally! */ 
    112         return 0; 
    113  
    114     if (!strncasecmp(cp->buf, "QUIT", 4)) { 
    115         destroy_connection(cp, ""); 
    116         return IRCD_CONNECTION_CLOSED; 
    117     } else if (!strncasecmp(cp->buf, "PROTOCOL", 8)) { 
    118         /* we received a 'protocol' command.  cool.  this makes our life easy, 
    119          * just grab the stuff after and find a protocol if possible */ 
    120         s += 8; 
    121         while (isspace(*s)) 
    122             s++; 
    123         if (*s == '\0') { 
    124             destroy_connection(cp, "bogus protocol command"); 
    125             return IRCD_CONNECTION_CLOSED; 
    126         } 
    127  
    128         /* otherwise, s points to their desired protocol */ 
    129     } else if (!strncasecmp(s, "NICK", 4) || !strncasecmp(s, "USER", 4) || 
    130                 !strncasecmp(s, "PASS", 4)) { 
    131             /* this is probably an rfc1459 connection */ 
    132         rfc1459 = 1; 
    133         s = "rfc1459"; 
    134     } else { 
    135         log_debug("received weird packet for unprotocoled connection: %s", 
    136                 cp->buf); 
    137         return 0; 
    138     } 
    139  
    140     /* s now points to our chosen protocol! joy */ 
    141     cp->proto = find_protocol(s); 
    142     if (cp->proto == NULL) { 
    143         sprintf(emsg, "protocol %s is not supported", s); 
    144         destroy_connection(cp, emsg); 
    145         return IRCD_CONNECTION_CLOSED; 
    146     } 
    147          
    148     /* call the setup function for this connection */ 
    149     if (cp->proto->setup != NULL) 
    150         cp->proto->setup(cp); 
    151          
    152     if (rfc1459) { 
    153         /* Re-adjust the buffer and return the special token to immediately 
    154          * and successfully halt parsing (see above).  We do this because 
    155          * the protocol itself needs to receive the message we hooked onto 
    156          * for 1459 verification. */ 
    157         if (*(end - 1) == '\0') 
    158             *(end - 1) = '\r'; 
    159         *end = '\n'; 
    160  
    161         return PROTOCOL_PARSE_1459STOP; 
    162     } 
    163  
    164     return PROTOCOL_PARSE_PROTOSET; 
    165 } 
    16616 
    16717protocol_t *find_protocol(char *name) { 
     
    23787        pp->bufsize = *i64p; 
    23888    else 
    239         pp->bufsize = DEFAULT_BUFFER_SIZE; 
     89        pp->bufsize = 512; 
    24090} 
    24191 
  • branches/ithildin-1.1/modules/ircd/protocols/rfc1459.c

    r814 r818  
    1616@DEPENDENCIES@: ircd 
    1717@DEPENDENCIES@: ircd/commands/nick ircd/commands/pass ircd/commands/user 
     18@DEPENDENCIES@: ircd/commands/protocol 
    1819*/ 
    1920 
Note: See TracChangeset for help on using the changeset viewer.