[idms-dbma-devel]commit - r42 - in trunk: include lib modules/protocols/imap4 modules/protocols/smt
Status: Pre-Alpha
Brought to you by:
nkukard
|
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
|