lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-devel] SMTP base64 patch, HTTPD question.


From: Ben Whitten
Subject: Re: [lwip-devel] SMTP base64 patch, HTTPD question.
Date: Thu, 23 May 2013 13:02:01 +0100

After working through it this patch appears to solve the problem. It might not be a good way of doing things but it works. I'm not getting any out of memory errors if writing more then the buf (which was stalling SYN ACK for 2-3 seconds) and the speed of replying to a GET has improved, reducing the chance of a retry.

--- C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/httpserver_raw/httpd.c    Mon Dec 17 19:07:22 2012
+++ C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/httpserver_raw/httpd - Copy.c    Thu May 23 12:56:32 2013
@@ -1197,7 +1197,7 @@
    * the buffer contents looking for SSI tags. */
   while((ssi->parse_left) && (err == ERR_OK)) {
     /* @todo: somewhere in this loop, 'len' should grow again... */
-    if (len == 0) {
+    if (tcp_sndbuf(pcb) == 0) {
       return data_to_send;
     }
     switch(ssi->tag_state) {
@@ -1344,15 +1344,18 @@
             if (ssi->tag_end > hs->file) {
               /* How much of the data can we send? */
 #if LWIP_HTTPD_SSI_INCLUDE_TAG
-              if(len > ssi->tag_end - hs->file) {
+              if(tcp_sndbuf(pcb) > ssi->tag_end - hs->file) {
                 len = (u16_t)(ssi->tag_end - hs->file);
               }
 #else /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
-              if(len > ssi->tag_started - hs->file) {
+              if(tcp_sndbuf(pcb) > ssi->tag_started - hs->file) {
                 /* we would include the tag in sending */
                 len = (u16_t)(ssi->tag_started - hs->file);
               }
 #endif /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
+          else {
+                len = tcp_sndbuf(pcb);
+              }
 
               err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
               if (err == ERR_OK) {
@@ -1390,16 +1393,20 @@
         if(ssi->tag_end > hs->file) {
           /* How much of the data can we send? */
 #if LWIP_HTTPD_SSI_INCLUDE_TAG
-          if(len > ssi->tag_end - hs->file) {
+          if(tcp_sndbuf(pcb) > ssi->tag_end - hs->file) {
             len = (u16_t)(ssi->tag_end - hs->file);
           }
 #else /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
           LWIP_ASSERT("hs->started >= hs->file", ssi->tag_started >= hs->file);
-          if (len > ssi->tag_started - hs->file) {
+          if (tcp_sndbuf(pcb) > ssi->tag_started - hs->file) {
             /* we would include the tag in sending */
             len = (u16_t)(ssi->tag_started - hs->file);
           }
 #endif /* LWIP_HTTPD_SSI_INCLUDE_TAG*/
+          else {
+            len = tcp_sndbuf(pcb);
+          }
+
           if (len != 0) {
             err = http_write(pcb, hs->file, &len, HTTP_IS_DATA_VOLATILE(hs));
           } else {
@@ -1432,8 +1439,10 @@
           if(ssi->tag_index < ssi->tag_insert_len) {
             /* We are sending the insert string itself. How much of the
              * insert can we send? */
-            if(len > (ssi->tag_insert_len - ssi->tag_index)) {
+            if(tcp_sndbuf(pcb) > (ssi->tag_insert_len - ssi->tag_index)) {
               len = (ssi->tag_insert_len - ssi->tag_index);
+            } else {
+              len = tcp_sndbuf(pcb);
             }
 
             /* Note that we set the copy flag here since we only have a
@@ -1444,7 +1453,8 @@
                              HTTP_IS_TAG_VOLATILE(hs));
             if (err == ERR_OK) {
               data_to_send = 1;
-              ssi->tag_index += len;
+              if (tcp_sndbuf(pcb) != 0)
+                ssi->tag_index += len;
               /* Don't return here: keep on sending data */
             }
           } else {



On 23 May 2013 09:22, Ben Whitten <address@hidden> wrote:
Hey,

This generates working userpass auth strings. Tested with GMX, Lavabit, Aol, Plusnet, and Yahoo. With various username/password sizes.

I am also hunting a bug in the httpserver_raw, when including SSI tags; it finds the tag, sends the preceding data, then the tag. But then the sending length is never reset so it sends the remaining page at the tag length.
As a result serving a webpage takes 2-3 seconds if its a 4K file with an SSI tag in the <title>.
The problem seems to be around :1351 where I think len is being mistaken for something else, where its actually the length of the previously sent section (last tag length). Could someone more familiar with the code take a look too?

Thanks,
Ben Whitten

--- C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/smtp/smtp.c    Mon Dec 17 19:03:22 2012
+++ C:/Users/bwhitten/Desktop/contrib-1.4.1/apps/smtp/smtp - Copy.c    Thu May 23 08:51:16 2013
@@ -804,8 +804,8 @@
   s8_t j;
   size_t target_idx = 0;
   size_t longer = 3 - (source_len % 3);
-  size_t source_len_b64 = source_len + longer;
-  size_t len = (((source_len_b64) * 4) / 3);
+  size_t source_len_b64 = source_len + ((longer != 3) ? longer : 0);
+  size_t len = (((source_len_b64 / 3) * 4));
   u8_t x = 5;
   u8_t current = 0;
   LWIP_UNUSED_ARG(target_len);
@@ -824,7 +824,7 @@
       }
     }
   }
-  for (i = len - longer; i < len; i++) {
+  for (i = len - ((longer != 3) ? longer : 0); i < len; i++) {
     target[i] = '=';
   }
   return len;



reply via email to

[Prev in Thread] Current Thread [Next in Thread]