*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
static void remove_lookup(struct proxy_lookup *lookup)
{
+ if (lookup->watch > 0)
+ g_source_remove(lookup->watch);
+
lookup_list = g_slist_remove(lookup_list, lookup);
+ connman_service_unref(lookup->service);
g_free(lookup->url);
g_free(lookup);
}
struct proxy_lookup *lookup = user_data;
GSList *list;
- if (lookup == NULL)
+ if (!lookup)
return FALSE;
lookup->watch = 0;
for (list = driver_list; list; list = list->next) {
struct connman_proxy_driver *proxy = list->data;
- if (proxy->request_lookup == NULL)
+ if (!proxy->request_lookup)
continue;
lookup->proxy = proxy;
break;
}
- if (lookup->proxy == NULL ||
+ if (!lookup->proxy ||
lookup->proxy->request_lookup(lookup->service,
lookup->url) < 0) {
DBG("interface %s url %s", interface, url);
- if (interface == NULL)
+ if (!interface)
return 0;
lookup = g_try_new0(struct proxy_lookup, 1);
- if (lookup == NULL)
+ if (!lookup)
return 0;
lookup->token = next_lookup_token++;
lookup->cb = cb;
lookup->user_data = user_data;
lookup->url = g_strdup(url);
- lookup->service = service;
+ lookup->service = connman_service_ref(service);
- lookup->watch = g_timeout_add_seconds(0, lookup_callback, lookup);
+ lookup->watch = g_idle_add(lookup_callback, lookup);
if (lookup->watch == 0) {
g_free(lookup->url);
g_free(lookup);
}
DBG("token %u", lookup->token);
- lookup_list = g_slist_append(lookup_list, lookup);
+ lookup_list = g_slist_prepend(lookup_list, lookup);
return lookup->token;
}
if (lookup->token == token)
break;
- }
- if (lookup != NULL) {
- if (lookup->watch > 0) {
- g_source_remove(lookup->watch);
- lookup->watch = 0;
- }
+ lookup = NULL;
+ }
- if (lookup->proxy != NULL &&
- lookup->proxy->cancel_lookup != NULL)
+ if (lookup) {
+ if (lookup->proxy &&
+ lookup->proxy->cancel_lookup)
lookup->proxy->cancel_lookup(lookup->service,
lookup->url);
}
void connman_proxy_driver_lookup_notify(struct connman_service *service,
- const char *url, const char *result)
+ const char *url, const char *result)
{
GSList *list, *matches = NULL;
if (lookup->cb)
lookup->cb(result, lookup->user_data);
- matches = g_slist_append(matches, lookup);
+ matches = g_slist_prepend(matches, lookup);
}
}
- if (matches != NULL)
+ if (matches)
remove_lookups(matches);
}