aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-30 17:08:58 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-03-30 17:08:58 +0100
commit7883c67c16b869e562b0fcdda103d76fafeb0f52 (patch)
treec2808388a999f86a7a606ff57c5123e2dce93263 /src
parent2509c1e9b5b6bf3a7364b79fbc644335df425970 (diff)
downloadrspamd-7883c67c16b869e562b0fcdda103d76fafeb0f52.tar.gz
rspamd-7883c67c16b869e562b0fcdda103d76fafeb0f52.zip
[Fix] Improve parsing of the connect string for the client
Diffstat (limited to 'src')
-rw-r--r--src/client/rspamc.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/client/rspamc.c b/src/client/rspamc.c
index 30d1b57cc..f3d8f1fc8 100644
--- a/src/client/rspamc.c
+++ b/src/client/rspamc.c
@@ -1251,31 +1251,47 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd,
FILE *in, const gchar *name, GQueue *attrs)
{
struct rspamd_client_connection *conn;
- gchar **connectv;
+ gchar *hostbuf = NULL, *p;
guint16 port;
GError *err = NULL;
struct rspamc_callback_data *cbdata;
- connectv = g_strsplit_set (connect_str, ":", -1);
+ if (connect_str[0] == '[') {
+ p = strrchr (connect_str, ']');
- if (connectv == NULL || connectv[0] == NULL) {
- fprintf (stderr, "bad connect string: %s\n", connect_str);
- exit (EXIT_FAILURE);
+ if (p != NULL) {
+ hostbuf = g_malloc (p - connect_str);
+ rspamd_strlcpy (hostbuf, connect_str + 1, p - connect_str);
+ p ++;
+ }
+ else {
+ p = connect_str;
+ }
}
+ else {
+ p = connect_str;
+ }
+
+ p = strrchr (p, ':');
- if (connectv[1] != NULL) {
- port = strtoul (connectv[1], NULL, 10);
+ if (p != NULL) {
+ port = strtoul (p + 1, NULL, 10);
}
- else if (*connectv[0] != '/') {
+ else {
port = cmd->is_controller ? DEFAULT_CONTROL_PORT : DEFAULT_PORT;
}
- else {
- /* Unix socket */
- port = 0;
+
+ if (!hostbuf) {
+ if (p != NULL) {
+ hostbuf = g_malloc (p - connect_str + 1);
+ rspamd_strlcpy (hostbuf, connect_str, p - connect_str + 1);
+ }
+ else {
+ hostbuf = g_strdup (connect_str);
+ }
}
- conn = rspamd_client_init (ev_base, connectv[0], port, timeout, key);
- g_strfreev (connectv);
+ conn = rspamd_client_init (ev_base, hostbuf, port, timeout, key);
if (conn != NULL) {
cbdata = g_slice_alloc (sizeof (struct rspamc_callback_data));
@@ -1297,6 +1313,8 @@ rspamc_process_input (struct event_base *ev_base, struct rspamc_command *cmd,
&err);
}
}
+
+ g_free (hostbuf);
}
static void