Added new SILC_STATUS_ERR_TIMEDOUT status type.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 16 Sep 2002 10:20:21 +0000 (10:20 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 16 Sep 2002 10:20:21 +0000 (10:20 +0000)
Added 'app_context' to silc_schedule_init to deliver application
specific context in task callbacks.

13 files changed:
apps/irssi/docs/help/in/stats.in [new file with mode: 0644]
apps/irssi/src/silc/core/client_ops.c
doc/draft-riikonen-silc-commands-04.nroff
lib/silcclient/client.c
lib/silccore/silcstatus.h
lib/silcutil/os2/silcos2schedule.c
lib/silcutil/silcprotocol.c
lib/silcutil/silcschedule.c
lib/silcutil/silcschedule.h
lib/silcutil/silcutil.c
lib/silcutil/unix/silcunixschedule.c
lib/silcutil/win32/silcwin32schedule.c
scripts/silcdoc/silcdoc

diff --git a/apps/irssi/docs/help/in/stats.in b/apps/irssi/docs/help/in/stats.in
new file mode 100644 (file)
index 0000000..5841879
--- /dev/null
@@ -0,0 +1,4 @@
+
+@SYNTAX:stats@
+
+Shows various server and network statistics.
index ff9e962dea1b017b39622128de49be60d27b3d3e..8a98a779fc26af134d6024d30e46830317c31550 100644 (file)
@@ -1116,11 +1116,11 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
          }
        }
        break;
-      }
-      
-      if (!success)
+      } else if (!success) {
+       silc_say_error("WHOIS: %s", silc_get_status_message(status));
        return;
-      
+      }
+
       client_entry = va_arg(vp, SilcClientEntry);
       nickname = va_arg(vp, char *);
       username = va_arg(vp, char *);
@@ -1247,10 +1247,10 @@ silc_command_reply(SilcClient client, SilcClientConnection conn,
          silc_say_error("%s: %s", tmp, 
                         silc_get_status_message(status));
        break;
-      }
-      
-      if (!success)
+      } else if (!success) {
+       silc_say_error("WHOWAS: %s", silc_get_status_message(status));
        return;
+      }
       
       (void)va_arg(vp, SilcClientEntry);
       nickname = va_arg(vp, char *);
index 9f3656e6440c4ab383ac0e9a0155b81e3914a5a8..b9359734953e81033d458a4c7132d2c36b84d684 100644 (file)
@@ -2291,6 +2291,11 @@ List of all defined status types:
 
         "Bad version".  Protocol or software version mismatch.
 
+   54   SILC_STATUS_ERR_TIMEDOUT
+
+        "Operation timed out".  Operation or service request timed
+        out, and thus was not processed.
+
 .in 3
 
 
index cc8841988568a3cfe07ead9f75503275252bd698..f54fd256815f69a781a7e50cff38f44d00399ee8 100644 (file)
@@ -120,7 +120,7 @@ int silc_client_init(SilcClient client)
   /* Initialize the scheduler */
   client->schedule = 
     silc_schedule_init(client->internal->params->task_max ?
-                      client->internal->params->task_max : 200);
+                      client->internal->params->task_max : 200, client);
   if (!client->schedule)
     return FALSE;
 
index f619ea9ed5964cb54983d9f5c3658833e92d9f91..8c91d7eb7893b8ccace45df7f703a1094e33f277 100644 (file)
@@ -99,6 +99,7 @@ typedef SilcUInt8 SilcStatus;
 #define SILC_STATUS_ERR_BAD_SERVER_ID       51
 #define SILC_STATUS_ERR_KEY_EXCHANGE_FAILED 52
 #define SILC_STATUS_ERR_BAD_VERSION         53
+#define SILC_STATUS_ERR_TIMEDOUT            54
 /***/
 
 #define SILC_STATUS_IS_ERROR(status) (status >= SILC_STATUS_ERR_NO_SUCH_NICK)
index 53904de47fc0290389d153e3b0a40a895b7b2f64..fc60566bc89b133452efac1a2845e4b9fa1bd5bf 100644 (file)
@@ -86,7 +86,7 @@ SILC_TASK_CALLBACK(silc_schedule_wakeup_cb)
    the scheduler needs to be wakenup when tasks are added or removed from
    the task queues.  Returns context to the platform specific scheduler. */
 
