[idms-dbma-devel]commit - r43 - trunk/modules/protocols/smtp
Status: Pre-Alpha
Brought to you by:
nkukard
|
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
|