Wireshark  4.3.0
The Wireshark network protocol analyzer
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 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26 
27 /*
28  * UAT maintains a dynamically allocated table accessible to the user
29  * via a file and/or via GUI preference dialogs.
30  *
31  * The file is read from and written in the personal configuration directory. If
32  * there is no such file, defaults will be loaded from the global data
33  * directory.
34  *
35  * The behaviour of the table is controlled by a series of callbacks which
36  * the caller (e.g. a dissector) must provide.
37  *
38  * BEWARE that the user can change an UAT at (almost) any time (via the GUI).
39  * That is, pointers to records in an UAT are valid only during the call
40  * to the function that obtains them (do not store pointers to these records).
41  * The records contents are only guaranteed to be valid in the post_update_cb
42  * function. (Implementation detail: currently a race condition is possible
43  * where the UAT consumer (dissector code) tries to use the UAT while the GUI
44  * user frees a record resulting in use-after-free. This is not ideal and might
45  * be fixed later.)
46  *
47  * UATs are meant for short tables of user data (passwords and such), there is
48  * no quick access, you must iterate through them each time to fetch the record
49  * you are looking for.
50  *
51  * Only users via GUI or editing the file can add/remove records, your
52  * (dissector) code cannot.
53  */
54 
55 /* obscure data type to handle an uat */
56 typedef struct epan_uat uat_t;
57 /********************************************
58  * Callbacks:
59  * these instruct uat on how to deal with user info and data in records
60  ********************************************/
61 
62 /********
63  * Callbacks dealing with the entire table
64  ********/
65 
66 /*
67  * Post-Update CB
68  *
69  * To be called by the GUI code after to the table has being edited.
70  * Will be called once the user clicks the Apply or OK button
71  * optional
72  */
73 typedef void (*uat_post_update_cb_t)(void);
74 
75 
76 /********
77  * Callbacks dealing with records (these deal with entire records)
78  ********/
79 
87 typedef void* (*uat_copy_cb_t)(void *dest, const void *source, size_t len);
88 
97 typedef void (*uat_free_cb_t)(void *record);
98 
105 typedef void (*uat_reset_cb_t)(void);
106 
119 typedef bool (*uat_update_cb_t)(void *record, char **error);
120 
121 
122 /*******
123  * Callbacks for single fields (these deal with single values)
124  * the caller should provide one of these for every field!
125  ********/
126 
127 /*
128  * Check CB
129  * chk(record, ptr, len, chk_data, fld_data, &error)
130  *
131  * given an input string (ptr, len) checks if the value is OK for a field in the record.
132  * it will return true if OK or else
133  * it will return false and set *error to inform the user on what's
134  * wrong with the given input
135  * The error string must be allocated with g_malloc() or
136  * a routine that calls it.
137  * optional, if not given any input is considered OK and the set cb will be called
138  */
139 typedef bool (*uat_fld_chk_cb_t)(void *record, const char *ptr, unsigned len, const void *chk_data, const void *fld_data, char **error);
140 
141 /*
142  * Set Field CB
143  * set(record, ptr, len, set_data, fld_data)
144  *
145  * given an input string (ptr, len) sets the value of a field in the record,
146  * it is mandatory
147  */
148 typedef void (*uat_fld_set_cb_t)(void *record, const char *ptr, unsigned len, const void *set_data, const void *fld_data);
149 
150 /*
151  * Convert-to-string CB
152  * tostr(record, &out_ptr, &out_len, tostr_data, fld_data)
153  *
154  * given a record returns a string representation of the field
155  * mandatory
156  */
157 typedef void (*uat_fld_tostr_cb_t)(void *record, char **out_ptr, unsigned *out_len, const void *tostr_data, const void *fld_data);
158 
159 /***********
160  * Text Mode
161  *
162  * used for file and dialog representation of fields in columns,
163  * when the file is read it modifies the way the value is passed back to the fld_set_cb
164  * (see definition bellow for description)
165  ***********/
166 
167 typedef enum _uat_text_mode_t {
168  PT_TXTMOD_NONE,
169  /* not used */
170 
171  PT_TXTMOD_STRING,
172  /*
173  file:
174  reads:
175  ,"\x20\x00\x30", as " \00",3 ("space nil zero" of length 3)
176  ,"", as "",0
177  ,, as NULL,0
178  writes:
179  ,"\x20\x30\x00\x20", for " 0\0 ",4
180  ,"", for *, 0
181  ,, for NULL, *
182  dialog:
183  accepts \x?? and other escapes
184  gets "",0 on empty string
185  */
186  PT_TXTMOD_HEXBYTES,
187  /*
188  file:
189  reads:
190  ,A1b2C3d4, as "\xa1\xb2\xc3\xd4",4
191  ,, as NULL,0
192  writes:
193  ,, on NULL, *
194  ,a1b2c3d4, on "\xa1\xb2\xc3\xd4",4
195  dialog:
196  interprets the following input ... as ...:
197  "a1b2c3d4" as "\xa1\xb2\xc3\xd4",4
198  "a1 b2:c3d4" as "\xa1\xb2\xc3\xd4",4
199  "" as NULL,0
200  "invalid" as NULL,3
201  "a1b" as NULL, 1
202  */
203  PT_TXTMOD_ENUM,
204  /* Read/Writes/displays the string value (not number!) */
205  PT_TXTMOD_DISSECTOR,
206  /* Shows a combobox of dissectors */
207 
208  PT_TXTMOD_COLOR,
209  /* Reads/Writes/display color in #RRGGBB format */
210 
211  PT_TXTMOD_FILENAME,
212  /* processed like a PT_TXTMOD_STRING, but shows a filename dialog */
213  PT_TXTMOD_DIRECTORYNAME,
214  /* processed like a PT_TXTMOD_STRING, but shows a directory dialog */
215  PT_TXTMOD_DISPLAY_FILTER,
216  /* processed like a PT_TXTMOD_STRING, but verifies display filter */
217  PT_TXTMOD_PROTO_FIELD,
218  /* processed like a PT_TXTMOD_STRING, but verifies protocol field name (e.g tcp.flags.syn) */
219  PT_TXTMOD_BOOL
220  /* Displays a checkbox for value */
221 } uat_text_mode_t;
222 
223 /*
224  * Fields
225  *
226  *
227  */
228 typedef struct _uat_field_t {
229  const char* name;
230  const char* title;
231  uat_text_mode_t mode;
232 
233  struct {
234  uat_fld_chk_cb_t chk;
235  uat_fld_set_cb_t set;
236  uat_fld_tostr_cb_t tostr;
237  } cb;
238 
239  struct {
240  const void* chk;
241  const void* set;
242  const void* tostr;
243  } cbdata;
244 
245  const void* fld_data;
246 
247  const char* desc;
248  struct _fld_data_t* priv;
249 } uat_field_t;
250 
251 #define FLDFILL NULL
252 #define UAT_END_FIELDS {NULL,NULL,PT_TXTMOD_NONE,{0,0,0},{0,0,0},0,0,FLDFILL}
253 
254 /*
255  * Flags to indicate what the settings in this UAT affect.
256  * This is used when UATs are changed interactively, to indicate what needs
257  * to be redone when the UAT is changed.
258  *
259  * UAT_AFFECTS_FIELDS does *not* trigger a redissection, so usually one
260  * will also want UAT_AFFECTS_DISSECTION. A rare exception is changing
261  * the defined dfilter macros.
262  */
263 #define UAT_AFFECTS_DISSECTION 0x00000001 /* affects packet dissection */
264 #define UAT_AFFECTS_FIELDS 0x00000002 /* affects what named fields exist */
265 
285 WS_DLL_PUBLIC
286 uat_t* uat_new(const char* name,
287  size_t size,
288  const char* filename,
289  bool from_profile,
290  void* data_ptr,
291  unsigned* num_items_ptr,
292  unsigned flags,
293  const char* help,
294  uat_copy_cb_t copy_cb,
295  uat_update_cb_t update_cb,
296  uat_free_cb_t free_cb,
297  uat_post_update_cb_t post_update_cb,
298  uat_reset_cb_t reset_cb,
299  uat_field_t* flds_array);
300 
304 void uat_cleanup(void);
305 
314 WS_DLL_PUBLIC
315 bool uat_load(uat_t* uat_in, const char *filename, char** err);
316 
326 bool uat_load_str(uat_t* uat_in, char* entry, char** err);
327 
334 uat_t *uat_find(char *name);
335 
336 WS_DLL_PUBLIC
337 uat_t* uat_get_table_by_name(const char* name);
338 
352 WS_DLL_PUBLIC
353 void uat_set_default_values(uat_t *uat_in, const char *default_values[]);
354 
355 /*
356  * Some common uat_fld_chk_cbs
357  */
358 WS_DLL_PUBLIC
359 bool uat_fld_chk_str(void*, const char*, unsigned, const void*, const void*, char** err);
360 bool uat_fld_chk_oid(void*, const char*, unsigned, const void*, const void*, char** err);
361 WS_DLL_PUBLIC
362 bool uat_fld_chk_proto(void*, const char*, unsigned, const void*, const void*, char** err);
363 WS_DLL_PUBLIC
364 bool uat_fld_chk_num_dec(void*, const char*, unsigned, const void*, const void*, char** err);
365 WS_DLL_PUBLIC
366 bool uat_fld_chk_num_dec64(void*, const char*, unsigned, const void*, const void*, char** err);
367 WS_DLL_PUBLIC
368 bool uat_fld_chk_num_hex(void*, const char*, unsigned, const void*, const void*, char** err);
369 WS_DLL_PUBLIC
370 bool uat_fld_chk_num_hex64(void*, const char*, unsigned, const void*, const void*, char** err);
371 WS_DLL_PUBLIC
372 bool uat_fld_chk_num_signed_dec(void*, const char*, unsigned, const void*, const void*, char** err);
373 WS_DLL_PUBLIC
374 bool uat_fld_chk_num_signed_dec64(void*, const char*, unsigned, const void*, const void*, char** err);
375 WS_DLL_PUBLIC
376 bool uat_fld_chk_bool(void*, const char*, unsigned, const void*, const void*, char** err);
377 WS_DLL_PUBLIC
378 bool uat_fld_chk_enum(void*, const char*, unsigned, const void*, const void*, char**);
379 WS_DLL_PUBLIC
380 bool uat_fld_chk_range(void*, const char*, unsigned, const void*, const void*, char**);
381 WS_DLL_PUBLIC
382 bool uat_fld_chk_color(void*, const char*, unsigned, const void*, const void*, char**);
383 
384 typedef void (*uat_cb_t)(void* uat,void* user_data);
385 WS_DLL_PUBLIC
386 void uat_foreach_table(uat_cb_t cb,void* user_data);
387 void uat_unload_all(void);
388 
389 char* uat_undquote(const char* si, unsigned in_len, unsigned* len_p);
390 char* uat_unbinstring(const char* si, unsigned in_len, unsigned* len_p);
391 char* uat_unesc(const char* si, unsigned in_len, unsigned* len_p);
392 char* uat_esc(const char* buf, unsigned len);
393 
394 /* Some strings entirely made of ... already declared */
395 
396 WS_DLL_PUBLIC
397 bool uat_fld_chk_str_isprint(void*, const char*, unsigned, const void*, const void*, char**);
398 
399 WS_DLL_PUBLIC
400 bool uat_fld_chk_str_isalpha(void*, const char*, unsigned, const void*, const void*, char**);
401 
402 WS_DLL_PUBLIC
403 bool uat_fld_chk_str_isalnum(void*, const char*, unsigned, const void*, const void*, char**);
404 
405 WS_DLL_PUBLIC
406 bool uat_fld_chk_str_isdigit(void*, const char*, unsigned, const void*, const void*, char**);
407 
408 WS_DLL_PUBLIC
409 bool uat_fld_chk_str_isxdigit(void*, const char*, unsigned, const void*, const void*, char**);
410 
411 
412 /*
413  * Macros
414  * to define basic uat_fld_set_cbs, uat_fld_tostr_cbs
415  * for those elements in uat_field_t array
416  */
417 
418 #ifdef __cplusplus
419 #define UNUSED_PARAMETER(n)
420 #else
421 #define UNUSED_PARAMETER(n) n _U_
422 #endif
423 
424 /*
425  * CSTRING macros,
426  * a simple c-string contained in (((rec_t*)rec)->(field_name))
427  */
428 #define UAT_CSTRING_CB_DEF(basename,field_name,rec_t) \
429 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
430  char* new_buf = g_strndup(buf,len); \
431  g_free((((rec_t*)rec)->field_name)); \
432  (((rec_t*)rec)->field_name) = new_buf; } \
433 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)) {\
434  if (((rec_t*)rec)->field_name ) { \
435  *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
436  *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
437  } else { \
438  *out_ptr = g_strdup(""); *out_len = 0; } }
439 
440 #define UAT_FLD_CSTRING(basename,field_name,title,desc) \
441  {#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}
442 
443 #define UAT_FLD_CSTRING_ISPRINT(basename,field_name,title,desc) \
444  {#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}
445 
446 #define UAT_FLD_CSTRING_OTHER(basename,field_name,title,chk,desc) \
447  {#field_name, title, PT_TXTMOD_STRING,{ chk ,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
448 
449 /*
450  * FILENAME and DIRECTORYNAME,
451  * a simple c-string contained in (((rec_t*)rec)->(field_name))
452  */
453 #define UAT_FILENAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
454 
455 /* XXX UAT_FLD_FILENAME is currently unused. */
456 #define UAT_FLD_FILENAME(basename,field_name,title,desc) \
457  {#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}
458 
459 /*
460  * Both the Qt and GTK+ UIs assume that we're opening a preexisting
461  * file. We might want to split the ..._FILENAME defines into
462  * ..._FILE_OPEN and ..._FILE_SAVE if we ever need to specify a
463  * file that we're creating.
464  */
465 #define UAT_FLD_FILENAME_OTHER(basename,field_name,title,chk,desc) \
466  {#field_name, title, PT_TXTMOD_FILENAME,{chk,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
467 
468 #define UAT_DIRECTORYNAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
469 
470 #define UAT_FLD_DIRECTORYNAME(basename,field_name,title,desc) \
471  {#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}
472 
473 /*
474  * DISPLAY_FILTER,
475  * a simple c-string contained in (((rec_t*)rec)->(field_name))
476  */
477 #define UAT_DISPLAY_FILTER_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
478 
479 #define UAT_FLD_DISPLAY_FILTER(basename,field_name,title,desc) \
480  {#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}
481 
482 /*
483  * PROTO_FIELD,
484  * a simple c-string contained in (((rec_t*)rec)->(field_name))
485  */
486 #define UAT_PROTO_FIELD_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
487 
488 #define UAT_FLD_PROTO_FIELD(basename,field_name,title,desc) \
489  {#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}
490 
491 /*
492  * OID - just a CSTRING with a specific check routine
493  */
494 #define UAT_FLD_OID(basename,field_name,title,desc) \
495  {#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}
496 
497 
498 /*
499  * LSTRING MACROS
500  */
501 #define UAT_LSTRING_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
502 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
503  char* new_val = uat_unesc(buf,len,&(((rec_t*)rec)->len_element)); \
504  g_free((((rec_t*)rec)->ptr_element)); \
505  (((rec_t*)rec)->ptr_element) = new_val; }\
506 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)) {\
507  if (((rec_t*)rec)->ptr_element ) { \
508  *out_ptr = uat_esc(((rec_t*)rec)->ptr_element, (((rec_t*)rec)->len_element)); \
509  *out_len = (unsigned)strlen(*out_ptr); \
510  } else { \
511  *out_ptr = g_strdup(""); \
512  *out_len = 0; \
513  } \
514 }
515 
516 #define UAT_FLD_LSTRING(basename,field_name,title, desc) \
517 {#field_name, title, PT_TXTMOD_STRING,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
518 
519 
520 /*
521  * BUFFER macros,
522  * a buffer_ptr contained in (((rec_t*)rec)->(field_name))
523  * and its len in (((rec_t*)rec)->(len_name))
524  */
525 #define UAT_BUFFER_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
526 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
527  unsigned char* new_buf = len ? (unsigned char *)g_memdup2(buf,len) : NULL; \
528  g_free((((rec_t*)rec)->ptr_element)); \
529  (((rec_t*)rec)->ptr_element) = new_buf; \
530  (((rec_t*)rec)->len_element) = len; } \
531 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)) {\
532  *out_ptr = ((rec_t*)rec)->ptr_element ? (char*)g_memdup2(((rec_t*)rec)->ptr_element,((rec_t*)rec)->len_element) : g_strdup(""); \
533  *out_len = ((rec_t*)rec)->len_element; }
534 
535 #define UAT_FLD_BUFFER(basename,field_name,title,desc) \
536  {#field_name, title, PT_TXTMOD_HEXBYTES,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
537 
538 
539 /*
540  * DEC Macros,
541  * an unsigned decimal number contained in (((rec_t*)rec)->(field_name))
542  */
543 #define UAT_DEC_CB_DEF(basename,field_name,rec_t) \
544 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
545  char* tmp_str = g_strndup(buf,len); \
546  ws_strtou32(tmp_str, NULL, &((rec_t*)rec)->field_name); \
547  g_free(tmp_str); } \
548 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)) {\
549  *out_ptr = ws_strdup_printf("%u",((rec_t*)rec)->field_name); \
550  *out_len = (unsigned)strlen(*out_ptr); }
551 
552 #define UAT_FLD_DEC(basename,field_name,title,desc) \
553  {#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}
554 
555  /*
556  * an unsigned 64bit decimal number contained in (((rec_t*)rec)->(field_name))
557  */
558 #define UAT_DEC64_CB_DEF(basename,field_name,rec_t) \
559 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
560  char* tmp_str = g_strndup(buf,len); \
561  ws_strtou64(tmp_str, NULL, &((rec_t*)rec)->field_name); \
562  g_free(tmp_str); } \
563 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)) {\
564  *out_ptr = ws_strdup_printf("%" PRIu64,((rec_t*)rec)->field_name); \
565  *out_len = (unsigned)strlen(*out_ptr); }
566 
567 #define UAT_FLD_DEC64(basename,field_name,title,desc) \
568  {#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}
569 
570 /*
571  * a *signed* decimal number contained in (((rec_t*)rec)->(field_name))
572  */
573 #define UAT_SIGNED_DEC_CB_DEF(basename,field_name,rec_t) \
574 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
575  char* tmp_str = g_strndup(buf,len); \
576  ws_strtoi32(tmp_str, NULL, &((rec_t*)rec)->field_name); \
577  g_free(tmp_str); } \
578 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)) {\
579  *out_ptr = ws_strdup_printf("%d",((rec_t*)rec)->field_name); \
580  *out_len = (unsigned)strlen(*out_ptr); }
581 
582 #define UAT_FLD_SIGNED_DEC(basename,field_name,title,desc) \
583  {#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}
584 
585  /*
586  * and a *signed* 64bit decimal number contained in (((rec_t*)rec)->(field_name))
587  */
588 #define UAT_SIGNED_DEC64_CB_DEF(basename,field_name,rec_t) \
589 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
590  char* tmp_str = g_strndup(buf,len); \
591  ws_strtoi64(tmp_str, NULL, &((rec_t*)rec)->field_name); \
592  g_free(tmp_str); } \
593 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)) {\
594  *out_ptr = ws_strdup_printf("%" PRId64,((rec_t*)rec)->field_name); \
595  *out_len = (unsigned)strlen(*out_ptr); }
596 
597 #define UAT_FLD_SIGNED_DEC64(basename,field_name,title,desc) \
598  {#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}
599 
600 #define UAT_FLD_NONE(basename,field_name,title,desc) \
601  {#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}
602 
603 
604 /*
605  * HEX Macros,
606  * an unsigned hexadecimal number contained in (((rec_t*)rec)->(field_name))
607  */
608 #define UAT_HEX_CB_DEF(basename,field_name,rec_t) \
609 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
610  char* tmp_str = g_strndup(buf,len); \
611  ws_hexstrtou32(tmp_str, NULL, &((rec_t*)rec)->field_name); \
612  g_free(tmp_str); } \
613 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)) {\
614  *out_ptr = ws_strdup_printf("%x",((rec_t*)rec)->field_name); \
615  *out_len = (unsigned)strlen(*out_ptr); }
616 
617 #define UAT_FLD_HEX(basename,field_name,title,desc) \
618 {#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}
619 
620  /*
621  * HEX Macros for 64bit,
622  * an unsigned long long hexadecimal number contained in (((rec_t*)rec)->(field_name))
623  */
624 #define UAT_HEX64_CB_DEF(basename,field_name,rec_t) \
625 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
626  char* tmp_str = g_strndup(buf,len); \
627  ws_hexstrtou64(tmp_str, NULL, &((rec_t*)rec)->field_name); \
628  g_free(tmp_str); } \
629 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)) {\
630  *out_ptr = ws_strdup_printf("%" PRIx64,((rec_t*)rec)->field_name); \
631  *out_len = (unsigned)strlen(*out_ptr); }
632 
633 #define UAT_FLD_HEX64(basename,field_name,title,desc) \
634 {#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}
635 
636 /*
637  * BOOL Macros,
638  * an boolean value contained in (((rec_t*)rec)->(field_name))
639  */
640 #define UAT_BOOL_CB_DEF(basename,field_name,rec_t) \
641 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
642  char* tmp_str = g_strndup(buf,len); \
643  if (g_strcmp0(tmp_str, "TRUE") == 0) \
644  ((rec_t*)rec)->field_name = 1; \
645  else \
646  ((rec_t*)rec)->field_name = 0; \
647  g_free(tmp_str); } \
648 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)) {\
649  *out_ptr = ws_strdup_printf("%s",((rec_t*)rec)->field_name ? "TRUE" : "FALSE"); \
650  *out_len = (unsigned)strlen(*out_ptr); }
651 
652 #define UAT_FLD_BOOL(basename,field_name,title,desc) \
653 {#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}
654 
655 /*
656  * ENUM macros
657  * enum_t: name = ((enum_t*)ptr)->strptr
658  * value = ((enum_t*)ptr)->value
659  * rec_t:
660  * value
661  */
662 #define UAT_VS_DEF(basename,field_name,rec_t,default_t,default_val,default_str) \
663 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
664  unsigned i; \
665  char* str = g_strndup(buf,len); \
666  const char* cstr; \
667  ((rec_t*)rec)->field_name = default_val; \
668  for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
669  if (g_str_equal(cstr,str)) { \
670  ((rec_t*)rec)->field_name = (default_t)((const value_string*)vs)[i].value; \
671  g_free(str); \
672  return; \
673  } \
674  } \
675  g_free(str); } \
676 static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
677  unsigned i; \
678  for(i=0;((const value_string*)vs)[i].strptr;i++) { \
679  if ( ((const value_string*)vs)[i].value == ((rec_t*)rec)->field_name ) { \
680  *out_ptr = g_strdup(((const value_string*)vs)[i].strptr); \
681  *out_len = (unsigned)strlen(*out_ptr); \
682  return; \
683  } \
684  } \
685  *out_ptr = g_strdup(default_str); \
686  *out_len = (unsigned)strlen(default_str); }
687 
688 #define UAT_VS_CSTRING_DEF(basename,field_name,rec_t,default_val,default_str) \
689 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
690  unsigned i; \
691  char* str = g_strndup(buf,len); \
692  const char* cstr; \
693  ((rec_t*)rec)->field_name = default_val; \
694  for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
695  if (g_str_equal(cstr,str)) { \
696  ((rec_t*)rec)->field_name = g_strdup(((const value_string*)vs)[i].strptr); \
697  g_free(str); \
698  return; \
699  } \
700  } \
701  g_free(str);} \
702 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)) {\
703  if (((rec_t*)rec)->field_name ) { \
704  *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
705  *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
706  } else { \
707  *out_ptr = g_strdup(""); *out_len = 0; } }
708 
709 #define UAT_FLD_VS(basename,field_name,title,enum,desc) \
710  {#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}
711 
712 
713 /*
714  * Color Macros,
715  * an #RRGGBB color value contained in (((rec_t*)rec)->(field_name))
716  */
717 #define UAT_COLOR_CB_DEF(basename,field_name,rec_t) \
718 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
719  if (len < 1) { \
720  ((rec_t*)rec)->field_name = 0; \
721  return; \
722  } \
723  char* tmp_str = g_strndup(buf+1,len-1); \
724  ((rec_t*)rec)->field_name = (unsigned)strtol(tmp_str,NULL,16); \
725  g_free(tmp_str); } \
726 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)) {\
727  *out_ptr = ws_strdup_printf("#%06X",((rec_t*)rec)->field_name); \
728  *out_len = (unsigned)strlen(*out_ptr); }
729 
730 #define UAT_FLD_COLOR(basename,field_name,title,desc) \
731 {#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}
732 
733 
734 /*
735  * DISSECTOR macros
736  */
737 
738 #define UAT_DISSECTOR_DEF(basename, field_name, dissector_field, name_field, rec_t) \
739 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
740  if (len) { \
741  ((rec_t*)rec)->name_field = g_strndup(buf, len); \
742  g_strstrip(((rec_t*)rec)->name_field); \
743  ((rec_t*)rec)->dissector_field = find_dissector(((rec_t*)rec)->name_field); \
744  } else { \
745  ((rec_t*)rec)->dissector_field = find_dissector("data"); \
746  ((rec_t*)rec)->name_field = NULL; \
747  } } \
748 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)) {\
749  if ( ((rec_t*)rec)->name_field ) { \
750  *out_ptr = g_strdup((((rec_t*)rec)->name_field)); \
751  *out_len = (unsigned)strlen(*out_ptr); \
752  } else { \
753  *out_ptr = g_strdup(""); *out_len = 0; } }
754 
755 
756 #define UAT_FLD_DISSECTOR(basename,field_name,title,desc) \
757  {#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}
758 
759 /*
760  * RANGE macros
761  */
762 
763 #define UAT_RANGE_CB_DEF(basename,field_name,rec_t) \
764 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* UNUSED_PARAMETER(u1), const void* u2) {\
765  char* rng = g_strndup(buf,len);\
766  range_convert_str(NULL, &(((rec_t*)rec)->field_name), rng,GPOINTER_TO_UINT(u2)); \
767  g_free(rng); \
768  } \
769 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)) {\
770  if ( ((rec_t*)rec)->field_name ) { \
771  *out_ptr = range_convert_range(NULL, ((rec_t*)rec)->field_name); \
772  *out_len = (unsigned)strlen(*out_ptr); \
773  } else { \
774  *out_ptr = g_strdup(""); *out_len = 0; } }
775 
776 
777 #define UAT_FLD_RANGE(basename,field_name,title,max,desc) \
778  {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_range,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},\
779  {0,0,0},GUINT_TO_POINTER(max),desc,FLDFILL}
780 
781 #ifdef __cplusplus
782 }
783 #endif /* __cplusplus */
784 
785 #endif /* __UAT_H__ */
Definition: uat-int.h:32
Definition: uat.h:228
Definition: uat-int.h:38
WS_DLL_PUBLIC void uat_set_default_values(uat_t *uat_in, const char *default_values[])
Definition: uat.c:269
uat_t * uat_find(char *name)
Definition: uat.c:449
void *(* uat_copy_cb_t)(void *dest, const void *source, size_t len)
Definition: uat.h:87
void(* uat_free_cb_t)(void *record)
Definition: uat.h:97
void uat_cleanup(void)
Definition: uat.c:502
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
WS_DLL_PUBLIC bool uat_load(uat_t *uat_in, const char *filename, char **err)
bool uat_load_str(uat_t *uat_in, char *entry, char **err)
bool(* uat_update_cb_t)(void *record, char **error)
Definition: uat.h:119
void(* uat_reset_cb_t)(void)
Definition: uat.h:105