src/irc_nm.h
changeset 39 a4891d71aca9
parent 38 0c2e0cb46c3a
child 40 51678c7eae03
equal deleted inserted replaced
38:0c2e0cb46c3a 39:a4891d71aca9
     1 #ifndef IRC_NM_H
       
     2 #define IRC_NM_H
       
     3 
       
     4 /**
       
     5  * @file
       
     6  *
       
     7  * Support for IRC nickmasks
       
     8  */
       
     9 #include "error.h"
       
    10 #include <stddef.h>
       
    11 
       
    12 /**
       
    13  * Maximum length of an IRC nickname including terminating NUL
       
    14  */
       
    15 #define IRC_NICK_MAX 31
       
    16 
       
    17 /**
       
    18  * Parsed nickmask
       
    19  */
       
    20 struct irc_nm {
       
    21     /** Nickname, not normalized */
       
    22     const char *nickname;
       
    23     
       
    24     /** Username, including any ident-related prefix from the network */
       
    25     const char *username;
       
    26 
       
    27     /** Hostname, either reverse DNS hostname, literal IPv4 or literal IPv6 */
       
    28     const char *hostname;
       
    29 };
       
    30 
       
    31 /**
       
    32  * Parse a full nickmask from a prefix. This fails if the prefix is a server name.
       
    33  *
       
    34  * XXX: not implemented, and memory-management issues
       
    35  */
       
    36 err_t irc_nm_parse (struct irc_nm *nm, char *prefix);
       
    37 
       
    38 /**
       
    39  * Compare two nicknames for equality, with standard strcmp() semantics.
       
    40  */
       
    41 int irc_cmp_nick (const char *nick1, const char *nick2);
       
    42 
       
    43 /**
       
    44  * Compare up to the first n chars of the two nickname strings for equality, with standard strcmp() semantics.
       
    45  */
       
    46 int irc_ncmp_nick (const char *nick1, const char *nick2, size_t n);
       
    47 
       
    48 /**
       
    49  * Parse the nickname portion of a prefix, storing it in the given buffer of IRC_NICK_MAX bytes.
       
    50  */
       
    51 err_t irc_prefix_parse_nick (const char *prefix, char nick[IRC_NICK_MAX]);
       
    52 
       
    53 /**
       
    54  * Compare the nickname in the given prefix and with the given nickname for equality.
       
    55  *
       
    56  * @return -err for invalid prefix, 0 for match, >0 for non-match.
       
    57  */
       
    58 int irc_prefix_cmp_nick (const char *prefix, const char *nick);
       
    59 
       
    60 #endif