updates.
[silc.git] / lib / silccore / silccommand.h
index c298d76237ce22803d99ac286da112f4af6eb010..531f1935aa114e9c66b939c02db1d810fad226a9 100644 (file)
@@ -1,24 +1,24 @@
-/****h* silccore/silccommand.h
- *
- * NAME
- *
- * silccommand.h
- *
- * COPYRIGHT
- *
- * Author: Pekka Riikonen <priikone@silcnet.org>
- *
- * Copyright (C) 1997 - 2001 Pekka Riikonen
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+/*
+  silccommand.h
+  Author: Pekka Riikonen <priikone@silcnet.org>
+  Copyright (C) 1997 - 2001 Pekka Riikonen
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+*/
+
+/****h* silccore/SILC Command Interface
  *
  * DESCRIPTION
  *
@@ -134,7 +134,7 @@ typedef unsigned char SilcCommand;
 #define SILC_COMMAND_QUIT              8
 #define SILC_COMMAND_KILL              9
 #define SILC_COMMAND_INFO              10
-#define SILC_COMMAND_CONNECT           11
+#define SILC_COMMAND_STATS             11
 #define SILC_COMMAND_PING              12
 #define SILC_COMMAND_OPER              13
 #define SILC_COMMAND_JOIN              14
@@ -144,13 +144,17 @@ typedef unsigned char SilcCommand;
 #define SILC_COMMAND_CUMODE            18
 #define SILC_COMMAND_KICK              19
 #define SILC_COMMAND_BAN               20
-#define        SILC_COMMAND_CLOSE              21
-#define        SILC_COMMAND_SHUTDOWN           22
+#define SILC_COMMAND_DETACH            21
 #define SILC_COMMAND_SILCOPER          23
 #define SILC_COMMAND_LEAVE             24
 #define SILC_COMMAND_USERS             25
 #define SILC_COMMAND_GETKEY            26
 
+/* Private range start */
+#define SILC_COMMAND_PRIV_CONNECT       200
+#define SILC_COMMAND_PRIV_CLOSE         201
+#define SILC_COMMAND_PRIV_SHUTDOWN      202
+
 /* Reserved */
 #define SILC_COMMAND_RESERVED           255
 /***/
@@ -159,7 +163,7 @@ typedef unsigned char SilcCommand;
  *
  * NAME
  * 
- *    typedef uint16 SilcCommandStatus;
+ *    typedef SilcUInt8 SilcCommandStatus;
  *
  * DESCRIPTION
  *
@@ -169,7 +173,7 @@ typedef unsigned char SilcCommand;
  *
  * SOURCE
  */
-typedef uint16 SilcCommandStatus;
+typedef SilcUInt8 SilcCommandStatus;
 
 /* Command Status messages */
 #define SILC_STATUS_OK                      0
@@ -222,7 +226,9 @@ typedef uint16 SilcCommandStatus;
  *
  * SYNOPSIS
  *
- *    SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer);
+ *    SilcCommandPayload 
+ *    silc_command_payload_parse(const unsigned char *payload,
+ *                               SilcUInt32 payload_len);
  *
  * DESCRIPTION
  *
