Introduce an Object Identifier field macro, together with an appropriate field
check routine. Also, a field type which is an enumerated string value. svn path=/trunk/; revision=33343
This commit is contained in:
parent
0d9ad5016e
commit
812274918a
25
epan/uat.c
25
epan/uat.c
|
@ -398,6 +398,31 @@ gboolean uat_fld_chk_str(void* u1 _U_, const char* strptr, unsigned len _U_, con
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean uat_fld_chk_oid(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, const char** err) {
|
||||
unsigned int i;
|
||||
*err = NULL;
|
||||
|
||||
if (strptr == NULL) {
|
||||
*err = "NULL pointer";
|
||||
}
|
||||
|
||||
for(i = 0; i < len; i++)
|
||||
if(!(isdigit(strptr[i]) || strptr[i] == '.')) {
|
||||
*err = "Only digits [0-9] and \".\" allowed in an OID";
|
||||
break;
|
||||
}
|
||||
|
||||
if(strptr[len-1] == '.')
|
||||
*err = "OIDs must not be terminated with a \".\"";
|
||||
|
||||
if(!((*strptr == '0' || *strptr == '1' || *strptr =='2') && (len > 1 && strptr[1] == '.')))
|
||||
*err = "OIDs must start with \"0.\" (ITU-T assigned), \"1.\" (ISO assigned) or \"2.\" (joint ISO/ITU-T assigned)";
|
||||
|
||||
/* should also check that the second arc is in the range 0-39 */
|
||||
|
||||
return *err == NULL;
|
||||
}
|
||||
|
||||
gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, const char** err) {
|
||||
if (len) {
|
||||
char* name = ep_strndup(strptr,len);
|
||||
|
|
23
epan/uat.h
23
epan/uat.h
|
@ -297,6 +297,7 @@ uat_t* uat_get_table_by_name(const char* name);
|
|||
* Some common uat_fld_chk_cbs
|
||||
*/
|
||||
gboolean uat_fld_chk_str(void*, const char*, unsigned, const void*, const void*, const char** err);
|
||||
gboolean uat_fld_chk_oid(void*, const char*, unsigned, const void*, const void*, const char** err);
|
||||
gboolean uat_fld_chk_proto(void*, const char*, unsigned, const void*, const void*, const char** err);
|
||||
gboolean uat_fld_chk_num_dec(void*, const char*, unsigned, const void*, const void*, const char** err);
|
||||
gboolean uat_fld_chk_num_hex(void*, const char*, unsigned, const void*, const void*, const char** err);
|
||||
|
@ -369,6 +370,14 @@ static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out
|
|||
#define UAT_FLD_PATHNAME(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}
|
||||
|
||||
/*
|
||||
* OID - just a CSTRING with a specific check routine
|
||||
*
|
||||
*/
|
||||
#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}
|
||||
|
||||
|
||||
/*
|
||||
* LSTRING MACROS
|
||||
*/
|
||||
|
@ -462,6 +471,20 @@ static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out
|
|||
*out_ptr = ep_strdup(((value_string*)vs)[i].strptr); \
|
||||
*out_len = (unsigned)strlen(*out_ptr); return; } } }
|
||||
|
||||
#define UAT_VS_CSTRING_DEF(basename,field_name,rec_t,default_val,default_str) \
|
||||
static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* vs, const void* u2 _U_) {\
|
||||
guint i; \
|
||||
char* str = ep_strndup(buf,len); \
|
||||
const char* cstr; ((rec_t*)rec)->field_name = default_val; \
|
||||
for(i=0; ( cstr = ((value_string*)vs)[i].strptr ) ;i++) { \
|
||||
if (g_str_equal(cstr,str)) { \
|
||||
((rec_t*)rec)->field_name = g_strdup(((value_string*)vs)[i].strptr); return; } } } \
|
||||
static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out_ptr, unsigned* out_len, const void* vs _U_, const void* u2 _U_) {\
|
||||
if (((rec_t*)rec)->field_name ) { \
|
||||
*out_ptr = (((rec_t*)rec)->field_name); \
|
||||
*out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
|
||||
} else { \
|
||||
*out_ptr = ""; *out_len = 0; } }
|
||||
|
||||
#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}
|
||||
|
|
Loading…
Reference in New Issue