* exec.c (make_tempdir) [_WIN32]: Modified to properly handle
[gnupg.git] / util / assuan-connect.c
blob9952b44060759346ed0a7a4bd5ab27f84472bb8f
1 /* assuan-connect.c - Establish a connection (client)
2 * Copyright (C) 2001, 2002 Free Software Foundation, Inc.
4 * This file is part of Assuan.
6 * Assuan is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * Assuan is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 * USA.
22 /* Please note that this is a stripped down and modified version of
23 the orginal Assuan code from libassuan. */
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <signal.h>
33 #include <unistd.h>
34 #include <errno.h>
35 #include <sys/types.h>
36 #ifndef HAVE_W32_SYSTEM
37 #include <sys/wait.h>
38 #endif
40 #include "assuan-defs.h"
42 /* Create a new context. */
43 int
44 _assuan_new_context (assuan_context_t *r_ctx)
46 assuan_context_t ctx;
48 *r_ctx = NULL;
49 ctx = xcalloc (1, sizeof *ctx);
51 ctx->input_fd = -1;
52 ctx->output_fd = -1;
54 ctx->inbound.fd = -1;
55 ctx->outbound.fd = -1;
56 ctx->io = NULL;
58 ctx->listen_fd = -1;
59 *r_ctx = ctx;
60 return 0;
64 void
65 _assuan_release_context (assuan_context_t ctx)
67 if (ctx)
69 xfree (ctx->hello_line);
70 xfree (ctx->okay_line);
71 xfree (ctx);
76 /* Disconnect and release the context CTX. */
77 void
78 assuan_disconnect (assuan_context_t ctx)
80 if (ctx)
82 assuan_write_line (ctx, "BYE");
83 ctx->finish_handler (ctx);
84 ctx->deinit_handler (ctx);
85 ctx->deinit_handler = NULL;
86 _assuan_release_context (ctx);
90 /* Return the PID of the peer or -1 if not known. */
91 pid_t
92 assuan_get_pid (assuan_context_t ctx)
94 return (ctx && ctx->pid)? ctx->pid : -1;