#include <connman/plugin.h>
#include <connman/resolver.h>
#include <connman/notifier.h>
+#include <connman/ondemand.h>
#include <connman/log.h>
#include <glib.h>
DBG("Received %d bytes (id 0x%04x)", len, buf[0] | buf[1] << 8);
err = parse_request(buf, len, query, sizeof(query));
- if (err < 0 || g_slist_length(server_list) == 0) {
+ if (err < 0 || (g_slist_length(server_list) == 0 &&
+ connman_ondemand_connected())) {
send_response(sk, buf, len, (struct sockaddr *) &sin, size);
return TRUE;
}
buf[0] = req->dstid & 0xff;
buf[1] = req->dstid >> 8;
+ if (!connman_ondemand_connected()) {
+ DBG("Starting on demand connection");
+ /*
+ * We're not connected, let's queue the request and start
+ * an on-demand connection.
+ */
+ req->request = g_try_malloc0(req->request_len);
+ if (req->request == NULL)
+ return TRUE;
+
+ memcpy(req->request, buf, req->request_len);
+
+ req->name = g_try_malloc0(sizeof(query));
+ if (req->name == NULL) {
+ g_free(req->request);
+ return TRUE;
+ }
+ memcpy(req->name, query, sizeof(query));
+
+ request_pending_list = g_slist_append(request_pending_list,
+ req);
+
+ connman_ondemand_start("", 300);
+
+ return TRUE;
+ }
+
return resolv(req, buf, query);
}