5 * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
6 * Copyright (C) 2010 BMW Car IT GmbH. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include <dbus/dbus.h>
33 extern char **environ;
35 static void append(DBusMessageIter *dict, const char *pattern)
37 DBusMessageIter entry;
38 const char *key, *value;
41 delim = strchr(pattern, '=');
47 dbus_message_iter_open_container(dict, DBUS_TYPE_DICT_ENTRY,
50 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key);
52 dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &value);
54 dbus_message_iter_close_container(dict, &entry);
57 int main(int argc, char *argv[])
62 DBusMessageIter iter, dict;
63 char **envp, *busname, *interface, *path, *reason;
65 busname = getenv("CONNMAN_BUSNAME");
66 interface = getenv("CONNMAN_INTERFACE");
67 path = getenv("CONNMAN_PATH");
69 reason = getenv("script_type");
71 if (!busname || !interface || !path || !reason) {
72 fprintf(stderr, "Required environment variables not set\n");
75 dbus_error_init(&error);
77 conn = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
79 if (dbus_error_is_set(&error) == TRUE) {
80 fprintf(stderr, "%s\n", error.message);
81 dbus_error_free(&error);
83 fprintf(stderr, "Failed to get on system bus\n");
87 msg = dbus_message_new_method_call(busname, path,
90 dbus_connection_unref(conn);
91 fprintf(stderr, "Failed to allocate method call\n");
95 dbus_message_set_no_reply(msg, TRUE);
97 dbus_message_append_args(msg,
98 DBUS_TYPE_STRING, &reason,
101 dbus_message_iter_init_append(msg, &iter);
103 dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
104 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
105 DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_STRING_AS_STRING
106 DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
108 for (envp = environ; envp && *envp; envp++)
109 append(&dict, *envp);
111 dbus_message_iter_close_container(&iter, &dict);
113 if (dbus_connection_send(conn, msg, NULL) == FALSE)
114 fprintf(stderr, "Failed to send message\n");
116 dbus_connection_flush(conn);
118 dbus_message_unref(msg);
120 dbus_connection_unref(conn);