Splitted SILC core library. Core library includes now only
authorPekka Riikonen <priikone@silcnet.org>
Wed, 13 Sep 2000 17:45:15 +0000 (17:45 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 13 Sep 2000 17:45:15 +0000 (17:45 +0000)
SILC protocol specific stuff. New utility library includes the
old stuff from core library that is more generic purpose stuff.

24 files changed:
lib/silccore/Makefile.am
lib/silccore/silccommand.h
lib/silccore/silcprotocol.h
lib/silcutil/Makefile.am [new file with mode: 0644]
lib/silcutil/silcbuffer.c [moved from lib/silccore/silcbuffer.c with 96% similarity]
lib/silcutil/silcbuffer.h [moved from lib/silccore/silcbuffer.h with 100% similarity]
lib/silcutil/silcbuffmt.c [moved from lib/silccore/silcbuffmt.c with 97% similarity]
lib/silcutil/silcbuffmt.h [moved from lib/silccore/silcbuffmt.h with 100% similarity]
lib/silcutil/silcbufutil.c [moved from lib/silccore/silcbufutil.c with 92% similarity]
lib/silcutil/silcbufutil.h [moved from lib/silccore/silcbufutil.h with 100% similarity]
lib/silcutil/silcconfig.c [moved from lib/silccore/silcconfig.c with 90% similarity]
lib/silcutil/silcconfig.h [moved from lib/silccore/silcconfig.h with 100% similarity]
lib/silcutil/silclog.c [moved from lib/silccore/silclog.c with 69% similarity]
lib/silcutil/silclog.h [moved from lib/silccore/silclog.h with 82% similarity]
lib/silcutil/silcmemory.c [moved from lib/silccore/silcmemory.c with 86% similarity]
lib/silcutil/silcmemory.h [moved from lib/silccore/silcmemory.h with 100% similarity]
lib/silcutil/silcnet.c [moved from lib/silccore/silcnet.c with 96% similarity]
lib/silcutil/silcnet.h [moved from lib/silccore/silcnet.h with 100% similarity]
lib/silcutil/silcschedule.c [moved from lib/silccore/silcschedule.c with 94% similarity]
lib/silcutil/silcschedule.h [moved from lib/silccore/silcschedule.h with 97% similarity]
lib/silcutil/silctask.c [moved from lib/silccore/silctask.c with 98% similarity]
lib/silcutil/silctask.h [moved from lib/silccore/silctask.h with 100% similarity]
lib/silcutil/silcutil.c [moved from lib/silccore/silcutil.c with 75% similarity]
lib/silcutil/silcutil.h [moved from lib/silccore/silcutil.h with 81% similarity]

index d4321eac8a4551a61236b1b5fe79578c9ba85813..62ed6aef58e61f66004a7694391efc23cc1d17d4 100644 (file)
@@ -23,24 +23,14 @@ noinst_LIBRARIES = libsilccore.a
 libsilccore_a_SOURCES = \
        id.c \
        idcache.c \
-       silcbuffer.c \
-       silcbuffmt.c \
-       silcbufutil.c \
        silcchannel.c \
        silccommand.c \
-       silcconfig.c \
-       silclog.c \
-       silcmemory.c \
-       silcnet.c \
        silcpacket.c \
        silcprotocol.c \
-       silcschedule.c \
-       silcsockconn.c \
-       silctask.c \
-       silcutil.c
+       silcsockconn.c
 
 EXTRA_DIST = *.h
 
 INCLUDES = -I. -I.. -I../silccrypt -I../silcmath -I../silcske \
-       -I../silcsim -I../.. -I../../includes \
+       -I../silcsim -I../.. -I../silcutil -I../../includes \
        -I../silcmath/gmp
index 155027d6195351bbda6d36a248c3a4d5aa4015e6..709115563c3b31d2064a327ae1405eddc24ed394 100644 (file)
@@ -80,16 +80,6 @@ typedef enum {
 #define SILC_COMMAND_LEAVE             23
 #define SILC_COMMAND_NAMES             24
 
-/* Local commands. Local commands are unofficial commands and
-   are implementation specific commands. These are used only by the
-   SILC client to extend user commands. */
-#define SILC_COMMAND_HELP              100
-#define SILC_COMMAND_CLEAR             101
-#define SILC_COMMAND_VERSION           102
-#define SILC_COMMAND_SERVER             103
-#define SILC_COMMAND_MSG               104
-#define SILC_COMMAND_AWAY              105
-
 /* Reserved */
 #define SILC_COMMAND_RESERVED           255
 
index fd564fcbcd7d8db99941278bf1d8bb5441a5bdd7..620ca85b7027ce4fe253f259e7a72e2350f19434 100644 (file)
@@ -39,6 +39,9 @@ typedef unsigned char SilcProtocolState;
 #define SILC_PROTOCOL_CONN_AUTH_PASSWORD 1
 #define SILC_PROTOCOL_CONN_AUTH_PUBLIC_KEY 2
 
+/* Type definition for above auth methods */
+typedef unsigned char SilcProtocolAuthMeth;
+
 /* 
    SILC Protocol Object.
 
diff --git a/lib/silcutil/Makefile.am b/lib/silcutil/Makefile.am
new file mode 100644 (file)
index 0000000..fc02b27
--- /dev/null
@@ -0,0 +1,39 @@
+#
+#  Makefile.am
+#
+#  Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
+#
+#  Copyright (C) 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.
+#
+
+AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign
+
+noinst_LIBRARIES = libsilcutil.a
+
+libsilcutil_a_SOURCES = \
+       silcbuffer.c \
+       silcbuffmt.c \
+       silcbufutil.c \
+       silcconfig.c \
+       silclog.c \
+       silcmemory.c \
+       silcnet.c \
+       silcschedule.c \
+       silctask.c \
+       silcutil.c
+
+EXTRA_DIST = *.h
+
+INCLUDES = -I. -I.. -I../silccrypt -I../silcmath -I../silcske \
+       -I../silcsim -I../.. -I../silccore -I../../includes \
+       -I../silcmath/gmp
similarity index 96%
rename from lib/silccore/silcbuffer.c
rename to lib/silcutil/silcbuffer.c
index fc2b6b4037a3cf1c67c37f4837c2ebbe26adff0a..ccaf1f572e7abb704b86d60d29aafc6d72e065d5 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:15  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.2  2000/07/05 06:06:35  priikone
  *     Global cosmetic change.
  *
similarity index 97%
rename from lib/silccore/silcbuffmt.c
rename to lib/silcutil/silcbuffmt.c
index 95fe728811f22ee928d2d39ebf1ef03b040002c1..3399ccb14f4828ad77dba7ac34c3b37d4020694d 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.2  2000/07/05 06:06:35  priikone
  *     Global cosmetic change.
  *
similarity index 92%
rename from lib/silccore/silcbufutil.c
rename to lib/silcutil/silcbufutil.c
index 7599868baeea4234906d7cefc0acde91c26da1b4..2c89a17cbdaec61ec44d12901f234c9b79bcc888 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.3  2000/07/14 06:08:49  priikone
  *     Added silc_buffer_realloc. Fixed silc_buffer_clone.
  *
similarity index 90%
rename from lib/silccore/silcconfig.c
rename to lib/silcutil/silcconfig.c
index 59fefec7e485f116436549f8f6b7de8020d1532f..1cb27bf4f78b9045a53b55ce1aa1634bb151b4dd 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.2  2000/07/05 06:06:35  priikone
  *     Global cosmetic change.
  *
similarity index 69%
rename from lib/silccore/silclog.c
rename to lib/silcutil/silclog.c
index b1ad9186d332d234f0a89ff21c2558415496da89..24f3ddcee748dabba4de0fbc190fdcd09de08bd5 100644 (file)
   GNU General Public License for more details.
 
 */
-/*
- * $Id$
- * $Log$
- * Revision 1.5  2000/07/17 16:46:37  priikone
- *     Still bug fix in silc_log_format :)
- *
- * Revision 1.4  2000/07/17 16:44:57  priikone
- *     Buffer overflow bug fixe in silc_log_format.
- *
- * Revision 1.3  2000/07/05 06:06:35  priikone
- *     Global cosmetic change.
- *
- * Revision 1.2  2000/07/03 05:53:58  priikone
- *     Fixed file purging bug.  The purging should work now ok.
- *
- * Revision 1.1.1.1  2000/06/27 11:36:55  priikone
- *     Imported from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
 
 #include "silcincludes.h"
 
+/* Set TRUE/FALSE to enable/disable debugging */
+int silc_debug;
+
 /* SILC Log name strings. These strings are printed to the log file. */
 const SilcLogTypeName silc_log_types[] =
 {
@@ -60,6 +44,17 @@ unsigned int log_warning_size;
 unsigned int log_error_size;
 unsigned int log_fatal_size;
 
+/* Log callbacks. If these are set by the application these are used
+   instead of the default functions in this file. */
+static SilcLogCb info_cb = NULL;
+static SilcLogCb warning_cb = NULL;
+static SilcLogCb error_cb = NULL;
+static SilcLogCb fatal_cb = NULL;
+
+/* Debug callbacks. If set these are used instead of default ones. */
+static SilcDebugCb debug_cb = NULL;
+static SilcDebugHexdumpCb debug_hexdump_cb = NULL;
+
 /* Formats arguments to a string and returns it after allocating memory
    for it. It must be remembered to free it later. */
 
@@ -84,6 +79,38 @@ void silc_log_output(const char *filename, unsigned int maxsize,
   FILE *fp;
   const SilcLogTypeName *np;
 
+  switch(type)
+    {
+    case SILC_LOG_INFO:
+      if (info_cb) {
+       (*info_cb)(string);
+       silc_free(string);
+       return;
+      }
+      break;
+    case SILC_LOG_WARNING:
+      if (warning_cb) {
+       (*warning_cb)(string);
+       silc_free(string);
+       return;
+      }
+      break;
+    case SILC_LOG_ERROR:
+      if (error_cb) {
+       (*error_cb)(string);
+       silc_free(string);
+       return;
+      }
+      break;
+    case SILC_LOG_FATAL:
+      if (fatal_cb) {
+       (*fatal_cb)(string);
+       silc_free(string);
+       return;
+      }
+      break;
+    }
+
   /* Purge the log file if the max size is defined. */
   if (maxsize) {
     fp = fopen(filename, "r");
@@ -124,6 +151,18 @@ void silc_log_output(const char *filename, unsigned int maxsize,
 void silc_log_output_debug(char *file, char *function, 
                           int line, char *string)
 {
+  if (!silc_debug) {
+    silc_free(string);
+    return;
+  }
+
+  if (debug_cb)
+    {
+      (*debug_cb)(file, function, line, string);
+      silc_free(string);
+      return;
+    }
+
   /* fprintf(stderr, "%s:%s:%d: %s\n", file, function, line, string); */
   fprintf(stderr, "%s:%d: %s\n", function, line, string);
   fflush(stderr);
@@ -140,6 +179,18 @@ void silc_log_output_hexdump(char *file, char *function,
   int off, pos, count;
   unsigned char *data = (unsigned char *)data_in;
 
+  if (!silc_debug) {
+    silc_free(string);
+    return;
+  }
+
+  if (debug_hexdump_cb)
+    {
+      (*debug_hexdump_cb)(file, function, line, data_in, len, string);
+      silc_free(string);
+      return;
+    }
+
   /* fprintf(stderr, "%s:%s:%d: %s\n", file, function, line, string); */
   fprintf(stderr, "%s:%d: %s\n", function, line, string);
   silc_free(string);
@@ -218,3 +269,38 @@ void silc_log_set_files(char *info, unsigned int info_size,
   log_error_size = error_size;
   log_fatal_size = fatal_size;
 }
+
+/* Sets log callbacks */
+
+void silc_log_set_callbacks(SilcLogCb info, SilcLogCb warning,
+                           SilcLogCb error, SilcLogCb fatal)
+{
+  info_cb = info;
+  warning_cb = warning;
+  error_cb = error;
+  fatal_cb = fatal;
+}
+
+/* Resets log callbacks */
+
+void silc_log_reset_callbacks()
+{
+  info_cb = warning_cb = error_cb = fatal_cb = NULL;
+}
+
+/* Sets debug callbacks */
+
+void silc_log_set_debug_callbacks(SilcDebugCb debug, 
+                                 SilcDebugHexdumpCb debug_hexdump)
+{
+  debug_cb = debug;
+  debug_hexdump_cb = debug_hexdump;
+}
+
+/* Resets debug callbacks */
+
+void silc_log_reset_debug_callbacks()
+{
+  debug_cb = NULL;
+  debug_hexdump_cb = NULL;
+}
similarity index 82%
rename from lib/silccore/silclog.h
rename to lib/silcutil/silclog.h
index a98e4af44fa62c6a04b3daf2f9aca6a32f933a84..cd34639f3d1fc994cd0c45ad54b3e11ec7361b5a 100644 (file)
@@ -21,6 +21,9 @@
 #ifndef SILCLOG_H
 #define SILCLOG_H
 
+/* Set TRUE/FALSE to enable/disable debugging */
+extern int silc_debug;
+
 /* SILC Log types */
 typedef enum {
   SILC_LOG_INFO,
@@ -35,6 +38,18 @@ typedef struct {
   SilcLogType type;
 } SilcLogTypeName;
 
+/* Log function callback. */
+typedef void (*SilcLogCb)(char *message);
+
+/* Debug function callback. */
+typedef void (*SilcDebugCb)(char *file, char *function, 
+                           int line, char *message);
+
+/* Debug hexdump function callback. */
+typedef void (*SilcDebugHexdumpCb)(char *file, char *function, 
+                                  int line, unsigned char *data,
+                                  unsigned int data_len, char *message);
+
 /* Default log filenames */
 #define SILC_LOG_FILE_INFO "silcd.log"
 #define SILC_LOG_FILE_WARNING "silcd_error.log"
@@ -100,5 +115,11 @@ void silc_log_set_files(char *info, unsigned int info_size,
                        char *warning, unsigned int warning_size,
                        char *error, unsigned int error_size,
                         char *fatal, unsigned int fatal_size);
+void silc_log_set_callbacks(SilcLogCb info, SilcLogCb warning,
+                           SilcLogCb error, SilcLogCb fatal);
+void silc_log_reset_callbacks();
+void silc_log_set_debug_callbacks(SilcDebugCb debug, 
+                                 SilcDebugHexdumpCb debug_hexdump);
+void silc_log_reset_debug_callbacks();
 
 #endif
similarity index 86%
rename from lib/silccore/silcmemory.c
rename to lib/silcutil/silcmemory.c
index 9a922bf913bf4d638ce0d7cca4544983134f509c..e5ebae567a4d0767611fb80239735f5545a02472 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.2  2000/07/05 06:05:56  priikone
  *     Assert if system is out of memory.
  *
similarity index 96%
rename from lib/silccore/silcnet.c
rename to lib/silcutil/silcnet.c
index 989020f7190d36ad69cd073a94edf257c47394ac..68a820f6316ec79b5fdb6dc95dc31a817f849b5f 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.3  2000/07/05 06:06:35  priikone
  *     Global cosmetic change.
  *
similarity index 94%
rename from lib/silccore/silcschedule.c
rename to lib/silcutil/silcschedule.c
index 5236e78985f197a8b085629f395fe78453f60d55..0cbf333e21ae98267f2a58f6f32ea94fe479af9b 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.3  2000/07/18 06:51:58  priikone
  *     Debug version bug fixes.
  *
@@ -41,20 +46,32 @@ static SilcSchedule schedule;
    the timeout task queue hook. This must be called before the schedule
    is able to work. */
 
-void silc_schedule_init(SilcTaskQueue fd_queue,
-                       SilcTaskQueue timeout_queue,
-                       SilcTaskQueue generic_queue,
+void silc_schedule_init(SilcTaskQueue *fd_queue,
+                       SilcTaskQueue *timeout_queue,
+                       SilcTaskQueue *generic_queue,
                        int max_fd)
 {
   int i;
 
   SILC_LOG_DEBUG(("Initializing scheduler"));
 
+  /* Register the task queues if they are not registered already. In SILC
+     we have by default three task queues. One task queue for non-timeout
+     tasks which perform different kind of I/O on file descriptors, timeout
+     task queue for timeout tasks, and, generic non-timeout task queue whose
+     tasks apply to all connections. */
+  if (!*fd_queue)
+    silc_task_queue_alloc(fd_queue, TRUE);
+  if (!*timeout_queue)
+    silc_task_queue_alloc(timeout_queue, TRUE);
+  if (!*generic_queue)
+    silc_task_queue_alloc(generic_queue, TRUE);
+
   /* Initialize the schedule */
   memset(&schedule, 0, sizeof(schedule));
-  schedule.fd_queue = fd_queue;
-  schedule.timeout_queue = timeout_queue;
-  schedule.generic_queue = generic_queue;
+  schedule.fd_queue = *fd_queue;
+  schedule.timeout_queue = *timeout_queue;
+  schedule.generic_queue = *generic_queue;
   schedule.fd_list.fd = silc_calloc(max_fd, sizeof(int));
   schedule.fd_list.last_fd = 0;
   schedule.fd_list.max_fd = max_fd;
similarity index 97%
rename from lib/silccore/silcschedule.h
rename to lib/silcutil/silcschedule.h
index 87af2d1e377876ef674f2ef259632aed10246375..19c384684e35f8c52b0f53f210b9a33794e98a5f 100644 (file)
@@ -110,9 +110,9 @@ typedef struct {
 typedef SilcScheduleObject SilcSchedule;
 
 /* Prototypes */
-void silc_schedule_init(SilcTaskQueue fd_queue,
-                       SilcTaskQueue timeout_queue,
-                       SilcTaskQueue generic_queue,
+void silc_schedule_init(SilcTaskQueue *fd_queue,
+                       SilcTaskQueue *timeout_queue,
+                       SilcTaskQueue *generic_queue,
                        int max_fd);
 int silc_schedule_uninit();
 void silc_schedule_stop();
similarity index 98%
rename from lib/silccore/silctask.c
rename to lib/silcutil/silctask.c
index cc177dc15a862c3a4b133648594558451db08ee2..1bf8388f9ffb45ef4f26127f8dc5725adff8603c 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.2  2000/07/05 06:06:35  priikone
  *     Global cosmetic change.
  *
similarity index 75%
rename from lib/silccore/silcutil.c
rename to lib/silcutil/silcutil.c
index 3a0b77ece7535a59d59850c59d5b3ae3bee1644d..39b9ab1ad92eb7a79c5f297f8a70324833a9fad4 100644 (file)
 /*
  * $Id$
  * $Log$
+ * Revision 1.1  2000/09/13 17:45:16  priikone
+ *     Splitted SILC core library. Core library includes now only
+ *     SILC protocol specific stuff. New utility library includes the
+ *     old stuff from core library that is more generic purpose stuff.
+ *
  * Revision 1.4  2000/07/19 07:04:04  priikone
  *     Minor bug fix in silc_encode_pem
  *
@@ -433,3 +438,112 @@ unsigned char *silc_decode_pem(unsigned char *pem, unsigned int pem_len,
 
   return data;
 }
+
+/* Parse nickname string. The format may be <num>!<nickname>@<server> to
+   support multiple same nicknames. The <num> is the final unifier if same
+   nickname is on same server. Note, this is only local format and server
+   does not know anything about these. */
+
+int silc_parse_nickname(char *string, char **nickname, char **server,
+                       unsigned int *num)
+{
+  unsigned int tlen;
+  char tmp[256];
+
+  if (!string)
+    return FALSE;
+
+  if (strchr(string, '!')) {
+    tlen = strcspn(string, "!");
+    memset(tmp, 0, sizeof(tmp));
+    memcpy(tmp, string, tlen);
+
+    if (num)
+      *num = atoi(tmp);
+
+    if (tlen >= strlen(string))
+      return FALSE;
+
+    string += tlen + 1;
+  }
+
+  if (strchr(string, '@')) {
+    tlen = strcspn(string, "@");
+    
+    if (nickname) {
+      *nickname = silc_calloc(tlen + 1, sizeof(char));
+      memcpy(*nickname, string, tlen);
+    }
+    
+    if (server) {
+      *server = silc_calloc(strlen(string) - tlen, sizeof(char));
+      memcpy(*server, string + tlen + 1, strlen(string) - tlen - 1);
+    }
+  } else {
+    if (nickname)
+      *nickname = strdup(string);
+  }
+
+  return TRUE;
+}
+
+/* Parses command line. At most `max_args' is taken. Rest of the line
+   will be allocated as the last argument if there are more than `max_args'
+   arguments in the line. Note that the command name is counted as one
+   argument and is saved. */
+
+void silc_parse_command_line(unsigned char *buffer, 
+                            unsigned char ***parsed,
+                            unsigned int **parsed_lens,
+                            unsigned int **parsed_types,
+                            unsigned int *parsed_num,
+                            unsigned int max_args)
+{
+  int i, len = 0;
+  int argc = 0;
+  const char *cp = buffer;
+
+  *parsed = silc_calloc(1, sizeof(**parsed));
+  *parsed_lens = silc_calloc(1, sizeof(**parsed_lens));
+
+  /* Get the command first */
+  len = strcspn(cp, " ");
+  (*parsed)[0] = silc_to_upper((char *)cp);
+  (*parsed_lens)[0] = len;
+  cp += len + 1;
+  argc++;
+
+  /* Parse arguments */
+  if (strchr(cp, ' ') || strlen(cp) != 0) {
+    for (i = 1; i < max_args; i++) {
+
+      if (i != max_args - 1)
+       len = strcspn(cp, " ");
+      else
+       len = strlen(cp);
+      
+      *parsed = silc_realloc(*parsed, sizeof(**parsed) * (argc + 1));
+      *parsed_lens = silc_realloc(*parsed_lens, 
+                                 sizeof(**parsed_lens) * (argc + 1));
+      (*parsed)[argc] = silc_calloc(len + 1, sizeof(char));
+      memcpy((*parsed)[argc], cp, len);
+      (*parsed_lens)[argc] = len;
+      argc++;
+
+      cp += len;
+      if (strlen(cp) == 0)
+       break;
+      else
+       cp++;
+    }
+  }
+
+  /* Save argument types. Protocol defines all argument types but
+     this implementation makes sure that they are always in correct
+     order hence this simple code. */
+  *parsed_types = silc_calloc(argc, sizeof(**parsed_types));
+  for (i = 0; i < argc; i++)
+    (*parsed_types)[i] = i;
+
+  *parsed_num = argc;
+}
similarity index 81%
rename from lib/silccore/silcutil.h
rename to lib/silcutil/silcutil.h
index 7607df737a22eea6884146c33391013882ddd41d..e9c011b3f0f2429039d3da59ebfa987d2c54bc68 100644 (file)
@@ -35,5 +35,13 @@ char *silc_encode_pem(unsigned char *data, unsigned int len);
 char *silc_encode_pem_file(unsigned char *data, unsigned int data_len);
 unsigned char *silc_decode_pem(unsigned char *pem, unsigned int pem_len,
                               unsigned int *ret_len);
+int silc_parse_nickname(char *string, char **nickname, char **server,
+                       unsigned int *num);
+void silc_parse_command_line(unsigned char *buffer, 
+                            unsigned char ***parsed,
+                            unsigned int **parsed_lens,
+                            unsigned int **parsed_types,
+                            unsigned int *parsed_num,
+                            unsigned int max_args);
 
 #endif