src/irc_cmd.h
changeset 37 4fe4a3c4496e
parent 23 542c73d07d3c
child 39 a4891d71aca9
equal deleted inserted replaced
36:791d7a5532e2 37:4fe4a3c4496e
     5  * @file
     5  * @file
     6  *
     6  *
     7  * Flexible command handlers callback lists for use with irc_lines
     7  * Flexible command handlers callback lists for use with irc_lines
     8  */
     8  */
     9 
     9 
    10 #include "irc_conn.h"
       
    11 #include "irc_line.h"
    10 #include "irc_line.h"
    12 #include <sys/queue.h>
    11 #include "chain.h"
    13 
    12 
    14 /**
    13 /**
    15  * Single command -> handler mapping for lookup
    14  * Single command -> handler mapping for lookup
    16  */
    15  */
    17 struct irc_cmd_handler {
    16 struct irc_cmd_handler {
    18     /** The command name to match */
    17     /** The command name to match */
    19     const char *command;
    18     const char *command;
    20 
    19 
    21     /** The handler function */
    20     /** The handler function */
    22     void (*func) (struct irc_conn *conn, const struct irc_line *line, void *arg);
    21     void (*func) (const struct irc_line *line, void *arg);
    23 };
    22 };
    24 
    23 
    25 /**
    24 /**
    26  * List item for a chain of irc_cmd_handler entries, with the context pointer
    25  * @struct irc_cmd_handlers
       
    26  *
       
    27  * A dynamic list of irc_cmd_chain handlers
    27  */
    28  */
    28 struct irc_cmd_chain {
    29 typedef struct chain_list irc_cmd_handlers_t;
    29     /** The list of handler lookup entries */
       
    30     struct irc_cmd_handler *handlers;
       
    31 
    30 
    32     /** Opaque context arg */
    31 /**
    33     void *arg;
    32  * Initialize a irc_cmd_handlers list.
       
    33  */
       
    34 void irc_cmd_init (irc_cmd_handlers_t *handlers);
    34 
    35 
    35     /** Linked list */
    36 /**
    36     STAILQ_ENTRY(irc_cmd_chain) node;
    37  * Add an irc_cmd_chain to the irc_cmd_handlers list for the given handlers/arg
    37 };
    38  */
       
    39 err_t irc_cmd_add (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);
    38 
    40 
    39 /*
    41 /**
    40  * IRC command numerics
    42  * Trigger irc_cmd_chain callbacks for the given irc_line
       
    43  */
       
    44 void irc_cmd_invoke (irc_cmd_handlers_t *handlers, const struct irc_line *line);
       
    45 
       
    46 /**
       
    47  * Cleanup an irc_cmd_handlers list
       
    48  */
       
    49 void irc_cmd_free (irc_cmd_handlers_t *handlers);
       
    50 
       
    51 /**
       
    52  * @group IRC command numerics
       
    53  * @{
       
    54  */
       
    55 
       
    56 /**
       
    57  * 001 <nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>
    41  */
    58  */
    42 #define IRC_RPL_WELCOME         "001"
    59 #define IRC_RPL_WELCOME         "001"
    43 
    60 
       
    61 // @}
    44 
    62 
    45 #endif /* IRC_CMD_H */
    63 #endif /* IRC_CMD_H */