-void *silc_schedule_internal_init(SilcSchedule schedule)
+void *silc_schedule_internal_init(SilcSchedule schedule, void *context)
 {
 #ifdef SILC_THREADS
   return NULL;
index 662390546eec28e0b0d619f412c97d6fb9c6bfe7..67a6640aaa2ebd116100d2afa0cb54533233400c 100644 (file)
@@ -123,14 +123,16 @@ void silc_protocol_execute(SilcProtocol protocol, SilcSchedule schedule,
                           SILC_TASK_TIMEOUT,
                           SILC_TASK_PRI_NORMAL);
   else
-    protocol->protocol->callback(schedule, 0, 0, (void *)protocol);
+    protocol->protocol->callback(schedule, silc_schedule_get_context(schedule),
+                                0, 0, (void *)protocol);
 }
 
 /* Executes the final callback of the protocol. */
 
 void silc_protocol_execute_final(SilcProtocol protocol, SilcSchedule schedule)
 {
-  protocol->final_callback(schedule, 0, 0, (void *)protocol);
+  protocol->final_callback(schedule, silc_schedule_get_context(schedule),
+                          0, 0, (void *)protocol);
 }
 
 /* Cancels the execution of the next state of the protocol. */
index bfb72997ad2017d2163c30c90cabac9278477468..af37e9fc10729166dfd591d78ed0d5e3bdae2d50 100644 (file)
@@ -35,7 +35,7 @@ int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count,
    the wakeup mechanism of the scheduler.  In multi-threaded environment
    the scheduler needs to be wakenup when tasks are added or removed from
    the task queues.  Returns context to the platform specific scheduler. */
-void *silc_schedule_internal_init(SilcSchedule schedule);
+void *silc_schedule_internal_init(SilcSchedule schedule, void *context);
 
 /* Uninitializes the platform specific scheduler context. */
 void silc_schedule_internal_uninit(void *context);
