2 libfmail: IPC mechanism
4 Copyright (C) 2007 Carlos Daniel Ruvalcaba Valenzuela <clsdaniel@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include <libfmail/ipc.h>
27 #include <libfmail/socket.h>
29 class SocketIPC
: public IPC
{
40 re
= odk_regex_new("([\\w\\d\\.]+)\\:(\\d*)[/]*(\\w*)", 0, 0);
41 m
= odk_regex_match(re
, uri
, 0);
43 str
= odk_submatch_copy(uri
, m
, 0);
45 printf("Host: %s\n", str
);
49 str
= odk_submatch_copy(uri
, m
, 1);
51 printf("Host: %s\n", str
);
56 str
= odk_submatch_copy(uri
, m
, 2);
58 printf("Options: %s\n", str
);
62 printf("Started socket on: %s\n", uri
);
67 sock
->Connect(host
, port
);
73 auxsock
= sock
->Accept();
82 int BeginMessage(char *msgname
){
83 sock
->Write("CMD:", 4);
84 sock
->Write(msgname
, strlen(msgname
));
85 sock
->Write("END", 3);
87 int MessageParam(char *paramname
, char *param
){
88 sock
->Write("PARM:", 5);
89 sock
->Write(paramname
, strlen(paramname
));
90 sock
->Write("END", 3);
91 sock
->Write("PARD:", 5);
92 sock
->Write(param
, strlen(param
));
93 sock
->Write("END", 3);
96 sock
->Write("FINISH", 3);
99 char *RetrieveMessage(){
101 char *GetParam(char *paramname
){
107 IPC
*IPC::CreateIPC(char *ipc_uri
){
114 re
= odk_regex_new("([\\w\\a]+)\\:\\/\\/([\\w\\a.\\/\\:]*)", 0, 0);
116 if (!odk_regex_validate(re
, ipc_uri
)){
117 printf("Invalid URI!\n");
120 m
= odk_regex_match(re
, ipc_uri
, 0);
127 str
= odk_submatch_copy(ipc_uri
, m
, 0);
133 if (!strcmp("socket", str
)){
134 printf("Got Socket!\n");
135 uri
= odk_submatch_copy(ipc_uri
, m
, 1);
136 ret
= new SocketIPC(uri
);