src/irc_proto.c
changeset 45 71e65564afd2
parent 39 a4891d71aca9
child 72 43084f103c2a
equal deleted inserted replaced
44:6bd70113e1ed 45:71e65564afd2
     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 (struct irc_nm *nm, char *buf, const char *prefix)
       
     6 {
       
     7     // too long?
       
     8     if (strlen(prefix) >= IRC_PREFIX_MAX)
       
     9         return ERR_INVALID_NM;
       
    10 
       
    11     // copy to mutable buffer
       
    12     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     
       
    23     // the hostname is then the rest of the prefix
       
    24     nm->hostname = buf;
       
    25 
       
    26     // ok
       
    27     return SUCCESS;
       
    28 }
     4 
    29 
     5 /**
    30 /**
     6  * Compare two nicknames
    31  * Compare two nicknames
     7  */
    32  */
     8 int irc_cmp_nick (const char *nick1, const char *nick2)
    33 int irc_cmp_nick (const char *nick1, const char *nick2)