Added SILC Thread Queue API
[crypto.git] / lib / silcclient / client_ops_example.c
index e35a56e6bd80fbdb265a57107ce0169700a23871..a14ebfb00ddbf84a951af5701f170624118e1cb3 100644 (file)
@@ -5,49 +5,41 @@
 
    At the end of this file SilcClientOperation structure is defined, and
    it is the one the you will give as an argument to the silc_client_alloc
-   function. See also lib/silcclient/README file, and silcclient.h. */
+   function. See also lib/silcclient/README file, and silcclient.h.
+
+   You may freely use this file in your application. */
 
 
 /* Message sent to the application by library. `conn' associates the
-   message to a specific connection.  `conn', however, may be NULL. 
+   message to a specific connection.  `conn', however, may be NULL.
    The `type' indicates the type of the message sent by the library.
-   The applicationi can for example filter the message according the
-   type. */
-
-static void 
-silc_say(SilcClient client, SilcClientConnection conn, 
-        SilcClientMessageType type, char *msg, ...)
-{
-
-}
-
+   The application can for example filter the message according the
+   type.  The variable argument list is arguments to the formatted
+   message that `msg' may be. */
+void silc_say(SilcClient client, SilcClientConnection conn,
+             SilcClientMessageType type, char *msg, ...);
 
 /* Message for a channel. The `sender' is the sender of the message
-   The `channel' is the channel. The `msg' is the message.  Note that  
-   `msg' maybe NULL. */
-
-static void 
-silc_channel_message(SilcClient client, SilcClientConnection conn, 
-                    SilcClientEntry sender, SilcChannelEntry channel, 
-                    SilcMessageFlags flags, const unsigned char *message,
-                    SilcUInt32 message_len);
-{
-
-}
-
+   The `channel' is the channel. The `message' is the message.  Note
+   that `message' maybe NULL.  The `flags' indicates message flags
+   and it is used to determine how the message can be interpreted
+   (like it may tell the message is multimedia message). */
+void silc_channel_message(SilcClient client, SilcClientConnection conn,
+                         SilcClientEntry sender, SilcChannelEntry channel,
+                         SilcMessagePayload payload,
+                         SilcChannelPrivateKey key, SilcMessageFlags flags,
+                         const unsigned char *message,
+                         SilcUInt32 message_len);
 
 /* Private message to the client. The `sender' is the sender of the
-   message. */
-
-static void 
-silc_private_message(SilcClient client, SilcClientConnection conn, 
-                    SilcClientEntry sender, SilcMessageFlags flags, 
-                    const unsigned char *message,
-                    SilcUInt32 message_len);
-{
-
-}
-
+   message. The message is `message'and maybe NULL.  The `flags'
+   indicates message flags  and it is used to determine how the message
+   can be interpreted (like it may tell the message is multimedia
+   message). */
+void silc_private_message(SilcClient client, SilcClientConnection conn,
+                         SilcClientEntry sender, SilcMessagePayload payload,
+                         SilcMessageFlags flags, const unsigned char *message,
+                         SilcUInt32 message_len);
 
 /* Notify message to the client. The notify arguments are sent in the
    same order as servers sends them. The arguments are same as received
@@ -57,39 +49,28 @@ silc_private_message(SilcClient client, SilcClientConnection conn,
    for channel the channel entry is sent to application (even if server
    does not send it because client library gets the channel entry from
    the Channel ID in the packet's header). */
