From: Marcus Brinkmann Date: Sat, 24 Nov 2001 19:31:26 +0000 (+0000) Subject: 2001-11-24 Marcus Brinkmann X-Git-Tag: gpgme-0-3-0~70 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a22eef99a2593ec5f0d7143bc901dc805983865e;p=gpgme.git 2001-11-24 Marcus Brinkmann * engine-gpgsm.c (gpgsm_status_handler): Don't break if bsearch fails. Deal with assuan read line returning more than one line (for now). --- diff --git a/gpgme/ChangeLog b/gpgme/ChangeLog index cb0c7b6..e7de915 100644 --- a/gpgme/ChangeLog +++ b/gpgme/ChangeLog @@ -1,3 +1,8 @@ +2001-11-24 Marcus Brinkmann + + * engine-gpgsm.c (gpgsm_status_handler): Don't break if bsearch fails. + Deal with assuan read line returning more than one line (for now). + 2001-11-23 Marcus Brinkmann * engine-gpgsm.c (_gpgme_gpgsm_op_sign): Implement it according to diff --git a/gpgme/engine-gpgsm.c b/gpgme/engine-gpgsm.c index bf6bf83..a41ead5 100644 --- a/gpgme/engine-gpgsm.c +++ b/gpgme/engine-gpgsm.c @@ -467,50 +467,68 @@ gpgsm_status_handler (void *opaque, int pid, int fd) int err; GpgsmObject gpgsm = opaque; ASSUAN_CONTEXT actx = gpgsm->assuan_ctx; + char *line; + int linelen; + char *next_line; assert (fd == gpgsm->assuan_ctx->inbound.fd); err = _assuan_read_line (gpgsm->assuan_ctx); - if (actx->inbound.line[0] == '#' || !actx->inbound.linelen) - return 0; /* FIXME */ + /* Assuan can currently return more than one line at once. */ + line = actx->inbound.line; - if ((actx->inbound.linelen >= 2 - && actx->inbound.line[0] == 'O' && actx->inbound.line[1] == 'K' - && (actx->inbound.line[2] == '\0' || actx->inbound.line[2] == ' ')) - || (actx->inbound.linelen >= 3 - && actx->inbound.line[0] == 'E' && actx->inbound.line[1] == 'R' - && actx->inbound.line[2] == 'R' - && (actx->inbound.line[3] == '\0' || actx->inbound.line[3] == ' '))) + while (line) { - /* FIXME Save error somewhere. */ - if (gpgsm->status.fnc) - gpgsm->status.fnc (gpgsm->status.fnc_value, STATUS_EOF, ""); - return 1; + next_line = strchr (line, '\n'); + if (next_line) + *next_line++ = 0; + linelen = strlen (line); + + if (line[0] == '#' || !linelen) + return 0; /* FIXME */ + + if ((linelen >= 2 + && line[0] == 'O' && line[1] == 'K' + && (line[2] == '\0' || line[2] == ' ')) + || (linelen >= 3 + && line[0] == 'E' && line[1] == 'R' && line[2] == 'R' + && (line[3] == '\0' || line[3] == ' '))) + { + /* FIXME Save error somewhere. */ + if (gpgsm->status.fnc) + gpgsm->status.fnc (gpgsm->status.fnc_value, STATUS_EOF, ""); + return 1; + } + /* FIXME: Parse the status and call the handler. */ + + if (linelen > 2 + && line[0] == 'S' && line[1] == ' ') + { + struct status_table_s t, *r; + char *rest; + + rest = strchr (line + 2, ' '); + if (!rest) + rest = line + linelen; /* set to an empty string */ + else + *rest++ = 0; + + t.name = line + 2; + r = bsearch (&t, status_table, DIM(status_table) - 1, + sizeof t, status_cmp); + + if (r) + { + if (gpgsm->status.fnc) + gpgsm->status.fnc (gpgsm->status.fnc_value, r->code, rest); + } + else + fprintf (stderr, "[UNKNOWN STATUS]%s %s", t.name, rest); + } + line = next_line; } - /* FIXME: Parse the status and call the handler. */ - - if (actx->inbound.linelen > 2 - && actx->inbound.line[0] == 'S' && actx->inbound.line[1] == ' ') - { - struct status_table_s t, *r; - char *rest; - - rest = strchr (actx->inbound.line + 2, ' '); - if (!rest) - rest = actx->inbound.line + actx->inbound.linelen; /* set to an empty string */ - else - *rest++ = 0; - t.name = actx->inbound.line + 2; - r = bsearch (&t, status_table, DIM(status_table) - 1, - sizeof t, status_cmp); - - if (gpgsm->status.fnc) - gpgsm->status.fnc (gpgsm->status.fnc_value, r->code, rest); - } - else - fprintf (stderr, "[UNCAUGHT STATUS]%s", actx->inbound.line); return 0; }