MSWSP: add two more Property Sets
[wireshark-wip.git] / epan / ftypes / ftype-guid.c
blob191694bee67bbb31a68aff1e824ea55c6312f9c6
1 /*
2 * $Id$
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 2001 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "config.h"
25 #include <string.h>
26 #include <stdlib.h>
27 #include <ctype.h>
29 #include <ftypes-int.h>
30 #include <epan/guid-utils.h>
31 #include <epan/to_str.h>
33 static void
34 guid_fvalue_set(fvalue_t *fv, gpointer value, gboolean already_copied)
36 g_assert(!already_copied);
37 fv->value.guid = *(e_guid_t*)value;
40 static gpointer
41 value_get(fvalue_t *fv)
43 return &(fv->value.guid);
46 static gboolean
47 get_guid(char *s, e_guid_t *guid)
49 size_t i, n;
50 char *p, digits[9];
51 static const char fmt[] = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
53 n = strlen(s);
54 if (n != strlen(fmt))
55 return FALSE;
56 for (i=0; i<n; i++) {
57 if (fmt[i] == 'X') {
58 if (!isxdigit((guchar)s[i]))
59 return FALSE;
60 } else {
61 if (s[i] != fmt[i])
62 return FALSE;
66 p = s;
67 strncpy(digits, p, 8);
68 digits[8] = '\0';
69 guid->data1 = (guint32)strtoul(digits, NULL, 16);
70 p += 9;
71 strncpy(digits, p, 4);
72 digits[4] = '\0';
73 guid->data2 = (guint16)strtoul(digits, NULL, 16);
74 p += 5;
75 strncpy(digits, p, 4);
76 digits[4] = '\0';
77 guid->data3 = (guint16)strtoul(digits, NULL, 16);
78 p += 5;
79 for (i=0; i < sizeof(guid->data4); i++) {
80 if (*p == '-') p++;
81 digits[0] = *(p++);
82 digits[1] = *(p++);
83 digits[2] = '\0';
84 guid->data4[i] = (guint8)strtoul(digits, NULL, 16);
86 return TRUE;
89 static gboolean
90 guid_from_unparsed(fvalue_t *fv, char *s, gboolean allow_partial_value _U_, LogFunc logfunc)
92 e_guid_t guid;
94 if (!get_guid(s, &guid)) {
95 logfunc("\"%s\" is not a valid GUID.", s);
96 return FALSE;
99 fv->value.guid = guid;
100 return TRUE;
103 static int
104 guid_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_)
106 return GUID_STR_LEN;
109 static void
110 guid_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, char *buf)
112 guid_to_str_buf(&fv->value.guid, buf, GUID_STR_LEN);
115 static gboolean
116 cmp_eq(const fvalue_t *a, const fvalue_t *b)
118 return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t)) == 0;
121 static gboolean
122 cmp_ne(const fvalue_t *a, const fvalue_t *b)
124 return memcmp(&a->value.guid, &b->value.guid, sizeof(e_guid_t)) != 0;
127 void
128 ftype_register_guid(void)
131 static ftype_t guid_type = {
132 FT_GUID, /* ftype */
133 "FT_GUID", /* name */
134 "Globally Unique Identifier", /* pretty_name */
135 GUID_LEN, /* wire_size */
136 NULL, /* new_value */
137 NULL, /* free_value */
138 guid_from_unparsed, /* val_from_unparsed */
139 NULL, /* val_from_string */
140 guid_to_repr, /* val_to_string_repr */
141 guid_repr_len, /* len_string_repr */
143 guid_fvalue_set, /* set_value */
144 NULL, /* set_value_uinteger */
145 NULL, /* set_value_sinteger */
146 NULL, /* set_value_integer64 */
147 NULL, /* set_value_floating */
149 value_get, /* get_value */
150 NULL, /* get_value_uinteger */
151 NULL, /* get_value_sinteger */
152 NULL, /* get_value_integer64 */
153 NULL, /* get_value_floating */
155 cmp_eq,
156 cmp_ne,
157 NULL,
158 NULL,
159 NULL,
160 NULL,
161 NULL,
162 NULL,
163 NULL, /* cmp_matches */
165 NULL,
166 NULL,
169 ftype_register(FT_GUID, &guid_type);