aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-01-01 16:56:07 (GMT)
committerJouni Malinen <j@w1.fi>2010-01-01 16:56:07 (GMT)
commit191204982810b21cd6459c89103b7dd452e0350d (patch)
tree848b17fe1c4c5ace0c0d30c70d70a0bff6f465a5
parent52bdd880a30b50d96d20f2bf0c998381bfc8f291 (diff)
downloadhostap-191204982810b21cd6459c89103b7dd452e0350d.zip
hostap-191204982810b21cd6459c89103b7dd452e0350d.tar.gz
hostap-191204982810b21cd6459c89103b7dd452e0350d.tar.bz2
dbus: Get rid of unnecessary string duplication in dbus_path
There is no point in making it so complex to initialize a string with two allocations and a function call.
-rw-r--r--wpa_supplicant/dbus/dbus_new.c43
-rw-r--r--wpa_supplicant/dbus/dbus_old.c40
-rw-r--r--wpa_supplicant/dbus/dbus_old.h2
3 files changed, 17 insertions, 68 deletions
diff --git a/wpa_supplicant/dbus/dbus_new.c b/wpa_supplicant/dbus/dbus_new.c
index a37419e..2941567 100644
--- a/wpa_supplicant/dbus/dbus_new.c
+++ b/wpa_supplicant/dbus/dbus_new.c
@@ -28,24 +28,6 @@
#include "dbus_common.h"
#include "dbus_common_i.h"
-/**
- * wpas_dbus_set_path - Assign a dbus path to an interface
- * @wpa_s: wpa_supplicant interface structure
- * @path: dbus path to set on the interface
- * Returns: 0 on success, -1 on error
- */
-static int wpas_dbus_set_path(struct wpa_supplicant *wpa_s,
- const char *path)
-{
- u32 len = os_strlen(path);
- if (len >= WPAS_DBUS_OBJECT_PATH_MAX)
- return -1;
- if (wpa_s->dbus_new_path)
- return -1;
- wpa_s->dbus_new_path = os_strdup(path);
- return 0;
-}
-
/**
* wpas_dbus_signal_interface - Send a interface related event signal
@@ -1766,7 +1748,6 @@ int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
{
struct wpa_dbus_object_desc *obj_desc = NULL;
- char *path;
struct wpas_dbus_priv *ctrl_iface = wpa_s->global->dbus;
int next;
@@ -1775,19 +1756,13 @@ int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
return 0;
/* Create and set the interface's object path */
- path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (path == NULL)
+ wpa_s->dbus_new_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
+ if (wpa_s->dbus_new_path == NULL)
return -1;
next = ctrl_iface->next_objid++;
- os_snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
+ os_snprintf(wpa_s->dbus_new_path, WPAS_DBUS_OBJECT_PATH_MAX,
WPAS_DBUS_NEW_PATH_INTERFACES "/%u",
next);
- if (wpas_dbus_set_path(wpa_s, path)) {
- wpa_printf(MSG_DEBUG,
- "Failed to set dbus path for interface %s",
- wpa_s->ifname);
- goto err;
- }
obj_desc = os_zalloc(sizeof(struct wpa_dbus_object_desc));
if (!obj_desc) {
@@ -1800,19 +1775,21 @@ int wpas_dbus_register_interface(struct wpa_supplicant *wpa_s)
wpas_dbus_interface_properties,
wpas_dbus_interface_signals);
- wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'", path);
- if (wpa_dbus_register_object_per_iface(ctrl_iface, path, wpa_s->ifname,
- obj_desc))
+ wpa_printf(MSG_DEBUG, "dbus: Register interface object '%s'",
+ wpa_s->dbus_new_path);
+ if (wpa_dbus_register_object_per_iface(ctrl_iface,
+ wpa_s->dbus_new_path,
+ wpa_s->ifname, obj_desc))
goto err;
wpas_dbus_signal_interface_added(wpa_s);
- os_free(path);
return 0;
err:
+ os_free(wpa_s->dbus_new_path);
+ wpa_s->dbus_new_path = NULL;
os_free(obj_desc);
- os_free(path);
return -1;
}
diff --git a/wpa_supplicant/dbus/dbus_old.c b/wpa_supplicant/dbus/dbus_old.c
index 2cf7ec6..674b9ff 100644
--- a/wpa_supplicant/dbus/dbus_old.c
+++ b/wpa_supplicant/dbus/dbus_old.c
@@ -696,7 +696,6 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
DBusObjectPathVTable vtable = {
NULL, &wpas_iface_message_handler, NULL, NULL, NULL, NULL
};
- char *path;
int ret = -1;
/* Do nothing if the control interface is not turned on */
@@ -707,21 +706,16 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
next = ctrl_iface->next_objid++;
/* Create and set the interface's object path */
- path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
- if (path == NULL)
+ wpa_s->dbus_path = os_zalloc(WPAS_DBUS_OBJECT_PATH_MAX);
+ if (wpa_s->dbus_path == NULL)
return -1;
- snprintf(path, WPAS_DBUS_OBJECT_PATH_MAX,
- WPAS_DBUS_PATH_INTERFACES "/%u",
- next);
- if (wpa_supplicant_set_dbus_path(wpa_s, path)) {
- wpa_printf(MSG_DEBUG,
- "Failed to set dbus path for interface %s",
- wpa_s->ifname);
- goto out;
- }
+ os_snprintf(wpa_s->dbus_path, WPAS_DBUS_OBJECT_PATH_MAX,
+ WPAS_DBUS_PATH_INTERFACES "/%u",
+ next);
/* Register the message handler for the interface functions */
- if (!dbus_connection_register_fallback(con, path, &vtable, wpa_s)) {
+ if (!dbus_connection_register_fallback(con, wpa_s->dbus_path, &vtable,
+ wpa_s)) {
perror("wpas_dbus_register_iface [dbus]");
wpa_printf(MSG_ERROR, "Could not set up DBus message "
"handler for interface %s.", wpa_s->ifname);
@@ -730,7 +724,6 @@ int wpas_dbus_register_iface(struct wpa_supplicant *wpa_s)
ret = 0;
out:
- os_free(path);
return ret;
}
@@ -788,25 +781,6 @@ struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
/**
- * wpa_supplicant_set_dbus_path - Assign a dbus path to an interface
- * @wpa_s: wpa_supplicant interface structure
- * @path: dbus path to set on the interface
- * Returns: 0 on succes, -1 on error
- */
-int wpa_supplicant_set_dbus_path(struct wpa_supplicant *wpa_s,
- const char *path)
-{
- u32 len = strlen (path);
- if (len >= WPAS_DBUS_OBJECT_PATH_MAX)
- return -1;
- if (wpa_s->dbus_path)
- return -1;
- wpa_s->dbus_path = os_strdup(path);
- return 0;
-}
-
-
-/**
* wpa_supplicant_get_dbus_path - Get an interface's dbus path
* @wpa_s: %wpa_supplicant interface structure
* Returns: Interface's dbus object path, or %NULL on error
diff --git a/wpa_supplicant/dbus/dbus_old.h b/wpa_supplicant/dbus/dbus_old.h
index 5aef01d..4c0b50d 100644
--- a/wpa_supplicant/dbus/dbus_old.h
+++ b/wpa_supplicant/dbus/dbus_old.h
@@ -91,8 +91,6 @@ int wpas_dbus_unregister_iface(struct wpa_supplicant *wpa_s);
/* Methods internal to the dbus control interface */
-int wpa_supplicant_set_dbus_path(struct wpa_supplicant *wpa_s,
- const char *path);
const char *wpa_supplicant_get_dbus_path(struct wpa_supplicant *wpa_s);
struct wpa_supplicant * wpa_supplicant_get_iface_by_dbus_path(
struct wpa_global *global, const char *path);