aboutsummaryrefslogtreecommitdiffstats
path: root/assuan/assuan-handler.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2006-09-19 14:01:54 +0000
committerMarcus Brinkmann <[email protected]>2006-09-19 14:01:54 +0000
commit9e09d93de83fe1160689acb36b082c02ccb52716 (patch)
tree807126be9dd89fe2850ad748de978de0c5d3b340 /assuan/assuan-handler.c
parent2006-07-29 Marcus Brinkmann <[email protected]> (diff)
downloadgpgme-9e09d93de83fe1160689acb36b082c02ccb52716.tar.gz
gpgme-9e09d93de83fe1160689acb36b082c02ccb52716.zip
assuan/
Update to current version. 2006-09-19 Marcus Brinkmann <[email protected]> * configure.ac: Turn stpcpy into a replacement function. Check for unistd.h and add setenv as replacement function. gpgme/ 2006-09-19 Marcus Brinkmann <[email protected]> * setenv.c: New file.
Diffstat (limited to 'assuan/assuan-handler.c')
-rw-r--r--assuan/assuan-handler.c117
1 files changed, 62 insertions, 55 deletions
diff --git a/assuan/assuan-handler.c b/assuan/assuan-handler.c
index 21501a35..bf00d1a1 100644
--- a/assuan/assuan-handler.c
+++ b/assuan/assuan-handler.c
@@ -15,7 +15,8 @@
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA.
*/
#include <config.h>
@@ -36,20 +37,20 @@ static int my_strcasecmp (const char *a, const char *b);
static int
-dummy_handler (ASSUAN_CONTEXT ctx, char *line)
+dummy_handler (assuan_context_t ctx, char *line)
{
return set_error (ctx, Server_Fault, "no handler registered");
}
static int
-std_handler_nop (ASSUAN_CONTEXT ctx, char *line)
+std_handler_nop (assuan_context_t ctx, char *line)
{
return 0; /* okay */
}
static int
-std_handler_cancel (ASSUAN_CONTEXT ctx, char *line)
+std_handler_cancel (assuan_context_t ctx, char *line)
{
if (ctx->cancel_notify_fnc)
ctx->cancel_notify_fnc (ctx);
@@ -57,7 +58,7 @@ std_handler_cancel (ASSUAN_CONTEXT ctx, char *line)
}
static int
-std_handler_option (ASSUAN_CONTEXT ctx, char *line)
+std_handler_option (assuan_context_t ctx, char *line)
{
char *key, *value, *p;
@@ -104,7 +105,7 @@ std_handler_option (ASSUAN_CONTEXT ctx, char *line)
}
static int
-std_handler_bye (ASSUAN_CONTEXT ctx, char *line)
+std_handler_bye (assuan_context_t ctx, char *line)
{
if (ctx->bye_notify_fnc)
ctx->bye_notify_fnc (ctx);
@@ -114,33 +115,35 @@ std_handler_bye (ASSUAN_CONTEXT ctx, char *line)
}
static int
-std_handler_auth (ASSUAN_CONTEXT ctx, char *line)
+std_handler_auth (assuan_context_t ctx, char *line)
{
return set_error (ctx, Not_Implemented, NULL);
}
static int
-std_handler_reset (ASSUAN_CONTEXT ctx, char *line)
+std_handler_reset (assuan_context_t ctx, char *line)
{
if (ctx->reset_notify_fnc)
ctx->reset_notify_fnc (ctx);
assuan_close_input_fd (ctx);
assuan_close_output_fd (ctx);
+ _assuan_uds_close_fds (ctx);
return 0;
}
static int
-std_handler_end (ASSUAN_CONTEXT ctx, char *line)
+std_handler_end (assuan_context_t ctx, char *line)
{
return set_error (ctx, Not_Implemented, NULL);
}
assuan_error_t
-assuan_command_parse_fd (ASSUAN_CONTEXT ctx, char *line, int *rfd)
+assuan_command_parse_fd (assuan_context_t ctx, char *line, int *rfd)
{
char *endp;
- if (strncmp (line, "FD", 2) != 0 || (line[2] != '=' && line[2] != '\0'))
+ if ( (strncmp (line, "FD", 2) && strncmp (line, "fd", 2))
+ || (line[2] != '=' && line[2] != '\0'))
return set_error (ctx, Syntax_Error, "FD[=<n>] expected");
line += 2;
if (*line == '=')
@@ -149,7 +152,7 @@ assuan_command_parse_fd (ASSUAN_CONTEXT ctx, char *line, int *rfd)
if (!digitp (*line))
return set_error (ctx, Syntax_Error, "number required");
*rfd = strtoul (line, &endp, 10);
- /* remove that argument so that a notify handler won't see it */
+ /* Remove that argument so that a notify handler won't see it. */
memset (line, ' ', endp? (endp-line):strlen(line));
if (*rfd == ctx->inbound.fd)
@@ -165,7 +168,7 @@ assuan_command_parse_fd (ASSUAN_CONTEXT ctx, char *line, int *rfd)
/* Format is INPUT FD=<n> */
static int
-std_handler_input (ASSUAN_CONTEXT ctx, char *line)
+std_handler_input (assuan_context_t ctx, char *line)
{
int rc, fd;
@@ -180,7 +183,7 @@ std_handler_input (ASSUAN_CONTEXT ctx, char *line)
/* Format is OUTPUT FD=<n> */
static int
-std_handler_output (ASSUAN_CONTEXT ctx, char *line)
+std_handler_output (assuan_context_t ctx, char *line)
{
int rc, fd;
@@ -202,7 +205,7 @@ std_handler_output (ASSUAN_CONTEXT ctx, char *line)
with default handlers */
static struct {
const char *name;
- int (*handler)(ASSUAN_CONTEXT, char *line);
+ int (*handler)(assuan_context_t, char *line);
int always; /* always initialize this command */
} std_cmd_table[] = {
{ "NOP", std_handler_nop, 1 },
@@ -234,9 +237,9 @@ static struct {
* Return value: 0 on success or an error code
**/
int
-assuan_register_command (ASSUAN_CONTEXT ctx,
+assuan_register_command (assuan_context_t ctx,
const char *cmd_name,
- int (*handler)(ASSUAN_CONTEXT, char *))
+ int (*handler)(assuan_context_t, char *))
{
int i;
const char *s;
@@ -245,7 +248,7 @@ assuan_register_command (ASSUAN_CONTEXT ctx,
cmd_name = NULL;
if (!cmd_name)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
if (!handler)
{ /* find a default handler. */
@@ -268,7 +271,7 @@ assuan_register_command (ASSUAN_CONTEXT ctx,
ctx->cmdtbl_size = 50;
ctx->cmdtbl = xtrycalloc ( ctx->cmdtbl_size, sizeof *ctx->cmdtbl);
if (!ctx->cmdtbl)
- return ASSUAN_Out_Of_Core;
+ return _assuan_error (ASSUAN_Out_Of_Core);
ctx->cmdtbl_used = 0;
}
else if (ctx->cmdtbl_used >= ctx->cmdtbl_size)
@@ -277,7 +280,7 @@ assuan_register_command (ASSUAN_CONTEXT ctx,
x = xtryrealloc ( ctx->cmdtbl, (ctx->cmdtbl_size+10) * sizeof *x);
if (!x)
- return ASSUAN_Out_Of_Core;
+ return _assuan_error (ASSUAN_Out_Of_Core);
ctx->cmdtbl = x;
ctx->cmdtbl_size += 50;
}
@@ -289,59 +292,62 @@ assuan_register_command (ASSUAN_CONTEXT ctx,
}
int
-assuan_register_bye_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT))
+assuan_register_bye_notify (assuan_context_t ctx,
+ void (*fnc)(assuan_context_t))
{
if (!ctx)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
ctx->bye_notify_fnc = fnc;
return 0;
}
int
-assuan_register_reset_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT))
+assuan_register_reset_notify (assuan_context_t ctx,
+ void (*fnc)(assuan_context_t))
{
if (!ctx)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
ctx->reset_notify_fnc = fnc;
return 0;
}
int
-assuan_register_cancel_notify (ASSUAN_CONTEXT ctx, void (*fnc)(ASSUAN_CONTEXT))
+assuan_register_cancel_notify (assuan_context_t ctx,
+ void (*fnc)(assuan_context_t))
{
if (!ctx)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
ctx->cancel_notify_fnc = fnc;
return 0;
}
int
-assuan_register_option_handler (ASSUAN_CONTEXT ctx,
- int (*fnc)(ASSUAN_CONTEXT,
+assuan_register_option_handler (assuan_context_t ctx,
+ int (*fnc)(assuan_context_t,
const char*, const char*))
{
if (!ctx)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
ctx->option_handler_fnc = fnc;
return 0;
}
int
-assuan_register_input_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT, const char *))
+assuan_register_input_notify (assuan_context_t ctx,
+ void (*fnc)(assuan_context_t, const char *))
{
if (!ctx)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
ctx->input_notify_fnc = fnc;
return 0;
}
int
-assuan_register_output_notify (ASSUAN_CONTEXT ctx,
- void (*fnc)(ASSUAN_CONTEXT, const char *))
+assuan_register_output_notify (assuan_context_t ctx,
+ void (*fnc)(assuan_context_t, const char *))
{
if (!ctx)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
ctx->output_notify_fnc = fnc;
return 0;
}
@@ -349,7 +355,7 @@ assuan_register_output_notify (ASSUAN_CONTEXT ctx,
/* Helper to register the standards commands */
int
-_assuan_register_std_commands (ASSUAN_CONTEXT ctx)
+_assuan_register_std_commands (assuan_context_t ctx)
{
int i, rc;
@@ -370,7 +376,7 @@ _assuan_register_std_commands (ASSUAN_CONTEXT ctx)
/* Process the special data lines. The "D " has already been removed
from the line. As all handlers this function may modify the line. */
static int
-handle_data_line (ASSUAN_CONTEXT ctx, char *line, int linelen)
+handle_data_line (assuan_context_t ctx, char *line, int linelen)
{
return set_error (ctx, Not_Implemented, NULL);
}
@@ -394,7 +400,7 @@ my_strcasecmp (const char *a, const char *b)
table, remove leading and white spaces from the arguments, call the
handler with the argument line and return the error */
static int
-dispatch_command (ASSUAN_CONTEXT ctx, char *line, int linelen)
+dispatch_command (assuan_context_t ctx, char *line, int linelen)
{
char *p;
const char *s;
@@ -406,7 +412,7 @@ dispatch_command (ASSUAN_CONTEXT ctx, char *line, int linelen)
for (p=line; *p && *p != ' ' && *p != '\t'; p++)
;
if (p==line)
- return set_error (ctx, Invalid_Command, "leading white-space");
+ return set_error (ctx, Syntax_Error, "leading white-space");
if (*p)
{ /* Skip over leading WS after the keyword */
*p++ = 0;
@@ -441,12 +447,12 @@ dispatch_command (ASSUAN_CONTEXT ctx, char *line, int linelen)
static int
-process_request (ASSUAN_CONTEXT ctx)
+process_request (assuan_context_t ctx)
{
int rc;
if (ctx->in_inquire)
- return ASSUAN_Nested_Commands;
+ return _assuan_error (ASSUAN_Nested_Commands);
rc = _assuan_read_line (ctx);
if (rc)
@@ -477,8 +483,8 @@ process_request (ASSUAN_CONTEXT ctx)
{
rc = assuan_write_line (ctx, ctx->okay_line? ctx->okay_line : "OK");
}
- else if (rc == -1)
- { /* No error checking because the peer may have already disconnect */
+ else if (err_is_eof (rc))
+ { /* No error checking because the peer may have already disconnect. */
assuan_write_line (ctx, "OK closing connection");
ctx->finish_handler (ctx);
}
@@ -488,7 +494,7 @@ process_request (ASSUAN_CONTEXT ctx)
if (rc < 100)
sprintf (errline, "ERR %d server fault (%.50s)",
- ASSUAN_Server_Fault, assuan_strerror (rc));
+ _assuan_error (ASSUAN_Server_Fault), assuan_strerror (rc));
else
{
const char *text = ctx->err_no == rc? ctx->err_str:NULL;
@@ -498,7 +504,7 @@ process_request (ASSUAN_CONTEXT ctx)
strings from libgpg-error without creating a dependency.
They are used for debugging purposes only, so there is no
problem if they are not available. We need to make sure
- that we are using elf because only this guarantees that
+ that we are using ELF because only this guarantees that
weak symbol support is available in case GNU ld is not
used. */
unsigned int source, code;
@@ -552,7 +558,7 @@ process_request (ASSUAN_CONTEXT ctx)
* failed. Note, that no error is returned for operational errors.
**/
int
-assuan_process (ASSUAN_CONTEXT ctx)
+assuan_process (assuan_context_t ctx)
{
int rc;
@@ -560,7 +566,7 @@ assuan_process (ASSUAN_CONTEXT ctx)
rc = process_request (ctx);
} while (!rc);
- if (rc == -1)
+ if (err_is_eof (rc))
rc = 0;
return rc;
@@ -579,7 +585,7 @@ assuan_process (ASSUAN_CONTEXT ctx)
* Return value: -1 for end of server, 0 on success or an error code
**/
int
-assuan_process_next (ASSUAN_CONTEXT ctx)
+assuan_process_next (assuan_context_t ctx)
{
return process_request (ctx);
}
@@ -603,7 +609,7 @@ assuan_process_next (ASSUAN_CONTEXT ctx)
* error which is most likely a too small fdarray.
**/
int
-assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
+assuan_get_active_fds (assuan_context_t ctx, int what,
int *fdarray, int fdarraysize)
{
int n = 0;
@@ -636,7 +642,7 @@ assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
implementaion for systems w/o a glibc, a simple implementation
could use a child process */
FILE *
-assuan_get_data_fp (ASSUAN_CONTEXT ctx)
+assuan_get_data_fp (assuan_context_t ctx)
{
#if defined (HAVE_FOPENCOOKIE) || defined (HAVE_FUNOPEN)
if (ctx->outbound.data.fp)
@@ -658,10 +664,10 @@ assuan_get_data_fp (ASSUAN_CONTEXT ctx)
/* Set the text used for the next OK reponse. This string is
automatically reset to NULL after the next command. */
assuan_error_t
-assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line)
+assuan_set_okay_line (assuan_context_t ctx, const char *line)
{
if (!ctx)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
if (!line)
{
xfree (ctx->okay_line);
@@ -673,7 +679,7 @@ assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line)
we should allocate the entire line in secure memory */
char *buf = xtrymalloc (3+strlen(line)+1);
if (!buf)
- return ASSUAN_Out_Of_Core;
+ return _assuan_error (ASSUAN_Out_Of_Core);
strcpy (buf, "OK ");
strcpy (buf+3, line);
xfree (ctx->okay_line);
@@ -685,7 +691,8 @@ assuan_set_okay_line (ASSUAN_CONTEXT ctx, const char *line)
assuan_error_t
-assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text)
+assuan_write_status (assuan_context_t ctx,
+ const char *keyword, const char *text)
{
char buffer[256];
char *helpbuf;
@@ -693,7 +700,7 @@ assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text)
assuan_error_t ae;
if ( !ctx || !keyword)
- return ASSUAN_Invalid_Value;
+ return _assuan_error (ASSUAN_Invalid_Value);
if (!text)
text = "";