From patchwork Fri Apr 13 07:33:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrien Bustany X-Patchwork-Id: 152257 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id A43C0B7013 for ; Fri, 13 Apr 2012 17:32:06 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C7B1F9D229; Fri, 13 Apr 2012 03:32:03 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id chF2tR7+UV+R; Fri, 13 Apr 2012 03:32:03 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id E03449D22A; Fri, 13 Apr 2012 03:31:58 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 24B8D9D22F for ; Fri, 13 Apr 2012 03:31:58 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IOiSQ-VsZ-bR for ; Fri, 13 Apr 2012 03:31:53 -0400 (EDT) Received: from mgw-sa02.nokia.com (smtp.nokia.com [147.243.1.48]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "smtp.nokia.com", Issuer "VeriSign Class 3 International Server CA - G3" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 38F269D229 for ; Fri, 13 Apr 2012 03:31:53 -0400 (EDT) Received: from pressepapier.europe.nokia.com (esdhcp00078.europe.nokia.com [172.22.0.78]) by mgw-sa02.nokia.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q3D7VlGp027867 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 13 Apr 2012 10:31:51 +0300 From: Adrien Bustany To: hostap@lists.shmoo.com Subject: [PATCH 2/2] P2P: Don't rely on dictionary ordering in wpas_dbus_handler_p2p_add_service Date: Fri, 13 Apr 2012 10:33:33 +0300 Message-Id: <1334302413-22098-3-git-send-email-adrien@bustany.org> X-Mailer: git-send-email 1.7.8.1 In-Reply-To: <1334302413-22098-1-git-send-email-adrien@bustany.org> References: <1334302413-22098-1-git-send-email-adrien@bustany.org> X-Nokia-AV: Clean X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Adrien Bustany In most languages, DBus dictionaries are mapped to either sorted maps or hash tables, so you can't control the actual ordering of the generated a{sv}. Relying on ordering in this method is unnecessary and makes it use from DBus much harder. Signed-hostap: Adrien Bustany --- wpa_supplicant/dbus/dbus_new_handlers_p2p.c | 49 +++++++++++--------------- 1 files changed, 21 insertions(+), 28 deletions(-) diff --git a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c index 12e095a..6adb547 100644 --- a/wpa_supplicant/dbus/dbus_new_handlers_p2p.c +++ b/wpa_supplicant/dbus/dbus_new_handlers_p2p.c @@ -2066,7 +2066,7 @@ DBusMessage * wpas_dbus_handler_p2p_add_service(DBusMessage *message, if (!wpa_dbus_dict_open_read(&iter, &iter_dict, NULL)) goto error; - if (wpa_dbus_dict_has_dict_entry(&iter_dict)) { + while (wpa_dbus_dict_has_dict_entry(&iter_dict)) { if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) goto error; @@ -2078,23 +2078,30 @@ DBusMessage * wpas_dbus_handler_p2p_add_service(DBusMessage *message, bonjour = 1; else goto error_clear; - wpa_dbus_dict_entry_clear(&entry); + } else if (!os_strcmp(entry.key, "version") && + entry.type == DBUS_TYPE_INT32) { + version = entry.uint32_value; + } else if (!os_strcmp(entry.key, "service") && + (entry.type == DBUS_TYPE_STRING)) { + service = os_strdup(entry.str_value); + } else if (!os_strcmp(entry.key, "query")) { + if ((entry.type != DBUS_TYPE_ARRAY) || + (entry.array_type != DBUS_TYPE_BYTE)) + goto error_clear; + query = wpabuf_alloc_copy( + entry.bytearray_value, + entry.array_len); + } else if (!os_strcmp(entry.key, "response")) { + if ((entry.type != DBUS_TYPE_ARRAY) || + (entry.array_type != DBUS_TYPE_BYTE)) + goto error_clear; + resp = wpabuf_alloc_copy(entry.bytearray_value, + entry.array_len); } + wpa_dbus_dict_entry_clear(&entry); } if (upnp == 1) { - while (wpa_dbus_dict_has_dict_entry(&iter_dict)) { - if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) - goto error; - - if (!os_strcmp(entry.key, "version") && - entry.type == DBUS_TYPE_INT32) - version = entry.uint32_value; - else if (!os_strcmp(entry.key, "service") && - entry.type == DBUS_TYPE_STRING) - service = os_strdup(entry.str_value); - wpa_dbus_dict_entry_clear(&entry); - } if (version <= 0 || service == NULL) goto error; @@ -2107,20 +2114,6 @@ DBusMessage * wpas_dbus_handler_p2p_add_service(DBusMessage *message, if (!wpa_dbus_dict_get_entry(&iter_dict, &entry)) goto error; - if (!os_strcmp(entry.key, "query")) { - if ((entry.type != DBUS_TYPE_ARRAY) || - (entry.array_type != DBUS_TYPE_BYTE)) - goto error_clear; - query = wpabuf_alloc_copy( - entry.bytearray_value, - entry.array_len); - } else if (!os_strcmp(entry.key, "response")) { - if ((entry.type != DBUS_TYPE_ARRAY) || - (entry.array_type != DBUS_TYPE_BYTE)) - goto error_clear; - resp = wpabuf_alloc_copy(entry.bytearray_value, - entry.array_len); - } wpa_dbus_dict_entry_clear(&entry); }