3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-29 13:59:24 +01:00

agent: Add a destroy function parameter for agent requests

This commit is contained in:
Andrew Zaborowski 2017-08-18 00:20:39 +02:00 committed by Denis Kenzior
parent 452e174802
commit 07b04e180f
3 changed files with 15 additions and 6 deletions

View File

@ -39,6 +39,7 @@ struct agent_request {
void *user_data; void *user_data;
void *user_callback; void *user_callback;
struct l_dbus_message *trigger; struct l_dbus_message *trigger;
agent_request_destroy_func_t destroy;
}; };
struct agent { struct agent {
@ -130,6 +131,9 @@ static void agent_request_free(void *user_data)
dbus_pending_reply(&request->trigger, dbus_pending_reply(&request->trigger,
dbus_error_aborted(request->trigger)); dbus_error_aborted(request->trigger));
if (request->destroy)
request->destroy(request->user_data);
l_free(request); l_free(request);
} }
@ -254,7 +258,8 @@ static unsigned int agent_queue_request(struct agent *agent,
struct l_dbus_message *message, struct l_dbus_message *message,
int timeout, void *callback, int timeout, void *callback,
struct l_dbus_message *trigger, struct l_dbus_message *trigger,
void *user_data) void *user_data,
agent_request_destroy_func_t destroy)
{ {
struct agent_request *request; struct agent_request *request;
@ -265,6 +270,7 @@ static unsigned int agent_queue_request(struct agent *agent,
request->user_data = user_data; request->user_data = user_data;
request->user_callback = callback; request->user_callback = callback;
request->trigger = l_dbus_message_ref(trigger); request->trigger = l_dbus_message_ref(trigger);
request->destroy = destroy;
agent->timeout_secs = timeout; agent->timeout_secs = timeout;
@ -311,6 +317,7 @@ static struct agent *get_agent(const char *owner)
* @callback: user callback called when the request is ready * @callback: user callback called when the request is ready
* @trigger: Message associated with (e.g. that triggered) this request * @trigger: Message associated with (e.g. that triggered) this request
* @user_data: user defined data * @user_data: user defined data
* @destroy: callback to release @user_data when this request finishes
* *
* Called when a passphrase information is needed from the user. Returns an * Called when a passphrase information is needed from the user. Returns an
* id that can be used to cancel the request. * id that can be used to cancel the request.
@ -324,7 +331,8 @@ static struct agent *get_agent(const char *owner)
unsigned int agent_request_passphrase(const char *path, unsigned int agent_request_passphrase(const char *path,
agent_request_passphrase_func_t callback, agent_request_passphrase_func_t callback,
struct l_dbus_message *trigger, struct l_dbus_message *trigger,
void *user_data) void *user_data,
agent_request_destroy_func_t destroy)
{ {
struct agent *agent = get_agent(l_dbus_message_get_sender(trigger)); struct agent *agent = get_agent(l_dbus_message_get_sender(trigger));
struct l_dbus_message *message; struct l_dbus_message *message;
@ -344,7 +352,7 @@ unsigned int agent_request_passphrase(const char *path,
return agent_queue_request(agent, message, return agent_queue_request(agent, message,
agent_timeout_input_request(), agent_timeout_input_request(),
callback, trigger, user_data); callback, trigger, user_data, destroy);
} }
static bool find_request(const void *a, const void *b) static bool find_request(const void *a, const void *b)

View File

@ -31,6 +31,7 @@ typedef void (*agent_request_passphrase_func_t) (enum agent_result result,
const char *passphrase, const char *passphrase,
struct l_dbus_message *message, struct l_dbus_message *message,
void *user_data); void *user_data);
typedef void (*agent_request_destroy_func_t)(void *user_data);
bool agent_init(struct l_dbus *dbus); bool agent_init(struct l_dbus *dbus);
bool agent_exit(struct l_dbus *dbus); bool agent_exit(struct l_dbus *dbus);
@ -39,5 +40,6 @@ void agent_shutdown(void);
unsigned int agent_request_passphrase(const char *path, unsigned int agent_request_passphrase(const char *path,
agent_request_passphrase_func_t callback, agent_request_passphrase_func_t callback,
struct l_dbus_message *message, struct l_dbus_message *message,
void *user_data); void *user_data,
agent_request_destroy_func_t destroy);
bool agent_request_cancel(unsigned int req_id, int reason); bool agent_request_cancel(unsigned int req_id, int reason);

View File

@ -602,8 +602,7 @@ static struct l_dbus_message *network_connect_psk(struct network *network,
network->agent_request = network->agent_request =
agent_request_passphrase(network->object_path, agent_request_passphrase(network->object_path,
passphrase_callback, passphrase_callback,
message, message, network, NULL);
network);
if (!network->agent_request) if (!network->agent_request)
return dbus_error_no_agent(message); return dbus_error_no_agent(message);