diff --git a/epan/uat-int.h b/epan/uat-int.h index e3eb29ce47..231c7d45d8 100644 --- a/epan/uat-int.h +++ b/epan/uat-int.h @@ -5,7 +5,25 @@ * Mantain an array of user accessible data strucures * Internal interface * - * (c) 2007, Luis E. Garcia Ontanon + * (c) 2007, Luis E. Garcia Ontanon + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2001 Gerald Combs + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #ifndef _UAT_INT_H_ @@ -47,7 +65,6 @@ struct _uat_t { guint ncols; GArray* user_data; gboolean finalized; - gboolean locked; uat_rep_t* rep; uat_rep_free_cb_t free_rep; diff --git a/epan/uat.c b/epan/uat.c index 41c911b90e..93bf611753 100644 --- a/epan/uat.c +++ b/epan/uat.c @@ -1,9 +1,30 @@ /* * uat.c * + * $Id$ + * * User Accessible Tables * Mantain an array of user accessible data strucures * + * (c) 2007, Luis E. Garcia Ontanon + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2001 Gerald Combs + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -108,6 +129,7 @@ uat_t* uat_new(const char* uat_name, uat_copy_cb_t copy_cb, uat_update_cb_t update_cb, uat_free_cb_t free_cb, + char** error, ...) { uat_t* uat = uat_start(uat_name, size, filename, data_ptr, numitems_ptr, copy_cb, update_cb, free_cb); va_list ap; @@ -116,7 +138,7 @@ uat_t* uat_new(const char* uat_name, uat_fld_chk_cb_t chk_cb; uat_fld_set_cb_t set_cb; uat_fld_tostr_cb_t tostr_cb; - va_start(ap,free_cb); + va_start(ap,error); name = va_arg(ap,char*); @@ -135,6 +157,8 @@ uat_t* uat_new(const char* uat_name, uat_finalize(uat); + uat_load(uat,error); + return uat; } diff --git a/epan/uat.h b/epan/uat.h index 54308940c9..57213a6487 100644 --- a/epan/uat.h +++ b/epan/uat.h @@ -4,8 +4,26 @@ * User Accessible Tables * Mantain an array of user accessible data strucures * - * (c) 2007, Luis E. Garcia Ontanon * + * (c) 2007, Luis E. Garcia Ontanon + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2001 Gerald Combs + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _UAT_H_ @@ -199,6 +217,7 @@ uat_t* uat_new(const char* name, uat_copy_cb_t copy_cb, uat_update_cb_t update_cb, uat_free_cb_t free_cb, + char** error, ...); diff --git a/epan/uat_load.l b/epan/uat_load.l index 1bd2474e80..a99f1c452f 100644 --- a/epan/uat_load.l +++ b/epan/uat_load.l @@ -2,10 +2,37 @@ %option nounput %option prefix="uat_load_" %option never-interactive +%option yylineno %{ /* - * one parser to fit them all + * uat_load.c + * + * $Id$ + * + * User Accessible Tables + * Mantain an array of user accessible data strucures + * One parser to fit them all + * + * (c) 2007, Luis E. Garcia Ontanon + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 2001 Gerald Combs + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H # include "config.h" @@ -32,7 +59,7 @@ static char* unbinstring(const char* si, guint in_len, guint* len_p); static char* undquote(const char* si, guint in_len, guint* len_p); -#define ERROR(txt) do { error = txt; yyterminate(); } while(0) +#define ERROR(txt) do { error = ep_strdup_printf("%s:%d: %s",uat->filename,yylineno,txt); yyterminate(); } while(0) #define SET_FIELD() \ { gchar* err; \ @@ -45,53 +72,97 @@ g_free(ptr);\ } while(0) +#if 1 +#define DUMP_FIELD(str) \ + { guint i; printf("%s: '",str); for(i=0;i{ws} ; +{newline} ; +{comment} ; +{newline} { + ERROR("expecting more fields in previuos line"); + BEGIN START_OF_LINE; +} {quoted_string} { ptr = undquote(yytext,yyleng,&len); - - if (( uat_fld = uat_fld->next )) { + + + if (uat_fld->next) { + DUMP("quoted_str->s"); BEGIN SEPARATOR; } else { + DUMP("quoted_str->eor"); BEGIN END_OF_RECORD; } } {binstring} { ptr = unbinstring(yytext,yyleng,&len); - + if (!ptr) { ERROR("uneven hexstring"); } - if (( uat_fld = uat_fld->next )) { + if ( uat_fld->next ) { + DUMP("binstring->s"); BEGIN SEPARATOR; } else { + DUMP("binstring->eor"); BEGIN END_OF_RECORD; } } {separator} { + + DUMP_FIELD("separator->next"); + SET_FIELD(); - uat_fld = uat_fld->next; - if (! uat_fld ) { + + if ( ! (uat_fld = uat_fld->next) ) { ERROR("more fields than required"); } + + BEGIN NEXT_FIELD; +} + +{newline} { + ERROR("expecting more fields in previuos line"); + BEGIN START_OF_LINE; +} + +. { + ERROR("unexpected char while looking for next field"); + BEGIN ERRORED; +} + +{separator} { + ERROR("more fields than required"); + BEGIN ERRORED; } {newline} { void* rec; gchar* err = NULL; + DUMP_FIELD("newline->start"); + SET_FIELD(); rec = uat_add_record(uat, record); @@ -111,6 +182,14 @@ newline [ \t]*[\r]?\n BEGIN START_OF_LINE; } +. { + ERROR("unexpected char while looking for end of line"); + BEGIN ERRORED; +} + +{newline} BEGIN START_OF_LINE; +. ; + {newline} { ERROR("incomplete record"); } . { ERROR("unexpected input"); } %% @@ -251,12 +330,12 @@ done: return buf; } -gboolean uat_load(uat_t* dt_in, char** err) { - gchar* fname = uat_get_actual_filename(uat, FALSE); +gboolean uat_load(uat_t* uat_in, char** err) { + gchar* fname = uat_get_actual_filename(uat_in, FALSE); - g_assert(uat->finalized && uat->locked); + g_assert(uat_in->finalized); - uat = dt_in; + uat = uat_in; ; if (!(yyin = fopen(fname,"r"))) {