]>
jfr.im git - irc/quakenet/newserv.git/blob - parser/parser.h
3 * Definitions etc. for the common parser engine.
5 * The aim is to use this code for incoming server messages,
6 * and also for any service modules which accept user commands
8 * This is heavily inspired by the ircu code.
14 #include "../lib/sstring.h"
16 /* Maximum allowed command length */
17 /* Not actually used for any static buffers hence fairly large */
19 #define MAX_COMMAND_LEN 100
26 /* Generic CommandHandler type
27 * void * = pointer to some relevant object to identify where the message came from
28 * int = number of parameters
29 * char ** = parameter vector
32 typedef int (*CommandHandler
)(void *, int, char**);
34 typedef struct Command
{
35 sstring
*command
; /* Name of the command/token/thing */
36 char *help
; /* Help information, sorry splidge! */
37 int level
; /* "level" required to use the command/token/thing */
38 int maxparams
; /* Maximum number of parameters for the command/token/thing */
39 CommandHandler handler
; /* Function to deal with the message */
40 void *ext
; /* Pointer to some arbitrary other data */
41 struct Command
*next
; /* Next handler chained onto this command */
44 typedef struct CommandTree
{
47 struct CommandTree
*next
[26];
50 CommandTree
*newcommandtree();
51 void destroycommandtree(CommandTree
*ct
);
52 Command
*addcommandhelptotree(CommandTree
*ct
, const char *cmdname
, int level
, int maxparams
, CommandHandler handler
, const char *help
);
53 int deletecommandfromtree(CommandTree
*ct
, const char *cmdname
, CommandHandler handler
);
54 Command
*findcommandintree(CommandTree
*ct
, const char *cmdname
, int strictcheck
);
55 int getcommandlist(CommandTree
*ct
, Command
**commandlist
, int maxcommands
);
57 #define addcommandtotree(a, b, c, d, e) addcommandhelptotree(a, b, c, d, e, NULL)