From: Patrik Flykt <[email protected]>

Create agent.h header file defining function
connman_agent_openconnect_request_cookie() used by the
openconnect vpn plugin. Implement the functionality by adding
'OpenConnect.Cookie' and 'Hostname' fields to the 'RequestInput'
Agent API method call. The value of the hostname is to be
provided by the openconnect plugin.
---
 Makefile.am     |    2 +-
 include/agent.h |   40 ++++++++++++++++
 src/agent.c     |  134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/connman.h   |    2 +
 4 files changed, 177 insertions(+), 1 deletions(-)
 create mode 100644 include/agent.h

diff --git a/Makefile.am b/Makefile.am
index d5a76f9..c7739ac 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,7 +7,7 @@ include_HEADERS = include/types.h include/log.h 
include/plugin.h \
                        include/notifier.h include/service.h \
                        include/resolver.h include/ipconfig.h \
                        include/device.h include/network.h include/inet.h \
-                       include/storage.h
+                       include/storage.h include/agent.h
 
 nodist_include_HEADERS = include/version.h
 
diff --git a/include/agent.h b/include/agent.h
new file mode 100644
index 0000000..fc1bbf8
--- /dev/null
+++ b/include/agent.h
@@ -0,0 +1,40 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 2011  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
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef __CONNMAN_AGENT_H
+#define __CONNMAN_AGENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct connman_service;
+
+typedef void (* openconnect_cb_t)(const char *cookie, void *cb_data);
+
+int connman_agent_openconnect_request_cookie(struct connman_service *service,
+               const char *host, openconnect_cb_t cb, void *cb_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __CONNMAN_AGENT_H */
diff --git a/src/agent.c b/src/agent.c
index 1c982ed..9c52507 100644
--- a/src/agent.c
+++ b/src/agent.c
@@ -546,6 +546,140 @@ int __connman_agent_report_error(struct connman_service 
*service,
        return -EIO;
 }
 
+struct openconnect_data {
+       openconnect_cb_t cb;
+       void *cb_data;
+};
+
+static void openconnect_cookie_reply(DBusPendingCall *call, void *user_data)
+{
+       struct openconnect_data *oc_data = user_data;
+       char *cookie = NULL;
+       char *key;
+       DBusMessageIter iter, dict;
+       DBusMessage *reply = dbus_pending_call_steal_reply(call);
+
+       if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR)
+               goto error;
+
+       dbus_message_iter_init(reply, &iter);
+       dbus_message_iter_recurse(&iter, &dict);
+       while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) {
+               DBusMessageIter entry, value;
+
+               dbus_message_iter_recurse(&dict, &entry);
+               if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+                       break;
+
+               dbus_message_iter_get_basic(&entry, &key);
+
+               if (g_str_equal(key, "OpenConnect.Cookie")) {
+                       dbus_message_iter_next(&entry);
+                       if (dbus_message_iter_get_arg_type(&entry)
+                                                       != DBUS_TYPE_VARIANT)
+                               break;
+
+                       dbus_message_iter_recurse(&entry, &value);
+                       dbus_message_iter_get_basic(&value, &cookie);
+                       break;
+               }
+               dbus_message_iter_next(&dict);
+       }
+
+error:
+       oc_data->cb(cookie, oc_data->cb_data);
+       dbus_message_unref(reply);
+       g_free(oc_data);
+}
+
+static void request_input_append_hostname(DBusMessageIter *iter,
+               void *user_data)
+{
+       char *host = user_data;
+       char *str;
+
+       if (host == NULL)
+               return;
+
+       str = "string";
+       connman_dbus_dict_append_basic(iter, "Type",
+                               DBUS_TYPE_STRING, &str);
+
+       connman_dbus_dict_append_basic(iter, "Value",
+                               DBUS_TYPE_STRING, &host);
+}
+
+static void request_input_append_mandatory_string(DBusMessageIter *iter,
+               void *user_data)
+{
+       char *str;
+
+       str = "string";
+       connman_dbus_dict_append_basic(iter, "Type",
+                               DBUS_TYPE_STRING, &str);
+       str = "Mandatory";
+       connman_dbus_dict_append_basic(iter, "Requirement",
+                               DBUS_TYPE_STRING, &str);
+}
+
+int connman_agent_openconnect_request_cookie(struct connman_service *service,
+               const char *host,
+               openconnect_cb_t cb, void *cb_data)
+{
+       DBusMessage *message;
+       DBusMessageIter iter, dict;
+       const char *path;
+       DBusPendingCall *call;
+       struct openconnect_data *oc_data;
+
+       if (host == NULL || cb == NULL)
+               return -ESRCH;
+
+       message = dbus_message_new_method_call(agent_sender, agent_path,
+                                       CONNMAN_AGENT_INTERFACE,
+                                       "RequestInput");
+       if (message == NULL)
+               return -ENOMEM;
+
+       dbus_message_iter_init_append(message, &iter);
+
+       path = __connman_service_get_path(service);
+       dbus_message_iter_append_basic(&iter,
+                               DBUS_TYPE_OBJECT_PATH, &path);
+
+       connman_dbus_dict_open(&iter, &dict);
+
+       connman_dbus_dict_append_dict(&dict, "Hostname",
+                       request_input_append_hostname, (void *)host);
+
+       connman_dbus_dict_append_dict(&dict, "OpenConnect.Cookie",
+                               request_input_append_mandatory_string, NULL);
+
+       connman_dbus_dict_close(&iter, &dict);
+
+       oc_data = g_try_new0(struct openconnect_data, 1);
+       if (oc_data == NULL) {
+               dbus_message_unref(message);
+               return -ENOMEM;
+       }
+
+       if (dbus_connection_send_with_reply(connection, message,
+                                       &call, -1) == FALSE || call == NULL) {
+               dbus_message_unref(message);
+               g_free(oc_data);
+               return -ESRCH;
+       }
+       oc_data->cb = cb;
+       oc_data->cb_data = cb_data;
+
+       dbus_pending_call_set_notify(call, openconnect_cookie_reply,
+                       oc_data, NULL);
+
+       dbus_message_unref(message);
+
+       return -EIO;
+}
+
 int __connman_agent_init(void)
 {
        DBG("");
diff --git a/src/connman.h b/src/connman.h
index 906483a..6625037 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -80,6 +80,8 @@ int __connman_counter_unregister(const char *owner, const 
char *path);
 int __connman_counter_init(void);
 void __connman_counter_cleanup(void);
 
+#include <connman/agent.h>
+
 struct connman_service;
 
 typedef void (* authentication_cb_t) (struct connman_service *service,
-- 
1.7.2.5

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to