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