-
-int _net_send_dbus_request(const char* destination, char *param_array[], DBusMessage** result)
-{
- __NETWORK_FUNC_ENTER__;
-
- DBusConnection *connection = NULL;
- DBusError error;
- DBusMessage *message = NULL;
- net_err_t Error = NET_ERR_NONE;
- char *RequestMethod = NULL;
- int i = 0;
- const char *path = NULL;
- const char *name = NULL;
- int param_count = 0;
- // const char *destination = CONNMAN_SERVICE;
- DBusMessageIter iter;
-
- for (param_count = 0; param_array[param_count] != NULL; param_count++) {
- NETWORK_LOG(NETWORK_HIGH, "[%s]\n", param_array[param_count]);
- }
- NETWORK_LOG(NETWORK_HIGH, "Total Arguments [%d]\n", param_count);
-
- path = param_array[i++]; /** 0th is path */
- name = param_array[i++]; /** 1st is request name */
-
- if ((strlen(path) == 0) || (strlen(name) == 0) ) {
- NETWORK_LOG(NETWORK_ASSERT, "Error!!! Invalid parameters passed path [%s], requested name [%s]\n",
- path, name);
- __NETWORK_FUNC_EXIT__;
- return NET_ERR_INVALID_PARAM;
- }
-
- dbus_error_init(&error);
-
- connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- if (connection == NULL) {
- NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! Failed to get system dbus, error [%s]\n",
- error.message);
- dbus_error_free(&error);
- __NETWORK_FUNC_EXIT__;
- return NET_ERR_UNKNOWN;
- }
-
- RequestMethod = strrchr(name, '.');
- if (RequestMethod == NULL) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid method in \"%s\"\n", name);
- dbus_connection_unref(connection);
- __NETWORK_FUNC_EXIT__;
- return NET_ERR_UNKNOWN;
- }
-
- *RequestMethod = '\0';
- message = dbus_message_new_method_call(NULL, path, name, RequestMethod + 1);
-
- if (message == NULL) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! dbus_message_new_method_call() failed\n");
- __NETWORK_FUNC_EXIT__;
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
-
- if (destination && !dbus_message_set_destination(message, destination)) {
- NETWORK_LOG(NETWORK_EXCEPTION, "Error!!! dbus_message_set_destination() failed\n");
- __NETWORK_FUNC_EXIT__;
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
-
- dbus_message_iter_init_append(message, &iter);
-
- /** Two arguments name and path already extracted, so i == 2 */
- while (i < param_count) {
- char *Args = NULL;
- char *Ch = NULL;
- int ArgType = 0;
- int SecondaryType = 0;
- int ContainerType = 0;
- DBusMessageIter *TargetIter = NULL;
- DBusMessageIter ContainerIter;
-
- ArgType = DBUS_TYPE_INVALID;
- Args = param_array[i++];
- Ch = strchr (Args, ':');
-
- if (Ch == NULL) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid data format[\"%s\"]\n", Args);
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
-
- *(Ch++) = 0;
-
- if (strcmp(Args, CONNMAN_CLIENT_DBUS_TYPE_VARIANT) == 0) {
- ContainerType = DBUS_TYPE_VARIANT;
- } else if (strcmp(Args, CONNMAN_CLIENT_DBUS_TYPE_ARRAY) == 0) {
- ContainerType = DBUS_TYPE_ARRAY;
- } else if (strcmp(Args, CONNMAN_CLIENT_DBUS_TYPE_DICT_ENTRY) == 0) {
- ContainerType = DBUS_TYPE_DICT_ENTRY;
- } else {
- ContainerType = DBUS_TYPE_INVALID;
- }
-
- if (ContainerType != DBUS_TYPE_INVALID) {
- Args = Ch;
- Ch = strchr(Args, ':');
- if (Ch == NULL) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid data format[\"%s\"]\n", Args);
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
- *(Ch++) = 0;
- }
-
- if (Args[0] == 0) {
- ArgType = DBUS_TYPE_STRING;
- } else {
- ArgType = __net_datatype_from_stringname(Args);
- if (ArgType == NET_ERR_UNKNOWN) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! Unknown data type\n");
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
- }
-
- if (ContainerType == DBUS_TYPE_DICT_ENTRY) {
- char Signature[5] = "";
- Args = Ch;
- Ch = strchr (Ch, ':');
-
- if (Ch == NULL) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! Invalid data format[\"%s\"]\n", Args);
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
-
- *(Ch++) = 0;
- SecondaryType = __net_datatype_from_stringname(Args);
-
- if (SecondaryType == NET_ERR_UNKNOWN) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! Unknown datatype\n");
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
-
- Signature[0] = DBUS_DICT_ENTRY_BEGIN_CHAR;
- Signature[1] = ArgType;
- Signature[2] = SecondaryType;
- Signature[3] = DBUS_DICT_ENTRY_END_CHAR;
- Signature[4] = '\0';
-
- dbus_message_iter_open_container(&iter,
- DBUS_TYPE_ARRAY,
- Signature,
- &ContainerIter);
- TargetIter = &ContainerIter;
- } else if (ContainerType != DBUS_TYPE_INVALID) {
- char Signature[2] = "";
- Signature[0] = ArgType;
- Signature[1] = '\0';
-
- dbus_message_iter_open_container(&iter,
- ContainerType,
- Signature,
- &ContainerIter);
- TargetIter = &ContainerIter;
- } else {
- TargetIter = &iter;
- }
-
- if (ContainerType == DBUS_TYPE_ARRAY) {
- if (__net_append_array(TargetIter, ArgType, Ch) != NET_ERR_NONE) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! __net_append_array() failed\n");
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
- } else if (ContainerType == DBUS_TYPE_DICT_ENTRY) {
- if (__net_append_dict(TargetIter, ArgType, SecondaryType, Ch) != NET_ERR_NONE) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! __net_append_dict() failed\n");
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
- } else {
- if (__net_append_argument(TargetIter, ArgType, Ch) != NET_ERR_NONE) {
- NETWORK_LOG(NETWORK_ERROR, "Error!!! __net_append_argument() failed\n");
- Error = NET_ERR_UNKNOWN;
- goto end_error;
- }
- }
-
- if (ContainerType != DBUS_TYPE_INVALID) {
- dbus_message_iter_close_container(&iter, &ContainerIter);
- }
- }
-
- DBusMessage *reply = NULL;
-
- dbus_error_init (&error);
-
- reply = dbus_connection_send_with_reply_and_block(connection,
- message,
- DBUS_REPLY_TIMEOUT,
- &error);
- if (reply == NULL) {
- if (dbus_error_is_set(&error) == TRUE) {
- NETWORK_LOG(NETWORK_ERROR,
- "Error!!! dbus_connection_send_with_reply_and_block() failed, Error[%s: %s]\n",
- error.name,
- error.message);
- Error = __net_error_string_to_enum(error.name);
- dbus_error_free(&error);
- } else
- Error = NET_ERR_UNKNOWN;
-
- goto end_error;
- } else {
- if (result != NULL) {
- *result = reply;
- } else {
- dbus_message_unref(reply);
- }
- }
-
-end_error:
- dbus_message_unref(message);
- dbus_connection_unref(connection);
-
- if (Error == NET_ERR_NONE)
- NETWORK_LOG(NETWORK_HIGH, "Successfully requested\n");
-
- __NETWORK_FUNC_EXIT__;
- return Error;
-}
-
-