/* Convert an FT_STRING using a callback function */ static gboolean string_walk(GList* arg1list, GList **retval, gchar(*conv_func)(gchar)) { GList *arg1; fvalue_t *arg_fvalue; fvalue_t *new_ft_string; char *s, *c; arg1 = arg1list; while (arg1) { arg_fvalue = (fvalue_t *)arg1->data; /* XXX - it would be nice to handle FT_TVBUFF, too */ if (IS_FT_STRING(fvalue_type_ftenum(arg_fvalue))) { s = (char *)ep_strdup((gchar *)fvalue_get(arg_fvalue)); for (c = s; *c; c++) { /**c = string_ascii_to_lower(*c);*/ *c = conv_func(*c); } new_ft_string = fvalue_new(FT_STRING); fvalue_set_string(new_ft_string, s); *retval = g_list_append(*retval, new_ft_string); } arg1 = arg1->next; } return TRUE; }
/* Convert an FT_STRING using a callback function */ static gboolean string_walk(GList* arg1list, GList **retval, gchar(*conv_func)(gchar)) { GList *arg1; fvalue_t *arg_fvalue; fvalue_t *new_ft_string; char *s, *c; arg1 = arg1list; while (arg1) { arg_fvalue = arg1->data; switch (fvalue_ftype(arg_fvalue)->ftype) { case FT_STRING: s = ep_strdup(fvalue_get(arg1->data)); for (c = s; *c; c++) { /**c = string_ascii_to_lower(*c);*/ *c = conv_func(*c); } new_ft_string = fvalue_new(FT_STRING); fvalue_set(new_ft_string, s, FALSE); *retval = g_list_append(*retval, new_ft_string); break; /* XXX - it would be nice to handle FT_TVBUFF, too */ default: break; } arg1 = arg1->next; } return TRUE; }
/* Creates a FT_UINT32 fvalue with a given value. */ static fvalue_t* mk_uint32_fvalue(guint32 val) { fvalue_t *fv; fv = fvalue_new(FT_UINT32); fvalue_set_uinteger(fv, val); return fv; }
/* Creates a FT_UINT64 fvalue with a given value. */ static fvalue_t* mk_uint64_fvalue(guint64 val) { fvalue_t *fv; fv = fvalue_new(FT_UINT64); fvalue_set_integer64(fv, val); return fv; }
fvalue_t* fvalue_from_string(ftenum_t ftype, char *s, LogFunc logfunc) { fvalue_t *fv; fv = fvalue_new(ftype); if (fv->ftype->val_from_string) { if (fv->ftype->val_from_string(fv, s, logfunc)) { return fv; } } else { logfunc("\"%s\" cannot be converted to %s.", s, ftype_pretty_name(ftype)); } FVALUE_FREE(fv); return NULL; }
fvalue_t* fvalue_from_unparsed(ftenum_t ftype, char *s, gboolean allow_partial_value, LogFunc logfunc) { fvalue_t *fv; fv = fvalue_new(ftype); if (fv->ftype->val_from_unparsed) { if (fv->ftype->val_from_unparsed(fv, s, allow_partial_value, logfunc)) { return fv; } } else { logfunc("\"%s\" cannot be converted to %s.", s, ftype_pretty_name(ftype)); } FVALUE_FREE(fv); return NULL; }
/* Returns a new FT_BYTES fvalue_t* if possible, otherwise NULL */ fvalue_t* fvalue_slice(fvalue_t *fv, drange *d_range) { slice_data_t slice_data; fvalue_t *new_fv; slice_data.fv = fv; slice_data.bytes = g_byte_array_new(); slice_data.slice_failure = FALSE; /* XXX - We could make some optimizations here based on * drange_has_total_length() and * drange_get_max_offset(). */ drange_foreach_drange_node(d_range, slice_func, &slice_data); new_fv = fvalue_new(FT_BYTES); fvalue_set(new_fv, slice_data.bytes, TRUE); return new_fv; }
fvalue_t* fvalue_from_string(ftenum_t ftype, const char *s, gchar **err_msg) { fvalue_t *fv; fv = fvalue_new(ftype); if (fv->ftype->val_from_string) { if (fv->ftype->val_from_string(fv, s, err_msg)) { /* Success */ if (err_msg != NULL) *err_msg = NULL; return fv; } } else { if (err_msg != NULL) { *err_msg = g_strdup_printf("\"%s\" cannot be converted to %s.", s, ftype_pretty_name(ftype)); } } FVALUE_FREE(fv); return NULL; }