aboutsummaryrefslogtreecommitdiffstats
path: root/assuan/assuan-pipe-server.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--assuan/assuan-pipe-server.c54
1 files changed, 38 insertions, 16 deletions
diff --git a/assuan/assuan-pipe-server.c b/assuan/assuan-pipe-server.c
index c283a925f..d15f54f5a 100644
--- a/assuan/assuan-pipe-server.c
+++ b/assuan/assuan-pipe-server.c
@@ -45,8 +45,10 @@ finish_connection (ASSUAN_CONTEXT ctx)
}
+/* Create a new context. Note that the handlers are set up for a pipe
+ server/client - this wau we don't need extra dummy functions */
int
-assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])
+_assuan_new_context (ASSUAN_CONTEXT *r_ctx)
{
ASSUAN_CONTEXT ctx;
int rc;
@@ -55,15 +57,14 @@ assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])
ctx = xtrycalloc (1, sizeof *ctx);
if (!ctx)
return ASSUAN_Out_Of_Core;
- ctx->is_server = 1;
ctx->input_fd = -1;
ctx->output_fd = -1;
- ctx->inbound.fd = filedes[0];
- ctx->outbound.fd = filedes[1];
+ ctx->inbound.fd = -1;
+ ctx->outbound.fd = -1;
- ctx->pipe_mode = 1;
ctx->listen_fd = -1;
+ /* use the pipe server handler as a default */
ctx->deinit_handler = deinit_pipe_server;
ctx->accept_handler = accept_connection;
ctx->finish_handler = finish_connection;
@@ -77,6 +78,37 @@ assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])
}
+
+int
+assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2])
+{
+ int rc;
+
+ rc = _assuan_new_context (r_ctx);
+ if (!rc)
+ {
+ ASSUAN_CONTEXT ctx = *r_ctx;
+
+ ctx->is_server = 1;
+ ctx->inbound.fd = filedes[0];
+ ctx->outbound.fd = filedes[1];
+ ctx->pipe_mode = 1;
+ }
+ return rc;
+}
+
+
+void
+_assuan_release_context (ASSUAN_CONTEXT ctx)
+{
+ if (ctx)
+ {
+ xfree (ctx->hello_line);
+ xfree (ctx->okay_line);
+ xfree (ctx);
+ }
+}
+
void
assuan_deinit_server (ASSUAN_CONTEXT ctx)
{
@@ -86,16 +118,6 @@ assuan_deinit_server (ASSUAN_CONTEXT ctx)
when not needed but still allow for a generic deinit function */
ctx->deinit_handler (ctx);
ctx->deinit_handler = NULL;
- xfree (ctx->hello_line);
- xfree (ctx->okay_line);
- xfree (ctx);
+ _assuan_release_context (ctx);
}
}
-
-
-
-
-
-
-
-