-
-static void 
-silc_notify(SilcClient client, SilcClientConnection conn, 
-           SilcNotifyType type, ...)
-{
-
-}
-
-
-/* Command handler. This function is called always in the command function.
-   If error occurs it will be called as well. `conn' is the associated
-   client connection. `cmd_context' is the command context that was
-   originally sent to the command. `success' is FALSE if error occurred
-   during command. `command' is the command being processed. It must be
-   noted that this is not reply from server. This is merely called just
-   after application has called the command. Just to tell application
-   that the command really was processed. */
-
-static void 
-silc_command(SilcClient client, SilcClientConnection conn, 
-            SilcClientCommandContext cmd_context, int success, 
-            SilcCommand command)
-{
-
-}
-
+void silc_notify(SilcClient client, SilcClientConnection conn,
+                SilcNotifyType type, ...);
+
+/* Command handler. This function is called always after application has
+   called a command.  It will be called to indicate that the command
+   was processed.  It will also be called if error occurs while processing
+   the command.  The `success' indicates whether the command was sent
+   or if error occurred.  The `status' indicates the actual error.
+   The `argc' and `argv' are the command line arguments sent to the
+   command by application.  Note that, this is not reply to the command
+   from server, this is merely and indication to application that the
+   command was processed. */
+void silc_command(SilcClient client, SilcClientConnection conn,
+                 SilcBool success, SilcCommand command, SilcStatus status,
+                 SilcUInt32 argc, unsigned char **argv);
 
 /* Command reply handler. This function is called always in the command reply
    function. If error occurs it will be called as well. Normal scenario
    is that it will be called after the received command data has been parsed
    and processed. The function is used to pass the received command data to
-   the application. 
-   
+   the application.
+
    `conn' is the associated client connection. `cmd_payload' is the command
    payload data received from server and it can be ignored. It is provided
    if the application would like to re-parse the received command data,
@@ -99,115 +80,63 @@ silc_command(SilcClient client, SilcClientConnection conn,
    the command reply status server returned. The `command' is the command
    reply being processed. The function has variable argument list and each
    command defines the number and type of arguments it passes to the
-   application (on error they are not sent). */
-
-static void 
-silc_command_reply(SilcClient client, SilcClientConnection conn, 
-                  SilcCommandPayload cmd_payload, int success, 
-                  SilcCommand command, SilcCommandStatus status, ...)
-{
-
-}
-
-
-/* Called to indicate that connection was either successfully established
-   or connecting failed.  This is also the first time application receives
-   the SilcClientConnection objecet which it should save somewhere.
-   If the `success' is FALSE the application must always call the function
-   silc_client_close_connection. */
-
-static void 
-silc_connect(SilcClient client, SilcClientConnection conn, int success)
-{
-
-}
+   application (on error they are not sent).
 
+   The arguments are sent in the same order as servers sends them.  The
+   arguments are same as received from the server except for ID's.  If
+   ID is received application receives the corresponding entry to the
+   ID. For example, if Client ID is receives application receives
+   SilcClientEntry.
 
