#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"
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)
{
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;
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)
free(buf);
fclose(fp);
+
+ return 0;
}
int test_http_init(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;