updates.
[silc.git] / lib / silcclient / command_reply.h
1 /*
2
3   command_reply.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2001 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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef COMMAND_REPLY_H
21 #define COMMAND_REPLY_H
22
23 /* Structure holding one command reply and pointer to its function. */
24 typedef struct {
25   SilcCommandCb cb;
26   SilcCommand cmd;
27 } SilcClientCommandReply;
28
29 /* Context holding pending command callbacks. */
30 typedef struct {
31   SilcCommandCb callback;
32   void *context;
33 } *SilcClientCommandPendingCallbacks;
34
35 /* Context sent as argument to all command reply functions */
36 struct SilcClientCommandReplyContextStruct {
37   SilcClient client;
38   SilcSocketConnection sock;
39   SilcCommandPayload payload;
40   SilcCommandStatus status;
41   SilcCommandStatus error;
42   SilcArgumentPayload args;
43   SilcPacketContext *packet;
44
45   /* If defined this executes the pending command. */
46   SilcClientCommandPendingCallbacks callbacks;
47   SilcUInt32 callbacks_count;
48   SilcUInt16 ident;
49 };
50
51 /* Macros */
52
53 /* Command reply operation that is called at the end of all command replys. 
54    Usage: COMMAND_REPLY((ARGS, argument1, argument2, etc...)), */
55 #define COMMAND_REPLY(args) cmd->client->internal->ops->command_reply args
56 #define ARGS cmd->client, cmd->sock->user_data,                         \
57              cmd->payload, TRUE, silc_command_get(cmd->payload), cmd->status
58
59 /* Error reply to application. Usage: COMMAND_REPLY_ERROR; */
60 #define COMMAND_REPLY_ERROR cmd->client->internal->ops->                \
61   command_reply(cmd->client, cmd->sock->user_data, cmd->payload,        \
62   FALSE, silc_command_get(cmd->payload), cmd->status)
63
64 /* Macro used to declare command reply functions */
65 #define SILC_CLIENT_CMD_REPLY_FUNC(func)                                \
66 void silc_client_command_reply_##func(void *context, void *context2)
67
68 /* Status message structure. Messages are defined below. */
69 typedef struct {
70   SilcCommandStatus status;
71   char *message;
72 } SilcCommandStatusMessage;
73
74 /* Status messages returned by the server */
75 #define STAT(x) SILC_STATUS_ERR_##x
76 DLLAPI extern const SilcCommandStatusMessage silc_command_status_messages[];
77
78 /* Prototypes */
79
80 void silc_client_command_reply_process(SilcClient client,
81                                        SilcSocketConnection sock,
82                                        SilcPacketContext *packet);
83 char *silc_client_command_status_message(SilcCommandStatus status);
84 void silc_client_command_reply_free(SilcClientCommandReplyContext cmd);
85 SILC_CLIENT_CMD_REPLY_FUNC(whois);
86 SILC_CLIENT_CMD_REPLY_FUNC(whowas);
87 SILC_CLIENT_CMD_REPLY_FUNC(identify);
88 SILC_CLIENT_CMD_REPLY_FUNC(nick);
89 SILC_CLIENT_CMD_REPLY_FUNC(list);
90 SILC_CLIENT_CMD_REPLY_FUNC(topic);
91 SILC_CLIENT_CMD_REPLY_FUNC(invite);
92 SILC_CLIENT_CMD_REPLY_FUNC(kill);
93 SILC_CLIENT_CMD_REPLY_FUNC(info);
94 SILC_CLIENT_CMD_REPLY_FUNC(stats);
95 SILC_CLIENT_CMD_REPLY_FUNC(ping);
96 SILC_CLIENT_CMD_REPLY_FUNC(oper);
97 SILC_CLIENT_CMD_REPLY_FUNC(join);
98 SILC_CLIENT_CMD_REPLY_FUNC(motd);
99 SILC_CLIENT_CMD_REPLY_FUNC(umode);
100 SILC_CLIENT_CMD_REPLY_FUNC(cmode);
101 SILC_CLIENT_CMD_REPLY_FUNC(cumode);
102 SILC_CLIENT_CMD_REPLY_FUNC(kick);
103 SILC_CLIENT_CMD_REPLY_FUNC(ban);
104 SILC_CLIENT_CMD_REPLY_FUNC(detach);
105 SILC_CLIENT_CMD_REPLY_FUNC(silcoper);
106 SILC_CLIENT_CMD_REPLY_FUNC(leave);
107 SILC_CLIENT_CMD_REPLY_FUNC(users);
108 SILC_CLIENT_CMD_REPLY_FUNC(getkey);
109 SILC_CLIENT_CMD_REPLY_FUNC(quit);
110
111 /* Internal command reply functions */
112 SILC_CLIENT_CMD_REPLY_FUNC(whois_i);
113 SILC_CLIENT_CMD_REPLY_FUNC(identify_i);
114 SILC_CLIENT_CMD_REPLY_FUNC(info_i);
115 SILC_CLIENT_CMD_REPLY_FUNC(users_i);
116
117 SILC_CLIENT_CMD_REPLY_FUNC(connect);
118 SILC_CLIENT_CMD_REPLY_FUNC(close);
119 SILC_CLIENT_CMD_REPLY_FUNC(shutdown);
120
121 #endif