From: Pekka Riikonen Date: Mon, 16 Sep 2002 10:20:21 +0000 (+0000) Subject: Added new SILC_STATUS_ERR_TIMEDOUT status type. X-Git-Tag: silc.client.0.9.6~97 X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=commitdiff_plain;h=4a0081751a282b29d525b5f9a3312628aed24a2f Added new SILC_STATUS_ERR_TIMEDOUT status type. Added 'app_context' to silc_schedule_init to deliver application specific context in task callbacks. --- diff --git a/apps/irssi/docs/help/in/stats.in b/apps/irssi/docs/help/in/stats.in new file mode 100644 index 00000000..58418794 --- /dev/null +++ b/apps/irssi/docs/help/in/stats.in @@ -0,0 +1,4 @@ + +@SYNTAX:stats@ + +Shows various server and network statistics. diff --git a/apps/irssi/src/silc/core/client_ops.c b/apps/irssi/src/silc/core/client_ops.c index ff9e962d..8a98a779 100644 --- a/apps/irssi/src/silc/core/client_ops.c +++ b/apps/irssi/src/silc/core/client_ops.c @@ -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 *); diff --git a/doc/draft-riikonen-silc-commands-04.nroff b/doc/draft-riikonen-silc-commands-04.nroff index 9f3656e6..b9359734 100644 --- a/doc/draft-riikonen-silc-commands-04.nroff +++ b/doc/draft-riikonen-silc-commands-04.nroff @@ -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 diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index cc884198..f54fd256 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -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; diff --git a/lib/silccore/silcstatus.h b/lib/silccore/silcstatus.h index f619ea9e..8c91d7eb 100644 --- a/lib/silccore/silcstatus.h +++ b/lib/silccore/silcstatus.h @@ -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) diff --git a/lib/silcutil/os2/silcos2schedule.c b/lib/silcutil/os2/silcos2schedule.c index 53904de4..fc60566b 100644 --- a/lib/silcutil/os2/silcos2schedule.c +++ b/lib/silcutil/os2/silcos2schedule.c @@ -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; diff --git a/lib/silcutil/silcprotocol.c b/lib/silcutil/silcprotocol.c index 66239054..67a6640a 100644 --- a/lib/silcutil/silcprotocol.c +++ b/lib/silcutil/silcprotocol.c @@ -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. */ diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index bfb72997..af37e9fc 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -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, diff --git a/lib/silcutil/silcschedule.h b/lib/silcutil/silcschedule.h index f10bd830..b7704e29 100644 --- a/lib/silcutil/silcschedule.h +++ b/lib/silcutil/silcschedule.h @@ -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 diff --git a/lib/silcutil/silcutil.c b/lib/silcutil/silcutil.c index 9b0294e8..da6da055 100644 --- a/lib/silcutil/silcutil.c +++ b/lib/silcutil/silcutil.c @@ -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 } }; diff --git a/lib/silcutil/unix/silcunixschedule.c b/lib/silcutil/unix/silcunixschedule.c index 2bdff338..846cfa4b 100644 --- a/lib/silcutil/unix/silcunixschedule.c +++ b/lib/silcutil/unix/silcunixschedule.c @@ -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; diff --git a/lib/silcutil/win32/silcwin32schedule.c b/lib/silcutil/win32/silcwin32schedule.c index e6aa6c9d..22445aef 100644 --- a/lib/silcutil/win32/silcwin32schedule.c +++ b/lib/silcutil/win32/silcwin32schedule.c @@ -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; diff --git a/scripts/silcdoc/silcdoc b/scripts/silcdoc/silcdoc index 61851b89..beb173d6 100755 --- a/scripts/silcdoc/silcdoc +++ b/scripts/silcdoc/silcdoc @@ -2,7 +2,7 @@ # # Author: Pekka Riikonen # -# 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