From 51399e50ffa1a124d43851d0b0b80e757013a04a Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Fri, 22 Jun 2007 10:38:47 -0700 Subject: [PATCH] Moved pop3 to SearchTree --- src/ipc.cpp | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/ipc.cpp diff --git a/src/ipc.cpp b/src/ipc.cpp new file mode 100644 index 0000000..3d224c4 --- /dev/null +++ b/src/ipc.cpp @@ -0,0 +1,140 @@ +/* +libfmail: IPC mechanism + +Copyright (C) 2007 Carlos Daniel Ruvalcaba Valenzuela + +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., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include +#include +#include + +#include +#include +#include + +class SocketIPC : public IPC{ + char *host; + int port; + Socket *sock; + Socket *auxsock; +public: + SocketIPC(char *uri){ + odkRegex *re; + odkRegMatch *m; + 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){ + printf("Host: %s\n", str); + port = atoi(str); + free(str); + } + + str = odk_submatch_copy(uri, m, 2); + if (str){ + printf("Options: %s\n", str); + free(str); + } + + printf("Started socket on: %s\n", uri); + sock = Socket(); + auxsock = NULL; + } + int RequestIPC(){ + sock->Connect(host, port); + } + int ListenIPC(){ + sock->Bind(port); + sock->Listen(1); + + auxsock = sock->Accept(); + return 0; + } + int CloseIPC(){ + sock->Close(); + if (auxsock) + auxsock->Close(); + } + + int BeginMessage(char *msgname){ + sock->Write("CMD:", 4); + sock->Write(msgname, strlen(msgname)); + sock->Write("END", 3); + } + int MessageParam(char *paramname, char *param){ + sock->Write("PARM:", 5); + sock->Write(paramname, strlen(paramname)); + sock->Write("END", 3); + sock->Write("PARD:", 5); + sock->Write(param, strlen(param)); + sock->Write("END", 3); + } + int EndMessage(){ + sock->Write("FINISH", 3); + } + + char *RetrieveMessage(){ + } + char *GetParam(char *paramname){ + } + int DeleteMessage(){ + } +}; + +IPC *IPC::CreateIPC(char *ipc_uri){ + odkRegex *re; + odkRegMatch *m; + char *str, *uri; + IPC *ret; + int i; + + re = odk_regex_new("([\\w\\a]+)\\:\\/\\/([\\w\\a.\\/\\:]*)", 0, 0); + + if (!odk_regex_validate(re, ipc_uri)){ + 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"); + } + + if (!strcmp("socket", str)){ + printf("Got Socket!\n"); + uri = odk_submatch_copy(ipc_uri, m, 1); + ret = new SocketIPC(uri); + } + free(str); + return ret; +} -- 2.11.4.GIT