sending a{sv} is crashing
Mike Gorse
mgorse at novell.com
Sat Oct 2 14:05:31 PDT 2010
You aren't writing to the variants correctly--you need to pass a pointer
to a char * (ie, a char **), rather than trying to pass the string
directly.
-MG
On Thu, 30 Sep 2010, Raghavendra. S wrote:
> Hi All,
>
> I am trying to call ConnectService API defined in connman (open source connection manager daemon). Connman has defined ConnectService with "a{sv}" signature.
>
> When I tried to form and send message using below code, code is crashing with signal 11. Please let me know whats the issue in below code.
>
>
> #include <stdio.h>
> #include <errno.h>
> #include <stdlib.h>
> #include <string.h>
> #include <stdbool.h>
> #include <glib.h>
> #include <dbus/dbus-glib.h>
> #include <dbus/dbus.h>
> #include <sys/types.h>
> #include <sys/stat.h>
>
> typedef struct{
> char type[20];
> char mode[20];
> char ssid[20];
> char security[20];
> char passphrase[20];
> } network_connect_service_info_t;
>
> static int
> network_dbus_connect_service(network_connect_service_info_t* conn_info)
> {
> DBusError error;
>
> const char *prop_type = "Type";
> const char *prop_mode = "Mode";
> const char *prop_ssid = "SSID";
> const char *prop_security = "Security";
> const char *prop_passphrase = "Passphrase";
>
> char* type = conn_info->type;
> char* mode = conn_info->mode;
> char* ssid = conn_info->ssid;
> char* security = conn_info->security;
> char* passphrase = conn_info->passphrase;
>
> DBusMessage *msg;
> DBusMessage *reply;
> DBusMessageIter dict, entry, array,value;
> DBusConnection* conn = NULL;
>
> conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
> if (conn == NULL) {
> printf("Error!!! Can't get on system bus\n");
> return -1;
> }
> msg = dbus_message_new_method_call("org.moblin.connman", "/", "org.moblin.connman.Manager", "ConnectService");
> if(msg == NULL)
> {
> printf("Error!!! dbus_message_new_method_call() failed\n");
> return -1;
> }
>
>
>
> dbus_message_iter_init_append(msg, &array);
> dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY,
> DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
> DBUS_TYPE_STRING_AS_STRING
> DBUS_TYPE_VARIANT_AS_STRING
> DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
> &dict);
>
> dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
> dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_type);
> dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
> dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, type);
> dbus_message_iter_close_container(&entry, &value);
> dbus_message_iter_close_container(&dict, &entry);
>
> dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
> dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_mode);
> dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
> dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, mode);
> dbus_message_iter_close_container(&entry, &value);
> dbus_message_iter_close_container(&dict, &entry);
>
> dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
> dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_ssid);
> dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
> dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, ssid);
> dbus_message_iter_close_container(&entry, &value);
> dbus_message_iter_close_container(&dict, &entry);
>
> dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
> dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_security);
> dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
> dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, security);
> dbus_message_iter_close_container(&entry, &value);
> dbus_message_iter_close_container(&dict, &entry);
>
> dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &entry);
> dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &prop_passphrase);
> dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value);
> dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, passphrase);
> dbus_message_iter_close_container(&entry, &value);
> dbus_message_iter_close_container(&dict, &entry);
> dbus_message_iter_close_container(&array, &dict);
>
> dbus_error_init (&error);
> reply = dbus_connection_send_with_reply_and_block (conn, msg, -1, &error);
> if (dbus_error_is_set (&error))
> {
> printf("Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n", error.name, error.message);
> return -1;
> }
>
> dbus_message_unref(reply);
> dbus_message_unref(msg);
> printf("Successfully configured\n");
> dbus_connection_unref(conn);
> return 0;
>
> }
>
> int main()
> {
>
> network_connect_service_info_t connection_info = {"wifi","managed","datanet","psk","datanettest"};
>
> network_dbus_connect_service(&connection_info);
>
> return 0;
>
> }
>
>
>
> --
> Regards & Thanks
> Raghavendra. S
> 9880329621
>
>
More information about the dbus
mailing list