diff options
author | Gerald Combs <gerald@wireshark.org> | 2015-10-27 16:24:01 -0700 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2015-10-28 02:40:47 +0000 |
commit | a25c4841d24b5da184afc8ff542a731a94aab2cb (patch) | |
tree | 9373f9e26e83d47670cf1f0079f650d9b9baf23b /epan | |
parent | c7e42be2e5baf0a5f351b126cdac5c3d6d9241a0 (diff) |
Get rid of a couple of UAT macros.
Declare and fill in some functions normally instead of using macros.
Change-Id: I06323ecf53e0fe8ce7299168984838c87209acc5
Reviewed-on: https://code.wireshark.org/review/11336
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r-- | epan/uat.c | 75 | ||||
-rw-r--r-- | epan/uat.h | 39 |
2 files changed, 86 insertions, 28 deletions
diff --git a/epan/uat.c b/epan/uat.c index 73659d57bf..327b8a29bd 100644 --- a/epan/uat.c +++ b/epan/uat.c @@ -747,11 +747,76 @@ char* uat_esc(const char* buf, guint len) { } -CHK_STR_IS_DEF(isprint) -CHK_STR_IS_DEF(isalpha) -CHK_STR_IS_DEF(isalnum) -CHK_STR_IS_DEF(isdigit) -CHK_STR_IS_DEF(isxdigit) +gboolean uat_fld_chk_str_isprint(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) { + guint i; + + for (i = 0; i < len; i++) { + char c = strptr[i]; + if (! g_ascii_isprint(c)) { + *err = g_strdup_printf("invalid char pos=%d value=%.2x",i,c); + return FALSE; + } + } + *err = NULL; + return TRUE; +} + +gboolean uat_fld_chk_str_isalpha(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) { + guint i; + + for (i = 0; i < len; i++) { + char c = strptr[i]; + if (! g_ascii_isalpha(c)) { + *err = g_strdup_printf("invalid char pos=%d value=%.2x",i,c); + return FALSE; + } + } + *err = NULL; + return TRUE; +} + +gboolean uat_fld_chk_str_isalnum(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) { + guint i; + + for (i = 0; i < len; i++) { + char c = strptr[i]; + if (! g_ascii_isalnum(c)) { + *err = g_strdup_printf("invalid char pos=%d value=%.2x",i,c); + return FALSE; + } + } + *err = NULL; + return TRUE; +} + +gboolean uat_fld_chk_str_isdigit(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) { + guint i; + + for (i = 0; i < len; i++) { + char c = strptr[i]; + if (! g_ascii_isdigit(c)) { + *err = g_strdup_printf("invalid char pos=%d value=%.2x",i,c); + return FALSE; + } + } + *err = NULL; + return TRUE; +} + +gboolean uat_fld_chk_str_isxdigit(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) { + guint i; + + for (i = 0; i < len; i++) { + char c = strptr[i]; + if (! g_ascii_isxdigit(c)) { + *err = g_strdup_printf("invalid char pos=%d value=%.2x",i,c); + return FALSE; + } + } + *err = NULL; + return TRUE; +} + /* * Editor modelines diff --git a/epan/uat.h b/epan/uat.h index 14204a5e53..3a87ca85ee 100644 --- a/epan/uat.h +++ b/epan/uat.h @@ -325,9 +325,6 @@ gboolean uat_fld_chk_enum(void*, const char*, unsigned, const void*, const void* WS_DLL_PUBLIC gboolean uat_fld_chk_range(void*, const char*, unsigned, const void*, const void*, char**); -#define CHK_STR_IS_DECL(what) \ -gboolean uat_fld_chk_str_ ## what (void*, const char*, unsigned, const void*, const void*, char**) - typedef void (*uat_cb_t)(void* uat,void* user_data); WS_DLL_PUBLIC void uat_foreach_table(uat_cb_t cb,void* user_data); @@ -338,31 +335,22 @@ 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); -#ifdef __cplusplus -#define UNUSED_PARAMETER(n) -#else -#define UNUSED_PARAMETER(n) n _U_ -#endif - /* Some strings entirely made of ... already declared */ + WS_DLL_PUBLIC -CHK_STR_IS_DECL(isprint); -WS_DLL_PUBLIC -CHK_STR_IS_DECL(isalpha); +gboolean uat_fld_chk_str_isprint(void*, const char*, unsigned, const void*, const void*, char**); + WS_DLL_PUBLIC -CHK_STR_IS_DECL(isalnum); +gboolean uat_fld_chk_str_isalpha(void*, const char*, unsigned, const void*, const void*, char**); + WS_DLL_PUBLIC -CHK_STR_IS_DECL(isdigit); +gboolean uat_fld_chk_str_isalnum(void*, const char*, unsigned, const void*, const void*, char**); + WS_DLL_PUBLIC -CHK_STR_IS_DECL(isxdigit); +gboolean uat_fld_chk_str_isdigit(void*, const char*, unsigned, const void*, const void*, char**); -#define CHK_STR_IS_DEF(what) \ -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) { \ - guint i; for (i=0;i<len;i++) { \ - char c = strptr[i]; \ - if (! g_ascii_ ## what(c)) { \ - *err = g_strdup_printf("invalid char pos=%d value=%.2x",i,c); return FALSE; } } \ - *err = NULL; return TRUE; } +WS_DLL_PUBLIC +gboolean uat_fld_chk_str_isxdigit(void*, const char*, unsigned, const void*, const void*, char**); /* @@ -371,6 +359,12 @@ gboolean uat_fld_chk_str_ ## what (void* UNUSED_PARAMETER(u1), const char* strpt * for those elements in uat_field_t array */ +#ifdef __cplusplus +#define UNUSED_PARAMETER(n) +#else +#define UNUSED_PARAMETER(n) n _U_ +#endif + /* * CSTRING macros, * a simple c-string contained in (((rec_t*)rec)->(field_name)) @@ -505,7 +499,6 @@ static void basename ## _ ## field_name ## _tostr_cb(void* rec, const char** out #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} - /* * ENUM macros * enum_t: name = ((enum_t*)ptr)->strptr |