idms-dbma-devel Mailing List for IDMS Damn Best Mail Agent (Page 3)
Status: Pre-Alpha
Brought to you by:
nkukard
You can subscribe to this list here.
| 2003 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
(1) |
Sep
|
Oct
|
Nov
|
Dec
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2004 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
(2) |
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(21) |
Nov
|
Dec
(2) |
| 2005 |
Jan
(2) |
Feb
(2) |
Mar
(16) |
Apr
(12) |
May
(6) |
Jun
|
Jul
|
Aug
|
Sep
(3) |
Oct
|
Nov
|
Dec
|
|
From: <idm...@li...> - 2004-10-24 19:57:17
|
Author: nkukard
Date: 2004-10-24 21:57:07 +0200 (Sun, 24 Oct 2004)
New Revision: 54
Modified:
trunk/modules/protocols/imap4/command_lexer.l
trunk/modules/protocols/imap4/imap4.c
trunk/modules/protocols/imap4/imap4.h
trunk/modules/protocols/imap4/imap4_cmd_append.c
trunk/modules/protocols/imap4/imap4_cmd_authenticate.c
trunk/modules/protocols/imap4/imap4_cmd_capability.c
trunk/modules/protocols/imap4/imap4_cmd_check.c
trunk/modules/protocols/imap4/imap4_cmd_close.c
trunk/modules/protocols/imap4/imap4_cmd_copy.c
trunk/modules/protocols/imap4/imap4_cmd_create.c
trunk/modules/protocols/imap4/imap4_cmd_delete.c
trunk/modules/protocols/imap4/imap4_cmd_expunge.c
trunk/modules/protocols/imap4/imap4_cmd_fetch.c
trunk/modules/protocols/imap4/imap4_cmd_list.c
trunk/modules/protocols/imap4/imap4_cmd_login.c
trunk/modules/protocols/imap4/imap4_cmd_logout.c
trunk/modules/protocols/imap4/imap4_cmd_lsub.c
trunk/modules/protocols/imap4/imap4_cmd_noop.c
trunk/modules/protocols/imap4/imap4_cmd_rename.c
trunk/modules/protocols/imap4/imap4_cmd_search.c
trunk/modules/protocols/imap4/imap4_cmd_select.c
trunk/modules/protocols/imap4/imap4_cmd_starttls.c
trunk/modules/protocols/imap4/imap4_cmd_status.c
trunk/modules/protocols/imap4/imap4_cmd_store.c
trunk/modules/protocols/imap4/imap4_cmd_subscribe.c
trunk/modules/protocols/imap4/imap4_cmd_uid.c
trunk/modules/protocols/imap4/imap4_cmd_unsubscribe.c
Log:
* Some small changes to accomodate the socklib.c changes
* Added missing headers
* GCC warning fixes
Modified: trunk/modules/protocols/imap4/command_lexer.l
===================================================================
--- trunk/modules/protocols/imap4/command_lexer.l 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/command_lexer.l 2004-10-24 19:57:07 UTC (rev 54)
@@ -104,6 +104,7 @@
#include "command_lexer.h"
#include "command_parser.h"
#include "debug.h"
+#include "misc.h"
#define P_DEFAULT -1
@@ -181,7 +182,7 @@
};
-
+/* Various prototypes we need */
void * commandget_extra(yyscan_t yyscanner);
void commandset_extra(void * user_defined, yyscan_t yyscanner);
@@ -241,6 +242,7 @@
state->error = strdup(s);
+ return 0;
}
@@ -895,8 +897,8 @@
/* Scan in date, MUST result in res == 7 */
- if ((res = sscanf(yytext,"\"%d-%3s-%d %d:%d:%d %s\"",&tmstruct.tm_mday,&month,
- &tmstruct.tm_year,&tmstruct.tm_hour,&tmstruct.tm_min,&tmstruct.tm_sec,&zone)) == 7)
+ if ((res = sscanf(yytext,"\"%d-%3s-%d %d:%d:%d %s\"",&tmstruct.tm_mday,month,
+ &tmstruct.tm_year,&tmstruct.tm_hour,&tmstruct.tm_min,&tmstruct.tm_sec,zone)) == 7)
{
/* Set some things we can't directly parse in above */
tmstruct.tm_mon = month2int(month);
Modified: trunk/modules/protocols/imap4/imap4.c
===================================================================
--- trunk/modules/protocols/imap4/imap4.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -102,11 +102,26 @@
data->username = NULL;
data->password = NULL;
+
+ /* Check if our memory allocation succeeded */
+ if (!(data->cmdLine = malloc(IMAP4_CMD_LEN)))
+ return 1;
data->tmpBufSize = IMAP4_RESP_LEN;
- data->tmpBuf = malloc(data->tmpBufSize);
- data->tmpCmd = malloc(sizeof(struct imap4_command_t));
+ if (!(data->tmpBuf = malloc(data->tmpBufSize)))
+ {
+ free(data->cmdLine);
+ return 1;
+ }
+
+ if (!(data->tmpCmd = malloc(sizeof(struct imap4_command_t))))
+ {
+ free(data->cmdLine);
+ free(data->tmpBuf);
+ return 1;
+ }
+
data->cmdHandle = NULL;
data->storeHandle = NULL;
@@ -131,7 +146,7 @@
/* Check if we must process user input */
fprintf(stderr,"We need user input\n");
data->position = IMAP4_POS_CMD;
- queueToReceive(connection,IMAP4_CMD_LEN,(data->state ==
+ queueToReceive(connection,data->cmdLine,IMAP4_CMD_LEN,(data->state ==
IMAP4_STATE_PREAUTH ? IMAP4_IO_PREAUTH_TIMEOUT : IMAP4_IO_TIMEOUT));
/* Exit here to bypass the fallthrough queueToSend */
return 0;
@@ -142,13 +157,10 @@
static int imap4_cmd(struct clientConnection_t *connection)
{
struct imap4_data_t *data = connection->data;
- struct imap4_cmd_t *imap4_cmd;
- char *buffer;
- buffer = getIOBuffer(connection);
/* Use our gramatical parser to parse command */
- parseCommand(buffer,data->tmpCmd);
+ parseCommand(data->cmdLine,data->tmpCmd);
D_PRINT(D_DEBUG,"Got command %i",data->tmpCmd->id);
/* Check what the outcome is */
if (data->tmpCmd->id > 0)
@@ -254,7 +266,6 @@
static int imap4_handler(struct clientConnection_t *connection)
{
struct imap4_data_t *data = connection->data;
- unsigned int timeout;
struct imap4_static_cmd_t *cmd = (struct imap4_static_cmd_t *) imap4_commands;
int ioState;
Modified: trunk/modules/protocols/imap4/imap4.h
===================================================================
--- trunk/modules/protocols/imap4/imap4.h 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4.h 2004-10-24 19:57:07 UTC (rev 54)
@@ -75,6 +75,8 @@
/* Username & password client entered */
char *username;
char *password;
+ /* Command line storage */
+ char *cmdLine;
/* Temporary stuff */
struct imap4_command_t *tmpCmd; /* this we use so we don't always have to malloc() */
char *tmpBuf;
Modified: trunk/modules/protocols/imap4/imap4_cmd_append.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_append.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_append.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,8 @@
*/
#include <stdio.h>
+#include <string.h>
+#include <time.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
@@ -36,6 +38,7 @@
struct imap4_cmd_append_t
{
char *tag;
+ char *buffer;
size_t size;
size_t pos;
void *handle;
@@ -84,7 +87,9 @@
D_PRINT(D_FATAL,"Failed to allocate memory");
return IMAP4_ERROR_FATAL;
}
-
+
+ // FIXME - erro check
+ cmdState->buffer = malloc(MAX_RECV_BUFSIZE);
cmdState->tag = strdup(cmdStruct->tag);
cmdState->size = appendParam->length + 2; /* +2 for CRLF */
cmdState->handle = NULL;
@@ -113,8 +118,6 @@
{
struct imap4_data_t *data = connection->data;
struct imap4_cmd_append_t *cmdState;
- char *buffer = NULL;
- size_t read = 0;
size_t dataLeft;
@@ -127,10 +130,7 @@
/* Initialize everything */
if (cmdState->handle)
- {
- buffer = getIOBuffer(connection);
cmdState->pos += getIOBufPos(connection);
- }
else
{
/* FIXME - call storage handler and create handle to new message */
@@ -143,7 +143,8 @@
/* Accept buffer */
if (dataLeft > 0)
{
- queueToReceiveRaw(connection,(dataLeft > MAX_RECV_BUFSIZE ? MAX_RECV_BUFSIZE : dataLeft),
+ // FIXME - queue IO to file here
+ queueToReceiveRaw(connection,cmdState->buffer,(dataLeft > MAX_RECV_BUFSIZE ? MAX_RECV_BUFSIZE : dataLeft),
IMAP4_IO_TIMEOUT);
}
else
@@ -152,6 +153,7 @@
snprintf(data->tmpBuf,data->tmpBufSize,"%s OK APPEND Completed"EOL,cmdState->tag);
/* Free state information */
+ free(cmdState->buffer);
free(cmdState->tag);
free(cmdState);
data->cmdHandle = NULL;
Modified: trunk/modules/protocols/imap4/imap4_cmd_authenticate.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_authenticate.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_authenticate.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_capability.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_capability.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_capability.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "socklib.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_check.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_check.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_check.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_close.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_close.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_close.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
@@ -32,7 +33,6 @@
int imap4_cmd_close(IMAP4_CMD_PARAMS)
{
struct imap4_data_t *data = connection->data;
- char *mailbox;
/* Check if we in the right state and continue */
Modified: trunk/modules/protocols/imap4/imap4_cmd_copy.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_copy.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_copy.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_create.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_create.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_create.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_delete.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_delete.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_delete.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_expunge.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_expunge.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_expunge.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_fetch.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_fetch.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_fetch.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
@@ -48,7 +49,6 @@
/* Check if we in the right state */
if (data->state == IMAP4_STATE_SELECTED)
{
- char *dataItems;
struct imap4_cmd_fetch_t *cmdState;
@@ -97,7 +97,7 @@
/* Check that we really do have data */
if ((fRes = cmdState->listPos->data))
{
- char buffer[1024];
+ //char buffer[1024];
#if 0
/* Blank buffer */
Modified: trunk/modules/protocols/imap4/imap4_cmd_list.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_list.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_list.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_login.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_login.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_login.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_logout.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_logout.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_logout.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "socklib.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_lsub.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_lsub.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_lsub.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_noop.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_noop.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_noop.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "socklib.h"
@@ -82,7 +83,6 @@
{
struct imap4_data_t *data = connection->data;
struct imap4_cmd_noop_t *cmdState;
- char *buffer;
unsigned int i;
@@ -109,8 +109,7 @@
case POS_END:
/* Last return result we sending */
- snprintf(data->tmpBuf,data->tmpBufSize,"%s OK NOOP Completed"EOL,cmdState->tag,
- buffer);
+ snprintf(data->tmpBuf,data->tmpBufSize,"%s OK NOOP Completed"EOL,cmdState->tag);
/* Free state information */
free(cmdState->tag);
Modified: trunk/modules/protocols/imap4/imap4_cmd_rename.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_rename.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_rename.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_search.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_search.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_search.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
@@ -48,7 +49,6 @@
/* Check if we in the right state */
if (data->state == IMAP4_STATE_SELECTED)
{
- char *searchString;
struct imap4_cmd_search_t *cmdState;
Modified: trunk/modules/protocols/imap4/imap4_cmd_select.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_select.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_select.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "mailstore.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_starttls.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_starttls.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_starttls.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -22,6 +22,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "socklib.h"
@@ -32,7 +33,6 @@
int imap4_cmd_starttls(IMAP4_CMD_PARAMS)
{
struct imap4_data_t *data = connection->data;
- char *method;
/* Check if we in the correct state */
Modified: trunk/modules/protocols/imap4/imap4_cmd_status.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_status.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_status.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_store.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_store.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_store.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
@@ -48,7 +49,7 @@
/* Check if we in the right state */
if (data->state == IMAP4_STATE_SELECTED)
{
- char *dataItems;
+ //char *dataItems;
struct imap4_cmd_store_t *cmdState;
@@ -98,7 +99,7 @@
/* Check that we really do have data */
if ((fRes = cmdState->listPos->data))
{
- char buffer[1024];
+ // char buffer[1024];
#if 0
/* Blank buffer */
Modified: trunk/modules/protocols/imap4/imap4_cmd_subscribe.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_subscribe.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_subscribe.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
Modified: trunk/modules/protocols/imap4/imap4_cmd_uid.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_uid.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_uid.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
@@ -46,7 +47,7 @@
if (data->state == IMAP4_STATE_SELECTED)
{
- char *command, *criteria;
+ //char *command, *criteria;
snprintf(data->tmpBuf,data->tmpBufSize,"* 2 WHATEVER "EOL);
Modified: trunk/modules/protocols/imap4/imap4_cmd_unsubscribe.c
===================================================================
--- trunk/modules/protocols/imap4/imap4_cmd_unsubscribe.c 2004-10-24 19:50:20 UTC (rev 53)
+++ trunk/modules/protocols/imap4/imap4_cmd_unsubscribe.c 2004-10-24 19:57:07 UTC (rev 54)
@@ -23,6 +23,7 @@
*/
#include <stdio.h>
+#include <string.h>
#include "debug.h"
#include "imap4_cmds.h"
#include "misc.h"
|
|
From: <idm...@li...> - 2004-10-24 19:50:33
|
Author: nkukard
Date: 2004-10-24 21:50:20 +0200 (Sun, 24 Oct 2004)
New Revision: 53
Added:
trunk/modules/protocols/pop3/TODO
Modified:
trunk/modules/protocols/pop3/pop3.c
trunk/modules/protocols/pop3/pop3.h
Log:
* Updated to conform to socklib bugfix
Added: trunk/modules/protocols/pop3/TODO
===================================================================
--- trunk/modules/protocols/pop3/TODO 2004-10-24 17:13:30 UTC (rev 52)
+++ trunk/modules/protocols/pop3/TODO 2004-10-24 19:50:20 UTC (rev 53)
@@ -0,0 +1 @@
+* Upgrade design to new parser, lexer & single file per rfc command
Modified: trunk/modules/protocols/pop3/pop3.c
===================================================================
--- trunk/modules/protocols/pop3/pop3.c 2004-10-24 17:13:30 UTC (rev 52)
+++ trunk/modules/protocols/pop3/pop3.c 2004-10-24 19:50:20 UTC (rev 53)
@@ -50,6 +50,9 @@
data->username = NULL;
data->password = NULL;
+ // FIXME - error check
+ data->cmdLine = malloc(POP3_CMD_LEN);
+
data->tmpBufSize = POP3_RESP_LEN;
data->tmpBuf = malloc(data->tmpBufSize);
@@ -78,6 +81,8 @@
free(data->username);
if (data->password)
free(data->password);
+ if (data->cmdLine)
+ free(data->cmdLine);
free(data->tmpBuf);
free(data);
fprintf(stderr,"%s: Closing connection\n",__FUNCTION__);
@@ -89,7 +94,6 @@
static int pop3_handler(struct clientConnection_t *connection)
{
struct pop3_data_t *data = connection->data;
- char *buffer;
fprintf(stderr,"state = %i, position = %i\n",data->state,data->position);
@@ -135,7 +139,6 @@
data->state = POP3_STATE_QUIT;
goto handler_end;
}
- buffer = getIOBuffer(connection);
}
/* Check if we must process user input */
@@ -143,7 +146,7 @@
{
fprintf(stderr,"We need user input\n");
data->position = unsetBit(data->position,POP3_POS_USER_INPUT);
- queueToReceive(connection,POP3_CMD_LEN,POP3_IO_TIMEOUT);
+ queueToReceive(connection,data->cmdLine,POP3_CMD_LEN,POP3_IO_TIMEOUT);
/* Exit here to bypass the fallthrough queueToSend */
return 0;
}
@@ -394,14 +397,14 @@
/* Small check */
- if (!(cmd = get_field(buffer,0,1)))
+ if (!(cmd = get_field(data->cmdLine,0,1)))
{
snprintf(data->tmpBuf,data->tmpBufSize,"-ERR No command received"EOL);
data->position = setBit(data->position,POP3_POS_USER);
goto handler_end;
}
- D_PRINT(D_DEBUG,"Client command: %s",buffer);
+ D_PRINT(D_DEBUG,"Client command: %s",data->cmdLine);
// Find associated ID
cmd_id = -1;
// Loop and get our command!
@@ -447,7 +450,7 @@
free(data->username);
/* Check if a username wasn't supplied */
- if (!(data->username = get_field(buffer,1,1)))
+ if (!(data->username = get_field(data->cmdLine,1,1)))
snprintf(data->tmpBuf,data->tmpBufSize,"-ERR Missing username"EOL);
else
/* Tell user we have his username */
@@ -476,7 +479,7 @@
}
/* Parse off password */
- if (!(data->password = get_field(buffer,1,1)))
+ if (!(data->password = get_field(data->cmdLine,1,1)))
{
snprintf(data->tmpBuf,data->tmpBufSize,"-ERR Missing password"EOL);
goto cmd_pass_end;
@@ -559,7 +562,7 @@
}
/* Check optional parameter */
- if ((opt = get_field(buffer,1,1)))
+ if ((opt = get_field(data->cmdLine,1,1)))
{
int msgID = atoi(opt);
struct message_t *message;
@@ -639,7 +642,7 @@
}
/* Check parameter */
- if ((opt = get_field(buffer,1,1)))
+ if ((opt = get_field(data->cmdLine,1,1)))
{
int msgID = atoi(opt);
struct message_t *message;
@@ -714,7 +717,7 @@
}
/* Check parameter */
- if ((opt = get_field(buffer,1,1)))
+ if ((opt = get_field(data->cmdLine,1,1)))
{
int msgID = atoi(opt);
struct message_t *message;
@@ -819,7 +822,7 @@
}
/* Check optional parameter */
- if ((opt = get_field(buffer,1,1)))
+ if ((opt = get_field(data->cmdLine,1,1)))
{
int msgID = atoi(opt);
struct message_t *message;
@@ -888,7 +891,7 @@
}
/* Check parameter */
- if ((opt = get_field(buffer,1,1)))
+ if ((opt = get_field(data->cmdLine,1,1)))
{
int msgID = atoi(opt);
struct message_t *message;
@@ -900,7 +903,7 @@
/* Dont need this no more */
free(opt);
/* Verify number of lines to display */
- opt2 = get_field(buffer,2,1);
+ opt2 = get_field(data->cmdLine,2,1);
if (!opt2)
{
snprintf(data->tmpBuf,data->tmpBufSize,"-ERR Missing number of lines"EOL);
Modified: trunk/modules/protocols/pop3/pop3.h
===================================================================
--- trunk/modules/protocols/pop3/pop3.h 2004-10-24 17:13:30 UTC (rev 52)
+++ trunk/modules/protocols/pop3/pop3.h 2004-10-24 19:50:20 UTC (rev 53)
@@ -145,6 +145,8 @@
/* Username & password client entered */
char *username;
char *password;
+ /* commandline stuff */
+ char *cmdLine;
/* Temporary stuff */
char *tmpBuf;
size_t tmpBufSize;
|
|
From: <idm...@li...> - 2004-10-24 17:13:39
|
Author: nkukard Date: 2004-10-24 19:13:30 +0200 (Sun, 24 Oct 2004) New Revision: 52 Modified: trunk/lib/misc.c Log: * Control reached end of non void function Modified: trunk/lib/misc.c =================================================================== --- trunk/lib/misc.c 2004-10-24 17:10:50 UTC (rev 51) +++ trunk/lib/misc.c 2004-10-24 17:13:30 UTC (rev 52) @@ -248,10 +248,12 @@ i++; /* Check for match */ if (strncasecmp(month,*mStr,3) == 0) - return i; + break; *mStr++; } + + return i; } /* function to return string with no char at the ends */ |
|
From: <idm...@li...> - 2004-10-24 17:11:03
|
Author: nkukard
Date: 2004-10-24 19:10:50 +0200 (Sun, 24 Oct 2004)
New Revision: 51
Modified:
trunk/modules/protocols/smtp/smtp.c
Log:
* Added some memory allocation checking
Modified: trunk/modules/protocols/smtp/smtp.c
===================================================================
--- trunk/modules/protocols/smtp/smtp.c 2004-10-24 15:41:27 UTC (rev 50)
+++ trunk/modules/protocols/smtp/smtp.c 2004-10-24 17:10:50 UTC (rev 51)
@@ -92,9 +92,18 @@
data->envelopeTo = NULL;
data->tmpBufSize = SMTP_RESP_LEN;
- data->tmpBuf = malloc(data->tmpBufSize);
- data->tmpCmd = malloc(sizeof(struct smtp_command_t));
+
+ /* Check if allocation succeeded */
+ if (!(data->tmpBuf = malloc(data->tmpBufSize)))
+ return 1;
+ /* Same here... */
+ if (!(data->tmpCmd = malloc(sizeof(struct smtp_command_t))))
+ {
+ free(data->tmpBuf);
+ return 1;
+ }
+
data->cmdHandle = NULL;
fprintf(stderr,"smtp startup\n");
|
|
From: <idm...@li...> - 2004-10-24 15:41:39
|
Author: nkukard Date: 2004-10-24 17:41:27 +0200 (Sun, 24 Oct 2004) New Revision: 50 Modified: trunk/modules/protocols/smtp/smtp_cmd_mail.c trunk/modules/protocols/smtp/smtp_cmd_rcpt.c Log: * Changed the way we check for number of parameters to something a bit more sane Modified: trunk/modules/protocols/smtp/smtp_cmd_mail.c =================================================================== --- trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-24 15:40:49 UTC (rev 49) +++ trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-24 15:41:27 UTC (rev 50) @@ -39,7 +39,7 @@ num_text_params = cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT); /* This is impossible */ - if (num_text_params > 2 || num_text_params == 1) + if (num_text_params != 2 && num_text_params != 0) return SMTP_ERROR_FATAL; /* Allocate memory for our envelope address */ Modified: trunk/modules/protocols/smtp/smtp_cmd_rcpt.c =================================================================== --- trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-24 15:40:49 UTC (rev 49) +++ trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-24 15:41:27 UTC (rev 50) @@ -39,7 +39,7 @@ num_text_params = cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT); /* This is impossible */ - if (num_text_params > 2 || num_text_params < 1) + if (num_text_params != 2 && num_text_params != 1) return SMTP_ERROR_FATAL; /* Allocate memory for our envelope address */ |
|
From: <idm...@li...> - 2004-10-24 15:41:04
|
Author: nkukard
Date: 2004-10-24 17:40:49 +0200 (Sun, 24 Oct 2004)
New Revision: 49
Modified:
trunk/modules/protocols/smtp/command_lexer.l
Log:
* Fixed bug where a bad sequence in commands generated a syntax error
Modified: trunk/modules/protocols/smtp/command_lexer.l
===================================================================
--- trunk/modules/protocols/smtp/command_lexer.l 2004-10-22 20:27:11 UTC (rev 48)
+++ trunk/modules/protocols/smtp/command_lexer.l 2004-10-24 15:40:49 UTC (rev 49)
@@ -488,7 +488,7 @@
/* Check if we in the right state */
if (protoData->state != SMTP_STATE_DATA)
{
- scanner->errID = COMMAND_LEXER_ERR_NONE;
+ scanner->errID = COMMAND_LEXER_ERR_STATE;
return ERROR;
}
|
|
From: <idm...@li...> - 2004-10-22 20:27:22
|
Author: nkukard
Date: 2004-10-22 22:27:11 +0200 (Fri, 22 Oct 2004)
New Revision: 48
Modified:
trunk/modules/protocols/smtp/smtp.c
Log:
* Added few comments
Modified: trunk/modules/protocols/smtp/smtp.c
===================================================================
--- trunk/modules/protocols/smtp/smtp.c 2004-10-22 20:26:48 UTC (rev 47)
+++ trunk/modules/protocols/smtp/smtp.c 2004-10-22 20:27:11 UTC (rev 48)
@@ -303,6 +303,7 @@
return 0;
}
+ /* If we busy closing, continue... */
if (data->state == SMTP_STATE_CLOSE)
{
D_PRINT(D_DEBUG,"state == close, closing...");
@@ -335,7 +336,7 @@
}
D_PRINT(D_DEBUG,"Done calling contFunc");
}
- else /* No POS case processing */
+ else /* No POS case processing, the developer forgot to add it above */
{
snprintf(data->tmpBuf,data->tmpBufSize,"* BAD Internal server error; No POS action"EOL);
data->state = SMTP_STATE_CLOSE;
@@ -344,6 +345,7 @@
}
else
{
+ /* Check what our state is */
switch (ioState)
{
case SOCK_STATE_TIMEOUT:
|
|
From: <idm...@li...> - 2004-10-22 20:27:01
|
Author: nkukard
Date: 2004-10-22 22:26:48 +0200 (Fri, 22 Oct 2004)
New Revision: 47
Modified:
trunk/modules/protocols/smtp/smtp_cmd_mail.c
Log:
* Special case <postmaster> is not part of the MAIL command
Modified: trunk/modules/protocols/smtp/smtp_cmd_mail.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-22 20:26:06 UTC (rev 46)
+++ trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-22 20:26:48 UTC (rev 47)
@@ -39,7 +39,7 @@
num_text_params = cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT);
/* This is impossible */
- if (num_text_params > 2)
+ if (num_text_params > 2 || num_text_params == 1)
return SMTP_ERROR_FATAL;
/* Allocate memory for our envelope address */
@@ -56,12 +56,6 @@
addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
addy->domainPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,1));
}
- else if (num_text_params == 1) /* Special case <postmaster> */
- {
- /* As I said, special case <postmaster> */
- addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
- addy->domainPart = NULL;
- }
else if (num_text_params == 0) /* Special case <> */
{
/* As I said, special case <> */
@@ -74,6 +68,7 @@
data->state = SMTP_STATE_RCPT; /* We now waiting for rcpt to */
#if 0
+ // This is how the ESMTP parameters are gathered
{
void printout(gpointer key, gpointer value, gpointer user_data)
{
|
|
From: <idm...@li...> - 2004-10-22 20:26:25
|
Author: nkukard
Date: 2004-10-22 22:26:06 +0200 (Fri, 22 Oct 2004)
New Revision: 46
Modified:
trunk/modules/protocols/smtp/command_lexer.l
trunk/modules/protocols/smtp/command_parser.y
trunk/modules/protocols/smtp/smtp_cmd_rcpt.c
Log:
* Added special case <postmaster> to RCPT command
Modified: trunk/modules/protocols/smtp/command_lexer.l
===================================================================
--- trunk/modules/protocols/smtp/command_lexer.l 2004-10-20 11:07:57 UTC (rev 45)
+++ trunk/modules/protocols/smtp/command_lexer.l 2004-10-22 20:26:06 UTC (rev 46)
@@ -312,7 +312,7 @@
/* Local part stuff */
lp_atom [#&+\-.0-9=A-Z_a-z]+
-lp_quoted \"{lp_atom}\"
+lp_quoted \"{lp_atom}\"
local_part ({lp_atom}|{lp_quoted})
/* Domain definition as per RFC1035 - condensed & with address literals */
@@ -430,8 +430,19 @@
}
<C_LOCAL_PART>{local_part} {
BEGIN(C_AT_SIGN);
- save_text_param(&scanner->commandParams,dequote(yytext));
- return LOCAL_PART;
+ /* Check if this is the special case "postmaster" */
+ if (strncasecmp(yytext,"postmaster",10) != 0)
+ {
+ /* Our local_part can be included in double quotes, use dequote() to remove these */
+ save_text_param(&scanner->commandParams,dequote(yytext));
+ return LOCAL_PART;
+ }
+ else
+ {
+ /* Local part cannot be postmaster and double quoted */
+ save_text_param(&scanner->commandParams,strdup(yytext));
+ return LOCAL_PART_POSTMASTER;
+ }
}
<C_AT_SIGN>{at_sign} {
BEGIN(C_DOMAIN_PART);
@@ -442,7 +453,7 @@
save_text_param(&scanner->commandParams,strdup(yytext));
return DOMAIN_PART;
}
-<C_MAIL_END,C_LOCAL_PART>{gthan} {
+<C_MAIL_END,C_LOCAL_PART,C_AT_SIGN>{gthan} {
/* Check if we can enable some more cool stuff */
if (protoData->mode == SMTP_MODE_ESMTP)
Modified: trunk/modules/protocols/smtp/command_parser.y
===================================================================
--- trunk/modules/protocols/smtp/command_parser.y 2004-10-20 11:07:57 UTC (rev 45)
+++ trunk/modules/protocols/smtp/command_parser.y 2004-10-22 20:26:06 UTC (rev 46)
@@ -57,6 +57,7 @@
%token RCPT
%token STHAN
%token LOCAL_PART
+%token LOCAL_PART_POSTMASTER
%token DOMAIN_PART
%token GTHAN
%token ESMTP_KEYWORD
@@ -166,21 +167,22 @@
| esmtp_params esmtp_param
;
-email_address:
- STHAN LOCAL_PART AT_SIGN DOMAIN_PART GTHAN
+email_address_possible_postmaster:
+ LOCAL_PART AT_SIGN DOMAIN_PART
+ | LOCAL_PART_POSTMASTER
+ | LOCAL_PART_POSTMASTER AT_SIGN DOMAIN_PART
;
-empty_email_address:
- STHAN GTHAN
+email_address_possible_empty:
+ | LOCAL_PART AT_SIGN DOMAIN_PART
;
mail_address:
- possible_whitespace email_address
- | possible_whitespace empty_email_address
+ possible_whitespace STHAN email_address_possible_empty GTHAN
;
rcpt_address:
- possible_whitespace email_address
+ possible_whitespace STHAN email_address_possible_postmaster GTHAN
;
help_params:
Modified: trunk/modules/protocols/smtp/smtp_cmd_rcpt.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-20 11:07:57 UTC (rev 45)
+++ trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-22 20:26:06 UTC (rev 46)
@@ -32,15 +32,16 @@
{
struct smtp_data_t *data = connection->data;
struct smtp_envelope_addy_t *addy;
+ int num_text_params;
- /* Check our params are ok */
- if (cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT) != 2)
- {
- D_PRINT(D_FATAL,"Wrong number of params");
+ /* Get the number of text parameters we have */
+ num_text_params = cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT);
+
+ /* This is impossible */
+ if (num_text_params > 2 || num_text_params < 1)
return SMTP_ERROR_FATAL;
- }
-
+
/* Allocate memory for our envelope address */
if (!(addy = malloc(sizeof(struct smtp_envelope_addy_t))))
{
@@ -48,11 +49,21 @@
return SMTP_ERROR_FATAL;
}
- /* First 2 params are the email address & domain */
- addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
- addy->domainPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,1));
+ /* Check our params are ok */
+ if (num_text_params == 2) /* Normal email address */
+ {
+ /* First 2 text params are the email address & domain */
+ addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
+ addy->domainPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,1));
+ }
+ else if (num_text_params == 1) /* Special case <postmaster> */
+ {
+ /* As I said, special case <postmaster> */
+ addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
+ addy->domainPart = NULL;
+ }
- /* Add this address to our envelopeFrom */
+ /* Add this address to our envelopeTo */
data->envelopeTo = g_list_append(data->envelopeTo,addy);
data->state = SMTP_STATE_DATA; /* We now waiting for data */
|
|
From: <idm...@li...> - 2004-10-20 11:08:27
|
Author: nkukard Date: 2004-10-20 13:07:57 +0200 (Wed, 20 Oct 2004) New Revision: 45 Modified: trunk/modules/protocols/imap4/TODO Log: * Changes from smtp which must be committed to imap4 Modified: trunk/modules/protocols/imap4/TODO =================================================================== --- trunk/modules/protocols/imap4/TODO 2004-10-20 11:07:00 UTC (rev 44) +++ trunk/modules/protocols/imap4/TODO 2004-10-20 11:07:57 UTC (rev 45) @@ -23,3 +23,5 @@ * remote TEXT_PARAM() macro & use smtp_cmds.c file from smtp module to handle counting & params +* remove IMAP4_ERROR_STATE from the command files & put in lexical analyser + |
|
From: <idm...@li...> - 2004-10-20 11:07:22
|
Author: nkukard
Date: 2004-10-20 13:07:00 +0200 (Wed, 20 Oct 2004)
New Revision: 44
Modified:
trunk/modules/protocols/smtp/smtp.c
trunk/modules/protocols/smtp/smtp_cmds.h
Log:
* Removed SMTP_ERROR_STATE from smtp command handler, this is handled by the lexer
Modified: trunk/modules/protocols/smtp/smtp.c
===================================================================
--- trunk/modules/protocols/smtp/smtp.c 2004-10-20 11:05:22 UTC (rev 43)
+++ trunk/modules/protocols/smtp/smtp.c 2004-10-20 11:07:00 UTC (rev 44)
@@ -162,11 +162,6 @@
/* Switch for errors */
switch (res)
{
- case SMTP_ERROR_STATE:
- snprintf(data->tmpBuf,data->tmpBufSize,"503 Bad sequence of commands"EOL);
- data->position = SMTP_POS_USER_INPUT;
- queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
- break;
case SMTP_ERROR_FATAL:
freeCommandStruct(data->tmpCmd);
smtp_close(connection);
Modified: trunk/modules/protocols/smtp/smtp_cmds.h
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmds.h 2004-10-20 11:05:22 UTC (rev 43)
+++ trunk/modules/protocols/smtp/smtp_cmds.h 2004-10-20 11:07:00 UTC (rev 44)
@@ -60,7 +60,6 @@
#define SMTP_POS_CMD_DATA 5
/* Error codes we can get */
-#define SMTP_ERROR_STATE -2 /* Command called from wrong state */
#define SMTP_ERROR_FATAL -1
#define SMTP_ERROR_NONE 0
|
|
From: <idm...@li...> - 2004-10-20 11:05:40
|
Author: nkukard
Date: 2004-10-20 13:05:22 +0200 (Wed, 20 Oct 2004)
New Revision: 43
Modified:
trunk/modules/protocols/smtp/command_lexer.h
trunk/modules/protocols/smtp/command_lexer.l
trunk/modules/protocols/smtp/command_parser.y
trunk/modules/protocols/smtp/smtp.c
trunk/modules/protocols/smtp/smtp_cmd_mail.c
trunk/modules/protocols/smtp/smtp_cmd_rcpt.c
trunk/modules/protocols/smtp/smtp_cmds.h
Log:
* Removed state checking from command files and added it directly to the lexical parser
Modified: trunk/modules/protocols/smtp/command_lexer.h
===================================================================
--- trunk/modules/protocols/smtp/command_lexer.h 2004-10-20 10:07:38 UTC (rev 42)
+++ trunk/modules/protocols/smtp/command_lexer.h 2004-10-20 11:05:22 UTC (rev 43)
@@ -28,9 +28,14 @@
#include "smtp_cmds.h"
+#define COMMAND_LEXER_ERR_STATE -1
+#define COMMAND_LEXER_ERR_NONE 0
+
+
/* Our data structure */
struct command_scanner_t
{
+ int errID;
char *error;
int commandID;
GList *commandParams;
Modified: trunk/modules/protocols/smtp/command_lexer.l
===================================================================
--- trunk/modules/protocols/smtp/command_lexer.l 2004-10-20 10:07:38 UTC (rev 42)
+++ trunk/modules/protocols/smtp/command_lexer.l 2004-10-20 11:05:22 UTC (rev 43)
@@ -118,6 +118,7 @@
/* Init state */
state->internalState = internalState;
/* Clear variables */
+ state->errID = COMMAND_LEXER_ERR_NONE;
state->error = NULL;
state->commandID = -1;
state->commandParams = NULL;
@@ -360,8 +361,11 @@
%%
struct command_scanner_t *scanner = yyget_extra(yyscanner);
+ /* Pull in protocol data structure */
+ struct smtp_data_t *protoData = scanner->data;
+
printf("Entering lexer\n");
@@ -398,11 +402,25 @@
/* MAIL FROM & RCPT TO */
{c_mail} {
+ /* Check if we in the right state */
+ if (protoData->state != SMTP_STATE_MAIL)
+ {
+ scanner->errID = COMMAND_LEXER_ERR_STATE;
+ return ERROR;
+ }
+
BEGIN(C_MAIL_FROM);
END_COMMAND(MAIL);
}
{c_rcpt} {
+ /* Check if we in the right state */
+ if (protoData->state != SMTP_STATE_RCPT && protoData->state != SMTP_STATE_DATA)
+ {
+ scanner->errID = COMMAND_LEXER_ERR_STATE;
+ return ERROR;
+ }
+
BEGIN(C_RCPT_TO);
END_COMMAND(RCPT);
}
@@ -425,12 +443,9 @@
return DOMAIN_PART;
}
<C_MAIL_END,C_LOCAL_PART>{gthan} {
- /* Pull in protocol data structure */
- struct smtp_data_t *data = scanner->data;
-
/* Check if we can enable some more cool stuff */
- if (data->mode == SMTP_MODE_ESMTP)
+ if (protoData->mode == SMTP_MODE_ESMTP)
BEGIN(C_MAIL_RCPT_PARAM);
return GTHAN;
@@ -457,8 +472,15 @@
}
+
{c_data} {
- printf("Line %i\n",__LINE__);
+ /* Check if we in the right state */
+ if (protoData->state != SMTP_STATE_DATA)
+ {
+ scanner->errID = COMMAND_LEXER_ERR_NONE;
+ return ERROR;
+ }
+
END_COMMAND(DATA);
}
Modified: trunk/modules/protocols/smtp/command_parser.y
===================================================================
--- trunk/modules/protocols/smtp/command_parser.y 2004-10-20 10:07:38 UTC (rev 42)
+++ trunk/modules/protocols/smtp/command_parser.y 2004-10-20 11:05:22 UTC (rev 43)
@@ -230,6 +230,7 @@
int parseCommand(struct clientConnection_t *connection, char *str, struct smtp_command_t *cmd)
{
struct command_scanner_t *scanner = malloc(sizeof(struct command_scanner_t));
+ int errID;
/* Init structure */
@@ -248,7 +249,8 @@
close_command_lexical_parser(scanner);
/* Assign at least this to the error */
- cmd->id = scanner->commandID;
+ cmd->id = scanner->commandID;
+ errID = scanner->errID;
/* Check if there was an error */
if (!(scanner->error))
{
@@ -276,11 +278,12 @@
g_list_free(scanner->commandParams);
}
// if (scanner->commandData)
- cmd->err = 1;
+ cmd->err = scanner->errID;
printf("ERROR: command = %i, string = \"%s\"\n",scanner->commandID,scanner->error);
}
free(scanner);
+ return errID;
}
Modified: trunk/modules/protocols/smtp/smtp.c
===================================================================
--- trunk/modules/protocols/smtp/smtp.c 2004-10-20 10:07:38 UTC (rev 42)
+++ trunk/modules/protocols/smtp/smtp.c 2004-10-20 11:05:22 UTC (rev 43)
@@ -128,68 +128,80 @@
struct smtp_data_t *data = connection->data;
struct smtp_cmd_t *smtp_cmd;
char *buffer;
+ int err;
buffer = getIOBuffer(connection);
/* Use our gramatical parser to parse command */
- parseCommand(connection,buffer,data->tmpCmd);
- D_PRINT(D_DEBUG,"Got command %i",data->tmpCmd->id);
- /* Check what the outcome is */
- if (data->tmpCmd->id > 0)
+ err = parseCommand(connection,buffer,data->tmpCmd);
+ if (!err)
{
- int res;
- struct smtp_static_cmd_t *cmd = (struct smtp_static_cmd_t *) smtp_commands;
-
-
- /* Try match up command ID */
- while (cmd->cmdID != SMTP_CMD_NONE)
+ D_PRINT(D_DEBUG,"Got command %i",data->tmpCmd->id);
+ /* Check what the outcome is */
+ if (data->tmpCmd->id > 0)
{
- if (cmd->cmdID == data->tmpCmd->id)
- break;
- cmd++;
- }
-
- /* Run appropriate function */
- if (cmd->cmdID != SMTP_CMD_NONE)
- {
- if (!data->tmpCmd->err)
+ int res;
+ struct smtp_static_cmd_t *cmd = (struct smtp_static_cmd_t *) smtp_commands;
+
+
+ /* Try match up command ID */
+ while (cmd->cmdID != SMTP_CMD_NONE)
{
- /* Run command */
- res = cmd->cmdFunc(connection,data->tmpCmd);
- /* Switch for errors */
- switch (res)
+ if (cmd->cmdID == data->tmpCmd->id)
+ break;
+ cmd++;
+ }
+
+ /* Run appropriate function */
+ if (cmd->cmdID != SMTP_CMD_NONE)
+ {
+ if (!data->tmpCmd->err)
{
- case SMTP_ERROR_STATE:
- snprintf(data->tmpBuf,data->tmpBufSize,"503 Bad sequence of commands"EOL);
- data->position = SMTP_POS_USER_INPUT;
- queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
- break;
- case SMTP_ERROR_FATAL:
- freeCommandStruct(data->tmpCmd);
- smtp_close(connection);
- break;
+ /* Run command */
+ res = cmd->cmdFunc(connection,data->tmpCmd);
+ /* Switch for errors */
+ switch (res)
+ {
+ case SMTP_ERROR_STATE:
+ snprintf(data->tmpBuf,data->tmpBufSize,"503 Bad sequence of commands"EOL);
+ data->position = SMTP_POS_USER_INPUT;
+ queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
+ break;
+ case SMTP_ERROR_FATAL:
+ freeCommandStruct(data->tmpCmd);
+ smtp_close(connection);
+ break;
+ }
}
+ else
+ {
+ snprintf(data->tmpBuf,data->tmpBufSize,"501 Invalid syntax"EOL);
+ data->position = SMTP_POS_USER_INPUT;
+ queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
+ }
}
else
- {
- snprintf(data->tmpBuf,data->tmpBufSize,"501 Invalid syntax"EOL);
- data->position = SMTP_POS_USER_INPUT;
- queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
- }
+ D_PRINT(D_ERROR,"Command not found in smtp_commands");
}
else
- D_PRINT(D_ERROR,"Command not found in smtp_commands");
- }
- else
+ {
+ /* Set request for user input */
+ data->position = SMTP_POS_USER_INPUT;
+
+ snprintf(data->tmpBuf,data->tmpBufSize,"500 Command not recognized"EOL);
+
+ queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
+ }
+ } else if (err == COMMAND_LEXER_ERR_STATE)
{
/* Set request for user input */
data->position = SMTP_POS_USER_INPUT;
-
- snprintf(data->tmpBuf,data->tmpBufSize,"500 Command not recognized"EOL);
-
+
+ snprintf(data->tmpBuf,data->tmpBufSize,"503 Bad sequence of commands"EOL);
+
queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
}
-
+
/* Free our command */
freeCommandStruct(data->tmpCmd);
Modified: trunk/modules/protocols/smtp/smtp_cmd_mail.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-20 10:07:38 UTC (rev 42)
+++ trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-20 11:05:22 UTC (rev 43)
@@ -35,10 +35,6 @@
int num_text_params;
- /* Check if we in the right state */
- if (data->state != SMTP_STATE_MAIL)
- return SMTP_ERROR_STATE;
-
/* Get the number of text parameters we have */
num_text_params = cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT);
@@ -77,6 +73,7 @@
data->envelopeFrom = addy;
data->state = SMTP_STATE_RCPT; /* We now waiting for rcpt to */
+#if 0
{
void printout(gpointer key, gpointer value, gpointer user_data)
{
@@ -93,9 +90,10 @@
GHashTable *esmtp_params = cmdGetParamData(cmdStruct->params,SMTP_PARAM_ESMTP_PARAM,0);
g_hash_table_foreach(esmtp_params,printout,NULL);
- /* Success */
- snprintf(data->tmpBuf,data->tmpBufSize,"250 OK cmds:%i"EOL,g_hash_table_size(esmtp_params));
}
+#endif
+ /* Success */
+ snprintf(data->tmpBuf,data->tmpBufSize,"250 OK"EOL);
data->position = SMTP_POS_USER_INPUT;
queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_TIMEOUT);
Modified: trunk/modules/protocols/smtp/smtp_cmd_rcpt.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-20 10:07:38 UTC (rev 42)
+++ trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-20 11:05:22 UTC (rev 43)
@@ -34,10 +34,6 @@
struct smtp_envelope_addy_t *addy;
- /* Check if we in the right state */
- if (data->state != SMTP_STATE_RCPT && data->state != SMTP_STATE_DATA)
- return SMTP_ERROR_STATE;
-
/* Check our params are ok */
if (cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT) != 2)
{
Modified: trunk/modules/protocols/smtp/smtp_cmds.h
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmds.h 2004-10-20 10:07:38 UTC (rev 42)
+++ trunk/modules/protocols/smtp/smtp_cmds.h 2004-10-20 11:05:22 UTC (rev 43)
@@ -32,6 +32,7 @@
/* Command codes returned by parser */
+#define SMTP_CMD_ERROR_STATE -2
#define SMTP_CMD_ERROR -1
#define SMTP_CMD_NONE 0
#define SMTP_CMD_HELO 1
|
|
From: <idm...@li...> - 2004-10-20 10:08:12
|
Author: nkukard
Date: 2004-10-20 12:07:38 +0200 (Wed, 20 Oct 2004)
New Revision: 42
Added:
trunk/modules/protocols/smtp/smtp_cmd_help.c
trunk/modules/protocols/smtp/smtp_cmds.c
Modified:
trunk/include/misc.h
trunk/lib/misc.c
trunk/modules/protocols/imap4/TODO
trunk/modules/protocols/imap4/command_parser.y
trunk/modules/protocols/smtp/Makefile
trunk/modules/protocols/smtp/Makefile.am
trunk/modules/protocols/smtp/Makefile.in
trunk/modules/protocols/smtp/TODO
trunk/modules/protocols/smtp/command_lexer.h
trunk/modules/protocols/smtp/command_lexer.l
trunk/modules/protocols/smtp/command_parser.y
trunk/modules/protocols/smtp/smtp.c
trunk/modules/protocols/smtp/smtp.h
trunk/modules/protocols/smtp/smtp_cmd_ehlo.c
trunk/modules/protocols/smtp/smtp_cmd_helo.c
trunk/modules/protocols/smtp/smtp_cmd_mail.c
trunk/modules/protocols/smtp/smtp_cmd_rcpt.c
trunk/modules/protocols/smtp/smtp_cmd_rset.c
trunk/modules/protocols/smtp/smtp_cmds.h
Log:
* Added HELP command
* Removed NUM_PARAMS and replaced with a proper function to count specific param
* Removed TEXT_PARAM and replaced with function to get specific type of param
* More of MAIL & RCPT implemented
Modified: trunk/include/misc.h
===================================================================
--- trunk/include/misc.h 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/include/misc.h 2004-10-20 10:07:38 UTC (rev 42)
@@ -25,6 +25,7 @@
#ifndef _MISC_H
#define _MISC_H
+#include <glib.h>
#include <linux/limits.h>
#include <stdlib.h>
@@ -51,7 +52,10 @@
inline int unsetBit(int bits, int bit);
/* Return integer for month text */
int month2int(const char *month);
-/* function to return string with no quotes */
-char *dequote(char *str);
+/* function to return string with no char at the ends */
+char *dechar(char *str, char chr);
+/* macro to return string with no quotes */
+#define dequote(str) dechar(str,'"')
+
#endif
Modified: trunk/lib/misc.c
===================================================================
--- trunk/lib/misc.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/lib/misc.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -254,8 +254,8 @@
}
}
-/* function to return string with no quotes */
-char *dequote(char *str)
+/* function to return string with no char at the ends */
+char *dechar(char *str, char chr)
{
size_t len;
@@ -264,10 +264,12 @@
/* Get length */
len = strlen(str);
/* Check if we quoted */
- if (str[0] == '"' && str[len-1] == '"')
+ if (str[0] == chr && str[len-1] == chr)
return strndup(str+1,len-2);
else
return strdup(str);
}
+
+
Modified: trunk/modules/protocols/imap4/TODO
===================================================================
--- trunk/modules/protocols/imap4/TODO 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/imap4/TODO 2004-10-20 10:07:38 UTC (rev 42)
@@ -21,3 +21,5 @@
* Global mailbox in namespace for news ... etc
+* remote TEXT_PARAM() macro & use smtp_cmds.c file from smtp module to handle counting & params
+
Modified: trunk/modules/protocols/imap4/command_parser.y
===================================================================
--- trunk/modules/protocols/imap4/command_parser.y 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/imap4/command_parser.y 2004-10-20 10:07:38 UTC (rev 42)
@@ -357,7 +357,7 @@
status_items:
- status_item
+ status_item
| status_items status_item
;
Modified: trunk/modules/protocols/smtp/Makefile
===================================================================
--- trunk/modules/protocols/smtp/Makefile 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/Makefile 2004-10-20 10:07:38 UTC (rev 42)
@@ -59,13 +59,13 @@
LTLIBRARIES = $(module_LTLIBRARIES)
smtp_la_LIBADD =
am_smtp_la_OBJECTS = smtp_la-command_lexer.lo \
- smtp_la-command_parser.lo smtp_la-smtp_cmd_helo.lo \
- smtp_la-smtp_cmd_ehlo.lo smtp_la-smtp_cmd_mail.lo \
- smtp_la-smtp_cmd_rcpt.lo smtp_la-smtp_cmd_data.lo \
- smtp_la-smtp_cmd_rset.lo smtp_la-smtp_cmd_vfry.lo \
- smtp_la-smtp_cmd_expand.lo smtp_la-smtp_cmd_help.lo \
- smtp_la-smtp_cmd_noop.lo smtp_la-smtp_cmd_quit.lo \
- smtp_la-smtp.lo
+ smtp_la-command_parser.lo smtp_la-smtp_cmds.lo \
+ smtp_la-smtp_cmd_helo.lo smtp_la-smtp_cmd_ehlo.lo \
+ smtp_la-smtp_cmd_mail.lo smtp_la-smtp_cmd_rcpt.lo \
+ smtp_la-smtp_cmd_data.lo smtp_la-smtp_cmd_rset.lo \
+ smtp_la-smtp_cmd_vfry.lo smtp_la-smtp_cmd_expand.lo \
+ smtp_la-smtp_cmd_help.lo smtp_la-smtp_cmd_noop.lo \
+ smtp_la-smtp_cmd_quit.lo smtp_la-smtp.lo
smtp_la_OBJECTS = $(am_smtp_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -202,11 +202,11 @@
BUILT_SOURCES = command_parser.h
AM_YFLAGS = -d
module_LTLIBRARIES = smtp.la
-smtp_la_SOURCES = command_lexer.l command_parser.y smtp_cmd_helo.c \
- smtp_cmd_ehlo.c smtp_cmd_mail.c smtp_cmd_rcpt.c \
- smtp_cmd_data.c smtp_cmd_rset.c smtp_cmd_vfry.c \
- smtp_cmd_expand.c smtp_cmd_help.c smtp_cmd_noop.c \
- smtp_cmd_quit.c smtp.c
+smtp_la_SOURCES = command_lexer.l command_parser.y smtp_cmds.c \
+ smtp_cmd_helo.c smtp_cmd_ehlo.c smtp_cmd_mail.c \
+ smtp_cmd_rcpt.c smtp_cmd_data.c smtp_cmd_rset.c \
+ smtp_cmd_vfry.c smtp_cmd_expand.c smtp_cmd_help.c \
+ smtp_cmd_noop.c smtp_cmd_quit.c smtp.c
smtp_la_CFLAGS = -I$(top_builddir)/include $(GLIB_CFLAGS) $(AM_CFLAGS)
smtp_la_LDFLAGS = $(GLIB_LIBS) -module -no-undefined -avoid-version
all: $(BUILT_SOURCES)
@@ -298,6 +298,7 @@
include ./$(DEPDIR)/smtp_la-smtp_cmd_rcpt.Plo
include ./$(DEPDIR)/smtp_la-smtp_cmd_rset.Plo
include ./$(DEPDIR)/smtp_la-smtp_cmd_vfry.Plo
+include ./$(DEPDIR)/smtp_la-smtp_cmds.Plo
.c.o:
if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@@ -334,6 +335,13 @@
# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \
# $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -c -o smtp_la-command_parser.lo `test -f 'command_parser.c' || echo '$(srcdir)/'`command_parser.c
+smtp_la-smtp_cmds.lo: smtp_cmds.c
+ if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -MT smtp_la-smtp_cmds.lo -MD -MP -MF "$(DEPDIR)/smtp_la-smtp_cmds.Tpo" -c -o smtp_la-smtp_cmds.lo `test -f 'smtp_cmds.c' || echo '$(srcdir)/'`smtp_cmds.c; \
+ then mv -f "$(DEPDIR)/smtp_la-smtp_cmds.Tpo" "$(DEPDIR)/smtp_la-smtp_cmds.Plo"; else rm -f "$(DEPDIR)/smtp_la-smtp_cmds.Tpo"; exit 1; fi
+# source='smtp_cmds.c' object='smtp_la-smtp_cmds.lo' libtool=yes \
+# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \
+# $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -c -o smtp_la-smtp_cmds.lo `test -f 'smtp_cmds.c' || echo '$(srcdir)/'`smtp_cmds.c
+
smtp_la-smtp_cmd_helo.lo: smtp_cmd_helo.c
if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -MT smtp_la-smtp_cmd_helo.lo -MD -MP -MF "$(DEPDIR)/smtp_la-smtp_cmd_helo.Tpo" -c -o smtp_la-smtp_cmd_helo.lo `test -f 'smtp_cmd_helo.c' || echo '$(srcdir)/'`smtp_cmd_helo.c; \
then mv -f "$(DEPDIR)/smtp_la-smtp_cmd_helo.Tpo" "$(DEPDIR)/smtp_la-smtp_cmd_helo.Plo"; else rm -f "$(DEPDIR)/smtp_la-smtp_cmd_helo.Tpo"; exit 1; fi
Modified: trunk/modules/protocols/smtp/Makefile.am
===================================================================
--- trunk/modules/protocols/smtp/Makefile.am 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/Makefile.am 2004-10-20 10:07:38 UTC (rev 42)
@@ -7,7 +7,7 @@
AM_YFLAGS = -d
module_LTLIBRARIES = smtp.la
-smtp_la_SOURCES = command_lexer.l command_parser.y
+smtp_la_SOURCES = command_lexer.l command_parser.y smtp_cmds.c
smtp_la_SOURCES += smtp_cmd_helo.c smtp_cmd_ehlo.c smtp_cmd_mail.c smtp_cmd_rcpt.c
smtp_la_SOURCES += smtp_cmd_data.c smtp_cmd_rset.c smtp_cmd_vfry.c smtp_cmd_expand.c
smtp_la_SOURCES += smtp_cmd_help.c smtp_cmd_noop.c smtp_cmd_quit.c
Modified: trunk/modules/protocols/smtp/Makefile.in
===================================================================
--- trunk/modules/protocols/smtp/Makefile.in 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/Makefile.in 2004-10-20 10:07:38 UTC (rev 42)
@@ -59,13 +59,13 @@
LTLIBRARIES = $(module_LTLIBRARIES)
smtp_la_LIBADD =
am_smtp_la_OBJECTS = smtp_la-command_lexer.lo \
- smtp_la-command_parser.lo smtp_la-smtp_cmd_helo.lo \
- smtp_la-smtp_cmd_ehlo.lo smtp_la-smtp_cmd_mail.lo \
- smtp_la-smtp_cmd_rcpt.lo smtp_la-smtp_cmd_data.lo \
- smtp_la-smtp_cmd_rset.lo smtp_la-smtp_cmd_vfry.lo \
- smtp_la-smtp_cmd_expand.lo smtp_la-smtp_cmd_help.lo \
- smtp_la-smtp_cmd_noop.lo smtp_la-smtp_cmd_quit.lo \
- smtp_la-smtp.lo
+ smtp_la-command_parser.lo smtp_la-smtp_cmds.lo \
+ smtp_la-smtp_cmd_helo.lo smtp_la-smtp_cmd_ehlo.lo \
+ smtp_la-smtp_cmd_mail.lo smtp_la-smtp_cmd_rcpt.lo \
+ smtp_la-smtp_cmd_data.lo smtp_la-smtp_cmd_rset.lo \
+ smtp_la-smtp_cmd_vfry.lo smtp_la-smtp_cmd_expand.lo \
+ smtp_la-smtp_cmd_help.lo smtp_la-smtp_cmd_noop.lo \
+ smtp_la-smtp_cmd_quit.lo smtp_la-smtp.lo
smtp_la_OBJECTS = $(am_smtp_la_OBJECTS)
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
depcomp = $(SHELL) $(top_srcdir)/depcomp
@@ -202,11 +202,11 @@
BUILT_SOURCES = command_parser.h
AM_YFLAGS = -d
module_LTLIBRARIES = smtp.la
-smtp_la_SOURCES = command_lexer.l command_parser.y smtp_cmd_helo.c \
- smtp_cmd_ehlo.c smtp_cmd_mail.c smtp_cmd_rcpt.c \
- smtp_cmd_data.c smtp_cmd_rset.c smtp_cmd_vfry.c \
- smtp_cmd_expand.c smtp_cmd_help.c smtp_cmd_noop.c \
- smtp_cmd_quit.c smtp.c
+smtp_la_SOURCES = command_lexer.l command_parser.y smtp_cmds.c \
+ smtp_cmd_helo.c smtp_cmd_ehlo.c smtp_cmd_mail.c \
+ smtp_cmd_rcpt.c smtp_cmd_data.c smtp_cmd_rset.c \
+ smtp_cmd_vfry.c smtp_cmd_expand.c smtp_cmd_help.c \
+ smtp_cmd_noop.c smtp_cmd_quit.c smtp.c
smtp_la_CFLAGS = -I$(top_builddir)/include $(GLIB_CFLAGS) $(AM_CFLAGS)
smtp_la_LDFLAGS = $(GLIB_LIBS) -module -no-undefined -avoid-version
all: $(BUILT_SOURCES)
@@ -298,6 +298,7 @@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smtp_la-smtp_cmd_rcpt.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smtp_la-smtp_cmd_rset.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smtp_la-smtp_cmd_vfry.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/smtp_la-smtp_cmds.Plo@am__quote@
.c.o:
@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
@@ -334,6 +335,13 @@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -c -o smtp_la-command_parser.lo `test -f 'command_parser.c' || echo '$(srcdir)/'`command_parser.c
+smtp_la-smtp_cmds.lo: smtp_cmds.c
+@am__fastdepCC_TRUE@ if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -MT smtp_la-smtp_cmds.lo -MD -MP -MF "$(DEPDIR)/smtp_la-smtp_cmds.Tpo" -c -o smtp_la-smtp_cmds.lo `test -f 'smtp_cmds.c' || echo '$(srcdir)/'`smtp_cmds.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/smtp_la-smtp_cmds.Tpo" "$(DEPDIR)/smtp_la-smtp_cmds.Plo"; else rm -f "$(DEPDIR)/smtp_la-smtp_cmds.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='smtp_cmds.c' object='smtp_la-smtp_cmds.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -c -o smtp_la-smtp_cmds.lo `test -f 'smtp_cmds.c' || echo '$(srcdir)/'`smtp_cmds.c
+
smtp_la-smtp_cmd_helo.lo: smtp_cmd_helo.c
@am__fastdepCC_TRUE@ if $(LIBTOOL) --mode=compile --tag=CC $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(smtp_la_CFLAGS) $(CFLAGS) -MT smtp_la-smtp_cmd_helo.lo -MD -MP -MF "$(DEPDIR)/smtp_la-smtp_cmd_helo.Tpo" -c -o smtp_la-smtp_cmd_helo.lo `test -f 'smtp_cmd_helo.c' || echo '$(srcdir)/'`smtp_cmd_helo.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/smtp_la-smtp_cmd_helo.Tpo" "$(DEPDIR)/smtp_la-smtp_cmd_helo.Plo"; else rm -f "$(DEPDIR)/smtp_la-smtp_cmd_helo.Tpo"; exit 1; fi
Modified: trunk/modules/protocols/smtp/TODO
===================================================================
--- trunk/modules/protocols/smtp/TODO 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/TODO 2004-10-20 10:07:38 UTC (rev 42)
@@ -64,3 +64,5 @@
* Set proper size limits - RFC2821 Section 4.5.3.1
* Possible config option to enable lexical parser syntax error descriptions?
+
+* Add checking of max number envelope rcpts per email
Modified: trunk/modules/protocols/smtp/command_lexer.h
===================================================================
--- trunk/modules/protocols/smtp/command_lexer.h 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/command_lexer.h 2004-10-20 10:07:38 UTC (rev 42)
@@ -34,7 +34,10 @@
char *error;
int commandID;
GList *commandParams;
+ /* user stuff */
+ void *data; /* user data */
/* DO NOT TOUCH THIS - internal lexer stuff */
+ void *tmp; /* used to temporarily store stuff */
GList *requiredParams;
void *internalState;
};
@@ -59,7 +62,7 @@
/* Free command structure */
void freeCommandStruct(struct smtp_command_t *cmd);
/* Parse the SMTP command */
-int parseCommand(char *str, struct smtp_command_t *cmd);
+int parseCommand(struct clientConnection_t *connection, char *str, struct smtp_command_t *cmd);
Modified: trunk/modules/protocols/smtp/command_lexer.l
===================================================================
--- trunk/modules/protocols/smtp/command_lexer.l 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/command_lexer.l 2004-10-20 10:07:38 UTC (rev 42)
@@ -27,8 +27,18 @@
%s C_HELO
%s C_EHLO
+
%s C_MAIL_FROM
%s C_RCPT_TO
+%s C_LOCAL_PART
+%s C_AT_SIGN
+%s C_DOMAIN_PART
+%s C_MAIL_END
+%s C_MAIL_RCPT_PARAM
+%s C_MAIL_RCPT_PARAM_EQUAL_SIGN
+%s C_MAIL_RCPT_PARAM_VALUE
+
+
%s C_NOOP
%s C_VFRY
%s C_EXPAND
@@ -44,6 +54,7 @@
#include "command_lexer.h"
#include "command_parser.h"
#include "debug.h"
+#include "misc.h"
#define P_DEFAULT -1
@@ -111,6 +122,8 @@
state->commandID = -1;
state->commandParams = NULL;
state->requiredParams = NULL;
+ state->data = NULL;
+ state->tmp = NULL;
return 0;
}
@@ -164,6 +177,45 @@
free(param);
}
+
+/* Function to be used with g_hash_table_foreach to free a hash of glist of pointers */
+static void free_hash_of_glists_of_pointers(gpointer key, gpointer value, gpointer user_data)
+{
+ GList *item;
+
+
+ /* Check & loop with list */
+ if ((item = g_list_first((GList *) value)))
+ {
+ while (item)
+ {
+ /* Free data */
+ if (item->data)
+ free(item->data);
+ item = g_list_next(item);
+ }
+
+ /* Finally, free the list */
+ g_list_free((GList *) value);
+ }
+
+}
+
+
+/* Function to free the esmtp stuff */
+static void free_esmtp_param(struct smtp_command_param_t *param)
+{
+ /* Check all is safe */
+ if (param->data)
+ {
+ g_hash_table_foreach(param->data,free_hash_of_glists_of_pointers,NULL);
+ g_hash_table_destroy(param->data);
+ }
+ /* Finish off */
+ free(param);
+}
+
+
/* Add text param to param list */
static void save_text_param(GList **paramList, char *str)
{
@@ -171,13 +223,72 @@
param->type = SMTP_PARAM_TEXT;
- param->data = strdup(str);
+ param->data = str;
param->free = free_generic_param;
*paramList = g_list_append(*paramList,param);
}
+/* Add esmtp param to param list */
+static void save_esmtp_param(GList **paramList, char *str)
+{
+ GHashTable *esmtpHash;
+
+
+ /* If we need to allocate the ESMTP_PARAM stuff */
+ if (!(esmtpHash = cmdGetParamData(*paramList,SMTP_PARAM_ESMTP_PARAM,0)))
+ {
+ struct smtp_command_param_t *param = malloc(sizeof(struct smtp_command_param_t));
+
+
+ param->type = SMTP_PARAM_ESMTP_PARAM;
+ param->data = g_hash_table_new_full(g_str_hash,g_str_equal,free,NULL);
+ /* Save hash so we can use it below */
+ esmtpHash = param->data;
+ param->free = free_esmtp_param;
+ /* Append */
+ *paramList = g_list_append(*paramList,param);
+ }
+ else
+ /* Check if we already have a key, if so just exit */
+ if (g_hash_table_lookup_extended(esmtpHash,str,NULL,NULL))
+ return;
+
+ /* If not commit param with no values */
+ g_hash_table_insert(esmtpHash,strdup(str),NULL);
+}
+
+
+/* Add esmtp param value to param list */
+static void save_esmtp_param_value(GList **paramList, char *str, char *value)
+{
+ GHashTable *esmtpHash;
+
+
+ /* It should never happen that we don't find the entry */
+ if ((esmtpHash = cmdGetParamData(*paramList,SMTP_PARAM_ESMTP_PARAM,0)))
+ {
+ GList *values;
+
+
+ /* Grab our current values */
+ if (!g_hash_table_lookup_extended(esmtpHash,str,NULL,(gpointer *) &values))
+ return;
+
+
+ /* Commit param values */
+ if (values)
+ /* We can commit directly if we have a node */
+ values = g_list_append(values,strdup(value));
+ else
+ /* If this is the first item we must replace the value with the first node */
+ g_hash_table_replace(esmtpHash,str,g_list_append(NULL,strdup(value)));
+ }
+}
+
+
+
%}
white [ \t]+
@@ -198,18 +309,14 @@
email_address {sthan}{local_part}\@{domain}{gthan}
from_email_address ({email_address}|{sthan}{gthan})
-atom [!#$&'+-\[\]-z|-~]+
-quoted \"[ !#-\[\]-~]+\"
+/* Local part stuff */
+lp_atom [#&+\-.0-9=A-Z_a-z]+
+lp_quoted \"{lp_atom}\"
+local_part ({lp_atom}|{lp_quoted})
-local_part ({atom}|{quoted})
-/* Is there a diff to local_part? */
-string ({atom}|{quoted})
-
/* Domain definition as per RFC1035 - condensed & with address literals */
domain ({domain_label}(\.{domain_label})*|{address_literal})
-domain_label {domain_ltr_dig}(({domain_ldh})*({domain_ltr_dig})+)*
-domain_ldh ({domain_ltr_dig}|-)
-domain_ltr_dig [0-9a-zA-Z]
+domain_label {alphanumeric}({alphanumeric_h}*{alphanumeric}+)*
/* Add in ipv6 support */
/* address_literal \[({ipv4_literal}|{ipv6_literal}|{general_literal})\] */
@@ -218,7 +325,18 @@
ipv4_digit [0-9]{3}
+/* RFC2821 section 4.1.2 - parameters */
+esmtp_keyword {alphanumeric}{alphanumeric_h}*
+esmtp_value [!-<>-\x7F]+
+/* Generic */
+atom [!#$&'+-\[\]-z|-~]+
+quoted \"[ !#-\[\]-~]+\"
+string ({atom}|{quoted})
+alphanumeric [0-9a-zA-Z]
+alphanumeric_h ({alphanumeric}|-)
+
+
dot \.
bopen \(
@@ -234,6 +352,8 @@
minus \-
colon :
+at_sign @
+equal_sign =
eol [\r]?\n
@@ -246,7 +366,8 @@
/* Various things that can have whitespaces */
-<C_NOOP,C_HELO,C_EHLO,C_MAIL_FROM,C_RCPT_TO,C_VFRY,C_EXPAND,C_HELP>{white} {
+<C_NOOP,C_HELO,C_EHLO,C_MAIL_FROM,C_RCPT_TO,C_VFRY,C_EXPAND,
+ C_HELP,C_MAIL_RCPT_PARAM>{white} {
/* do nothing */
return WHITE_SPACE;
}
@@ -259,7 +380,7 @@
END_COMMAND(HELO);
}
<C_HELO>{domain} {
- save_text_param(&scanner->commandParams,yytext);
+ save_text_param(&scanner->commandParams,strdup(yytext));
return HELO_DOMAIN;
}
@@ -270,24 +391,72 @@
END_COMMAND(EHLO);
}
<C_EHLO>{domain} {
- save_text_param(&scanner->commandParams,yytext);
+ save_text_param(&scanner->commandParams,strdup(yytext));
return EHLO_DOMAIN;
}
-
+ /* MAIL FROM & RCPT TO */
{c_mail} {
- printf("Line %i\n",__LINE__);
BEGIN(C_MAIL_FROM);
END_COMMAND(MAIL);
}
{c_rcpt} {
- printf("Line %i\n",__LINE__);
BEGIN(C_RCPT_TO);
END_COMMAND(RCPT);
}
+<C_MAIL_FROM,C_RCPT_TO>{sthan} {
+ BEGIN(C_LOCAL_PART);
+ return STHAN;
+ }
+<C_LOCAL_PART>{local_part} {
+ BEGIN(C_AT_SIGN);
+ save_text_param(&scanner->commandParams,dequote(yytext));
+ return LOCAL_PART;
+ }
+<C_AT_SIGN>{at_sign} {
+ BEGIN(C_DOMAIN_PART);
+ return AT_SIGN;
+ }
+<C_DOMAIN_PART>{domain} {
+ BEGIN(C_MAIL_END);
+ save_text_param(&scanner->commandParams,strdup(yytext));
+ return DOMAIN_PART;
+ }
+<C_MAIL_END,C_LOCAL_PART>{gthan} {
+ /* Pull in protocol data structure */
+ struct smtp_data_t *data = scanner->data;
+
+ /* Check if we can enable some more cool stuff */
+ if (data->mode == SMTP_MODE_ESMTP)
+ BEGIN(C_MAIL_RCPT_PARAM);
+
+ return GTHAN;
+ }
+<C_MAIL_RCPT_PARAM>{esmtp_keyword} {
+ BEGIN(C_MAIL_RCPT_PARAM_EQUAL_SIGN);
+
+ scanner->tmp = (void *) strtolower(yytext);
+
+ save_esmtp_param(&scanner->commandParams, scanner->tmp);
+
+ return ESMTP_KEYWORD;
+ }
+<C_MAIL_RCPT_PARAM_EQUAL_SIGN>{equal_sign} {
+ BEGIN(C_MAIL_RCPT_PARAM_VALUE);
+ return EQUAL_SIGN;
+ }
+<C_MAIL_RCPT_PARAM_VALUE>{esmtp_value} {
+ BEGIN(C_MAIL_RCPT_PARAM);
+
+ save_esmtp_param_value(&scanner->commandParams, scanner->tmp, yytext);
+
+ return ESMTP_VALUE;
+ }
+
+
{c_data} {
printf("Line %i\n",__LINE__);
END_COMMAND(DATA);
@@ -336,16 +505,6 @@
return ATOM;
}
-<C_MAIL_FROM>{from_email_address} {
- printf("Line %i\n",__LINE__);
- return EMAIL_ADDRESS;
- }
-
-<C_RCPT_TO>{email_address} {
- printf("Line %i\n",__LINE__);
- return EMAIL_ADDRESS;
- }
-
{eol} {
printf("Line %i\n",__LINE__);
return END;
Modified: trunk/modules/protocols/smtp/command_parser.y
===================================================================
--- trunk/modules/protocols/smtp/command_parser.y 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/command_parser.y 2004-10-20 10:07:38 UTC (rev 42)
@@ -55,6 +55,13 @@
%token MAIL
%token RCPT
+%token STHAN
+%token LOCAL_PART
+%token DOMAIN_PART
+%token GTHAN
+%token ESMTP_KEYWORD
+%token ESMTP_VALUE
+
%token DATA
%token RSET
%token VFRY
@@ -68,6 +75,8 @@
%token ATOM
%token EMAIL_ADDRESS
%token STRING
+%token AT_SIGN
+%token EQUAL_SIGN
/* Internal tokens */
%token END
@@ -105,11 +114,11 @@
printf("ehlo command\n");
}
- | MAIL mail_address {
+ | MAIL mail_address esmtp_params {
printf("mail from command\n");
}
- | RCPT mail_address {
+ | RCPT rcpt_address esmtp_params {
printf("rcpt to command\n");
}
@@ -143,11 +152,37 @@
;
+possible_whitespace:
+ | WHITE_SPACE
+;
+
+esmtp_param:
+ WHITE_SPACE ESMTP_KEYWORD
+ | WHITE_SPACE ESMTP_KEYWORD EQUAL_SIGN ESMTP_VALUE
+;
+
+esmtp_params:
+ | esmtp_param
+ | esmtp_params esmtp_param
+;
+
+email_address:
+ STHAN LOCAL_PART AT_SIGN DOMAIN_PART GTHAN
+;
+
+empty_email_address:
+ STHAN GTHAN
+;
+
mail_address:
- EMAIL_ADDRESS
- | WHITE_SPACE EMAIL_ADDRESS
+ possible_whitespace email_address
+ | possible_whitespace empty_email_address
;
+rcpt_address:
+ possible_whitespace email_address
+;
+
help_params:
| WHITE_SPACE STRING
;
@@ -192,7 +227,7 @@
}
/* Parse the SMTP command */
-int parseCommand(char *str, struct smtp_command_t *cmd)
+int parseCommand(struct clientConnection_t *connection, char *str, struct smtp_command_t *cmd)
{
struct command_scanner_t *scanner = malloc(sizeof(struct command_scanner_t));
@@ -205,6 +240,8 @@
/* Init scanner with string & pass it the scanner struct */
init_command_lexical_parser(scanner,str);
+ /* Set user data */
+ scanner->data = (void *) connection->data;
/* Run gramatical scanner */
start_command_grammar_parser(scanner);
/* clean everything up */
Modified: trunk/modules/protocols/smtp/smtp.c
===================================================================
--- trunk/modules/protocols/smtp/smtp.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -80,13 +80,16 @@
struct smtp_data_t *data = malloc(sizeof(struct smtp_data_t));
- data->state = SMTP_STATE_PREAUTH;
data->position = SMTP_POS_USER_INPUT;
/* Protocol specific */
data->mode = SMTP_MODE_NONE;
data->myHostname = "fully.qualified.domain.com";
data->helloDomain = NULL;
+ data->state = SMTP_STATE_HELO;
+
+ data->envelopeFrom = NULL;
+ data->envelopeTo = NULL;
data->tmpBufSize = SMTP_RESP_LEN;
data->tmpBuf = malloc(data->tmpBufSize);
@@ -113,8 +116,7 @@
/* Check if we must process user input */
fprintf(stderr,"We need user input\n");
data->position = SMTP_POS_CMD;
- queueToReceive(connection,SMTP_CMD_LEN,(data->state ==
- SMTP_STATE_PREAUTH ? SMTP_IO_PREAUTH_TIMEOUT : SMTP_IO_TIMEOUT));
+ queueToReceive(connection,SMTP_CMD_LEN,SMTP_IO_TIMEOUT);
/* Exit here to bypass the fallthrough queueToSend */
return 0;
}
@@ -130,7 +132,7 @@
buffer = getIOBuffer(connection);
/* Use our gramatical parser to parse command */
- parseCommand(buffer,data->tmpCmd);
+ parseCommand(connection,buffer,data->tmpCmd);
D_PRINT(D_DEBUG,"Got command %i",data->tmpCmd->id);
/* Check what the outcome is */
if (data->tmpCmd->id > 0)
@@ -158,7 +160,7 @@
switch (res)
{
case SMTP_ERROR_STATE:
- snprintf(data->tmpBuf,data->tmpBufSize,"500 Command not valid in this state"EOL);
+ snprintf(data->tmpBuf,data->tmpBufSize,"503 Bad sequence of commands"EOL);
data->position = SMTP_POS_USER_INPUT;
queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_PREAUTH_TIMEOUT);
break;
@@ -203,9 +205,8 @@
/* myHostname is just a link to a char *, DO NOT FREE!!! */
- /* Free stuff we allocated */
- if (data->helloDomain)
- free(data->helloDomain);
+ /* This basically frees everything */
+ smtpResetState(connection);
free(data->tmpBuf);
free(data);
@@ -217,6 +218,64 @@
}
+/* Reset smtp state, required for helo, ehlo and rset */
+void smtpResetState(struct clientConnection_t *connection)
+{
+ struct smtp_data_t *data = connection->data;
+
+
+ /* Reset state */
+ data->state = SMTP_STATE_MAIL;
+
+ /* Free stuff we allocated */
+ FREE0(data->helloDomain);
+
+ /* Free envelope from */
+ if (data->envelopeFrom)
+ {
+ /* Free the stuff we allocated only if it was allocated */
+ if (data->envelopeFrom->localPart)
+ free(data->envelopeFrom->localPart);
+ if (data->envelopeFrom->domainPart)
+ free(data->envelopeFrom->domainPart);
+
+ free(data->envelopeFrom);
+ data->envelopeFrom = NULL;
+ }
+
+ /* Free envelope to */
+ if (data->envelopeTo)
+ {
+ GList *item = g_list_first(data->envelopeTo);
+
+ /* Loop with items and dispose of accordingly */
+ while (item)
+ {
+ struct smtp_envelope_addy_t *itemAddy;
+
+
+ /* Make sure this isn't a blank data entry */
+ if ((itemAddy = item->data))
+ {
+ /* Free the stuff we allocated only if it was allocated */
+ if (itemAddy->localPart)
+ free(itemAddy->localPart);
+ if (itemAddy->domainPart)
+ free(itemAddy->domainPart);
+ /* Including the actual struct */
+ free(itemAddy);
+ }
+
+ item = g_list_next(item);
+ }
+ /* Finally dispose of the list pointing to nothing but junk */
+ g_list_free(data->envelopeTo);
+
+ data->envelopeTo = NULL;
+ }
+}
+
+
/* Main smtp protocol handler */
static int smtp_handler(struct clientConnection_t *connection)
{
@@ -273,8 +332,7 @@
{
snprintf(data->tmpBuf,data->tmpBufSize,"* BAD Internal server error; No POS action"EOL);
data->state = SMTP_STATE_CLOSE;
- queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),(data->state ==
- SMTP_STATE_PREAUTH ? SMTP_IO_PREAUTH_TIMEOUT : SMTP_IO_TIMEOUT));
+ queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_TIMEOUT);
}
}
else
@@ -301,8 +359,7 @@
}
data->state = SMTP_STATE_CLOSE;
- queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),(data->state ==
- SMTP_STATE_PREAUTH ? SMTP_IO_PREAUTH_TIMEOUT : SMTP_IO_TIMEOUT));
+ queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_TIMEOUT);
}
Modified: trunk/modules/protocols/smtp/smtp.h
===================================================================
--- trunk/modules/protocols/smtp/smtp.h 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp.h 2004-10-20 10:07:38 UTC (rev 42)
@@ -48,12 +48,12 @@
#define SMTP_MODE_SMTP 1
#define SMTP_MODE_ESMTP 2
-/* Possible SMTP states as described in RFC2060 section 3 */
-#define SMTP_STATE_PREAUTH 1 /* Pre-authenticated state */
-#define SMTP_STATE_AUTHED 2 /* Authenticated state */
-#define SMTP_STATE_SELECTED 3 /* SELECT or EXAMINE state */
-#define SMTP_STATE_LOGOUT 4 /* in process of logging out */
-#define SMTP_STATE_CLOSE 5 /* Next loop will close connection */
+/* Possible SMTP states */
+#define SMTP_STATE_HELO 0 /* Must first send a HELO or EHLO */
+#define SMTP_STATE_MAIL 1 /* Waiting for MAIL FROM command */
+#define SMTP_STATE_RCPT 2 /* Waiting for RCPT TO command */
+#define SMTP_STATE_DATA 3 /* Waiting for DATA command */
+#define SMTP_STATE_CLOSE 255 /* Closing */
/*
* Protocol implementation stuff
@@ -62,26 +62,42 @@
#define SMTP_CMD_LEN 255
#define SMTP_RESP_LEN 512
+/* This defines a basic easy to use email address */
+struct smtp_envelope_addy_t
+{
+ char *localPart;
+ char *domainPart;
+};
-
/* This is basically the smtp implementations' handle to the client connection */
struct smtp_data_t
{
- unsigned short int state; /* what rfc state are we in here? */
int position; /* Position in processing */
+
/* protocol specific stuff */
+ unsigned short int state; /* Current state */
char *myHostname; /* Hostname of smtp service */
char *helloDomain; /* Domain name returned in HELO/EHLO */
+
+ /* Envelope stuff */
int mode; /* Either SMTP_MODE_SMTP or SMTP_MODE_ESMTP */
+ struct smtp_envelope_addy_t *envelopeFrom; /* Contents of the MAIL FROM command (envelope from) */
+ GList *envelopeTo; /* Contains a linked list of smtp_envelope_addy's of the recipients */
+
/* Temporary stuff */
struct smtp_command_t *tmpCmd; /* this we use so we don't always have to malloc() */
char *tmpBuf;
size_t tmpBufSize;
+
/* Internals */
void *cmdHandle; /* Handle to a command we busy processing */
};
+/* Reset smtp state, required for helo, ehlo and rset */
+void smtpResetState(struct clientConnection_t *connection);
+
+
#endif
Modified: trunk/modules/protocols/smtp/smtp_cmd_ehlo.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_ehlo.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmd_ehlo.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -48,6 +48,13 @@
struct smtp_cmd_ehlo_t *cmdState;
+ /* Check our params are ok */
+ if (cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT) != 1)
+ {
+ D_PRINT(D_FATAL,"Wrong number of params");
+ return SMTP_ERROR_FATAL;
+ }
+
/* Setup state stuff */
if (!(cmdState = malloc(sizeof(struct smtp_cmd_ehlo_t))))
{
@@ -56,7 +63,8 @@
}
/* Pull params out */
- data->helloDomain = strdup(TEXT_PARAM(0));
+ smtpResetState(connection);
+ data->helloDomain = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
/* We support extensions */
snprintf(data->tmpBuf,data->tmpBufSize,"250-%s" EOL,data->myHostname);
Modified: trunk/modules/protocols/smtp/smtp_cmd_helo.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_helo.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmd_helo.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -34,20 +34,22 @@
/* Check our params are ok */
- if (NUM_PARAMS != 1)
+ if (cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT) != 1)
{
D_PRINT(D_FATAL,"Wrong number of params");
return SMTP_ERROR_FATAL;
}
- /* Pull params out */
- data->helloDomain = strdup(TEXT_PARAM(0));
+ /* Pull params out */
+ smtpResetState(connection);
+ data->helloDomain = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
/* No real hard work here */
snprintf(data->tmpBuf,data->tmpBufSize,"250 %s" EOL,data->myHostname);
/* We dont support extensions */
data->mode = SMTP_MODE_SMTP;
+ data->state = SMTP_STATE_MAIL;
/* Keep cmdState up to date */
data->position = SMTP_POS_USER_INPUT;
Added: trunk/modules/protocols/smtp/smtp_cmd_help.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_help.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmd_help.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -0,0 +1,46 @@
+/*
+ * smtp_cmd_help.c - SMTP Implementation - HELP
+ * Copyright (C) 2002-2004, Linux Based Systems Design
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * 15/10/2004 - Nigel Kukard <nk...@lb...>
+ *
+*/
+
+#include <stdio.h>
+#include "debug.h"
+#include "smtp_cmds.h"
+#include "socklib.h"
+
+
+/* HELP - RFC2821 section 4.1.1.8 */
+int smtp_cmd_help(SMTP_CMD_PARAMS)
+{
+ struct smtp_data_t *data = connection->data;
+
+
+
+ snprintf(data->tmpBuf,data->tmpBufSize,"502 Command not implemented"EOL);
+
+ data->position = SMTP_POS_USER_INPUT;
+ queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_TIMEOUT);
+
+ return SMTP_ERROR_NONE;
+}
+
+
+// vim:ts=4
Modified: trunk/modules/protocols/smtp/smtp_cmd_mail.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmd_mail.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -31,11 +31,72 @@
int smtp_cmd_mail(SMTP_CMD_PARAMS)
{
struct smtp_data_t *data = connection->data;
+ struct smtp_envelope_addy_t *addy;
+ int num_text_params;
+
+
+ /* Check if we in the right state */
+ if (data->state != SMTP_STATE_MAIL)
+ return SMTP_ERROR_STATE;
+
+ /* Get the number of text parameters we have */
+ num_text_params = cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT);
+
+ /* This is impossible */
+ if (num_text_params > 2)
+ return SMTP_ERROR_FATAL;
+ /* Allocate memory for our envelope address */
+ if (!(addy = malloc(sizeof(struct smtp_envelope_addy_t))))
+ {
+ D_PRINT(D_FATAL,"Failed to allocate memory");
+ return SMTP_ERROR_FATAL;
+ }
+ /* Check our params are ok */
+ if (num_text_params == 2) /* Normal email address */
+ {
+ /* First 2 text params are the email address & domain */
+ addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
+ addy->domainPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,1));
+ }
+ else if (num_text_params == 1) /* Special case <postmaster> */
+ {
+ /* As I said, special case <postmaster> */
+ addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
+ addy->domainPart = NULL;
+ }
+ else if (num_text_params == 0) /* Special case <> */
+ {
+ /* As I said, special case <> */
+ addy->localPart = NULL;
+ addy->domainPart = NULL;
+ }
- snprintf(data->tmpBuf,data->tmpBufSize,"250 OK"EOL);
+ /* Add envelopeFrom */
+ data->envelopeFrom = addy;
+ data->state = SMTP_STATE_RCPT; /* We now waiting for rcpt to */
+ {
+ void printout(gpointer key, gpointer value, gpointer user_data)
+ {
+ GList *item = g_list_first((GList *) value);
+
+ fprintf(stderr,"printout start\n");
+ while (item)
+ {
+ fprintf(stderr,"Value: %s\n",(char *) item->data);
+ item = g_list_next(item);
+ }
+ }
+
+ GHashTable *esmtp_params = cmdGetParamData(cmdStruct->params,SMTP_PARAM_ESMTP_PARAM,0);
+
+ g_hash_table_foreach(esmtp_params,printout,NULL);
+ /* Success */
+ snprintf(data->tmpBuf,data->tmpBufSize,"250 OK cmds:%i"EOL,g_hash_table_size(esmtp_params));
+ }
+
data->position = SMTP_POS_USER_INPUT;
queueToSend(connection,data->tmpBuf,strlen(data->tmpBuf),SMTP_IO_TIMEOUT);
Modified: trunk/modules/protocols/smtp/smtp_cmd_rcpt.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmd_rcpt.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -31,9 +31,36 @@
int smtp_cmd_rcpt(SMTP_CMD_PARAMS)
{
struct smtp_data_t *data = connection->data;
+ struct smtp_envelope_addy_t *addy;
+
+
+ /* Check if we in the right state */
+ if (data->state != SMTP_STATE_RCPT && data->state != SMTP_STATE_DATA)
+ return SMTP_ERROR_STATE;
+
+ /* Check our params are ok */
+ if (cmdNumParams(cmdStruct->params,SMTP_PARAM_TEXT) != 2)
+ {
+ D_PRINT(D_FATAL,"Wrong number of params");
+ return SMTP_ERROR_FATAL;
+ }
+
+ /* Allocate memory for our envelope address */
+ if (!(addy = malloc(sizeof(struct smtp_envelope_addy_t))))
+ {
+ D_PRINT(D_FATAL,"Failed to allocate memory");
+ return SMTP_ERROR_FATAL;
+ }
+ /* First 2 params are the email address & domain */
+ addy->localPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,0));
+ addy->domainPart = strdup(cmdGetParamData(cmdStruct->params,SMTP_PARAM_TEXT,1));
+ /* Add this address to our envelopeFrom */
+ data->envelopeTo = g_list_append(data->envelopeTo,addy);
+ data->state = SMTP_STATE_DATA; /* We now waiting for data */
+ /* Success */
snprintf(data->tmpBuf,data->tmpBufSize,"250 OK"EOL);
data->position = SMTP_POS_USER_INPUT;
Modified: trunk/modules/protocols/smtp/smtp_cmd_rset.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmd_rset.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmd_rset.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -33,6 +33,8 @@
struct smtp_data_t *data = connection->data;
+ /* Reset connection state data */
+ smtpResetState(connection);
snprintf(data->tmpBuf,data->tmpBufSize,"250 OK"EOL);
Added: trunk/modules/protocols/smtp/smtp_cmds.c
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmds.c 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmds.c 2004-10-20 10:07:38 UTC (rev 42)
@@ -0,0 +1,80 @@
+/*
+ * smtp_cmds.c - SMTP Implementaion - Various functions we might need
+ * Copyright (C) 2002-2004, Linux Based Systems Design
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ *
+ * 19/10/2004 - Nigel Kukard <nk...@lb...>
+ * * Initial design
+ *
+*/
+
+#include "smtp_cmds.h"
+
+
+/* Count the number of specific parameters we have */
+unsigned int cmdNumParams(GList *params, unsigned int type)
+{
+ unsigned int count = 0;
+ GList *item = g_list_first(params);
+
+
+ /* Loop & count */
+ while (item)
+ {
+ struct smtp_command_param_t *param;
+
+
+ /* Safely check */
+ if ((param = item->data))
+ if (param->type == type)
+ count++;
+
+ item = g_list_next(item);
+ }
+
+ return count;
+}
+
+
+/* Count the number of specific parameters we have */
+void *cmdGetParamData(GList *params, unsigned int type, unsigned int num)
+{
+ unsigned int cur = 0;
+ GList *item = g_list_first(params);
+
+
+ /* Loop & count */
+ while (item)
+ {
+ struct smtp_command_param_t *param;
+
+
+ /* Safely check */
+ if ((param = item->data))
+ if (param->type == type)
+ {
+ /* Check if this is the param we looking for */
+ if (cur++ == num)
+ return param->data;
+ }
+
+ item = g_list_next(item);
+ }
+
+ return NULL;
+}
+
Modified: trunk/modules/protocols/smtp/smtp_cmds.h
===================================================================
--- trunk/modules/protocols/smtp/smtp_cmds.h 2004-10-17 12:13:09 UTC (rev 41)
+++ trunk/modules/protocols/smtp/smtp_cmds.h 2004-10-20 10:07:38 UTC (rev 42)
@@ -46,6 +46,10 @@
#define SMTP_CMD_NOOP 10
#define SMTP_CMD_QUIT 11
+/* Current sequence positions */
+#define SMTP_CMD_POS_MAIL 0
+#define SMTP_CMD_POS_RCPT 1
+
/* Command states ... used for continuation of commands */
#define SMTP_POS_USER_INPUT 0 /* require user input */
#define SMTP_POS_CMD 1 /* process command */
@@ -70,14 +74,10 @@
/* Param types */
#define SMTP_PARAM_TEXT 1
-#define SMTP_PARAM_OTHER 2
+#define SMTP_PARAM_ESMTP_PARAM 2
+#define SMTP_PARAM_OTHER 3
-/* Macros that can help us to get our params */
-#define TEXT_PARAM(num) ((struct smtp_command_param_t *) (g_list_nth(cmdStruct->params,num))->data)->data
-#define OTHER_PARAM(num) ((struct smtp_command_param_t *) (g_list_nth(cmdStruct->params,num))->data)->data
-#define NUM_PARAMS (g_list_length(cmdStruct->params))
-
/* Command returned by the parser, passed to the command we executing */
struct smtp_command_t
{
@@ -132,6 +132,13 @@
};
+/* Count the number of specific parameters we have */
+unsigned int cmdNumParams(GList *params, unsigned int type);
+
+/* Count the number of specific parameters we have */
+void *cmdGetParamData(GList *params, unsigned int type, unsigned int num);
+
+
#endif
|
|
From: <idm...@li...> - 2004-10-17 12:13:29
|
Author: nkukard Date: 2004-10-17 14:13:09 +0200 (Sun, 17 Oct 2004) New Revision: 41 Modified: trunk/modules/protocols/smtp/smtp.c trunk/modules/protocols/smtp/smtp_cmd_ehlo.c trunk/modules/protocols/smtp/smtp_cmd_helo.c Log: * Finished off ehlo & helo basic commands Modified: trunk/modules/protocols/smtp/smtp.c =================================================================== --- trunk/modules/protocols/smtp/smtp.c 2004-10-15 17:24:35 UTC (rev 40) +++ trunk/modules/protocols/smtp/smtp.c 2004-10-17 12:13:09 UTC (rev 41) @@ -86,6 +86,7 @@ /* Protocol specific */ data->mode = SMTP_MODE_NONE; data->myHostname = "fully.qualified.domain.com"; + data->helloDomain = NULL; data->tmpBufSize = SMTP_RESP_LEN; data->tmpBuf = malloc(data->tmpBufSize); @@ -200,6 +201,12 @@ struct smtp_data_t *data = connection->data; + /* myHostname is just a link to a char *, DO NOT FREE!!! */ + + /* Free stuff we allocated */ + if (data->helloDomain) + free(data->helloDomain); + free(data->tmpBuf); free(data); Modified: trunk/modules/protocols/smtp/smtp_cmd_ehlo.c =================================================================== --- trunk/modules/protocols/smtp/smtp_cmd_ehlo.c 2004-10-15 17:24:35 UTC (rev 40) +++ trunk/modules/protocols/smtp/smtp_cmd_ehlo.c 2004-10-17 12:13:09 UTC (rev 41) @@ -55,12 +55,14 @@ return SMTP_ERROR_FATAL; } - cmdState->cur = (char **) smtp_capabilities; + /* Pull params out */ + data->helloDomain = strdup(TEXT_PARAM(0)); + /* We support extensions */ snprintf(data->tmpBuf,data->tmpBufSize,"250-%s" EOL,data->myHostname); - - /* We support extensions */ data->mode = SMTP_MODE_ESMTP; + + cmdState->cur = (char **) smtp_capabilities; /* Keep cmdState up to date */ data->cmdHandle = cmdState; Modified: trunk/modules/protocols/smtp/smtp_cmd_helo.c =================================================================== --- trunk/modules/protocols/smtp/smtp_cmd_helo.c 2004-10-15 17:24:35 UTC (rev 40) +++ trunk/modules/protocols/smtp/smtp_cmd_helo.c 2004-10-17 12:13:09 UTC (rev 41) @@ -41,7 +41,7 @@ } /* Pull params out */ - data->helloDomain = TEXT_PARAM(0); + data->helloDomain = strdup(TEXT_PARAM(0)); /* No real hard work here */ snprintf(data->tmpBuf,data->tmpBufSize,"250 %s" EOL,data->myHostname); |
|
From: Vernon S. <rzm...@en...> - 2004-06-11 21:17:15
|
araneae pseudo pore shamefully feel junoesque mendicate |
|
From: <ben...@id...> - 2004-05-22 12:33:54
|
Dear Open Source developer I am doing a research project on "Fun and Software Development" in which I kindly invite you to participate. You will find the online survey under http://fasd.ethz.ch/qsf/. The questionnaire consists of 53 questions and you will need about 15 minutes to complete it. With the FASD project (Fun and Software Development) we want to define the motivational significance of fun when software developers decide to engage in Open Source projects. What is special about our research project is that a similar survey is planned with software developers in commercial firms. This procedure allows the immediate comparison between the involved individuals and the conditions of production of these two development models. Thus we hope to obtain substantial new insights to the phenomenon of Open Source Development. With many thanks for your participation, Benno Luthiger PS: The results of the survey will be published under http://www.isu.unizh.ch/fuehrung/blprojects/FASD/. We have set up the mailing list fa...@we... for this study. Please see http://fasd.ethz.ch/qsf/mailinglist_en.html for registration to this mailing list. _______________________________________________________________________ Benno Luthiger Swiss Federal Institute of Technology Zurich 8092 Zurich Mail: benno.luthiger(at)id.ethz.ch _______________________________________________________________________ |
|
From: Danika B. <wmq...@wa...> - 2004-05-10 04:11:12
|
inactively gazetted trying decrepit planchet grenadine trainload apostles saxicola easter designatum oddity lissom fraternity sextet addicted oilpaper |
|
From: Omega A. <mvt...@tn...> - 2004-04-19 00:29:34
|
inclemency cynanche aversive pentail presentday autotomy drink carbomycin comity guise cortland ordeal farriery suspicion bellyache depository boathouse grands guiser wrack auricula unvexed tridymite incapable typhaceae smarten lifetime marasmus optimally center nonmodern ladyfinger wool scat |
|
From: Steve B <st...@bo...> - 2003-08-31 07:57:46
|
Steve. http://www.bov.nu - Homepages. http://www.pokwe.org.uk - Support site for parents of children with epilepsy. |
|
From: Scott K <sc...@mi...> - 2003-07-23 18:36:18
|
Excuse the interruption but could someone please explain a bit bettter exactly what IDMS is supposed to do?? and maybe what it is capable of now ? If I am to understand correctly it is designed to be a fault resilent back end for email systems? if so what MTAs are supported ? postfix ?? sendmail ?? |