diff --git a/src/bin/empdd.c b/src/bin/empdd.c index c80d381..63442a3 100644 --- a/src/bin/empdd.c +++ b/src/bin/empdd.c @@ -283,20 +283,21 @@ static void reconnect(const char *host, int port, const char *pass) { struct mpd_settings *s = empd->settings; - const char *h; - int p; + const char *h = host; + int p = port; if (pass && (!pass[0])) pass = NULL; - h = host && host[0] ? host : mpd_settings_get_host(empd->settings); - if (h[0] == '/') + if (s) + h = host && host[0] ? host : mpd_settings_get_host(s); + if (h && (h[0] == '/')) p = -1; - else - p = port == -1 ? (int)mpd_settings_get_port(empd->settings) : port; + else if (s) + p = port == -1 ? (int)mpd_settings_get_port(s) : port; if (host || s) s = mpd_settings_new(h, p, 3000, NULL, pass); - if ((empd->async || empd->svr) && + if ((empd->async || empd->svr) && empd->settings && ((!host) || (!host[0]) || (!strcmp(host, mpd_settings_get_host(empd->settings)))) && ((port == -1) || ((unsigned int)port == mpd_settings_get_port(empd->settings)))) { @@ -1263,22 +1264,35 @@ static Eldbus_Message * _dbus_isconnected_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) { Eldbus_Message *ret; + const char *host = ""; + unsigned int port = DEFAULT_PORT; ret = eldbus_message_method_return_new(msg); - eldbus_message_arguments_append(ret, "bsu", empd->connected, mpd_settings_get_host(empd->settings), mpd_settings_get_port(empd->settings)); + if (empd->settings) + { + host = mpd_settings_get_host(empd->settings); + port = mpd_settings_get_port(empd->settings); + } + eldbus_message_arguments_append(ret, "bsu", empd->connected, host, port); return ret; } static Eldbus_Message * _dbus_connect_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) { - const char *host, *pass; - int port; + const char *host = NULL, *pass = NULL; + int port = DEFAULT_PORT; if (!eldbus_message_arguments_get(msg, "sis", &host, &port, &pass)) return eldbus_message_method_return_new(msg); - reconnect(host, port, pass); + if (empd->settings) + reconnect(host, port, pass); + else + { + empd->settings = mpd_settings_new(host, port, 3000, NULL, pass); + reconnect(NULL, -1, NULL); + } return eldbus_message_method_return_new(msg); } @@ -1414,7 +1428,6 @@ main(int argc, char *argv[]) else settings = mpd_settings_new(argv[1], atoi(argv[2]), 3000, NULL, pass); - if (!settings) return 1; empd = calloc(1, sizeof(EMPD)); empd->settings = settings; ecore_app_no_system_modules(); @@ -1439,7 +1452,8 @@ main(int argc, char *argv[]) E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DEL, del, NULL); E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DATA, data_cb, NULL); - reconnect(NULL, -1, NULL); + if (settings) + reconnect(NULL, -1, NULL); ecore_main_loop_begin(); return 0;