vpn-agent: Add generic functions to add information into agent dict
authorJukka Rissanen <jukka.rissanen@linux.intel.com>
Fri, 30 Nov 2012 09:30:38 +0000 (11:30 +0200)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Fri, 30 Nov 2012 13:01:18 +0000 (15:01 +0200)
Makefile.am
vpn/vpn-agent.c [new file with mode: 0644]
vpn/vpn-agent.h [new file with mode: 0644]

index daca2527420af13ce43021ae0f44dd475d618f68..c0aa793b14f17849c5a4dc6ecc5c94ee6e359c67 100644 (file)
@@ -123,7 +123,8 @@ vpn_connman_vpnd_SOURCES = $(gdbus_sources) $(builtin_vpn_sources) \
                        vpn/vpn-manager.c vpn/vpn-provider.c \
                        vpn/vpn-provider.h vpn/vpn-rtnl.h \
                        vpn/vpn-ipconfig.c src/inet.c vpn/vpn-rtnl.c \
-                       src/dbus.c src/storage.c src/ipaddress.c src/agent.c
+                       src/dbus.c src/storage.c src/ipaddress.c src/agent.c \
+                       vpn/vpn-agent.c vpn/vpn-agent.h
 
 vpn_connman_vpnd_LDADD = $(builtin_vpn_libadd) @GLIB_LIBS@ @DBUS_LIBS@ \
                                @GNUTLS_LIBS@ -lresolv -ldl
diff --git a/vpn/vpn-agent.c b/vpn/vpn-agent.c
new file mode 100644 (file)
index 0000000..0281764
--- /dev/null
@@ -0,0 +1,100 @@
+/*
+ *
+ *  Connection Manager
+ *
+ *  Copyright (C) 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
+ *  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
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <gdbus.h>
+#include <connman/log.h>
+#include <connman/agent.h>
+#include <vpn/vpn-provider.h>
+
+#include "vpn-agent.h"
+#include "vpn.h"
+
+connman_bool_t vpn_agent_check_reply_has_dict(DBusMessage *reply)
+{
+       const char *signature = DBUS_TYPE_ARRAY_AS_STRING
+               DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+               DBUS_TYPE_STRING_AS_STRING
+               DBUS_TYPE_VARIANT_AS_STRING
+               DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
+
+       if (dbus_message_has_signature(reply, signature) == TRUE)
+               return TRUE;
+
+       connman_warn("Reply %s to %s from %s has wrong signature %s",
+                       signature,
+                       dbus_message_get_interface(reply),
+                       dbus_message_get_sender(reply),
+                       dbus_message_get_signature(reply));
+
+       return FALSE;
+}
+
+static void request_input_append_name(DBusMessageIter *iter, void *user_data)
+{
+       struct vpn_provider *provider = user_data;
+       const char *str = "string";
+
+       connman_dbus_dict_append_basic(iter, "Type",
+                               DBUS_TYPE_STRING, &str);
+       str = "informational";
+       connman_dbus_dict_append_basic(iter, "Requirement",
+                               DBUS_TYPE_STRING, &str);
+
+       str = vpn_provider_get_name(provider);
+       connman_dbus_dict_append_basic(iter, "Value",
+                               DBUS_TYPE_STRING, &str);
+}
+
+static void request_input_append_host(DBusMessageIter *iter, void *user_data)
+{
+       struct vpn_provider *provider = user_data;
+       const char *str = "string";
+
+       connman_dbus_dict_append_basic(iter, "Type",
+                               DBUS_TYPE_STRING, &str);
+       str = "informational";
+       connman_dbus_dict_append_basic(iter, "Requirement",
+                               DBUS_TYPE_STRING, &str);
+
+       str = vpn_provider_get_host(provider);
+       connman_dbus_dict_append_basic(iter, "Value",
+                               DBUS_TYPE_STRING, &str);
+}
+
+void vpn_agent_append_host_and_name(DBusMessageIter *iter,
+                               struct vpn_provider *provider)
+{
+       connman_dbus_dict_append_dict(iter, "Host",
+                               request_input_append_host,
+                               provider);
+
+       connman_dbus_dict_append_dict(iter, "Name",
+                               request_input_append_name,
+                               provider);
+}
diff --git a/vpn/vpn-agent.h b/vpn/vpn-agent.h
new file mode 100644 (file)
index 0000000..41b7f8c
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ *
+ *  ConnMan VPN daemon
+ *
+ *  Copyright (C) 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
+ *  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 __VPN_AGENT_H
+#define __VPN_AGENT_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * SECTION:agent
+ * @title: Agent premitives
+ * @short_description: Functions for interaction with agent
+ */
+
+void vpn_agent_append_host_and_name(DBusMessageIter *iter,
+                               struct vpn_provider *provider);
+connman_bool_t vpn_agent_check_reply_has_dict(DBusMessage *reply);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __VPN_AGENT_H */