Factor out more common code in opts parsing.
This commit is contained in:
@@ -19,6 +19,31 @@ static char *opts_split(char **arg, char delim) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void opts_add_listen(char *host_port, incoming_connection_handler handler, void *passthrough) {
|
||||||
|
char *host = opts_split(&host_port, '/');
|
||||||
|
if (host) {
|
||||||
|
incoming_new(host, host_port, handler, passthrough);
|
||||||
|
free(host);
|
||||||
|
} else {
|
||||||
|
incoming_new(NULL, host_port, handler, passthrough);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct serializer *opts_get_serializer(char **arg) {
|
||||||
|
char *format = opts_split(arg, '=');
|
||||||
|
if (!format) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct serializer *serializer = send_get_serializer(format);
|
||||||
|
free(format);
|
||||||
|
if (!serializer) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return serializer;
|
||||||
|
}
|
||||||
|
|
||||||
bool opts_add_dump(char *arg) {
|
bool opts_add_dump(char *arg) {
|
||||||
struct serializer *serializer = send_get_serializer(arg);
|
struct serializer *serializer = send_get_serializer(arg);
|
||||||
if (!serializer) {
|
if (!serializer) {
|
||||||
@@ -40,58 +65,32 @@ bool opts_add_connect_receive(char *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool opts_add_connect_send(char *arg) {
|
bool opts_add_connect_send(char *arg) {
|
||||||
char *format = opts_split(&arg, '=');
|
struct serializer *serializer = opts_get_serializer(&arg);
|
||||||
if (!format) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct serializer *serializer = send_get_serializer(format);
|
|
||||||
if (!serializer) {
|
if (!serializer) {
|
||||||
free(format);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *host = opts_split(&arg, '/');
|
char *host = opts_split(&arg, '/');
|
||||||
if (!host) {
|
if (!host) {
|
||||||
free(format);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
incoming_new(host, arg, send_add_wrapper, serializer);
|
incoming_new(host, arg, send_add_wrapper, serializer);
|
||||||
free(format);
|
|
||||||
free(host);
|
free(host);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool opts_add_listen_receive(char *arg) {
|
bool opts_add_listen_receive(char *arg) {
|
||||||
char *host = opts_split(&arg, '/');
|
opts_add_listen(arg, receive_new, NULL);
|
||||||
if (host) {
|
|
||||||
incoming_new(host, arg, receive_new, NULL);
|
|
||||||
free(host);
|
|
||||||
} else {
|
|
||||||
incoming_new(NULL, arg, receive_new, NULL);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool opts_add_listen_send(char *arg) {
|
bool opts_add_listen_send(char *arg) {
|
||||||
char *format = opts_split(&arg, '=');
|
struct serializer *serializer = opts_get_serializer(&arg);
|
||||||
if (!format) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct serializer *serializer = send_get_serializer(format);
|
|
||||||
if (!serializer) {
|
if (!serializer) {
|
||||||
free(format);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *host = opts_split(&arg, '/');
|
opts_add_listen(arg, send_add_wrapper, serializer);
|
||||||
if (host) {
|
|
||||||
incoming_new(host, arg, send_add_wrapper, serializer);
|
|
||||||
free(host);
|
|
||||||
} else {
|
|
||||||
incoming_new(NULL, arg, send_add_wrapper, serializer);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user