[svn] assuan - r314 - in trunk: . src tests
svn author wk
cvs at cvs.gnupg.org
Wed Nov 4 11:00:25 CET 2009
Author: wk
Date: 2009-11-04 11:00:24 +0100 (Wed, 04 Nov 2009)
New Revision: 314
Modified:
trunk/ChangeLog
trunk/NEWS
trunk/src/ChangeLog
trunk/src/Makefile.am
trunk/src/assuan-defs.h
trunk/src/assuan-handler.c
trunk/src/assuan.h
trunk/tests/fdpassing.c
Log:
Extended HELP command.
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/ChangeLog 2009-11-04 10:00:24 UTC (rev 314)
@@ -1,3 +1,8 @@
+2009-11-04 Werner Koch <wk at g10code.com>
+
+ * tests/fdpassing.c (register_commands): Add NULL arg to
+ assuan_register_command.
+
2009-10-16 Marcus Brinkmann <marcus at g10code.de>
* autogen.sh: Remove --with-pth-prefix from configure invocation.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/src/ChangeLog 2009-11-04 10:00:24 UTC (rev 314)
@@ -1,3 +1,11 @@
+2009-11-04 Werner Koch <wk at g10code.com>
+
+ * Makefile.am (common_sources): Add debug.h.
+
+ * assuan-defs.h (cmdtbl_s): Add field HELPSTR.
+ * assuan-handler.c (assuan_register_command): Add arg HELP_STRING.
+ (std_handler_help): Print the help.
+
2009-11-02 Marcus Brinkmann <marcus at g10code.de>
* assuan.h (assuan_handler_t): New type.
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/NEWS 2009-11-04 10:00:24 UTC (rev 314)
@@ -14,7 +14,8 @@
of NULL, you have to provide a non-NULL ARGV argument and check
that against "server" or "client" to determine which end you got
after fork(). If you use the assuan sock interface, you must call
- assuan_sock_init after setting global context defaults.
+ assuan_sock_init after setting global context defaults. Add a NULL
+ as the last arg to assuan_register_command.
* Pth support has changed. This now follows the same style as
libgcrypt by setting system hook callbacks.
@@ -68,11 +69,12 @@
assuan_sock_init NEW
assuan_sock_deinit NEW
assuan_handler_t NEW
+assuan_register_command CHANGED: Add arg HELP_STRING.
assuan_register_bye_notify CHANGED: Handler gets line and returns err now.
assuan_register_reset_notify CHANGED: Handler gets line and returns err now.
assuan_register_cancel_notify CHANGED: Handler gets line and returns err now.
assuan_register_input_notify CHANGED: Handler returns error now.
-assuan_register_output_notify CHANGED: Handler returns error now.
+assuan_register_output_notify CHANGED: Handler returns error now.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Modified: trunk/src/Makefile.am
===================================================================
--- trunk/src/Makefile.am 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/src/Makefile.am 2009-11-04 10:00:24 UTC (rev 314)
@@ -39,7 +39,7 @@
assuan.c \
context.c \
system.c \
- debug.c \
+ debug.c debug.h \
conversion.c \
assuan-error.c \
assuan-buffer.c \
Modified: trunk/src/assuan-defs.h
===================================================================
--- trunk/src/assuan-defs.h 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/src/assuan-defs.h 2009-11-04 10:00:24 UTC (rev 314)
@@ -53,6 +53,7 @@
{
const char *name;
assuan_handler_t handler;
+ const char *helpstr;
};
Modified: trunk/src/assuan-handler.c
===================================================================
--- trunk/src/assuan-handler.c 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/src/assuan-handler.c 2009-11-04 10:00:24 UTC (rev 314)
@@ -155,13 +155,56 @@
{
unsigned int i;
char buf[ASSUAN_LINELENGTH];
+ const char *helpstr;
+ size_t n;
- for (i = 0; i < ctx->cmdtbl_used; i++)
+ n = strcspn (line, " \t\n");
+ if (!n)
{
- snprintf (buf, sizeof (buf), "# %s", ctx->cmdtbl[i].name);
- buf[ASSUAN_LINELENGTH - 1] = '\0';
- assuan_write_line (ctx, buf);
+ /* Print all commands. If a help string is available and that
+ starts with the command name, print the first line of the
+ help string. */
+ for (i = 0; i < ctx->cmdtbl_used; i++)
+ {
+ n = strlen (ctx->cmdtbl[i].name);
+ helpstr = ctx->cmdtbl[i].helpstr;
+ if (helpstr
+ && !strncmp (ctx->cmdtbl[i].name, helpstr, n)
+ && (!helpstr[n] || helpstr[n] == '\n' || helpstr[n] == ' ')
+ && (n = strcspn (helpstr, "\n")) )
+ snprintf (buf, sizeof (buf), "# %.*s", (int)n, helpstr);
+ else
+ snprintf (buf, sizeof (buf), "# %s", ctx->cmdtbl[i].name);
+ buf[ASSUAN_LINELENGTH - 1] = '\0';
+ assuan_write_line (ctx, buf);
+ }
}
+ else
+ {
+ /* Print the help for the given command. */
+ int c = line[n];
+ line[n] = 0;
+ for (i=0; ctx->cmdtbl[i].name; i++)
+ if (!my_strcasecmp (line, ctx->cmdtbl[i].name))
+ break;
+ line[n] = c;
+ if (!ctx->cmdtbl[i].name)
+ return PROCESS_DONE (ctx, set_error (ctx,GPG_ERR_UNKNOWN_COMMAND,NULL));
+ helpstr = ctx->cmdtbl[i].helpstr;
+ if (!helpstr)
+ return PROCESS_DONE (ctx, set_error (ctx, GPG_ERR_NOT_FOUND, NULL));
+ do
+ {
+ n = strcspn (helpstr, "\n");
+ snprintf (buf, sizeof (buf), "# %.*s", (int)n, helpstr);
+ helpstr += n;
+ if (*helpstr == '\n')
+ helpstr++;
+ buf[ASSUAN_LINELENGTH - 1] = '\0';
+ assuan_write_line (ctx, buf);
+ }
+ while (*helpstr);
+ }
return PROCESS_DONE (ctx, 0);
}
@@ -275,6 +318,7 @@
* @cmd_name: A string with the command name
* @handler: The handler function to be called or NULL to use a default
* handler.
+ * HELPSTRING
*
* Register a handler to be used for a given command. Note that
* several default handlers are already regsitered with a new context.
@@ -284,7 +328,7 @@
**/
gpg_error_t
assuan_register_command (assuan_context_t ctx, const char *cmd_name,
- assuan_handler_t handler)
+ assuan_handler_t handler, const char *help_string)
{
int i;
const char *s;
@@ -332,6 +376,7 @@
ctx->cmdtbl[ctx->cmdtbl_used].name = cmd_name;
ctx->cmdtbl[ctx->cmdtbl_used].handler = handler;
+ ctx->cmdtbl[ctx->cmdtbl_used].helpstr = help_string;
ctx->cmdtbl_used++;
return 0;
}
@@ -424,7 +469,7 @@
{
if (std_cmd_table[i].always)
{
- rc = assuan_register_command (ctx, std_cmd_table[i].name, NULL);
+ rc = assuan_register_command (ctx, std_cmd_table[i].name, NULL, NULL);
if (rc)
return rc;
}
Modified: trunk/src/assuan.h
===================================================================
--- trunk/src/assuan.h 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/src/assuan.h 2009-11-04 10:00:24 UTC (rev 314)
@@ -305,9 +305,11 @@
/*-- assuan-handler.c --*/
gpg_error_t assuan_register_command (assuan_context_t ctx,
const char *cmd_string,
- assuan_handler_t handler);
+ assuan_handler_t handler,
+ const char *help_string);
gpg_error_t assuan_register_post_cmd_notify (assuan_context_t ctx,
- void (*fnc)(assuan_context_t, gpg_error_t));
+ void (*fnc)(assuan_context_t,
+ gpg_error_t));
gpg_error_t assuan_register_bye_notify (assuan_context_t ctx,
assuan_handler_t handler);
gpg_error_t assuan_register_reset_notify (assuan_context_t ctx,
@@ -321,7 +323,8 @@
gpg_error_t assuan_register_option_handler (assuan_context_t ctx,
gpg_error_t (*fnc)(assuan_context_t,
- const char*, const char*));
+ const char*,
+ const char*));
gpg_error_t assuan_process (assuan_context_t ctx);
gpg_error_t assuan_process_next (assuan_context_t ctx);
Modified: trunk/tests/fdpassing.c
===================================================================
--- trunk/tests/fdpassing.c 2009-11-02 17:33:53 UTC (rev 313)
+++ trunk/tests/fdpassing.c 2009-11-04 10:00:24 UTC (rev 314)
@@ -88,7 +88,7 @@
for (i=0; table[i].name; i++)
{
- rc = assuan_register_command (ctx, table[i].name, table[i].handler);
+ rc = assuan_register_command (ctx, table[i].name, table[i].handler, NULL);
if (rc)
return rc;
}
More information about the Gnupg-commits
mailing list