From 103c18ade58f4321e80c619ef4c93b068728884f Mon Sep 17 00:00:00 2001 From: fcolin Date: Thu, 1 Feb 2007 13:00:31 +0000 Subject: Utilisateur : Fcolin Date : 1/06/06 Heure : 15:54 Archivé dans $/Bus/Ivy Commentaire: Separation module de traitement regexp (vss 32) --- Bus/Ivy/IvyApplication.cxx | 92 +++++++++++----------------------------------- 1 file changed, 21 insertions(+), 71 deletions(-) (limited to 'Bus/Ivy/IvyApplication.cxx') diff --git a/Bus/Ivy/IvyApplication.cxx b/Bus/Ivy/IvyApplication.cxx index c3f6f02..53341bc 100644 --- a/Bus/Ivy/IvyApplication.cxx +++ b/Bus/Ivy/IvyApplication.cxx @@ -4,7 +4,7 @@ #include "IvyStdAfx.h" #include "IvyApplication.h" - +#include "IvyBinding.h" //#define IVY_DEBUG @@ -52,11 +52,7 @@ IvyApplication::~IvyApplication() { // bus->RemoveApplication( this ); for ( unsigned int i = 0; i < regexp_in.size(); i++) -#ifdef USE_PCRE - pcre_free( regexp_in[i] ); -#else delete regexp_in[i]; -#endif regexp_in.clear(); if ( m_hSocket != INVALID_SOCKET ) Close(); @@ -100,18 +96,13 @@ void IvyApplication::OnReceive(char * line) char *arg; int argc = 0; char *arg_ptr; - -#ifdef USE_PCRE - pcre *exp; + static const int max_subexp = 200; const char *argv[max_subexp]; - const char *errmsg; - int erroffset; -#else - Regexp *exp; - const char *argv[Regexp::NSUBEXP]; -#endif - + IvyBinding *exp; + int erroffset; + const char *errmsg; + #ifdef IVY_DEBUG TRACE("Receive %s\n",line); #endif //IVY_DEBUG @@ -152,7 +143,7 @@ void IvyApplication::OnReceive(char * line) TRACE("Regexp id=%d exp='%s'\n", id, arg); #endif //IVY_DEBUG - if ( !bus->CheckRegexp( arg ) ) + if ( !IvyBinding::Filter( arg ) ) { #ifdef IVY_DEBUG TRACE("Warning exp='%s' can't match removing from %s\n",arg,appname.c_str()); @@ -160,9 +151,8 @@ void IvyApplication::OnReceive(char * line) bus->CallBindingFilterCallback( this, id, arg ); return; } -#ifdef USE_PCRE - exp = pcre_compile( arg, PCRE_CASELESS, &errmsg, &erroffset, NULL ); - if ( !exp ) + exp = new IvyBinding(); + if ( !exp->Compile(arg, &erroffset, &errmsg ) ) { ivy::string errstr( "Error can't compile regexp '" ); errstr += arg; @@ -170,21 +160,10 @@ void IvyApplication::OnReceive(char * line) errstr += errmsg; SendMsg( Error, Error, errstr.c_str() ); TRACE("IvyApplication %s\n",errstr.c_str()); + delete exp; return; } -#else - exp = new Regexp( arg ); - if ( !exp->CompiledOK() ) - { - ivy::string err( "Error can't compile regexp '" ); - err += arg; - err += "' error "; - err += exp->GetErrorString(); - SendMsg( Error, Error, err.c_str() ); - TRACE("IvyApplication %s\n",err.c_str()); - return; - } -#endif + if ( regexp_in.size() < (id + 1) ) { regexp_in.resize( id + 1 ); @@ -206,11 +185,8 @@ void IvyApplication::OnReceive(char * line) { exp = regexp_in[ id ]; bus->CallBindingRemoveCallback( this, id, regexp_str_in[id].c_str() ); -#ifdef USE_PCRE - pcre_free( exp ); -#else + delete exp; -#endif regexp_in[ id ] = NULL; } break; @@ -325,11 +301,7 @@ void IvyApplication::OnClose(int nErrorCode) bus->CallApplicationDisconnectedCallback( this ); for ( unsigned int i = 0; i < regexp_in.size(); i++) -#ifdef USE_PCRE - pcre_free( regexp_in[i] ); -#else delete regexp_in[i]; -#endif regexp_in.clear(); Close(); //bus->RemoveApplication( this ); @@ -338,51 +310,29 @@ void IvyApplication::OnClose(int nErrorCode) int IvyApplication::SendMsg(const char *message) { int count = 0; -#ifdef USE_PCRE - pcre *exp; - int ovector[max_subexp*3]; -#else - Regexp *exp; -#endif + IvyBinding *exp; + /* send to already connected */ for ( unsigned int i = 0; i < regexp_in.size(); i++ ) { exp = regexp_in[i]; -#ifdef USE_PCRE - int match_count = pcre_exec( exp, NULL, message, (int) strlen( message ), 0, 0, ovector, max_subexp ); + int match_count = exp->Exec( message ); if ( match_count > 0 ) { ivy::string buffer; - const char **substring; - int err = pcre_get_substring_list(message,ovector, match_count, &substring); - if ( err != 0 ) - { - SendMsg( Error, Error, "Memory Alloc Error" ); - } - else { + int arglen; + const char *arg; + for ( int j = 1; j < match_count; j++ ) { - buffer += substring[j]; + exp->Match(message, j, &arglen, &arg); + buffer += arg; buffer += ARG_END; } - pcre_free_substring_list(substring); SendMsg( Msg, i, buffer.c_str() ); count++; - } } -#else - if ( exp && exp->Match( message ) ) - { - ivy::string buffer; - for ( int j = 1; j < exp->SubStrings()+1; j++ ) - { - buffer += (*exp)[j]; - buffer += ARG_END; - } - SendMsg( Msg, i, buffer.c_str() ); - count++; - } -#endif + } return count; } -- cgit v1.1