- Refactor and fix connection opening.
- Target test.winehq.org.
This commit is contained in:
parent
5983223b70
commit
ca0f5793da
|
@ -33,25 +33,29 @@ open_http (const char *server)
|
||||||
report (R_STATUS, "Opening HTTP connection to %s", server);
|
report (R_STATUS, "Opening HTTP connection to %s", server);
|
||||||
if (WSAStartup (MAKEWORD (2,2), &wsad)) return INVALID_SOCKET;
|
if (WSAStartup (MAKEWORD (2,2), &wsad)) return INVALID_SOCKET;
|
||||||
|
|
||||||
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
sa.sin_family = AF_INET;
|
||||||
if (s != INVALID_SOCKET) {
|
sa.sin_port = htons (80);
|
||||||
unsigned long addr = inet_addr(server);
|
sa.sin_addr.s_addr = inet_addr (server);
|
||||||
|
if (sa.sin_addr.s_addr == INADDR_NONE) {
|
||||||
sa.sin_family = AF_INET;
|
struct hostent *host = gethostbyname (server);
|
||||||
sa.sin_port = htons (80);
|
if (!host) {
|
||||||
if (addr != INADDR_NONE)
|
report (R_ERROR, "Hostname lookup failed for %s", server);
|
||||||
sa.sin_addr.s_addr = addr;
|
goto failure;
|
||||||
else
|
|
||||||
{
|
|
||||||
struct hostent *host;
|
|
||||||
|
|
||||||
if ((host = gethostbyname(server)) != NULL)
|
|
||||||
addr = ((struct in_addr *)host->h_addr)->s_addr;
|
|
||||||
}
|
}
|
||||||
if (!connect (s, (struct sockaddr*)&sa,
|
sa.sin_addr.s_addr = ((struct in_addr *)host->h_addr)->s_addr;
|
||||||
sizeof (struct sockaddr_in)))
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
|
if (s == INVALID_SOCKET) {
|
||||||
|
report (R_ERROR, "Can't open network socket: %d",
|
||||||
|
WSAGetLastError ());
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
if (!connect (s, (struct sockaddr*)&sa, sizeof (struct sockaddr_in)))
|
||||||
|
return s;
|
||||||
|
|
||||||
|
report (R_ERROR, "Can't connect: %d", WSAGetLastError ());
|
||||||
|
closesocket (s);
|
||||||
|
failure:
|
||||||
WSACleanup ();
|
WSACleanup ();
|
||||||
return INVALID_SOCKET;
|
return INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
@ -110,7 +114,7 @@ send_file (const char *name)
|
||||||
/* RFC 2068 */
|
/* RFC 2068 */
|
||||||
#define SEP "-"
|
#define SEP "-"
|
||||||
const char head[] = "POST /submit HTTP/1.0\r\n"
|
const char head[] = "POST /submit HTTP/1.0\r\n"
|
||||||
"Host: afavant\r\n"
|
"Host: test.winehq.org\r\n"
|
||||||
"User-Agent: Winetest Shell\r\n"
|
"User-Agent: Winetest Shell\r\n"
|
||||||
"Content-Type: multipart/form-data; boundary=" SEP "\r\n"
|
"Content-Type: multipart/form-data; boundary=" SEP "\r\n"
|
||||||
"Content-Length: %u\r\n\r\n";
|
"Content-Length: %u\r\n\r\n";
|
||||||
|
@ -123,12 +127,8 @@ send_file (const char *name)
|
||||||
"--" SEP "--\r\n";
|
"--" SEP "--\r\n";
|
||||||
|
|
||||||
buffer = xmalloc (BUFLEN + 1);
|
buffer = xmalloc (BUFLEN + 1);
|
||||||
s = open_http ("www.winehq.org");
|
s = open_http ("test.winehq.org");
|
||||||
if (s == INVALID_SOCKET) {
|
if (s == INVALID_SOCKET) return 1;
|
||||||
report (R_WARNING, "Can't open network connection: %d",
|
|
||||||
WSAGetLastError ());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
f = fopen (name, "rb");
|
f = fopen (name, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#include "winetest.h"
|
#include "winetest.h"
|
||||||
|
|
||||||
|
@ -43,7 +44,8 @@ void xprintf (const char *fmt, ...)
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start (ap, fmt);
|
va_start (ap, fmt);
|
||||||
if (vprintf (fmt, ap) < 0) report (R_FATAL, "Can't write logs.");
|
if (vprintf (fmt, ap) < 0)
|
||||||
|
report (R_FATAL, "Can't write logs: %d", errno);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue