struct agent *agent_get(const char *owner) { struct agent *agent; if (owner) { agent = g_hash_table_lookup(agent_list, owner); if (agent) return agent_ref(agent); } if (!queue_isempty(default_agents)) return agent_ref(queue_peek_head(default_agents)); return NULL; }
struct agent *agent_get(const char *owner) { struct agent *agent; if (owner) { agent = g_hash_table_lookup(agent_list, owner); if (agent) return agent_ref(agent); } if (default_agent) return agent_ref(default_agent); return NULL; }
static void pincode_reply(DBusPendingCall *call, void *user_data) { struct agent_request *req = user_data; struct agent *agent = req->agent; agent_pincode_cb cb = req->cb; DBusMessage *message; DBusError err; size_t len; char *pin; /* steal_reply will always return non-NULL since the callback * is only called after a reply has been received */ message = dbus_pending_call_steal_reply(call); /* Protect from the callback freeing the agent */ agent_ref(agent); dbus_error_init(&err); if (dbus_set_error_from_message(&err, message)) { error("Agent %s replied with an error: %s, %s", agent->path, err.name, err.message); cb(agent, &err, NULL, req->user_data); dbus_error_free(&err); goto done; } if (!dbus_message_get_args(message, &err, DBUS_TYPE_STRING, &pin, DBUS_TYPE_INVALID)) { error("Wrong passkey reply signature: %s", err.message); cb(agent, &err, NULL, req->user_data); dbus_error_free(&err); goto done; } len = strlen(pin); if (len > 16 || len < 1) { error("Invalid PIN length (%zu) from agent", len); dbus_set_error_const(&err, ERROR_INTERFACE ".InvalidArgs", "Invalid passkey length"); cb(agent, &err, NULL, req->user_data); dbus_error_free(&err); goto done; } cb(agent, NULL, pin, req->user_data); done: if (message) dbus_message_unref(message); dbus_pending_call_cancel(req->call); agent->request = NULL; agent_request_free(req, TRUE); agent_unref(agent); }
static void simple_agent_reply(DBusPendingCall *call, void *user_data) { struct agent_request *req = user_data; struct agent *agent = req->agent; DBusMessage *message; DBusError err; agent_cb cb = req->cb; /* steal_reply will always return non-NULL since the callback * is only called after a reply has been received */ message = dbus_pending_call_steal_reply(call); /* Protect from the callback freeing the agent */ agent_ref(agent); dbus_error_init(&err); if (dbus_set_error_from_message(&err, message)) { DBG("agent error reply: %s, %s", err.name, err.message); cb(agent, &err, req->user_data); if (dbus_error_has_name(&err, DBUS_ERROR_NO_REPLY)) { error("Timed out waiting for reply from agent"); agent_cancel(agent); dbus_message_unref(message); dbus_error_free(&err); agent_unref(agent); return; } dbus_error_free(&err); goto done; } if (!dbus_message_get_args(message, &err, DBUS_TYPE_INVALID)) { error("Wrong reply signature: %s", err.message); cb(agent, &err, req->user_data); dbus_error_free(&err); goto done; } cb(agent, NULL, req->user_data); done: dbus_message_unref(message); agent->request = NULL; agent_request_free(req, TRUE); agent_unref(agent); }
static struct connman_agent *agent_create(const char *name, const char *path) { struct connman_agent *agent; agent = g_new0(struct connman_agent, 1); agent->owner = g_strdup(name); agent->path = g_strdup(path); agent->watch = g_dbus_add_disconnect_watch(connection, name, agent_disconnect, agent, NULL); return agent_ref(agent); }
static struct agent *agent_create( const char *name, const char *path, uint8_t capability) { struct agent *agent; agent = g_new0(struct agent, 1); agent->owner = g_strdup(name); agent->path = g_strdup(path); agent->capability = capability; agent->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(), name, agent_disconnect, agent, NULL); return agent_ref(agent); }
static struct agent *agent_create( const char *name, const char *path, uint8_t capability) { struct agent *agent; agent = g_new0(struct agent, 1); agent->owner = g_strdup(name); agent->path = g_strdup(path); agent->capability = capability; agent->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(), name, agent_disconnect, agent, NULL); if (queue_isempty(default_agents)) add_default_agent(agent); else queue_push_tail(default_agents, agent); return agent_ref(agent); }
agent_ref_t agent_t::create_ref() { agent_ref_t agent_ref( this ); return agent_ref; }