src/irc_cmd.h
author Tero Marttila <terom@fixme.fi>
Thu, 12 Mar 2009 18:11:44 +0200
changeset 37 4fe4a3c4496e
parent 23 542c73d07d3c
child 39 a4891d71aca9
permissions -rw-r--r--
change irc_chan.state into bool fields, move irc_cmd implementation from irc_conn.c into irc_cmd.c, remove irc_conn arg from irc_cmd_handler, add irc_conn.nickname tracking, and handle irc_chan JOINs
#ifndef IRC_CMD_H
#define IRC_CMD_H

/**
 * @file
 *
 * Flexible command handlers callback lists for use with irc_lines
 */

#include "irc_line.h"
#include "chain.h"

/**
 * Single command -> handler mapping for lookup
 */
struct irc_cmd_handler {
    /** The command name to match */
    const char *command;

    /** The handler function */
    void (*func) (const struct irc_line *line, void *arg);
};

/**
 * @struct irc_cmd_handlers
 *
 * A dynamic list of irc_cmd_chain handlers
 */
typedef struct chain_list irc_cmd_handlers_t;

/**
 * Initialize a irc_cmd_handlers list.
 */
void irc_cmd_init (irc_cmd_handlers_t *handlers);

/**
 * Add an irc_cmd_chain to the irc_cmd_handlers list for the given handlers/arg
 */
err_t irc_cmd_add (irc_cmd_handlers_t *handlers, const struct irc_cmd_handler *list, void *arg);

/**
 * Trigger irc_cmd_chain callbacks for the given irc_line
 */
void irc_cmd_invoke (irc_cmd_handlers_t *handlers, const struct irc_line *line);

/**
 * Cleanup an irc_cmd_handlers list
 */
void irc_cmd_free (irc_cmd_handlers_t *handlers);

/**
 * @group IRC command numerics
 * @{
 */

/**
 * 001 <nick> :Welcome to the Internet Relay Network <nick>!<user>@<host>
 */
#define IRC_RPL_WELCOME         "001"

// @}

#endif /* IRC_CMD_H */