Wireshark 4.7.0
The Wireshark network protocol analyzer
Loading...
Searching...
No Matches
uat.h
Go to the documentation of this file.
1
15#ifndef __UAT_H__
16#define __UAT_H__
17
18#include <stdlib.h>
19
20#include "ws_symbol_export.h"
21#include <wsutil/strtoi.h>
22#include <wsutil/dtoa.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif /* __cplusplus */
27
28/*
29 * UAT maintains a dynamically allocated table accessible to the user
30 * via a file and/or via GUI preference dialogs.
31 *
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
34 * directory.
35 *
36 * The behaviour of the table is controlled by a series of callbacks which
37 * the caller (e.g. a dissector) must provide.
38 *
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
46 * be fixed later.)
47 *
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.
51 *
52 * Only users via GUI or editing the file can add/remove records, your
53 * (dissector) code cannot.
54 */
55
56/* opaque data type to handle an uat */
57typedef struct epan_uat uat_t;
58/********************************************
59 * Callbacks:
60 * these instruct uat on how to deal with user info and data in records
61 ********************************************/
62
63/********
64 * Callbacks dealing with the entire table
65 ********/
66
67/*
68 * Post-Update CB
69 *
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
72 * optional
73 */
74typedef void (*uat_post_update_cb_t)(void);
75
76
77/********
78 * Callbacks dealing with records (these deal with entire records)
79 ********/
80
88typedef void* (*uat_copy_cb_t)(void *dest, const void *source, size_t len);
89
98typedef void (*uat_free_cb_t)(void *record);
99
106typedef void (*uat_reset_cb_t)(void);
107
126typedef bool (*uat_update_cb_t)(void *record, char **error);
127
128
129/*******
130 * Callbacks for single fields (these deal with single values)
131 * the caller should provide one of these for every field!
132 ********/
133
134/*
135 * Check CB
136 * chk(record, ptr, len, chk_data, fld_data, &error)
137 *
138 * given an input string (ptr, len) checks if the value is OK for a field in the record.
139 * it will return true if OK or else
140 * it will return false and set *error to inform the user on what's
141 * wrong with the given input
142 * The error string must be allocated with g_malloc() or
143 * a routine that calls it.
144 * optional, if not given any input is considered OK and the set cb will be called
145 */
146typedef bool (*uat_fld_chk_cb_t)(void *record, const char *ptr, unsigned len, const void *chk_data, const void *fld_data, char **error);
147
148/*
149 * Set Field CB
150 * set(record, ptr, len, set_data, fld_data)
151 *
152 * given an input string (ptr, len) sets the value of a field in the record,
153 * it is mandatory
154 */
155typedef void (*uat_fld_set_cb_t)(void *record, const char *ptr, unsigned len, const void *set_data, const void *fld_data);
156
157/*
158 * Convert-to-string CB
159 * tostr(record, &out_ptr, &out_len, tostr_data, fld_data)
160 *
161 * given a record returns a string representation of the field
162 * mandatory
163 */
164typedef void (*uat_fld_tostr_cb_t)(void *record, char **out_ptr, unsigned *out_len, const void *tostr_data, const void *fld_data);
165
166/***********
167 * Text Mode
168 *
169 * used for file and dialog representation of fields in columns,
170 * when the file is read it modifies the way the value is passed back to the fld_set_cb
171 * (see definition bellow for description)
172 ***********/
173
174typedef enum _uat_text_mode_t {
175 PT_TXTMOD_NONE,
176 /* not used */
177
178 PT_TXTMOD_STRING,
179 /*
180 file:
181 reads:
182 ,"\x20\x00\x30", as " \00",3 ("space nil zero" of length 3)
183 ,"", as "",0
184 ,, as NULL,0
185 writes:
186 ,"\x20\x30\x00\x20", for " 0\0 ",4
187 ,"", for *, 0
188 ,, for NULL, *
189 dialog:
190 accepts \x?? and other escapes
191 gets "",0 on empty string
192 */
193 PT_TXTMOD_HEXBYTES,
194 /*
195 file:
196 reads:
197 ,A1b2C3d4, as "\xa1\xb2\xc3\xd4",4
198 ,, as NULL,0
199 writes:
200 ,, on NULL, *
201 ,a1b2c3d4, on "\xa1\xb2\xc3\xd4",4
202 dialog:
203 interprets the following input ... as ...:
204 "a1b2c3d4" as "\xa1\xb2\xc3\xd4",4
205 "a1 b2:c3d4" as "\xa1\xb2\xc3\xd4",4
206 "" as NULL,0
207 "invalid" as NULL,3
208 "a1b" as NULL, 1
209 */
210 PT_TXTMOD_ENUM,
211 /* Read/Writes/displays the string value (not number!) */
212 PT_TXTMOD_DISSECTOR,
213 /* Shows a combobox of dissectors */
214
215 PT_TXTMOD_COLOR,
216 /* Reads/Writes/display color in #RRGGBB format */
217
218 PT_TXTMOD_FILENAME,
219 /* processed like a PT_TXTMOD_STRING, but shows a filename dialog */
220 PT_TXTMOD_DIRECTORYNAME,
221 /* processed like a PT_TXTMOD_STRING, but shows a directory dialog */
222 PT_TXTMOD_DISPLAY_FILTER,
223 /* processed like a PT_TXTMOD_STRING, but verifies display filter */
224 PT_TXTMOD_PROTO_FIELD,
225 /* processed like a PT_TXTMOD_STRING, but verifies protocol field name (e.g tcp.flags.syn) */
226 PT_TXTMOD_BOOL
227 /* Displays a checkbox for value */
228} uat_text_mode_t;
229
230/*
231 * Fields
232 *
233 *
234 */
235typedef struct _uat_field_t {
236 const char* name;
237 const char* title;
238 uat_text_mode_t mode;
239
240 struct {
241 uat_fld_chk_cb_t chk;
242 uat_fld_set_cb_t set;
243 uat_fld_tostr_cb_t tostr;
244 } cb;
245
246 struct {
247 const void* chk;
248 const void* set;
249 const void* tostr;
250 } cbdata;
251
252 const void* fld_data;
253
254 const char* desc;
255 struct _fld_data_t* priv;
257
258#define FLDFILL NULL
259#define UAT_END_FIELDS {NULL,NULL,PT_TXTMOD_NONE,{0,0,0},{0,0,0},0,0,FLDFILL}
260
261/*
262 * Flags to indicate what the settings in this UAT affect.
263 * This is used when UATs are changed interactively, to indicate what needs
264 * to be redone when the UAT is changed.
265 *
266 * UAT_AFFECTS_FIELDS does *not* trigger a redissection, so usually one
267 * will also want UAT_AFFECTS_DISSECTION. A rare exception is changing
268 * the defined dfilter macros.
269 */
270#define UAT_AFFECTS_DISSECTION 0x00000001 /* affects packet dissection */
271#define UAT_AFFECTS_FIELDS 0x00000002 /* affects what named fields exist */
272
292WS_DLL_PUBLIC
293uat_t* uat_new(const char* name,
294 size_t size,
295 const char* filename,
296 bool from_profile,
297 void* data_ptr,
298 unsigned* num_items_ptr,
299 unsigned flags,
300 const char* help,
301 uat_copy_cb_t copy_cb,
302 uat_update_cb_t update_cb,
303 uat_free_cb_t free_cb,
304 uat_post_update_cb_t post_update_cb,
305 uat_reset_cb_t reset_cb,
306 uat_field_t* flds_array);
307
311WS_DLL_PUBLIC
312void uat_destroy(uat_t *uat);
313
317void uat_cleanup(void);
318
328WS_DLL_PUBLIC
329bool uat_load(uat_t* uat_in, const char *filename, const char* app_env_var_prefix, char** err);
330
340WS_DLL_PUBLIC
341bool uat_load_str(uat_t* uat_in, const char* entry, char** err);
342
349uat_t *uat_find(char *name);
350
351WS_DLL_PUBLIC
352uat_t* uat_get_table_by_name(const char* name);
353
367WS_DLL_PUBLIC
368void uat_set_default_values(uat_t *uat_in, const char *default_values[]);
369
370/*
371 * Some common uat_fld_chk_cbs
372 */
373WS_DLL_PUBLIC
374bool uat_fld_chk_str(void*, const char*, unsigned, const void*, const void*, char** err);
375WS_DLL_PUBLIC
376bool uat_fld_chk_oid(void*, const char*, unsigned, const void*, const void*, char** err);
377WS_DLL_PUBLIC
378bool uat_fld_chk_proto(void*, const char*, unsigned, const void*, const void*, char** err);
379WS_DLL_PUBLIC
380bool uat_fld_chk_field(void*, const char*, unsigned, const void*, const void*, char** err);
381WS_DLL_PUBLIC
382bool uat_fld_chk_num_dec(void*, const char*, unsigned, const void*, const void*, char** err);
383WS_DLL_PUBLIC
384bool uat_fld_chk_num_dec64(void*, const char*, unsigned, const void*, const void*, char** err);
385WS_DLL_PUBLIC
386bool uat_fld_chk_num_hex(void*, const char*, unsigned, const void*, const void*, char** err);
387WS_DLL_PUBLIC
388bool uat_fld_chk_num_hex64(void*, const char*, unsigned, const void*, const void*, char** err);
389WS_DLL_PUBLIC
390bool uat_fld_chk_num_signed_dec(void*, const char*, unsigned, const void*, const void*, char** err);
391WS_DLL_PUBLIC
392bool uat_fld_chk_num_signed_dec64(void*, const char*, unsigned, const void*, const void*, char** err);
393WS_DLL_PUBLIC
394bool uat_fld_chk_num_dbl(void*, const char*, unsigned, const void*, const void*, char** err);
395WS_DLL_PUBLIC
396bool uat_fld_chk_bool(void*, const char*, unsigned, const void*, const void*, char** err);
397WS_DLL_PUBLIC
398bool uat_fld_chk_enum(void*, const char*, unsigned, const void*, const void*, char**);
399WS_DLL_PUBLIC
400bool uat_fld_chk_range(void*, const char*, unsigned, const void*, const void*, char**);
401WS_DLL_PUBLIC
402bool uat_fld_chk_color(void*, const char*, unsigned, const void*, const void*, char**);
403
404typedef void (*uat_cb_t)(void* uat,void* user_data);
405WS_DLL_PUBLIC
406void uat_foreach_table(uat_cb_t cb,void* user_data);
407void uat_unload_all(void);
408
409/* Converts an ASCII string using C-style escapes (e.g., for unprintable
410 * characters) into a "stringlike" array of bytes that may include internal
411 * NUL bytes and other unprintable characters. This is the PT_TEXTMOD_STRING
412 * format.
413 */
414uint8_t* uat_unesc(const char* si, unsigned in_len, unsigned* len_p);
415
416/* The same as uat_unesc, but removing the first and last byte. The
417 * assumption is that the first and last byte are quote characters. When
418 * writing the PT_TEXTMOD_STRING format to file, the escaped string is
419 * enclosed in quotes; this function undoes that.
420 *
421 * TODO - This should probably return a uint8_t* as well, but requires
422 * changing types (or casting pointers) in several other files to do so.
423 */
424char* uat_undquote(const char* si, unsigned in_len, unsigned* len_p);
425
426/* Converts a "stringlike" array of bytes into a null-terminated ASCII string
427 * using C-style escapes. The inverse of uat_unesc.
428 */
429char* uat_esc(const uint8_t* buf, unsigned len);
430
431/* Converts a ASCII hexstring into an array of bytes. Used to convert
432 * the PT_TXTMOD_HEXBYTES format.
433 * TODO - This should probably return a uint8_t* as well.
434 */
435char* uat_unbinstring(const char* si, unsigned in_len, unsigned* len_p);
436
437/* Some strings entirely made of ... already declared */
438
439WS_DLL_PUBLIC
440bool uat_fld_chk_str_isprint(void*, const char*, unsigned, const void*, const void*, char**);
441
442WS_DLL_PUBLIC
443bool uat_fld_chk_str_isalpha(void*, const char*, unsigned, const void*, const void*, char**);
444
445WS_DLL_PUBLIC
446bool uat_fld_chk_str_isalnum(void*, const char*, unsigned, const void*, const void*, char**);
447
448WS_DLL_PUBLIC
449bool uat_fld_chk_str_isdigit(void*, const char*, unsigned, const void*, const void*, char**);
450
451WS_DLL_PUBLIC
452bool uat_fld_chk_str_isxdigit(void*, const char*, unsigned, const void*, const void*, char**);
453
454
455/*
456 * Macros
457 * to define basic uat_fld_set_cbs, uat_fld_tostr_cbs
458 * for those elements in uat_field_t array
459 */
460
461#ifdef __cplusplus
462#define UNUSED_PARAMETER(n)
463#else
464#define UNUSED_PARAMETER(n) n _U_
465#endif
466
467/*
468 * CSTRING macros,
469 * a simple c-string contained in (((rec_t*)rec)->(field_name))
470 */
471#define UAT_CSTRING_CB_DEF(basename,field_name,rec_t) \
472static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
473 char* new_buf = g_strndup(buf,len); \
474 g_free((((rec_t*)rec)->field_name)); \
475 (((rec_t*)rec)->field_name) = new_buf; } \
476static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
477 if (((rec_t*)rec)->field_name ) { \
478 *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
479 *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
480 } else { \
481 *out_ptr = g_strdup(""); *out_len = 0; \
482 } }
483
484#define UAT_FLD_CSTRING(basename,field_name,title,desc) \
485 {#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}
486
487#define UAT_FLD_CSTRING_ISPRINT(basename,field_name,title,desc) \
488 {#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}
489
490#define UAT_FLD_CSTRING_OTHER(basename,field_name,title,chk,desc) \
491 {#field_name, title, PT_TXTMOD_STRING,{ chk ,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
492
493/*
494 * FILENAME and DIRECTORYNAME,
495 * a simple c-string contained in (((rec_t*)rec)->(field_name))
496 */
497#define UAT_FILENAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
498
499/* XXX UAT_FLD_FILENAME is currently unused. */
500#define UAT_FLD_FILENAME(basename,field_name,title,desc) \
501 {#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}
502
503/*
504 * Both the Qt and GTK+ UIs assume that we're opening a preexisting
505 * file. We might want to split the ..._FILENAME defines into
506 * ..._FILE_OPEN and ..._FILE_SAVE if we ever need to specify a
507 * file that we're creating.
508 */
509#define UAT_FLD_FILENAME_OTHER(basename,field_name,title,chk,desc) \
510 {#field_name, title, PT_TXTMOD_FILENAME,{chk,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
511
512#define UAT_DIRECTORYNAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
513
514#define UAT_FLD_DIRECTORYNAME(basename,field_name,title,desc) \
515 {#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}
516
517/*
518 * DISPLAY_FILTER,
519 * a simple c-string contained in (((rec_t*)rec)->(field_name))
520 */
521#define UAT_DISPLAY_FILTER_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
522
523#define UAT_FLD_DISPLAY_FILTER(basename,field_name,title,desc) \
524 {#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}
525
526/*
527 * PROTO_FIELD,
528 * a simple c-string contained in (((rec_t*)rec)->(field_name))
529 */
530#define UAT_PROTO_FIELD_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
531
532#define UAT_FLD_PROTO_FIELD(basename,field_name,title,desc) \
533 {#field_name, title, PT_TXTMOD_PROTO_FIELD, {uat_fld_chk_field,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
534
535/*
536 * OID - just a CSTRING with a specific check routine
537 */
538#define UAT_FLD_OID(basename,field_name,title,desc) \
539 {#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}
540
541
542/*
543 * LSTRING MACROS - a "string" with an explicit length, so it can contain
544 * internal null characters and possibly unprintable characters, that are
545 * displayed to the user and written to the file using C-style escapes. An
546 * alternative to BUFFER for when the data is often but not necessarily an
547 * ASCII printable string, such as in some types of encryption keys.
548 */
549#define UAT_LSTRING_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
550static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
551 uint8_t* new_val = uat_unesc(buf,len,&(((rec_t*)rec)->len_element)); \
552 g_free((((rec_t*)rec)->ptr_element)); \
553 (((rec_t*)rec)->ptr_element) = new_val; } \
554static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
555 if (((rec_t*)rec)->ptr_element ) { \
556 *out_ptr = uat_esc(((rec_t*)rec)->ptr_element, (((rec_t*)rec)->len_element)); \
557 *out_len = (unsigned)strlen(*out_ptr); \
558 } else { \
559 *out_ptr = g_strdup(""); \
560 *out_len = 0; \
561 } }
562
563#define UAT_FLD_LSTRING(basename,field_name,title, desc) \
564{#field_name, title, PT_TXTMOD_STRING,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
565
566
567/*
568 * BUFFER macros,
569 * a buffer_ptr contained in (((rec_t*)rec)->(field_name))
570 * and its len in (((rec_t*)rec)->(len_name))
571 */
572#define UAT_BUFFER_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
573static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
574 unsigned char* new_buf = len ? (unsigned char *)g_memdup2(buf,len) : NULL; \
575 g_free((((rec_t*)rec)->ptr_element)); \
576 (((rec_t*)rec)->ptr_element) = new_buf; \
577 (((rec_t*)rec)->len_element) = len; } \
578static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
579 *out_ptr = ((rec_t*)rec)->ptr_element ? (char*)g_memdup2(((rec_t*)rec)->ptr_element,((rec_t*)rec)->len_element) : g_strdup(""); \
580 *out_len = ((rec_t*)rec)->len_element; }
581
582#define UAT_FLD_BUFFER(basename,field_name,title,desc) \
583 {#field_name, title, PT_TXTMOD_HEXBYTES,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
584
585
586/*
587 * DEC Macros,
588 * an unsigned decimal number contained in (((rec_t*)rec)->(field_name))
589 */
590#define UAT_DEC_CB_DEF(basename,field_name,rec_t) \
591static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
592 char* tmp_str = g_strndup(buf,len); \
593 ws_strtou32(tmp_str, NULL, &((rec_t*)rec)->field_name); \
594 g_free(tmp_str); } \
595static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
596 *out_ptr = ws_strdup_printf("%u",((rec_t*)rec)->field_name); \
597 *out_len = (unsigned)strlen(*out_ptr); }
598
599#define UAT_FLD_DEC(basename,field_name,title,desc) \
600 {#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}
601
602 /*
603 * an unsigned 64bit decimal number contained in (((rec_t*)rec)->(field_name))
604 */
605#define UAT_DEC64_CB_DEF(basename,field_name,rec_t) \
606static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
607 char* tmp_str = g_strndup(buf,len); \
608 ws_strtou64(tmp_str, NULL, &((rec_t*)rec)->field_name); \
609 g_free(tmp_str); } \
610static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
611 *out_ptr = ws_strdup_printf("%" PRIu64,((rec_t*)rec)->field_name); \
612 *out_len = (unsigned)strlen(*out_ptr); }
613
614#define UAT_FLD_DEC64(basename,field_name,title,desc) \
615 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_num_dec64,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
616
617/*
618 * a *signed* decimal number contained in (((rec_t*)rec)->(field_name))
619 */
620#define UAT_SIGNED_DEC_CB_DEF(basename,field_name,rec_t) \
621static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
622 char* tmp_str = g_strndup(buf,len); \
623 ws_strtoi32(tmp_str, NULL, &((rec_t*)rec)->field_name); \
624 g_free(tmp_str); } \
625static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
626 *out_ptr = ws_strdup_printf("%d",((rec_t*)rec)->field_name); \
627 *out_len = (unsigned)strlen(*out_ptr); }
628
629#define UAT_FLD_SIGNED_DEC(basename,field_name,title,desc) \
630 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_num_signed_dec,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
631
632 /*
633 * and a *signed* 64bit decimal number contained in (((rec_t*)rec)->(field_name))
634 */
635#define UAT_SIGNED_DEC64_CB_DEF(basename,field_name,rec_t) \
636static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
637 char* tmp_str = g_strndup(buf,len); \
638 ws_strtoi64(tmp_str, NULL, &((rec_t*)rec)->field_name); \
639 g_free(tmp_str); } \
640static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
641 *out_ptr = ws_strdup_printf("%" PRId64,((rec_t*)rec)->field_name); \
642 *out_len = (unsigned)strlen(*out_ptr); }
643
644#define UAT_FLD_SIGNED_DEC64(basename,field_name,title,desc) \
645 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_num_signed_dec64,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
646
647#define UAT_FLD_NONE(basename,field_name,title,desc) \
648 {#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}
649
650
651/*
652 * HEX Macros,
653 * an unsigned hexadecimal number contained in (((rec_t*)rec)->(field_name))
654 */
655#define UAT_HEX_CB_DEF(basename,field_name,rec_t) \
656static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
657 char* tmp_str = g_strndup(buf,len); \
658 ws_hexstrtou32(tmp_str, NULL, &((rec_t*)rec)->field_name); \
659 g_free(tmp_str); } \
660static 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 *out_ptr = ws_strdup_printf("%x",((rec_t*)rec)->field_name); \
662 *out_len = (unsigned)strlen(*out_ptr); }
663
664#define UAT_FLD_HEX(basename,field_name,title,desc) \
665{#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}
666
667 /*
668 * HEX Macros for 64bit,
669 * an unsigned long long hexadecimal number contained in (((rec_t*)rec)->(field_name))
670 */
671#define UAT_HEX64_CB_DEF(basename,field_name,rec_t) \
672static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
673 char* tmp_str = g_strndup(buf,len); \
674 ws_hexstrtou64(tmp_str, NULL, &((rec_t*)rec)->field_name); \
675 g_free(tmp_str); } \
676static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
677 *out_ptr = ws_strdup_printf("%" PRIx64,((rec_t*)rec)->field_name); \
678 *out_len = (unsigned)strlen(*out_ptr); }
679
680#define UAT_FLD_HEX64(basename,field_name,title,desc) \
681{#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_num_hex64,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
682
683/*
684 * DBL Macros,
685 * a double precision floating-point number contained in (((rec_t*)rec)->(field_name))
686 *
687 * [using g_ascii_dtostr() would be fine for tostr_cb for storing data, but
688 * produces more ugly looking values when presenting to the user. dtoa_g_fmt
689 * produces the shortest string which also is a unique round-trip for any
690 * particular value.]
691 */
692#define UAT_DBL_CB_DEF(basename,field_name,rec_t) \
693static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
694 char* tmp_str = g_strndup(buf,len); \
695 ((rec_t*)rec)->field_name = g_ascii_strtod(tmp_str, NULL); \
696 g_free(tmp_str); } \
697static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
698 char buf[32]; \
699 *out_ptr = ws_strdup(dtoa_g_fmt(buf, ((rec_t*)rec)->field_name)); \
700 *out_len = (unsigned)strlen(*out_ptr); }
701
702#define UAT_FLD_DBL(basename,field_name,title,desc) \
703 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_num_dbl,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
704
705/*
706 * BOOL Macros,
707 * an boolean value contained in (((rec_t*)rec)->(field_name))
708 *
709 * Write "TRUE" or "FALSE" for backwards compatibility with pre-4.4
710 * versions that expect that capitalization.
711 */
712#define UAT_BOOL_CB_DEF(basename,field_name,rec_t) \
713static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
714 char* tmp_str = g_strndup(buf,len); \
715 if (tmp_str && g_ascii_strcasecmp(tmp_str, "true") == 0) \
716 ((rec_t*)rec)->field_name = 1; \
717 else \
718 ((rec_t*)rec)->field_name = 0; \
719 g_free(tmp_str); } \
720static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
721 *out_ptr = ws_strdup_printf("%s",((rec_t*)rec)->field_name ? "TRUE" : "FALSE"); \
722 *out_len = (unsigned)strlen(*out_ptr); }
723
724#define UAT_FLD_BOOL(basename,field_name,title,desc) \
725{#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}
726
727/*
728 * ENUM macros
729 * enum_t: name = ((enum_t*)ptr)->strptr
730 * value = ((enum_t*)ptr)->value
731 * rec_t:
732 * value
733 */
734#define UAT_VS_DEF(basename,field_name,rec_t,default_t,default_val,default_str) \
735static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
736 unsigned i; \
737 char* str = g_strndup(buf,len); \
738 const char* cstr; \
739 ((rec_t*)rec)->field_name = default_val; \
740 for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
741 if (g_str_equal(cstr,str)) { \
742 ((rec_t*)rec)->field_name = (default_t)((const value_string*)vs)[i].value; \
743 g_free(str); \
744 return; \
745 } \
746 } \
747 g_free(str); } \
748static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
749 unsigned i; \
750 for(i=0;((const value_string*)vs)[i].strptr;i++) { \
751 if ( ((const value_string*)vs)[i].value == ((rec_t*)rec)->field_name ) { \
752 *out_ptr = g_strdup(((const value_string*)vs)[i].strptr); \
753 *out_len = (unsigned)strlen(*out_ptr); \
754 return; \
755 } \
756 } \
757 *out_ptr = g_strdup(default_str); \
758 *out_len = (unsigned)strlen(default_str); }
759
760#define UAT_VS_CSTRING_DEF(basename,field_name,rec_t,default_val,default_str) \
761static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
762 unsigned i; \
763 char* str = g_strndup(buf,len); \
764 const char* cstr; \
765 ((rec_t*)rec)->field_name = default_val; \
766 for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
767 if (g_str_equal(cstr,str)) { \
768 ((rec_t*)rec)->field_name = g_strdup(((const value_string*)vs)[i].strptr); \
769 g_free(str); \
770 return; \
771 } \
772 } \
773 g_free(str);} \
774static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(vs), const void* UNUSED_PARAMETER(u2)) {\
775 if (((rec_t*)rec)->field_name ) { \
776 *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
777 *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
778 } else { \
779 *out_ptr = g_strdup(""); *out_len = 0; } }
780
781#define UAT_FLD_VS(basename,field_name,title,enum,desc) \
782 {#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}
783
784
785/*
786 * Color Macros,
787 * an #RRGGBB color value contained in (((rec_t*)rec)->(field_name))
788 */
789#define UAT_COLOR_CB_DEF(basename,field_name,rec_t) \
790static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
791 if (len < 1) { \
792 ((rec_t*)rec)->field_name = 0; \
793 return; \
794 } \
795 char* tmp_str = g_strndup(buf+1,len-1); \
796 ((rec_t*)rec)->field_name = (unsigned)strtol(tmp_str,NULL,16); \
797 g_free(tmp_str); } \
798static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
799 *out_ptr = ws_strdup_printf("#%06X",((rec_t*)rec)->field_name); \
800 *out_len = (unsigned)strlen(*out_ptr); }
801
802#define UAT_FLD_COLOR(basename,field_name,title,desc) \
803{#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}
804
805
806/*
807 * DISSECTOR macros
808 */
809
810#define UAT_DISSECTOR_DEF(basename, field_name, dissector_field, name_field, rec_t) \
811static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
812 if (len) { \
813 ((rec_t*)rec)->name_field = g_strndup(buf, len); \
814 g_strstrip(((rec_t*)rec)->name_field); \
815 ((rec_t*)rec)->dissector_field = find_dissector(((rec_t*)rec)->name_field); \
816 } else { \
817 ((rec_t*)rec)->dissector_field = find_dissector("data"); \
818 ((rec_t*)rec)->name_field = NULL; \
819 } } \
820static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
821 if ( ((rec_t*)rec)->name_field ) { \
822 *out_ptr = g_strdup((((rec_t*)rec)->name_field)); \
823 *out_len = (unsigned)strlen(*out_ptr); \
824 } else { \
825 *out_ptr = g_strdup(""); *out_len = 0; \
826 } }
827
828
829#define UAT_FLD_DISSECTOR(basename,field_name,title,desc) \
830 {#field_name, title, PT_TXTMOD_DISSECTOR,{uat_fld_chk_proto,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
831
832#define UAT_FLD_DISSECTOR_OTHER(basename,field_name,title,chk,desc) \
833 {#field_name, title, PT_TXTMOD_DISSECTOR,{chk,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
834
835/*
836 * RANGE macros
837 */
838
839#define UAT_RANGE_CB_DEF(basename,field_name,rec_t) \
840static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* u2) {\
841 char* rng = g_strndup(buf,len);\
842 range_convert_str(NULL, &(((rec_t*)rec)->field_name), rng,GPOINTER_TO_UINT(u2)); \
843 g_free(rng); \
844 } \
845static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
846 if ( ((rec_t*)rec)->field_name ) { \
847 *out_ptr = range_convert_range(NULL, ((rec_t*)rec)->field_name); \
848 *out_len = (unsigned)strlen(*out_ptr); \
849 } else { \
850 *out_ptr = g_strdup(""); *out_len = 0; \
851 } }
852
853
854#define UAT_FLD_RANGE(basename,field_name,title,max,desc) \
855 {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_range,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},\
856 {0,0,0},GUINT_TO_POINTER(max),desc,FLDFILL}
857
858#ifdef __cplusplus
859}
860#endif /* __cplusplus */
861
862#endif /* __UAT_H__ */
863
864/*
865 * Editor modelines
866 *
867 * Local Variables:
868 * c-basic-offset: 4
869 * tab-width: 8
870 * indent-tabs-mode: nil
871 * End:
872 *
873 * ex: set shiftwidth=4 tabstop=8 expandtab:
874 * :indentSize=4:tabSize=8:noTabs=true:
875 */
Definition uat-int.h:34
Definition uat.h:235
Definition uat-int.h:40
void *(* uat_copy_cb_t)(void *dest, const void *source, size_t len)
Definition uat.h:88
WS_DLL_PUBLIC void uat_set_default_values(uat_t *uat_in, const char *default_values[])
Definition uat.c:283
WS_DLL_PUBLIC uat_t * uat_new(const char *name, size_t size, const char *filename, bool from_profile, void *data_ptr, unsigned *num_items_ptr, unsigned flags, const char *help, uat_copy_cb_t copy_cb, uat_update_cb_t update_cb, uat_free_cb_t free_cb, uat_post_update_cb_t post_update_cb, uat_reset_cb_t reset_cb, uat_field_t *flds_array)
Definition uat.c:43
void(* uat_free_cb_t)(void *record)
Definition uat.h:98
void uat_cleanup(void)
Definition uat.c:589
WS_DLL_PUBLIC bool uat_load_str(uat_t *uat_in, const char *entry, char **err)
bool(* uat_update_cb_t)(void *record, char **error)
Definition uat.h:126
void(* uat_reset_cb_t)(void)
Definition uat.h:106
uat_t * uat_find(char *name)
Definition uat.c:520
WS_DLL_PUBLIC void uat_destroy(uat_t *uat)
Definition uat.c:601
WS_DLL_PUBLIC bool uat_load(uat_t *uat_in, const char *filename, const char *app_env_var_prefix, char **err)