4 * User Accessible Tables
5 * Maintain an array of user accessible data structures
7 * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 2001 Gerald Combs
13 * SPDX-License-Identifier: GPL-2.0-or-later
21 #include "ws_symbol_export.h"
22 #include <wsutil/strtoi.h>
26 #endif /* __cplusplus */
29 * UAT maintains a dynamically allocated table accessible to the user
30 * via a file and/or via GUI preference dialogs.
32 * The file is read from and written in the personal configuration directory. If
33 * there is no such file, defaults will be loaded from the global data
36 * The behaviour of the table is controlled by a series of callbacks which
37 * the caller (e.g. a dissector) must provide.
39 * BEWARE that the user can change an UAT at (almost) any time (via the GUI).
40 * That is, pointers to records in an UAT are valid only during the call
41 * to the function that obtains them (do not store pointers to these records).
42 * The records contents are only guaranteed to be valid in the post_update_cb
43 * function. (Implementation detail: currently a race condition is possible
44 * where the UAT consumer (dissector code) tries to use the UAT while the GUI
45 * user frees a record resulting in use-after-free. This is not ideal and might
48 * UATs are meant for short tables of user data (passwords and such), there is
49 * no quick access, you must iterate through them each time to fetch the record
50 * you are looking for.
52 * Only users via GUI or editing the file can add/remove records, your
53 * (dissector) code cannot.
56 /* obscure data type to handle an uat */
57 typedef struct epan_uat uat_t;
58 /********************************************
60 * these instruct uat on how to deal with user info and data in records
61 ********************************************/
64 * Callbacks dealing with the entire table
70 * To be called by the GUI code after to the table has being edited.
71 * Will be called once the user clicks the Apply or OK button
74 typedef void (*uat_post_update_cb_t)(void);
78 * Callbacks dealing with records (these deal with entire records)
83 * copy(dest, source, len)
85 * Used to duplicate the contents of one record to another.
86 * Optional, memcpy will be used if not given.
88 typedef void* (*uat_copy_cb_t)(void *dest, const void *source, size_t len);
94 * Destroy the contents of a record, possibly freeing some fields.
95 * Do not free the container itself, this memory is owned by the UAT core.
96 * Optional if the record contains no pointers that need to be freed.
98 typedef void (*uat_free_cb_t)(void *record);
103 * Used to free resources associated with a UAT loaded from file (e.g. post_update_cb)
106 typedef void (*uat_reset_cb_t)(void);
110 * update(record,&error)
112 * Validates the contents of the record contents, to be called after any record
113 * fields had been updated (either from file or after modifications in the GUI).
115 * Optional, the record will be considered valid if the callback is omitted.
116 * It must return TRUE if the contents are considered valid and FALSE otherwise
117 * in which case the failure reason is set in 'error'. The error string will be
120 typedef gboolean (*uat_update_cb_t)(void *record, char **error);
124 * Callbacks for single fields (these deal with single values)
125 * the caller should provide one of these for every field!
130 * chk(record, ptr, len, chk_data, fld_data, &error)
132 * given an input string (ptr, len) checks if the value is OK for a field in the record.
133 * it will return TRUE if OK or else
134 * it will return FALSE and set *error to inform the user on what's
135 * wrong with the given input
136 * The error string must be allocated with g_malloc() or
137 * a routine that calls it.
138 * optional, if not given any input is considered OK and the set cb will be called
140 typedef gboolean (*uat_fld_chk_cb_t)(void *record, const char *ptr, unsigned len, const void *chk_data, const void *fld_data, char **error);
144 * set(record, ptr, len, set_data, fld_data)
146 * given an input string (ptr, len) sets the value of a field in the record,
149 typedef void (*uat_fld_set_cb_t)(void *record, const char *ptr, unsigned len, const void *set_data, const void *fld_data);
152 * Convert-to-string CB
153 * tostr(record, &out_ptr, &out_len, tostr_data, fld_data)
155 * given a record returns a string representation of the field
158 typedef void (*uat_fld_tostr_cb_t)(void *record, char **out_ptr, unsigned *out_len, const void *tostr_data, const void *fld_data);
163 * used for file and dialog representation of fields in columns,
164 * when the file is read it modifies the way the value is passed back to the fld_set_cb
165 * (see definition bellow for description)
168 typedef enum _uat_text_mode_t {
176 ,"\x20\x00\x30", as " \00",3 ("space nil zero" of length 3)
180 ,"\x20\x30\x00\x20", for " 0\0 ",4
184 accepts \x?? and other escapes
185 gets "",0 on empty string
191 ,A1b2C3d4, as "\xa1\xb2\xc3\xd4",4
195 ,a1b2c3d4, on "\xa1\xb2\xc3\xd4",4
197 interprets the following input ... as ...:
198 "a1b2c3d4" as "\xa1\xb2\xc3\xd4",4
199 "a1 b2:c3d4" as "\xa1\xb2\xc3\xd4",4
205 /* Read/Writes/displays the string value (not number!) */
208 /* Reads/Writes/display color in #RRGGBB format */
211 /* processed like a PT_TXTMOD_STRING, but shows a filename dialog */
212 PT_TXTMOD_DIRECTORYNAME,
213 /* processed like a PT_TXTMOD_STRING, but shows a directory dialog */
214 PT_TXTMOD_DISPLAY_FILTER,
215 /* processed like a PT_TXTMOD_STRING, but verifies display filter */
216 PT_TXTMOD_PROTO_FIELD,
217 /* processed like a PT_TXTMOD_STRING, but verifies protocol field name (e.g tcp.flags.syn) */
219 /* Displays a checkbox for value */
227 typedef struct _uat_field_t {
230 uat_text_mode_t mode;
233 uat_fld_chk_cb_t chk;
234 uat_fld_set_cb_t set;
235 uat_fld_tostr_cb_t tostr;
244 const void* fld_data;
247 struct _fld_data_t* priv;
251 #define UAT_END_FIELDS {NULL,NULL,PT_TXTMOD_NONE,{0,0,0},{0,0,0},0,0,FLDFILL}
254 * Flags to indicate what the settings in this UAT affect.
255 * This is used when UATs are changed interactively, to indicate what needs
256 * to be redone when the UAT is changed.
258 #define UAT_AFFECTS_DISSECTION 0x00000001 /* affects packet dissection */
259 #define UAT_AFFECTS_FIELDS 0x00000002 /* affects what named fields exist */
263 * @param name The name of the table
264 * @param size The size of the structure
265 * @param filename The filename to be used (either in userdir or datadir)
266 * @param from_profile TRUE if profile directory to be used
267 * @param data_ptr Although a void*, this is really a pointer to a null terminated array of pointers to the data
268 * @param num_items_ptr A pointer with number of items
269 * @param flags flags indicating what this UAT affects
270 * @param help A pointer to help text
271 * @param copy_cb A function that copies the data in the struct
272 * @param update_cb Will be called when a record is updated
273 * @param free_cb Will be called to destroy a struct in the dataset
274 * @param post_update_cb Will be called once the user clicks the Apply or OK button
275 * @param reset_cb Will be called to destroy internal data
276 * @param flds_array A pointer to an array of uat_field_t structs
278 * @return A freshly-allocated and populated uat_t struct.
281 uat_t* uat_new(const char* name,
283 const char* filename,
284 gboolean from_profile,
286 guint* num_items_ptr,
289 uat_copy_cb_t copy_cb,
290 uat_update_cb_t update_cb,
291 uat_free_cb_t free_cb,
292 uat_post_update_cb_t post_update_cb,
293 uat_reset_cb_t reset_cb,
294 uat_field_t* flds_array);
299 void uat_cleanup(void);
301 /** Populate a uat using its file.
303 * @param uat_in Pointer to a uat. Must not be NULL.
304 * @param filename Filename to load, NULL to fetch from current profile.
305 * @param err Upon failure, points to an error string.
307 * @return TRUE on success, FALSE on failure.
310 gboolean uat_load(uat_t* uat_in, const gchar *filename, char** err);
312 /** Create or update a single uat entry using a string.
314 * @param uat_in Pointer to a uat. Must not be NULL.
315 * @param entry The string representation of the entry. Format must match
316 * what's written to the uat's output file.
317 * @param err Upon failure, points to an error string.
319 * @return TRUE on success, FALSE on failure.
321 gboolean uat_load_str(uat_t* uat_in, char* entry, char** err);
323 /** Given a uat name or filename, find its pointer.
325 * @param name The name or filename of the uat
327 * @return A pointer to the uat on success, NULL on failure.
329 uat_t *uat_find(gchar *name);
332 uat_t* uat_get_table_by_name(const char* name);
335 * Some common uat_fld_chk_cbs
338 gboolean uat_fld_chk_str(void*, const char*, unsigned, const void*, const void*, char** err);
339 gboolean uat_fld_chk_oid(void*, const char*, unsigned, const void*, const void*, char** err);
341 gboolean uat_fld_chk_proto(void*, const char*, unsigned, const void*, const void*, char** err);
343 gboolean uat_fld_chk_num_dec(void*, const char*, unsigned, const void*, const void*, char** err);
345 gboolean uat_fld_chk_num_hex(void*, const char*, unsigned, const void*, const void*, char** err);
347 gboolean uat_fld_chk_bool(void*, const char*, unsigned, const void*, const void*, char** err);
349 gboolean uat_fld_chk_enum(void*, const char*, unsigned, const void*, const void*, char**);
351 gboolean uat_fld_chk_range(void*, const char*, unsigned, const void*, const void*, char**);
353 gboolean uat_fld_chk_color(void*, const char*, unsigned, const void*, const void*, char**);
355 typedef void (*uat_cb_t)(void* uat,void* user_data);
357 void uat_foreach_table(uat_cb_t cb,void* user_data);
358 void uat_unload_all(void);
360 char* uat_undquote(const char* si, guint in_len, guint* len_p);
361 char* uat_unbinstring(const char* si, guint in_len, guint* len_p);
362 char* uat_unesc(const char* si, guint in_len, guint* len_p);
363 char* uat_esc(const char* buf, guint len);
365 /* Some strings entirely made of ... already declared */
368 gboolean uat_fld_chk_str_isprint(void*, const char*, unsigned, const void*, const void*, char**);
371 gboolean uat_fld_chk_str_isalpha(void*, const char*, unsigned, const void*, const void*, char**);
374 gboolean uat_fld_chk_str_isalnum(void*, const char*, unsigned, const void*, const void*, char**);
377 gboolean uat_fld_chk_str_isdigit(void*, const char*, unsigned, const void*, const void*, char**);
380 gboolean uat_fld_chk_str_isxdigit(void*, const char*, unsigned, const void*, const void*, char**);
385 * to define basic uat_fld_set_cbs, uat_fld_tostr_cbs
386 * for those elements in uat_field_t array
390 #define UNUSED_PARAMETER(n)
392 #define UNUSED_PARAMETER(n) n _U_
397 * a simple c-string contained in (((rec_t*)rec)->(field_name))
399 #define UAT_CSTRING_CB_DEF(basename,field_name,rec_t) \
400 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
401 char* new_buf = g_strndup(buf,len); \
402 g_free((((rec_t*)rec)->field_name)); \
403 (((rec_t*)rec)->field_name) = new_buf; } \
404 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
405 if (((rec_t*)rec)->field_name ) { \
406 *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
407 *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
409 *out_ptr = g_strdup(""); *out_len = 0; } }
411 #define UAT_FLD_CSTRING(basename,field_name,title,desc) \
412 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
414 #define UAT_FLD_CSTRING_ISPRINT(basename,field_name,title,desc) \
415 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_str_isprint,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
417 #define UAT_FLD_CSTRING_OTHER(basename,field_name,title,chk,desc) \
418 {#field_name, title, PT_TXTMOD_STRING,{ chk ,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
421 * FILENAME and DIRECTORYNAME,
422 * a simple c-string contained in (((rec_t*)rec)->(field_name))
424 #define UAT_FILENAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
426 /* XXX UAT_FLD_FILENAME is currently unused. */
427 #define UAT_FLD_FILENAME(basename,field_name,title,desc) \
428 {#field_name, title, PT_TXTMOD_FILENAME,{uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
431 * Both the Qt and GTK+ UIs assume that we're opening a preexisting
432 * file. We might want to split the ..._FILENAME defines into
433 * ..._FILE_OPEN and ..._FILE_SAVE if we ever need to specify a
434 * file that we're creating.
436 #define UAT_FLD_FILENAME_OTHER(basename,field_name,title,chk,desc) \
437 {#field_name, title, PT_TXTMOD_FILENAME,{chk,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
439 #define UAT_DIRECTORYNAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
441 #define UAT_FLD_DIRECTORYNAME(basename,field_name,title,desc) \
442 {#field_name, title, PT_TXTMOD_DIRECTORYNAME,{uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
446 * a simple c-string contained in (((rec_t*)rec)->(field_name))
448 #define UAT_DISPLAY_FILTER_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
450 #define UAT_FLD_DISPLAY_FILTER(basename,field_name,title,desc) \
451 {#field_name, title, PT_TXTMOD_DISPLAY_FILTER, {uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
455 * a simple c-string contained in (((rec_t*)rec)->(field_name))
457 #define UAT_PROTO_FIELD_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
459 #define UAT_FLD_PROTO_FIELD(basename,field_name,title,desc) \
460 {#field_name, title, PT_TXTMOD_PROTO_FIELD, {uat_fld_chk_str,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
463 * OID - just a CSTRING with a specific check routine
465 #define UAT_FLD_OID(basename,field_name,title,desc) \
466 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_oid,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
472 #define UAT_LSTRING_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
473 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
474 char* new_val = uat_unesc(buf,len,&(((rec_t*)rec)->len_element)); \
475 g_free((((rec_t*)rec)->ptr_element)); \
476 (((rec_t*)rec)->ptr_element) = new_val; }\
477 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
478 if (((rec_t*)rec)->ptr_element ) { \
479 *out_ptr = uat_esc(((rec_t*)rec)->ptr_element, (((rec_t*)rec)->len_element)); \
480 *out_len = (unsigned)strlen(*out_ptr); \
482 *out_ptr = g_strdup(""); \
487 #define UAT_FLD_LSTRING(basename,field_name,title, desc) \
488 {#field_name, title, PT_TXTMOD_STRING,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
493 * a buffer_ptr contained in (((rec_t*)rec)->(field_name))
494 * and its len in (((rec_t*)rec)->(len_name))
496 #define UAT_BUFFER_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
497 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
498 char* new_buf = len ? (char *)g_memdup(buf,len) : NULL; \
499 g_free((((rec_t*)rec)->ptr_element)); \
500 (((rec_t*)rec)->ptr_element) = new_buf; \
501 (((rec_t*)rec)->len_element) = len; } \
502 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
503 *out_ptr = ((rec_t*)rec)->ptr_element ? (char*)g_memdup(((rec_t*)rec)->ptr_element,((rec_t*)rec)->len_element) : g_strdup(""); \
504 *out_len = ((rec_t*)rec)->len_element; }
506 #define UAT_FLD_BUFFER(basename,field_name,title,desc) \
507 {#field_name, title, PT_TXTMOD_HEXBYTES,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
512 * a decimal number contained in
514 #define UAT_DEC_CB_DEF(basename,field_name,rec_t) \
515 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
516 char* tmp_str = g_strndup(buf,len); \
517 ((rec_t*)rec)->field_name = (guint)strtol(tmp_str,NULL,10); \
519 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
520 *out_ptr = g_strdup_printf("%d",((rec_t*)rec)->field_name); \
521 *out_len = (unsigned)strlen(*out_ptr); }
523 #define UAT_FLD_DEC(basename,field_name,title,desc) \
524 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_num_dec,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
526 #define UAT_FLD_NONE(basename,field_name,title,desc) \
527 {#field_name, title, PT_TXTMOD_NONE,{uat_fld_chk_num_dec,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
532 * an hexadecimal number contained in
534 #define UAT_HEX_CB_DEF(basename,field_name,rec_t) \
535 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
536 char* tmp_str = g_strndup(buf,len); \
537 ws_hexstrtou32(tmp_str, NULL, &((rec_t*)rec)->field_name); \
539 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
540 *out_ptr = g_strdup_printf("%x",((rec_t*)rec)->field_name); \
541 *out_len = (unsigned)strlen(*out_ptr); }
543 #define UAT_FLD_HEX(basename,field_name,title,desc) \
544 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_num_hex,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
548 * an boolean value contained in
550 #define UAT_BOOL_CB_DEF(basename,field_name,rec_t) \
551 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
552 char* tmp_str = g_strndup(buf,len); \
553 if (g_strcmp0(tmp_str, "TRUE") == 0) \
554 ((rec_t*)rec)->field_name = 1; \
556 ((rec_t*)rec)->field_name = 0; \
558 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
559 *out_ptr = g_strdup_printf("%s",((rec_t*)rec)->field_name ? "TRUE" : "FALSE"); \
560 *out_len = (unsigned)strlen(*out_ptr); }
562 #define UAT_FLD_BOOL(basename,field_name,title,desc) \
563 {#field_name, title, PT_TXTMOD_BOOL,{uat_fld_chk_bool,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
567 * enum_t: name = ((enum_t*)ptr)->strptr
568 * value = ((enum_t*)ptr)->value
572 #define UAT_VS_DEF(basename,field_name,rec_t,default_t,default_val,default_str) \
573 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
575 char* str = g_strndup(buf,len); \
577 ((rec_t*)rec)->field_name = default_val; \
578 for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
579 if (g_str_equal(cstr,str)) { \
580 ((rec_t*)rec)->field_name = (default_t)((const value_string*)vs)[i].value; \
586 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
588 for(i=0;((const value_string*)vs)[i].strptr;i++) { \
589 if ( ((const value_string*)vs)[i].value == ((rec_t*)rec)->field_name ) { \
590 *out_ptr = g_strdup(((const value_string*)vs)[i].strptr); \
591 *out_len = (unsigned)strlen(*out_ptr); \
595 *out_ptr = g_strdup(default_str); \
596 *out_len = (unsigned)strlen(default_str); }
598 #define UAT_VS_CSTRING_DEF(basename,field_name,rec_t,default_val,default_str) \
599 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
601 char* str = g_strndup(buf,len); \
603 ((rec_t*)rec)->field_name = default_val; \
604 for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
605 if (g_str_equal(cstr,str)) { \
606 ((rec_t*)rec)->field_name = g_strdup(((const value_string*)vs)[i].strptr); \
612 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(vs), const void* UNUSED_PARAMETER(u2)) {\
613 if (((rec_t*)rec)->field_name ) { \
614 *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
615 *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
617 *out_ptr = g_strdup(""); *out_len = 0; } }
619 #define UAT_FLD_VS(basename,field_name,title,enum,desc) \
620 {#field_name, title, PT_TXTMOD_ENUM,{uat_fld_chk_enum,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{&(enum),&(enum),&(enum)},&(enum),desc,FLDFILL}
625 * an #RRGGBB color value contained in
627 #define UAT_COLOR_CB_DEF(basename,field_name,rec_t) \
628 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
630 ((rec_t*)rec)->field_name = 0; \
633 char* tmp_str = g_strndup(buf+1,len-1); \
634 ((rec_t*)rec)->field_name = (guint)strtol(tmp_str,NULL,16); \
636 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
637 *out_ptr = g_strdup_printf("#%06X",((rec_t*)rec)->field_name); \
638 *out_len = (unsigned)strlen(*out_ptr); }
640 #define UAT_FLD_COLOR(basename,field_name,title,desc) \
641 {#field_name, title, PT_TXTMOD_COLOR,{uat_fld_chk_color,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
648 #define UAT_PROTO_DEF(basename, field_name, dissector_field, name_field, rec_t) \
649 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
651 gchar *tmp = g_strndup(buf,len); \
652 ((rec_t*)rec)->name_field = g_ascii_strdown(tmp, -1); \
654 g_strchug(((rec_t*)rec)->name_field); \
655 ((rec_t*)rec)->dissector_field = find_dissector(((rec_t*)rec)->name_field); \
657 ((rec_t*)rec)->dissector_field = find_dissector("data"); \
658 ((rec_t*)rec)->name_field = NULL; \
660 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
661 if ( ((rec_t*)rec)->name_field ) { \
662 *out_ptr = g_strdup((((rec_t*)rec)->name_field)); \
663 *out_len = (unsigned)strlen(*out_ptr); \
665 *out_ptr = g_strdup(""); *out_len = 0; } }
668 #define UAT_FLD_PROTO(basename,field_name,title,desc) \
669 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_proto,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
675 #define UAT_RANGE_CB_DEF(basename,field_name,rec_t) \
676 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* u2) {\
677 char* rng = g_strndup(buf,len);\
678 range_convert_str(NULL, &(((rec_t*)rec)->field_name), rng,GPOINTER_TO_UINT(u2)); \
681 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
682 if ( ((rec_t*)rec)->field_name ) { \
683 *out_ptr = range_convert_range(NULL, ((rec_t*)rec)->field_name); \
684 *out_len = (unsigned)strlen(*out_ptr); \
686 *out_ptr = g_strdup(""); *out_len = 0; } }
689 #define UAT_FLD_RANGE(basename,field_name,title,max,desc) \
690 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_range,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},\
691 {0,0,0},GUINT_TO_POINTER(max),desc,FLDFILL}
695 #endif /* __cplusplus */
697 #endif /* __UAT_H__ */