aboutsummaryrefslogtreecommitdiffstats
path: root/src/assuan-handler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/assuan-handler.c')
-rw-r--r--src/assuan-handler.c93
1 files changed, 43 insertions, 50 deletions
diff --git a/src/assuan-handler.c b/src/assuan-handler.c
index 9d73e0e..f8b85db 100644
--- a/src/assuan-handler.c
+++ b/src/assuan-handler.c
@@ -25,9 +25,15 @@
#include "assuan-defs.h"
+
+
#define spacep(p) (*(p) == ' ' || *(p) == '\t')
#define digitp(a) ((a) >= '0' && (a) <= '9')
+static int my_strcasecmp (const char *a, const char *b);
+
+
+
static int
dummy_handler (ASSUAN_CONTEXT ctx, char *line)
{
@@ -191,25 +197,24 @@ std_handler_output (ASSUAN_CONTEXT ctx, char *line)
/* This is a table with the standard commands and handler for them.
- The table is used to initialize a new context and assuciate strings
- and handlers with cmd_ids */
+ The table is used to initialize a new context and associate strings
+ with default handlers */
static struct {
const char *name;
- int cmd_id;
int (*handler)(ASSUAN_CONTEXT, char *line);
int always; /* always initialize this command */
} std_cmd_table[] = {
- { "NOP", ASSUAN_CMD_NOP, std_handler_nop, 1 },
- { "CANCEL", ASSUAN_CMD_CANCEL, std_handler_cancel, 1 },
- { "OPTION", ASSUAN_CMD_OPTION, std_handler_option, 1 },
- { "BYE", ASSUAN_CMD_BYE, std_handler_bye, 1 },
- { "AUTH", ASSUAN_CMD_AUTH, std_handler_auth, 1 },
- { "RESET", ASSUAN_CMD_RESET, std_handler_reset, 1 },
- { "END", ASSUAN_CMD_END, std_handler_end, 1 },
-
- { "INPUT", ASSUAN_CMD_INPUT, std_handler_input },
- { "OUTPUT", ASSUAN_CMD_OUTPUT, std_handler_output },
- { "OPTION", ASSUAN_CMD_OPTION, std_handler_option, 1 },
+ { "NOP", std_handler_nop, 1 },
+ { "CANCEL", std_handler_cancel, 1 },
+ { "OPTION", std_handler_option, 1 },
+ { "BYE", std_handler_bye, 1 },
+ { "AUTH", std_handler_auth, 1 },
+ { "RESET", std_handler_reset, 1 },
+ { "END", std_handler_end, 1 },
+
+ { "INPUT", std_handler_input },
+ { "OUTPUT", std_handler_output },
+ { "OPTION", std_handler_option, 1 },
{ NULL }
};
@@ -217,54 +222,46 @@ static struct {
/**
* assuan_register_command:
* @ctx: the server context
- * @cmd_id: An ID value for the command
* @cmd_name: A string with the command name
- * @handler: The handler function to be called
+ * @handler: The handler function to be called or NULL to use a default
+ * handler.
*
- * Register a handler to be used for a given command.
+ * Register a handler to be used for a given command. Note that
+ * several default handlers are already regsitered with a new context.
+ * This function however allows to override them.
*
- * The @cmd_name must be %NULL or an empty string for all @cmd_ids
- * below %ASSUAN_CMD_USER because predefined values are used.
- *
- * Return value:
+ * Return value: 0 on success or an error code
**/
int
assuan_register_command (ASSUAN_CONTEXT ctx,
- int cmd_id, const char *cmd_name,
+ const char *cmd_name,
int (*handler)(ASSUAN_CONTEXT, char *))
{
int i;
+ const char *s;
if (cmd_name && !*cmd_name)
cmd_name = NULL;
- if (cmd_id < ASSUAN_CMD_USER)
- {
- if (cmd_name)
- return ASSUAN_Invalid_Value; /* must be NULL for these values*/
+ if (!cmd_name)
+ return ASSUAN_Invalid_Value;
- for (i=0; std_cmd_table[i].name; i++)
- {
- if (std_cmd_table[i].cmd_id == cmd_id)
- {
- cmd_name = std_cmd_table[i].name;
- if (!handler)
- handler = std_cmd_table[i].handler;
- break;
- }
+ if (!handler)
+ { /* find a default handler. */
+ for (i=0; (s=std_cmd_table[i].name) && strcmp (cmd_name, s); i++)
+ ;
+ if (!s)
+ { /* Try again but case insensitive. */
+ for (i=0; (s=std_cmd_table[i].name)
+ && my_strcasecmp (cmd_name, s); i++)
+ ;
}
- if (!std_cmd_table[i].name)
- return ASSUAN_Invalid_Value; /* not a pre-registered one */
+ if (s)
+ handler = std_cmd_table[i].handler;
+ if (!handler)
+ handler = dummy_handler; /* Last resort is the dummy handler. */
}
- if (!handler)
- handler = dummy_handler;
-
- if (!cmd_name)
- return ASSUAN_Invalid_Value;
-
-/* fprintf (stderr, "DBG-assuan: registering %d as `%s'\n", cmd_id, cmd_name); */
-
if (!ctx->cmdtbl)
{
ctx->cmdtbl_size = 50;
@@ -285,7 +282,6 @@ assuan_register_command (ASSUAN_CONTEXT ctx,
}
ctx->cmdtbl[ctx->cmdtbl_used].name = cmd_name;
- ctx->cmdtbl[ctx->cmdtbl_used].cmd_id = cmd_id;
ctx->cmdtbl[ctx->cmdtbl_used].handler = handler;
ctx->cmdtbl_used++;
return 0;
@@ -360,8 +356,7 @@ _assuan_register_std_commands (ASSUAN_CONTEXT ctx)
{
if (std_cmd_table[i].always)
{
- rc = assuan_register_command (ctx, std_cmd_table[i].cmd_id,
- NULL, NULL);
+ rc = assuan_register_command (ctx, std_cmd_table[i].name, NULL);
if (rc)
return rc;
}
@@ -610,8 +605,6 @@ assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
FILE *
assuan_get_data_fp (ASSUAN_CONTEXT ctx)
{
- cookie_io_functions_t cookie_fnc;
-
if (ctx->outbound.data.fp)
return ctx->outbound.data.fp;