packet-smb2: maintain a smb2_fid_info per open file
[metze/wireshark/wip.git] / epan / guid-utils.c
index 3e44f46a98e58f2cab5b981287678cf60c170c03..8bb95b98b5bc33b2f22daa729522bf7d8ffa8063 100644 (file)
@@ -1,8 +1,6 @@
 /* guid-utils.c
  * GUID handling
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  *
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 
 #include <string.h>
 
 #include <glib.h>
 #include <epan/epan.h>
 #include <wsutil/unicode-utils.h>
-#include <epan/emem.h>
+#include <epan/wmem/wmem.h>
 #include "guid-utils.h"
 
 #ifdef _WIN32
 #include <windows.h>
 #endif
 
-static emem_tree_t *guid_to_name_tree = NULL;
+static wmem_tree_t *guid_to_name_tree = NULL;
 
 
 #ifdef _WIN32
-/* try to resolve an DCE/RPC interface name to it's name using the Windows registry entries */
+/* try to resolve an DCE/RPC interface name to its name using the Windows registry entries */
 /* XXX - might be better to fill all interfaces into our database at startup instead of searching each time */
 int
 ResolveWin32UUID(e_guid_t if_id, char *uuid_name, int uuid_name_max_len)
@@ -54,8 +50,8 @@ ResolveWin32UUID(e_guid_t if_id, char *uuid_name, int uuid_name_max_len)
        DWORD uuid_max_size = MAX_PATH;
        TCHAR *reg_uuid_str;
 
-       reg_uuid_name=ep_alloc(MAX_PATH*sizeof(TCHAR));
-       reg_uuid_str=ep_alloc(MAX_PATH*sizeof(TCHAR));
+       reg_uuid_name=wmem_alloc(wmem_packet_scope(), (MAX_PATH*sizeof(TCHAR))+1);
+       reg_uuid_str=wmem_alloc(wmem_packet_scope(), (MAX_PATH*sizeof(TCHAR))+1);
 
        if(uuid_name_max_len < 2){
                return 0;
@@ -83,9 +79,9 @@ ResolveWin32UUID(e_guid_t if_id, char *uuid_name, int uuid_name_max_len)
 
 /* store a guid to name mapping */
 void
-guids_add_guid(e_guid_t *guid, const gchar *name)
+guids_add_guid(const e_guid_t *guid, const gchar *name)
 {
-       emem_tree_key_t guidkey[2];
+       wmem_tree_key_t guidkey[2];
        guint32 g[4];
 
        g[0]=guid->data1;
@@ -114,15 +110,15 @@ guids_add_guid(e_guid_t *guid, const gchar *name)
        guidkey[0].length=4;
        guidkey[1].length=0;
 
-       pe_tree_insert32_array(guid_to_name_tree, &guidkey[0], (gchar *) name);
+       wmem_tree_insert32_array(guid_to_name_tree, &guidkey[0], (gchar *) name);
 }
 
 
 /* retrieve the registered name for this GUID */
 const gchar *
-guids_get_guid_name(e_guid_t *guid)
+guids_get_guid_name(const e_guid_t *guid)
 {
-       emem_tree_key_t guidkey[2];
+       wmem_tree_key_t guidkey[2];
        guint32 g[4];
        char *name;
 #ifdef _WIN32
@@ -155,14 +151,14 @@ guids_get_guid_name(e_guid_t *guid)
        guidkey[0].length=4;
        guidkey[1].length=0;
 
-       if((name = pe_tree_lookup32_array(guid_to_name_tree, &guidkey[0]))){
+       if((name = (char *)wmem_tree_lookup32_array(guid_to_name_tree, &guidkey[0]))){
                return name;
        }
 
 #ifdef _WIN32
        /* try to resolve the mapping from the Windows registry */
        /* XXX - prefill the resolving database with all the Windows registry entries once at init only (instead of searching each time)? */
-       uuid_name=ep_alloc(128);
+       uuid_name=wmem_alloc(wmem_packet_scope(), 128);
        if(ResolveWin32UUID(*guid, uuid_name, 128)) {
                return uuid_name;
        }
@@ -175,7 +171,7 @@ guids_get_guid_name(e_guid_t *guid)
 void
 guids_init(void)
 {
-       guid_to_name_tree=pe_tree_create(EMEM_TREE_TYPE_RED_BLACK, "guid_to_name");
+       guid_to_name_tree=wmem_tree_new(wmem_epan_scope());
        /* XXX here is a good place to read a config file with wellknown guids */
 }
 
@@ -185,7 +181,7 @@ guids_init(void)
    Formats uuid number and returns the resulting string, if name is unknown.
    (derived from val_to_str) */
 const gchar *
-guids_resolve_guid_to_str(e_guid_t *guid)
+guids_resolve_guid_to_str(const e_guid_t *guid)
 {
        const gchar *name;
 
@@ -194,11 +190,40 @@ guids_resolve_guid_to_str(e_guid_t *guid)
                return name;
        }
 
-       return ep_strdup_printf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
-                      guid->data1, guid->data2, guid->data3,
-                      guid->data4[0], guid->data4[1],
-                      guid->data4[2], guid->data4[3],
-                      guid->data4[4], guid->data4[5],
-                      guid->data4[6], guid->data4[7]);
+       return wmem_strdup_printf(wmem_packet_scope(), "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
+                               guid->data1, guid->data2, guid->data3,
+                               guid->data4[0], guid->data4[1],
+                               guid->data4[2], guid->data4[3],
+                               guid->data4[4], guid->data4[5],
+                               guid->data4[6], guid->data4[7]);
+}
+
+int guid_cmp(const e_guid_t *g1, const e_guid_t *g2)
+{
+       if (g1->data1 != g2->data1) {
+               return (g1->data1 < g2->data1) ? -1 : 1;
+       }
+
+       if (g1->data2 != g2->data2) {
+               return (g1->data2 < g2->data2) ? -1 : 1;
+       }
+
+       if (g1->data3 != g2->data3) {
+               return (g1->data3 < g2->data3) ? -1 : 1;
+       }
+
+       return memcmp(&g1->data4[0], &g2->data4[0], 8);
 }
 
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */