3 #include <libfmail/socketipc.h>
7 class InternalHandler
: public ProtocolHandler
{
15 ipc
= new SocketIPC(s
);
18 if (ipc
->PeekMessage()){
19 msg
= ipc
->PopMessage();
21 if (!strcmp(msg
->GetMessageName(), "shutdown")){
34 class FSAuth
: public ProtocolHandler
{
36 int Handle(Socket
*s
){
40 char *user
, *pass
, buffer
[255], auxbuffer
[255];
43 printf("Got Client\n");
44 printf("Creating new IPC\n");
46 ipc
= new SocketIPC(s
);
50 printf("Waiting for Message\n");
51 if (ipc
->PeekMessage()){
52 printf("Got Message\n");
53 msg
= ipc
->PopMessage();
55 if (!strcmp(msg
->GetMessageName(), "auth")){
56 printf("Got Auth Request\n");
57 user
= msg
->PopParam();
58 pass
= msg
->PopParam();
61 printf("Authenticating %s : %s\n", user
, pass
);
63 sprintf(buffer
, "/tmp/fmail/%s.passwd", user
);
64 fd
= fopen(buffer
, "r");
66 msg
= new IPCMessage("failed");
68 memset(auxbuffer
, 0, 255);
69 fread(auxbuffer
, 1, 255, fd
);
71 if (!strcmp(pass
, auxbuffer
)){
72 msg
= new IPCMessage("failed");
74 msg
= new IPCMessage("authok");
77 ipc
->PushMessage(msg
);
90 class SimpleLoad
: public LoadHandler
{
92 int Dispatch(Socket
*sock
, ProtocolHandler
*ph
){
93 printf("SimpleLoad: Dispatching\n");
95 return ph
->Handle(sock
);
101 BaseServer
*serv
, *serv_conf
;
106 printf("Creating new FSAuth\n");
107 fsauth
= new FSAuth();
108 ih
= new InternalHandler();
110 printf("Creating new SimpleLoad\n");
111 lh
= new SimpleLoad();
113 printf("Creating new BaseServer\n");
114 serv
= new BaseServer(fsauth
, 14000);
115 serv_conf
= new BaseServer(ih
, 13000);
117 printf("Setting Load Handler\n");
118 serv
->SetLoadhandler(lh
);
119 serv_conf
->SetLoadhandler(lh
);
121 printf("Listening\n");