@@ -230,18 +236,19 @@ typedef uint16 SilcCommandStatus;
  *    `buffer' is the raw payload.
  *
  ***/
-SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer);
+SilcCommandPayload silc_command_payload_parse(const unsigned char *payload,
+                                             SilcUInt32 payload_len);
 
 /****f* silccore/SilcCommandAPI/silc_command_payload_encode
  *
  * SYNOPSIS
  *
  *    SilcBuffer silc_command_payload_encode(SilcCommand cmd,
- *                                           uint32 argc,
+ *                                           SilcUInt32 argc,
  *                                           unsigned char **argv,
- *                                           uint32 *argv_lens,
- *                                           uint32 *argv_types,
- *                                           uint16 ident);
+ *                                           SilcUInt32 *argv_lens,
+ *                                           SilcUInt32 *argv_types,
+ *                                           SilcUInt16 ident);
  *
  * DESCRIPTION
  *
@@ -249,11 +256,11 @@ SilcCommandPayload silc_command_payload_parse(SilcBuffer buffer);
  *
  ***/
 SilcBuffer silc_command_payload_encode(SilcCommand cmd,
-                                      uint32 argc,
+                                      SilcUInt32 argc,
                                       unsigned char **argv,
-                                      uint32 *argv_lens,
-                                      uint32 *argv_types,
-                                      uint16 ident);
+                                      SilcUInt32 *argv_lens,
+                                      SilcUInt32 *argv_types,
+                                      SilcUInt16 ident);
 
 /****f* silccore/SilcCommandAPI/silc_command_payload_encode_payload
  *
@@ -275,31 +282,31 @@ SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload);
  * SYNOPSIS
  *
  *    SilcBuffer silc_command_payload_encode_va(SilcCommand cmd, 
- *                                              uint16 ident, 
- *                                              uint32 argc, ...);
+ *                                              SilcUInt16 ident, 
+ *                                              SilcUInt32 argc, ...);
  *
  * DESCRIPTION
  *
  *    Encodes Command payload with variable argument list. The arguments
- *    must be: uint32, unsigned char *, unsigned int, ... One 
- *    {uint32, unsigned char * and unsigned int} forms one argument, 
- *    thus `argc' in case when sending one {uint32, unsigned char * 
- *    and uint32} equals one (1) and when sending two of those it
+ *    must be: SilcUInt32, unsigned char *, unsigned int, ... One 
+ *    {SilcUInt32, unsigned char * and unsigned int} forms one argument, 
+ *    thus `argc' in case when sending one {SilcUInt32, unsigned char * 
+ *    and SilcUInt32} equals one (1) and when sending two of those it
  *    equals two (2), and so on. This has to be preserved or bad things
  *    will happen. The variable arguments is: {type, data, data_len}.
  *
  ***/
 SilcBuffer silc_command_payload_encode_va(SilcCommand cmd, 
-                                         uint16 ident, 
-                                         uint32 argc, ...);
+                                         SilcUInt16 ident, 
+                                         SilcUInt32 argc, ...);
 
 /****f* silccore/SilcCommandAPI/silc_command_payload_encode_vap
  *
  * SYNOPSIS
  *
  *    SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, 
- *                                               uint16 ident, 
- *                                               uint32 argc, va_list ap);
+ *                                               SilcUInt16 ident, 
+ *                                               SilcUInt32 argc, va_list ap);
  *
  * DESCRIPTION
  *
@@ -308,8 +315,8 @@ SilcBuffer silc_command_payload_encode_va(SilcCommand cmd,
  *
  ***/
 SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd, 
-                                          uint16 ident, 
-                                          uint32 argc, va_list ap);
+                                          SilcUInt16 ident, 
+                                          SilcUInt32 argc, va_list ap);
 
 /****f* silccore/SilcCommandAPI/silc_command_reply_payload_encode_va
  *
@@ -318,22 +325,61 @@ SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
  *    SilcBuffer 
  *    silc_command_reply_payload_encode_va(SilcCommand cmd, 
  *                                         SilcCommandStatus status,
- *                                         uint16 ident,
- *                                         uint32 argc, ...);
+ *                                         SilcCommandStatus error,
+ *                                         SilcUInt16 ident,
+ *                                         SilcUInt32 argc, ...);
  *
  * DESCRIPTION
  *
  *    Same as silc_command_payload_encode_va except that this is used to 
- *    encode strictly command reply packets. The command status message
- *    to be returned is sent as extra argument to this function. The `argc'
- *    must not count `status' as on argument.
+ *    encode strictly command reply packets.  The `argc' must not count 
+ *    `status' and `error' as arguments.  The `status' includes the
+ *    command reply status.  If single reply will be sent then it includes
+ *    SILC_STATUS_OK if error did not occur.  It includes an error value
+ *    if error did occur.  In this case `error' field is ignored.  If
+ *    there will be multiple successful command replies then the `status'
+ *    includes a list value and `error' is ignored.  If there will
+ *    multiple error replies the `status' includes a list value, and
+ *    the `error' includes an error value.  Thus, the `error' value is
+ *    specified only if there will be list of errors.
+ *
+ * NOTES
+ *
+ *    Protocol defines that it is possible to send both list of successful
+ *    and list of error replies at the same time, as long as the error
+ *    replies are sent after the successful replies.
  *
  ***/
 SilcBuffer 
 silc_command_reply_payload_encode_va(SilcCommand cmd, 
                                     SilcCommandStatus status,
-                                    uint16 ident,
-                                    uint32 argc, ...);
+                                    SilcCommandStatus error,
+                                    SilcUInt16 ident,
+                                    SilcUInt32 argc, ...);
+
+/****f* silccore/SilcCommandAPI/silc_command_reply_payload_encode_vap
+ *
+ * SYNOPSIS
+ *
+ *    SilcBuffer 
+ *    silc_command_reply_payload_encode_vap(SilcCommand cmd, 
+ *                                          SilcCommandStatus status,
+ *                                          SilcCommandStatus error,
+ *                                          SilcUInt16 ident, SilcUInt32 argc,
+ *                                          va_list ap);
+ *
+ * DESCRIPTION
+ *
+ *    This is equivalent to the silc_command_reply_payload_encode_va except
+ *    takes the va_list as argument.
+ *
+ ***/
+SilcBuffer 
+silc_command_reply_payload_encode_vap(SilcCommand cmd, 
+                                     SilcCommandStatus status,
+                                     SilcCommandStatus error,
+                                     SilcUInt16 ident, SilcUInt32 argc, 
+                                     va_list ap);
 
 /****f* silccore/SilcCommandAPI/silc_command_free
  *
@@ -379,7 +425,7 @@ SilcArgumentPayload silc_command_get_args(SilcCommandPayload payload);
  *
  * SYNOPSIS
  *
- *    uint16 silc_command_get_ident(SilcCommandPayload payload);
+ *    SilcUInt16 silc_command_get_ident(SilcCommandPayload payload);
  *
  * DESCRIPTION
  *
@@ -389,13 +435,36 @@ SilcArgumentPayload silc_command_get_args(SilcCommandPayload payload);
  *    the same identifier in the command reply.
  *
  ***/
