]> jfr.im git - irc/quakenet/newserv.git/blob - parser/parser.h
Initial Import
[irc/quakenet/newserv.git] / parser / parser.h
1 /*
2 * parser.h
3 * Definitions etc. for the common parser engine.
4 *
5 * The aim is to use this code for incoming server messages,
6 * and also for any service modules which accept user commands
7 *
8 * This is heavily inspired by the ircu code.
9 */
10
11 #ifndef __PARSER_H
12 #define __PARSER_H
13
14 #include "../lib/sstring.h"
15
16 /* Maximum allowed command length */
17 /* Not actually used for any static buffers hence fairly large */
18
19 #define MAX_COMMAND_LEN 100
20
21 #define CMD_OK 0
22 #define CMD_ERROR 1
23 #define CMD_LAST 2
24
25 /* Generic CommandHandler type
26 * void * = pointer to some relevant object to identify where the message came from
27 * int = number of parameters
28 * char ** = parameter vector
29 */
30
31 typedef int (*CommandHandler)(void *, int, char**);
32
33 typedef struct Command {
34 sstring *command; /* Name of the command/token/thing */
35 int level; /* "level" required to use the command/token/thing */
36 int maxparams; /* Maximum number of parameters for the command/token/thing */
37 CommandHandler handler; /* Function to deal with the message */
38 void *ext; /* Pointer to some arbitrary other data */
39 struct Command *next; /* Next handler chained onto this command */
40 } Command;
41
42 typedef struct CommandTree {
43 Command *cmd;
44 char *final;
45 struct CommandTree *next[26];
46 } CommandTree;
47
48 CommandTree *newcommandtree();
49 void destroycommandtree(CommandTree *ct);
50 Command *addcommandtotree(CommandTree *ct, const char *cmdname, int level, int maxparams, CommandHandler handler);
51 int deletecommandfromtree(CommandTree *ct, const char *cmdname, CommandHandler handler);
52 Command *findcommandintree(CommandTree *ct, const char *cmdname, int strictcheck);
53 int getcommandlist(CommandTree *ct, Command **commandlist, int maxcommands);
54
55 #endif