Merged silc_1_0_branch to trunk.
[silc.git] / lib / silcclient / client_ops_example.c
1 /* Predefined stub functions for the SilcClientOperation callbacks.
2    You can freely use this template in your application. These are
3    the functions that you as an application programmer need to implement
4    for the library.  The library may call these functions at any time.
5
6    At the end of this file SilcClientOperation structure is defined, and
7    it is the one the you will give as an argument to the silc_client_alloc
8    function. See also lib/silcclient/README file, and silcclient.h. */
9
10
11 /* Message sent to the application by library. `conn' associates the
12    message to a specific connection.  `conn', however, may be NULL.
13    The `type' indicates the type of the message sent by the library.
14    The application can for example filter the message according the
15    type. */
16
17 static void
18 silc_say(SilcClient client, SilcClientConnection conn,
19          SilcClientMessageType type, char *msg, ...)
20 {
21
22 }
23
24
25 /* Message for a channel. The `sender' is the sender of the message
26    The `channel' is the channel. The `message' is the message.  Note
27    that `message' maybe NULL.  The `flags' indicates message flags
28    and it is used to determine how the message can be interpreted
29    (like it may tell the message is multimedia message). */
30
31 static void
32 silc_channel_message(SilcClient client, SilcClientConnection conn,
33                      SilcClientEntry sender, SilcChannelEntry channel,
34                      SilcMessagePayload payload, SilcChannelPrivateKey key,
35                      SilcMessageFlags flags, const unsigned char *message,
36                      SilcUInt32 message_len)
37 {
38
39 }
40
41
42 /* Private message to the client. The `sender' is the sender of the
43    message. The message is `message'and maybe NULL.  The `flags'
44    indicates message flags  and it is used to determine how the message
45    can be interpreted (like it may tell the message is multimedia
46    message). */
47
48 static void
49 silc_private_message(SilcClient client, SilcClientConnection conn,
50                      SilcClientEntry sender, SilcMessagePayload payload,
51                      SilcMessageFlags flags, const unsigned char *message,
52                      SilcUInt32 message_len)
53 {
54
55 }
56
57
58 /* Notify message to the client. The notify arguments are sent in the
59    same order as servers sends them. The arguments are same as received
60    from the server except for ID's.  If ID is received application receives
61    the corresponding entry to the ID. For example, if Client ID is received
62    application receives SilcClientEntry.  Also, if the notify type is
63    for channel the channel entry is sent to application (even if server
64    does not send it because client library gets the channel entry from
65    the Channel ID in the packet's header). */
66
67 static void
68 silc_notify(SilcClient client, SilcClientConnection conn,
69             SilcNotifyType type, ...)
70 {
71
72 }
73
74
75 /* Command handler. This function is called always in the command function.
76    If error occurs it will be called as well. `conn' is the associated
77    client connection. `cmd_context' is the command context that was
78    originally sent to the command. `success' is FALSE if error occurred
79    during command. `command' is the command being processed. It must be
80    noted that this is not reply from server. This is merely called just
81    after application has called the command. Just to tell application
82    that the command really was processed. */
83
84 static void
85 silc_command(SilcClient client, SilcClientConnection conn,
86              SilcClientCommandContext cmd_context, bool success,
87              SilcCommand command, SilcStatus status)
88 {
89
90 }
91
92
93 /* Command reply handler. This function is called always in the command reply
94    function. If error occurs it will be called as well. Normal scenario
95    is that it will be called after the received command data has been parsed
96    and processed. The function is used to pass the received command data to
97    the application.
98
99    `conn' is the associated client connection. `cmd_payload' is the command
100    payload data received from server and it can be ignored. It is provided
101    if the application would like to re-parse the received command data,
102    however, it must be noted that the data is parsed already by the library
103    thus the payload can be ignored. `success' is FALSE if error occurred.
104    In this case arguments are not sent to the application. The `status' is
105    the command reply status server returned. The `command' is the command
106    reply being processed. The function has variable argument list and each
107    command defines the number and type of arguments it passes to the
108    application (on error they are not sent). */
109
110 static void
111 silc_command_reply(SilcClient client, SilcClientConnection conn,
112                    SilcCommandPayload cmd_payload, bool success,
113                    SilcCommand command, SilcStatus status, ...)
114 {
115
116 }
117
118
119 /* Called to indicate that connection was either successfully established
120    or connecting failed.  This is also the first time application receives
121    the SilcClientConnection objecet which it should save somewhere.
122    If the `success' is FALSE the application must always call the function
123    silc_client_close_connection. */
124
125 static void
126 silc_connected(SilcClient client, SilcClientConnection conn,
127                SilcClientConnectionStatus status)
128 {
129
130 }
131
132
133 /* Called to indicate that connection was disconnected to the server.
134    The `status' may tell the reason of the disconnection, and if the
135    `message' is non-NULL it may include the disconnection message
136    received from server. */
137
138 static void
139 silc_disconnected(SilcClient client, SilcClientConnection conn,
140                   SilcStatus status, const char *message)
141 {
142
143 }
144
145
146 /* Find authentication method and authentication data by hostname and
147    port. The hostname may be IP address as well. When the authentication
148    method has been resolved the `completion' callback with the found
149    authentication method and authentication data is called. The `conn'
150    may be NULL. */
151
152 static void
153 silc_get_auth_method(SilcClient client, SilcClientConnection conn,
154                      char *hostname, SilcUInt16 port, SilcGetAuthMeth completion,
155                      void *context)
156 {
157
158 }
159
160
161 /* Verifies received public key. The `conn_type' indicates which entity
162    (server, client etc.) has sent the public key. If user decides to trust
163    the application may save the key as trusted public key for later
164    use. The `completion' must be called after the public key has been
165    verified. */
166
167 static void
168 silc_verify_public_key(SilcClient client, SilcClientConnection conn,
169                        SilcSocketType conn_type, unsigned char *pk,
170                        SilcUInt32 pk_len, SilcSKEPKType pk_type,
171                        SilcVerifyPublicKey completion, void *context)
172 {
173
174 }
175
176
177 /* Ask (interact, that is) a passphrase from user. The passphrase is
178    returned to the library by calling the `completion' callback with
179    the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
180    if not then the library will attempt to encode. */
181
182 static void
183 silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
184                     SilcAskPassphrase completion, void *context)
185 {
186
187 }
188
189
190 /* Notifies application that failure packet was received.  This is called
191    if there is some protocol active in the client.  The `protocol' is the
192    protocol context.  The `failure' is opaque pointer to the failure
193    indication.  Note, that the `failure' is protocol dependant and
194    application must explicitly cast it to correct type.  Usually `failure'
195    is 32 bit failure type (see protocol specs for all protocol failure
196    types). */
197
198 static void
199 silc_failure(SilcClient client, SilcClientConnection conn,
200              SilcProtocol protocol, void *failure)
201 {
202
203 }
204
205
206 /* Asks whether the user would like to perform the key agreement protocol.
207    This is called after we have received an key agreement packet or an
208    reply to our key agreement packet. This returns TRUE if the user wants
209    the library to perform the key agreement protocol and FALSE if it is not
210    desired (application may start it later by calling the function
211    silc_client_perform_key_agreement). If TRUE is returned also the
212    `completion' and `context' arguments must be set by the application. */
213
214 static bool
215 silc_key_agreement(SilcClient client, SilcClientConnection conn,
216                    SilcClientEntry client_entry, const char *hostname,
217                    SilcUInt16 port, SilcKeyAgreementCallback *completion,
218                    void **context)
219 {
220
221 }
222
223
224 /* Notifies application that file transfer protocol session is being
225    requested by the remote client indicated by the `client_entry' from
226    the `hostname' and `port'. The `session_id' is the file transfer
227    session and it can be used to either accept or reject the file
228    transfer request, by calling the silc_client_file_receive or
229    silc_client_file_close, respectively. */
230
231 static void
232 silc_ftp(SilcClient client, SilcClientConnection conn,
233          SilcClientEntry client_entry, SilcUInt32 session_id,
234          const char *hostname, SilcUInt16 port)
235 {
236
237 }
238
239
240 /* Delivers SILC session detachment data indicated by `detach_data' to the
241    application.  If application has issued SILC_COMMAND_DETACH command
242    the client session in the SILC network is not quit.  The client remains
243    in the network but is detached.  The detachment data may be used later
244    to resume the session in the SILC Network.  The appliation is
245    responsible of saving the `detach_data', to for example in a file.
246
247    The detachment data can be given as argument to the functions
248    silc_client_connect_to_server, or silc_client_add_connection when
249    creating connection to remote server, inside SilcClientConnectionParams
250    structure.  If it is provided the client library will attempt to resume
251    the session in the network.  After the connection is created
252    successfully, the application is responsible of setting the user
253    interface for user into the same state it was before detaching (showing
254    same channels, channel modes, etc).  It can do this by fetching the
255    information (like joined channels) from the client library. */
256
257 static void
258 silc_detach(SilcClient client, SilcClientConnection conn,
259             const unsigned char *detach_data, SilcUInt32 detach_data_len)
260 {
261
262 }
263
264
265 /* The SilcClientOperation structure containing the operation functions.
266    You will give this as an argument to silc_client_alloc function. */
267 SilcClientOperations ops = {
268   silc_say,
269   silc_channel_message,
270   silc_private_message,
271   silc_notify,
272   silc_command,
273   silc_command_reply,
274   silc_connected,
275   silc_disconnected,
276   silc_get_auth_method,
277   silc_verify_public_key,
278   silc_ask_passphrase,
279   silc_failure,
280   silc_key_agreement,
281   silc_ftp,
282   silc_detach
283 };