src/irc_line.h
changeset 34 763f65f9df0c
parent 18 dedf137b504f
child 68 591a574f390e
equal deleted inserted replaced
33:e5139b339b18 34:763f65f9df0c
     1 #ifndef IRC_LINE_H
     1 #ifndef IRC_LINE_H
     2 #define IRC_LINE_H
     2 #define IRC_LINE_H
     3 
     3 
       
     4 /**
       
     5  * @file
       
     6  *
       
     7  * The low-level IRC protocol unit is a line, with prefix, command and arguments
       
     8  */
     4 #include "error.h"
     9 #include "error.h"
     5 
    10 
     6 /*
    11 /**
     7  * The maximum length of a line, without terminating CRLF
    12  * The maximum length of a line, without terminating CRLF
     8  */
    13  */
     9 #define IRC_LINE_MAX 510
    14 #define IRC_LINE_MAX 510
    10 
    15 
    11 /*
    16 /**
    12  * The maximum number of arguments for a single command
    17  * The maximum number of arguments for a single command
    13  */
    18  */
    14 #define IRC_ARG_MAX 15
    19 #define IRC_ARG_MAX 15
    15 
    20 
    16 /*
    21 /**
    17  * Chars that are invalid inside of tokens
    22  * Chars that are invalid inside of tokens
    18  */
    23  */
    19 #define IRC_TOKEN_INVALID "\r\n\n "
    24 #define IRC_TOKEN_INVALID "\r\n\n "
    20 #define IRC_TOKEN_TRAILING_INVALID "\r\n\n"
    25 #define IRC_TOKEN_TRAILING_INVALID "\r\n\n"
    21 
    26 
    22 /*
    27 /**
    23  * Low-level IRC protocol unit is a line with its bits
    28  * Low-level IRC protocol unit
    24  */
    29  */
    25 struct irc_line {
    30 struct irc_line {
    26     /* The message source, either a server name or a nickmask */
    31     /** The message source, either a server name or a nickmask */
    27     const char *prefix;
    32     const char *prefix;
    28 
    33 
    29     /* The command, either a numeric or a primary command */
    34     /** The command, either a numeric or a primary command */
    30     const char *command;
    35     const char *command;
    31 
    36 
    32     /* The arguments, with unused ones set to NULL */
    37     /** The arguments, with unused ones set to NULL */
    33     const char *args[IRC_ARG_MAX];
    38     const char *args[IRC_ARG_MAX];
    34 };
    39 };
    35 
    40 
    36 /*
    41 /**
    37  * Parse an IRC message to fill in an irc_line. This mutates the value of data (to insert NULs between tokens), and
    42  * 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.
    43  * stores pointers into this data into the irc_line.
       
    44  *
       
    45  * The irc_line will have the first N args values set to valid values, and all the rest set to NULL.
    39  */
    46  */
    40 err_t irc_line_parse (struct irc_line *line, char *data);
    47 err_t irc_line_parse (struct irc_line *line, char *data);
    41 
    48 
    42 /*
    49 /**
    43  * Formats an irc_line as a protocol line into the given buffer (which should hold at least IRC_LINE_MAX bytes).
    50  * Formats an irc_line as a protocol line into the given buffer (which should hold at least IRC_LINE_MAX bytes).
       
    51  *
       
    52  * The irc_line.args are ignored from the first NULL argument onwards.
       
    53  *
       
    54  * An error is returned if a token has an invalid value (e.g. a space in the command or an argument other than the last
       
    55  * one), or if the resulting line is too long.
    44  */
    56  */
    45 err_t irc_line_build (const struct irc_line *line, char *buf);
    57 err_t irc_line_build (const struct irc_line *line, char *buf);
    46 
    58 
    47 #endif /* IRC_LINE_H */
    59 #endif /* IRC_LINE_H */