]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: Add URI based constructor
authorAki Tuomi <aki.tuomi@dovecot.fi>
Fri, 21 Oct 2016 11:34:51 +0000 (14:34 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 22 Oct 2016 10:00:31 +0000 (13:00 +0300)
src/lib-program-client/program-client.c
src/lib-program-client/program-client.h

index edf14f42daa36b4a3d3e4ae3d66ff11978c3e342..047e9ed2a3ab458204db25887a9c685d34c3bc2b 100644 (file)
@@ -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)
 {
index 1067fe0288271ec422d205e0cecb364511b70c61..041a63b890358537076fdb3e7e07ee5ce73f09ab 100644 (file)
@@ -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);