From 967a15b7f4427dc94ddd9fe1092f6a20104caa2a Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 9 Mar 2007 20:18:38 +0100 Subject: [PATCH] smb: download resuming --- src/protocol/smb/smb2.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/protocol/smb/smb2.c b/src/protocol/smb/smb2.c index e7e3a8ecc..2bbdbd34a 100644 --- a/src/protocol/smb/smb2.c +++ b/src/protocol/smb/smb2.c @@ -26,6 +26,7 @@ #include "main/module.h" #include "main/select.h" #include "network/connection.h" +#include "network/progress.h" #include "network/socket.h" #include "osdep/osdep.h" #include "protocol/auth/auth.h" @@ -342,6 +343,9 @@ do_smb(struct connection *conn) fprintf(stderr, "%" OFF_T_FORMAT, sb.st_size); fclose(stderr); + if (conn->progress->start > 0) { + smbc_lseek(file, conn->progress->start, SEEK_SET); + } while ((r = smbc_read(file, buf, READ_SIZE)) > 0) { if (safe_write(STDOUT_FILENO, buf, r) <= 0) break; @@ -427,7 +431,7 @@ smb_got_header(struct socket *socket, struct read_buffer *rb) { struct connection *conn = socket->conn; struct read_buffer *buf; - int error = 0; + int type_of_data = 0; conn->cached = get_cache_entry(conn->uri); if (!conn->cached) { @@ -448,7 +452,7 @@ smb_got_header(struct socket *socket, struct read_buffer *rb) if (ctype && *ctype) { if (!strcmp(ctype, "text/x-error")) { - error = 1; + type_of_data = 1; mem_free(ctype); } else { if (ctype[0] >= '0' && ctype[0] <= '9') { @@ -464,6 +468,7 @@ smb_got_header(struct socket *socket, struct read_buffer *rb) abort_connection(conn, S_OK); return; } + type_of_data = 2; } else mem_free_set(&conn->cached->content_type, ctype); } @@ -479,10 +484,16 @@ smb_got_header(struct socket *socket, struct read_buffer *rb) abort_connection(conn, S_OUT_OF_MEM); return; } - if (error) { + switch (type_of_data) { + case 1: mem_free_set(&conn->cached->content_type, stracpy("text/html")); read_from_socket(conn->data_socket, buf, S_CONN, smb_got_error); - } else { + break; + case 2: + if (conn->progress->start > 0) { + conn->progress->seek = conn->from = conn->progress->start; + } /* no break here! --witekfl */ + default: read_from_socket(conn->data_socket, buf, S_CONN, smb_got_data); } } @@ -504,8 +515,6 @@ smb_protocol_handler(struct connection *conn) abort_connection(conn, -s_errno); return; } - conn->from = 0; - conn->unrestartable = 1; find_auth(conn->uri); /* remember username and password */ cpid = fork();