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