-/* Called to indicate that connection was disconnected to the server. */
-
-static void 
-silc_disconnect(SilcClient client, SilcClientConnection conn)
-{
-
-}
-
+   See: http://silcnet.org/docs/toolkit/command_reply_args.html */
+void silc_command_reply(SilcClient client, SilcClientConnection conn,
+                       SilcCommand command, SilcStatus status,
+                       SilcStatus error, va_list ap);
 
 /* Find authentication method and authentication data by hostname and
-   port. The hostname may be IP address as well. When the authentication
-   method has been resolved the `completion' callback with the found
-   authentication method and authentication data is called. The `conn'
-   may be NULL. */
-
-static void 
-silc_get_auth_method(SilcClient client, SilcClientConnection conn, 
-                    char *hostname, SilcUInt16 port, SilcGetAuthMeth completion, 
-                    void *context)
-{
-
-}
-
+   port. The hostname may be IP address as well. The `auth_method' is
+   the authentication method the remote connection requires.  It is
+   however possible that remote accepts also some other authentication
+   method.  Application should use the method that may have been
+   configured for this connection.  If none has been configured it should
+   use the required `auth_method'.  If the `auth_method' is
+   SILC_AUTH_NONE, server does not require any authentication or the
+   required authentication method is not known.  The `completion'
+   callback must be called to deliver the chosen authentication method
+   and data. The `conn' may be NULL. */
+void silc_get_auth_method(SilcClient client, SilcClientConnection conn,
+                         char *hostname, SilcUInt16 port,
+                         SilcAuthMethod auth_method,
+                         SilcGetAuthMeth completion, void *context);
 
 /* Verifies received public key. The `conn_type' indicates which entity
-   (server, client etc.) has sent the public key. If user decides to trust
-   the key may be saved as trusted public key for later use. The 
-   `completion' must be called after the public key has been verified. */
-
-static void 
-silc_verify_public_key(SilcClient client, SilcClientConnection conn, 
-                      SilcSocketType conn_type, unsigned char *pk, 
-                      SilcUInt32 pk_len, SilcSKEPKType pk_type, 
-                      SilcVerifyPublicKey completion, void *context)
-{
-
-}
-
+   (server or client) has sent the public key. If user decides to trust
+   the key the application may save the key as trusted public key for
+   later use. The `completion' must be called after the public key has
+   been verified. */
+void silc_verify_public_key(SilcClient client, SilcClientConnection conn,
+                           SilcConnectionType conn_type,
+                           SilcPublicKey public_key,
+                           SilcVerifyPublicKey completion, void *context);
 
 /* Ask (interact, that is) a passphrase from user. The passphrase is
    returned to the library by calling the `completion' callback with
    the `context'. The returned passphrase SHOULD be in UTF-8 encoded,
    if not then the library will attempt to encode. */
-
-static void 
-silc_ask_passphrase(SilcClient client, SilcClientConnection conn, 
-                   SilcAskPassphrase completion, void *context)
-{
-
-}
-
-
-/* Notifies application that failure packet was received.  This is called
-   if there is some protocol active in the client.  The `protocol' is the
-   protocol context.  The `failure' is opaque pointer to the failure
-   indication.  Note, that the `failure' is protocol dependant and
-   application must explicitly cast it to correct type.  Usually `failure'
-   is 32 bit failure type (see protocol specs for all protocol failure
-   types). */
-
-static void 
-silc_failure(SilcClient client, SilcClientConnection conn, 
-            SilcProtocol protocol, void *failure)
-{
-
-}
-
-
-/* Asks whether the user would like to perform the key agreement protocol.
-   This is called after we have received an key agreement packet or an
-   reply to our key agreement packet. This returns TRUE if the user wants
-   the library to perform the key agreement protocol and FALSE if it is not
-   desired (application may start it later by calling the function
-   silc_client_perform_key_agreement). If TRUE is returned also the
-   `completion' and `context' arguments must be set by the application. */
-
-static int 
-silc_key_agreement(SilcClient client, SilcClientConnection conn, 
-                  SilcClientEntry client_entry, const char *hostname, 
-                  SilcUInt16 port, SilcKeyAgreementCallback *completion, 
-                  void **context)
-{
-
-}
-
+void silc_ask_passphrase(SilcClient client, SilcClientConnection conn,
+                        SilcAskPassphrase completion, void *context);
+
+/* Called to indicate that incoming key agreement request has been
+   received.  If the application wants to perform key agreement it may
+   call silc_client_perform_key_agreement to initiate key agreementn or
+   silc_client_send_key_agreement to provide connection point to the
+   remote client in case the `hostname' is NULL.  If key agreement is
+   not desired this request can be ignored.  The `protocol' is either
+   value 0 for TCP or value 1 for UDP. */
+void silc_key_agreement(SilcClient client, SilcClientConnection conn,
+                       SilcClientEntry client_entry,
+                       const char *hostname, SilcUInt16 protocol,
+                       SilcUInt16 port);
 
 /* Notifies application that file transfer protocol session is being
    requested by the remote client indicated by the `client_entry' from
@@ -215,15 +144,9 @@ silc_key_agreement(SilcClient client, SilcClientConnection conn,
    session and it can be used to either accept or reject the file
    transfer request, by calling the silc_client_file_receive or
    silc_client_file_close, respectively. */
-
-static void 
-silc_ftp(SilcClient client, SilcClientConnection conn, 
-        SilcClientEntry client_entry, SilcUInt32 session_id, 
-        const char *hostname, SilcUInt16 port)
-{
-
-}
-
+void silc_ftp(SilcClient client, SilcClientConnection conn,
+             SilcClientEntry client_entry, SilcUInt32 session_id,
+             const char *hostname, SilcUInt16 port);
 
 /* The SilcClientOperation structure containing the operation functions.
    You will give this as an argument to silc_client_alloc function. */
@@ -234,12 +157,9 @@ SilcClientOperations ops = {
   silc_notify,
   silc_command,
   silc_command_reply,
-  silc_connect,
-  silc_disconnect,
   silc_get_auth_method,
   silc_verify_public_key,
   silc_ask_passphrase,
-  silc_failure,
   silc_key_agreement,
   silc_ftp
 };