mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
(assuan_process): Moved bulk of function to ..
(process_request): .. new. (assuan_process_next): One shot version of above. (assuan_get_active_fds): New. NOTE - this has not been tested yet.
This commit is contained in:
parent
c0d12ef3fb
commit
8cf367848a
@ -4,6 +4,10 @@
|
|||||||
(assuan_register_reset_notify)
|
(assuan_register_reset_notify)
|
||||||
(assuan_register_cancel_notify): New and call them from the
|
(assuan_register_cancel_notify): New and call them from the
|
||||||
standard handlers.
|
standard handlers.
|
||||||
|
(assuan_process): Moved bulk of function to ..
|
||||||
|
(process_request): .. new.
|
||||||
|
(assuan_process_next): One shot version of above.
|
||||||
|
(assuan_get_active_fds): New.
|
||||||
|
|
||||||
2001-11-24 Werner Koch <wk@gnupg.org>
|
2001-11-24 Werner Koch <wk@gnupg.org>
|
||||||
|
|
||||||
|
@ -323,35 +323,17 @@ dispatch_command (ASSUAN_CONTEXT ctx, char *line, int linelen)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
static int
|
||||||
* assuan_process:
|
process_request (ASSUAN_CONTEXT ctx)
|
||||||
* @ctx: assuan context
|
|
||||||
*
|
|
||||||
* This fucntion is used to handle the assuan protocol after a
|
|
||||||
* connection has been established using assuan_accept(). This is the
|
|
||||||
* main protocol handler.
|
|
||||||
*
|
|
||||||
* Return value: 0 on success or an error code if the assuan operation
|
|
||||||
* failed. Note, that no error is returned for operational errors.
|
|
||||||
**/
|
|
||||||
int
|
|
||||||
assuan_process (ASSUAN_CONTEXT ctx)
|
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
do {
|
|
||||||
/* Read the line but skip comments */
|
|
||||||
do
|
|
||||||
{
|
|
||||||
rc = _assuan_read_line (ctx);
|
rc = _assuan_read_line (ctx);
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
if (*ctx->inbound.line == '#' || !ctx->inbound.linelen)
|
||||||
/* fprintf (stderr, "DBG-assuan: got %d bytes `%s'\n", */
|
return 0; /* comment line - ignore */
|
||||||
/* ctx->inbound.linelen, ctx->inbound.line); */
|
|
||||||
}
|
|
||||||
while ( *ctx->inbound.line == '#' || !ctx->inbound.linelen);
|
|
||||||
|
|
||||||
ctx->outbound.data.error = 0;
|
ctx->outbound.data.error = 0;
|
||||||
ctx->outbound.data.linelen = 0;
|
ctx->outbound.data.linelen = 0;
|
||||||
@ -390,6 +372,28 @@ assuan_process (ASSUAN_CONTEXT ctx)
|
|||||||
}
|
}
|
||||||
rc = _assuan_write_line (ctx, errline);
|
rc = _assuan_write_line (ctx, errline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* assuan_process:
|
||||||
|
* @ctx: assuan context
|
||||||
|
*
|
||||||
|
* This fucntion is used to handle the assuan protocol after a
|
||||||
|
* connection has been established using assuan_accept(). This is the
|
||||||
|
* main protocol handler.
|
||||||
|
*
|
||||||
|
* Return value: 0 on success or an error code if the assuan operation
|
||||||
|
* failed. Note, that no error is returned for operational errors.
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
assuan_process (ASSUAN_CONTEXT ctx)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
do {
|
||||||
|
rc = process_request (ctx);
|
||||||
} while (!rc);
|
} while (!rc);
|
||||||
|
|
||||||
if (rc == -1)
|
if (rc == -1)
|
||||||
@ -399,6 +403,65 @@ assuan_process (ASSUAN_CONTEXT ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* assuan_process_next:
|
||||||
|
* @ctx: Assuan context
|
||||||
|
*
|
||||||
|
* Same as assuan_process() but the user has to provide the outer
|
||||||
|
* loop. He should loop as long as the return code is zero and stop
|
||||||
|
* otherwise; -1 is regular end.
|
||||||
|
*
|
||||||
|
* See also: assuan_get_active_fds()
|
||||||
|
* Return value: -1 for end of server, 0 on success or an error code
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
assuan_process_next (ASSUAN_CONTEXT ctx)
|
||||||
|
{
|
||||||
|
return process_request (ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* assuan_get_active_fds:
|
||||||
|
* @ctx: Assuan context
|
||||||
|
* @what: 0 for read fds, 1 for write fds
|
||||||
|
* @fdarray: Caller supplied array to store the FDs
|
||||||
|
* @fdarraysize: size of that array
|
||||||
|
*
|
||||||
|
* Return all active filedescriptors for the given context. This
|
||||||
|
* function can be used to select on the fds and call
|
||||||
|
* assuan_process_next() if there is an active one.
|
||||||
|
*
|
||||||
|
* Note, that write FDs are not yet supported.
|
||||||
|
*
|
||||||
|
* Return value: number of FDs active and put into @fdarray or -1 on
|
||||||
|
* error which is most likely a too small fdarray.
|
||||||
|
**/
|
||||||
|
int
|
||||||
|
assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
|
||||||
|
int *fdarray, int fdarraysize)
|
||||||
|
{
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
if (ctx || fdarraysize < 2 || what < 0 || what > 1)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!what)
|
||||||
|
{
|
||||||
|
if (ctx->inbound.fd != -1)
|
||||||
|
fdarray[n++] = ctx->inbound.fd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (ctx->outbound.fd != -1)
|
||||||
|
fdarray[n++] = ctx->outbound.fd;
|
||||||
|
if (ctx->outbound.data.fp)
|
||||||
|
fdarray[n++] = fileno (ctx->outbound.data.fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return n;
|
||||||
|
}
|
||||||
|
|
||||||
/* Return a FP to be used for data output. The FILE pointer is valid
|
/* Return a FP to be used for data output. The FILE pointer is valid
|
||||||
until the end of a handler. So a close is not needed. Assuan does
|
until the end of a handler. So a close is not needed. Assuan does
|
||||||
all the buffering needed to insert the status line as well as the
|
all the buffering needed to insert the status line as well as the
|
||||||
|
@ -92,6 +92,11 @@ int assuan_register_reset_notify (ASSUAN_CONTEXT ctx,
|
|||||||
int assuan_register_cancel_notify (ASSUAN_CONTEXT ctx,
|
int assuan_register_cancel_notify (ASSUAN_CONTEXT ctx,
|
||||||
void (*fnc)(ASSUAN_CONTEXT));
|
void (*fnc)(ASSUAN_CONTEXT));
|
||||||
int assuan_process (ASSUAN_CONTEXT ctx);
|
int assuan_process (ASSUAN_CONTEXT ctx);
|
||||||
|
int assuan_process_next (ASSUAN_CONTEXT ctx);
|
||||||
|
int assuan_get_active_fds (ASSUAN_CONTEXT ctx, int what,
|
||||||
|
int *fdarray, int fdarraysize);
|
||||||
|
|
||||||
|
|
||||||
FILE *assuan_get_data_fp (ASSUAN_CONTEXT ctx);
|
FILE *assuan_get_data_fp (ASSUAN_CONTEXT ctx);
|
||||||
void assuan_write_status (ASSUAN_CONTEXT ctx,
|
void assuan_write_status (ASSUAN_CONTEXT ctx,
|
||||||
const char *keyword, const char *text);
|
const char *keyword, const char *text);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user