Bladeren bron

fix not enough header buffer size, compile warning (#101)

dongly 5 maanden geleden
bovenliggende
commit
d30f86d39b

+ 1 - 0
samples/webclient_get_sample.c

@@ -10,6 +10,7 @@
 
 #include <rtthread.h>
 #include <webclient.h>
+#include <string.h>
 
 #define GET_HEADER_BUFSZ               1024
 #define GET_RESP_BUFSZ                 1024

+ 0 - 1
samples/webclient_post_sample.c

@@ -9,7 +9,6 @@
  */
 
 #include <string.h>
-
 #include <rtthread.h>
 #include <webclient.h>
 

+ 2 - 1
samples/webclient_shard_download_sample.c

@@ -10,7 +10,8 @@
 
 #include <rtthread.h>
 #include <webclient.h>
-#include "stdlib.h"
+#include <stdlib.h>
+#include <string.h>
 
 #define GET_LOCAL_URI                  "http://www.rt-thread.com/service/rt-thread.txt"
 #define CHARACTER_LENGTH 60

+ 2 - 6
src/webclient.c

@@ -19,9 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
-
 #include <webclient.h>
-
 #include <sys/errno.h>
 #include <sys/time.h>
 
@@ -47,8 +45,6 @@
 /* default receive or send timeout */
 #define WEBCLIENT_DEFAULT_TIMEO        6
 
-extern long int strtol(const char *nptr, char **endptr, int base);
-
 static int webclient_strncasecmp(const char *a, const char *b, size_t n)
 {
     uint8_t c1, c2;
@@ -775,7 +771,7 @@ int webclient_handle_response(struct webclient_session *session)
         mime_buffer = session->header->buffer + session->header->length;
 
         /* read a line from the header information. */
-        rc = webclient_read_line(session, mime_buffer, session->header->size - session->header->length);
+        rc = webclient_read_line(session, mime_buffer, session->header->size - session->header->length - 1);
         if (rc < 0)
             break;
 
@@ -798,7 +794,7 @@ int webclient_handle_response(struct webclient_session *session)
 
         if (session->header->length >= session->header->size)
         {
-            LOG_E("not enough header buffer size(%d)!", session->header->size);
+            LOG_E("L%d: not enough header buffer size(%d)!", __LINE__, session->header->size);
             return -WEBCLIENT_NOMEM;
         }
     }

+ 1 - 1
src/webclient_file.c

@@ -120,7 +120,7 @@ int webclient_get_file(const char* URI, const char* filename)
 
     if (total_length)
     {
-        LOG_D("save %d bytes.", total_length);
+        LOG_I("Download to '%s', size: %d bytes.", filename, total_length);
     }
 
 __exit: