1 /*
2 
3   silcnotify.h
4 
5   Author: Pekka Riikonen <priikone@silcnet.org>
6 
7   Copyright (C) 1997 - 2006 Pekka Riikonen
8 
9   The contents of this file are subject to one of the Licenses specified
10   in the COPYING file;  You may not use this file except in compliance
11   with the License.
12 
13   The software distributed under the License is distributed on an "AS IS"
14   basis, in the hope that it will be useful, but WITHOUT WARRANTY OF ANY
15   KIND, either expressed or implied.  See the COPYING file for more
16   information.
17 
18 */
19 
20 /****h* silccore/SILC Notify Interface
21  *
22  * DESCRIPTION
23  *
24  * Implementation of the Notify Payload. Notify Payload is used usually
25  * by servers to send different kind of important notify messages to other
26  * servers and to clients.
27  *
28  ***/
29 
30 #ifndef SILCNOTIFY_H
31 #define SILCNOTIFY_H
32 
33 /****s* silccore/SilcNotifyAPI/SilcNotifyPayload
34  *
35  * NAME
36  *
37  *    typedef struct SilcNotifyPayloadStruct *SilcNotifyPayload;
38  *
39  * DESCRIPTION
40  *
41  *    This context is the actual Notify Payload and is allocated
42  *    by silc_notify_payload_parse and given as argument usually to
43  *    all silc_notify_payload_* functions.  It is freed by the
44  *    silc_notify_payload_free function.
45  *
46  ***/
47 typedef struct SilcNotifyPayloadStruct *SilcNotifyPayload;
48 
49 /****d* silccore/SilcNotifyAPI/SilcNotifyType
50  *
51  * NAME
52  *
53  *    typedef SilcUInt16 SilcNotifyType;
54  *
55  * DESCRIPTION
56  *
57  *    The notify type definition and all of the notify types.
58  *
59  * SOURCE
60  */
61 typedef SilcUInt16 SilcNotifyType;
62 
63 /* SILC notify types. Server may send these notify types to client to
64    notify of some action. */
65 #define SILC_NOTIFY_TYPE_NONE            0  /* no specific type */
66 #define SILC_NOTIFY_TYPE_INVITE          1  /* invites/invite list change */
67 #define SILC_NOTIFY_TYPE_JOIN            2  /* "has joined channel" */
68 #define SILC_NOTIFY_TYPE_LEAVE           3  /* "has left channel" */
69 #define SILC_NOTIFY_TYPE_SIGNOFF         4  /* "signoff" */
70 #define SILC_NOTIFY_TYPE_TOPIC_SET       5  /* "topic has been changed" */
71 #define SILC_NOTIFY_TYPE_NICK_CHANGE     6  /* "has changed nickname" */
72 #define SILC_NOTIFY_TYPE_CMODE_CHANGE    7  /* "has changed channel mode" */
73 #define SILC_NOTIFY_TYPE_CUMODE_CHANGE   8  /* "has change mode" */
74 #define SILC_NOTIFY_TYPE_MOTD            9  /* message of the day */
75 #define SILC_NOTIFY_TYPE_CHANNEL_CHANGE  10 /* Channel's ID has changed */
76 #define SILC_NOTIFY_TYPE_SERVER_SIGNOFF  11 /* Server quitting SILC */
77 #define SILC_NOTIFY_TYPE_KICKED          12 /* Kicked from channel */
78 #define SILC_NOTIFY_TYPE_KILLED          13 /* Killed from the network */
79 #define SILC_NOTIFY_TYPE_UMODE_CHANGE    14 /* user mode was changed */
80 #define SILC_NOTIFY_TYPE_BAN             15 /* ban list change */
81 #define SILC_NOTIFY_TYPE_ERROR           16 /* error notify */
82 #define SILC_NOTIFY_TYPE_WATCH           17 /* watch notify */
83 /***/
84 
85 /* Prototypes */
86 
87 /****f* silccore/SilcNotifyAPI/silc_notify_payload_parse
88  *
89  * SYNOPSIS
90  *
91  *    SilcNotifyPayload
92  *    silc_notify_payload_parse(const unsigned char *payload,
93  *                              SilcUInt32 payload_len);
94  *
95  * DESCRIPTION
96  *
97  *    Parse notify payload buffer and return data into payload structure.
98  *    The `buffer' is the raw payload data.
99  *
100  ***/
101 SilcNotifyPayload silc_notify_payload_parse(const unsigned char *payload,
102 					    SilcUInt32 payload_len);
103 
104 /****f* silccore/SilcNotifyAPI/silc_notify_payload_encode
105  *
106  * SYNOPSIS
107  *
108  *    SilcBuffer silc_notify_payload_encode(SilcNotifyType type,
109  *                                          SilcUInt32 argc,
110  *                                          va_list ap);
111  *
112  * DESCRIPTION
113  *
114  *    Encode notify payload with variable argument list. If `argc' is > 0
115  *    argument payloads will be associated to the notify payload. Variable
116  *    arguments must be {unsigned char *, SilcUInt32 (len)}.
117  *
118  ***/
119 SilcBuffer silc_notify_payload_encode(SilcNotifyType type, SilcUInt32 argc,
120 				      va_list ap);
121 
122 /****f* silccore/SilcNotifyAPI/silc_notify_payload_encode_args
123  *
124  * SYNOPSIS
125  *
126  *    SilcBuffer silc_notify_payload_encode_args(SilcNotifyType type,
127  *                                               SilcUInt32 argc,
128  *                                               SilcBuffer args);
129  *
130  * DESCRIPTION
131  *
132  *    Same as silc_notify_payload_encode but takes arguments from the `args'
133  *    encoded Argument Payload buffer.
134  *
135  ***/
136 SilcBuffer silc_notify_payload_encode_args(SilcNotifyType type,
137 					   SilcUInt32 argc,
138 					   SilcBuffer args);
139 
140 /****f* silccore/SilcNotifyAPI/silc_notify_payload_free
141  *
142  * SYNOPSIS
143  *
144  *    void silc_notify_payload_free(SilcNotifyPayload payload);
145  *
146  * DESCRIPTION
147  *
148  *    Frees the Notify Payload and all data in it.
149  *
150  ***/
151 void silc_notify_payload_free(SilcNotifyPayload payload);
152 
153 /****f* silccore/SilcNotifyAPI/silc_notify_get_type
154  *
155  * SYNOPSIS
156  *
157  *    SilcNotifyType silc_notify_get_type(SilcNotifyPayload payload);
158  *
159  * DESCRIPTION
160  *
161  *    Return the notify type from the payload.
162  *
163  ***/
164 SilcNotifyType silc_notify_get_type(SilcNotifyPayload payload);
165 
166 /****f* silccore/SilcNotifyAPI/silc_notify_get_arg_num
167  *
168  * SYNOPSIS
169  *
170  *    SilcUInt32 silc_notify_get_arg_num(SilcNotifyPayload payload);
171  *
172  * DESCRIPTION
173  *
174  *    Return the number of the arguments associated with the Notify Payload.
175  *
176  ***/
177 SilcUInt32 silc_notify_get_arg_num(SilcNotifyPayload payload);
178 
179 /****f* silccore/SilcNotifyAPI/silc_notify_get_args
180  *
181  * SYNOPSIS
182  *
183  *    SilcArgumentPayload silc_notify_get_args(SilcNotifyPayload payload);
184  *
185  * DESCRIPTION
186  *
187  *    Return the Argument Payload containing the arguments from the
188  *    Notify Payload. The caller must not free it.
189  *
190  ***/
191 SilcArgumentPayload silc_notify_get_args(SilcNotifyPayload payload);
192 
193 #endif
194