aboutsummaryrefslogtreecommitdiffstats
path: root/epan/uat.c
diff options
context:
space:
mode:
Diffstat (limited to 'epan/uat.c')
-rw-r--r--epan/uat.c363
1 files changed, 189 insertions, 174 deletions
diff --git a/epan/uat.c b/epan/uat.c
index 6bce2cbc33..6fca2badda 100644
--- a/epan/uat.c
+++ b/epan/uat.c
@@ -43,10 +43,10 @@ static GPtrArray* all_uats = NULL;
uat_t* uat_new(const char* name,
size_t size,
const char* filename,
- gboolean from_profile,
+ bool from_profile,
void* data_ptr,
- guint* numitems_ptr,
- guint flags,
+ unsigned* numitems_ptr,
+ unsigned flags,
const char* help,
uat_copy_cb_t copy_cb,
uat_update_cb_t update_cb,
@@ -56,7 +56,7 @@ uat_t* uat_new(const char* name,
uat_field_t* flds_array) {
/* Create new uat */
uat_t* uat = g_new(uat_t, 1);
- guint i;
+ unsigned i;
/* Add to global array of uats */
if (!all_uats)
@@ -85,12 +85,12 @@ uat_t* uat_new(const char* name,
uat->post_update_cb = post_update_cb;
uat->reset_cb = reset_cb;
uat->fields = flds_array;
- uat->user_data = g_array_new(FALSE,FALSE,(guint)uat->record_size);
- uat->raw_data = g_array_new(FALSE,FALSE,(guint)uat->record_size);
- uat->valid_data = g_array_new(FALSE,FALSE,sizeof(gboolean));
- uat->changed = FALSE;
- uat->loaded = FALSE;
- uat->from_global = FALSE;
+ uat->default_values = NULL;
+ uat->user_data = g_array_new(false,FALSE,(unsigned)uat->record_size);
+ uat->raw_data = g_array_new(false,FALSE,(unsigned)uat->record_size);
+ uat->valid_data = g_array_new(false,FALSE,sizeof(bool));
+ uat->changed = false;
+ uat->loaded = false;
uat->rep = NULL;
uat->free_rep = NULL;
uat->help = g_strdup(help);
@@ -114,9 +114,9 @@ uat_t* uat_new(const char* name,
return uat;
}
-void* uat_add_record(uat_t* uat, const void* data, gboolean valid_rec) {
+void* uat_add_record(uat_t* uat, const void* data, bool valid_rec) {
void* rec;
- gboolean* valid;
+ bool* valid;
uat_insert_record_idx(uat, uat->raw_data->len, data);
@@ -132,7 +132,7 @@ void* uat_add_record(uat_t* uat, const void* data, gboolean valid_rec) {
UAT_UPDATE(uat);
- valid = &g_array_index(uat->valid_data, gboolean, uat->valid_data->len-1);
+ valid = &g_array_index(uat->valid_data, bool, uat->valid_data->len-1);
*valid = valid_rec;
} else {
rec = NULL;
@@ -142,9 +142,9 @@ void* uat_add_record(uat_t* uat, const void* data, gboolean valid_rec) {
}
/* Updates the validity of a record. */
-void uat_update_record(uat_t *uat, const void *record, gboolean valid_rec) {
- guint pos;
- gboolean *valid;
+void uat_update_record(uat_t *uat, const void *record, bool valid_rec) {
+ unsigned pos;
+ bool *valid;
/* Locate internal UAT data pointer. */
for (pos = 0; pos < uat->raw_data->len; pos++) {
@@ -157,14 +157,14 @@ void uat_update_record(uat_t *uat, const void *record, gboolean valid_rec) {
ws_assert_not_reached();
}
- valid = &g_array_index(uat->valid_data, gboolean, pos);
+ valid = &g_array_index(uat->valid_data, bool, pos);
*valid = valid_rec;
}
-void uat_swap(uat_t* uat, guint a, guint b) {
+void uat_swap(uat_t* uat, unsigned a, unsigned b) {
size_t s = uat->record_size;
void* tmp;
- gboolean tmp_bool;
+ bool tmp_bool;
ws_assert( a < uat->raw_data->len && b < uat->raw_data->len );
@@ -176,14 +176,14 @@ void uat_swap(uat_t* uat, guint a, guint b) {
memcpy(UAT_INDEX_PTR(uat,b), tmp, s);
g_free(tmp);
- tmp_bool = *(gboolean*)(uat->valid_data->data + (sizeof(gboolean) * (a)));
- *(gboolean*)(uat->valid_data->data + (sizeof(gboolean) * (a))) = *(gboolean*)(uat->valid_data->data + (sizeof(gboolean) * (b)));
- *(gboolean*)(uat->valid_data->data + (sizeof(gboolean) * (b))) = tmp_bool;
+ tmp_bool = *(bool*)(uat->valid_data->data + (sizeof(bool) * (a)));
+ *(bool*)(uat->valid_data->data + (sizeof(bool) * (a))) = *(bool*)(uat->valid_data->data + (sizeof(bool) * (b)));
+ *(bool*)(uat->valid_data->data + (sizeof(bool) * (b))) = tmp_bool;
}
-void uat_insert_record_idx(uat_t* uat, guint idx, const void *src_record) {
+void uat_insert_record_idx(uat_t* uat, unsigned idx, const void *src_record) {
/* Allow insert before an existing item or append after the last item. */
ws_assert( idx <= uat->raw_data->len );
@@ -198,11 +198,11 @@ void uat_insert_record_idx(uat_t* uat, guint idx, const void *src_record) {
/* Initially assume that the record is invalid, it is not copied to the
* user-visible records list. */
- gboolean valid_rec = FALSE;
+ bool valid_rec = false;
g_array_insert_val(uat->valid_data, idx, valid_rec);
}
-void uat_remove_record_idx(uat_t* uat, guint idx) {
+void uat_remove_record_idx(uat_t* uat, unsigned idx) {
ws_assert( idx < uat->raw_data->len );
@@ -214,10 +214,10 @@ void uat_remove_record_idx(uat_t* uat, guint idx) {
g_array_remove_index(uat->valid_data, idx);
}
-void uat_move_index(uat_t * uat, guint old_idx, guint new_idx)
+void uat_move_index(uat_t * uat, unsigned old_idx, unsigned new_idx)
{
- guint dir = 1;
- guint start = old_idx;
+ unsigned dir = 1;
+ unsigned start = old_idx;
if ( old_idx > new_idx )
dir = -1;
@@ -229,15 +229,12 @@ void uat_move_index(uat_t * uat, guint old_idx, guint new_idx)
}
/* The returned filename was g_malloc()'d so the caller must free it */
-gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing) {
- gchar *pers_fname = NULL;
-
- if (! uat->from_global) {
- pers_fname = get_persconffile_path(uat->filename, uat->from_profile);
- }
+char* uat_get_actual_filename(uat_t* uat, bool for_writing) {
+ char *pers_fname = NULL;
+ pers_fname = get_persconffile_path(uat->filename, uat->from_profile);
if ((! for_writing ) && (! file_exists(pers_fname) )) {
- gchar* data_fname = get_datafile_path(uat->filename);
+ char* data_fname = get_datafile_path(uat->filename);
if (file_exists(data_fname)) {
g_free(pers_fname);
@@ -253,7 +250,7 @@ gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing) {
}
uat_t* uat_get_table_by_name(const char* name) {
- guint i;
+ unsigned i;
for (i=0; i < all_uats->len; i++) {
uat_t* u = (uat_t *)g_ptr_array_index(all_uats,i);
@@ -265,8 +262,13 @@ uat_t* uat_get_table_by_name(const char* name) {
return NULL;
}
+void uat_set_default_values(uat_t *uat_in, const char *default_values[])
+{
+ uat_in->default_values = default_values;
+}
+
char *uat_fld_tostr(void *rec, uat_field_t *f) {
- guint len;
+ unsigned len;
char *ptr;
char *out;
@@ -286,13 +288,13 @@ char *uat_fld_tostr(void *rec, uat_field_t *f) {
break;
case PT_TXTMOD_HEXBYTES: {
GString *s = g_string_sized_new( len*2 + 1 );
- guint i;
+ unsigned i;
- for (i=0; i<len;i++) g_string_append_printf(s, "%.2X", ((const guint8*)ptr)[i]);
+ for (i=0; i<len;i++) g_string_append_printf(s, "%.2X", ((const uint8_t*)ptr)[i]);
out = g_strdup(s->str);
- g_string_free(s, TRUE);
+ g_string_free(s, true);
break;
}
default:
@@ -306,7 +308,7 @@ char *uat_fld_tostr(void *rec, uat_field_t *f) {
}
static void putfld(FILE* fp, void* rec, uat_field_t* f) {
- guint fld_len;
+ unsigned fld_len;
char* fld_ptr;
f->cb.tostr(rec,&fld_ptr,&fld_len,f->cbdata.tostr,f->fld_data);
@@ -319,16 +321,18 @@ static void putfld(FILE* fp, void* rec, uat_field_t* f) {
case PT_TXTMOD_DISPLAY_FILTER:
case PT_TXTMOD_PROTO_FIELD:
case PT_TXTMOD_COLOR:
- case PT_TXTMOD_STRING: {
- guint i;
+ case PT_TXTMOD_STRING:
+ case PT_TXTMOD_DISSECTOR:
+ {
+ unsigned i;
putc('"',fp);
for(i=0;i<fld_len;i++) {
char c = fld_ptr[i];
- if (c == '"' || c == '\\' || ! g_ascii_isprint((guchar)c) ) {
- fprintf(fp,"\\x%02x", (guchar) c);
+ if (c == '"' || c == '\\' || ! g_ascii_isprint((unsigned char)c) ) {
+ fprintf(fp,"\\x%02x", (unsigned char) c);
} else {
putc(c,fp);
}
@@ -338,10 +342,10 @@ static void putfld(FILE* fp, void* rec, uat_field_t* f) {
break;
}
case PT_TXTMOD_HEXBYTES: {
- guint i;
+ unsigned i;
for(i=0;i<fld_len;i++) {
- fprintf(fp,"%02x", (guchar)fld_ptr[i]);
+ fprintf(fp,"%02x", (unsigned char)fld_ptr[i]);
}
break;
@@ -357,29 +361,29 @@ static void putfld(FILE* fp, void* rec, uat_field_t* f) {
g_free(fld_ptr);
}
-gboolean uat_save(uat_t* uat, char** error) {
- guint i;
- gchar* fname = uat_get_actual_filename(uat,TRUE);
+bool uat_save(uat_t* uat, char** error) {
+ unsigned i;
+ char* fname = uat_get_actual_filename(uat,true);
FILE* fp;
- if (! fname ) return FALSE;
+ if (! fname ) return false;
fp = ws_fopen(fname,"w");
if (!fp && errno == ENOENT) {
/* Parent directory does not exist, try creating first */
- gchar *pf_dir_path = NULL;
+ char *pf_dir_path = NULL;
if (create_persconffile_dir(&pf_dir_path) != 0) {
- *error = g_strdup_printf("uat_save: error creating '%s'", pf_dir_path);
+ *error = ws_strdup_printf("uat_save: error creating '%s'", pf_dir_path);
g_free (pf_dir_path);
- return FALSE;
+ return false;
}
fp = ws_fopen(fname,"w");
}
if (!fp) {
- *error = g_strdup_printf("uat_save: error opening '%s': %s",fname,g_strerror(errno));
- return FALSE;
+ *error = ws_strdup_printf("uat_save: error opening '%s': %s",fname,g_strerror(errno));
+ return false;
}
*error = NULL;
@@ -401,7 +405,7 @@ gboolean uat_save(uat_t* uat, char** error) {
/* Now copy "good" raw_data entries to user_data */
for ( i = 0 ; i < uat->raw_data->len ; i++ ) {
void *rec = UAT_INDEX_PTR(uat, i);
- gboolean valid = g_array_index(uat->valid_data, gboolean, i);
+ bool valid = g_array_index(uat->valid_data, bool, i);
if (valid) {
g_array_append_vals(uat->user_data, rec, 1);
if (uat->copy_cb) {
@@ -419,7 +423,7 @@ gboolean uat_save(uat_t* uat, char** error) {
for ( i = 0 ; i < uat->user_data->len ; i++ ) {
void* rec = uat->user_data->data + (uat->record_size * i);
uat_field_t* f;
- guint j;
+ unsigned j;
f = uat->fields;
@@ -433,13 +437,13 @@ gboolean uat_save(uat_t* uat, char** error) {
fclose(fp);
- uat->changed = FALSE;
+ uat->changed = false;
- return TRUE;
+ return true;
}
-uat_t *uat_find(gchar *name) {
- guint i;
+uat_t *uat_find(char *name) {
+ unsigned i;
for (i=0; i < all_uats->len; i++) {
uat_t* u = (uat_t *)g_ptr_array_index(all_uats,i);
@@ -452,7 +456,7 @@ uat_t *uat_find(gchar *name) {
}
void uat_clear(uat_t* uat) {
- guint i;
+ unsigned i;
for ( i = 0 ; i < uat->user_data->len ; i++ ) {
if (uat->free_cb) {
@@ -479,42 +483,54 @@ void uat_clear(uat_t* uat) {
}
void uat_unload_all(void) {
- guint i;
+ unsigned i;
for (i=0; i < all_uats->len; i++) {
uat_t* u = (uat_t *)g_ptr_array_index(all_uats,i);
/* Do not unload if not in profile */
if (u->from_profile) {
uat_clear(u);
- u->loaded = FALSE;
+ u->loaded = false;
}
}
}
+static void free_uat(uat_t *uat)
+{
+ unsigned j;
+
+ uat_clear(uat);
+ g_free(uat->help);
+ g_free(uat->name);
+ g_free(uat->filename);
+ g_array_free(uat->user_data, true);
+ g_array_free(uat->raw_data, true);
+ g_array_free(uat->valid_data, true);
+ for (j = 0; uat->fields[j].title; j++)
+ g_free(uat->fields[j].priv);
+ g_free(uat);
+}
+
void uat_cleanup(void) {
- guint i;
- guint j;
+ unsigned i;
uat_t* uat;
for (i = 0; i < all_uats->len; i++) {
uat = (uat_t *)g_ptr_array_index(all_uats, i);
- uat_clear(uat);
- g_free(uat->help);
- g_free(uat->name);
- g_free(uat->filename);
- g_array_free(uat->user_data, TRUE);
- g_array_free(uat->raw_data, TRUE);
- g_array_free(uat->valid_data, TRUE);
- for (j = 0; uat->fields[j].title; j++)
- g_free(uat->fields[j].priv);
- g_free(uat);
+ free_uat(uat);
}
- g_ptr_array_free(all_uats,TRUE);
+ g_ptr_array_free(all_uats,true);
+}
+
+void uat_destroy(uat_t *uat)
+{
+ g_ptr_array_remove(all_uats, uat);
+ free_uat(uat);
}
void uat_foreach_table(uat_cb_t cb,void* user_data) {
- guint i;
+ unsigned i;
for (i=0; i < all_uats->len; i++)
cb(g_ptr_array_index(all_uats,i), user_data);
@@ -522,8 +538,8 @@ void uat_foreach_table(uat_cb_t cb,void* user_data) {
}
void uat_load_all(void) {
- guint i;
- gchar* err;
+ unsigned i;
+ char* err;
for (i=0; i < all_uats->len; i++) {
uat_t* u = (uat_t *)g_ptr_array_index(all_uats,i);
@@ -539,44 +555,44 @@ void uat_load_all(void) {
}
-gboolean uat_fld_chk_str(void* u1 _U_, const char* strptr, guint len _U_, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_str(void* u1 _U_, const char* strptr, unsigned len _U_, const void* u2 _U_, const void* u3 _U_, char** err) {
if (strptr == NULL) {
*err = g_strdup("NULL pointer");
- return FALSE;
+ return false;
}
*err = NULL;
- return TRUE;
+ return true;
}
-gboolean uat_fld_chk_oid(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_oid(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
unsigned int i;
*err = NULL;
if (strptr == NULL) {
*err = g_strdup("NULL pointer");
- return FALSE;
+ return false;
}
if (len == 0) {
*err = g_strdup("Empty OID");
- return FALSE;
+ return false;
}
for(i = 0; i < len; i++)
if(!(g_ascii_isdigit(strptr[i]) || strptr[i] == '.')) {
*err = g_strdup("Only digits [0-9] and \".\" allowed in an OID");
- return FALSE;
+ return false;
}
if(strptr[len-1] == '.') {
*err = g_strdup("OIDs must not be terminated with a \".\"");
- return FALSE;
+ return false;
}
if(!((*strptr == '0' || *strptr == '1' || *strptr =='2') && (len > 1 && strptr[1] == '.'))) {
*err = g_strdup("OIDs must start with \"0.\" (ITU-T assigned), \"1.\" (ISO assigned) or \"2.\" (joint ISO/ITU-T assigned)");
- return FALSE;
+ return false;
}
/* should also check that the second arc is in the range 0-39 */
@@ -584,31 +600,30 @@ gboolean uat_fld_chk_oid(void* u1 _U_, const char* strptr, guint len, const void
return *err == NULL;
}
-gboolean uat_fld_chk_proto(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_proto(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
if (len) {
char* name = g_strndup(strptr,len);
- ascii_strdown_inplace(name);
- g_strchug(name);
+ g_strstrip(name);
if (find_dissector(name)) {
*err = NULL;
g_free(name);
- return TRUE;
+ return true;
} else {
*err = g_strdup("dissector not found");
g_free(name);
- return FALSE;
+ return false;
}
} else {
*err = NULL;
- return TRUE;
+ return true;
}
}
-static gboolean uat_fld_chk_num_check_result(gboolean result, const char* strn, char** err) {
+static bool uat_fld_chk_num_check_result(bool result, const char* strn, char** err) {
if (result && ((*strn != '\0') && (*strn != ' '))) {
/* string valid, but followed by something other than a space */
- result = FALSE;
+ result = false;
errno = EINVAL;
}
if (!result) {
@@ -631,12 +646,12 @@ static gboolean uat_fld_chk_num_check_result(gboolean result, const char* strn,
return result;
}
-static gboolean uat_fld_chk_num(int base, const char* strptr, guint len, char** err) {
+static bool uat_fld_chk_num(int base, const char* strptr, unsigned len, char** err) {
if (len > 0) {
char* str = g_strndup(strptr, len);
const char* strn;
- gboolean result;
- guint32 value;
+ bool result;
+ uint32_t value;
result = ws_basestrtou32(str, &strn, &value, base);
result = uat_fld_chk_num_check_result(result, strn, err);
@@ -645,15 +660,15 @@ static gboolean uat_fld_chk_num(int base, const char* strptr, guint len, char**
}
*err = NULL;
- return TRUE;
+ return true;
}
-static gboolean uat_fld_chk_num64(int base, const char* strptr, guint len, char** err) {
+static bool uat_fld_chk_num64(int base, const char* strptr, unsigned len, char** err) {
if (len > 0) {
char* str = g_strndup(strptr, len);
const char* strn;
- gboolean result;
- guint64 value64;
+ bool result;
+ uint64_t value64;
result = ws_basestrtou64(str, &strn, &value64, base);
result = uat_fld_chk_num_check_result(result, strn, err);
@@ -662,31 +677,31 @@ static gboolean uat_fld_chk_num64(int base, const char* strptr, guint len, char*
}
*err = NULL;
- return TRUE;
+ return true;
}
-gboolean uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_num_dec(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
return uat_fld_chk_num(10, strptr, len, err);
}
-gboolean uat_fld_chk_num_hex(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_num_hex(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
return uat_fld_chk_num(16, strptr, len, err);
}
-gboolean uat_fld_chk_num_dec64(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_num_dec64(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
return uat_fld_chk_num64(10, strptr, len, err);
}
-gboolean uat_fld_chk_num_hex64(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_num_hex64(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
return uat_fld_chk_num64(16, strptr, len, err);
}
-gboolean uat_fld_chk_num_signed_dec(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_num_signed_dec(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
if (len > 0) {
char* str = g_strndup(strptr,len);
const char* strn;
- gboolean result;
- gint32 value;
+ bool result;
+ int32_t value;
result = ws_strtoi32(str, &strn, &value);
result = uat_fld_chk_num_check_result(result, strn, err);
@@ -696,15 +711,15 @@ gboolean uat_fld_chk_num_signed_dec(void* u1 _U_, const char* strptr, guint len,
}
*err = NULL;
- return TRUE;
+ return true;
}
-gboolean uat_fld_chk_num_signed_dec64(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_num_signed_dec64(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
if (len > 0) {
char* str = g_strndup(strptr, len);
const char* strn;
- gboolean result;
- gint64 value;
+ bool result;
+ int64_t value;
result = ws_strtoi64(str, &strn, &value);
result = uat_fld_chk_num_check_result(result, strn, err);
@@ -714,10 +729,10 @@ gboolean uat_fld_chk_num_signed_dec64(void* u1 _U_, const char* strptr, guint le
}
*err = NULL;
- return TRUE;
+ return true;
}
-gboolean uat_fld_chk_bool(void* u1 _U_, const char* strptr, guint len, const void* u2 _U_, const void* u3 _U_, char** err)
+bool uat_fld_chk_bool(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err)
{
char* str = g_strndup(strptr,len);
@@ -725,55 +740,55 @@ gboolean uat_fld_chk_bool(void* u1 _U_, const char* strptr, guint len, const voi
(g_strcmp0(str, "FALSE") == 0)) {
*err = NULL;
g_free(str);
- return TRUE;
+ return true;
}
- *err = g_strdup_printf("invalid value: %s (must be TRUE or FALSE)", str);
+ *err = ws_strdup_printf("invalid value: %s (must be true or false)", str);
g_free(str);
- return FALSE;
+ return false;
}
-gboolean uat_fld_chk_enum(void* u1 _U_, const char* strptr, guint len, const void* v, const void* u3 _U_, char** err) {
+bool uat_fld_chk_enum(void* u1 _U_, const char* strptr, unsigned len, const void* v, const void* u3 _U_, char** err) {
char* str = g_strndup(strptr,len);
- guint i;
+ unsigned i;
const value_string* vs = (const value_string *)v;
for(i=0;vs[i].strptr;i++) {
if (g_strcmp0(vs[i].strptr,str) == 0) {
*err = NULL;
g_free(str);
- return TRUE;
+ return true;
}
}
- *err = g_strdup_printf("invalid value: %s",str);
+ *err = ws_strdup_printf("invalid value: %s",str);
g_free(str);
- return FALSE;
+ return false;
}
-gboolean uat_fld_chk_range(void* u1 _U_, const char* strptr, guint len, const void* v _U_, const void* u3, char** err) {
+bool uat_fld_chk_range(void* u1 _U_, const char* strptr, unsigned len, const void* v _U_, const void* u3, char** err) {
char* str = g_strndup(strptr,len);
range_t* r = NULL;
convert_ret_t ret = range_convert_str(NULL, &r, str,GPOINTER_TO_UINT(u3));
- gboolean ret_value = FALSE;
+ bool ret_value = false;
switch ( ret ) {
case CVT_NO_ERROR:
*err = NULL;
- ret_value = TRUE;
+ ret_value = true;
break;
case CVT_SYNTAX_ERROR:
- *err = g_strdup_printf("syntax error in range: %s",str);
- ret_value = FALSE;
+ *err = ws_strdup_printf("syntax error in range: %s",str);
+ ret_value = false;
break;
case CVT_NUMBER_TOO_BIG:
- *err = g_strdup_printf("value too large in range: '%s' (max = %u)",str,GPOINTER_TO_UINT(u3));
- ret_value = FALSE;
+ *err = ws_strdup_printf("value too large in range: '%s' (max = %u)",str,GPOINTER_TO_UINT(u3));
+ ret_value = false;
break;
default:
*err = g_strdup("Unable to convert range. Please report this to wireshark-dev@wireshark.org");
- ret_value = FALSE;
+ ret_value = false;
break;
}
@@ -782,20 +797,20 @@ gboolean uat_fld_chk_range(void* u1 _U_, const char* strptr, guint len, const vo
return ret_value;
}
-gboolean uat_fld_chk_color(void* u1 _U_, const char* strptr, guint len, const void* v _U_, const void* u3 _U_, char** err) {
+bool uat_fld_chk_color(void* u1 _U_, const char* strptr, unsigned len, const void* v _U_, const void* u3 _U_, char** err) {
if ((len != 7) || (*strptr != '#')) {
*err = g_strdup("Color must be of the format #RRGGBB");
- return FALSE;
+ return false;
}
/* Color is just # followed by hex string, so use hex verification */
return uat_fld_chk_num(16, strptr + 1, len - 1, err);
}
-char* uat_unbinstring(const char* si, guint in_len, guint* len_p) {
- guint8* buf;
- guint len = in_len/2;
+char* uat_unbinstring(const char* si, unsigned in_len, unsigned* len_p) {
+ uint8_t* buf;
+ unsigned len = in_len/2;
int i = 0;
int d0, d1;
@@ -803,7 +818,7 @@ char* uat_unbinstring(const char* si, guint in_len, guint* len_p) {
return NULL;
}
- buf= (guint8 *)g_malloc0(len+1);
+ buf= (uint8_t *)g_malloc0(len+1);
if (len_p) *len_p = len;
while(in_len) {
@@ -818,10 +833,10 @@ char* uat_unbinstring(const char* si, guint in_len, guint* len_p) {
return (char*)buf;
}
-char* uat_unesc(const char* si, guint in_len, guint* len_p) {
+char* uat_unesc(const char* si, unsigned in_len, unsigned* len_p) {
char* buf = (char *)g_malloc0(in_len+1);
char* p = buf;
- guint len = 0;
+ unsigned len = 0;
const char* s;
const char* in_end = si+in_len;
@@ -900,20 +915,20 @@ char* uat_unesc(const char* si, guint in_len, guint* len_p) {
return buf;
}
-char* uat_undquote(const char* si, guint in_len, guint* len_p) {
+char* uat_undquote(const char* si, unsigned in_len, unsigned* len_p) {
return uat_unesc(si+1,in_len-2,len_p);
}
-char* uat_esc(const char* buf, guint len) {
- const guint8* end = ((const guint8*)buf)+len;
+char* uat_esc(const char* buf, unsigned len) {
+ const uint8_t* end = ((const uint8_t*)buf)+len;
char* out = (char *)g_malloc0((4*len)+1);
- const guint8* b;
+ const uint8_t* b;
char* s = out;
- for (b = (const guint8 *)buf; b < end; b++) {
+ for (b = (const uint8_t *)buf; b < end; b++) {
if (*b == '"' || *b == '\\' || ! g_ascii_isprint(*b) ) {
- g_snprintf(s,5,"\\x%02x",((guint)*b));
+ snprintf(s,5,"\\x%02x",((unsigned)*b));
s+=4;
} else {
*(s++) = (*b);
@@ -924,74 +939,74 @@ char* uat_esc(const char* buf, guint len) {
}
-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;
+bool uat_fld_chk_str_isprint(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
+ unsigned 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=%02x", i, (guchar) c);
- return FALSE;
+ *err = ws_strdup_printf("invalid char pos=%d value=%02x", i, (unsigned char) c);
+ return false;
}
}
*err = NULL;
- return TRUE;
+ 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;
+bool uat_fld_chk_str_isalpha(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
+ unsigned 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=%02x", i, (guchar) c);
- return FALSE;
+ *err = ws_strdup_printf("invalid char pos=%d value=%02x", i, (unsigned char) c);
+ return false;
}
}
*err = NULL;
- return TRUE;
+ 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;
+bool uat_fld_chk_str_isalnum(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
+ unsigned 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=%02x", i, (guchar) c);
- return FALSE;
+ *err = ws_strdup_printf("invalid char pos=%d value=%02x", i, (unsigned char) c);
+ return false;
}
}
*err = NULL;
- return TRUE;
+ 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;
+bool uat_fld_chk_str_isdigit(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
+ unsigned 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=%02x", i, (guchar) c);
- return FALSE;
+ *err = ws_strdup_printf("invalid char pos=%d value=%02x", i, (unsigned char) c);
+ return false;
}
}
*err = NULL;
- return TRUE;
+ 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;
+bool uat_fld_chk_str_isxdigit(void* u1 _U_, const char* strptr, unsigned len, const void* u2 _U_, const void* u3 _U_, char** err) {
+ unsigned 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=%02x", i, (guchar) c);
- return FALSE;
+ *err = ws_strdup_printf("invalid char pos=%d value=%02x", i, (unsigned char) c);
+ return false;
}
}
*err = NULL;
- return TRUE;
+ return true;
}