2007-01-28 10:31:32 +00:00
|
|
|
/*
|
|
|
|
* uat.h
|
|
|
|
*
|
|
|
|
* User Accessible Tables
|
|
|
|
* Mantain an array of user accessible data strucures
|
2008-02-15 22:36:24 +00:00
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
|
2007-01-29 04:47:58 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 2001 Gerald Combs
|
2008-02-15 22:36:24 +00:00
|
|
|
*
|
2007-01-29 04:47:58 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2008-02-15 22:36:24 +00:00
|
|
|
*
|
2007-01-29 04:47:58 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2008-02-15 22:36:24 +00:00
|
|
|
*
|
2007-01-29 04:47:58 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-01-28 10:31:32 +00:00
|
|
|
*/
|
|
|
|
|
2013-07-25 23:49:47 +00:00
|
|
|
#ifndef __UAT_H__
|
|
|
|
#define __UAT_H__
|
2007-01-28 10:31:32 +00:00
|
|
|
|
2013-11-10 15:59:37 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
#include "ws_symbol_export.h"
|
|
|
|
|
2013-07-25 23:49:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
2007-01-28 10:31:32 +00:00
|
|
|
/*
|
|
|
|
* uat mantains a dynamically allocated table accessible to the user
|
|
|
|
* via a file and/or gui tables.
|
|
|
|
*
|
|
|
|
* the file is located either in userdir(when first read or when writen) or
|
|
|
|
* in datadir for defaults (read only , it will be always written to userdir).
|
|
|
|
*
|
|
|
|
* the behaviour of the table is controlled by a series of callbacks
|
|
|
|
* the caller must provide.
|
|
|
|
*
|
2008-02-15 22:36:24 +00:00
|
|
|
* BEWARE that the user can change an uat at (almost) any time,
|
2007-01-28 10:31:32 +00:00
|
|
|
* That is pointers to records in an uat are valid only during the call
|
|
|
|
* to the function that obtains them (do not store them).
|
|
|
|
*
|
|
|
|
* UATs are meant for short tables of user data (passwords and such) there's
|
|
|
|
* no quick access, you must iterate through them each time to fetch the record
|
2014-06-15 16:44:01 +00:00
|
|
|
* you are looking for.
|
2007-01-28 10:31:32 +00:00
|
|
|
*
|
|
|
|
* Only users via gui or editing the file can add/remove records your code cannot.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* obscure data type to handle an uat */
|
2013-12-03 21:35:36 +00:00
|
|
|
typedef struct epan_uat uat_t;
|
2007-01-28 10:31:32 +00:00
|
|
|
/********************************************
|
|
|
|
* Callbacks:
|
|
|
|
* these instruct uat on how to deal with user info and data in records
|
|
|
|
********************************************/
|
|
|
|
|
|
|
|
/********
|
2010-03-04 12:50:18 +00:00
|
|
|
* Callbacks dealing with the entire table
|
|
|
|
********/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Post-Update CB
|
|
|
|
*
|
|
|
|
* to be called after to the table has being edited
|
|
|
|
* Will be called once the user clicks the Apply or OK button
|
|
|
|
* optional
|
|
|
|
*/
|
|
|
|
typedef void (*uat_post_update_cb_t)(void);
|
|
|
|
|
|
|
|
|
|
|
|
/********
|
|
|
|
* Callbacks dealing with records (these deal with entire records)
|
2007-01-28 10:31:32 +00:00
|
|
|
********/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy CB
|
2015-02-18 00:40:28 +00:00
|
|
|
* copy(dest,orig,len)
|
|
|
|
*
|
2007-01-28 10:31:32 +00:00
|
|
|
* used to copy a record
|
|
|
|
* optional, memcpy will be used if not given
|
|
|
|
*/
|
2010-10-29 21:11:33 +00:00
|
|
|
typedef void* (*uat_copy_cb_t)(void*, const void*, size_t);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free CB
|
2015-02-18 00:40:28 +00:00
|
|
|
* free(record)
|
2007-01-28 10:31:32 +00:00
|
|
|
*
|
|
|
|
* destroy a record's child data
|
|
|
|
* (do not free the container, it will be handled by uat)
|
|
|
|
* it is optional, no child data will be freed if no present
|
|
|
|
*/
|
|
|
|
typedef void (*uat_free_cb_t)(void*);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update CB
|
2015-02-18 00:40:28 +00:00
|
|
|
* update(record,&error)
|
2007-01-28 10:31:32 +00:00
|
|
|
*
|
2010-03-04 12:50:18 +00:00
|
|
|
* to be called after any record fields had been updated
|
2007-01-28 10:31:32 +00:00
|
|
|
* optional, record will be updated always if not given
|
2015-02-18 00:40:28 +00:00
|
|
|
* it will return TRUE if OK or else
|
|
|
|
* it will return FALSE and set *error to inform the user on what's
|
|
|
|
* wrong with the given input
|
2015-01-13 20:13:45 +00:00
|
|
|
* The error string must be allocated with g_malloc() or
|
|
|
|
* a routine that calls it.
|
2007-01-28 10:31:32 +00:00
|
|
|
*/
|
2015-02-18 00:40:28 +00:00
|
|
|
typedef gboolean (*uat_update_cb_t)(void *, char**);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*******
|
|
|
|
* Callbacks for single fields (these deal with single values)
|
|
|
|
* the caller should provide one of these for every field!
|
|
|
|
********/
|
|
|
|
|
2008-02-15 22:36:24 +00:00
|
|
|
/*
|
2015-02-18 00:40:28 +00:00
|
|
|
* Check CB
|
|
|
|
* chk(record, ptr, len, chk_data, fld_data, &error)
|
|
|
|
*
|
2007-01-28 10:31:32 +00:00
|
|
|
* given an input string (ptr, len) checks if the value is OK for a field in the record.
|
|
|
|
* it will return TRUE if OK or else
|
2015-02-18 00:40:28 +00:00
|
|
|
* it will return FALSE and set *error to inform the user on what's
|
2007-01-28 10:31:32 +00:00
|
|
|
* wrong with the given input
|
2015-02-18 00:40:28 +00:00
|
|
|
* The error string must be allocated with g_malloc() or
|
|
|
|
* a routine that calls it.
|
2007-01-28 10:31:32 +00:00
|
|
|
* optional, if not given any input is considered OK and the set cb will be called
|
|
|
|
*/
|
2015-01-13 20:13:45 +00:00
|
|
|
typedef gboolean (*uat_fld_chk_cb_t)(void*, const char*, unsigned, const void*, const void*, char**);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set Field CB
|
2015-02-18 00:40:28 +00:00
|
|
|
* set(record, ptr, len, set_data, fld_data)
|
2007-01-28 10:31:32 +00:00
|
|
|
*
|
|
|
|
* given an input string (ptr, len) sets the value of a field in the record,
|
|
|
|
* it is mandatory
|
|
|
|
*/
|
2009-04-20 18:34:06 +00:00
|
|
|
typedef void (*uat_fld_set_cb_t)(void*, const char*, unsigned, const void*, const void*);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
|
|
|
/*
|
2015-02-18 00:40:28 +00:00
|
|
|
* Convert-to-string CB
|
|
|
|
* tostr(record, &out_ptr, &out_len, tostr_data, fld_data)
|
|
|
|
*
|
2007-01-28 10:31:32 +00:00
|
|
|
* given a record returns a string representation of the field
|
|
|
|
* mandatory
|
|
|
|
*/
|
2009-04-20 18:34:06 +00:00
|
|
|
typedef void (*uat_fld_tostr_cb_t)(void*, const char**, unsigned*, const void*, const void*);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
2008-02-15 22:36:24 +00:00
|
|
|
/***********
|
2007-01-28 10:31:32 +00:00
|
|
|
* Text Mode
|
|
|
|
*
|
2010-02-16 20:35:58 +00:00
|
|
|
* used for file and dialog representation of fields in columns,
|
2008-02-15 22:36:24 +00:00
|
|
|
* when the file is read it modifies the way the value is passed back to the fld_set_cb
|
2007-01-28 10:31:32 +00:00
|
|
|
* (see definition bellow for description)
|
|
|
|
***********/
|
|
|
|
|
|
|
|
typedef enum _uat_text_mode_t {
|
|
|
|
PT_TXTMOD_NONE,
|
|
|
|
/* not used */
|
2008-02-15 22:36:24 +00:00
|
|
|
|
2007-01-28 10:31:32 +00:00
|
|
|
PT_TXTMOD_STRING,
|
|
|
|
/*
|
|
|
|
file:
|
|
|
|
reads:
|
|
|
|
,"\x20\x00\x30", as " \00",3
|
|
|
|
,"", as "",0
|
|
|
|
,, as NULL,0
|
|
|
|
writes:
|
|
|
|
,"\x20\x30\x00\x20", for " 0\0 ",4
|
|
|
|
,"", for *, 0
|
|
|
|
,, for NULL, *
|
|
|
|
dialog:
|
|
|
|
accepts \x?? and other escapes
|
|
|
|
gets "",0 on empty string
|
|
|
|
*/
|
|
|
|
PT_TXTMOD_HEXBYTES,
|
|
|
|
/*
|
|
|
|
file:
|
|
|
|
reads:
|
|
|
|
,A1b2C3d4, as "\001\002\003\004",4
|
|
|
|
,, as NULL,0
|
|
|
|
writes:
|
|
|
|
,, on NULL, *
|
|
|
|
,a1b2c3d4, on "\001\002\003\004",4
|
|
|
|
dialog:
|
|
|
|
"a1b2c3d4" as "\001\002\003\004",4
|
|
|
|
"a1 b2:c3d4" as "\001\002\003\004",4
|
|
|
|
"" as NULL,0
|
|
|
|
"invalid" as NULL,3
|
|
|
|
"a1b" as NULL, 1
|
|
|
|
*/
|
2011-09-20 10:14:58 +00:00
|
|
|
PT_TXTMOD_ENUM,
|
|
|
|
|
|
|
|
PT_TXTMOD_FILENAME,
|
|
|
|
/* processed like a PT_TXTMOD_STRING, but shows a filename dialog */
|
2011-11-01 01:23:10 +00:00
|
|
|
PT_TXTMOD_DIRECTORYNAME
|
2011-09-20 10:14:58 +00:00
|
|
|
/* processed like a PT_TXTMOD_STRING, but shows a directory dialog */
|
2007-01-28 10:31:32 +00:00
|
|
|
} uat_text_mode_t;
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
/*
|
|
|
|
* Fields
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
typedef struct _uat_field_t {
|
|
|
|
const char* name;
|
2009-02-16 04:10:06 +00:00
|
|
|
const char* title;
|
2007-02-03 14:25:02 +00:00
|
|
|
uat_text_mode_t mode;
|
2008-02-15 22:36:24 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
struct {
|
|
|
|
uat_fld_chk_cb_t chk;
|
|
|
|
uat_fld_set_cb_t set;
|
|
|
|
uat_fld_tostr_cb_t tostr;
|
|
|
|
} cb;
|
2008-02-15 22:36:24 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
struct {
|
2009-04-20 18:34:06 +00:00
|
|
|
const void* chk;
|
|
|
|
const void* set;
|
|
|
|
const void* tostr;
|
2007-02-03 14:25:02 +00:00
|
|
|
} cbdata;
|
2008-02-15 22:36:24 +00:00
|
|
|
|
2009-04-20 18:34:06 +00:00
|
|
|
const void* fld_data;
|
2008-02-15 22:36:24 +00:00
|
|
|
|
2007-04-23 10:59:26 +00:00
|
|
|
const char* desc;
|
2007-02-03 14:25:02 +00:00
|
|
|
struct _fld_data_t* priv;
|
|
|
|
} uat_field_t;
|
|
|
|
|
|
|
|
#define FLDFILL NULL
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_END_FIELDS {NULL,NULL,PT_TXTMOD_NONE,{0,0,0},{0,0,0},0,0,FLDFILL}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
UATs could be put into "categories". The categories were defined only
implicitly by the #define name and string they were defined to; not all
UATs neatly fit into any of the categories, so some of them were put
into categories that weren't obviously correct for them, and one - the
display filter macro UAT - wasn't put into any category at all (which
caused crashes when editing them, as the GUI code that handled UAT
changes from a dialog assumed the category field was non-null).
The category was, in practice, used only to decide, in the
aforementioned GUI code, whether the packet summary pane needed to be
updated or not. It also offered no option of "don't update the packet
summary pane *and* don't redissect anything", which is what would be
appropriate for the display filter macro UAT.
Replace the category with a set of fields indicating what the UAT
affects; we currently offer "dissection", which applies to most UATs
(any UAT in libwireshark presumably affects dissection at a minimum) and
"the set of named fields that exist". Changing any UAT that affects
dissection requires a redissection; changing any UAT that affects the
set of named fields that exist requires a redissection *and* rebuilding
the packet summary pane.
Perhaps we also need "filtering", so that if you change a display filter
macro, we re-filter, in case the display is currently filtered with a
display filter that uses a macro that changed.
svn path=/trunk/; revision=43603
2012-07-08 01:00:46 +00:00
|
|
|
/*
|
|
|
|
* Flags to indicate what the settings in this UAT affect.
|
|
|
|
* This is used when UATs are changed interactively, to indicate what needs
|
|
|
|
* to be redone when the UAT is changed.
|
|
|
|
*/
|
|
|
|
#define UAT_AFFECTS_DISSECTION 0x00000001 /* affects packet dissection */
|
|
|
|
#define UAT_AFFECTS_FIELDS 0x00000002 /* affects what named fields exist */
|
2007-01-28 10:31:32 +00:00
|
|
|
|
2008-02-15 22:36:24 +00:00
|
|
|
/** Create a new uat
|
2007-01-28 10:31:32 +00:00
|
|
|
*
|
2008-02-15 22:36:24 +00:00
|
|
|
* @param name The name of the table
|
|
|
|
* @param size The size of the structure
|
|
|
|
* @param filename The filename to be used (either in userdir or datadir)
|
2012-05-03 15:31:45 +00:00
|
|
|
* @param from_profile TRUE if profile directory to be used
|
2014-01-30 17:43:52 +00:00
|
|
|
* @param data_ptr Although a void*, this is really a pointer to a null terminated array of pointers to the data
|
2013-08-10 21:28:25 +00:00
|
|
|
* @param num_items_ptr A pointer with number of items
|
UATs could be put into "categories". The categories were defined only
implicitly by the #define name and string they were defined to; not all
UATs neatly fit into any of the categories, so some of them were put
into categories that weren't obviously correct for them, and one - the
display filter macro UAT - wasn't put into any category at all (which
caused crashes when editing them, as the GUI code that handled UAT
changes from a dialog assumed the category field was non-null).
The category was, in practice, used only to decide, in the
aforementioned GUI code, whether the packet summary pane needed to be
updated or not. It also offered no option of "don't update the packet
summary pane *and* don't redissect anything", which is what would be
appropriate for the display filter macro UAT.
Replace the category with a set of fields indicating what the UAT
affects; we currently offer "dissection", which applies to most UATs
(any UAT in libwireshark presumably affects dissection at a minimum) and
"the set of named fields that exist". Changing any UAT that affects
dissection requires a redissection; changing any UAT that affects the
set of named fields that exist requires a redissection *and* rebuilding
the packet summary pane.
Perhaps we also need "filtering", so that if you change a display filter
macro, we re-filter, in case the display is currently filtered with a
display filter that uses a macro that changed.
svn path=/trunk/; revision=43603
2012-07-08 01:00:46 +00:00
|
|
|
* @param flags flags indicating what this UAT affects
|
2010-02-16 20:35:58 +00:00
|
|
|
* @param help A pointer to help text
|
2008-02-15 22:36:24 +00:00
|
|
|
* @param copy_cb A function that copies the data in the struct
|
|
|
|
* @param update_cb Will be called when a record is updated
|
|
|
|
* @param free_cb Will be called to destroy a struct in the dataset
|
2010-03-04 12:50:18 +00:00
|
|
|
* @param post_update_cb Will be called once the user clicks the Apply or OK button
|
2010-02-16 20:35:58 +00:00
|
|
|
* @param flds_array A pointer to an array of uat_field_t structs
|
2007-01-28 10:31:32 +00:00
|
|
|
*
|
2008-02-15 22:36:24 +00:00
|
|
|
* @return A freshly-allocated and populated uat_t struct.
|
2007-01-28 10:31:32 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-01-28 10:31:32 +00:00
|
|
|
uat_t* uat_new(const char* name,
|
|
|
|
size_t size,
|
2007-04-23 10:59:26 +00:00
|
|
|
const char* filename,
|
2008-03-06 22:13:24 +00:00
|
|
|
gboolean from_profile,
|
2014-01-30 17:43:52 +00:00
|
|
|
void* data_ptr,
|
2010-02-16 20:35:58 +00:00
|
|
|
guint* num_items_ptr,
|
UATs could be put into "categories". The categories were defined only
implicitly by the #define name and string they were defined to; not all
UATs neatly fit into any of the categories, so some of them were put
into categories that weren't obviously correct for them, and one - the
display filter macro UAT - wasn't put into any category at all (which
caused crashes when editing them, as the GUI code that handled UAT
changes from a dialog assumed the category field was non-null).
The category was, in practice, used only to decide, in the
aforementioned GUI code, whether the packet summary pane needed to be
updated or not. It also offered no option of "don't update the packet
summary pane *and* don't redissect anything", which is what would be
appropriate for the display filter macro UAT.
Replace the category with a set of fields indicating what the UAT
affects; we currently offer "dissection", which applies to most UATs
(any UAT in libwireshark presumably affects dissection at a minimum) and
"the set of named fields that exist". Changing any UAT that affects
dissection requires a redissection; changing any UAT that affects the
set of named fields that exist requires a redissection *and* rebuilding
the packet summary pane.
Perhaps we also need "filtering", so that if you change a display filter
macro, we re-filter, in case the display is currently filtered with a
display filter that uses a macro that changed.
svn path=/trunk/; revision=43603
2012-07-08 01:00:46 +00:00
|
|
|
guint flags,
|
2007-04-23 10:59:26 +00:00
|
|
|
const char* help,
|
2007-01-28 10:31:32 +00:00
|
|
|
uat_copy_cb_t copy_cb,
|
|
|
|
uat_update_cb_t update_cb,
|
|
|
|
uat_free_cb_t free_cb,
|
2010-03-04 12:50:18 +00:00
|
|
|
uat_post_update_cb_t post_update_cb,
|
2007-02-03 14:25:02 +00:00
|
|
|
uat_field_t* flds_array);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
2008-02-15 22:36:24 +00:00
|
|
|
/** Populate a uat using its file.
|
|
|
|
*
|
|
|
|
* @param uat_in Pointer to a uat. Must not be NULL.
|
|
|
|
* @param err Upon failure, points to an error string.
|
|
|
|
*
|
|
|
|
* @return TRUE on success, FALSE on failure.
|
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2015-01-10 00:50:09 +00:00
|
|
|
gboolean uat_load(uat_t* uat_in, char** err);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
2008-02-15 22:36:24 +00:00
|
|
|
/** Create or update a single uat entry using a string.
|
|
|
|
*
|
|
|
|
* @param uat_in Pointer to a uat. Must not be NULL.
|
|
|
|
* @param entry The string representation of the entry. Format must match
|
|
|
|
* what's written to the uat's output file.
|
|
|
|
* @param err Upon failure, points to an error string.
|
|
|
|
*
|
|
|
|
* @return TRUE on success, FALSE on failure.
|
|
|
|
*/
|
|
|
|
gboolean uat_load_str(uat_t* uat_in, char* entry, char** err);
|
|
|
|
|
|
|
|
/** Given a uat name or filename, find its pointer.
|
|
|
|
*
|
|
|
|
* @param name The name or filename of the uat
|
|
|
|
*
|
|
|
|
* @return A pointer to the uat on success, NULL on failure.
|
|
|
|
*/
|
|
|
|
uat_t *uat_find(gchar *name);
|
|
|
|
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2008-01-30 22:50:55 +00:00
|
|
|
uat_t* uat_get_table_by_name(const char* name);
|
2007-01-28 10:31:32 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
/*
|
2008-02-15 22:36:24 +00:00
|
|
|
* Some common uat_fld_chk_cbs
|
2007-02-03 14:25:02 +00:00
|
|
|
*/
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_str(void*, const char*, unsigned, const void*, const void*, char** err);
|
|
|
|
gboolean uat_fld_chk_oid(void*, const char*, unsigned, const void*, const void*, char** err);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_proto(void*, const char*, unsigned, const void*, const void*, char** err);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_num_dec(void*, const char*, unsigned, const void*, const void*, char** err);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_num_hex(void*, const char*, unsigned, const void*, const void*, char** err);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_enum(void*, const char*, unsigned, const void*, const void*, char**);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_range(void*, const char*, unsigned, const void*, const void*, char**);
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
#define CHK_STR_IS_DECL(what) \
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_str_ ## what (void*, const char*, unsigned, const void*, const void*, char**)
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2007-02-08 10:15:04 +00:00
|
|
|
typedef void (*uat_cb_t)(void* uat,void* user_data);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-02-08 10:15:04 +00:00
|
|
|
void uat_foreach_table(uat_cb_t cb,void* user_data);
|
2008-01-19 01:18:35 +00:00
|
|
|
void uat_unload_all(void);
|
2007-02-08 10:15:04 +00:00
|
|
|
|
2007-04-01 16:02:41 +00:00
|
|
|
char* uat_undquote(const char* si, guint in_len, guint* len_p);
|
|
|
|
char* uat_unbinstring(const char* si, guint in_len, guint* len_p);
|
|
|
|
char* uat_unesc(const char* si, guint in_len, guint* len_p);
|
|
|
|
char* uat_esc(const char* buf, guint len);
|
|
|
|
|
2014-09-06 20:08:40 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
#define UNUSED_PARAMETER(n)
|
|
|
|
#else
|
|
|
|
#define UNUSED_PARAMETER(n) n _U_
|
|
|
|
#endif
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
/* Some strings entirely made of ... already declared */
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-02-03 14:25:02 +00:00
|
|
|
CHK_STR_IS_DECL(isprint);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-02-03 14:25:02 +00:00
|
|
|
CHK_STR_IS_DECL(isalpha);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-02-03 14:25:02 +00:00
|
|
|
CHK_STR_IS_DECL(isalnum);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-02-03 14:25:02 +00:00
|
|
|
CHK_STR_IS_DECL(isdigit);
|
2013-03-01 23:53:11 +00:00
|
|
|
WS_DLL_PUBLIC
|
2007-02-03 14:25:02 +00:00
|
|
|
CHK_STR_IS_DECL(isxdigit);
|
|
|
|
|
|
|
|
#define CHK_STR_IS_DEF(what) \
|
2015-01-13 20:13:45 +00:00
|
|
|
gboolean uat_fld_chk_str_ ## what (void* UNUSED_PARAMETER(u1), const char* strptr, guint len, const void* UNUSED_PARAMETER(u2), const void* UNUSED_PARAMETER(u3), char** err) { \
|
2007-02-03 14:25:02 +00:00
|
|
|
guint i; for (i=0;i<len;i++) { \
|
|
|
|
char c = strptr[i]; \
|
2014-10-17 23:10:53 +00:00
|
|
|
if (! g_ascii_ ## what(c)) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*err = g_strdup_printf("invalid char pos=%d value=%.2x",i,c); return FALSE; } } \
|
2007-02-03 14:25:02 +00:00
|
|
|
*err = NULL; return TRUE; }
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros
|
|
|
|
* to define basic uat_fld_set_cbs, uat_fld_tostr_cbs
|
|
|
|
* for those elements in uat_field_t array
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* CSTRING macros,
|
|
|
|
* a simple c-string contained in (((rec_t*)rec)->(field_name))
|
|
|
|
*/
|
|
|
|
#define UAT_CSTRING_CB_DEF(basename,field_name,rec_t) \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2008-08-05 11:16:24 +00:00
|
|
|
char* new_buf = g_strndup(buf,len); \
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free((((rec_t*)rec)->field_name)); \
|
2008-08-05 11:16:24 +00:00
|
|
|
(((rec_t*)rec)->field_name) = new_buf; } \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2007-02-03 14:25:02 +00:00
|
|
|
if (((rec_t*)rec)->field_name ) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
|
2009-03-16 06:11:30 +00:00
|
|
|
*out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
|
2007-02-03 14:25:02 +00:00
|
|
|
} else { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup(""); *out_len = 0; } }
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_CSTRING(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_CSTRING_ISPRINT(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_CSTRING_OTHER(basename,field_name,title,chk,desc) \
|
|
|
|
{#field_name, title, PT_TXTMOD_STRING,{ chk ,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
|
|
|
|
|
|
|
|
/*
|
2011-09-20 10:14:58 +00:00
|
|
|
* FILENAME and DIRECTORYNAME,
|
|
|
|
* a simple c-string contained in (((rec_t*)rec)->(field_name))
|
2009-02-16 04:10:06 +00:00
|
|
|
*/
|
2011-09-20 10:14:58 +00:00
|
|
|
#define UAT_FILENAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
|
|
|
|
|
|
|
|
#define UAT_FLD_FILENAME(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
|
|
|
|
|
|
|
#define UAT_FLD_FILENAME_OTHER(basename,field_name,title,chk,desc) \
|
|
|
|
{#field_name, title, PT_TXTMOD_FILENAME,{chk,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
|
|
|
|
|
|
|
|
#define UAT_DIRECTORYNAME_CB_DEF(basename,field_name,rec_t) UAT_CSTRING_CB_DEF(basename,field_name,rec_t)
|
|
|
|
|
|
|
|
#define UAT_FLD_DIRECTORYNAME(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2010-06-28 09:30:15 +00:00
|
|
|
/*
|
2011-11-01 01:23:10 +00:00
|
|
|
* OID - just a CSTRING with a specific check routine
|
2010-06-28 09:30:15 +00:00
|
|
|
*/
|
|
|
|
#define UAT_FLD_OID(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
|
|
|
|
|
|
|
|
2007-02-07 03:39:40 +00:00
|
|
|
/*
|
|
|
|
* LSTRING MACROS
|
|
|
|
*/
|
|
|
|
#define UAT_LSTRING_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2008-08-05 20:38:22 +00:00
|
|
|
char* new_val = uat_unesc(buf,len,&(((rec_t*)rec)->len_element)); \
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free((((rec_t*)rec)->ptr_element)); \
|
2008-08-05 11:16:24 +00:00
|
|
|
(((rec_t*)rec)->ptr_element) = new_val; }\
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2007-02-07 03:39:40 +00:00
|
|
|
if (((rec_t*)rec)->ptr_element ) { \
|
2007-04-01 14:55:25 +00:00
|
|
|
*out_ptr = uat_esc(((rec_t*)rec)->ptr_element, (((rec_t*)rec)->len_element)); \
|
2009-03-16 06:11:30 +00:00
|
|
|
*out_len = (unsigned)strlen(*out_ptr); \
|
2007-02-07 03:39:40 +00:00
|
|
|
} else { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup(""); \
|
|
|
|
*out_len = 0; \
|
|
|
|
} \
|
|
|
|
}
|
2007-02-07 03:39:40 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_LSTRING(basename,field_name,title, desc) \
|
|
|
|
{#field_name, title, PT_TXTMOD_STRING,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
|
2007-02-07 03:39:40 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* BUFFER macros,
|
|
|
|
* a buffer_ptr contained in (((rec_t*)rec)->(field_name))
|
|
|
|
* and its len in (((rec_t*)rec)->(len_name))
|
2008-08-05 11:16:24 +00:00
|
|
|
* XXX: UNTESTED and probably BROKEN
|
2007-02-03 14:25:02 +00:00
|
|
|
*/
|
2007-02-07 03:39:40 +00:00
|
|
|
#define UAT_BUFFER_CB_DEF(basename,field_name,rec_t,ptr_element,len_element) \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2013-02-17 22:15:16 +00:00
|
|
|
char* new_buf = len ? (char *)g_memdup(buf,len) : NULL; \
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free((((rec_t*)rec)->ptr_element)); \
|
|
|
|
(((rec_t*)rec)->ptr_element) = new_buf; \
|
|
|
|
(((rec_t*)rec)->len_element) = len; } \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = ((rec_t*)rec)->ptr_element ? (const char*)g_memdup(((rec_t*)rec)->ptr_element,((rec_t*)rec)->len_element) : g_strdup(""); \
|
2007-02-07 03:39:40 +00:00
|
|
|
*out_len = ((rec_t*)rec)->len_element; }
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_BUFFER(basename,field_name,title,desc) \
|
|
|
|
{#field_name, title, PT_TXTMOD_HEXBYTES,{0,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DEC Macros,
|
2008-02-15 22:36:24 +00:00
|
|
|
* a decimal number contained in
|
2007-02-03 14:25:02 +00:00
|
|
|
*/
|
|
|
|
#define UAT_DEC_CB_DEF(basename,field_name,rec_t) \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2015-01-10 00:50:09 +00:00
|
|
|
char* tmp_str = g_strndup(buf,len); \
|
|
|
|
((rec_t*)rec)->field_name = (guint)strtol(tmp_str,NULL,10); \
|
|
|
|
g_free(tmp_str); } \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup_printf("%d",((rec_t*)rec)->field_name); \
|
2009-03-16 06:11:30 +00:00
|
|
|
*out_len = (unsigned)strlen(*out_ptr); }
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_DEC(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2013-12-10 15:33:07 +00:00
|
|
|
#define UAT_FLD_NONE(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* HEX Macros,
|
2008-02-15 22:36:24 +00:00
|
|
|
* an hexadecimal number contained in
|
2007-02-03 14:25:02 +00:00
|
|
|
*/
|
|
|
|
#define UAT_HEX_CB_DEF(basename,field_name,rec_t) \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2015-01-10 00:50:09 +00:00
|
|
|
char* tmp_str = g_strndup(buf,len); \
|
|
|
|
((rec_t*)rec)->field_name = (guint)strtol(tmp_str,NULL,16); \
|
|
|
|
g_free(tmp_str); } \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup_printf("%x",((rec_t*)rec)->field_name); \
|
2009-03-16 06:11:30 +00:00
|
|
|
*out_len = (unsigned)strlen(*out_ptr); }
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_HEX(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ENUM macros
|
2008-02-15 22:36:24 +00:00
|
|
|
* enum_t: name = ((enum_t*)ptr)->strptr
|
|
|
|
* value = ((enum_t*)ptr)->value
|
2007-02-03 14:25:02 +00:00
|
|
|
* rec_t:
|
|
|
|
* value
|
|
|
|
*/
|
2013-03-12 06:40:13 +00:00
|
|
|
#define UAT_VS_DEF(basename,field_name,rec_t,default_t,default_val,default_str) \
|
2014-09-06 20:08:40 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
|
2007-02-07 18:56:07 +00:00
|
|
|
guint i; \
|
2015-01-10 00:50:09 +00:00
|
|
|
char* str = g_strndup(buf,len); \
|
|
|
|
const char* cstr; \
|
|
|
|
((rec_t*)rec)->field_name = default_val; \
|
2013-12-08 23:16:06 +00:00
|
|
|
for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
|
2007-02-07 03:39:40 +00:00
|
|
|
if (g_str_equal(cstr,str)) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
((rec_t*)rec)->field_name = (default_t)((const value_string*)vs)[i].value; \
|
|
|
|
g_free(str); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
g_free(str); } \
|
2014-09-06 20:08:40 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
|
2007-02-07 03:39:40 +00:00
|
|
|
guint i; \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup(default_str); \
|
2009-03-16 06:11:30 +00:00
|
|
|
*out_len = (unsigned)strlen(default_str);\
|
2013-12-08 23:16:06 +00:00
|
|
|
for(i=0;((const value_string*)vs)[i].strptr;i++) { \
|
|
|
|
if ( ((const value_string*)vs)[i].value == ((rec_t*)rec)->field_name ) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
g_free((char*)*out_ptr); \
|
|
|
|
*out_ptr = g_strdup(((const value_string*)vs)[i].strptr); \
|
|
|
|
*out_len = (unsigned)strlen(*out_ptr); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} } \
|
2007-02-07 03:39:40 +00:00
|
|
|
|
2010-06-28 09:30:15 +00:00
|
|
|
#define UAT_VS_CSTRING_DEF(basename,field_name,rec_t,default_val,default_str) \
|
2014-09-06 20:08:40 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* vs, const void* UNUSED_PARAMETER(u2)) {\
|
2010-06-28 09:30:15 +00:00
|
|
|
guint i; \
|
2015-01-10 00:50:09 +00:00
|
|
|
char* str = g_strndup(buf,len); \
|
|
|
|
const char* cstr; \
|
|
|
|
((rec_t*)rec)->field_name = default_val; \
|
2013-12-08 23:16:06 +00:00
|
|
|
for(i=0; ( cstr = ((const value_string*)vs)[i].strptr ) ;i++) { \
|
2010-06-28 09:30:15 +00:00
|
|
|
if (g_str_equal(cstr,str)) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
((rec_t*)rec)->field_name = g_strdup(((const value_string*)vs)[i].strptr); \
|
|
|
|
g_free(str); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
g_free(str);} \
|
2014-09-06 20:08:40 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(vs), const void* UNUSED_PARAMETER(u2)) {\
|
2010-06-28 09:30:15 +00:00
|
|
|
if (((rec_t*)rec)->field_name ) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
|
2010-06-28 09:30:15 +00:00
|
|
|
*out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
|
|
|
|
} else { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup(""); *out_len = 0; } }
|
2007-02-07 03:39:40 +00:00
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_VS(basename,field_name,title,enum,desc) \
|
|
|
|
{#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}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
|
2007-02-07 18:56:07 +00:00
|
|
|
/*
|
|
|
|
* PROTO macros
|
|
|
|
*/
|
|
|
|
|
2007-05-25 16:47:22 +00:00
|
|
|
#define UAT_PROTO_DEF(basename, field_name, dissector_field, name_field, rec_t) \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2007-02-07 18:56:07 +00:00
|
|
|
if (len) { \
|
2012-01-25 23:03:33 +00:00
|
|
|
gchar *tmp = g_strndup(buf,len); \
|
|
|
|
((rec_t*)rec)->name_field = g_ascii_strdown(tmp, -1); \
|
|
|
|
g_free(tmp); \
|
|
|
|
g_strchug(((rec_t*)rec)->name_field); \
|
2007-05-25 16:47:22 +00:00
|
|
|
((rec_t*)rec)->dissector_field = find_dissector(((rec_t*)rec)->name_field); \
|
|
|
|
} else { \
|
|
|
|
((rec_t*)rec)->dissector_field = find_dissector("data"); \
|
|
|
|
((rec_t*)rec)->name_field = NULL; \
|
|
|
|
} } \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2007-05-25 16:47:22 +00:00
|
|
|
if ( ((rec_t*)rec)->name_field ) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup((((rec_t*)rec)->name_field)); \
|
2009-03-16 06:11:30 +00:00
|
|
|
*out_len = (unsigned)strlen(*out_ptr); \
|
2007-02-07 20:45:14 +00:00
|
|
|
} else { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup(""); *out_len = 0; } }
|
2007-02-03 14:25:02 +00:00
|
|
|
|
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_PROTO(basename,field_name,title,desc) \
|
|
|
|
{#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}
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2007-04-03 19:08:00 +00:00
|
|
|
/*
|
|
|
|
* RANGE macros
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define UAT_RANGE_CB_DEF(basename,field_name,rec_t) \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, guint len, const void* UNUSED_PARAMETER(u1), const void* u2) {\
|
2015-01-10 00:50:09 +00:00
|
|
|
char* rng = g_strndup(buf,len);\
|
2007-04-03 19:08:00 +00:00
|
|
|
range_convert_str(&(((rec_t*)rec)->field_name), rng,GPOINTER_TO_UINT(u2)); \
|
2015-01-10 00:50:09 +00:00
|
|
|
g_free(rng); \
|
2007-04-03 19:08:00 +00:00
|
|
|
} \
|
2014-09-06 22:36:44 +00:00
|
|
|
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* UNUSED_PARAMETER(u1), const void* UNUSED_PARAMETER(u2)) {\
|
2007-04-03 19:08:00 +00:00
|
|
|
if ( ((rec_t*)rec)->field_name ) { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = range_convert_range(NULL, ((rec_t*)rec)->field_name); \
|
2009-03-16 06:11:30 +00:00
|
|
|
*out_len = (unsigned)strlen(*out_ptr); \
|
2007-04-03 19:08:00 +00:00
|
|
|
} else { \
|
2015-01-10 00:50:09 +00:00
|
|
|
*out_ptr = g_strdup(""); *out_len = 0; } }
|
2007-04-03 19:08:00 +00:00
|
|
|
|
|
|
|
|
2009-02-16 04:10:06 +00:00
|
|
|
#define UAT_FLD_RANGE(basename,field_name,title,max,desc) \
|
|
|
|
{#field_name, title, PT_TXTMOD_STRING,{uat_fld_chk_range,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},\
|
2010-10-30 17:51:20 +00:00
|
|
|
{0,0,0},GUINT_TO_POINTER(max),desc,FLDFILL}
|
2007-04-03 19:08:00 +00:00
|
|
|
|
2013-07-25 23:49:47 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif /* __cplusplus */
|
|
|
|
|
|
|
|
#endif /* __UAT_H__ */
|