forked from osmocom/wireshark
One more patch for mate:
- renamed analyze_frame() into mate_analyze_frame(). - prepare mate to be statically linked - use report_open_failure() , report_read_failure() and report_failure() in case there's an error while loading the config - some cleanup in mate_util.c - some fixes and cleanup in examples and matelib svn path=/trunk/; revision=13001
This commit is contained in:
parent
2f5e81cccc
commit
2b88200a3a
|
@ -32,19 +32,26 @@
|
|||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#ifndef ENABLE_STATIC
|
||||
#include "plugins/plugin_api.h"
|
||||
#include "moduleinfo.h"
|
||||
|
||||
#include <gmodule.h>
|
||||
#else
|
||||
#include <glib.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <epan/packet.h>
|
||||
#include <epan/strutil.h>
|
||||
#include <epan/prefs.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <epan/proto.h>
|
||||
#include <epan/epan_dissect.h>
|
||||
#include <epan/tap.h>
|
||||
#include <epan/filesystem.h>
|
||||
#include <epan/report_err.h>
|
||||
|
||||
#include "mate_util.h"
|
||||
#include "plugins/plugin_api_defs.h"
|
||||
|
@ -52,7 +59,6 @@
|
|||
|
||||
/* defaults */
|
||||
|
||||
#define DEFAULT_MAX_MATE_ITEMS 0
|
||||
#define DEFAULT_GOG_EXPIRATION 2.0
|
||||
|
||||
#ifdef WIN32
|
||||
|
@ -317,7 +323,7 @@ struct _mate_item {
|
|||
/* from mate_runtime.c */
|
||||
extern void initialize_mate_runtime(void);
|
||||
extern mate_pdu* mate_get_pdus(guint32 framenum);
|
||||
extern void analyze_frame(packet_info *pinfo, proto_tree* tree);
|
||||
extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree);
|
||||
extern int mate_packet(void* _U_, packet_info* _U_, epan_dissect_t* _U_,const void* _U_);
|
||||
|
||||
/* from mate_setup.c */
|
||||
|
|
|
@ -740,7 +740,7 @@ static void delete_mate_pdu(mate_pdu* pdu) {
|
|||
g_mem_chunk_free(rd->mate_items,pdu);
|
||||
}
|
||||
|
||||
extern void analyze_frame(packet_info *pinfo, proto_tree* tree) {
|
||||
extern void mate_analyze_frame(packet_info *pinfo, proto_tree* tree) {
|
||||
mate_cfg_pdu* cfg;
|
||||
GPtrArray* protos;
|
||||
field_info* proto;
|
||||
|
|
|
@ -45,6 +45,23 @@ static GHashTable* actions = NULL;
|
|||
/* aestetics: I like keywords separated from user attributes */
|
||||
static AVPL* all_keywords = NULL;
|
||||
|
||||
/* configuration error */
|
||||
GString* config_error;
|
||||
|
||||
static void report_error(guint8* fmt, ...) {
|
||||
static guint8 error_buffer[DEBUG_BUFFER_SIZE];
|
||||
|
||||
va_list list;
|
||||
|
||||
va_start( list, fmt );
|
||||
g_vsnprintf(error_buffer,DEBUG_BUFFER_SIZE,fmt,list);
|
||||
va_end( list );
|
||||
|
||||
g_string_append(config_error,error_buffer);
|
||||
g_string_append_c(config_error,'\n');
|
||||
|
||||
}
|
||||
|
||||
/* use as: setting = extract_named_xxx(avpl,keyword,default_value); */
|
||||
static int extract_named_int(AVPL* avpl, guint8* keyword, int value) {
|
||||
AVP* avp = NULL;
|
||||
|
@ -274,18 +291,18 @@ static gboolean mate_load_config(guint8* filename) {
|
|||
|
||||
if (action) {
|
||||
if ( ! action(avpl) ) {
|
||||
g_warning("MATE: Error on: %s",avpl->name);
|
||||
report_error("MATE: Error on: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
g_warning("MATE: action '%s' unknown in: %s",name,avpl->name);
|
||||
report_error("MATE: action '%s' unknown in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
} else {
|
||||
g_warning("MATE: error reading config file: %s",loal->name);
|
||||
report_error("MATE: error reading config file: %s",loal->name);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -316,7 +333,7 @@ static gboolean add_hfid(guint8* what, guint8* how, GHashTable* where) {
|
|||
if (( as = g_hash_table_lookup(where,ip) )) {
|
||||
g_free(ip);
|
||||
if (! g_str_equal(as,how)) {
|
||||
g_warning("MATE Error: add field to Pdu: attempt to add %s(%i) as %s"
|
||||
report_error("MATE Error: add field to Pdu: attempt to add %s(%i) as %s"
|
||||
" failed: field already added as '%s'",what,hfi->id,how,as);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -333,7 +350,7 @@ static gboolean add_hfid(guint8* what, guint8* how, GHashTable* where) {
|
|||
}
|
||||
|
||||
if (! exists) {
|
||||
g_warning("MATE Error: cannot find field %s",what);
|
||||
report_error("MATE Error: cannot find field %s",what);
|
||||
}
|
||||
|
||||
return exists;
|
||||
|
@ -351,14 +368,14 @@ static gboolean config_pdu(AVPL* avpl) {
|
|||
AVP* attr_avp;
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: PduDef: No Name in: %s",avpl->name);
|
||||
report_error("MATE: PduDef: No Name in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! cfg) {
|
||||
cfg = new_pducfg(name);
|
||||
} else {
|
||||
g_warning("MATE: PduDef: No such PDU: '%s' in: %s",cfg->name,avpl->name);
|
||||
report_error("MATE: PduDef: No such PDU: '%s' in: %s",cfg->name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -371,7 +388,7 @@ static gboolean config_pdu(AVPL* avpl) {
|
|||
if (hfi) {
|
||||
cfg->hfid_proto = hfi->id;
|
||||
} else {
|
||||
g_warning("MATE: PduDef: no such proto: '%s' in: %s",proto,avpl->name);
|
||||
report_error("MATE: PduDef: no such proto: '%s' in: %s",proto,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -390,7 +407,7 @@ static gboolean config_pdu(AVPL* avpl) {
|
|||
g_ptr_array_add(cfg->hfid_ranges,(gpointer)hfidp);
|
||||
g_string_sprintfa(matecfg->mate_attrs_filter, "||%s",transports[i]);
|
||||
} else {
|
||||
g_warning("MATE: PduDef: no such proto: '%s' for Transport in: %s",proto,avpl->name);
|
||||
report_error("MATE: PduDef: no such proto: '%s' for Transport in: %s",proto,avpl->name);
|
||||
g_strfreev(transports);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -399,13 +416,13 @@ static gboolean config_pdu(AVPL* avpl) {
|
|||
g_strfreev(transports);
|
||||
}
|
||||
} else {
|
||||
g_warning("MATE: PduDef: no Transport for '%s' in: %s",cfg->name,avpl->name);
|
||||
report_error("MATE: PduDef: no Transport for '%s' in: %s",cfg->name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
while (( attr_avp = extract_first_avp(avpl) )) {
|
||||
if ( ! add_hfid(attr_avp->v,attr_avp->n,cfg->hfids_attr) ) {
|
||||
g_warning("MATE: PduDef: failed to set PDU attribute '%s' in: %s",attr_avp->n,avpl->name);
|
||||
report_error("MATE: PduDef: failed to set PDU attribute '%s' in: %s",attr_avp->n,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
g_string_sprintfa(matecfg->mate_attrs_filter, "||%s",attr_avp->v);
|
||||
|
@ -420,12 +437,12 @@ static gboolean config_pduextra(AVPL* avpl) {
|
|||
mate_cfg_pdu* cfg = lookup_using_index_avp(avpl,KEYWORD_FOR,matecfg->pducfgs,&name);
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: PduExtra: No For in: %s",avpl->name);
|
||||
report_error("MATE: PduExtra: No For in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! cfg) {
|
||||
g_warning("MATE: PduExtra: no such Pdu '%s' in: %s",name,avpl->name);
|
||||
report_error("MATE: PduExtra: no such Pdu '%s' in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -435,7 +452,7 @@ static gboolean config_pduextra(AVPL* avpl) {
|
|||
|
||||
while (( attr_avp = extract_first_avp(avpl) )) {
|
||||
if ( ! add_hfid(attr_avp->v,attr_avp->n,cfg->hfids_attr) ) {
|
||||
g_warning("MATE: PduExtra: failed to set attr '%s' in: %s",attr_avp->n,avpl->name);
|
||||
report_error("MATE: PduExtra: failed to set attr '%s' in: %s",attr_avp->n,avpl->name);
|
||||
delete_avp(attr_avp);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -456,12 +473,12 @@ static gboolean config_pducriteria(AVPL* avpl) {
|
|||
guint8* mode = extract_named_str(avpl, KEYWORD_MODE, NULL);
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: PduCriteria: No For in: %s",avpl->name);
|
||||
report_error("MATE: PduCriteria: No For in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cfg) {
|
||||
g_warning("MATE: PduCriteria: Pdu '%s' does not exist in: %s",name,avpl->name);
|
||||
report_error("MATE: PduCriteria: Pdu '%s' does not exist in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -471,7 +488,7 @@ static gboolean config_pducriteria(AVPL* avpl) {
|
|||
} else if ( g_strcasecmp(mode,KEYWORD_REJECT) == 0 ) {
|
||||
mode = matecfg->reject;
|
||||
} else {
|
||||
g_warning("MATE: PduCriteria: no such criteria mode: '%s' in %s",mode,avpl->name);
|
||||
report_error("MATE: PduCriteria: no such criteria mode: '%s' in %s",mode,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
|
@ -488,7 +505,7 @@ static gboolean config_pducriteria(AVPL* avpl) {
|
|||
} else if ( g_strcasecmp(match,KEYWORD_STRICT) == 0 ) {
|
||||
match_mode = AVPL_STRICT;
|
||||
} else {
|
||||
g_warning("MATE: PduCriteria: Config error: no such match mode '%s' in: %s",match,avpl->name);
|
||||
report_error("MATE: PduCriteria: Config error: no such match mode '%s' in: %s",match,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
@ -497,7 +514,7 @@ static gboolean config_pducriteria(AVPL* avpl) {
|
|||
|
||||
if (cfg->criterium) {
|
||||
/* FEATURE: more criteria */
|
||||
g_warning("MATE: PduCriteria: PduCriteria alredy exists for '%s' in: %s",name,avpl->name);
|
||||
report_error("MATE: PduCriteria: PduCriteria alredy exists for '%s' in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -513,12 +530,12 @@ static gboolean config_include(AVPL* avpl) {
|
|||
guint8* lib = extract_named_str(avpl,KEYWORD_LIB,NULL);
|
||||
|
||||
if ( ! filename && ! lib ) {
|
||||
g_warning("MATE: Include: no Filename or Lib given in: %s",avpl->name);
|
||||
report_error("MATE: Include: no Filename or Lib given in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( filename && lib ) {
|
||||
g_warning("MATE: Include: use either Filename or Lib, not both. in: %s",avpl->name);
|
||||
report_error("MATE: Include: use either Filename or Lib, not both. in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -528,7 +545,7 @@ static gboolean config_include(AVPL* avpl) {
|
|||
|
||||
/* FIXME: stop recursion */
|
||||
if ( ! mate_load_config(filename) ) {
|
||||
g_warning("MATE: Include: Error Loading '%s' in: %s",filename,avpl->name);
|
||||
report_error("MATE: Include: Error Loading '%s' in: %s",filename,avpl->name);
|
||||
if (lib) g_free(filename);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -601,7 +618,7 @@ static gboolean config_transform(AVPL* avpl) {
|
|||
} else if ( g_strcasecmp(match,KEYWORD_STRICT) == 0 ) {
|
||||
match_mode = AVPL_STRICT;
|
||||
} else {
|
||||
g_warning("MATE: Transform: no such match mode: '%s' in: %s",match,avpl->name);
|
||||
report_error("MATE: Transform: no such match mode: '%s' in: %s",match,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
|
@ -614,7 +631,7 @@ static gboolean config_transform(AVPL* avpl) {
|
|||
} else if ( g_strcasecmp(mode,KEYWORD_REPLACE) == 0 ) {
|
||||
replace_mode = AVPL_REPLACE;
|
||||
} else {
|
||||
g_warning("MATE: Transform: no such replace mode: '%s' in: %s",mode,avpl->name);
|
||||
report_error("MATE: Transform: no such replace mode: '%s' in: %s",mode,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -623,7 +640,7 @@ static gboolean config_transform(AVPL* avpl) {
|
|||
}
|
||||
|
||||
if (! name) {
|
||||
g_warning("MATE: Transform: no Name in: %s",avpl->name);
|
||||
report_error("MATE: Transform: no Name in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -646,22 +663,22 @@ static gboolean config_xxx_transform(AVPL* avpl, GHashTable* hash, guint8* keywo
|
|||
mate_cfg_pdu* cfg = lookup_using_index_avp(avpl,KEYWORD_FOR,hash,&cfg_name);;
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: %s: no Name in: %s",keyword,avpl->name);
|
||||
report_error("MATE: %s: no Name in: %s",keyword,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! cfg_name ) {
|
||||
g_warning("MATE: %s: no For in: %s",keyword,avpl->name);
|
||||
report_error("MATE: %s: no For in: %s",keyword,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! cfg ) {
|
||||
g_warning("MATE: %s: '%s' doesn't exist in: %s",keyword,cfg_name,avpl->name);
|
||||
report_error("MATE: %s: '%s' doesn't exist in: %s",keyword,cfg_name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!transf) {
|
||||
g_warning("MATE: %s: Transform '%s' doesn't exist in: %s",keyword,name,avpl->name);
|
||||
report_error("MATE: %s: Transform '%s' doesn't exist in: %s",keyword,name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -688,24 +705,24 @@ static gboolean config_gop(AVPL* avpl) {
|
|||
guint8* on = extract_named_str(avpl,KEYWORD_ON,NULL);
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: GopDef: no Name in: %s",avpl->name);
|
||||
report_error("MATE: GopDef: no Name in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cfg) {
|
||||
cfg = new_gopcfg(name);
|
||||
} else {
|
||||
g_warning("MATE: GopDef: Gop '%s' exists already in: %s",name,avpl->name);
|
||||
report_error("MATE: GopDef: Gop '%s' exists already in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! on ) {
|
||||
g_warning("MATE: GopDef: no On in: %s",avpl->name);
|
||||
report_error("MATE: GopDef: no On in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (g_hash_table_lookup(matecfg->gops_by_pduname,on) ) {
|
||||
g_warning("MATE: GopDef: Gop for Pdu '%s' exists already in: %s",on,avpl->name);
|
||||
report_error("MATE: GopDef: Gop for Pdu '%s' exists already in: %s",on,avpl->name);
|
||||
return FALSE;
|
||||
} else {
|
||||
g_hash_table_insert(matecfg->gops_by_pduname,on,cfg);
|
||||
|
@ -725,18 +742,18 @@ static gboolean config_start(AVPL* avpl) {
|
|||
mate_cfg_gop* cfg = lookup_using_index_avp(avpl, KEYWORD_FOR,matecfg->gopcfgs,&name);;
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: GopStart: no For in: %s",avpl->name);
|
||||
report_error("MATE: GopStart: no For in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cfg) {
|
||||
g_warning("MATE: GopStart: Gop '%s' doesn't exist in: %s",name,avpl->name);
|
||||
report_error("MATE: GopStart: Gop '%s' doesn't exist in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (cfg->start) {
|
||||
/* FEATURE: more start conditions */
|
||||
g_warning("MATE: GopStart: GopStart for '%s' exists already in: %s",name,avpl->name);
|
||||
report_error("MATE: GopStart: GopStart for '%s' exists already in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -750,17 +767,17 @@ static gboolean config_stop(AVPL* avpl) {
|
|||
mate_cfg_gop* cfg = lookup_using_index_avp(avpl, KEYWORD_FOR,matecfg->gopcfgs,&name);;
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: GopStop: no For in: %s",avpl->name);
|
||||
report_error("MATE: GopStop: no For in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cfg) {
|
||||
g_warning("MATE: GopStop: Gop '%s' doesn't exist in: %s",name,avpl->name);
|
||||
report_error("MATE: GopStop: Gop '%s' doesn't exist in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (cfg->stop) {
|
||||
g_warning("MATE: GopStop: GopStop alredy exists for '%s' in: %s",name,avpl->name);
|
||||
report_error("MATE: GopStop: GopStop alredy exists for '%s' in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -774,12 +791,12 @@ static gboolean config_gopextra(AVPL* avpl) {
|
|||
mate_cfg_gop* cfg = lookup_using_index_avp(avpl, KEYWORD_FOR,matecfg->gopcfgs,&name);;
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: GopExtra: no For in: %s",avpl->name);
|
||||
report_error("MATE: GopExtra: no For in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (!cfg) {
|
||||
g_warning("MATE: GopExtra: Gop '%s' does not exist in: %s",name,avpl->name);
|
||||
report_error("MATE: GopExtra: Gop '%s' does not exist in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -797,12 +814,12 @@ static gboolean config_gog(AVPL* avpl) {
|
|||
mate_cfg_gog* cfg = NULL;
|
||||
|
||||
if (! name ) {
|
||||
g_warning("MATE: GogDef: no Name in: %s",avpl->name);
|
||||
report_error("MATE: GogDef: no Name in: %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( g_hash_table_lookup(matecfg->gogcfgs,name) ) {
|
||||
g_warning("MATE: GogDef: Gog '%s' exists already in: %s",name,avpl->name);
|
||||
report_error("MATE: GogDef: Gog '%s' exists already in: %s",name,avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -823,15 +840,15 @@ static gboolean config_gogkey(AVPL* avpl) {
|
|||
|
||||
if ( ! name || ! cfg ) {
|
||||
if ( ! name )
|
||||
g_warning("MATE: GogKey: no Name in %s",avpl->name);
|
||||
report_error("MATE: GogKey: no Name in %s",avpl->name);
|
||||
else
|
||||
g_warning("MATE: GogKey: no such Gop '%s' in %s",name,avpl->name);
|
||||
report_error("MATE: GogKey: no such Gop '%s' in %s",name,avpl->name);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (! on ) {
|
||||
g_warning("MATE: GogKey: no On in %s",avpl->name);
|
||||
report_error("MATE: GogKey: no On in %s",avpl->name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -859,9 +876,9 @@ static gboolean config_gogextra(AVPL* avpl) {
|
|||
|
||||
if ( ! name || ! cfg ) {
|
||||
if ( ! name )
|
||||
g_warning("MATE: GogExtra: no Name in %s",avpl->name);
|
||||
report_error("MATE: GogExtra: no Name in %s",avpl->name);
|
||||
else
|
||||
g_warning("MATE: GogExtra: no such Gop '%s' in %s",name,avpl->name);
|
||||
report_error("MATE: GogExtra: no such Gop '%s' in %s",name,avpl->name);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -1595,11 +1612,15 @@ extern mate_config* mate_make_config(guint8* filename) {
|
|||
|
||||
matecfg->show_pdu_tree = matecfg->frame_tree;
|
||||
|
||||
config_error = g_string_new("");
|
||||
|
||||
if ( mate_load_config(filename) ) {
|
||||
analyze_config();
|
||||
dbg_print (dbg_cfg,3,dbg_facility,"mate_make_config: OK");
|
||||
if (dbg_cfg_lvl > 0) print_config();
|
||||
} else {
|
||||
report_failure("%s",config_error->str);
|
||||
g_string_free(config_error,TRUE);
|
||||
if (matecfg) destroy_mate_config(matecfg,FALSE);
|
||||
matecfg = NULL;
|
||||
return NULL;
|
||||
|
|
|
@ -25,28 +25,7 @@
|
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "mate.h"
|
||||
#include "mate_util.h"
|
||||
|
||||
/* TODO:
|
||||
+ fix debug_print levels
|
||||
+ chunks for scs_strings (do I realy need em??)
|
||||
+ checking bounds in (almost) every operator
|
||||
- operators
|
||||
+ rethink '&' operator
|
||||
- bounds check on op_match()
|
||||
? change &{} into []
|
||||
? add {xxx} to get avps named xxxx from the src avpl
|
||||
? add (yyy) to do aaa+31 or and similar stuff
|
||||
- add perlre operator?
|
||||
- transform
|
||||
+ map (N->M hash)
|
||||
*/
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* dbg_print
|
||||
|
@ -324,7 +303,7 @@ static int* dbg_avpl_op = &dbg_avpl_op_level;
|
|||
* @avpl: a pointer to the level of debugging of facility "avpl"
|
||||
* @avpl_op: a pointer to the level of debugging of facility "avpl_op"
|
||||
*
|
||||
* (If enabled set's up the debug facilities for the avp library.
|
||||
* If enabled set's up the debug facilities for the avp library.
|
||||
*
|
||||
**/
|
||||
extern void setup_avp_debug(FILE* fp, int* general, int* avp, int* avp_op, int* avpl, int* avpl_op) {
|
||||
|
@ -347,13 +326,10 @@ extern void setup_avp_debug(FILE* fp, int* general, int* avp, int* avp_op, int*
|
|||
**/
|
||||
extern void avp_init(void) {
|
||||
|
||||
if (avp_strings) destroy_scs_collection(avp_strings);
|
||||
avp_strings = scs_init();
|
||||
|
||||
|
||||
if ( avp_chunk ) {
|
||||
g_mem_chunk_destroy(avp_chunk);
|
||||
}
|
||||
|
||||
if ( avp_chunk ) g_mem_chunk_destroy(avp_chunk);
|
||||
avp_chunk = g_mem_chunk_new("avp_chunk", sizeof(any_avp_type),
|
||||
AVP_CHUNK_SIZE, G_ALLOC_AND_FREE);
|
||||
|
||||
|
@ -965,106 +941,6 @@ extern AVPL* new_avpl_from_avpl(guint8* name, AVPL* avpl, gboolean copy_avps) {
|
|||
return newavpl;
|
||||
}
|
||||
|
||||
|
||||
#define TRANS_NUM '-': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '0'
|
||||
|
||||
/* BROKEN, makes no sense right now */
|
||||
/* FIXME: Use subscribe/unsubscribe */
|
||||
#if 0
|
||||
static AVP* avp_transform(AVP* src, AVP* op) {
|
||||
unsigned int i;
|
||||
guint8 c;
|
||||
|
||||
GString* replace_str = NULL;
|
||||
GString* num_str = NULL;
|
||||
GString* return_str = NULL;
|
||||
guint8* v;
|
||||
long num = 0;
|
||||
|
||||
enum _tranf_state {
|
||||
START,
|
||||
IN_NUM,
|
||||
IN_REPLACE,
|
||||
END
|
||||
} state;
|
||||
|
||||
state = START;
|
||||
|
||||
for(i = 0; i < strlen(op->v); i++) {
|
||||
c= op->v[i];
|
||||
|
||||
if (state == END) break;
|
||||
|
||||
switch(state) {
|
||||
case START:
|
||||
switch(c) {
|
||||
case '{':
|
||||
num_str = g_string_new("");
|
||||
state = IN_NUM;
|
||||
continue;
|
||||
default:
|
||||
continue;
|
||||
};
|
||||
case IN_NUM:
|
||||
switch(c) {
|
||||
case TRANS_NUM:
|
||||
g_string_append_c(num_str,c);
|
||||
continue;
|
||||
case ':':
|
||||
num = strtol(num_str->str,NULL,10);
|
||||
g_string_free(num_str,TRUE);
|
||||
replace_str = g_string_new("");
|
||||
state = IN_REPLACE;
|
||||
continue;
|
||||
default:
|
||||
/* will ignore any char that is not a number */
|
||||
continue;
|
||||
};
|
||||
case IN_REPLACE:
|
||||
switch(c) {
|
||||
case '\\':
|
||||
continue;
|
||||
case '}':
|
||||
state = END;
|
||||
continue;
|
||||
default :
|
||||
g_string_append_c(replace_str,c);
|
||||
continue;
|
||||
}
|
||||
case END:
|
||||
/* it will never reach */
|
||||
continue;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
v = src->v;
|
||||
|
||||
if (num > 0) {
|
||||
return_str = g_string_new(v);
|
||||
g_string_erase(return_str,0,num);
|
||||
g_string_prepend(return_str,replace_str->str);
|
||||
} else if (num < 0) {
|
||||
return_str = g_string_new(v);
|
||||
g_string_truncate(return_str,return_str->len+num);
|
||||
g_string_append(return_str,replace_str->str);
|
||||
|
||||
} else {
|
||||
return_str = g_string_new(replace_str->str);
|
||||
}
|
||||
|
||||
g_mem_chunk_free(avp_chunk,v);
|
||||
g_string_free(replace_str,TRUE);
|
||||
|
||||
src->o = '=';
|
||||
src->v = return_str->str;
|
||||
g_string_free(return_str,FALSE);
|
||||
|
||||
return src;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* match_avp:
|
||||
* @src: an src to be compared agains an "op" avp
|
||||
|
@ -1796,8 +1672,7 @@ extern LoAL* loal_from_file(guint8* filename) {
|
|||
|
||||
#ifndef _WIN32
|
||||
if (! getuid()) {
|
||||
g_warning( "MATE Will not run as root");
|
||||
return NULL;
|
||||
return load_loal_error(fp,loal,curr,linenum,"MATE Will not run as root");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -1808,6 +1683,7 @@ extern LoAL* loal_from_file(guint8* filename) {
|
|||
|
||||
if ( feof(fp) ) {
|
||||
if ( ferror(fp) ) {
|
||||
report_read_failure(filename,errno);
|
||||
return load_loal_error(fp,loal,curr,linenum,"Error while reading '%f'",filename);
|
||||
}
|
||||
break;
|
||||
|
@ -1940,6 +1816,7 @@ extern LoAL* loal_from_file(guint8* filename) {
|
|||
return loal;
|
||||
|
||||
} else {
|
||||
report_open_failure(filename,errno,FALSE);
|
||||
return load_loal_error(NULL,loal,NULL,0,"Cannot Open file '%s'",filename);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
# sip.mate
|
||||
# $Id$
|
||||
|
||||
Action=PduDef; Name=sip_pdu; Proto=sip_pdu; Transport=tcp/ip; addr=ip.addr; port=tcp.port; sip_method=sip.Method; sip_callid=sip.Call-ID; calling=sdp.owner.username;
|
||||
Action=PduDef; Name=sip_pdu; Proto=sip; Transport=tcp/ip; addr=ip.addr; port=tcp.port; sip_method=sip.Method; sip_callid=sip.Call-ID; calling=sdp.owner.username;
|
||||
Action=GopDef; Name=sip_leg; On=sip_pdu; addr; addr; port; port;
|
||||
Action=GopStart; For=sip; sip_method=INVITE;
|
||||
Action=GopStop; For=sip; sip_method=BYE;
|
||||
Action=GopStart; For=sip_leg; sip_method=INVITE;
|
||||
Action=GopStop; For=sip_leg; sip_method=BYE;
|
||||
|
||||
Action=PduDef; Name=sip_trunk_pdu; Proto=sip; Transport=udp/ip; addr=ip.addr; port=udp.port; sip_method=sip.Method; sip_callid=sip.Call-ID; calling=sdp.owner.username;
|
||||
Action=GopDef; Name=sip_trunk_leg; On=sip_pdu; addr; addr; sip_callid;
|
||||
Action=GopStart; For=sip_trunk_leg; sip_method=INVITE;
|
||||
Action=GopStop; For=sip_trunk_leg; sip_method=BYE;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ static mate_config* mc = NULL;
|
|||
static int proto_mate = -1;
|
||||
|
||||
static char* pref_mate_config_filename = "";
|
||||
static char* current_mate_config_filename = NULL;
|
||||
|
||||
static proto_item *mate_i = NULL;
|
||||
|
||||
|
@ -223,7 +224,7 @@ extern void mate_tree(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
|
|||
|
||||
if ( ! mc || ! tree ) return;
|
||||
|
||||
analyze_frame(pinfo,tree);
|
||||
mate_analyze_frame(pinfo,tree);
|
||||
|
||||
if (( pdus = mate_get_pdus(pinfo->fd->num) )) {
|
||||
for ( ; pdus; pdus = pdus->next_in_frame) {
|
||||
|
@ -261,12 +262,20 @@ proto_reg_handoff_mate(void)
|
|||
{
|
||||
if ( *pref_mate_config_filename != '\0' ) {
|
||||
|
||||
mc = mate_make_config(pref_mate_config_filename);
|
||||
if (current_mate_config_filename) {
|
||||
report_failure("Mate cannot reconfigure itself.\n"
|
||||
"for changes to be applied you have to save the preferences and restart ethereal\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (mc) {
|
||||
proto_register_field_array(proto_mate, (hf_register_info*) mc->hfrs->data, mc->hfrs->len );
|
||||
proto_register_subtree_array((gint**) mc->ett->data, mc->ett->len);
|
||||
register_init_routine(init_mate);
|
||||
if (!mc) {
|
||||
mc = mate_make_config(pref_mate_config_filename);
|
||||
current_mate_config_filename = pref_mate_config_filename;
|
||||
if (mc) {
|
||||
proto_register_field_array(proto_mate, (hf_register_info*) mc->hfrs->data, mc->hfrs->len );
|
||||
proto_register_subtree_array((gint**) mc->ett->data, mc->ett->len);
|
||||
register_init_routine(init_mate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue