mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
* assuan-connect.c (assuan_pipe_connect): Implemented the inital
handshake. * assuan-client.c (read_from_server): Renamed to (_assuan_read_from_server): this and made external. * assuan-listen.c (assuan_set_hello_line): New. (assuan_accept): Use a custom hello line is available. * assuan-buffer.c (assuan_read_line): New. (assuan_pending_line): New. (_assuan_write_line): Renamed to .. (assuan_write_line): this, made public and changed all callers.
This commit is contained in:
parent
6a8c47bd29
commit
d0eb9ade2c
@ -1,3 +1,18 @@
|
|||||||
|
2001-12-12 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
* assuan-connect.c (assuan_pipe_connect): Implemented the inital
|
||||||
|
handshake.
|
||||||
|
* assuan-client.c (read_from_server): Renamed to
|
||||||
|
(_assuan_read_from_server): this and made external.
|
||||||
|
|
||||||
|
* assuan-listen.c (assuan_set_hello_line): New.
|
||||||
|
(assuan_accept): Use a custom hello line is available.
|
||||||
|
|
||||||
|
* assuan-buffer.c (assuan_read_line): New.
|
||||||
|
(assuan_pending_line): New.
|
||||||
|
(_assuan_write_line): Renamed to ..
|
||||||
|
(assuan_write_line): this, made public and changed all callers.
|
||||||
|
|
||||||
2001-12-04 Werner Koch <wk@gnupg.org>
|
2001-12-04 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
* assuan-connect.c (assuan_pipe_connect): Add more error reporting.
|
* assuan-connect.c (assuan_pipe_connect): Add more error reporting.
|
||||||
|
@ -123,16 +123,25 @@ _assuan_read_line (ASSUAN_CONTEXT ctx)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx->inbound.attic.pending = 0;
|
||||||
for (n=0; n < nread; n++)
|
for (n=0; n < nread; n++)
|
||||||
{
|
{
|
||||||
if (line[n] == '\n')
|
if (line[n] == '\n')
|
||||||
{
|
{
|
||||||
if (n+1 < nread)
|
if (n+1 < nread)
|
||||||
{
|
{
|
||||||
|
char *s, *d;
|
||||||
|
int i;
|
||||||
|
|
||||||
n++;
|
n++;
|
||||||
/* we have to copy the rest because the handlers are
|
/* we have to copy the rest because the handlers are
|
||||||
allowed to modify the passed buffer */
|
allowed to modify the passed buffer */
|
||||||
memcpy (ctx->inbound.attic.line, line+n, nread-n);
|
for (d=ctx->inbound.attic.line, s=line+n, i=nread-n; i; i--)
|
||||||
|
{
|
||||||
|
if (*s=='\n')
|
||||||
|
ctx->inbound.attic.pending = 1;
|
||||||
|
*d++ = *s++;
|
||||||
|
}
|
||||||
ctx->inbound.attic.linelen = nread-n;
|
ctx->inbound.attic.linelen = nread-n;
|
||||||
n--;
|
n--;
|
||||||
}
|
}
|
||||||
@ -150,12 +159,43 @@ _assuan_read_line (ASSUAN_CONTEXT ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Read the next line from the client or server and return a pointer
|
||||||
|
to a buffer with holding that line. linelen returns the length of
|
||||||
|
the line. This buffer is valid until another read operation is
|
||||||
|
done on this buffer. The caller is allowed to modify this buffer.
|
||||||
|
He should only use the buffer if the function returns without an
|
||||||
|
error.
|
||||||
|
|
||||||
|
Returns: 0 on success or an assuan error code
|
||||||
|
See also: assuan_pending_line().
|
||||||
|
*/
|
||||||
|
AssuanError
|
||||||
|
assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen)
|
||||||
|
{
|
||||||
|
if (!ctx)
|
||||||
|
return ASSUAN_Invalid_Value;
|
||||||
|
*line = ctx->inbound.line;
|
||||||
|
*linelen = ctx->inbound.linelen;
|
||||||
|
return _assuan_read_line (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
/* Return true when a full line is pending for a read, without the need
|
||||||
_assuan_write_line (ASSUAN_CONTEXT ctx, const char *line )
|
for actual IO */
|
||||||
|
int
|
||||||
|
assuan_pending_line (ASSUAN_CONTEXT ctx)
|
||||||
|
{
|
||||||
|
return ctx && ctx->inbound.attic.pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AssuanError
|
||||||
|
assuan_write_line (ASSUAN_CONTEXT ctx, const char *line )
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
if (!ctx)
|
||||||
|
return ASSUAN_Invalid_Value;
|
||||||
|
|
||||||
/* fixme: we should do some kind of line buffering */
|
/* fixme: we should do some kind of line buffering */
|
||||||
rc = writen (ctx->outbound.fd, line, strlen(line));
|
rc = writen (ctx->outbound.fd, line, strlen(line));
|
||||||
@ -297,7 +337,7 @@ assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length)
|
|||||||
if (ctx->outbound.data.error)
|
if (ctx->outbound.data.error)
|
||||||
return ctx->outbound.data.error;
|
return ctx->outbound.data.error;
|
||||||
if (!ctx->is_server)
|
if (!ctx->is_server)
|
||||||
return _assuan_write_line (ctx, "END");
|
return assuan_write_line (ctx, "END");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
|
#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
|
||||||
|
|
||||||
|
|
||||||
static AssuanError
|
AssuanError
|
||||||
read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off)
|
_assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
int linelen;
|
int linelen;
|
||||||
@ -114,12 +114,12 @@ assuan_transact (ASSUAN_CONTEXT ctx,
|
|||||||
unsigned char *line;
|
unsigned char *line;
|
||||||
int linelen;
|
int linelen;
|
||||||
|
|
||||||
rc = _assuan_write_line (ctx, command);
|
rc = assuan_write_line (ctx, command);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
again:
|
again:
|
||||||
rc = read_from_server (ctx, &okay, &off);
|
rc = _assuan_read_from_server (ctx, &okay, &off);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc; /* error reading from server */
|
return rc; /* error reading from server */
|
||||||
|
|
||||||
@ -162,8 +162,8 @@ assuan_transact (ASSUAN_CONTEXT ctx,
|
|||||||
{
|
{
|
||||||
if (!inquire_cb)
|
if (!inquire_cb)
|
||||||
{
|
{
|
||||||
_assuan_write_line (ctx, "END"); /* get out of inquire mode */
|
assuan_write_line (ctx, "END"); /* get out of inquire mode */
|
||||||
read_from_server (ctx, &okay, &off); /* dummy read the response */
|
_assuan_read_from_server (ctx, &okay, &off); /* dummy read */
|
||||||
rc = ASSUAN_No_Inquire_Callback;
|
rc = ASSUAN_No_Inquire_Callback;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_JNLIB_LOGGING
|
#ifdef HAVE_JNLIB_LOGGING
|
||||||
|
#include "../jnlib/logging.h"
|
||||||
#define LOGERROR1(a,b) log_error ((a), (b))
|
#define LOGERROR1(a,b) log_error ((a), (b))
|
||||||
#else
|
#else
|
||||||
#define LOGERROR1(a,b) fprintf (stderr, (a), (b))
|
#define LOGERROR1(a,b) fprintf (stderr, (a), (b))
|
||||||
@ -188,35 +189,37 @@ assuan_pipe_connect (ASSUAN_CONTEXT *ctx, const char *name, char *const argv[])
|
|||||||
|
|
||||||
close (rp[1]);
|
close (rp[1]);
|
||||||
close (wp[0]);
|
close (wp[0]);
|
||||||
_assuan_read_line (*ctx); /* FIXME: Handshake. */
|
|
||||||
|
|
||||||
#if 0 /* old stuff */
|
/* initial handshake */
|
||||||
inbound.eof = 0;
|
{
|
||||||
inbound.linelen = 0;
|
int okay, off;
|
||||||
inbound.attic.linelen = 0;
|
|
||||||
|
|
||||||
/* The server is available - read the greeting */
|
err = _assuan_read_from_server (*ctx, &okay, &off);
|
||||||
rc = read_from_agent (&okay);
|
if (err)
|
||||||
if (rc)
|
{
|
||||||
|
LOGERROR1 ("can't connect server: %s\n", assuan_strerror (err));
|
||||||
|
}
|
||||||
|
else if (okay != 1)
|
||||||
|
{
|
||||||
|
LOGERROR1 ("can't connect server: `%s'\n", (*ctx)->inbound.line);
|
||||||
|
err = ASSUAN_Connect_Failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err)
|
||||||
{
|
{
|
||||||
log_error ("can't connect to the agent: %s\n", gnupg_strerror (rc));
|
if ((*ctx)->pid != -1)
|
||||||
|
waitpid ((*ctx)->pid, NULL, 0); /* FIXME Check return value. */
|
||||||
|
assuan_deinit_pipe_server (*ctx); /* FIXME: Common code should be factored out. */
|
||||||
}
|
}
|
||||||
else if (!okay)
|
|
||||||
{
|
|
||||||
log_error ("can't connect to the agent: %s\n", inbound.line);
|
|
||||||
rc = seterr (No_Agent);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
return err;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
assuan_pipe_disconnect (ASSUAN_CONTEXT ctx)
|
assuan_pipe_disconnect (ASSUAN_CONTEXT ctx)
|
||||||
{
|
{
|
||||||
_assuan_write_line (ctx, "BYE");
|
assuan_write_line (ctx, "BYE");
|
||||||
close (ctx->inbound.fd);
|
close (ctx->inbound.fd);
|
||||||
close (ctx->outbound.fd);
|
close (ctx->outbound.fd);
|
||||||
waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */
|
waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */
|
||||||
|
@ -38,6 +38,7 @@ struct assuan_context_s {
|
|||||||
|
|
||||||
int is_server; /* set if this is context belongs to a server */
|
int is_server; /* set if this is context belongs to a server */
|
||||||
int in_inquire;
|
int in_inquire;
|
||||||
|
char *hello_line;
|
||||||
|
|
||||||
void *user_pointer; /* for assuan_[gs]et_pointer () */
|
void *user_pointer; /* for assuan_[gs]et_pointer () */
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ struct assuan_context_s {
|
|||||||
struct {
|
struct {
|
||||||
char line[LINELENGTH];
|
char line[LINELENGTH];
|
||||||
int linelen ;
|
int linelen ;
|
||||||
|
int pending; /* i.e. at least one line is available in the attic */
|
||||||
} attic;
|
} attic;
|
||||||
} inbound;
|
} inbound;
|
||||||
|
|
||||||
@ -91,12 +93,12 @@ struct assuan_context_s {
|
|||||||
int _assuan_register_std_commands (ASSUAN_CONTEXT ctx);
|
int _assuan_register_std_commands (ASSUAN_CONTEXT ctx);
|
||||||
|
|
||||||
/*-- assuan-buffer.c --*/
|
/*-- assuan-buffer.c --*/
|
||||||
int _assuan_write_line (ASSUAN_CONTEXT ctx, const char *line);
|
|
||||||
int _assuan_read_line (ASSUAN_CONTEXT ctx);
|
int _assuan_read_line (ASSUAN_CONTEXT ctx);
|
||||||
int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
|
int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size);
|
||||||
int _assuan_cookie_write_flush (void *cookie);
|
int _assuan_cookie_write_flush (void *cookie);
|
||||||
|
|
||||||
|
/*-- assuan-client.c --*/
|
||||||
|
AssuanError _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off);
|
||||||
|
|
||||||
|
|
||||||
/*-- assuan-util.c --*/
|
/*-- assuan-util.c --*/
|
||||||
|
@ -377,11 +377,11 @@ process_request (ASSUAN_CONTEXT ctx)
|
|||||||
/* Error handling */
|
/* Error handling */
|
||||||
if (!rc)
|
if (!rc)
|
||||||
{
|
{
|
||||||
rc = _assuan_write_line (ctx, "OK");
|
rc = assuan_write_line (ctx, "OK");
|
||||||
}
|
}
|
||||||
else if (rc == -1)
|
else if (rc == -1)
|
||||||
{ /* No error checking because the peer may have already disconnect */
|
{ /* No error checking because the peer may have already disconnect */
|
||||||
_assuan_write_line (ctx, "OK Bye, bye - hope to meet you again");
|
assuan_write_line (ctx, "OK Hope to meet you again");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -397,7 +397,7 @@ process_request (ASSUAN_CONTEXT ctx)
|
|||||||
sprintf (errline, "ERR %d %.50s%s%.100s",
|
sprintf (errline, "ERR %d %.50s%s%.100s",
|
||||||
rc, assuan_strerror (rc), text? " - ":"", text?text:"");
|
rc, assuan_strerror (rc), text? " - ":"", text?text:"");
|
||||||
}
|
}
|
||||||
rc = _assuan_write_line (ctx, errline);
|
rc = assuan_write_line (ctx, errline);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
@ -538,7 +538,7 @@ assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text)
|
|||||||
strcat (buffer, " ");
|
strcat (buffer, " ");
|
||||||
strcat (buffer, text);
|
strcat (buffer, text);
|
||||||
}
|
}
|
||||||
_assuan_write_line (ctx, buffer);
|
assuan_write_line (ctx, buffer);
|
||||||
}
|
}
|
||||||
else if ( (helpbuf = xtrymalloc (n)) )
|
else if ( (helpbuf = xtrymalloc (n)) )
|
||||||
{
|
{
|
||||||
@ -549,7 +549,7 @@ assuan_write_status (ASSUAN_CONTEXT ctx, const char *keyword, const char *text)
|
|||||||
strcat (helpbuf, " ");
|
strcat (helpbuf, " ");
|
||||||
strcat (helpbuf, text);
|
strcat (helpbuf, text);
|
||||||
}
|
}
|
||||||
_assuan_write_line (ctx, helpbuf);
|
assuan_write_line (ctx, helpbuf);
|
||||||
xfree (helpbuf);
|
xfree (helpbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
|
|||||||
init_membuf (&mb, maxlen? maxlen:1024, maxlen);
|
init_membuf (&mb, maxlen? maxlen:1024, maxlen);
|
||||||
|
|
||||||
strcpy (stpcpy (cmdbuf, "INQUIRE "), keyword);
|
strcpy (stpcpy (cmdbuf, "INQUIRE "), keyword);
|
||||||
rc = _assuan_write_line (ctx, cmdbuf);
|
rc = assuan_write_line (ctx, cmdbuf);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto leave;
|
goto leave;
|
||||||
|
|
||||||
|
@ -25,6 +25,28 @@
|
|||||||
|
|
||||||
#include "assuan-defs.h"
|
#include "assuan-defs.h"
|
||||||
|
|
||||||
|
AssuanError
|
||||||
|
assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line)
|
||||||
|
{
|
||||||
|
if (!ctx)
|
||||||
|
return ASSUAN_Invalid_Value;
|
||||||
|
if (!line)
|
||||||
|
{
|
||||||
|
xfree (ctx->hello_line);
|
||||||
|
ctx->hello_line = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char *buf = xtrymalloc (3+strlen(line)+1);
|
||||||
|
if (!buf)
|
||||||
|
return ASSUAN_Out_Of_Core;
|
||||||
|
strcpy (buf, "OK ");
|
||||||
|
strcpy (buf+3, line);
|
||||||
|
xfree (ctx->hello_line);
|
||||||
|
ctx->hello_line = buf;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +60,7 @@
|
|||||||
* Return value: 0 on success or an error if the connection could for
|
* Return value: 0 on success or an error if the connection could for
|
||||||
* some reason not be established.
|
* some reason not be established.
|
||||||
**/
|
**/
|
||||||
int
|
AssuanError
|
||||||
assuan_accept (ASSUAN_CONTEXT ctx)
|
assuan_accept (ASSUAN_CONTEXT ctx)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -57,9 +79,8 @@ assuan_accept (ASSUAN_CONTEXT ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* send the hello */
|
/* send the hello */
|
||||||
|
rc = assuan_write_line (ctx, ctx->hello_line? ctx->hello_line
|
||||||
rc = _assuan_write_line (ctx,
|
: "OK Your orders please");
|
||||||
"OK Hello dear client - what can I do for you?");
|
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
@ -70,6 +91,7 @@ assuan_accept (ASSUAN_CONTEXT ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
assuan_get_input_fd (ASSUAN_CONTEXT ctx)
|
assuan_get_input_fd (ASSUAN_CONTEXT ctx)
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,11 @@ assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])
|
|||||||
void
|
void
|
||||||
assuan_deinit_pipe_server (ASSUAN_CONTEXT ctx)
|
assuan_deinit_pipe_server (ASSUAN_CONTEXT ctx)
|
||||||
{
|
{
|
||||||
xfree (ctx);
|
if (ctx)
|
||||||
|
{
|
||||||
|
xfree (ctx->hello_line);
|
||||||
|
xfree (ctx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,4 +71,3 @@ assuan_deinit_pipe_server (ASSUAN_CONTEXT ctx)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ typedef enum {
|
|||||||
ASSUAN_Invalid_Response = 11,
|
ASSUAN_Invalid_Response = 11,
|
||||||
ASSUAN_No_Data_Callback = 12,
|
ASSUAN_No_Data_Callback = 12,
|
||||||
ASSUAN_No_Inquire_Callback = 13,
|
ASSUAN_No_Inquire_Callback = 13,
|
||||||
|
ASSUAN_Connect_Failed = 14,
|
||||||
|
|
||||||
/* error codes above 99 are meant as status codes */
|
/* error codes above 99 are meant as status codes */
|
||||||
ASSUAN_Not_Implemented = 100,
|
ASSUAN_Not_Implemented = 100,
|
||||||
@ -130,7 +131,8 @@ void assuan_write_status (ASSUAN_CONTEXT ctx,
|
|||||||
|
|
||||||
|
|
||||||
/*-- assuan-listen.c --*/
|
/*-- assuan-listen.c --*/
|
||||||
int assuan_accept (ASSUAN_CONTEXT ctx);
|
AssuanError assuan_set_hello_line (ASSUAN_CONTEXT ctx, const char *line);
|
||||||
|
AssuanError assuan_accept (ASSUAN_CONTEXT ctx);
|
||||||
int assuan_get_input_fd (ASSUAN_CONTEXT ctx);
|
int assuan_get_input_fd (ASSUAN_CONTEXT ctx);
|
||||||
int assuan_get_output_fd (ASSUAN_CONTEXT ctx);
|
int assuan_get_output_fd (ASSUAN_CONTEXT ctx);
|
||||||
|
|
||||||
@ -161,6 +163,10 @@ AssuanError assuan_inquire (ASSUAN_CONTEXT ctx, const char *keyword,
|
|||||||
char **r_buffer, size_t *r_length, size_t maxlen);
|
char **r_buffer, size_t *r_length, size_t maxlen);
|
||||||
|
|
||||||
/*-- assuan-buffer.c --*/
|
/*-- assuan-buffer.c --*/
|
||||||
|
AssuanError assuan_read_line (ASSUAN_CONTEXT ctx,
|
||||||
|
char **line, size_t *linelen);
|
||||||
|
int assuan_pending_line (ASSUAN_CONTEXT ctx);
|
||||||
|
AssuanError assuan_write_line (ASSUAN_CONTEXT ctx, const char *line );
|
||||||
AssuanError assuan_send_data (ASSUAN_CONTEXT ctx,
|
AssuanError assuan_send_data (ASSUAN_CONTEXT ctx,
|
||||||
const void *buffer, size_t length);
|
const void *buffer, size_t length);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user