summaryrefslogtreecommitdiff
path: root/src/assuan-connect.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2001-12-12 09:17:23 +0000
committerWerner Koch <wk@gnupg.org>2001-12-12 09:17:23 +0000
commitfa5bb5013db68a145938661777fa65df467fce1d (patch)
tree3eca86186ae4b47004163726fc00d68313c2267f /src/assuan-connect.c
parent7f3bee654181f1af9468c1cd2e46fd1bd2e6738a (diff)
downloadlibassuan-fa5bb5013db68a145938661777fa65df467fce1d.tar.gz
* 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.
Diffstat (limited to 'src/assuan-connect.c')
-rw-r--r--src/assuan-connect.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/assuan-connect.c b/src/assuan-connect.c
index abc5d74..683c7f0 100644
--- a/src/assuan-connect.c
+++ b/src/assuan-connect.c
@@ -40,6 +40,7 @@
#endif
#ifdef HAVE_JNLIB_LOGGING
+#include "../jnlib/logging.h"
#define LOGERROR1(a,b) log_error ((a), (b))
#else
#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 (wp[0]);
- _assuan_read_line (*ctx); /* FIXME: Handshake. */
-#if 0 /* old stuff */
- inbound.eof = 0;
- inbound.linelen = 0;
- inbound.attic.linelen = 0;
+ /* initial handshake */
+ {
+ int okay, off;
+
+ err = _assuan_read_from_server (*ctx, &okay, &off);
+ if (err)
+ {
+ 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;
+ }
+ }
- /* The server is available - read the greeting */
- rc = read_from_agent (&okay);
- if (rc)
- {
- log_error ("can't connect to the agent: %s\n", gnupg_strerror (rc));
- }
- else if (!okay)
+ if (err)
{
- log_error ("can't connect to the agent: %s\n", inbound.line);
- rc = seterr (No_Agent);
+ 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
-#endif
-
- return 0;
+ return err;
}
void
assuan_pipe_disconnect (ASSUAN_CONTEXT ctx)
{
- _assuan_write_line (ctx, "BYE");
+ assuan_write_line (ctx, "BYE");
close (ctx->inbound.fd);
close (ctx->outbound.fd);
waitpid (ctx->pid, NULL, 0); /* FIXME Check return value. */