From ae45d46c874f99b6396c8c6c751c367937269c82 Mon Sep 17 00:00:00 2001 From: Carlos Daniel Ruvalcaba Valenzuela Date: Sat, 6 Oct 2007 02:57:21 -0700 Subject: [PATCH] Fixed missing closing of client socket, minor cleanups --- backends/protocol/smtp.cpp | 56 +++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/backends/protocol/smtp.cpp b/backends/protocol/smtp.cpp index 4089c0b..bc6a1cf 100644 --- a/backends/protocol/smtp.cpp +++ b/backends/protocol/smtp.cpp @@ -94,38 +94,38 @@ public: while (onrun){ /* Wait for client input */ - memset(buffer, 0, 255); - r = s->Read(buffer, 255); + memset(buffer, 0, 255); + r = s->Read(buffer, 255); /* Find the given command on our search tree */ - try{ - cmd = cmdtree.Lookup(buffer); - }catch (SearchNotFound){ - cmd = -1; - } + try{ + cmd = cmdtree.Lookup(buffer); + }catch (SearchNotFound){ + cmd = -1; + } - switch(cmd){ - case CMD_HELO: + switch(cmd){ + case CMD_HELO: /* We got normal SMTP HELO, write response */ - s->Write("250 ok localhost", 16); - s->Write(CRLF, 2); + s->Write("250 ok localhost", 16); + s->Write(CRLF, 2); /* Client presented itself, we can accept other * commands, we pass to state 1 */ - state = 1; - break; - case CMD_EHLO: + state = 1; + break; + case CMD_EHLO: /* We still not support ESMTP, write not implemented */ - s->Write( "502 Not implemented", 19); - s->Write( CRLF, 2); - break; - case CMD_MAIL: + s->Write( "502 Not implemented", 19); + s->Write( CRLF, 2); + break; + case CMD_MAIL: /* Check if we had the proper greeting */ - if (state != 1){ - s->Write( "502 Not implemented", 19); - s->Write( CRLF, 2); - break; - } + if (state != 1){ + s->Write( "502 Not implemented", 19); + s->Write( CRLF, 2); + break; + } /* Extract the command mail from data */ ret = reCmd.PartialMatch(buffer, &mailfrom); @@ -165,7 +165,6 @@ public: s->Write( "354 OK", 6); s->Write( CRLF, 2); - /* Request a slot */ msg = new IPCMessage("slot"); msg->PushParam("incoming"); @@ -184,7 +183,6 @@ public: fd = NULL; fd = fopen(slotname, "w"); - free(slotname); if (fd == NULL){ printf("Error: Unable to open destination SLOT\n"); @@ -222,7 +220,9 @@ public: msg->PushParam("incoming"); msg->PushParam(slotname); ipc->SendMessage(msg); + delete msg; + free(slotname); s->Write( "250 OK", 6); s->Write( CRLF, 2); @@ -238,6 +238,7 @@ public: state = 1; break; case CMD_QUIT: + printf("GOT QUIT\n"); s->Write( "221 Exiting", 11); s->Write(CRLF, 2); @@ -257,6 +258,9 @@ public: msg = new IPCMessage("quit"); ipc->SendMessage(msg); ipc->CloseIPC(); + + s->Close(); + return 0; } }; @@ -319,8 +323,10 @@ int main(){ ret = s->Poll(1000000, SOCKET_POLL_READ | SOCKET_POLL_ERROR); if (ret & SOCKET_POLL_READ){ /* Accept client and dispatch */ + printf("Dispatching Client\n"); cl = s->Accept(); lh->Dispatch(cl, handler); + printf("On to next client!\n"); }else if(ret & SOCKET_POLL_ERROR){ //error return -1; }else{ //timeout -- 2.11.4.GIT