Updates.
[silc.git] / apps / silcd / command.h
1 /*
2
3   servercommand.h
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 1997 - 2000 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; either version 2 of the License, or
12   (at your option) any later version.
13   
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License for more details.
18
19 */
20
21 #ifndef COMMAND_H
22 #define COMMAND_H
23
24 #include "command_reply.h"
25
26 /* 
27    Structure holding one command and pointer to its function. 
28
29    SilcCommandCb cb
30
31        Callback function called when this command is executed.
32
33    SilcCommand cmd
34
35        The actual command. Defined in silccore/silccommand.h
36
37    SilcCommandFlag flags
38
39        Flags for the command. These set how command behaves on different
40        situations. 
41
42 */
43 typedef struct {
44   SilcCommandCb cb;
45   SilcCommand cmd;
46   SilcCommandFlag flags;
47 } SilcServerCommand;
48
49 /* All server commands */
50 extern SilcServerCommand silc_command_list[];
51
52 /* Context sent as argument to all commands */
53 typedef struct {
54   SilcServer server;
55   SilcSocketConnection sock;
56   SilcCommandPayload payload;
57   SilcArgumentPayload args;
58   SilcPacketContext *packet;
59   int pending;                  /* Command is being re-processed when TRUE */
60 } *SilcServerCommandContext;
61
62 /* Structure holding pending commands. If command is pending it will be
63    executed after command reply has been received and executed. */
64 typedef struct SilcServerCommandPendingStruct {
65   SilcServer server;
66   SilcCommand reply_cmd;
67   SilcCommandCb callback;
68   void *context;
69   unsigned short ident;
70   struct SilcServerCommandPendingStruct *next;
71 } SilcServerCommandPending;
72
73 /* Macros */
74
75 /* Macro used for command declaration in command list structure */
76 #define SILC_SERVER_CMD(func, cmd, flags) \
77 { silc_server_command_##func, SILC_COMMAND_##cmd, flags }
78
79 /* Macro used to declare command functions */
80 #define SILC_SERVER_CMD_FUNC(func) \
81 void silc_server_command_##func(void *context)
82
83 /* Executed pending command */
84 #define SILC_SERVER_COMMAND_EXEC_PENDING(ctx, cmd)                      \
85 do {                                                                    \
86   if (ctx->callback) {                                                  \
87     (*ctx->callback)(ctx->context);                                     \
88     silc_server_command_pending_del(ctx->server, cmd, ctx->ident);      \
89   }                                                                     \
90 } while(0)
91
92 /* Prototypes */
93 void silc_server_command_process(SilcServer server,
94                                  SilcSocketConnection sock,
95                                  SilcPacketContext *packet);
96 void silc_server_command_pending(SilcServer server,
97                                  SilcCommand reply_cmd,
98                                  unsigned short ident,
99                                  SilcCommandCb callback,
100                                  void *context);
101 void silc_server_command_pending_del(SilcServer server,
102                                      SilcCommand reply_cmd,
103                                      unsigned short ident);
104 int silc_server_command_pending_check(SilcServer server,
105                                       SilcServerCommandReplyContext ctx,
106                                       SilcCommand command, 
107                                       unsigned short ident);
108 SILC_SERVER_CMD_FUNC(whois);
109 SILC_SERVER_CMD_FUNC(whowas);
110 SILC_SERVER_CMD_FUNC(identify);
111 SILC_SERVER_CMD_FUNC(newuser);
112 SILC_SERVER_CMD_FUNC(nick);
113 SILC_SERVER_CMD_FUNC(list);
114 SILC_SERVER_CMD_FUNC(topic);
115 SILC_SERVER_CMD_FUNC(invite);
116 SILC_SERVER_CMD_FUNC(quit);
117 SILC_SERVER_CMD_FUNC(kill);
118 SILC_SERVER_CMD_FUNC(info);
119 SILC_SERVER_CMD_FUNC(connect);
120 SILC_SERVER_CMD_FUNC(ping);
121 SILC_SERVER_CMD_FUNC(oper);
122 SILC_SERVER_CMD_FUNC(pass);
123 SILC_SERVER_CMD_FUNC(admin);
124 SILC_SERVER_CMD_FUNC(join);
125 SILC_SERVER_CMD_FUNC(motd);
126 SILC_SERVER_CMD_FUNC(umode);
127 SILC_SERVER_CMD_FUNC(cmode);
128 SILC_SERVER_CMD_FUNC(cumode);
129 SILC_SERVER_CMD_FUNC(kick);
130 SILC_SERVER_CMD_FUNC(ignore);
131 SILC_SERVER_CMD_FUNC(restart);
132 SILC_SERVER_CMD_FUNC(close);
133 SILC_SERVER_CMD_FUNC(die);
134 SILC_SERVER_CMD_FUNC(silcoper);
135 SILC_SERVER_CMD_FUNC(leave);
136 SILC_SERVER_CMD_FUNC(users);
137
138 #endif