mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
Gisle Vanem: patches to make sws.c compile under MingW/MSVC is
attached. And some cosmetic fixes.
This commit is contained in:
parent
78ebe3fa5a
commit
25e98179be
@ -33,11 +33,14 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#ifdef HAVE_UNISTD_H
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
#ifdef HAVE_SYS_SOCKET_H
|
#ifdef HAVE_SYS_SOCKET_H
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#endif
|
#endif
|
||||||
@ -61,14 +64,23 @@
|
|||||||
#define TRUE 1
|
#define TRUE 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <winsock2.h>
|
#include <winsock2.h>
|
||||||
|
#include <process.h>
|
||||||
|
|
||||||
|
#define sleep(sec) Sleep ((sec)*1000)
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#define strncasecmp strnicmp
|
||||||
|
#endif
|
||||||
|
|
||||||
#define EINPROGRESS WSAEINPROGRESS
|
#define EINPROGRESS WSAEINPROGRESS
|
||||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||||
#define EISCONN WSAEISCONN
|
#define EISCONN WSAEISCONN
|
||||||
#define ENOTSOCK WSAENOTSOCK
|
#define ENOTSOCK WSAENOTSOCK
|
||||||
#define ECONNREFUSED WSAECONNREFUSED
|
#define ECONNREFUSED WSAECONNREFUSED
|
||||||
|
|
||||||
|
static void win32_cleanup(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define REQBUFSIZ 150000
|
#define REQBUFSIZ 150000
|
||||||
@ -118,6 +130,8 @@ void storerequest(char *reqbuf);
|
|||||||
|
|
||||||
#define CMD_AUTH_REQUIRED "auth_required"
|
#define CMD_AUTH_REQUIRED "auth_required"
|
||||||
|
|
||||||
|
#define END_OF_HEADERS "\r\n\r\n"
|
||||||
|
|
||||||
/* global variable, where to find the 'data' dir */
|
/* global variable, where to find the 'data' dir */
|
||||||
const char *path=".";
|
const char *path=".";
|
||||||
|
|
||||||
@ -134,25 +148,22 @@ enum {
|
|||||||
|
|
||||||
/* sent as reply to a QUIT */
|
/* sent as reply to a QUIT */
|
||||||
static const char *docquit =
|
static const char *docquit =
|
||||||
"HTTP/1.1 200 Goodbye\r\n"
|
"HTTP/1.1 200 Goodbye" END_OF_HEADERS;
|
||||||
"\r\n";
|
|
||||||
|
|
||||||
/* sent as reply to a CONNECT */
|
/* sent as reply to a CONNECT */
|
||||||
static const char *docconnect =
|
static const char *docconnect =
|
||||||
"HTTP/1.1 200 Mighty fine indeed\r\n"
|
"HTTP/1.1 200 Mighty fine indeed" END_OF_HEADERS;
|
||||||
"\r\n";
|
|
||||||
|
|
||||||
/* sent as reply to a "bad" CONNECT */
|
/* sent as reply to a "bad" CONNECT */
|
||||||
static const char *docbadconnect =
|
static const char *docbadconnect =
|
||||||
"HTTP/1.1 501 Forbidden you fool\r\n"
|
"HTTP/1.1 501 Forbidden you fool" END_OF_HEADERS;
|
||||||
"\r\n";
|
|
||||||
|
|
||||||
/* send back this on 404 file not found */
|
/* send back this on 404 file not found */
|
||||||
static const char *doc404 = "HTTP/1.1 404 Not Found\n"
|
static const char *doc404 = "HTTP/1.1 404 Not Found\r\n"
|
||||||
"Server: " SWSVERSION "\n"
|
"Server: " SWSVERSION "\r\n"
|
||||||
"Connection: close\n"
|
"Connection: close\r\n"
|
||||||
"Content-Type: text/html\n"
|
"Content-Type: text/html"
|
||||||
"\n"
|
END_OF_HEADERS
|
||||||
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
|
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
|
||||||
"<HTML><HEAD>\n"
|
"<HTML><HEAD>\n"
|
||||||
"<TITLE>404 Not Found</TITLE>\n"
|
"<TITLE>404 Not Found</TITLE>\n"
|
||||||
@ -162,7 +173,7 @@ static const char *doc404 = "HTTP/1.1 404 Not Found\n"
|
|||||||
"<P><HR><ADDRESS>" SWSVERSION "</ADDRESS>\n" "</BODY></HTML>\n";
|
"<P><HR><ADDRESS>" SWSVERSION "</ADDRESS>\n" "</BODY></HTML>\n";
|
||||||
|
|
||||||
#ifdef SIGPIPE
|
#ifdef SIGPIPE
|
||||||
static volatile int sigpipe;
|
static volatile int sigpipe; /* Why? It's not used */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void logmsg(const char *msg, ...)
|
static void logmsg(const char *msg, ...)
|
||||||
@ -197,7 +208,23 @@ static void sigpipe_handler(int sig)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define END_OF_HEADERS "\r\n\r\n"
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||||
|
#undef perror
|
||||||
|
#define perror(m) win32_perror(m)
|
||||||
|
|
||||||
|
static void win32_perror (const char *msg)
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
DWORD err = WSAGetLastError();
|
||||||
|
|
||||||
|
if (!FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
|
||||||
|
LANG_NEUTRAL, buf, sizeof(buf), NULL))
|
||||||
|
snprintf(buf, sizeof(buf), "Unknown error %lu (%#lx)", err, err);
|
||||||
|
if (msg)
|
||||||
|
fprintf(stderr, "%s: ", msg);
|
||||||
|
fprintf(stderr, "%s\n", buf);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static char *test2file(int testno)
|
static char *test2file(int testno)
|
||||||
{
|
{
|
||||||
@ -267,7 +294,7 @@ int ProcessRequest(struct httprequest *req)
|
|||||||
else
|
else
|
||||||
req->partno = 0;
|
req->partno = 0;
|
||||||
|
|
||||||
sprintf(logbuf, "Reqested test number %ld part %ld",
|
sprintf(logbuf, "Requested test number %ld part %ld",
|
||||||
req->testno, req->partno);
|
req->testno, req->partno);
|
||||||
|
|
||||||
logmsg(logbuf);
|
logmsg(logbuf);
|
||||||
@ -577,7 +604,7 @@ static int send_doc(int sock, struct httprequest *req)
|
|||||||
client... */
|
client... */
|
||||||
if(strstr(buffer, "swsclose") || !count) {
|
if(strstr(buffer, "swsclose") || !count) {
|
||||||
persistant = FALSE;
|
persistant = FALSE;
|
||||||
logmsg("connection close instruction swsclose found in response");
|
logmsg("connection close instruction \"swsclose\" found in response");
|
||||||
}
|
}
|
||||||
if(strstr(buffer, "swsbounce")) {
|
if(strstr(buffer, "swsbounce")) {
|
||||||
prevbounce = TRUE;
|
prevbounce = TRUE;
|
||||||
@ -635,7 +662,7 @@ static int send_doc(int sock, struct httprequest *req)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
#if defined(WIN32) && !defined(__CYGWIN__)
|
||||||
static void win32_init(void)
|
static void win32_init(void)
|
||||||
{
|
{
|
||||||
WORD wVersionRequested;
|
WORD wVersionRequested;
|
||||||
@ -647,7 +674,7 @@ static void win32_init(void)
|
|||||||
|
|
||||||
if (err != 0) {
|
if (err != 0) {
|
||||||
perror("Winsock init failed");
|
perror("Winsock init failed");
|
||||||
logmsg("Error initializing winsock -- aborting\n");
|
logmsg("Error initialising winsock -- aborting\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -684,7 +711,8 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
||||||
win32_init();
|
win32_init();
|
||||||
#endif
|
atexit(win32_cleanup);
|
||||||
|
#else
|
||||||
|
|
||||||
#ifdef SIGPIPE
|
#ifdef SIGPIPE
|
||||||
#ifdef HAVE_SIGNAL
|
#ifdef HAVE_SIGNAL
|
||||||
@ -693,6 +721,7 @@ int main(int argc, char *argv[])
|
|||||||
#ifdef HAVE_SIGINTERRUPT
|
#ifdef HAVE_SIGINTERRUPT
|
||||||
siginterrupt(SIGPIPE, 1);
|
siginterrupt(SIGPIPE, 1);
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
@ -776,10 +805,6 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
sclose(sock);
|
sclose(sock);
|
||||||
|
|
||||||
#if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
|
|
||||||
win32_cleanup();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user