From 030449c41866c03c435e779bb27e4d9e6d2aea56 Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Fri, 20 Jul 2007 01:00:22 -0700 Subject: [PATCH] Cut down odkUtils dependency, added standard pcrecpp --- backends/auth/fsauth.cpp | 1 - backends/mailbox/fsmailbox.cpp | 27 ++++++++++++++++++++++++--- backends/protocol/pop3.cpp | 31 ++++++++++--------------------- backends/protocol/smtp.cpp | 2 +- compile.sh | 12 ++++-------- src/ipcmsg.cpp | 13 ++++++++++++- 6 files changed, 51 insertions(+), 35 deletions(-) diff --git a/backends/auth/fsauth.cpp b/backends/auth/fsauth.cpp index b6de284..bd859e8 100644 --- a/backends/auth/fsauth.cpp +++ b/backends/auth/fsauth.cpp @@ -1,6 +1,5 @@ #include -#include #include int Server_onRun; diff --git a/backends/mailbox/fsmailbox.cpp b/backends/mailbox/fsmailbox.cpp index 572d951..674fed6 100644 --- a/backends/mailbox/fsmailbox.cpp +++ b/backends/mailbox/fsmailbox.cpp @@ -1,7 +1,7 @@ -#include #include #include +#include int knhash(char v){ if ((v >= 65) && (v <= 90)) @@ -19,14 +19,18 @@ private: public: FSMailbox(){ cmdtree.Insert("listmail", 1); - cmdtree.Insert("sendmail", 2); + cmdtree.Insert("mailinfo", 2); + cmdtree.Insert("sendmail", 3); + cmdtree.Insert("retr", 4); } int Handle(Socket *s){ IPCMessage *msg; IPC *ipc; - int onRun, msgid; + int onRun, msgid, n, i; char *user, *pass, buffer[255], auxbuffer[255]; FILE *fd; + DIR *dir; + struct dirent **dent; printf("Got Client\n"); printf("Creating new IPC\n"); @@ -46,9 +50,26 @@ public: } switch(msgid){ case 1: + user = msg->PopParam(); + sprintf(buffer, "/tmp/fmail/%s/", user); + n = scandir(buffer, &dent, NULL, alphasort); + sprintf(buffer, "%i", n); + msg = new IPCMessage("ok"); + msg->PushParam(buffer); + ipc->PushMessage(msg); + for (i = 0; i < n; i++){ + msg = new IPCMessage("mailinfo"); + msg->PushParam(dent[i]->d_name); + free(dent[i]); + } + free(dent); break; case 2: break; + case 3: + break; + case 4: + break; default: break; } diff --git a/backends/protocol/pop3.cpp b/backends/protocol/pop3.cpp index 80b4b81..36ba448 100644 --- a/backends/protocol/pop3.cpp +++ b/backends/protocol/pop3.cpp @@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include -#include +#include char *demomsg = "From: Test John \n" "To: test@localhost\n" @@ -88,6 +88,7 @@ public: cmdtree.Insert("RSET", 9); cmdtree.Insert("TOP", 10); cmdtree.Insert("CAPA", 11); + printf("SearchTree Memory Usage: %i bytes\n", cmdtree.getTreeSize()); } int Handle(Socket *s){ char buffer[255]; @@ -95,23 +96,18 @@ public: char outbuff[255]; int r, i, j; int onrun, cmd, state; - odkRegex *reg; - odkRegMatch *m; IPC *ipc; IPCMessage *msg; - char *user, *pass; + string user, pass; + pcrecpp::RE reg("[\\w\\a]*\\s([\\w\\a]*)"); ipc = IPC::CreateIPC("socket://127.0.0.1:14000"); - reg = odk_regex_new("[\\w\\a]*\\s([\\w\\a]*)", 0, 0); s->Write("+OK FancyMail v0.1", 18); s->Write(CRLF, 2); state = STATE_AUTH; - user = NULL; - pass = NULL; - onrun = 1; while (onrun){ @@ -134,11 +130,8 @@ public: switch (state){ case STATE_AUTH: if (cmd == CMD_USER){ - - m = odk_regex_match(reg, buffer, 0); - user = odk_submatch_copy(buffer, m, 0); - printf("Got USERNAME: %s\n", user); - odk_match_free(m); + reg.FullMatch(buffer, &user); + printf("Got USERNAME: %s\n", user.c_str()); s->Write( "+OK", 3); s->Write( CRLF, 2); @@ -151,13 +144,9 @@ public: break; case STATE_AUTH2: if (cmd == CMD_PASS){ + reg.FullMatch(buffer, &pass); - m = odk_regex_match(reg, buffer, 0); - - pass = odk_submatch_copy(buffer, m, 0); - odk_match_free(m); - - printf("Got Password: %s\n", pass); + printf("Got Password: %s\n", pass.c_str()); i = 0; while (i < 10){ @@ -166,8 +155,8 @@ public: } msg = new IPCMessage("auth"); - msg->PushParam(user); - msg->PushParam(pass); + msg->PushParam((char*)user.c_str()); + msg->PushParam((char*)pass.c_str()); ipc->PushMessage(msg); while(ipc->PeekMessage() == 0){ diff --git a/backends/protocol/smtp.cpp b/backends/protocol/smtp.cpp index 25d7931..13fa55c 100644 --- a/backends/protocol/smtp.cpp +++ b/backends/protocol/smtp.cpp @@ -64,7 +64,7 @@ public: cmdtree.Insert("RSET", 7); } int Handle(Socket *s){ - char buffer[255], username[255]; + char buffer[255], username[255], recipent[255]; int r, l; int onrun, cmd, state; FILE *fd; diff --git a/compile.sh b/compile.sh index 2e0600b..9c05b3e 100755 --- a/compile.sh +++ b/compile.sh @@ -4,7 +4,7 @@ rm -fr bin mkdir -p bin -CFLAGS="-g `odkutils-config --cflags`" +CFLAGS="-g" echo "Compiling libfmail" g++ src/baseserver.cpp -I./include ${CFLAGS} -c -o bin/baseserver.o @@ -21,13 +21,9 @@ g++ bin/baseserver.o bin/socket.o bin/socketipc.o bin/ipc.o bin/ipcmsg.o -lpcrec #g++ testcase/ipctest.cpp -lfmail -g -I./include -L./bin -o bin/ipctest #g++ testcase/ipccommand.cpp -lfmail -g -I./include -L./bin -o bin/ipccommand -echo "Compiling Protocols" -g++ backends/protocol/pop3.cpp -lstdc++ `odkutils-config --libs --cflags` -I./include -L./bin -lfmail -shared ${CFLAGS} -o bin/libfmail-pop3.so -g++ backends/protocol/smtp.cpp -lstdc++ -I./include -L./bin -lfmail -shared ${CFLAGS} -o bin/libfmail-smtp.so +echo "Compiling Servers" g++ backends/auth/fsauth.cpp -lstdc++ -I./include -L./bin -lfmail `odkutils-config --libs` ${CFLAGS} -o bin/fmail-fsauth g++ backends/mailbox/fsmailbox.cpp -lstdc++ -I./include -L./bin -lfmail `odkutils-config --libs` ${CFLAGS} -o bin/fmail-fsmailbox -echo "Compiling FancyMail Server" -g++ src/fmail.cpp -I./include -L./bin -lfmail -lstdc++ `odkutils-config --libs` ${CFLAGS} -o bin/fmail -g++ backends/protocol/pop3.cpp -I./include -L./bin -lfmail -lstdc++ `odkutils-config --libs` ${CFLAGS} -DSTANDALONE -o bin/fmail-pop3 -g++ backends/protocol/smtp.cpp -I./include -L./bin -lfmail -lstdc++ `odkutils-config --libs` ${CFLAGS} -DSTANDALONE -o bin/fmail-smtp +g++ backends/protocol/pop3.cpp -I./include -L./bin -lfmail -lstdc++ -lpcrecpp ${CFLAGS} -DSTANDALONE -o bin/fmail-pop3 +g++ backends/protocol/smtp.cpp -I./include -L./bin -lfmail -lstdc++ -lpcrecpp ${CFLAGS} -DSTANDALONE -o bin/fmail-smtp diff --git a/src/ipcmsg.cpp b/src/ipcmsg.cpp index 6fa0c1d..e463405 100644 --- a/src/ipcmsg.cpp +++ b/src/ipcmsg.cpp @@ -22,11 +22,22 @@ with this program; if not, write to the Free Software Foundation, Inc., #include #include #include -#include #include #include +char *strcopy(char *s){ + char *ret; + int l; + + l = strlen(s); + ret = (char*)malloc(sizeof(char) * (l + 1)); + + strcpy(ret, s); + + return ret; +} + IPCMessage::IPCMessage(char *msgname){ msghead = strcopy(msgname); } -- 2.11.4.GIT