[svn-commits] murf: branch group/http_mods r60169 - /team/group/http_mods/main/minimime/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Apr 4 12:11:45 MST 2007


Author: murf
Date: Wed Apr  4 14:11:45 2007
New Revision: 60169

URL: http://svn.digium.com/view/asterisk?view=rev&rev=60169
Log:
OK, the parser can now be run multiple times from the same routine, with no diffs in behavior from one run to the next.  Those globals were of course the problem; and the spice was that the lexer also has its own set of globals, which is good to know for the work to come.

Modified:
    team/group/http_mods/main/minimime/mimeparser.l
    team/group/http_mods/main/minimime/mimeparser.y
    team/group/http_mods/main/minimime/mm_parse.c

Modified: team/group/http_mods/main/minimime/mimeparser.l
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mimeparser.l?view=diff&rev=60169&r1=60168&r2=60169
==============================================================================
--- team/group/http_mods/main/minimime/mimeparser.l (original)
+++ team/group/http_mods/main/minimime/mimeparser.l Wed Apr  4 14:11:45 2007
@@ -418,6 +418,28 @@
 
 %%
 
+void reset_lexer_state(void)
+{
+	BEGIN(0);
+	header_state = STATE_MAIL;
+	lineno = 0;
+	current_pos = 1;
+	condition = 0;
+
+	is_envelope = 1;
+
+	message_len = 0;
+	buffer_length = 0;
+
+	/* temporary marker variables */
+	body_opaque_start = 0;
+	body_start = 0;
+	body_end = 0;
+	preamble_start = 0;
+	preamble_end = 0;
+	postamble_start = 0;
+	postamble_end = 0;
+}
 
 void
 PARSER_setbuffer(const char *string)

Modified: team/group/http_mods/main/minimime/mimeparser.y
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mimeparser.y?view=diff&rev=60169&r1=60168&r2=60169
==============================================================================
--- team/group/http_mods/main/minimime/mimeparser.y (original)
+++ team/group/http_mods/main/minimime/mimeparser.y Wed Apr  4 14:11:45 2007
@@ -48,34 +48,36 @@
 #include "mm_internal.h"
 
 int set_boundary(char *);
+
+/* globals to get rid of */
 extern int lineno;
 extern int condition;
-
 char *boundary_string = NULL;
 char *endboundary_string = NULL;
-
 const char *message_buffer = NULL;
-
 extern FILE *mimeparser_yyin;
 FILE *curin;
-
 static int mime_parts = 0;
 static int debug = 0;
-
 /* MiniMIME specific object pointers */
 static MM_CTX *ctx;
 static struct mm_mimepart *envelope = NULL;
 static struct mm_mimepart *tmppart = NULL;
 static struct mm_content *ctype = NULL;
-
 /* Always points to the current MIME part */
 static struct mm_mimepart *current_mimepart = NULL;
 
 /* Marker for indicating a found Content-Type header */
 static int have_contenttype;
-
 /* The parse mode */
 static int parsemode;
+
+
+
+
+
+
+
 
 static char *PARSE_readmessagepart(size_t, size_t, size_t, size_t *);
 
@@ -126,7 +128,7 @@
 /* This is a parser for a MIME-conform message, which is in either single
  * part or multi part format.
  */
-message :
+message : 
 	multipart_message
 	|
 	singlepart_message
@@ -713,12 +715,31 @@
 	
 }
 
+void reset_environ(void)
+{
+	lineno = 0;
+	condition = 0;
+	boundary_string = NULL;
+	endboundary_string = NULL;
+	message_buffer = NULL;
+	mime_parts = 0;
+	debug = 0;
+	ctx= NULL;
+	envelope = NULL;
+	tmppart = NULL;
+	ctype = NULL;
+	current_mimepart = NULL;
+
+	have_contenttype = 0;
+	parsemode=0;
+}
 /**
  * Initializes the parser engine.
  */
 int
 PARSER_initialize(MM_CTX *newctx, int mode)
 {
+	void reset_lexer_state(void);
 #if 0
 	if (ctx != NULL) {
 		xfree(ctx);
@@ -733,6 +754,9 @@
 		ctype = NULL;
 	}	
 #endif
+	/* yydebug = 1; */
+	reset_environ();
+	reset_lexer_state();
 
 	ctx = newctx;
 	parsemode = mode;
@@ -748,3 +772,4 @@
 	return 1;
 }
 
+

Modified: team/group/http_mods/main/minimime/mm_parse.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mm_parse.c?view=diff&rev=60169&r1=60168&r2=60169
==============================================================================
--- team/group/http_mods/main/minimime/mm_parse.c (original)
+++ team/group/http_mods/main/minimime/mm_parse.c Wed Apr  4 14:11:45 2007
@@ -117,6 +117,7 @@
 mm_parse_file(MM_CTX *ctx, const char *filename, int parsemode, int flags)
 {
 	FILE *fp;
+	int res;
 
 	if ((fp = fopen(filename, "r")) == NULL) {
 		mm_errno = MM_ERROR_ERRNO;
@@ -126,5 +127,7 @@
 	PARSER_setfp(fp);
 	PARSER_initialize(ctx, parsemode);
 
-	return mimeparser_yyparse();
+	res = mimeparser_yyparse();
+	fclose(fp);
+	return res;
 }



More information about the svn-commits mailing list