/* 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)
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;
/* 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;
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
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;
}
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 */
}
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;
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:
+ */