Moved silc_client_ch[u]mode[_char] to client library from silc/.
[silc.git] / lib / silcclient / command_reply.h
1 /*
2
3   command_reply.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_REPLY_H
22 #define COMMAND_REPLY_H
23
24 /* Structure holding one command reply and pointer to its function. */
25 typedef struct {
26   SilcCommandCb cb;
27   SilcCommand cmd;
28 } SilcClientCommandReply;
29
30 /* All client command replys */
31 extern SilcClientCommandReply silc_command_reply_list[];
32
33 /* Context sent as argument to all command reply functions */
34 typedef struct {
35   SilcClient client;
36   SilcSocketConnection sock;
37   SilcCommandPayload payload;
38   SilcArgumentPayload args;
39   SilcPacketContext *packet;
40
41   /* If defined this executes the pending command. */
42   void *context;
43   SilcClientCommandCallback callback;
44 } *SilcClientCommandReplyContext;
45
46 /* Macros */
47
48 /* Macro used for command declaration in command reply list structure */
49 #define SILC_CLIENT_CMD_REPLY(func, cmd ) \
50 { silc_client_command_reply_##func, SILC_COMMAND_##cmd }
51
52 /* Macro used to declare command reply functions */
53 #define SILC_CLIENT_CMD_REPLY_FUNC(func) \
54 void silc_client_command_reply_##func(void *context)
55
56 /* Macro used to execute command replies */
57 #define SILC_CLIENT_COMMAND_REPLY_EXEC(ctx)             \
58 do {                                                    \
59   SilcClientCommandReply *cmd;                          \
60                                                         \
61   for (cmd = silc_command_reply_list; cmd->cb; cmd++)   \
62     if (cmd->cmd == silc_command_get(ctx->payload)) {   \
63       cmd->cb(ctx);                                     \
64       break;                                            \
65     }                                                   \
66                                                         \
67   if (cmd == NULL) {                                    \
68     silc_free(ctx);                                     \
69     return;                                             \
70   }                                                     \
71 } while(0)
72
73 /* Prototypes */
74 void silc_client_command_reply_process(SilcClient client,
75                                        SilcSocketConnection sock,
76                                        SilcPacketContext *packet);
77 SILC_CLIENT_CMD_REPLY_FUNC(whois);
78 SILC_CLIENT_CMD_REPLY_FUNC(whowas);
79 SILC_CLIENT_CMD_REPLY_FUNC(identify);
80 SILC_CLIENT_CMD_REPLY_FUNC(nick);
81 SILC_CLIENT_CMD_REPLY_FUNC(list);
82 SILC_CLIENT_CMD_REPLY_FUNC(topic);
83 SILC_CLIENT_CMD_REPLY_FUNC(invite);
84 SILC_CLIENT_CMD_REPLY_FUNC(quit);
85 SILC_CLIENT_CMD_REPLY_FUNC(kill);
86 SILC_CLIENT_CMD_REPLY_FUNC(info);
87 SILC_CLIENT_CMD_REPLY_FUNC(links);
88 SILC_CLIENT_CMD_REPLY_FUNC(stats);
89 SILC_CLIENT_CMD_REPLY_FUNC(users);
90 SILC_CLIENT_CMD_REPLY_FUNC(connect);
91 SILC_CLIENT_CMD_REPLY_FUNC(ping);
92 SILC_CLIENT_CMD_REPLY_FUNC(pong);
93 SILC_CLIENT_CMD_REPLY_FUNC(oper);
94 SILC_CLIENT_CMD_REPLY_FUNC(join);
95 SILC_CLIENT_CMD_REPLY_FUNC(motd);
96 SILC_CLIENT_CMD_REPLY_FUNC(umode);
97 SILC_CLIENT_CMD_REPLY_FUNC(cmode);
98 SILC_CLIENT_CMD_REPLY_FUNC(cumode);
99 SILC_CLIENT_CMD_REPLY_FUNC(kick);
100 SILC_CLIENT_CMD_REPLY_FUNC(restart);
101 SILC_CLIENT_CMD_REPLY_FUNC(close);
102 SILC_CLIENT_CMD_REPLY_FUNC(die);
103 SILC_CLIENT_CMD_REPLY_FUNC(silcoper);
104 SILC_CLIENT_CMD_REPLY_FUNC(leave);
105 SILC_CLIENT_CMD_REPLY_FUNC(names);
106
107 #endif