X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=plugins%2Fpacrunner.c;h=9c652f3b188af9f4147bbf6613ef7c6e8ede82d7;hb=4b56bbc05a7e48de6209d03280c60bf53fceb91f;hp=3a21011a7fef84e721c9b3e41111a44ed783b0d4;hpb=f51b128435835e903b54f07a7e96449260b5f371;p=platform%2Fupstream%2Fconnman.git diff --git a/plugins/pacrunner.c b/plugins/pacrunner.c old mode 100644 new mode 100755 index 3a21011..9c652f3 --- a/plugins/pacrunner.c +++ b/plugins/pacrunner.c @@ -2,7 +2,7 @@ * * Connection Manager * - * Copyright (C) 2007-2010 Intel Corporation. All rights reserved. + * Copyright (C) 2007-2013 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 @@ -24,6 +24,7 @@ #endif #include +#include #include @@ -32,13 +33,22 @@ #include #include #include +#include #define PACRUNNER_SERVICE "org.pacrunner" #define PACRUNNER_INTERFACE "org.pacrunner.Manager" #define PACRUNNER_PATH "/org/pacrunner/manager" +#define PACRUNNER_CLIENT_INTERFACE "org.pacrunner.Client" +#define PACRUNNER_CLIENT_PATH "/org/pacrunner/client" + #define DBUS_TIMEOUT 5000 +struct proxy_data { + struct connman_service *service; + char *url; +}; + static DBusConnection *connection; static dbus_bool_t daemon_running = FALSE; @@ -57,8 +67,8 @@ static void create_config_reply(DBusPendingCall *call, void *user_data) goto done; } - if (dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, &path, - DBUS_TYPE_INVALID) == FALSE) + if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_OBJECT_PATH, + &path, DBUS_TYPE_INVALID)) goto done; g_free(current_config); @@ -68,9 +78,14 @@ done: dbus_message_unref(reply); } -static void append_string(DBusMessageIter *iter, void *user_data) +static void append_string_list(DBusMessageIter *iter, void *user_data) { - dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, user_data); + char **list = user_data; + int i; + + for (i = 0; list[i]; i++) + dbus_message_iter_append_basic(iter, + DBUS_TYPE_STRING, &list[i]); } static void create_proxy_configuration(void) @@ -80,16 +95,18 @@ static void create_proxy_configuration(void) DBusPendingCall *call; dbus_bool_t result; char *interface; + const char *method; const char *str; + char **str_list; - if (default_service == NULL) + if (!default_service) return; DBG(""); msg = dbus_message_new_method_call(PACRUNNER_SERVICE, PACRUNNER_PATH, PACRUNNER_INTERFACE, "CreateProxyConfiguration"); - if (msg == NULL) + if (!msg) return; dbus_message_set_auto_start(msg, FALSE); @@ -97,49 +114,86 @@ static void create_proxy_configuration(void) dbus_message_iter_init_append(msg, &iter); connman_dbus_dict_open(&iter, &dict); + switch(connman_service_get_proxy_method(default_service)) { + case CONNMAN_SERVICE_PROXY_METHOD_UNKNOWN: + connman_dbus_dict_close(&iter, &dict); + goto done; + case CONNMAN_SERVICE_PROXY_METHOD_DIRECT: + method= "direct"; + break; + case CONNMAN_SERVICE_PROXY_METHOD_MANUAL: + method = "manual"; + + str_list = connman_service_get_proxy_servers(default_service); + if (!str_list) { + connman_dbus_dict_close(&iter, &dict); + goto done; + } + + connman_dbus_dict_append_array(&dict, "Servers", + DBUS_TYPE_STRING, append_string_list, + str_list); + g_strfreev(str_list); + + str_list = connman_service_get_proxy_excludes(default_service); + if (!str_list) + break; + + connman_dbus_dict_append_array(&dict, "Excludes", + DBUS_TYPE_STRING, append_string_list, + str_list); + g_strfreev(str_list); + + break; + case CONNMAN_SERVICE_PROXY_METHOD_AUTO: + method = "auto"; + + str = connman_service_get_proxy_url(default_service); + if (!str) { + str = connman_service_get_proxy_autoconfig( + default_service); + if (!str) { + connman_dbus_dict_close(&iter, &dict); + goto done; + } + } + + connman_dbus_dict_append_basic(&dict, "URL", + DBUS_TYPE_STRING, &str); + break; + } + + connman_dbus_dict_append_basic(&dict, "Method", + DBUS_TYPE_STRING, &method); + interface = connman_service_get_interface(default_service); - if (interface != NULL) { + if (interface) { connman_dbus_dict_append_basic(&dict, "Interface", DBUS_TYPE_STRING, &interface); g_free(interface); } - str = connman_service_get_proxy_autoconfig(default_service); - if (str != NULL) { - const char *method = "auto"; - connman_dbus_dict_append_basic(&dict, "Method", - DBUS_TYPE_STRING, &method); - connman_dbus_dict_append_basic(&dict, "URL", - DBUS_TYPE_STRING, &str); - } else { - const char *method = "direct"; - connman_dbus_dict_append_basic(&dict, "Method", - DBUS_TYPE_STRING, &method); - } - - str = connman_service_get_domainname(default_service); - if (str != NULL) - connman_dbus_dict_append_array(&dict, "Domains", - DBUS_TYPE_STRING, append_string, &str); - - str = connman_service_get_nameserver(default_service); - if (str != NULL) + str_list = connman_service_get_nameservers(default_service); + if (str_list) connman_dbus_dict_append_array(&dict, "Nameservers", - DBUS_TYPE_STRING, append_string, &str); + DBUS_TYPE_STRING, append_string_list, + str_list); + g_strfreev(str_list); connman_dbus_dict_close(&iter, &dict); result = dbus_connection_send_with_reply(connection, msg, &call, DBUS_TIMEOUT); - dbus_message_unref(msg); - - if (result == FALSE || call == NULL) - return; + if (!result || !call) + goto done; dbus_pending_call_set_notify(call, create_config_reply, NULL, NULL); dbus_pending_call_unref(call); + +done: + dbus_message_unref(msg); } static void destroy_config_reply(DBusPendingCall *call, void *user_data) @@ -160,14 +214,14 @@ static void destroy_proxy_configuration(void) DBusPendingCall *call; dbus_bool_t result; - if (current_config == NULL) + if (!current_config) return; DBG(""); msg = dbus_message_new_method_call(PACRUNNER_SERVICE, PACRUNNER_PATH, PACRUNNER_INTERFACE, "DestroyProxyConfiguration"); - if (msg == NULL) + if (!msg) return; dbus_message_set_auto_start(msg, FALSE); @@ -180,7 +234,7 @@ static void destroy_proxy_configuration(void) dbus_message_unref(msg); - if (result == FALSE || call == NULL) + if (!result || !call) return; dbus_pending_call_set_notify(call, destroy_config_reply, NULL, NULL); @@ -200,7 +254,7 @@ static void default_service_changed(struct connman_service *service) default_service = service; - if (daemon_running == FALSE) + if (!daemon_running) return; destroy_proxy_configuration(); @@ -208,9 +262,25 @@ static void default_service_changed(struct connman_service *service) create_proxy_configuration(); } -static struct connman_notifier pacrunner_notifier = { +static void proxy_changed(struct connman_service *service) +{ + DBG("service %p", service); + + if (service != default_service) + return; + + if (!daemon_running) + return; + + destroy_proxy_configuration(); + + create_proxy_configuration(); +} + +static const struct connman_notifier pacrunner_notifier = { .name = "pacrunner", .default_changed = default_service_changed, + .proxy_changed = proxy_changed, }; static void pacrunner_connect(DBusConnection *conn, void *user_data) @@ -232,12 +302,137 @@ static void pacrunner_disconnect(DBusConnection *conn, void *user_data) current_config = NULL; } +static char * parse_url(const char *url) +{ + char *scheme, *host, *path, *host_ret; + + scheme = g_strdup(url); + if (!scheme) + return NULL; + + host = strstr(scheme, "://"); + if (host) { + *host = '\0'; + host += 3; + } else + host = scheme; + + path = strchr(host, '/'); + if (path) + *(path++) = '\0'; + + host_ret = g_strdup(host); + + g_free(scheme); + + return host_ret; +} + +static void request_lookup_reply(DBusPendingCall *call, void *user_data) +{ + DBusMessage *reply = dbus_pending_call_steal_reply(call); + struct proxy_data *data = user_data; + const char *proxy; + + DBG(""); + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + connman_error("Failed to find URL:%s", data->url); + proxy = NULL; + goto done; + } + + if (!dbus_message_get_args(reply, NULL, DBUS_TYPE_STRING, + &proxy, DBUS_TYPE_INVALID)) + proxy = NULL; + +done: + connman_proxy_driver_lookup_notify(data->service, data->url, proxy); + + connman_service_unref(data->service); + + g_free(data->url); + g_free(data); + + dbus_message_unref(reply); +} + +static int request_lookup(struct connman_service *service, const char *url) +{ + DBusMessage *msg; + DBusPendingCall *call; + dbus_bool_t result; + char *host; + struct proxy_data *data; + + DBG(""); + + msg = dbus_message_new_method_call(PACRUNNER_SERVICE, + PACRUNNER_CLIENT_PATH, + PACRUNNER_CLIENT_INTERFACE, + "FindProxyForURL"); + if (!msg) + return -1; + + host = parse_url(url); + if (!host) { + dbus_message_unref(msg); + return -EINVAL; + } + + data = g_try_new0(struct proxy_data, 1); + if (!data) { + dbus_message_unref(msg); + g_free(host); + return -ENOMEM; + } + + data->url = g_strdup(url); + data->service = connman_service_ref(service); + + dbus_message_append_args(msg, DBUS_TYPE_STRING, &url, + DBUS_TYPE_STRING, &host, + DBUS_TYPE_INVALID); + + result = dbus_connection_send_with_reply(connection, msg, + &call, DBUS_TIMEOUT); + + dbus_message_unref(msg); + + if (!result || !call) { + g_free(host); + g_free(data->url); + g_free(data); + return -EINVAL; + } + + dbus_pending_call_set_notify(call, request_lookup_reply, + data, NULL); + + dbus_pending_call_unref(call); + g_free(host); + + return 0; +} + +static void cancel_lookup(struct connman_service *service, const char *url) +{ + DBG(""); +} + +static struct connman_proxy_driver pacrunner_proxy = { + .name = "pacrunnerproxy", + .priority = CONNMAN_PROXY_PRIORITY_HIGH, + .request_lookup = request_lookup, + .cancel_lookup = cancel_lookup, +}; + static guint pacrunner_watch; static int pacrunner_init(void) { connection = connman_dbus_get_connection(); - if (connection == NULL) + if (!connection) return -EIO; pacrunner_watch = g_dbus_add_service_watch(connection, @@ -250,11 +445,15 @@ static int pacrunner_init(void) connman_notifier_register(&pacrunner_notifier); + connman_proxy_driver_register(&pacrunner_proxy); + return 0; } static void pacrunner_exit(void) { + connman_proxy_driver_unregister(&pacrunner_proxy); + connman_notifier_unregister(&pacrunner_notifier); g_dbus_remove_watch(connection, pacrunner_watch);