dbus: Cleaned up signal message construction functions

This commit is contained in:
Jouni Malinen 2010-01-02 12:06:44 +02:00
parent fff9ab1b2d
commit 88ba1f7213
2 changed files with 193 additions and 289 deletions

View file

@ -33,7 +33,7 @@
* wpas_dbus_signal_interface - Send a interface related event signal * wpas_dbus_signal_interface - Send a interface related event signal
* @wpa_s: %wpa_supplicant network interface data * @wpa_s: %wpa_supplicant network interface data
* @sig_name: signal name - InterfaceAdded or InterfaceRemoved * @sig_name: signal name - InterfaceAdded or InterfaceRemoved
* @properties: determines if add second argument with object properties * @properties: Whether to add second argument with object properties
* *
* Notify listeners about event related with interface * Notify listeners about event related with interface
*/ */
@ -41,9 +41,8 @@ static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
const char *sig_name, int properties) const char *sig_name, int properties)
{ {
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
DBusMessage *_signal; DBusMessage *msg;
DBusMessageIter iter, iter_dict; DBusMessageIter iter, iter_dict;
const char *path;
iface = wpa_s->global->dbus; iface = wpa_s->global->dbus;
@ -51,26 +50,21 @@ static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(WPAS_DBUS_NEW_PATH, msg = dbus_message_new_signal(WPAS_DBUS_NEW_PATH,
WPAS_DBUS_NEW_INTERFACE, sig_name); WPAS_DBUS_NEW_INTERFACE, sig_name);
if (_signal == NULL) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_interface[dbus]: "
"enough memory to send scan results signal.");
return; return;
}
dbus_message_iter_init_append(_signal, &iter); dbus_message_iter_init_append(msg, &iter);
path = wpa_s->dbus_new_path;
if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
&path)) &wpa_s->dbus_new_path))
goto err; goto err;
if (properties) { if (properties) {
if (!wpa_dbus_dict_open_write(&iter, &iter_dict)) if (!wpa_dbus_dict_open_write(&iter, &iter_dict))
goto err; goto err;
wpa_dbus_get_object_properties(iface, path, wpa_dbus_get_object_properties(iface, wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_INTERFACE, WPAS_DBUS_NEW_IFACE_INTERFACE,
&iter_dict); &iter_dict);
@ -78,15 +72,13 @@ static void wpas_dbus_signal_interface(struct wpa_supplicant *wpa_s,
goto err; goto err;
} }
dbus_connection_send(iface->con, _signal, NULL); dbus_connection_send(iface->con, msg, NULL);
dbus_message_unref(msg);
dbus_message_unref(_signal);
return; return;
err: err:
wpa_printf(MSG_ERROR, "wpas_dbus_signal_interface[dbus]: " wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"not enough memory to construct signal."); dbus_message_unref(msg);
dbus_message_unref(_signal);
} }
@ -125,7 +117,7 @@ static void wpas_dbus_signal_interface_removed(struct wpa_supplicant *wpa_s)
void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success) void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
{ {
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
DBusMessage *_signal; DBusMessage *msg;
dbus_bool_t succ; dbus_bool_t succ;
iface = wpa_s->global->dbus; iface = wpa_s->global->dbus;
@ -134,24 +126,19 @@ void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_INTERFACE, WPAS_DBUS_NEW_IFACE_INTERFACE,
"ScanDone"); "ScanDone");
if (_signal == NULL) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_scan_done[dbus]: "
"enough memory to send signal.");
return; return;
}
succ = success ? TRUE : FALSE; succ = success ? TRUE : FALSE;
if (dbus_message_append_args(_signal, DBUS_TYPE_BOOLEAN, &succ, if (dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &succ,
DBUS_TYPE_INVALID)) { DBUS_TYPE_INVALID))
dbus_connection_send(iface->con, _signal, NULL); dbus_connection_send(iface->con, msg, NULL);
} else { else
wpa_printf(MSG_ERROR, "wpas_dbus_signal_scan_done[dbus]: " wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"not enough memory to construct signal."); dbus_message_unref(msg);
}
dbus_message_unref(_signal);
} }
@ -160,7 +147,7 @@ void wpas_dbus_signal_scan_done(struct wpa_supplicant *wpa_s, int success)
* @wpa_s: %wpa_supplicant network interface data * @wpa_s: %wpa_supplicant network interface data
* @bss_obj_path: BSS object path * @bss_obj_path: BSS object path
* @sig_name: signal name - BSSAdded or BSSRemoved * @sig_name: signal name - BSSAdded or BSSRemoved
* @properties: determines if add second argument with object properties * @properties: Whether to add second argument with object properties
* *
* Notify listeners about event related with BSS * Notify listeners about event related with BSS
*/ */
@ -169,7 +156,7 @@ static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
const char *sig_name, int properties) const char *sig_name, int properties)
{ {
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
DBusMessage *_signal; DBusMessage *msg;
DBusMessageIter iter, iter_dict; DBusMessageIter iter, iter_dict;
iface = wpa_s->global->dbus; iface = wpa_s->global->dbus;
@ -178,17 +165,13 @@ static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_INTERFACE, WPAS_DBUS_NEW_IFACE_INTERFACE,
sig_name); sig_name);
if (_signal == NULL) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_bss[dbus]: "
"enough memory to send signal.");
return; return;
}
dbus_message_iter_init_append(_signal, &iter);
dbus_message_iter_init_append(msg, &iter);
if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
&bss_obj_path)) &bss_obj_path))
goto err; goto err;
@ -205,15 +188,13 @@ static void wpas_dbus_signal_bss(struct wpa_supplicant *wpa_s,
goto err; goto err;
} }
dbus_connection_send(iface->con, _signal, NULL); dbus_connection_send(iface->con, msg, NULL);
dbus_message_unref(msg);
dbus_message_unref(_signal);
return; return;
err: err:
wpa_printf(MSG_ERROR, "wpas_dbus_signal_bss[dbus]: " wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"not enough memory to construct signal."); dbus_message_unref(msg);
dbus_message_unref(_signal);
} }
@ -257,7 +238,7 @@ static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
const char *name, const char *sig_name) const char *name, const char *sig_name)
{ {
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
DBusMessage *_signal; DBusMessage *msg;
iface = wpa_s->global->dbus; iface = wpa_s->global->dbus;
@ -265,23 +246,18 @@ static void wpas_dbus_signal_blob(struct wpa_supplicant *wpa_s,
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_INTERFACE, WPAS_DBUS_NEW_IFACE_INTERFACE,
sig_name); sig_name);
if (_signal == NULL) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_blob[dbus]: "
"enough memory to send signal.");
return; return;
}
if (dbus_message_append_args(_signal, DBUS_TYPE_STRING, &name, if (dbus_message_append_args(msg, DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID)) { DBUS_TYPE_INVALID))
dbus_connection_send(iface->con, _signal, NULL); dbus_connection_send(iface->con, msg, NULL);
} else { else
wpa_printf(MSG_ERROR, "wpas_dbus_signal_blob[dbus]: " wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"not enough memory to construct signal."); dbus_message_unref(msg);
}
dbus_message_unref(_signal);
} }
@ -327,9 +303,9 @@ static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
int properties) int properties)
{ {
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
DBusMessage *_signal; DBusMessage *msg;
DBusMessageIter iter, iter_dict; DBusMessageIter iter, iter_dict;
char *net_obj_path; char net_obj_path[WPAS_DBUS_OBJECT_PATH_MAX], *path;
iface = wpa_s->global->dbus; iface = wpa_s->global->dbus;
@ -337,27 +313,20 @@ static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
if (iface == NULL) if (iface == NULL)
return; return;
net_obj_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
if (net_obj_path == NULL)
return;
os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX, os_snprintf(net_obj_path, WPAS_DBUS_OBJECT_PATH_MAX,
"%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u", "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%u",
wpa_s->dbus_new_path, id); wpa_s->dbus_new_path, id);
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_INTERFACE, WPAS_DBUS_NEW_IFACE_INTERFACE,
sig_name); sig_name);
if (_signal == NULL) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_network[dbus]: "
"enough memory to send signal.");
os_free(net_obj_path);
return; return;
}
dbus_message_iter_init_append(_signal, &iter);
dbus_message_iter_init_append(msg, &iter);
path = net_obj_path;
if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH,
&net_obj_path)) &path))
goto err; goto err;
if (properties) { if (properties) {
@ -372,17 +341,14 @@ static void wpas_dbus_signal_network(struct wpa_supplicant *wpa_s,
goto err; goto err;
} }
dbus_connection_send(iface->con, _signal, NULL); dbus_connection_send(iface->con, msg, NULL);
os_free(net_obj_path); dbus_message_unref(msg);
dbus_message_unref(_signal);
return; return;
err: err:
wpa_printf(MSG_ERROR, "wpas_dbus_signal_network[dbus]: " wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"not enough memory to construct signal."); dbus_message_unref(msg);
os_free(net_obj_path);
dbus_message_unref(_signal);
} }
@ -427,6 +393,15 @@ void wpas_dbus_signal_network_selected(struct wpa_supplicant *wpa_s, int id)
} }
static void str_to_lower(char *s)
{
while (*s) {
*s = tolower(*s);
s++;
}
}
/** /**
* wpas_dbus_signal_state_changed - Send a state changed signal * wpas_dbus_signal_state_changed - Send a state changed signal
* @wpa_s: %wpa_supplicant network interface data * @wpa_s: %wpa_supplicant network interface data
@ -440,9 +415,8 @@ void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
enum wpa_states old_state) enum wpa_states old_state)
{ {
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
DBusMessage *_signal = NULL; DBusMessage *msg;
char *new_state_str, *old_state_str; char *new_state_str, *old_state_str;
char *tmp;
/* Do nothing if the control interface is not turned on */ /* Do nothing if the control interface is not turned on */
if (wpa_s->global == NULL) if (wpa_s->global == NULL)
@ -455,10 +429,10 @@ void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
if (new_state == old_state) if (new_state == old_state)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_INTERFACE, WPAS_DBUS_NEW_IFACE_INTERFACE,
"StateChanged"); "StateChanged");
if (_signal == NULL) if (msg == NULL)
return; return;
new_state_str = os_strdup(wpa_supplicant_state_txt(new_state)); new_state_str = os_strdup(wpa_supplicant_state_txt(new_state));
@ -467,32 +441,22 @@ void wpas_dbus_signal_state_changed(struct wpa_supplicant *wpa_s,
goto out; goto out;
/* make state string lowercase to fit new DBus API convention */ /* make state string lowercase to fit new DBus API convention */
tmp = new_state_str; str_to_lower(new_state_str);
while (*tmp) { str_to_lower(old_state_str);
*tmp = tolower(*tmp);
tmp++;
}
tmp = old_state_str;
while (*tmp) {
*tmp = tolower(*tmp);
tmp++;
}
if (!dbus_message_append_args(_signal, if (!dbus_message_append_args(msg,
DBUS_TYPE_STRING, &new_state_str, DBUS_TYPE_STRING, &new_state_str,
DBUS_TYPE_STRING, &old_state_str, DBUS_TYPE_STRING, &old_state_str,
DBUS_TYPE_INVALID)) { DBUS_TYPE_INVALID)) {
wpa_printf(MSG_ERROR, wpa_printf(MSG_ERROR, "dbus: Failed to construct state change "
"dbus: wpas_dbus_signal_state_changed: "
"not enough memory to construct state change "
"signal"); "signal");
goto out; goto out;
} }
dbus_connection_send(iface->con, _signal, NULL); dbus_connection_send(iface->con, msg, NULL);
out: out:
dbus_message_unref(_signal); dbus_message_unref(msg);
os_free(new_state_str); os_free(new_state_str);
os_free(old_state_str); os_free(old_state_str);
} }
@ -510,8 +474,7 @@ void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid) struct wpa_ssid *ssid)
{ {
struct network_handler_args args = {wpa_s, ssid}; struct network_handler_args args = { wpa_s, ssid };
char path[WPAS_DBUS_OBJECT_PATH_MAX]; char path[WPAS_DBUS_OBJECT_PATH_MAX];
os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX, os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
"%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d", "%s/" WPAS_DBUS_NEW_NETWORKS_PART "/%d",
@ -536,7 +499,7 @@ void wpas_dbus_signal_network_enabled_changed(struct wpa_supplicant *wpa_s,
void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s) void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
{ {
DBusMessage *_signal = NULL; DBusMessage *msg;
DBusMessageIter iter, dict_iter; DBusMessageIter iter, dict_iter;
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
char *key = "success"; char *key = "success";
@ -547,27 +510,21 @@ void wpas_dbus_signal_wps_event_success(struct wpa_supplicant *wpa_s)
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_WPS, "Event"); WPAS_DBUS_NEW_IFACE_WPS, "Event");
if (!_signal) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_success"
"[dbus]: out of memory when creating a signal");
return; return;
}
dbus_message_iter_init_append(_signal, &iter); dbus_message_iter_init_append(msg, &iter);
if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) || if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
!wpa_dbus_dict_open_write(&iter, &dict_iter) || !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
!wpa_dbus_dict_close_write(&iter, &dict_iter)) { !wpa_dbus_dict_close_write(&iter, &dict_iter))
wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_success" wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"[dbus]: out of memory"); else
goto out; dbus_connection_send(iface->con, msg, NULL);
}
dbus_connection_send(iface->con, _signal, NULL); dbus_message_unref(msg);
out:
dbus_message_unref(_signal);
} }
@ -582,7 +539,7 @@ void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
struct wps_event_fail *fail) struct wps_event_fail *fail)
{ {
DBusMessage *_signal = NULL; DBusMessage *msg;
DBusMessageIter iter, dict_iter; DBusMessageIter iter, dict_iter;
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
char *key = "fail"; char *key = "fail";
@ -593,28 +550,22 @@ void wpas_dbus_signal_wps_event_fail(struct wpa_supplicant *wpa_s,
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_WPS, "Event"); WPAS_DBUS_NEW_IFACE_WPS, "Event");
if (!_signal) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_fail[dbus]: "
"out of memory when creating a signal");
return; return;
}
dbus_message_iter_init_append(_signal, &iter); dbus_message_iter_init_append(msg, &iter);
if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) || if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
!wpa_dbus_dict_open_write(&iter, &dict_iter) || !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
!wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) || !wpa_dbus_dict_append_int32(&dict_iter, "msg", fail->msg) ||
!wpa_dbus_dict_close_write(&iter, &dict_iter)) { !wpa_dbus_dict_close_write(&iter, &dict_iter))
wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_fail[dbus]: " wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"out of memory"); else
goto out; dbus_connection_send(iface->con, msg, NULL);
}
dbus_connection_send(iface->con, _signal, NULL); dbus_message_unref(msg);
out:
dbus_message_unref(_signal);
} }
@ -629,7 +580,7 @@ void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
struct wps_event_m2d *m2d) struct wps_event_m2d *m2d)
{ {
DBusMessage *_signal = NULL; DBusMessage *msg;
DBusMessageIter iter, dict_iter; DBusMessageIter iter, dict_iter;
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
char *key = "m2d"; char *key = "m2d";
@ -640,52 +591,46 @@ void wpas_dbus_signal_wps_event_m2d(struct wpa_supplicant *wpa_s,
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_WPS, "Event"); WPAS_DBUS_NEW_IFACE_WPS, "Event");
if (!_signal) { if (msg == NULL)
wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_m2d[dbus]: "
"out of memory when creating a signal");
return; return;
}
dbus_message_iter_init_append(_signal, &iter); dbus_message_iter_init_append(msg, &iter);
if (!(dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) && if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key) ||
wpa_dbus_dict_open_write(&iter, &dict_iter) && !wpa_dbus_dict_open_write(&iter, &dict_iter) ||
wpa_dbus_dict_append_uint16(&dict_iter, "config_methods", !wpa_dbus_dict_append_uint16(&dict_iter, "config_methods",
m2d->config_methods) && m2d->config_methods) ||
wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer", !wpa_dbus_dict_append_byte_array(&dict_iter, "manufacturer",
(const char *) m2d->manufacturer, (const char *) m2d->manufacturer,
m2d->manufacturer_len) && m2d->manufacturer_len) ||
wpa_dbus_dict_append_byte_array(&dict_iter, "model_name", !wpa_dbus_dict_append_byte_array(&dict_iter, "model_name",
(const char *) m2d->model_name, (const char *) m2d->model_name,
m2d->model_name_len) && m2d->model_name_len) ||
wpa_dbus_dict_append_byte_array(&dict_iter, "model_number", !wpa_dbus_dict_append_byte_array(&dict_iter, "model_number",
(const char *) m2d->model_number, (const char *) m2d->model_number,
m2d->model_number_len) && m2d->model_number_len) ||
wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number", !wpa_dbus_dict_append_byte_array(&dict_iter, "serial_number",
(const char *) (const char *)
m2d->serial_number, m2d->serial_number,
m2d->serial_number_len) && m2d->serial_number_len) ||
wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name", !wpa_dbus_dict_append_byte_array(&dict_iter, "dev_name",
(const char *) m2d->dev_name, (const char *) m2d->dev_name,
m2d->dev_name_len) && m2d->dev_name_len) ||
wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type", !wpa_dbus_dict_append_byte_array(&dict_iter, "primary_dev_type",
(const char *) (const char *)
m2d->primary_dev_type, 8) && m2d->primary_dev_type, 8) ||
wpa_dbus_dict_append_uint16(&dict_iter, "config_error", !wpa_dbus_dict_append_uint16(&dict_iter, "config_error",
m2d->config_error) && m2d->config_error) ||
wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id", !wpa_dbus_dict_append_uint16(&dict_iter, "dev_password_id",
m2d->dev_password_id) && m2d->dev_password_id) ||
wpa_dbus_dict_close_write(&iter, &dict_iter))) { !wpa_dbus_dict_close_write(&iter, &dict_iter))
wpa_printf(MSG_ERROR, "wpas_dbus_signal_wps_event_m2d[dbus]: " wpa_printf(MSG_ERROR, "dbus: Failed to construct signal");
"out of memory"); else
goto out; dbus_connection_send(iface->con, msg, NULL);
}
dbus_connection_send(iface->con, _signal, NULL); dbus_message_unref(msg);
out:
dbus_message_unref(_signal);
} }
@ -698,7 +643,7 @@ out:
void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s, void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
const struct wps_credential *cred) const struct wps_credential *cred)
{ {
DBusMessage *_signal = NULL; DBusMessage *msg;
DBusMessageIter iter, dict_iter; DBusMessageIter iter, dict_iter;
struct wpas_dbus_priv *iface; struct wpas_dbus_priv *iface;
char *auth_type[6]; /* we have six possible authorization types */ char *auth_type[6]; /* we have six possible authorization types */
@ -712,14 +657,13 @@ void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
if (iface == NULL) if (iface == NULL)
return; return;
_signal = dbus_message_new_signal(wpa_s->dbus_new_path, msg = dbus_message_new_signal(wpa_s->dbus_new_path,
WPAS_DBUS_NEW_IFACE_WPS, WPAS_DBUS_NEW_IFACE_WPS,
"Credentials"); "Credentials");
if (!_signal) if (msg == NULL)
return; return;
dbus_message_iter_init_append(_signal, &iter); dbus_message_iter_init_append(msg, &iter);
if (!wpa_dbus_dict_open_write(&iter, &dict_iter)) if (!wpa_dbus_dict_open_write(&iter, &dict_iter))
goto nomem; goto nomem;
@ -754,29 +698,27 @@ void wpas_dbus_signal_wps_cred(struct wpa_supplicant *wpa_s,
goto nomem; goto nomem;
} }
if (!(wpa_dbus_dict_append_byte_array(&dict_iter, "SSID", if (!wpa_dbus_dict_append_byte_array(&dict_iter, "SSID",
(const char *) cred->ssid, (const char *) cred->ssid,
cred->ssid_len) && cred->ssid_len) ||
wpa_dbus_dict_append_string_array(&dict_iter, "AuthType", !wpa_dbus_dict_append_string_array(&dict_iter, "AuthType",
(const char **) auth_type, (const char **) auth_type,
at_num) && at_num) ||
wpa_dbus_dict_append_string_array(&dict_iter, "EncrType", !wpa_dbus_dict_append_string_array(&dict_iter, "EncrType",
(const char **) encr_type, (const char **) encr_type,
et_num) && et_num) ||
wpa_dbus_dict_append_byte_array(&dict_iter, "Key", !wpa_dbus_dict_append_byte_array(&dict_iter, "Key",
(const char *) cred->key, (const char *) cred->key,
cred->key_len) && cred->key_len) ||
wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex", !wpa_dbus_dict_append_uint32(&dict_iter, "KeyIndex",
cred->key_idx))) cred->key_idx) ||
!wpa_dbus_dict_close_write(&iter, &dict_iter))
goto nomem; goto nomem;
if (!wpa_dbus_dict_close_write(&iter, &dict_iter)) dbus_connection_send(iface->con, msg, NULL);
goto nomem;
dbus_connection_send(iface->con, _signal, NULL);
nomem: nomem:
dbus_message_unref(_signal); dbus_message_unref(msg);
} }
#endif /* CONFIG_WPS */ #endif /* CONFIG_WPS */
@ -794,46 +736,36 @@ void wpas_dbus_signal_prop_changed(struct wpa_supplicant *wpa_s,
enum wpas_dbus_prop property) enum wpas_dbus_prop property)
{ {
WPADBusPropertyAccessor getter; WPADBusPropertyAccessor getter;
char *iface;
char *prop; char *prop;
void *arg;
switch (property) { switch (property) {
case WPAS_DBUS_PROP_AP_SCAN: case WPAS_DBUS_PROP_AP_SCAN:
getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan; getter = (WPADBusPropertyAccessor) wpas_dbus_getter_ap_scan;
arg = wpa_s;
iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
prop = "ApScan"; prop = "ApScan";
break; break;
case WPAS_DBUS_PROP_SCANNING: case WPAS_DBUS_PROP_SCANNING:
getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning; getter = (WPADBusPropertyAccessor) wpas_dbus_getter_scanning;
arg = wpa_s;
iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
prop = "Scanning"; prop = "Scanning";
break; break;
case WPAS_DBUS_PROP_CURRENT_BSS: case WPAS_DBUS_PROP_CURRENT_BSS:
getter = (WPADBusPropertyAccessor) getter = (WPADBusPropertyAccessor)
wpas_dbus_getter_current_bss; wpas_dbus_getter_current_bss;
arg = wpa_s;
iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
prop = "CurrentBSS"; prop = "CurrentBSS";
break; break;
case WPAS_DBUS_PROP_CURRENT_NETWORK: case WPAS_DBUS_PROP_CURRENT_NETWORK:
getter = (WPADBusPropertyAccessor) getter = (WPADBusPropertyAccessor)
wpas_dbus_getter_current_network; wpas_dbus_getter_current_network;
arg = wpa_s;
iface = WPAS_DBUS_NEW_IFACE_INTERFACE;
prop = "CurrentNetwork"; prop = "CurrentNetwork";
break; break;
default: default:
wpa_printf(MSG_ERROR, "wpas_dbus_signal_prop_changed[dbus]: " wpa_printf(MSG_ERROR, "dbus: %s: Unknown Property value %d",
"Unknown Property enum value %d", property); __func__, property);
return; return;
} }
wpa_dbus_signal_property_changed(wpa_s->global->dbus, wpa_dbus_signal_property_changed(wpa_s->global->dbus,
getter, arg, wpa_s->dbus_new_path, getter, wpa_s, wpa_s->dbus_new_path,
iface, prop); WPAS_DBUS_NEW_IFACE_INTERFACE, prop);
} }

