Merged from silc_1_0_branch.
[silc.git] / lib / silccore / silccommand.c
index 20b90c66535918c43917306e7d59d03f5109aeef..a16dfc6fce792b6e0c8edfe1ac0d17265120b219 100644 (file)
@@ -1,16 +1,15 @@
 /*
 
-  silccommand.c
+  silccommand.c 
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 1997 - 2001 Pekka Riikonen
+  Copyright (C) 1997 - 2002 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.
-  
+  the Free Software Foundation; version 2 of the License.
+
   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
@@ -76,6 +75,7 @@ SilcCommandPayload silc_command_payload_parse(const unsigned char *payload,
   }
 
   if (newp->cmd == 0) {
+    SILC_LOG_ERROR(("Incorrect command type in command payload"));
     silc_free(newp);
     return NULL;
   }
@@ -111,6 +111,8 @@ SilcBuffer silc_command_payload_encode(SilcCommand cmd,
 
   if (argc) {
     args = silc_argument_payload_encode(argc, argv, argv_lens, argv_types);
+    if (!args)
+      return NULL;
     len = args->len;
   }
 
@@ -154,7 +156,8 @@ SilcBuffer silc_command_payload_encode_payload(SilcCommandPayload payload)
 
   if (payload->args) {
     args = silc_argument_payload_encode_payload(payload->args);
-    len = args->len;
+    if (args)
+      len = args->len;
     argc = silc_argument_get_arg_num(payload->args);
   }
 
@@ -271,8 +274,8 @@ SilcBuffer silc_command_payload_encode_vap(SilcCommand cmd,
 
 SilcBuffer 
 silc_command_reply_payload_encode_va(SilcCommand cmd, 
-                                    SilcCommandStatus status,
-                                    SilcCommandStatus error,
+                                    SilcStatus status,
+                                    SilcStatus error,
                                     SilcUInt16 ident,
                                     SilcUInt32 argc, ...)
 {
@@ -289,8 +292,8 @@ silc_command_reply_payload_encode_va(SilcCommand cmd,
 
 SilcBuffer 
 silc_command_reply_payload_encode_vap(SilcCommand cmd, 
-                                     SilcCommandStatus status,
-                                     SilcCommandStatus error,
+                                     SilcStatus status,
+                                     SilcStatus error,
                                      SilcUInt16 ident, SilcUInt32 argc, 
                                      va_list ap)
 {
@@ -394,8 +397,8 @@ SilcUInt16 silc_command_get_ident(SilcCommandPayload payload)
 /* Return command status */
 
 bool silc_command_get_status(SilcCommandPayload payload, 
-                            SilcCommandStatus *status,
-                            SilcCommandStatus *error)
+                            SilcStatus *status,
+                            SilcStatus *error)
 {
   unsigned char *tmp;
   SilcUInt32 tmp_len;
@@ -409,7 +412,7 @@ bool silc_command_get_status(SilcCommandPayload payload,
   /* Check for 1.0 protocol version which didn't have `error' */
   if (tmp[0] == 0 && tmp[1] != 0) {
     /* Protocol 1.0 version */
-    SilcCommandStatus s;
+    SilcStatus s;
     SILC_GET16_MSB(s, tmp);
     if (status)
       *status = s;
@@ -422,9 +425,9 @@ bool silc_command_get_status(SilcCommandPayload payload,
 
   /* Take both status and possible error */
   if (status)
-    *status = (SilcCommandStatus)tmp[0];
+    *status = (SilcStatus)tmp[0];
   if (error)
-    *error = (SilcCommandStatus)tmp[1];
+    *error = (SilcStatus)tmp[1];
 
   /* If single error occurred have the both `status' and `error' indicate
      the error value for convenience. */