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
#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
#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.
--- /dev/null
+#
+# 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
/*
* $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.
*
/*
* $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.
*
/*
* $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.
*
/*
* $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.
*
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[] =
{
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. */
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");
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);
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);
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;
+}
#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,
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"
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
/*
* $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.
*
/*
* $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.
*
/*
* $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.
*
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;
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();
/*
* $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.
*
/*
* $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
*
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;
+}
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