rerun pidl
[metze/wireshark/wip.git] / epan / uat.h
1 /*
2  *  uat.h
3  *
4  *  $Id$
5  *
6  *  User Accessible Tables
7  *  Mantain an array of user accessible data strucures
8  *
9  * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
10  *
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 2001 Gerald Combs
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28  */
29
30 #ifndef __UAT_H__
31 #define __UAT_H__
32
33 #include <stdlib.h>
34
35 #include <epan/emem.h>
36
37 #include "ws_symbol_export.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42
43 /*
44  * uat mantains a dynamically allocated table accessible to the user
45  * via a file and/or gui tables.
46  *
47  * the file is located either in userdir(when first read or when writen) or
48  * in datadir for defaults (read only , it will be always written to userdir).
49  *
50  * the behaviour of the table is controlled by a series of callbacks
51  * the caller must provide.
52  *
53  * BEWARE that the user can change an uat at (almost) any time,
54  * That is pointers to records in an uat are valid only during the call
55  * to the function that obtains them (do not store them).
56  *
57  * UATs are meant for short tables of user data (passwords and such) there's
58  * no quick access, you must iterate through them each time to fetch the record
59  * you are looking for. Use uat_dup() or uat_se_dup() if necessary.
60  *
61  * Only users via gui or editing the file can add/remove records your code cannot.
62  */
63
64 /* obscure data type to handle an uat */
65 typedef struct epan_uat uat_t;
66 /********************************************
67  * Callbacks:
68  * these instruct uat on how to deal with user info and data in records
69  ********************************************/
70
71 /********
72  * Callbacks dealing with the entire table
73  ********/
74
75 /*
76  * Post-Update CB
77  *
78  * to be called after to the table has being edited
79  * Will be called once the user clicks the Apply or OK button
80  * optional
81  */
82 typedef void (*uat_post_update_cb_t)(void);
83
84
85 /********
86  * Callbacks dealing with records (these deal with entire records)
87  ********/
88
89 /*
90  * Copy CB
91  * used to copy a record
92  * optional, memcpy will be used if not given
93  * copy(dest,orig,len)
94  */
95 typedef void* (*uat_copy_cb_t)(void*, const void*, size_t);
96
97 /*
98  *
99  * Free CB
100  *
101  * destroy a record's child data
102  * (do not free the container, it will be handled by uat)
103  * it is optional, no child data will be freed if no present
104  * free(record)
105  */
106 typedef void (*uat_free_cb_t)(void*);
107
108 /*
109  * Update CB
110  *
111  * to be called after any record fields had been updated
112  * optional, record will be updated always if not given
113  * update(record,&error)
114  */
115 typedef void (*uat_update_cb_t)(void* , const char** );
116
117
118 /*******
119  * Callbacks for single fields (these deal with single values)
120  * the caller should provide one of these for every field!
121  ********/
122
123 /*
124  * given an input string (ptr, len) checks if the value is OK for a field in the record.
125  * it will return TRUE if OK or else
126  * it will return FALSE and may set *error to inform the user on what's
127  * wrong with the given input
128  * optional, if not given any input is considered OK and the set cb will be called
129  * chk(record, ptr, len, chk_data, fld_data, &error)
130  */
131 typedef gboolean (*uat_fld_chk_cb_t)(void*, const char*, unsigned, const void*, const void*, const char**);
132
133 /*
134  * Set Field CB
135  *
136  * given an input string (ptr, len) sets the value of a field in the record,
137  * it will return TRUE if OK or else
138  * it will return FALSE and may set *error to inform the user on what's
139  * wrong with the given input
140  * it is mandatory
141  * set(record, ptr, len, set_data, fld_data)
142  */
143 typedef void (*uat_fld_set_cb_t)(void*, const char*, unsigned, const void*, const void*);
144
145 /*
146  * given a record returns a string representation of the field
147  * mandatory
148  * tostr(record, &out_ptr, &out_len, tostr_data, fld_data)
149  */
150 typedef void (*uat_fld_tostr_cb_t)(void*, const char**, unsigned*, const void*, const void*);
151
152 /***********
153  * Text Mode
154  *
155  * used for file and dialog representation of fields in columns,
156  * when the file is read it modifies the way the value is passed back to the fld_set_cb
157  * (see definition bellow for description)
158  ***********/
159
160 typedef enum _uat_text_mode_t {
161         PT_TXTMOD_NONE,
162         /* not used */
163
164         PT_TXTMOD_STRING,
165         /*
166          file:
167                  reads:
168                          ,"\x20\x00\x30", as " \00",3
169                          ,"", as "",0
170                          ,, as NULL,0
171                  writes:
172                          ,"\x20\x30\x00\x20", for " 0\0 ",4
173                          ,"", for *, 0
174                          ,, for NULL, *
175          dialog:
176                  accepts \x?? and other escapes
177                  gets "",0 on empty string
178          */
179         PT_TXTMOD_HEXBYTES,
180         /*
181          file:
182                  reads:
183                          ,A1b2C3d4, as "\001\002\003\004",4
184                          ,, as NULL,0
185                  writes:
186                          ,, on NULL, *
187                          ,a1b2c3d4, on "\001\002\003\004",4
188          dialog:
189                  "a1b2c3d4" as "\001\002\003\004",4
190                  "a1 b2:c3d4" as "\001\002\003\004",4
191                  "" as NULL,0
192                  "invalid" as NULL,3
193                  "a1b" as NULL, 1
194          */
195         PT_TXTMOD_ENUM,
196
197         PT_TXTMOD_FILENAME,
198         /* processed like a PT_TXTMOD_STRING, but shows a filename dialog */
199         PT_TXTMOD_DIRECTORYNAME
200         /* processed like a PT_TXTMOD_STRING, but shows a directory dialog */
201 } uat_text_mode_t;
202
203 /*
204  * Fields
205  *
206  *
207  */
208 typedef struct _uat_field_t {
209         const char* name;
210         const char* title;
211         uat_text_mode_t mode;
212
213         struct {
214                 uat_fld_chk_cb_t chk;
215                 uat_fld_set_cb_t set;
216                 uat_fld_tostr_cb_t tostr;
217         } cb;
218
219         struct {
220                 const void* chk;
221                 const void* set;
222                 const void* tostr;
223         } cbdata;
224
225         const void* fld_data;
226
227         const char* desc;
228         struct _fld_data_t* priv;
229 } uat_field_t;
230
231 #define FLDFILL NULL
232 #define UAT_END_FIELDS {NULL,NULL,PT_TXTMOD_NONE,{0,0,0},{0,0,0},0,0,FLDFILL}
233
234 /*
235  * Flags to indicate what the settings in this UAT affect.
236  * This is used when UATs are changed interactively, to indicate what needs
237  * to be redone when the UAT is changed.
238  */
239 #define UAT_AFFECTS_DISSECTION  0x00000001      /* affects packet dissection */
240 #define UAT_AFFECTS_FIELDS      0x00000002      /* affects what named fields exist */
241
242 /** Create a new uat
243  *
244  * @param name The name of the table
245  * @param size The size of the structure
246  * @param filename The filename to be used (either in userdir or datadir)
247  * @param from_profile TRUE if profile directory to be used
248  * @param data_ptr A pointer to a null terminated array of pointers to the data
249  * @param num_items_ptr A pointer with number of items
250  * @param flags flags indicating what this UAT affects
251  * @param help A pointer to help text
252  * @param copy_cb A function that copies the data in the struct
253  * @param update_cb Will be called when a record is updated
254  * @param free_cb Will be called to destroy a struct in the dataset
255  * @param post_update_cb Will be called once the user clicks the Apply or OK button
256  * @param flds_array A pointer to an array of uat_field_t structs
257  *
258  * @return A freshly-allocated and populated uat_t struct.
259  */
260 WS_DLL_PUBLIC
261 uat_t* uat_new(const char* name,
262                            size_t size,
263                            const char* filename,
264                            gboolean from_profile,
265                            void** data_ptr,
266                            guint* num_items_ptr,
267                            guint flags,
268                            const char* help,
269                            uat_copy_cb_t copy_cb,
270                            uat_update_cb_t update_cb,
271                            uat_free_cb_t free_cb,
272                            uat_post_update_cb_t post_update_cb,
273                            uat_field_t* flds_array);
274
275 /** Populate a uat using its file.
276  *
277  * @param uat_in Pointer to a uat. Must not be NULL.
278  * @param err Upon failure, points to an error string.
279  *
280  * @return TRUE on success, FALSE on failure.
281  */
282 WS_DLL_PUBLIC
283 gboolean uat_load(uat_t* uat_in, const char** err);
284
285 /** Create or update a single uat entry using a string.
286  *
287  * @param uat_in Pointer to a uat. Must not be NULL.
288  * @param entry The string representation of the entry. Format must match
289  * what's written to the uat's output file.
290  * @param err Upon failure, points to an error string.
291  *
292  * @return TRUE on success, FALSE on failure.
293  */
294 gboolean uat_load_str(uat_t* uat_in, char* entry, char** err);
295
296 /** Given a uat name or filename, find its pointer.
297  *
298  * @param name The name or filename of the uat
299  *
300  * @return A pointer to the uat on success, NULL on failure.
301  */
302 uat_t *uat_find(gchar *name);
303
304 /*
305  * uat_dup()
306  * uat_se_dup()
307  * make a reliable copy of an uat for internal use,
308  * so that pointers to records can be kept through calls.
309  * return NULL on zero len.
310  */
311 void* uat_dup(uat_t*, guint* len_p); /* to be freed */
312 void* uat_se_dup(uat_t*, guint* len_p);
313 WS_DLL_PUBLIC
314 uat_t* uat_get_table_by_name(const char* name);
315
316 /*
317  * Some common uat_fld_chk_cbs
318  */
319 WS_DLL_PUBLIC
320 gboolean uat_fld_chk_str(void*, const char*, unsigned, const void*, const void*, const char** err);
321 gboolean uat_fld_chk_oid(void*, const char*, unsigned, const void*, const void*, const char** err);
322 WS_DLL_PUBLIC
323 gboolean uat_fld_chk_proto(void*, const char*, unsigned, const void*, const void*, const char** err);
324 WS_DLL_PUBLIC
325 gboolean uat_fld_chk_num_dec(void*, const char*, unsigned, const void*, const void*, const char** err);
326 WS_DLL_PUBLIC
327 gboolean uat_fld_chk_num_hex(void*, const char*, unsigned, const void*, const void*, const char** err);
328 WS_DLL_PUBLIC
329 gboolean uat_fld_chk_enum(void*, const char*, unsigned, const void*, const void*, const char**);
330 WS_DLL_PUBLIC
331 gboolean uat_fld_chk_range(void*, const char*, unsigned, const void*, const void*, const char**);
332
333 #define CHK_STR_IS_DECL(what) \
334 gboolean uat_fld_chk_str_ ## what (void*, const char*, unsigned, const void*, const void*, const char**)
335
336 typedef void (*uat_cb_t)(void* uat,void* user_data);
337 WS_DLL_PUBLIC
338 void uat_foreach_table(uat_cb_t cb,void* user_data);
339 void uat_unload_all(void);
340
341 char* uat_undquote(const char* si, guint in_len, guint* len_p);
342 char* uat_unbinstring(const char* si, guint in_len, guint* len_p);
343 char* uat_unesc(const char* si, guint in_len, guint* len_p);
344 char* uat_esc(const char* buf, guint len);
345
346 /* Some strings entirely made of ... already declared */
347 WS_DLL_PUBLIC
348 CHK_STR_IS_DECL(isprint);
349 WS_DLL_PUBLIC
350 CHK_STR_IS_DECL(isalpha);
351 WS_DLL_PUBLIC
352 CHK_STR_IS_DECL(isalnum);
353 WS_DLL_PUBLIC
354 CHK_STR_IS_DECL(isdigit);
355 WS_DLL_PUBLIC
356 CHK_STR_IS_DECL(isxdigit);
357
358 #define CHK_STR_IS_DEF(what) \
359 gboolean uat_fld_chk_str_ ## what (void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, const char** err) { \
360         guint i; for (i=0;i<len;i++) { \
361                 char c = strptr[i]; \
362                         if (! what((int)c)) { \
363                                 *err = ep_strdup_printf("invalid char pos=%d value=%.2x",i,c); return FALSE;  } } \
364                 *err = NULL; return TRUE; }
365
366
367 /*
368  * Macros
369  *   to define basic uat_fld_set_cbs, uat_fld_tostr_cbs
370  *   for those elements in uat_field_t array
371  */
372
373 /*
374  * CSTRING macros,
375  *    a simple c-string contained in (((rec_t*)rec)->(field_name))
376  */
377 #define UAT_CSTRING_CB_DEF(basename,field_name,rec_t) \
378 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* u1 _U_, const void* u2 _U_) {\
379     char* new_buf = g_strndup(buf,len); \
380         g_free((((rec_t*)rec)->field_name)); \
381         (((rec_t*)rec)->field_name) = new_buf; } \
382 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) {\
383                 if (((rec_t*)rec)->field_name ) { \
384                         *out_ptr = (((rec_t*)rec)->field_name); \
385                         *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
386                 } else { \
387                         *out_ptr = ""; *out_len = 0; } }
388
389 #define UAT_FLD_CSTRING(basename,field_name,title,desc) \
390         {#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}
391
392 #define UAT_FLD_CSTRING_ISPRINT(basename,field_name,title,desc) \
393         {#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}
394
395 #define UAT_FLD_CSTRING_OTHER(basename,field_name,title,chk,desc) \
396         {#field_name, title, PT_TXTMOD_STRING,{ chk ,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
397
398 /*
399  * FILENAME and DIRECTORYNAME,
400  *    a simple c-string contained in (((rec_t*)rec)->(field_name))
401  */
402 #define UAT_FILENAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
403
404 #define UAT_FLD_FILENAME(basename,field_name,title,desc) \
405         {#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}
406
407 #define UAT_FLD_FILENAME_OTHER(basename,field_name,title,chk,desc) \
408         {#field_name, title, PT_TXTMOD_FILENAME,{chk,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
409
410 #define UAT_DIRECTORYNAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
411
412 #define UAT_FLD_DIRECTORYNAME(basename,field_name,title,desc) \
413         {#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}
414
415 /*
416  * OID - just a CSTRING with a specific check routine
417  */
418 #define UAT_FLD_OID(basename,field_name,title,desc) \
419         {#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}
420
421
422 /*
423  * LSTRING MACROS
424  */
425 #define UAT_LSTRING_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
426 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* u1 _U_, const void* u2 _U_) {\
427         char* new_val = uat_unesc(buf,len,&(((rec_t*)rec)->len_element)); \
428         g_free((((rec_t*)rec)->ptr_element)); \
429         (((rec_t*)rec)->ptr_element) = new_val; }\
430 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) {\
431         if (((rec_t*)rec)->ptr_element ) { \
432                 *out_ptr = uat_esc(((rec_t*)rec)->ptr_element, (((rec_t*)rec)->len_element)); \
433                 *out_len = (unsigned)strlen(*out_ptr); \
434         } else { \
435                 *out_ptr = ""; *out_len = 0; } }
436
437 #define UAT_FLD_LSTRING(basename,field_name,title, desc) \
438 {#field_name, title, PT_TXTMOD_STRING,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
439
440
441 /*
442  * BUFFER macros,
443  *    a buffer_ptr contained in (((rec_t*)rec)->(field_name))
444  *    and its len in (((rec_t*)rec)->(len_name))
445  *  XXX: UNTESTED and probably BROKEN
446  */
447 #define UAT_BUFFER_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
448 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* u1 _U_, const void* u2 _U_) {\
449         char* new_buf = len ? (char *)g_memdup(buf,len) : NULL; \
450         g_free((((rec_t*)rec)->ptr_element)); \
451         (((rec_t*)rec)->ptr_element) = new_buf; \
452         (((rec_t*)rec)->len_element) = len; } \
453 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) {\
454         *out_ptr = ((rec_t*)rec)->ptr_element ? (const char*)ep_memdup(((rec_t*)rec)->ptr_element,((rec_t*)rec)->len_element) : ""; \
455         *out_len = ((rec_t*)rec)->len_element; }
456
457 #define UAT_FLD_BUFFER(basename,field_name,title,desc) \
458         {#field_name, title, PT_TXTMOD_HEXBYTES,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
459
460
461 /*
462  * DEC Macros,
463  *   a decimal number contained in
464  */
465 #define UAT_DEC_CB_DEF(basename,field_name,rec_t) \
466 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* u1 _U_, const void* u2 _U_) {\
467         ((rec_t*)rec)->field_name = (guint)strtol(ep_strndup(buf,len),NULL,10); } \
468 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) {\
469         *out_ptr = ep_strdup_printf("%d",((rec_t*)rec)->field_name); \
470         *out_len = (unsigned)strlen(*out_ptr); }
471
472 #define UAT_FLD_DEC(basename,field_name,title,desc) \
473         {#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}
474
475 #define UAT_FLD_NONE(basename,field_name,title,desc) \
476         {#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}
477
478
479 /*
480  * HEX Macros,
481  *   an hexadecimal number contained in
482  */
483 #define UAT_HEX_CB_DEF(basename,field_name,rec_t) \
484 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* u1 _U_, const void* u2 _U_) {\
485         ((rec_t*)rec)->field_name = (guint)strtol(ep_strndup(buf,len),NULL,16); } \
486 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) {\
487         *out_ptr = ep_strdup_printf("%x",((rec_t*)rec)->field_name); \
488         *out_len = (unsigned)strlen(*out_ptr); }
489
490 #define UAT_FLD_HEX(basename,field_name,title,desc) \
491 {#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}
492
493
494 /*
495  * ENUM macros
496  *  enum_t: name = ((enum_t*)ptr)->strptr
497  *          value = ((enum_t*)ptr)->value
498  *  rec_t:
499  *        value
500  */
501 #define UAT_VS_DEF(basename,field_name,rec_t,default_t,default_val,default_str) \
502 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* vs, const void* u2 _U_) {\
503         guint i; \
504         char* str = ep_strndup(buf,len); \
505         const char* cstr; ((rec_t*)rec)->field_name = default_val; \
506         for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
507                 if (g_str_equal(cstr,str)) { \
508                         ((rec_t*)rec)->field_name = (default_t)((const value_string*)vs)[i].value; return; } } } \
509 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* vs, const void* u2 _U_) {\
510         guint i; \
511         *out_ptr = ep_strdup(default_str); \
512         *out_len = (unsigned)strlen(default_str);\
513         for(i=0;((const value_string*)vs)[i].strptr;i++) { \
514                 if ( ((const value_string*)vs)[i].value == ((rec_t*)rec)->field_name ) { \
515                         *out_ptr = ep_strdup(((const value_string*)vs)[i].strptr); \
516                         *out_len = (unsigned)strlen(*out_ptr); return; } } }
517
518 #define UAT_VS_CSTRING_DEF(basename,field_name,rec_t,default_val,default_str) \
519 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* vs, const void* u2 _U_) {\
520         guint i; \
521         char* str = ep_strndup(buf,len); \
522         const char* cstr; ((rec_t*)rec)->field_name = default_val; \
523         for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
524                 if (g_str_equal(cstr,str)) { \
525                   ((rec_t*)rec)->field_name = g_strdup(((const value_string*)vs)[i].strptr); return; } } } \
526 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* vs _U_, const void* u2 _U_) {\
527                 if (((rec_t*)rec)->field_name ) { \
528                         *out_ptr = (((rec_t*)rec)->field_name); \
529                         *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
530                 } else { \
531                         *out_ptr = ""; *out_len = 0; } }
532
533 #define UAT_FLD_VS(basename,field_name,title,enum,desc) \
534         {#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}
535
536
537 /*
538  * PROTO macros
539  */
540
541 #define UAT_PROTO_DEF(basename, field_name, dissector_field, name_field, rec_t) \
542 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* u1 _U_, const void* u2 _U_) {\
543         if (len) { \
544                 gchar *tmp = g_strndup(buf,len); \
545                 ((rec_t*)rec)->name_field = g_ascii_strdown(tmp, -1); \
546                 g_free(tmp); \
547                 g_strchug(((rec_t*)rec)->name_field); \
548                 ((rec_t*)rec)->dissector_field = find_dissector(((rec_t*)rec)->name_field); \
549         } else { \
550                 ((rec_t*)rec)->dissector_field = find_dissector("data"); \
551                 ((rec_t*)rec)->name_field = NULL; \
552                 } } \
553 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) {\
554         if ( ((rec_t*)rec)->name_field ) { \
555                 *out_ptr = (((rec_t*)rec)->name_field); \
556                 *out_len = (unsigned)strlen(*out_ptr); \
557         } else { \
558                 *out_ptr = ""; *out_len = 0; } }
559
560
561 #define UAT_FLD_PROTO(basename,field_name,title,desc) \
562         {#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}
563
564 /*
565  * RANGE macros
566  */
567
568 #define UAT_RANGE_CB_DEF(basename,field_name,rec_t) \
569 static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* u1 _U_, const void* u2) {\
570         char* rng = ep_strndup(buf,len);\
571                 range_convert_str(&(((rec_t*)rec)->field_name), rng,GPOINTER_TO_UINT(u2)); \
572         } \
573 static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) {\
574         if ( ((rec_t*)rec)->field_name ) { \
575                 *out_ptr = range_convert_range(((rec_t*)rec)->field_name); \
576                 *out_len = (unsigned)strlen(*out_ptr); \
577         } else { \
578                 *out_ptr = ""; *out_len = 0; } }
579
580
581 #define UAT_FLD_RANGE(basename,field_name,title,max,desc) \
582         {#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_range,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},\
583           {0,0,0},GUINT_TO_POINTER(max),desc,FLDFILL}
584
585 #ifdef __cplusplus
586 }
587 #endif /* __cplusplus */
588
589 #endif /* __UAT_H__ */