[asterisk-commits] russell: branch group/http_mods r60010 - /team/group/http_mods/main/minimime/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Tue Apr 3 15:06:25 MST 2007


Author: russell
Date: Tue Apr  3 17:06:25 2007
New Revision: 60010

URL: http://svn.digium.com/view/asterisk?view=rev&rev=60010
Log:
Update the "mytest" app that demonstrates how the parser doesn't work the 2nd
time it is used.

Modified:
    team/group/http_mods/main/minimime/mytest_files/mytest.c

Modified: team/group/http_mods/main/minimime/mytest_files/mytest.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/minimime/mytest_files/mytest.c?view=diff&rev=60010&r1=60009&r2=60010
==============================================================================
--- team/group/http_mods/main/minimime/mytest_files/mytest.c (original)
+++ team/group/http_mods/main/minimime/mytest_files/mytest.c Tue Apr  3 17:06:25 2007
@@ -10,54 +10,64 @@
 	struct mm_mimepart *part;
 	int res = 0;
 	const char *disp;
+	int i;
 
 	mm_library_init();
 	mm_codec_registerdefaultcodecs();
 
-	if (!(ctx = mm_context_new())) {
-		printf("Failed to create MiniMIME context!\n");
-		exit(1);
+	printf("\nThe test should run 2 times with the same results.\n\n");
+
+	for (i = 0; i < 2; i++) {
+		printf("\nTest run #%d ...\n", i + 1);
+
+		if (!(ctx = mm_context_new())) {
+			printf("Failed to create MiniMIME context!\n\n");
+			break;
+		}
+	
+		res = mm_parse_file(ctx, filename, MM_PARSE_LOOSE, 0);
+		if (res == -1) {
+			printf("Error parsing file %s\n\n", filename);
+			mm_context_free(ctx);
+			break;
+		}
+	
+		res = mm_context_countparts(ctx);
+		if (res != 3) {
+			printf("This file should have 3 parts, but parser says %d\n\n", res);
+			res = -1;
+			mm_context_free(ctx);
+			break;
+		}
+	
+		/* Part 2 is the file */
+		if (!(part = mm_context_getpart(ctx, 2))) {
+			printf("Failed to get a reference to part 2 of the MIME data\n\n");
+			res = -1;
+			mm_context_free(ctx);
+			break;
+		}
+	
+		/* This is where the problems are demonstrated. */
+	
+		if ((disp = mm_mimepart_getheadervalue(part, "Content-Disposition", 0)))
+			printf("SUCCESS: Got the Content-Disposition header: %s\n", disp);
+		else
+			printf("FAILURE: Could not get the Content-Disposition header value!\n");
+	
+		/* hmmm... strange, headers don't have params, which is really quite not-nice! */
+		/* but the author has been storing Content-Disposition params in the part structure */
+	
+		printf("Interesting: the mimepart name is %s\n", part->the_name);
+	
+		res = mm_mimepart_getlength(part);
+		if (res)
+			printf("SUCCESS: Got a non-zero value for the body length: %d\n\n", res);
+		else
+			printf("FAILURE: The silly parser says this MIME part has 0 length!\n\n");
+
+		mm_context_free(ctx);
 	}
 
-	res = mm_parse_file(ctx, filename, MM_PARSE_LOOSE, 0);
-	if (res == -1) {
-		printf("Error parsing file %s\n", filename);
-		goto cleanup;
-	}
-
-	res = mm_context_countparts(ctx);
-	if (res != 3) {
-		printf("This file should have 3 parts, but parser says %d\n", res);
-		res = -1;
-		goto cleanup;
-	}
-
-	/* Part 2 is the file */
-	if (!(part = mm_context_getpart(ctx, 2))) {
-		printf("Failed to get a reference to part 2 of the MIME data\n");
-		res = -1;
-		goto cleanup;
-	}
-
-	/* This is where the problems are demonstrated. */
-
-	if ((disp = mm_mimepart_getheadervalue(part, "Content-Disposition", 0)))
-		printf("SUCCESS: Got the Content-Disposition header: %s\n", disp);
-	else
-		printf("FAILURE: Could not get the Content-Disposition header value!\n");
-
-	/* hmmm... strange, headers don't have params, which is really quite not-nice! */
-	/* but the author has been storing Content-Disposition params in the part structure */
-
-	printf("Interesting: the mimepart name is %s\n", part->the_name);
-
-	res = mm_mimepart_getlength(part);
-	if (res)
-		printf("SUCCESS: Got a non-zero value for the body length: %d\n", res);
-	else
-		printf("FAILURE: The silly parser says this MIME part has 0 length!\n");
-
-cleanup:
-	mm_context_free(ctx);
 	exit(res);
 }



More information about the asterisk-commits mailing list