From: Aki Tuomi Date: Fri, 21 Oct 2016 11:34:51 +0000 (+0300) Subject: lib-program-client: Add URI based constructor X-Git-Tag: 2.2.26~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=959c2cf5c0468a11c8918a18a63a4690bfd3fce1;p=thirdparty%2Fdovecot%2Fcore.git lib-program-client: Add URI based constructor --- diff --git a/src/lib-program-client/program-client.c b/src/lib-program-client/program-client.c index edf14f42da..047e9ed2a3 100644 --- a/src/lib-program-client/program-client.c +++ b/src/lib-program-client/program-client.c @@ -571,6 +571,32 @@ void program_client_switch_ioloop(struct program_client *pclient) pclient->switch_ioloop(pclient); } +int program_client_create(const char *uri, const char *const *args, + const struct program_client_settings *set, + bool noreply, struct program_client **pc_r, + const char **error_r) +{ + if (strncmp(uri, "exec:", 5) == 0) { + *pc_r = program_client_local_create( + uri+5, + args, + set); + return 0; + } else if (strncmp(uri, "unix:", 5) == 0) { + *pc_r = program_client_remote_create( + uri+5, + args, + set, noreply); + return 0; + } else { + *error_r = t_strdup_printf( + "Unsupported program client scheme '%s'", + t_strcut(uri, ':')); + return -1; + } +} + + static void program_client_run_callback(int result, int *context) { diff --git a/src/lib-program-client/program-client.h b/src/lib-program-client/program-client.h index 1067fe0288..041a63b890 100644 --- a/src/lib-program-client/program-client.h +++ b/src/lib-program-client/program-client.h @@ -31,6 +31,10 @@ struct program_client *program_client_local_create(const char *bin_path, struct program_client *program_client_remote_create(const char *socket_path, const char *const *args, const struct program_client_settings *set, bool noreply); +int program_client_create(const char *uri, const char *const *args, + const struct program_client_settings *set, + bool noreply, struct program_client **pc_r, + const char **error_r); void program_client_destroy(struct program_client **_pclient);