src/irc_proto.c
changeset 75 ff6272398d2e
parent 72 43084f103c2a
child 82 bc767e01648d
equal deleted inserted replaced
74:11ec458d1cbf 75:ff6272398d2e
     1 #include "irc_proto.h"
     1 #include "irc_proto.h"
     2 
     2 
     3 #include <string.h>
     3 #include <string.h>
       
     4 
       
     5 err_t irc_nm_parse_buf (struct irc_nm *nm, char *prefix)
       
     6 {
       
     7     // XXX: handle server name prefixes
       
     8 
       
     9     // mangle tokens
       
    10     nm->nickname = strsep(&prefix, "!");
       
    11     nm->username = strsep(&prefix, "@");
       
    12 
       
    13     // did we find the ! and @ tokens?
       
    14     if (!prefix)
       
    15         // probably a server name instead
       
    16         return ERR_INVALID_NM;
       
    17     
       
    18     // the hostname is then the rest of the prefix
       
    19     nm->hostname = prefix;
       
    20 
       
    21     // ok
       
    22     return SUCCESS;
       
    23 
       
    24 }
     4 
    25 
     5 err_t irc_nm_parse (struct irc_nm *nm, char *buf, const char *prefix)
    26 err_t irc_nm_parse (struct irc_nm *nm, char *buf, const char *prefix)
     6 {
    27 {
     7     // too long?
    28     // too long?
     8     if (strlen(prefix) >= IRC_PREFIX_MAX)
    29     if (strlen(prefix) >= IRC_PREFIX_MAX)
     9         return ERR_INVALID_NM;
    30         return ERR_INVALID_NM;
    10 
    31 
    11     // copy to mutable buffer
    32     // copy to mutable buffer
    12     strcpy(buf, prefix);
    33     strcpy(buf, prefix);
    13 
       
    14     // mangle tokens
       
    15     nm->nickname = strsep(&buf, "!");
       
    16     nm->username = strsep(&buf, "@");
       
    17 
       
    18     // did we find the ! and @ tokens?
       
    19     if (!buf)
       
    20         // probably a server name instead
       
    21         return ERR_INVALID_NM;
       
    22     
    34     
    23     // the hostname is then the rest of the prefix
    35     // parse from buf
    24     nm->hostname = buf;
    36     return irc_nm_parse_buf(nm, buf);
    25 
       
    26     // ok
       
    27     return SUCCESS;
       
    28 }
    37 }
    29 
    38 
    30 /**
    39 /**
    31  * Compare two nicknames
    40  * Compare two nicknames
    32  */
    41  */