static DBusMessage *remove(DBusConnection *conn, DBusMessage *msg, void *data) { const char *path; int err; dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); DBG("conn %p path %s", conn, path); err = __vpn_provider_remove(path); if (err < 0) return __connman_error_failed(msg, -err); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static void media_request_reply(struct media_request *req, int err) { DBusMessage *reply; DBG("Request %s Reply %s", dbus_message_get_member(req->msg), strerror(err)); if (!err) reply = g_dbus_create_reply(req->msg, DBUS_TYPE_INVALID); else reply = g_dbus_create_error(req->msg, ERROR_INTERFACE ".Failed", "%s", strerror(err)); g_dbus_send_message(btd_get_dbus_connection(), reply); }
static DBusMessage *media_player_previous(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_player *mp = data; struct player_callback *cb = mp->cb; int err; if (cb->cbs->previous == NULL) return btd_error_not_supported(msg); err = cb->cbs->previous(mp, cb->user_data); if (err < 0) return btd_error_failed(msg, strerror(-err)); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg, void *data) { struct vpn_provider *provider = data; DBusMessageIter iter, value; const char *name; int type; DBG("conn %p", conn); if (dbus_message_iter_init(msg, &iter) == FALSE) return __connman_error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return __connman_error_invalid_arguments(msg); dbus_message_iter_get_basic(&iter, &name); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) return __connman_error_invalid_arguments(msg); dbus_message_iter_recurse(&iter, &value); type = dbus_message_iter_get_arg_type(&value); if (g_str_equal(name, "UserRoutes") == TRUE) { GSList *networks; if (type != DBUS_TYPE_ARRAY) return __connman_error_invalid_arguments(msg); networks = get_user_networks(&value); if (networks != NULL) { del_routes(provider); provider->user_networks = networks; set_user_networks(provider, provider->user_networks); if (handle_routes == FALSE) provider_schedule_changed(provider, USER_ROUTES_CHANGED); } } else return __connman_error_invalid_property(msg); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *agent_cancel_method(DBusConnection *dbus_cnx, DBusMessage *msg, void *data) { if (agent_if == NULL) goto reply; if (agent_if->pending_reply != NULL) { dbus_message_unref(agent_if->pending_reply); agent_if->pending_reply = NULL; } if (agent_if->cancel_cb != NULL) agent_if->cancel_cb(); reply: return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *create_session(DBusConnection *conn, DBusMessage *msg, void *data) { int err; DBG("conn %p", conn); err = __connman_session_create(msg); if (err < 0) { if (err == -EINPROGRESS) return NULL; return __connman_error_failed(msg, -err); } return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *media_item_play(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_item *item = data; struct media_player *mp = item->player; struct player_callback *cb = mp->cb; int err; if (!item->playable || !cb->cbs->play_item) return btd_error_not_supported(msg); err = cb->cbs->play_item(mp, item->path, item->uid, cb->user_data); if (err < 0) return btd_error_failed(msg, strerror(-err)); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *release_private_network(DBusConnection *conn, DBusMessage *msg, void *data) { const char *path; int err; DBG("conn %p", conn); dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); err = __connman_private_network_release(path); if (err < 0) return __connman_error_failed(msg, -err); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg, void *data) { DBusMessageIter iter, value; const char *name; int type; DBG("conn %p", conn); if (!dbus_message_iter_init(msg, &iter)) return __connman_error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return __connman_error_invalid_arguments(msg); dbus_message_iter_get_basic(&iter, &name); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) return __connman_error_invalid_arguments(msg); dbus_message_iter_recurse(&iter, &value); type = dbus_message_iter_get_arg_type(&value); if (g_str_equal(name, "OfflineMode")) { dbus_bool_t offlinemode; if (type != DBUS_TYPE_BOOLEAN) return __connman_error_invalid_arguments(msg); dbus_message_iter_get_basic(&value, &offlinemode); __connman_technology_set_offlinemode(offlinemode); } else if (g_str_equal(name, "SessionMode")) { if (type != DBUS_TYPE_BOOLEAN) return __connman_error_invalid_arguments(msg); dbus_message_iter_get_basic(&value, &sessionmode); } else return __connman_error_invalid_property(msg); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *connect_peer(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct connman_peer *peer = user_data; GList *list, *start; int err; DBG("peer %p", peer); if (peer->pending) return __connman_error_in_progress(msg); list = g_hash_table_get_values(peers_table); start = list; for (; list; list = list->next) { struct connman_peer *temp = list->data; if (temp == peer || temp->device != peer->device) continue; if (is_connecting(temp) || is_connected(temp)) { if (peer_disconnect(temp) == -EINPROGRESS) { g_list_free(start); return __connman_error_in_progress(msg); } } } g_list_free(start); peer->pending = dbus_message_ref(msg); err = peer_connect(peer); if (err == -EINPROGRESS) return NULL; if (err < 0) { dbus_message_unref(peer->pending); peer->pending = NULL; return __connman_error_failed(msg, -err); } return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *set_property(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_transport *transport = data; DBusMessageIter iter; DBusMessageIter value; const char *property, *sender; GSList *l; int err; if (!dbus_message_iter_init(msg, &iter)) return btd_error_invalid_args(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return btd_error_invalid_args(msg); dbus_message_iter_get_basic(&iter, &property); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) return btd_error_invalid_args(msg); dbus_message_iter_recurse(&iter, &value); sender = dbus_message_get_sender(msg); err = -EINVAL; /* Check if sender has acquired the transport */ for (l = transport->owners; l; l = l->next) { struct media_owner *owner = l->data; if (g_strcmp0(owner->name, sender) == 0) { err = transport->set_property(transport, property, &value); break; } } if (err < 0) { if (err == -EINVAL) return btd_error_invalid_args(msg); return btd_error_failed(msg, strerror(-err)); } return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *lookup_service(DBusConnection *conn, DBusMessage *msg, void *data) { const char *pattern, *path; int err; DBG("conn %p", conn); dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID); err = __connman_service_lookup(pattern, &path); if (err < 0) return __connman_error_failed(msg, -err); return g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); }
static DBusMessage *disconnect_session(DBusConnection *conn, DBusMessage *msg, void *user_data) { struct connman_session *session = user_data; DBG("session %p", session); if (ecall_session != NULL) { if (ecall_session->ecall == TRUE && ecall_session != session) return __connman_error_failed(msg, EBUSY); session->ecall = FALSE; } session_changed(session, CONNMAN_SESSION_TRIGGER_DISCONNECT); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *push_oob_method(DBusConnection *dbus_conn, DBusMessage *message, void *user_data) { const uint8_t *tlv_msg; int err = EINVAL; int length; DBG(""); if (parse_request_oob_params(message, &tlv_msg, &length) != 0) return get_reply_on_error(message, err); err = handle_wcs_data(tlv_msg, length); if (err != 0) return get_reply_on_error(message, err); return g_dbus_create_reply(message, DBUS_TYPE_INVALID); }
static DBusMessage *register_agent(DBusConnection *conn, DBusMessage *msg, void *data) { const char *sender, *path; int err; DBG("conn %p", conn); sender = dbus_message_get_sender(msg); dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID); err = connman_agent_register(sender, path); if (err < 0) return __connman_error_failed(msg, -err); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *default_connection(DBusConnection *conn, DBusMessage *msg, void *data) { const char *path; if (connection_paths == NULL || g_slist_length (connection_paths) == 0) return does_not_exist(msg); path = g_slist_nth_data (connection_paths, default_index); if (path == NULL) { path = last_connection_used(conn); connection_store(path, TRUE); } return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); }
static void open_notify(int fd, int err, struct serial_port *port) { struct serial_device *device = port->device; DBusMessage *reply; if (err) { /* Max tries exceeded */ port_release(port); reply = failed(port->msg, strerror(err)); } else { port->fd = fd; reply = g_dbus_create_reply(port->msg, DBUS_TYPE_STRING, &port->dev, DBUS_TYPE_INVALID); } /* Reply to the requestor */ g_dbus_send_message(device->conn, reply); }
/* * Phdc Manager requests to be removed from the existing list of managers. */ static DBusMessage *dbus_unregister_phdc_agent(DBusConnection *conn, DBusMessage *msg, void *data) { struct near_phdc_data *mgr; DBusMessageIter iter; const char *path, *role, *sender; DBG("conn %p", conn); if (!dbus_message_iter_init(msg, &iter)) return error_invalid_arguments(msg); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH) return error_invalid_arguments(msg); sender = dbus_message_get_sender(msg); dbus_message_iter_get_basic(&iter, &path); dbus_message_iter_next(&iter); if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) return error_invalid_arguments(msg); dbus_message_iter_get_basic(&iter, &role); /* look for specific path */ mgr = search_mgr_list_by_path(path); if (!mgr) return error_not_found(msg); DBG("%s", mgr->sender); if (strncmp(sender, mgr->sender, strlen(mgr->sender))) return error_permission_denied(msg); /* remove it */ near_p2p_unregister(mgr->p2p_driver); g_hash_table_remove(mgr_list, mgr->p2p_driver->service_name); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *remove_path(DBusConnection *conn, DBusMessage *msg, GSList **list, const char *sname) { const char *path; GSList *l; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID) == FALSE) return NULL; l = g_slist_find_custom(*list, path, (GCompareFunc) strcmp); if (!l) return does_not_exist(msg); /* Remove references from the storage */ if (*list == connection_paths) { if (connection_has_pending(path)) return connection_is_busy(msg); connection_remove_stored(path); /* Reset default connection */ if (l == g_slist_nth(*list, default_index)) { const char *dpath; dpath = last_connection_used(conn); connection_store(dpath, TRUE); } } g_free(l->data); *list = g_slist_remove(*list, l->data); g_dbus_emit_signal(conn, NETWORK_PATH, NETWORK_MANAGER_INTERFACE, sname, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); g_dbus_unregister_interface(conn, path, NETWORK_CONNECTION_INTERFACE); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *agent_release_method(DBusConnection *dbus_cnx, DBusMessage *msg, void *data) { if (agent_if == NULL) goto reply; g_dbus_unregister_interface(agent_if->dbus_cnx, CONNMAN_AGENT_PATH, CONNMAN_AGENT_INTERFACE); if (agent_if->pending_reply != NULL) dbus_message_unref(agent_if->pending_reply); dbus_connection_unref(agent_if->dbus_cnx); g_free(agent_if); agent_if = NULL; reply: return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *find_connection(DBusConnection *conn, DBusMessage *msg, void *data) { const char *pattern; const char *path; GSList *list; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID) == FALSE) return NULL; list = find_connection_pattern(conn, pattern); if (list == NULL) return does_not_exist(msg); path = list->data; return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); }
static DBusMessage *remove_remote_data(DBusConnection *conn, DBusMessage *msg, void *data) { struct btd_adapter *adapter = data; const char *addr; bdaddr_t bdaddr; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &addr, DBUS_TYPE_INVALID)) return btd_error_invalid_args(msg); if (bachk(addr)) return btd_error_invalid_args(msg); str2ba(addr, &bdaddr); if (btd_adapter_remove_remote_oob_data(adapter, &bdaddr)) return btd_error_failed(msg, "Request failed"); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *serial_disconnect(DBusConnection *conn, DBusMessage *msg, void *user_data) { const char *device, *sender; int err, id; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &device, DBUS_TYPE_INVALID) == FALSE) return NULL; sender = dbus_message_get_sender(msg); if (sscanf(device, "/dev/rfcomm%d", &id) != 1) return g_dbus_create_error(msg, ERROR_INVALID_ARGS, NULL); err = port_remove_listener(sender, device); if (err < 0) return g_dbus_create_error(msg, ERROR_DOES_NOT_EXIST, NULL); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *stop_poll_loop(DBusConnection *conn, DBusMessage *msg, void *data) { struct near_adapter *adapter = data; int err; DBG("conn %p", conn); if (!adapter->polling) return __near_error_not_polling(msg); err = __near_netlink_stop_poll(adapter->idx); if (err < 0) return __near_error_failed(msg, -err); adapter->polling = false; polling_changed(adapter); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *create_notify_reply(struct async_dbus_op *op, bool success, uint8_t att_ecode) { DBusMessage *reply = NULL; if (!op->msg) return NULL; if (success) reply = g_dbus_create_reply(op->msg, DBUS_TYPE_INVALID); else if (att_ecode) reply = create_gatt_dbus_error(op->msg, att_ecode); else reply = btd_error_failed(op->msg, "Characteristic not available"); if (!reply) error("Failed to construct D-Bus message reply"); return reply; }
static DBusMessage *register_endpoint(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_adapter *adapter = data; DBusMessageIter args, props; const char *sender, *path, *uuid; gboolean delay_reporting = FALSE; uint8_t codec; uint8_t *capabilities; int size = 0; int err; sender = dbus_message_get_sender(msg); dbus_message_iter_init(msg, &args); dbus_message_iter_get_basic(&args, &path); dbus_message_iter_next(&args); if (media_adapter_find_endpoint(adapter, sender, path, NULL) != NULL) return btd_error_already_exists(msg); dbus_message_iter_recurse(&args, &props); if (dbus_message_iter_get_arg_type(&props) != DBUS_TYPE_DICT_ENTRY) return btd_error_invalid_args(msg); if (parse_properties(&props, &uuid, &delay_reporting, &codec, &capabilities, &size) < 0) return btd_error_invalid_args(msg); if (media_endpoint_create(adapter, sender, path, uuid, delay_reporting, codec, capabilities, size, &err) == NULL) { if (err == -EPROTONOSUPPORT) return btd_error_not_supported(msg); else return btd_error_invalid_args(msg); } return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *change_default_connection(DBusConnection *conn, DBusMessage *msg, void *data) { const char *path; const char *pattern; GSList *list; if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_INVALID) == FALSE) return NULL; if (connection_paths == NULL || g_slist_length(connection_paths) == 0) return does_not_exist(msg); list = g_slist_find_custom(connection_paths, pattern, (GCompareFunc) strcmp); /* Find object path via pattern */ if (list == NULL) { list = find_connection_pattern(conn, pattern); if (list == NULL) return does_not_exist(msg); path = list->data; } else path = list->data; default_index = g_slist_position(connection_paths, list); connection_store(path, TRUE); g_dbus_emit_signal(connection, NETWORK_PATH, NETWORK_MANAGER_INTERFACE, "DefaultConnectionChanged", DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID); }
static void read_op_cb(struct gatt_db_attribute *attrib, int err, const uint8_t *value, size_t length, void *user_data) { struct async_dbus_op *op = user_data; DBusMessage *reply; if (err) { error("Failed to read attribute"); return; } reply = g_dbus_create_reply(op->msg, DBUS_TYPE_INVALID); if (!reply) { error("Failed to allocate D-Bus message reply"); return; } message_append_byte_array(reply, value, length); g_dbus_send_message(btd_get_dbus_connection(), reply); }
static DBusMessage *unregister_endpoint(DBusConnection *conn, DBusMessage *msg, void *data) { struct media_adapter *adapter = data; struct media_endpoint *endpoint; const char *sender, *path; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID)) return btd_error_invalid_args(msg); sender = dbus_message_get_sender(msg); endpoint = media_adapter_find_endpoint(adapter, sender, path, NULL); if (endpoint == NULL) return btd_error_does_not_exist(msg); media_endpoint_remove(endpoint); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); }
static DBusMessage *create_proxy(DBusConnection *conn, DBusMessage *msg, void *data) { struct serial_adapter *adapter = data; struct serial_proxy *proxy; const char *pattern, *address; char *uuid_str; int err; if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID)) return NULL; uuid_str = bt_name2string(pattern); if (!uuid_str) return invalid_arguments(msg, "Invalid UUID"); err = register_proxy(adapter, uuid_str, address, &proxy); g_free(uuid_str); if (err == -EINVAL) return invalid_arguments(msg, "Invalid address"); else if (err == -EALREADY) return g_dbus_create_error(msg, ERROR_INTERFACE ".AlreadyExist", "Proxy already exists"); else if (err < 0) return g_dbus_create_error(msg, ERROR_INTERFACE "Failed", "Proxy creation failed (%s)", strerror(-err)); proxy->owner = g_strdup(dbus_message_get_sender(msg)); proxy->watch = g_dbus_add_disconnect_watch(conn, proxy->owner, watch_proxy, proxy, NULL); return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &proxy->path, DBUS_TYPE_INVALID); }