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));
&err);
}
}
+
+ g_free (hostbuf);
}
static void