@@ -210,6 +210,7 @@ struct SilcTaskQueueStruct {
 
 */
 struct SilcScheduleStruct {
+  void *app_context;           /* Application specific context */
   SilcTaskQueue fd_queue;
   SilcTaskQueue timeout_queue;
   SilcTaskQueue generic_queue;
@@ -227,9 +228,10 @@ struct SilcScheduleStruct {
 /* Initializes the scheduler. This returns the scheduler context that
    is given as arugment usually to all silc_schedule_* functions.
    The `max_tasks' indicates the number of maximum tasks that the
-   scheduler can handle. */
+   scheduler can handle. The `app_context' is application specific
+   context that is delivered to task callbacks. */
 
-SilcSchedule silc_schedule_init(int max_tasks)
+SilcSchedule silc_schedule_init(int max_tasks, void *app_context)
 {
   SilcSchedule schedule;
 
@@ -251,12 +253,13 @@ SilcSchedule silc_schedule_init(int max_tasks)
   schedule->max_fd = max_tasks;
   schedule->timeout = NULL;
   schedule->valid = TRUE;
+  schedule->app_context = app_context;
 
   /* Allocate scheduler lock */
   silc_mutex_alloc(&schedule->lock);
 
   /* Initialize the platform specific scheduler. */
-  schedule->internal = silc_schedule_internal_init(schedule);
+  schedule->internal = silc_schedule_internal_init(schedule, app_context);
 
   return schedule;
 }
@@ -366,7 +369,8 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
       if (task->valid && schedule->fd_list[i].revents & SILC_TASK_READ) {
        silc_mutex_unlock(schedule->fd_queue->lock);
        SILC_SCHEDULE_UNLOCK(schedule);
-       task->callback(schedule, SILC_TASK_READ, task->fd, task->context);
+       task->callback(schedule, schedule->app_context,
+                      SILC_TASK_READ, task->fd, task->context);
        SILC_SCHEDULE_LOCK(schedule);
        silc_mutex_lock(schedule->fd_queue->lock);
       }
@@ -375,7 +379,8 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
       if (task->valid && schedule->fd_list[i].revents & SILC_TASK_WRITE) {
        silc_mutex_unlock(schedule->fd_queue->lock);
        SILC_SCHEDULE_UNLOCK(schedule);
-       task->callback(schedule, SILC_TASK_WRITE, task->fd, task->context);
+       task->callback(schedule, schedule->app_context,
+                      SILC_TASK_WRITE, task->fd, task->context);
        SILC_SCHEDULE_LOCK(schedule);
        silc_mutex_lock(schedule->fd_queue->lock);
       }
@@ -405,7 +410,8 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
        if (task->valid && schedule->fd_list[i].revents & SILC_TASK_READ) {
          silc_mutex_unlock(schedule->generic_queue->lock);
          SILC_SCHEDULE_UNLOCK(schedule);
-         task->callback(schedule, SILC_TASK_READ, fd, task->context);
+         task->callback(schedule, schedule->app_context,
+                        SILC_TASK_READ, fd, task->context);
          SILC_SCHEDULE_LOCK(schedule);
          silc_mutex_lock(schedule->generic_queue->lock);
        }
@@ -414,7 +420,8 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
        if (task->valid && schedule->fd_list[i].revents & SILC_TASK_WRITE) {
          silc_mutex_unlock(schedule->generic_queue->lock);
          SILC_SCHEDULE_UNLOCK(schedule);
-         task->callback(schedule, SILC_TASK_WRITE, fd, task->context);
+         task->callback(schedule, schedule->app_context,
+                        SILC_TASK_WRITE, fd, task->context);
          SILC_SCHEDULE_LOCK(schedule);
          silc_mutex_lock(schedule->generic_queue->lock);
        }
@@ -476,7 +483,8 @@ static void silc_schedule_dispatch_timeout(SilcSchedule schedule,
         if (task->valid) {
          silc_mutex_unlock(queue->lock);
          SILC_SCHEDULE_UNLOCK(schedule);
-         task->callback(schedule, SILC_TASK_EXPIRE, task->fd, task->context);
+         task->callback(schedule, schedule->app_context,
+                        SILC_TASK_EXPIRE, task->fd, task->context);
          SILC_SCHEDULE_LOCK(schedule);
          silc_mutex_lock(queue->lock);
        }
@@ -688,6 +696,16 @@ void silc_schedule_wakeup(SilcSchedule schedule)
 #endif
 }
 
+/* Returns the application specific context that was saved into the
+   scheduler in silc_schedule_init function.  The context is also
+   returned to application in task callback functions, but this function
+   may be used to get it as well if needed. */
+
+void *silc_schedule_get_context(SilcSchedule schedule)
+{
+  return schedule->app_context;
+}
+
 /* Add new task to the scheduler */
 
 SilcTask silc_schedule_task_add(SilcSchedule schedule, SilcUInt32 fd,
index f10bd8306ad34e373993902c470732f122164ace..b7704e2962c7d085fe211efcb0c9aa4743793fd0 100644 (file)
@@ -205,8 +205,9 @@ typedef enum {
  *
  * SYNOPSIS
  *
- *    typedef void (*SilcTaskCallback)(SilcSchedule schedule, 
- *                                     SilcTaskEvent type, SilcUInt32 fd, 
+ *    typedef void (*SilcTaskCallback)(SilcSchedule schedule,
+ *                                     void *app_context,
+ *                                     SilcTaskEvent type, SilcUInt32 fd,
  *                                     void *context);
  *
  * DESCRIPTION
@@ -218,15 +219,18 @@ typedef enum {
  *    The `schedule' is the scheduler context, the `type' is the indicated
  *    event, the `fd' is the file descriptor of the task and the `context'
  *    is a caller specified context. If multiple events occurred this
- *    callback is called separately for all events.
+ *    callback is called separately for all events.  The `app_context'
+ *    is application specific context that was given as argument to the
+ *    silc_schedule_init function.
  *
  *    To specify task callback function in the application using the
  *    SILC_TASK_CALLBACK and SILC_TASK_CALLBACK_GLOBAL macros is
  *    recommended.
  *
  ***/
-typedef void (*SilcTaskCallback)(SilcSchedule schedule, SilcTaskEvent type,
-                                SilcUInt32 fd, void *context);
+typedef void (*SilcTaskCallback)(SilcSchedule schedule, void *app_context,
+                                SilcTaskEvent type, SilcUInt32 fd,
+                                void *context);
 
 /* Macros */
 
@@ -260,7 +264,8 @@ typedef void (*SilcTaskCallback)(SilcSchedule schedule, SilcTaskEvent type,
  * SOURCE
  */
 #define SILC_TASK_CALLBACK(func)                               \
-static void func(SilcSchedule schedule, SilcTaskEvent type,    \
+static void func(SilcSchedule schedule, void *app_context,     \
+                SilcTaskEvent type,                            \
                 SilcUInt32 fd, void *context)
 /***/
 
@@ -279,8 +284,8 @@ static void func(SilcSchedule schedule, SilcTaskEvent type, \
  *
  * SOURCE
  */
-#define SILC_TASK_CALLBACK_GLOBAL(func)                        \
-void func(SilcSchedule schedule, SilcTaskEvent type,   \
+#define SILC_TASK_CALLBACK_GLOBAL(func)                                        \
+void func(SilcSchedule schedule, void *app_context, SilcTaskEvent type,        \
          SilcUInt32 fd, void *context)
 /***/
 
@@ -290,17 +295,20 @@ void func(SilcSchedule schedule, SilcTaskEvent type,      \
  *
  * SYNOPSIS
  *
- *    SilcSchedule silc_schedule_init(int max_tasks);
+ *    SilcSchedule silc_schedule_init(int max_tasks, void *app_context);
  *
  * DESCRIPTION
  *
  *    Initializes the scheduler. This returns the scheduler context that
  *    is given as argument usually to all silc_schedule_* functions.
  *    The `max_tasks' indicates the number of maximum tasks that the
- *    scheduler can handle.
+ *    scheduler can handle. The `app_context' is application specific
+ *    context that is delivered to all task callbacks. The caller must
+ *    free that context.  The 'app_context' can be for example the
+ *    application itself.
  *
  ***/
-SilcSchedule silc_schedule_init(int max_tasks);
+SilcSchedule silc_schedule_init(int max_tasks, void *app_context);
 
 /****f* silcutil/SilcScheduleAPI/silc_schedule_uninit
  *
@@ -407,6 +415,22 @@ bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs);
  ***/
 void silc_schedule_wakeup(SilcSchedule schedule);
 
+/****f* silcutil/SilcScheduleAPI/silc_schedule_get_context
+ *
+ * SYNOPSIS
+ *
+ *    void *silc_schedule_get_context(SilcSchedule schedule);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the application specific context that was saved into the
+ *    scheduler in silc_schedule_init function.  The context is also
+ *    returned to application in task callback functions, but this function
+ *    may be used to get it as well if needed.
+ *
+ ***/
+void *silc_schedule_get_context(SilcSchedule schedule);
+
 /****f* silcutil/SilcScheduleAPI/silc_schedule_task_add
  *
  * SYNOPSIS
index 9b0294e8a9ba632aab0fa34d4019561b8f568c57..da6da055f855969d0b67090f2a3d72eeb49b659d 100644 (file)
@@ -389,7 +389,7 @@ int silc_string_compare(char *string1, char *string2)
   slen2 = strlen(string2);
 
   /* See if they are same already */
-  if (!strncmp(string1, string2, strlen(string2)))
+  if (!strncmp(string1, string2, slen2) && slen2 == slen1)
     return TRUE;
 
   if (slen2 < slen1)
@@ -1030,6 +1030,7 @@ static const SilcStatusMessage silc_status_messages[] = {
   { STAT(BAD_SERVER_ID), "Server ID is not valid" },
   { STAT(KEY_EXCHANGE_FAILED), "Key exchange failed" },
   { STAT(BAD_VERSION), "Bad version" },
+  { STAT(TIMEDOUT), "Service timed out" },
 
   { 0, NULL }
 };
index 2bdff338251bc68f921f797b9f1973e0b5938a62..846cfa4bf68e2aac91751e0e83253dbeeca5e556 100644 (file)
@@ -76,6 +76,7 @@ typedef struct {
 
 /* Internal context. */
 typedef struct {
+  void *app_context;
   int wakeup_pipe[2];
   SilcTask wakeup_task;
   sigset_t signals;
@@ -100,7 +101,8 @@ SILC_TASK_CALLBACK(silc_schedule_wakeup_cb)
    the scheduler needs to be wakenup when tasks are added or removed from
    the task queues.  Returns context to the platform specific scheduler. */
 
-void *silc_schedule_internal_init(SilcSchedule schedule)
+void *silc_schedule_internal_init(SilcSchedule schedule,
+                                 void *app_context)
 {
   SilcUnixScheduler internal;
 
@@ -131,6 +133,8 @@ void *silc_schedule_internal_init(SilcSchedule schedule)
   }
 #endif
 
+  internal->app_context = app_context;
+
   return (void *)internal;
 }
 
@@ -256,7 +260,8 @@ void silc_schedule_internal_signals_call(void *context,
   for (i = 0; i < SIGNAL_COUNT; i++) {
     if (internal->signal_call[i].call &&
         internal->signal_call[i].callback) {
-      internal->signal_call[i].callback(schedule, SILC_TASK_INTERRUPT,
+      internal->signal_call[i].callback(schedule, internal->app_context,
+                                       SILC_TASK_INTERRUPT,
                                        internal->signal_call[i].signal,
                                        internal->signal_call[i].context);
       internal->signal_call[i].call = FALSE;
index e6aa6c9d04023df98dd58579359f8e755d11acbb..22445aef9bb1cbe5b869c0e1d58c1a49571627a4 100644 (file)
@@ -193,7 +193,7 @@ SILC_TASK_CALLBACK(silc_schedule_wakeup_cb)
    the scheduler needs to be wakenup when tasks are added or removed from
    the task queues.  Returns context to the platform specific scheduler. */
 
-void *silc_schedule_internal_init(SilcSchedule schedule)
+void *silc_schedule_internal_init(SilcSchedule schedule, void *app_context)
 {
 #ifdef SILC_THREADS
   SilcWin32Wakeup wakeup;
index 61851b89030ffc15debb8ab8b41b55b9d72b05de..beb173d6daab6a66d3dcba31369523d4ea247d36 100755 (executable)
@@ -2,7 +2,7 @@
 #
 # Author: Pekka Riikonen <priikone@silcnet.org>
 #
-# Copyright (C) GNU GPL 2001 Pekka Riikonen
+# Copyright (C) GNU GPL 2001 - 2002 Pekka Riikonen
 #
 # SILC Toolkit Reference Manual documentation script.  This will automatically
 # generate documentation from the source tree.  This will require the