Skip to content

Commit

Permalink
lib-program-client: Add URI based constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse committed Oct 19, 2016
1 parent 3f67fea commit 80521bc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/lib-program-client/program-client.c
Expand Up @@ -566,6 +566,38 @@ void program_client_switch_ioloop(struct program_client *pclient)
pclient->switch_ioloop(pclient);
}

struct program_client *
program_client_create(const char *uri, const char *const *args,
const struct program_client_settings *set,
bool noreply)
{
if (strncmp(uri, "exec:", 5) == 0) {
return program_client_local_create(
uri+5,
args,
set);
} else if (strncmp(uri, "unix:", 5) == 0) {
return program_client_unix_create(
uri+5,
args,
set, noreply);
} else if (strncmp(uri, "tcp:", 4) == 0) {
const char *host;
in_port_t port;
if (net_str2hostport(uri+4, 0, &host, &port) < 0 || port == 0) {
i_error("program-client-net: Invalid syntax, must be host:port");
return NULL;
}
return program_client_net_create(
host, port,
args,
set, noreply);
} else {
i_error("Unsupported program client scheme in '%s'", uri);
}
return NULL;
}

static
void program_client_run_callback(int result, int *context)
{
Expand Down
4 changes: 4 additions & 0 deletions src/lib-program-client/program-client.h
Expand Up @@ -41,6 +41,10 @@ program_client_net_create_ips(const struct ip_addr *ips, size_t ips_count,
in_port_t port, const char *const *args,
const struct program_client_settings *set,
bool noreply);
struct program_client *program_client_create(const char *uri,
const char *const *args,
const struct program_client_settings *set, bool noreply);

void program_client_destroy(struct program_client **_pclient);

void program_client_set_input(struct program_client *pclient,
Expand Down

0 comments on commit 80521bc

Please sign in to comment.