vpn-agent.c 3.74 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*
 *
 *  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"

38
bool vpn_agent_check_reply_has_dict(DBusMessage *reply)
39 40 41 42 43 44 45
{
	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;

46 47
	if (dbus_message_has_signature(reply, signature))
		return true;
48 49 50 51 52 53 54

	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));

55
	return false;
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
}

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);
}

struct user_info_data {
	struct vpn_provider *provider;
	const char *username_str;
};

static void request_input_append_user_info(DBusMessageIter *iter,
						void *user_data)
{
	struct user_info_data *data = user_data;
	struct vpn_provider *provider = data->provider;
	const char *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);

120
	if (data->username_str) {
121
		str = vpn_provider_get_string(provider, data->username_str);
122
		if (str)
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
			connman_dbus_dict_append_basic(iter, "Value",
						DBUS_TYPE_STRING, &str);
	}
}

void vpn_agent_append_user_info(DBusMessageIter *iter,
				struct vpn_provider *provider,
				const char *username_str)
{
	struct user_info_data data = {
		.provider = provider,
		.username_str = username_str
	};

	connman_dbus_dict_append_dict(iter, "Username",
				request_input_append_user_info,
				&data);

	data.username_str = NULL;
	connman_dbus_dict_append_dict(iter, "Password",
				request_input_append_user_info,
				&data);
}