View file

@ -37,7 +37,7 @@ static void recursive_iter_copy(DBusMessageIter *from, DBusMessageIter *to)
int type; int type;
/* iterate over iterator to copy */ /* iterate over iterator to copy */
while ((type = dbus_message_iter_get_arg_type (from)) != while ((type = dbus_message_iter_get_arg_type(from)) !=
DBUS_TYPE_INVALID) { DBUS_TYPE_INVALID) {
/* simply copy basic type entries */ /* simply copy basic type entries */
@ -49,12 +49,12 @@ static void recursive_iter_copy(DBusMessageIter *from, DBusMessageIter *to)
* 8 bytes * 8 bytes
*/ */
dbus_uint64_t v; dbus_uint64_t v;
dbus_message_iter_get_basic (from, &v); dbus_message_iter_get_basic(from, &v);
dbus_message_iter_append_basic (to, type, &v); dbus_message_iter_append_basic(to, type, &v);
} else { } else {
char *v; char *v;
dbus_message_iter_get_basic (from, &v); dbus_message_iter_get_basic(from, &v);
dbus_message_iter_append_basic (to, type, &v); dbus_message_iter_append_basic(to, type, &v);
} }
} else { } else {
/* recursively copy container type entries */ /* recursively copy container type entries */
@ -960,90 +960,62 @@ void wpa_dbus_signal_property_changed(struct wpas_dbus_priv *iface,
{ {
DBusConnection *connection; DBusConnection *connection;
DBusMessage *_signal, *getter_reply; DBusMessage *msg, *getter_reply;
DBusMessageIter prop_iter, signal_iter, dict_iter, entry_iter; DBusMessageIter prop_iter, signal_iter, dict_iter, entry_iter;
if (!iface) if (!iface)
return; return;
connection = iface->con; connection = iface->con;
if (!property_getter) { if (!property_getter || !path || !interface_name || !property_name) {
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed" wpa_printf(MSG_ERROR, "dbus: %s: A parameter not specified",
"[dbus]: property getter not specified"); __func__);
return;
}
if (!path || !interface_name || !property_name) {
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed"
"[dbus]: path interface of property not specified");
return; return;
} }
getter_reply = property_getter(NULL, getter_arg); getter_reply = property_getter(NULL, getter_arg);
if (!getter_reply || if (!getter_reply ||
dbus_message_get_type(getter_reply) == DBUS_MESSAGE_TYPE_ERROR) { dbus_message_get_type(getter_reply) == DBUS_MESSAGE_TYPE_ERROR) {
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed" wpa_printf(MSG_ERROR, "dbus: %s: Cannot get new value of "
"[dbus]: cannot get new value of property %s", "property %s", __func__, property_name);
property_name);
return; return;
} }
_signal = dbus_message_new_signal(path, interface_name, msg = dbus_message_new_signal(path, interface_name,
"PropertiesChanged"); "PropertiesChanged");
if (!_signal) { if (msg == NULL) {
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed"
"[dbus]: cannot allocate signal");
dbus_message_unref(getter_reply); dbus_message_unref(getter_reply);
return; return;
} }
dbus_message_iter_init(getter_reply, &prop_iter); dbus_message_iter_init(getter_reply, &prop_iter);
dbus_message_iter_init_append(_signal, &signal_iter); dbus_message_iter_init_append(msg, &signal_iter);
if (!dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_ARRAY, if (!dbus_message_iter_open_container(&signal_iter, DBUS_TYPE_ARRAY,
"{sv}", &dict_iter)) { "{sv}", &dict_iter) ||
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed" !dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_DICT_ENTRY,
"[dbus]: out of memory. cannot open dictionary"); NULL, &entry_iter) ||
!dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING,
&property_name))
goto err; goto err;
}
if (!dbus_message_iter_open_container(&dict_iter, DBUS_TYPE_DICT_ENTRY,
NULL, &entry_iter)) {
wpa_printf(MSG_ERROR, "iwpa_dbus_signal_property_changed"
"[dbus]: out of memory. cannot open dictionary "
"element");
goto err;
}
if (!dbus_message_iter_append_basic(&entry_iter, DBUS_TYPE_STRING,
&property_name)) {
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed"
"[dbus]: out of memory. cannot open add property "
"name");
goto err;
}
recursive_iter_copy(&prop_iter, &entry_iter); recursive_iter_copy(&prop_iter, &entry_iter);
if (!dbus_message_iter_close_container(&dict_iter, &entry_iter)) { if (!dbus_message_iter_close_container(&dict_iter, &entry_iter) ||
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed" !dbus_message_iter_close_container(&signal_iter, &dict_iter))
"[dbus]: out of memory. cannot close dictionary "
"element");
goto err; goto err;
}
if (!dbus_message_iter_close_container(&signal_iter, &dict_iter)) { dbus_connection_send(connection, msg, NULL);
wpa_printf(MSG_ERROR, "wpa_dbus_signal_property_changed"
"[dbus]: out of memory. cannot close dictionary");
goto err;
}
dbus_connection_send(connection, _signal, NULL); out:
dbus_message_unref(getter_reply);
dbus_message_unref(msg);
return;
err: err:
dbus_message_unref(getter_reply); wpa_printf(MSG_DEBUG, "dbus: %s: Failed to construct signal",
dbus_message_unref(_signal); __func__);
goto out;
} }