src/irc_line.h
changeset 17 5001564ac5fc
child 18 dedf137b504f
equal deleted inserted replaced
16:20ce0029e4a0 17:5001564ac5fc
       
     1 #ifndef IRC_LINE_H
       
     2 #define IRC_LINE_H
       
     3 
       
     4 #include "error.h"
       
     5 
       
     6 /*
       
     7  * The maximum length of a line, including terminating CRLF
       
     8  */
       
     9 #define IRC_LINE_MAX 512
       
    10 
       
    11 /*
       
    12  * The maximum number of arguments for a single command
       
    13  */
       
    14 #define IRC_ARG_MAX 15
       
    15 
       
    16 /*
       
    17  * Chars that are invalid inside of tokens
       
    18  */
       
    19 #define IRC_TOKEN_INVALID "\r\n\n "
       
    20 #define IRC_TOKEN_TRAILING_INVALID "\r\n\n"
       
    21 
       
    22 /*
       
    23  * Low-level IRC protocol unit is a line with its bits
       
    24  */
       
    25 struct irc_line {
       
    26     /* The message source, either a server name or a nickmask */
       
    27     const char *prefix;
       
    28 
       
    29     /* The command, either a numeric or a primary command */
       
    30     const char *command;
       
    31 
       
    32     /* The arguments, with unused ones set to NULL */
       
    33     const char *args[IRC_ARG_MAX];
       
    34 };
       
    35 
       
    36 /*
       
    37  * Parse an IRC message to fill in an irc_line. This mutates the value of data (to insert NULs between tokens), and
       
    38  * stores pointers into this data into the irc_line.
       
    39  */
       
    40 err_t irc_line_parse (struct irc_line *line, char *data);
       
    41 
       
    42 /*
       
    43  * Formats an irc_line as a protocol line into the given buffer (which should hold at least IRC_LINE_MAX bytes).
       
    44  */
       
    45 err_t irc_line_build (const struct irc_line *line, char *buf);
       
    46 
       
    47 #endif /* IRC_LINE_H */