Index: src/ne_basic.c =================================================================== --- src/ne_basic.c (revision 313) +++ src/ne_basic.c (working copy) @@ -107,8 +107,8 @@ ne_lock_using_parent(req, uri); #endif - ne_set_request_body_fd(req, fd, 0, st.st_size); - + ne_set_request_body_fd(req, fd, 0, st.st_size, NULL); + ret = ne_request_dispatch(req); if (ret == NE_OK && ne_get_status(req)->klass != 2) Index: src/ne_request.c =================================================================== --- src/ne_request.c (revision 313) +++ src/ne_request.c (working copy) @@ -42,6 +42,9 @@ #include #endif +#include //AVM +#include + #include "ne_internal.h" #include "ne_alloc.h" @@ -101,6 +104,7 @@ int fd; ne_off_t offset, length; ne_off_t remain; /* remaining bytes to send. */ + char* path; } file; struct { /* length bytes @ buffer = whole body. @@ -185,7 +189,7 @@ ne_session *sess = req->session; int ret = NE_ERROR; - NE_DEBUG(NE_DBG_HTTP, "Aborted request (%" NE_FMT_SSIZE_T "): %s\n", + NE_DEBUG(NE_DBG_AVM, "Aborted request (%" NE_FMT_SSIZE_T "): %s", code, doing); switch(code) { @@ -199,7 +203,7 @@ } break; case NE_SOCK_TIMEOUT: - ne_set_error(sess, _("%s: connection timed out"), doing); + ne_set_error(sess, _("%s: connection timed out (aborted)"), doing); ret = NE_TIMEOUT; break; case NE_SOCK_ERROR: @@ -216,11 +220,12 @@ return ret; } -static void notify_status(ne_session *sess, ne_session_status status) +static int notify_status(ne_session *sess, ne_session_status status) { if (sess->notify_cb) { - sess->notify_cb(sess->notify_ud, status, &sess->status); + return sess->notify_cb(sess->notify_ud, status, &sess->status); } + return 0; } static void *get_private(const struct hook *hk, const char *id) @@ -394,16 +399,25 @@ } req->session->status.sr.progress = 0; - notify_status(sess, ne_status_sending); - + req->session->status.sr.duration = 0; + req->session->status.sr.current = 0; + + if(notify_status(sess, ne_status_sending)){ + NE_DEBUG(NE_DBG_AVM, "Send request body: notify abort"); + ne_close_connection(sess); + return NE_ERROR; + } + /* tell the source to start again from the beginning. */ if (req->body_cb(req->body_ud, NULL, 0) != 0) { + NE_DEBUG(NE_DBG_AVM, "Send request body: must start again"); ne_close_connection(sess); return NE_ERROR; } while ((bytes = req->body_cb(req->body_ud, start, buflen)) > 0) { req->session->status.sr.progress += bytes; + req->session->status.sr.current = bytes; if (chunked) { /* Overwrite the buffer prefix with the appropriate chunk * size; since ne_snprintf always NUL-terminates, the \n @@ -417,9 +431,13 @@ buffer[CHUNK_OFFSET - 1] = '\n'; bytes += CHUNK_OFFSET; } + //AVM + struct timeval start_time; + gettimeofday(&start_time, NULL); ret = ne_sock_fullwrite(sess->socket, buffer, bytes); if (ret < 0) { + NE_DEBUG(NE_DBG_AVM, "Sending request body failed"); int aret = aborted(req, _("Could not send request body"), ret); return RETRY_RET(retry, ret, aret); } @@ -429,11 +447,34 @@ bytes, (int)bytes, buffer); /* invoke progress callback */ - notify_status(sess, ne_status_sending); + struct timeval end_time; + gettimeofday(&end_time, NULL); + req->session->status.sr.duration = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_usec - start_time.tv_usec); + if(notify_status(sess, ne_status_sending)){ + NE_DEBUG(NE_DBG_AVM, "Send request body: notify abort"); + ne_close_connection(sess); + return NE_ERROR; + } + //-AVM +#ifdef NE_LFS +#define ne_stat stat64 +typedef struct stat64 struct_stat; +#else +#define ne_stat stat +typedef struct stat struct_stat; +#endif + struct_stat st; + if (req->body.file.fd>0 && req->body.file.path && ne_stat(req->body.file.path, &st)) { + /* Abort upload, if file is removed in the meantime */ + NE_DEBUG(NE_DBG_AVM, "Send request body: upload aborted, input file is lost"); + ne_close_connection(sess); + return NE_ERROR; + } + //AVM- } if (bytes) { - NE_DEBUG(NE_DBG_HTTP, "Request body provider failed with " + NE_DEBUG(NE_DBG_AVM, "Request body provider failed with " "%" NE_FMT_SSIZE_T "\n", bytes); ne_close_connection(sess); return NE_ERROR; @@ -452,7 +493,7 @@ return RETRY_RET(retry, ret, aret); } } - + NE_DEBUG(NE_DBG_HTTP, "Request body completely sended"); return NE_OK; } @@ -539,7 +580,9 @@ } } - return req; + req->body.file.path = NULL; + + return req; } /* Set the request body length to 'length' */ @@ -573,10 +616,11 @@ } void ne_set_request_body_fd(ne_request *req, int fd, - ne_off_t offset, ne_off_t length) + ne_off_t offset, ne_off_t length, const char* path) { req->body.file.fd = fd; req->body.file.offset = offset; + req->body.file.path = path ? ne_strdup(path) : NULL; req->body.file.length = length; req->body_cb = body_fd_send; req->body_ud = req; @@ -585,7 +629,7 @@ void ne_set_request_flag(ne_request *req, ne_request_flag flag, int value) { - if (flag < (ne_request_flag)NE_SESSFLAG_LAST) { + if (flag < (ne_request_flag)NE_REQFLAG_LAST/*AVM NE_SESSFLAG_LAST was wrong*/) { req->flags[flag] = value; } } @@ -750,6 +794,9 @@ if (req->status.reason_phrase) ne_free(req->status.reason_phrase); + if (req->body.file.path) + ne_free(req->body.file.path); + NE_DEBUG(NE_DBG_HTTP, "Request ends.\n"); ne_free(req); } @@ -859,16 +906,26 @@ size_t readlen = buflen; struct ne_response *const resp = &req->resp; + //AVM + req->session->status.sr.duration = 0; + req->session->status.sr.current = 0; + struct timeval start_time; + gettimeofday(&start_time, NULL);; if (read_response_block(req, resp, buffer, &readlen)) return -1; if (readlen) { + struct timeval end_time; + gettimeofday(&end_time, NULL); + req->session->status.sr.duration = (end_time.tv_sec - start_time.tv_sec) * 1000000 + (end_time.tv_usec - start_time.tv_usec); + req->session->status.sr.current = readlen; req->session->status.sr.progress += readlen; - notify_status(req->session, ne_status_recving); + notify_status(req->session, ne_status_recving); } for (rdr = req->body_readers; rdr!=NULL; rdr=rdr->next) { if (rdr->use && rdr->handler(rdr->userdata, buffer, readlen) != 0) { + NE_DEBUG(NE_DBG_AVM, "Read response block: close connection"); ne_close_connection(req->session); return -1; } @@ -1234,7 +1291,7 @@ * do that. */ if (!req->flags[NE_REQFLAG_IDEMPOTENT] && req->session->persisted && !req->session->flags[NE_SESSFLAG_CONNAUTH]) { - NE_DEBUG(NE_DBG_HTTP, "req: Closing connection for non-idempotent " + NE_DEBUG(NE_DBG_AVM, "req: Closing connection for non-idempotent " "request.\n"); ne_close_connection(req->session); } @@ -1245,7 +1302,7 @@ ret = send_request(req, data); /* Retry this once after a persistent connection timeout. */ if (ret == NE_RETRY) { - NE_DEBUG(NE_DBG_HTTP, "Persistent connection timed out, retrying.\n"); + NE_DEBUG(NE_DBG_AVM, "Persistent connection timed out, retrying.\n"); ret = send_request(req, data); } ne_buffer_destroy(data); @@ -1372,7 +1429,9 @@ } req->session->status.sr.progress = 0; - req->session->status.sr.total = + req->session->status.sr.duration = 0; + req->session->status.sr.current = 0; + req->session->status.sr.total = req->resp.mode == R_CLENGTH ? req->resp.body.clen.total : -1; notify_status(req->session, ne_status_recving); @@ -1401,8 +1460,10 @@ /* Close the connection if persistent connections are disabled or * not supported by the server. */ - if (!req->session->flags[NE_SESSFLAG_PERSIST] || !req->can_persist) + if (!req->session->flags[NE_SESSFLAG_PERSIST] || !req->can_persist){ + NE_DEBUG(NE_DBG_AVM, "End Request: close connection"); ne_close_connection(req->session); + } else req->session->persisted = 1; @@ -1556,9 +1617,9 @@ sess->status.ci.address = host->current; notify_status(sess, ne_status_connecting); #ifdef NE_DEBUGGING - if (ne_debug_mask & NE_DBG_HTTP) { + if (ne_debug_mask & NE_DBG_AVM) { char buf[150]; - NE_DEBUG(NE_DBG_HTTP, "req: Connecting to %s:%u\n", + NE_DEBUG(NE_DBG_AVM, "req: Connecting to %s:%u\n", ne_iaddr_print(host->current, buf, sizeof buf), host->port); } @@ -1568,6 +1629,7 @@ (host->current = resolve_next(host)) != NULL); if (ret) { + NE_DEBUG(NE_DBG_AVM, "Connecting failed: %s\n", ne_sock_error(sess->socket)); const char *msg; if (host->proxy == PROXY_NONE) @@ -1585,6 +1647,7 @@ notify_status(sess, ne_status_connected); sess->nexthop = host; + NE_DEBUG(NE_DBG_AVM, "Connected"); sess->connected = 1; /* clear persistent connection flag. */ @@ -1704,8 +1767,10 @@ if (ret == NE_OK) { ret = ne__negotiate_ssl(sess); - if (ret != NE_OK) + if (ret != NE_OK){ + NE_DEBUG(NE_DBG_AVM, "Opening Connection: Negotiate SSL failed"); ne_close_connection(sess); + } } } #endif Index: src/ne_request.h =================================================================== --- src/ne_request.h (revision 313) +++ src/ne_request.h (working copy) @@ -57,7 +57,7 @@ /* The request body will be taken from 'length' bytes read from the * file descriptor 'fd', starting from file offset 'offset'. */ void ne_set_request_body_fd(ne_request *req, int fd, - ne_off_t offset, ne_off_t length); + ne_off_t offset, ne_off_t length, const char* path); /* "Pull"-based request body provider: a callback which is invoked to * provide blocks of request body on demand.