Started implementing protocol version 1.1 and narrowing down
[silc.git] / lib / silccore / silccommand.h
index 32ef4ba59dfaee6a5262690ef664598811a0a21c..4e84bd5b8c158d372419f72575ac4991b75030df 100644 (file)
@@ -1,24 +1,24 @@
-/****h* silccore/silccommand.h
- *
- * NAME
- *
- * silccommand.h
- *
- * COPYRIGHT
- *
- * Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- *
- * Copyright (C) 1997 - 2000 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
  *
  *
  * SYNOPSIS
  *
- *    SilcChannelPayload silc_channel_payload_parse(SilcBuffer buffer);
+ *    typedef void (*SilcCommandCb)(void *context, void *context2);
  *
  * DESCRIPTION
  *
  *    Command function callback. The actual command function pointer.
  *    This is generic command callback that the application may choose to
- *    use with its command routines.
+ *    use with its command routines.  However, none of the generic
+ *    routines depend on this callback so application may freely define
+ *    their own command callback if desired.
  *
  ***/
-typedef void (*SilcCommandCb)(void *context);
+typedef void (*SilcCommandCb)(void *context, void *context2);
 
 /****s* silccore/SilcCommandAPI/SilcCommandPayload
  *
@@ -132,7 +134,6 @@ 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_PING              12
 #define SILC_COMMAND_OPER              13
 #define SILC_COMMAND_JOIN              14
@@ -142,13 +143,16 @@ 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_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
 /***/
@@ -157,7 +161,7 @@ typedef unsigned char SilcCommand;
  *
  * NAME
  * 
- *    typedef uint16 SilcCommandStatus;
+ *    typedef SilcUInt16 SilcCommandStatus;
  *
  * DESCRIPTION
  *
@@ -167,7 +171,7 @@ typedef unsigned char SilcCommand;
  *
  * SOURCE
  */
-typedef uint16 SilcCommandStatus;
+typedef SilcUInt16 SilcCommandStatus;
 
 /* Command Status messages */
 #define SILC_STATUS_OK                      0
@@ -220,7 +224,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
  *
@@ -228,18 +234,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
  *
@@ -247,11 +254,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
  *
@@ -273,31 +280,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
  *
@@ -306,8 +313,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
  *
@@ -316,8 +323,8 @@ SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
  *    SilcBuffer 
  *    silc_command_reply_payload_encode_va(SilcCommand cmd, 
  *                                         SilcCommandStatus status,
- *                                         uint16 ident,
- *                                         uint32 argc, ...);
+ *                                         SilcUInt16 ident,
+ *                                         SilcUInt32 argc, ...);
  *
  * DESCRIPTION
  *
@@ -330,8 +337,30 @@ SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
 SilcBuffer 
 silc_command_reply_payload_encode_va(SilcCommand cmd, 
                                     SilcCommandStatus status,
-                                    uint16 ident,
-                                    uint32 argc, ...);
+                                    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,
+ *                                          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,
+                                     SilcUInt16 ident, SilcUInt32 argc, 
+                                     va_list ap);
 
 /****f* silccore/SilcCommandAPI/silc_command_free
  *
@@ -377,7 +406,7 @@ SilcArgumentPayload silc_command_get_args(SilcCommandPayload payload);
  *
  * SYNOPSIS
  *
- *    uint16 silc_command_get_ident(SilcCommandPayload payload);
+ *    SilcUInt16 silc_command_get_ident(SilcCommandPayload payload);
  *
  * DESCRIPTION
  *
@@ -387,13 +416,28 @@ 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
+ *
+ *    SilcCommandStatus silc_command_get_status(SilcCommandPayload payload);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the SilcCommandStatus from command reply payload's argument 
+ *    payload.  Status can be returned only from command reply payload.
+ *
+ ***/
+SilcCommandStatus silc_command_get_status(SilcCommandPayload payload);
 
 /****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
  *
@@ -402,7 +446,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
  *