From f966aca11a4959369e890405fc2f007222781ef0 Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Fri, 20 Jul 2007 00:42:56 -0700 Subject: [PATCH] Removed odkUtils dependency from IPC code, we now use pcre-cpp for Regular Expresions --- include/libfmail/socketipc.h | 2 -- src/ipc.cpp | 27 ++++++++------------------- src/socketipc.cpp | 40 ++++++++++------------------------------ 3 files changed, 18 insertions(+), 51 deletions(-) diff --git a/include/libfmail/socketipc.h b/include/libfmail/socketipc.h index b690b14..551e543 100644 --- a/include/libfmail/socketipc.h +++ b/include/libfmail/socketipc.h @@ -24,8 +24,6 @@ class SocketIPC : public IPC{ Socket *sock; Socket *auxsock; queue msgQueue; - odkRegex *re; - odkRegMatch *m; public: SocketIPC(Socket *s); SocketIPC(char *uri); diff --git a/src/ipc.cpp b/src/ipc.cpp index 6ced024..80d58bc 100644 --- a/src/ipc.cpp +++ b/src/ipc.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#include +#include #include @@ -33,36 +33,25 @@ with this program; if not, write to the Free Software Foundation, Inc., IPC *IPC::CreateIPC(char *ipc_uri){ - odkRegex *re; - odkRegMatch *m; char *str, *uri; IPC *ret; int i; + string proto, opts; + + pcrecpp::RE re("([\\w\\a]+)\\:\\/\\/([\\w\\a.\\/\\:]*)"); - re = odk_regex_new("([\\w\\a]+)\\:\\/\\/([\\w\\a.\\/\\:]*)", 0, 0); - - if (!odk_regex_validate(re, ipc_uri)){ + if (!re.FullMatch(ipc_uri, &proto, &opts)){ printf("Invalid URI!\n"); return NULL; } - m = odk_regex_match(re, ipc_uri, 0); - - if (m == NULL){ - printf("No MATCH!"); - return NULL; - } - - str = odk_submatch_copy(ipc_uri, m, 0); - if (str == NULL){ - printf("ERROR!\n"); - } + str = (char*)proto.c_str(); if (!strcmp("socket", str)){ printf("Got Socket!\n"); - uri = odk_submatch_copy(ipc_uri, m, 1); + uri = (char*)opts.c_str(); ret = new SocketIPC(uri); } - free(str); + return ret; } diff --git a/src/socketipc.cpp b/src/socketipc.cpp index fa4a3e2..36c18e8 100644 --- a/src/socketipc.cpp +++ b/src/socketipc.cpp @@ -22,7 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include -#include +#include #include @@ -33,41 +33,21 @@ with this program; if not, write to the Free Software Foundation, Inc., SocketIPC::SocketIPC(Socket *s){ sock = s; - re = odk_regex_new("(\\w+)\\[(\\d+)\\]\\[(\\d+)\\]", 0, 0); } SocketIPC::SocketIPC(char *uri){ char *str; - - re = odk_regex_new("([\\w\\d\\.]+)\\:(\\d*)[/]*(\\w*)", 0, 0); - m = odk_regex_match(re, uri, 0); - - str = odk_submatch_copy(uri, m, 0); - if (str){ - printf("Host: %s\n", str); - host = str; - } - - str = odk_submatch_copy(uri, m, 1); - if (str){ - port = atoi(str); - printf("Port: %i\n", port); - free(str); - } - - str = odk_submatch_copy(uri, m, 2); - if (str){ - printf("Options: %s\n", str); - free(str); - } - + string shost; + string options; + pcrecpp::RE re("([\\w\\d\\.]+)\\:(\\d*)[/]*(\\w*)"); + + re.FullMatch(uri, &shost, &port, &options); + host = (char*)shost.c_str(); + printf("Started socket on: %s\n", uri); - sock = new Socket(); + printf("Host: %s\nPort: %i\n", host, port); + sock = new Socket(); auxsock = NULL; - odk_regex_free(re); - odk_match_free(m); - - re = odk_regex_new("(\\w+)\\[(\\d+)\\]\\[(\\d+)\\]", 0, 0); } int SocketIPC::RequestIPC(){ -- 2.11.4.GIT