2003-12-04 03:01:39 +01:00
|
|
|
/*
|
|
|
|
* HTTP handling functions.
|
|
|
|
*
|
|
|
|
* Copyright 2003 Ferenc Wagner
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-12-04 03:01:39 +01:00
|
|
|
*/
|
2004-06-16 00:45:15 +02:00
|
|
|
|
2012-01-23 12:16:36 +01:00
|
|
|
#include <winsock2.h>
|
2009-05-27 11:45:35 +02:00
|
|
|
#include <wininet.h>
|
2003-12-04 03:01:39 +01:00
|
|
|
#include <stdio.h>
|
2004-01-15 02:48:05 +01:00
|
|
|
#include <errno.h>
|
2003-12-04 03:01:39 +01:00
|
|
|
|
|
|
|
#include "winetest.h"
|
|
|
|
|
2009-05-27 11:45:35 +02:00
|
|
|
#define USER_AGENT "Winetest Shell"
|
|
|
|
#define SERVER_NAME "test.winehq.org"
|
|
|
|
#define URL_PATH "/submit"
|
|
|
|
#define SEP "--8<--cut-here--8<--"
|
|
|
|
#define CONTENT_HEADERS "Content-Type: multipart/form-data; boundary=\"" SEP "\"\r\n" \
|
|
|
|
"Content-Length: %u\r\n\r\n"
|
|
|
|
static const char body1[] = "--" SEP "\r\n"
|
|
|
|
"Content-Disposition: form-data; name=\"reportfile\"; filename=\"%s\"\r\n"
|
|
|
|
"Content-Type: application/octet-stream\r\n\r\n";
|
|
|
|
static const char body2[] = "\r\n--" SEP "\r\n"
|
|
|
|
"Content-Disposition: form-data; name=\"submit\"\r\n\r\n"
|
|
|
|
"Upload File\r\n"
|
|
|
|
"--" SEP "--\r\n";
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static SOCKET
|
2004-03-02 00:28:02 +01:00
|
|
|
open_http (const char *server)
|
2003-12-04 03:01:39 +01:00
|
|
|
{
|
|
|
|
WSADATA wsad;
|
|
|
|
struct sockaddr_in sa;
|
|
|
|
SOCKET s;
|
|
|
|
|
2004-03-02 00:28:02 +01:00
|
|
|
report (R_STATUS, "Opening HTTP connection to %s", server);
|
2003-12-04 03:01:39 +01:00
|
|
|
if (WSAStartup (MAKEWORD (2,2), &wsad)) return INVALID_SOCKET;
|
|
|
|
|
2004-03-19 20:15:23 +01:00
|
|
|
sa.sin_family = AF_INET;
|
|
|
|
sa.sin_port = htons (80);
|
|
|
|
sa.sin_addr.s_addr = inet_addr (server);
|
|
|
|
if (sa.sin_addr.s_addr == INADDR_NONE) {
|
|
|
|
struct hostent *host = gethostbyname (server);
|
|
|
|
if (!host) {
|
|
|
|
report (R_ERROR, "Hostname lookup failed for %s", server);
|
|
|
|
goto failure;
|
2004-03-02 00:28:02 +01:00
|
|
|
}
|
2004-03-19 20:15:23 +01:00
|
|
|
sa.sin_addr.s_addr = ((struct in_addr *)host->h_addr)->s_addr;
|
|
|
|
}
|
|
|
|
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
|
|
|
if (s == INVALID_SOCKET) {
|
|
|
|
report (R_ERROR, "Can't open network socket: %d",
|
|
|
|
WSAGetLastError ());
|
|
|
|
goto failure;
|
2003-12-04 03:01:39 +01:00
|
|
|
}
|
2004-03-19 20:15:23 +01:00
|
|
|
if (!connect (s, (struct sockaddr*)&sa, sizeof (struct sockaddr_in)))
|
|
|
|
return s;
|
|
|
|
|
|
|
|
report (R_ERROR, "Can't connect: %d", WSAGetLastError ());
|
|
|
|
closesocket (s);
|
|
|
|
failure:
|
2003-12-04 03:01:39 +01:00
|
|
|
WSACleanup ();
|
|
|
|
return INVALID_SOCKET;
|
|
|
|
}
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static int
|
2003-12-04 03:01:39 +01:00
|
|
|
close_http (SOCKET s)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = closesocket (s);
|
|
|
|
return (WSACleanup () || ret);
|
|
|
|
}
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static int
|
2003-12-04 03:01:39 +01:00
|
|
|
send_buf (SOCKET s, const char *buf, size_t length)
|
|
|
|
{
|
|
|
|
int sent;
|
|
|
|
|
|
|
|
while (length > 0) {
|
|
|
|
sent = send (s, buf, length, 0);
|
2014-06-12 06:45:36 +02:00
|
|
|
if (sent == SOCKET_ERROR) {
|
|
|
|
if (errno == EINTR) continue;
|
|
|
|
return 1;
|
|
|
|
}
|
2003-12-04 03:01:39 +01:00
|
|
|
buf += sent;
|
|
|
|
length -= sent;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-06-04 12:01:25 +02:00
|
|
|
static int
|
2004-01-15 02:48:05 +01:00
|
|
|
send_str (SOCKET s, ...)
|
2003-12-04 03:01:39 +01:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *p;
|
|
|
|
int ret;
|
|
|
|
size_t len;
|
|
|
|
|
2004-01-15 02:48:05 +01:00
|
|
|
va_start (ap, s);
|
|
|
|
p = vstrmake (&len, ap);
|
2003-12-04 03:01:39 +01:00
|
|
|
va_end (ap);
|
|
|
|
if (!p) return 1;
|
|
|
|
ret = send_buf (s, p, len);
|
2009-05-17 13:28:23 +02:00
|
|
|
heap_free (p);
|
2003-12-04 03:01:39 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-05-27 11:45:35 +02:00
|
|
|
static int
|
|
|
|
send_file_direct (const char *name)
|
2003-12-04 03:01:39 +01:00
|
|
|
{
|
|
|
|
SOCKET s;
|
2008-07-10 17:45:22 +02:00
|
|
|
HANDLE file;
|
2004-02-21 05:01:56 +01:00
|
|
|
#define BUFLEN 8192
|
2005-08-26 10:53:31 +02:00
|
|
|
char buffer[BUFLEN+1];
|
2008-07-10 17:45:22 +02:00
|
|
|
DWORD bytes_read, filesize;
|
2008-07-21 13:00:14 +02:00
|
|
|
size_t total, count;
|
2003-12-04 03:01:39 +01:00
|
|
|
char *str;
|
|
|
|
int ret;
|
|
|
|
|
2004-10-05 04:10:37 +02:00
|
|
|
/* RFC 2616 */
|
2009-05-27 11:45:35 +02:00
|
|
|
static const char head[] = "POST " URL_PATH " HTTP/1.0\r\n"
|
|
|
|
"Host: " SERVER_NAME "\r\n"
|
|
|
|
"User-Agent: " USER_AGENT "\r\n"
|
|
|
|
CONTENT_HEADERS
|
|
|
|
"\r\n";
|
|
|
|
|
|
|
|
s = open_http (SERVER_NAME);
|
2004-03-19 20:15:23 +01:00
|
|
|
if (s == INVALID_SOCKET) return 1;
|
2003-12-04 03:01:39 +01:00
|
|
|
|
2008-07-10 17:45:22 +02:00
|
|
|
file = CreateFileA( name, GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL );
|
2008-07-16 18:33:12 +02:00
|
|
|
|
|
|
|
if ((file == INVALID_HANDLE_VALUE) &&
|
|
|
|
(GetLastError() == ERROR_INVALID_PARAMETER)) {
|
|
|
|
/* FILE_SHARE_DELETE not supported on win9x */
|
|
|
|
file = CreateFileA( name, GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL );
|
|
|
|
}
|
2008-07-10 17:45:22 +02:00
|
|
|
if (file == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
report (R_WARNING, "Can't open file '%s': %u", name, GetLastError());
|
2004-01-15 02:48:05 +01:00
|
|
|
goto abort1;
|
|
|
|
}
|
2008-07-10 17:45:22 +02:00
|
|
|
filesize = GetFileSize( file, NULL );
|
2006-11-30 19:01:02 +01:00
|
|
|
if (filesize > 1.5*1024*1024) {
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_WARNING,
|
2006-11-30 19:01:02 +01:00
|
|
|
"File too big (%.1f MB > 1.5 MB); submitting partial report.",
|
2004-07-06 23:03:22 +02:00
|
|
|
filesize/1024.0/1024);
|
2009-05-27 11:45:35 +02:00
|
|
|
filesize = (DWORD) 1.5*1024*1024;
|
2004-01-15 02:48:05 +01:00
|
|
|
}
|
2003-12-04 03:01:39 +01:00
|
|
|
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_STATUS, "Sending header");
|
2003-12-04 03:01:39 +01:00
|
|
|
str = strmake (&total, body1, name);
|
|
|
|
ret = send_str (s, head, filesize + total + sizeof body2 - 1) ||
|
|
|
|
send_buf (s, str, total);
|
2009-05-17 13:28:23 +02:00
|
|
|
heap_free (str);
|
2003-12-04 03:01:39 +01:00
|
|
|
if (ret) {
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_WARNING, "Error sending header: %d, %d",
|
|
|
|
errno, WSAGetLastError ());
|
2003-12-04 03:01:39 +01:00
|
|
|
goto abort2;
|
|
|
|
}
|
|
|
|
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_STATUS, "Sending %u bytes of data", filesize);
|
2004-02-21 05:01:56 +01:00
|
|
|
report (R_PROGRESS, 2, filesize);
|
2004-07-06 23:03:22 +02:00
|
|
|
total = 0;
|
2008-07-10 17:45:22 +02:00
|
|
|
while (total < filesize && ReadFile( file, buffer, BUFLEN/2, &bytes_read, NULL )) {
|
2010-06-24 21:11:43 +02:00
|
|
|
if (aborting) goto abort2;
|
2008-07-10 17:45:22 +02:00
|
|
|
if (!bytes_read) break;
|
2004-07-06 23:03:22 +02:00
|
|
|
total += bytes_read;
|
|
|
|
if (total > filesize) bytes_read -= total - filesize;
|
2003-12-04 03:01:39 +01:00
|
|
|
if (send_buf (s, buffer, bytes_read)) {
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_WARNING, "Error sending body: %d, %d",
|
|
|
|
errno, WSAGetLastError ());
|
2003-12-04 03:01:39 +01:00
|
|
|
goto abort2;
|
|
|
|
}
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_DELTA, bytes_read, "Network transfer: In progress");
|
|
|
|
}
|
2008-07-10 17:45:22 +02:00
|
|
|
CloseHandle( file );
|
2003-12-04 03:01:39 +01:00
|
|
|
|
|
|
|
if (send_buf (s, body2, sizeof body2 - 1)) {
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_WARNING, "Error sending trailer: %d, %d",
|
|
|
|
errno, WSAGetLastError ());
|
2006-10-14 02:55:40 +02:00
|
|
|
goto abort1;
|
2003-12-04 03:01:39 +01:00
|
|
|
}
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_DELTA, 0, "Network transfer: Done");
|
2003-12-04 03:01:39 +01:00
|
|
|
|
|
|
|
total = 0;
|
2004-02-21 05:01:56 +01:00
|
|
|
while ((bytes_read = recv (s, buffer+total, BUFLEN-total, 0))) {
|
2003-12-04 03:01:39 +01:00
|
|
|
if ((signed)bytes_read == SOCKET_ERROR) {
|
2014-06-12 06:45:36 +02:00
|
|
|
if (errno == EINTR) continue;
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_WARNING, "Error receiving reply: %d, %d",
|
|
|
|
errno, WSAGetLastError ());
|
2003-12-04 03:01:39 +01:00
|
|
|
goto abort1;
|
|
|
|
}
|
|
|
|
total += bytes_read;
|
2004-02-21 05:01:56 +01:00
|
|
|
if (total == BUFLEN) {
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_WARNING, "Buffer overflow");
|
2003-12-04 03:01:39 +01:00
|
|
|
goto abort1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (close_http (s)) {
|
2004-01-15 02:48:05 +01:00
|
|
|
report (R_WARNING, "Error closing connection: %d, %d",
|
|
|
|
errno, WSAGetLastError ());
|
2003-12-04 03:01:39 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-07-21 13:00:14 +02:00
|
|
|
str = strmake (&count, "Received %s (%d bytes).\n",
|
2003-12-04 03:01:39 +01:00
|
|
|
name, filesize);
|
2009-05-27 11:45:35 +02:00
|
|
|
ret = total < count || memcmp (str, buffer + total - count, count) != 0;
|
2009-05-17 13:28:23 +02:00
|
|
|
heap_free (str);
|
2004-02-21 05:01:56 +01:00
|
|
|
if (ret) {
|
|
|
|
buffer[total] = 0;
|
|
|
|
str = strstr (buffer, "\r\n\r\n");
|
2004-08-18 22:56:00 +02:00
|
|
|
if (!str) str = buffer;
|
|
|
|
else str = str + 4;
|
2004-02-21 05:01:56 +01:00
|
|
|
report (R_ERROR, "Can't submit logfile '%s'. "
|
2004-08-18 22:56:00 +02:00
|
|
|
"Server response: %s", name, str);
|
2004-02-21 05:01:56 +01:00
|
|
|
}
|
|
|
|
return ret;
|
2003-12-04 03:01:39 +01:00
|
|
|
|
|
|
|
abort2:
|
2008-07-10 17:45:22 +02:00
|
|
|
CloseHandle( file );
|
2003-12-04 03:01:39 +01:00
|
|
|
abort1:
|
|
|
|
close_http (s);
|
|
|
|
return 1;
|
|
|
|
}
|
2009-05-27 11:45:35 +02:00
|
|
|
|
|
|
|
static int
|
|
|
|
send_file_wininet (const char *name)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
HMODULE wininet_mod = NULL;
|
|
|
|
HINTERNET (WINAPI *pInternetOpen)(LPCSTR agent, DWORD access_type, LPCSTR proxy_name, LPCSTR proxy_bypass, DWORD flags);
|
|
|
|
HINTERNET (WINAPI *pInternetConnect)(HINTERNET session, LPCSTR server_name, INTERNET_PORT server_port, LPCSTR username, LPCSTR password, DWORD service, DWORD flags, DWORD_PTR *context);
|
|
|
|
HINTERNET (WINAPI *pHttpOpenRequest)(HINTERNET connection, LPCSTR verb, LPCSTR object_name, LPCSTR version, LPCSTR referer, LPCSTR *accept_types, DWORD flags, DWORD_PTR context);
|
|
|
|
BOOL (WINAPI *pHttpSendRequestEx)(HINTERNET request, LPINTERNET_BUFFERSA buffers_in, LPINTERNET_BUFFERSA buffers_out, DWORD flags, DWORD_PTR context);
|
|
|
|
BOOL (WINAPI *pInternetWriteFile)(HINTERNET file, LPCVOID buffer, DWORD number_of_bytes_to_write, LPDWORD number_of_bytes_written);
|
|
|
|
BOOL (WINAPI *pHttpEndRequest)(HINTERNET request, LPINTERNET_BUFFERSA buffers_out, DWORD flags, DWORD_PTR context);
|
|
|
|
BOOL (WINAPI *pInternetReadFile)(HINTERNET file, LPCVOID buffer, DWORD number_of_bytes_to_read, LPDWORD number_of_bytes_read);
|
|
|
|
BOOL (WINAPI *pInternetCloseHandle)(HINTERNET Handle) = NULL;
|
|
|
|
HANDLE file = INVALID_HANDLE_VALUE;
|
|
|
|
DWORD filesize, bytes_read, bytes_written;
|
|
|
|
size_t total, count;
|
|
|
|
char *str = NULL;
|
|
|
|
HINTERNET session = NULL;
|
|
|
|
HINTERNET connection = NULL;
|
|
|
|
HINTERNET request = NULL;
|
|
|
|
INTERNET_BUFFERSA buffers_in = { 0 };
|
|
|
|
char buffer[BUFLEN+1];
|
|
|
|
|
|
|
|
static const char extra_headers[] =
|
|
|
|
CONTENT_HEADERS;
|
|
|
|
|
2012-01-19 21:05:28 +01:00
|
|
|
wininet_mod = LoadLibraryA("wininet.dll");
|
2009-05-27 11:45:35 +02:00
|
|
|
if (wininet_mod == NULL)
|
|
|
|
goto done;
|
|
|
|
pInternetOpen = (void *)GetProcAddress(wininet_mod, "InternetOpenA");
|
|
|
|
pInternetConnect = (void *)GetProcAddress(wininet_mod, "InternetConnectA");
|
|
|
|
pHttpOpenRequest = (void *)GetProcAddress(wininet_mod, "HttpOpenRequestA");
|
|
|
|
pHttpSendRequestEx = (void *)GetProcAddress(wininet_mod, "HttpSendRequestExA");
|
|
|
|
pInternetWriteFile = (void *)GetProcAddress(wininet_mod, "InternetWriteFile");
|
|
|
|
pHttpEndRequest = (void *)GetProcAddress(wininet_mod, "HttpEndRequestA");
|
|
|
|
pInternetReadFile = (void *)GetProcAddress(wininet_mod, "InternetReadFile");
|
|
|
|
pInternetCloseHandle = (void *)GetProcAddress(wininet_mod, "InternetCloseHandle");
|
|
|
|
if (pInternetOpen == NULL || pInternetConnect == NULL || pHttpOpenRequest == NULL || pHttpSendRequestEx == NULL || pHttpEndRequest == NULL ||
|
|
|
|
pInternetWriteFile == NULL || pInternetReadFile == NULL || pInternetCloseHandle == NULL) {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
file = CreateFileA( name, GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL );
|
|
|
|
|
|
|
|
if ((file == INVALID_HANDLE_VALUE) &&
|
|
|
|
(GetLastError() == ERROR_INVALID_PARAMETER)) {
|
|
|
|
/* FILE_SHARE_DELETE not supported on win9x */
|
|
|
|
file = CreateFileA( name, GENERIC_READ,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE,
|
|
|
|
NULL, OPEN_EXISTING, 0, NULL );
|
|
|
|
}
|
|
|
|
if (file == INVALID_HANDLE_VALUE) {
|
|
|
|
report (R_WARNING, "Can't open file '%s': %u", name, GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
filesize = GetFileSize( file, NULL );
|
|
|
|
if (filesize > 1.5*1024*1024) {
|
|
|
|
report (R_WARNING,
|
|
|
|
"File too big (%.1f MB > 1.5 MB); submitting partial report.",
|
|
|
|
filesize/1024.0/1024);
|
2009-12-19 18:00:46 +01:00
|
|
|
filesize = 1.5*1024*1024;
|
2009-05-27 11:45:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
report (R_STATUS, "Opening HTTP connection to " SERVER_NAME);
|
|
|
|
session = pInternetOpen (USER_AGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
|
|
|
|
if (session == NULL) {
|
|
|
|
report (R_WARNING, "Unable to open connection, error %u", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
connection = pInternetConnect (session, SERVER_NAME, INTERNET_DEFAULT_HTTP_PORT, "", "", INTERNET_SERVICE_HTTP, 0, 0);
|
|
|
|
if (connection == NULL) {
|
|
|
|
report (R_WARNING, "Unable to connect, error %u", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
request = pHttpOpenRequest (connection, "POST", URL_PATH, NULL, NULL, NULL,
|
|
|
|
INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES | INTERNET_FLAG_NO_UI |
|
|
|
|
INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);
|
|
|
|
if (request == NULL) {
|
|
|
|
report (R_WARNING, "Unable to open request, error %u", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
report (R_STATUS, "Sending request");
|
|
|
|
str = strmake (&total, body1, name);
|
|
|
|
memset(&buffers_in, 0, sizeof(INTERNET_BUFFERSA));
|
|
|
|
buffers_in.dwStructSize = sizeof(INTERNET_BUFFERSA);
|
|
|
|
buffers_in.dwBufferTotal = filesize + total + sizeof body2 - 1;
|
|
|
|
buffers_in.lpcszHeader = strmake (&count, extra_headers, buffers_in.dwBufferTotal);
|
|
|
|
buffers_in.dwHeadersLength = count;
|
|
|
|
if (! pHttpSendRequestEx(request, &buffers_in, NULL, 0, 0)) {
|
|
|
|
report (R_WARNING, "Unable to send request, error %u", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! pInternetWriteFile(request, str, total, &bytes_written) || bytes_written != total) {
|
|
|
|
report (R_WARNING, "Unable to write body data, error %u", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
report (R_STATUS, "Sending %u bytes of data", filesize);
|
|
|
|
report (R_PROGRESS, 2, filesize);
|
|
|
|
total = 0;
|
|
|
|
while (total < filesize && ReadFile( file, buffer, BUFLEN/2, &bytes_read, NULL )) {
|
2010-06-24 21:11:43 +02:00
|
|
|
if (aborting) goto done;
|
2009-05-27 11:45:35 +02:00
|
|
|
if (!bytes_read) break;
|
|
|
|
total += bytes_read;
|
|
|
|
if (total > filesize) bytes_read -= total - filesize;
|
|
|
|
if (! pInternetWriteFile (request, buffer, bytes_read, &bytes_written) || bytes_written != bytes_read) {
|
|
|
|
report (R_WARNING, "Error sending body: %u", GetLastError ());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
report (R_DELTA, bytes_read, "Network transfer: In progress");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! pInternetWriteFile(request, body2, sizeof body2 - 1, &bytes_written) || bytes_written != sizeof body2 - 1) {
|
|
|
|
report (R_WARNING, "Unable to write final body data, error %u", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (! pHttpEndRequest(request, NULL, 0, 0)) {
|
|
|
|
report (R_WARNING, "Unable to end request, error %u", GetLastError());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
report (R_DELTA, 0, "Network transfer: Done");
|
|
|
|
|
|
|
|
total = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (! pInternetReadFile(request, buffer+total, BUFLEN-total, &bytes_read)) {
|
|
|
|
report (R_WARNING, "Error receiving reply: %u", GetLastError ());
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
total += bytes_read;
|
|
|
|
if (total == BUFLEN) {
|
|
|
|
report (R_WARNING, "Buffer overflow");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (bytes_read != 0);
|
|
|
|
|
|
|
|
heap_free (str);
|
|
|
|
str = strmake (&count, "Received %s (%d bytes).\n",
|
|
|
|
name, filesize);
|
|
|
|
if (total < count || memcmp (str, buffer + total - count, count) != 0) {
|
|
|
|
buffer[total] = 0;
|
|
|
|
report (R_ERROR, "Can't submit logfile '%s'. "
|
|
|
|
"Server response: %s", name, buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
2016-07-08 10:09:51 +02:00
|
|
|
heap_free((void *)buffers_in.lpcszHeader);
|
|
|
|
heap_free(str);
|
2009-05-27 11:45:35 +02:00
|
|
|
if (pInternetCloseHandle != NULL && request != NULL)
|
|
|
|
pInternetCloseHandle (request);
|
|
|
|
if (pInternetCloseHandle != NULL && connection != NULL)
|
|
|
|
pInternetCloseHandle (connection);
|
|
|
|
if (pInternetCloseHandle != NULL && session != NULL)
|
|
|
|
pInternetCloseHandle (session);
|
|
|
|
if (file != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle (file);
|
|
|
|
if (wininet_mod != NULL)
|
|
|
|
FreeLibrary (wininet_mod);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
send_file (const char *name)
|
|
|
|
{
|
|
|
|
return send_file_wininet( name ) || send_file_direct( name );
|
|
|
|
}
|