[WGID-248725] Add file mode checking code in test file 62/149662/2 accepted/tizen/unified/20170914.065434 submit/tizen/20170913.024954
authorSeonah Moon <seonah1.moon@samsung.com>
Wed, 13 Sep 2017 01:30:38 +0000 (10:30 +0900)
committerSeonah Moon <seonah1.moon@samsung.com>
Wed, 13 Sep 2017 02:07:42 +0000 (11:07 +0900)
Change-Id: I2a832ea01a2d9c627cbaa7dc7d2d487d03174715
Signed-off-by: Seonah Moon <seonah1.moon@samsung.com>
packaging/capi-network-http.spec
test/http_test.c

index 7d8e0a1..9a11214 100644 (file)
@@ -1,6 +1,6 @@
 Name:          capi-network-http
 Summary:       Http Framework
-Version:       0.0.27
+Version:       0.0.28
 Release:       0
 Group:         System/Network
 License:       Apache-2.0
index 615cbca..a0ca2eb 100644 (file)
@@ -17,9 +17,9 @@
 
 #include <stdio.h>
 #include <string.h>
+#include <sys/stat.h>
 #include <glib.h>
 #include <gio/gio.h>
-#include <sys/stat.h>
 
 #include "http.h"
 #include "http_internal.h"
@@ -36,7 +36,7 @@ http_session_h session = NULL;
 int cancel = 0;
 
 void _register_callbacks(http_transaction_h transaction);
-void _write_message_body(http_transaction_h transaction, const char *file_path);
+int _write_message_body(http_transaction_h transaction, const char *file_path);
 
 void __transaction_header_cb(http_transaction_h transaction, char *header, size_t header_len, void *user_data)
 {
@@ -153,7 +153,7 @@ void _register_callbacks(http_transaction_h transaction)
        http_transaction_set_progress_cb(transaction, __transaction_progress_cb, NULL);
 }
 
-void _write_message_body(http_transaction_h transaction, const char *file_path)
+int _write_message_body(http_transaction_h transaction, const char *file_path)
 {
        struct stat file_info;
        FILE *fp;
@@ -161,10 +161,25 @@ void _write_message_body(http_transaction_h transaction, const char *file_path)
        size_t chunk_size = 50;
        char *buf = malloc(chunk_size);
 
-       stat(file_path, &file_info);
+       if (stat(file_path, &file_info) != 0) {
+               ERR("stat() is failed", -1);
+               free(buf);
+               return -1;
+       }
+
+       if (!S_ISREG(file_info.st_mode)) {
+               ERR("path is not a regular file", -1);
+               free(buf);
+               return -1;
+       }
+
        file_size = file_info.st_size;
 
        fp = fopen(file_path, "rb");
+       if (!fp) {
+               free(buf);
+               return -1;
+       }
 
        while (fread(buf, 1, chunk_size, fp) > 0) {
                if (file_size < chunk_size)
@@ -177,6 +192,8 @@ void _write_message_body(http_transaction_h transaction, const char *file_path)
 
        free(buf);
        fclose(fp);
+
+       return 0;
 }
 
 int test_http_init(void)
@@ -440,12 +457,16 @@ int test_post_chunk(void)
        }
 
        _register_callbacks(transaction);
-       _write_message_body(transaction, path);
+       ret = _write_message_body(transaction, path);
+       if (ret != 0) {
+               ERR("Failed write message body", ret);
+               return 0;
+
+       }
 
        http_transaction_set_ready_to_write(transaction, TRUE);
        http_transaction_header_add_field(transaction, "Transfer-Encoding", "chunked");
        http_transaction_header_add_field(transaction, "Expect", "");
-
        http_transaction_submit(transaction);
 
        return 1;