[svn-commits] rmudgett: branch rmudgett/http_persistent r417418 - /team/rmudgett/http_persi...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jun 26 13:06:41 CDT 2014


Author: rmudgett
Date: Thu Jun 26 13:06:37 2014
New Revision: 417418

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=417418
Log:
* In ast_http_get_contents() stay in fread() until get all the expected
data or timeout.

* Add some more debug output to ast_http_get_contents().

* Rename MAX_POST_CONTENT to MAX_CONTENT_LENGTH and fix its inconsistent use.

Modified:
    team/rmudgett/http_persistent/main/http.c

Modified: team/rmudgett/http_persistent/main/http.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/http_persistent/main/http.c?view=diff&rev=417418&r1=417417&r2=417418
==============================================================================
--- team/rmudgett/http_persistent/main/http.c (original)
+++ team/rmudgett/http_persistent/main/http.c Thu Jun 26 13:06:37 2014
@@ -659,8 +659,6 @@
 	AST_RWLIST_UNLOCK(&uris);
 }
 
-#define MAX_POST_CONTENT 1025
-
 /*!
  * \brief Retrieves the header with the given field name.
  *
@@ -834,6 +832,8 @@
 	int bufsize = 250;
 	char *buf;
 
+#define MAX_CONTENT_LENGTH 1024
+
 	/* Use errno to distinguish errors from no body */
 	errno = 0;
 
@@ -849,10 +849,10 @@
 			request->body_read = 1;
 			return NULL;
 		}
-		if (content_length > MAX_POST_CONTENT - 1) {
+		if (content_length > MAX_CONTENT_LENGTH) {
 			ast_log(LOG_WARNING,
 				"Excessively long HTTP content. (%d > %d)\n",
-				content_length, MAX_POST_CONTENT);
+				content_length, MAX_CONTENT_LENGTH);
 			errno = EFBIG;
 			return NULL;
 		}
@@ -861,12 +861,14 @@
 			/* Malloc sets ENOMEM */
 			return NULL;
 		}
-		res = fread(buf, 1, content_length, ser->f);
-		if (res < content_length) {
+
+		/* Stay in fread until get all the expected data or timeout. */
+		res = fread(buf, content_length, 1, ser->f);
+		if (res < 1) {
 			/* Error, distinguishable by ferror() or feof(), but neither
 			 * is good. Treat either one as I/O error */
-			ast_log(LOG_WARNING, "Short HTTP request body (%d < %d)\n",
-				res, content_length);
+			ast_log(LOG_WARNING, "Short HTTP request body (Wanted %d)\n",
+				content_length);
 			errno = EIO;
 			ast_free(buf);
 			return NULL;
@@ -894,6 +896,7 @@
 			ast_free(buf);
 			return NULL;
 		}
+		ast_log(LOG_NOTICE, "BUGBUG Chunk header: '%s'\n", header_line);
 		chunk_length = chunked_atoh(header_line, sizeof(header_line));
 		if (chunk_length < 0) {
 			ast_log(LOG_WARNING, "Invalid HTTP chunk size\n");
@@ -905,10 +908,10 @@
 			/* parsed last-chunk */
 			break;
 		}
-		if (content_length + chunk_length > MAX_POST_CONTENT - 1) {
+		if (content_length + chunk_length > MAX_CONTENT_LENGTH) {
 			ast_log(LOG_WARNING,
 				"Excessively long HTTP chunk. (%d + %d > %d)\n",
-				content_length, chunk_length, MAX_POST_CONTENT);
+				content_length, chunk_length, MAX_CONTENT_LENGTH);
 			errno = EFBIG;
 			ast_free(buf);
 			return NULL;
@@ -931,22 +934,23 @@
 			buf = new_buf;
 		}
 
-		/* read the chunk-data */
-		res = fread(buf + content_length, 1, chunk_length, ser->f);
-		if (res < chunk_length) {
-			ast_log(LOG_WARNING, "Short HTTP chunk read (%d < %d)\n",
-				res, chunk_length);
+		/* Stay in fread until get all the expected chunk-data or timeout. */
+		res = fread(buf + content_length, chunk_length, 1, ser->f);
+		if (res < 1) {
+			ast_log(LOG_WARNING, "Short HTTP chunk read (Wanted %d)\n",
+				chunk_length);
 			errno = EIO;
 			ast_free(buf);
 			return NULL;
 		}
 		content_length += chunk_length;
-
-		/* insure the next 2 bytes are CRLF */
-		res = fread(header_line, 1, 2, ser->f);
-		if (res < 2) {
+		ast_log(LOG_NOTICE, "BUGBUG Got chunk data\n");
+
+		/* Stay in fread until get the expected CRLF or timeout. */
+		res = fread(header_line, 2, 1, ser->f);
+		if (res < 1) {
 			ast_log(LOG_WARNING,
-				"Short HTTP chunk sync read (%d < 2)\n", res);
+				"Short HTTP chunk sync read (Wanted 2)\n");
 			errno = EIO;
 			ast_free(buf);
 			return NULL;
@@ -959,6 +963,7 @@
 			ast_free(buf);
 			return NULL;
 		}
+		ast_log(LOG_NOTICE, "BUGBUG Got chunk data line termination\n");
 	}
 
 	/*
@@ -976,6 +981,7 @@
 			ast_free(buf);
 			return NULL;
 		}
+		ast_log(LOG_NOTICE, "BUGBUG Chunk trailer header: '%s'\n", header_line);
 
 		/* Trim trailing whitespace */
 		ast_trim_blanks(header_line);




More information about the svn-commits mailing list