-uint16 silc_command_get_ident(SilcCommandPayload payload);
+SilcUInt16 silc_command_get_ident(SilcCommandPayload payload);
+
+/****f* silccore/SilcCommandAPI/silc_command_get_status
+ *
+ * SYNOPSIS
+ *
+ *    bool silc_command_get_status(SilcCommandPayload payload, 
+ *                                 SilcCommandStatus *status,
+ *                                 SilcCommandStatus *error);
+ *
+ * DESCRIPTION
+ *
+ *    This function returns the command reply status into `status' and
+ *    error status, if error occurred into the `error'.  The function
+ *    returns TRUE if command reply status is not error, and FALSE if
+ *    error occurred.  In this case the `error' will include the actual
+ *    error status.  The `status' can be in this case some list value
+ *    which indicates that there will be list of errors.
+ *
+ ***/
+bool silc_command_get_status(SilcCommandPayload payload, 
+                            SilcCommandStatus *status,
+                            SilcCommandStatus *error);
 
 /****f* silccore/SilcCommandAPI/silc_command_set_ident
  *
  * SYNOPSIS
  *
- *    void silc_command_set_ident(SilcCommandPayload payload, uint16 ident);
+ *    void silc_command_set_ident(SilcCommandPayload payload, 
+ *                                SilcUInt16 ident);
  *
  * DESCRIPTION
  *
@@ -404,7 +473,7 @@ uint16 silc_command_get_ident(SilcCommandPayload payload);
  *    to set the identifier without encoding new Command Payload. 
  *
  ***/
-void silc_command_set_ident(SilcCommandPayload payload, uint16 ident);
+void silc_command_set_ident(SilcCommandPayload payload, SilcUInt16 ident);
 
 /****f* silccore/SilcCommandAPI/silc_command_set_command
  *