mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
introduce win32 build capability
This adds win32 build compatability to libwebsockets. The patch is from Peter Hinz, Andy Green has cleaned it up a bit and possibly broken win32 compatability since I can't test it, so there may be followup patches. It compiles fine under Linux after this patch anyway. Much of the patch is changing a reserved keyword for Visual C compiler "this" to "context", but there is no real C99 support in the MSFT compiler even though it is 2011 so C99 style array declarations have been mangled back into "ancient C" style. Some windows-isms are also added like closesocket() but these are quite localized. Win32 random is just using C library random() call at the moment vs Linux /dev/urandom. canonical hostname detection is broken in win32 at the moment. Signed-off-by: Peter Hinz <cerebusrc@gmail.com> Signed-off-by: Andy Green <andy@warmcat.com>
This commit is contained in:
parent
385e7ad034
commit
56885f3084
32 changed files with 1605 additions and 450 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
/**
|
||||
* libwebsocket_client_connect() - Connect to another websocket server
|
||||
* @this: Websocket context
|
||||
* @context: Websocket context
|
||||
* @address: Remote server address, eg, "myserver.com"
|
||||
* @port: Port to connect to on the remote server, eg, 80
|
||||
* @ssl_connection: 0 = ws://, 1 = wss:// encrypted, 2 = wss:// allow self
|
||||
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
|
||||
struct libwebsocket *
|
||||
libwebsocket_client_connect(struct libwebsocket_context *this,
|
||||
libwebsocket_client_connect(struct libwebsocket_context *context,
|
||||
const char *address,
|
||||
int port,
|
||||
int ssl_connection,
|
||||
|
@ -117,7 +117,7 @@ libwebsocket_client_connect(struct libwebsocket_context *this,
|
|||
|
||||
/* force no mask if he asks for that though */
|
||||
|
||||
if (this->options & LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK)
|
||||
if (context->options & LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK)
|
||||
wsi->xor_mask = xor_no_mask;
|
||||
|
||||
for (n = 0; n < WSI_TOKEN_COUNT; n++) {
|
||||
|
@ -129,7 +129,7 @@ libwebsocket_client_connect(struct libwebsocket_context *this,
|
|||
* proxy?
|
||||
*/
|
||||
|
||||
if (this->http_proxy_port) {
|
||||
if (context->http_proxy_port) {
|
||||
plen = sprintf(pkt, "CONNECT %s:%u HTTP/1.0\x0d\x0a"
|
||||
"User-agent: libwebsockets\x0d\x0a"
|
||||
/*Proxy-authorization: basic aGVsbG86d29ybGQ= */
|
||||
|
@ -137,8 +137,8 @@ libwebsocket_client_connect(struct libwebsocket_context *this,
|
|||
|
||||
/* OK from now on we talk via the proxy */
|
||||
|
||||
address = this->http_proxy_address;
|
||||
port = this->http_proxy_port;
|
||||
address = context->http_proxy_address;
|
||||
port = context->http_proxy_port;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -171,26 +171,30 @@ libwebsocket_client_connect(struct libwebsocket_context *this,
|
|||
|
||||
/* into fd -> wsi hashtable */
|
||||
|
||||
insert_wsi(this, wsi);
|
||||
insert_wsi(context, wsi);
|
||||
|
||||
/* into internal poll list */
|
||||
|
||||
this->fds[this->fds_count].fd = wsi->sock;
|
||||
this->fds[this->fds_count].revents = 0;
|
||||
this->fds[this->fds_count++].events = POLLIN;
|
||||
context->fds[context->fds_count].fd = wsi->sock;
|
||||
context->fds[context->fds_count].revents = 0;
|
||||
context->fds[context->fds_count++].events = POLLIN;
|
||||
|
||||
/* external POLL support via protocol 0 */
|
||||
this->protocols[0].callback(this, wsi,
|
||||
context->protocols[0].callback(context, wsi,
|
||||
LWS_CALLBACK_ADD_POLL_FD,
|
||||
(void *)(long)wsi->sock, NULL, POLLIN);
|
||||
|
||||
/* we are connected to server, or proxy */
|
||||
|
||||
if (this->http_proxy_port) {
|
||||
if (context->http_proxy_port) {
|
||||
|
||||
n = send(wsi->sock, pkt, plen, 0);
|
||||
if (n < 0) {
|
||||
#ifdef WIN32
|
||||
closesocket(wsi->sock);
|
||||
#else
|
||||
close(wsi->sock);
|
||||
#endif
|
||||
fprintf(stderr, "ERROR writing to proxy socket\n");
|
||||
goto bail1;
|
||||
}
|
||||
|
@ -213,7 +217,7 @@ libwebsocket_client_connect(struct libwebsocket_context *this,
|
|||
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
|
||||
pfd.fd = wsi->sock;
|
||||
pfd.revents = POLLIN;
|
||||
libwebsocket_service_fd(this, &pfd);
|
||||
libwebsocket_service_fd(context, &pfd);
|
||||
|
||||
return wsi;
|
||||
|
||||
|
|
|
@ -318,7 +318,8 @@ handshake_0405(struct libwebsocket *wsi)
|
|||
|
||||
/* select the nonce */
|
||||
|
||||
n = read(wsi->protocol->owning_server->fd_random, hash, 16);
|
||||
n = libwebsockets_get_random(wsi->protocol->owning_server,
|
||||
hash, 16);
|
||||
if (n != 16) {
|
||||
fprintf(stderr, "Unable to read random device %s %d\n",
|
||||
SYSTEM_RANDOM_FILEPATH, n);
|
||||
|
@ -448,7 +449,7 @@ bail:
|
|||
*/
|
||||
|
||||
int
|
||||
libwebsocket_read(struct libwebsocket_context *this, struct libwebsocket *wsi,
|
||||
libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi,
|
||||
unsigned char * buf, size_t len)
|
||||
{
|
||||
size_t n;
|
||||
|
@ -490,7 +491,7 @@ libwebsocket_read(struct libwebsocket_context *this, struct libwebsocket *wsi,
|
|||
if (!wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len ||
|
||||
!wsi->utf8_token[WSI_TOKEN_CONNECTION].token_len) {
|
||||
if (wsi->protocol->callback)
|
||||
(wsi->protocol->callback)(this, wsi,
|
||||
(wsi->protocol->callback)(context, wsi,
|
||||
LWS_CALLBACK_HTTP, wsi->user_space,
|
||||
wsi->utf8_token[WSI_TOKEN_GET_URI].token, 0);
|
||||
wsi->state = WSI_STATE_HTTP;
|
||||
|
@ -612,7 +613,7 @@ libwebsocket_read(struct libwebsocket_context *this, struct libwebsocket *wsi,
|
|||
return 0;
|
||||
|
||||
bail:
|
||||
libwebsocket_close_and_free_session(this, wsi,
|
||||
libwebsocket_close_and_free_session(context, wsi,
|
||||
LWS_CLOSE_STATUS_NOSTATUS);
|
||||
|
||||
return -1;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,7 +22,22 @@
|
|||
#ifndef __LIBWEBSOCKET_H__
|
||||
#define __LIBWEBSOCKET_H__
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include "websock-w32.h"
|
||||
#include "gettimeofday.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#else
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#define CONTEXT_PORT_NO_LISTEN 0
|
||||
|
||||
|
@ -48,7 +63,6 @@ enum libwebsocket_callback_reasons {
|
|||
LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS,
|
||||
LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION,
|
||||
LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER,
|
||||
|
||||
/* external poll() management support */
|
||||
LWS_CALLBACK_ADD_POLL_FD,
|
||||
LWS_CALLBACK_DEL_POLL_FD,
|
||||
|
@ -388,7 +402,7 @@ struct libwebsocket_protocols {
|
|||
};
|
||||
|
||||
extern struct libwebsocket_context *
|
||||
libwebsocket_create_context(int port, const char * interface,
|
||||
libwebsocket_create_context(int port, const char * interf,
|
||||
struct libwebsocket_protocols *protocols,
|
||||
const char *ssl_cert_filepath,
|
||||
const char *ssl_private_key_filepath, int gid, int uid,
|
||||
|
@ -500,4 +514,9 @@ extern void
|
|||
libwebsocket_close_and_free_session(struct libwebsocket_context *context,
|
||||
struct libwebsocket *wsi, enum lws_close_status);
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -22,25 +22,29 @@
|
|||
#include "private-libwebsockets.h"
|
||||
|
||||
const struct lws_tokens lws_tokens[WSI_TOKEN_COUNT] = {
|
||||
[WSI_TOKEN_GET_URI] = { "GET ", 4 },
|
||||
[WSI_TOKEN_HOST] = { "Host:", 5 },
|
||||
[WSI_TOKEN_CONNECTION] = { "Connection:", 11 },
|
||||
[WSI_TOKEN_KEY1] = { "Sec-WebSocket-Key1:", 19 },
|
||||
[WSI_TOKEN_KEY2] = { "Sec-WebSocket-Key2:", 19 },
|
||||
[WSI_TOKEN_PROTOCOL] = { "Sec-WebSocket-Protocol:", 23 },
|
||||
[WSI_TOKEN_UPGRADE] = { "Upgrade:", 8 },
|
||||
[WSI_TOKEN_EXTENSIONS] = { "Sec-WebSocket-Extensions:", 25 },
|
||||
[WSI_TOKEN_ORIGIN] = { "Origin:", 7 },
|
||||
[WSI_TOKEN_DRAFT] = { "Sec-WebSocket-Draft:", 20 },
|
||||
[WSI_TOKEN_CHALLENGE] = { "\x0d\x0a", 2 },
|
||||
|
||||
[WSI_TOKEN_KEY] = { "Sec-WebSocket-Key:", 18 },
|
||||
[WSI_TOKEN_VERSION] = { "Sec-WebSocket-Version:", 22 },
|
||||
/* win32 can't do C99 */
|
||||
|
||||
[WSI_TOKEN_ACCEPT] = { "Sec-WebSocket-Accept:", 21 },
|
||||
[WSI_TOKEN_NONCE] = { "Sec-WebSocket-Nonce:", 20 },
|
||||
[WSI_TOKEN_HTTP] = { "HTTP/1.1 ", 9 },
|
||||
[WSI_TOKEN_SWORIGIN] = { "Sec-WebSocket-Origin:", 21 },
|
||||
/* [WSI_TOKEN_GET_URI] = */{ "GET ", 4 },
|
||||
/* [WSI_TOKEN_HOST] = */{ "Host:", 5 },
|
||||
/* [WSI_TOKEN_CONNECTION] = */{ "Connection:", 11 },
|
||||
/* [WSI_TOKEN_KEY1] = */{ "Sec-WebSocket-Key1:", 19 },
|
||||
/* [WSI_TOKEN_KEY2] = */{ "Sec-WebSocket-Key2:", 19 },
|
||||
/* [WSI_TOKEN_PROTOCOL] = */{ "Sec-WebSocket-Protocol:", 23 },
|
||||
/* [WSI_TOKEN_UPGRADE] = */{ "Upgrade:", 8 },
|
||||
/* [WSI_TOKEN_ORIGIN] = */{ "Origin:", 7 },
|
||||
/* [WSI_TOKEN_DRAFT] = */{ "Sec-WebSocket-Draft:", 20 },
|
||||
/* [WSI_TOKEN_CHALLENGE] = */{ "\x0d\x0a", 2 },
|
||||
|
||||
/* [WSI_TOKEN_KEY] = */{ "Sec-WebSocket-Key:", 18 },
|
||||
/* [WSI_TOKEN_VERSION] = */{ "Sec-WebSocket-Version:", 22 },
|
||||
/* [WSI_TOKEN_SWORIGIN]= */{ "Sec-WebSocket-Origin:", 21 },
|
||||
|
||||
/* [WSI_TOKEN_EXTENSIONS] = */{ "Sec-WebSocket-Extensions:", 25 },
|
||||
|
||||
/* [WSI_TOKEN_ACCEPT] = */{ "Sec-WebSocket-Accept:", 21 },
|
||||
/* [WSI_TOKEN_NONCE] = */{ "Sec-WebSocket-Nonce:", 20 },
|
||||
/* [WSI_TOKEN_HTTP] = */{ "HTTP/1.1 ", 9 },
|
||||
|
||||
};
|
||||
|
||||
|
@ -116,17 +120,16 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
|
|||
|
||||
/* -76 has no version header ... server */
|
||||
if (!wsi->utf8_token[WSI_TOKEN_VERSION].token_len &&
|
||||
wsi->mode != LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY &&
|
||||
wsi->mode != LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY &&
|
||||
wsi->utf8_token[wsi->parser_state].token_len != 8)
|
||||
break;
|
||||
|
||||
/* -76 has no version header ... client */
|
||||
if (!wsi->utf8_token[WSI_TOKEN_VERSION].token_len &&
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY &&
|
||||
wsi->utf8_token[wsi->parser_state].token_len != 16)
|
||||
wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_SERVER_REPLY &&
|
||||
wsi->utf8_token[wsi->parser_state].token_len != 16)
|
||||
break;
|
||||
|
||||
|
||||
/* <= 03 has old handshake with version header needs 8 bytes */
|
||||
if (wsi->utf8_token[WSI_TOKEN_VERSION].token_len &&
|
||||
atoi(wsi->utf8_token[WSI_TOKEN_VERSION].token) < 4 &&
|
||||
|
@ -1019,7 +1022,7 @@ libwebsocket_0405_frame_mask_generate(struct libwebsocket *wsi)
|
|||
|
||||
/* fetch the per-frame nonce */
|
||||
|
||||
n = read(wsi->protocol->owning_server->fd_random,
|
||||
n = libwebsockets_get_random(wsi->protocol->owning_server,
|
||||
wsi->frame_masking_nonce_04, 4);
|
||||
if (n != 4) {
|
||||
fprintf(stderr, "Unable to read from random device %s %d\n",
|
||||
|
@ -1336,7 +1339,7 @@ int libwebsockets_serve_http_file(struct libwebsocket *wsi, const char *file,
|
|||
const char *content_type)
|
||||
{
|
||||
int fd;
|
||||
struct stat stat;
|
||||
struct stat stat_buf;
|
||||
char buf[512];
|
||||
char *p = buf;
|
||||
int n;
|
||||
|
@ -1353,12 +1356,12 @@ int libwebsockets_serve_http_file(struct libwebsocket *wsi, const char *file,
|
|||
return -1;
|
||||
}
|
||||
|
||||
fstat(fd, &stat);
|
||||
fstat(fd, &stat_buf);
|
||||
p += sprintf(p, "HTTP/1.0 200 OK\x0d\x0a"
|
||||
"Server: libwebsockets\x0d\x0a"
|
||||
"Content-Type: %s\x0d\x0a"
|
||||
"Content-Length: %u\x0d\x0a"
|
||||
"\x0d\x0a", content_type, (unsigned int)stat.st_size);
|
||||
"\x0d\x0a", content_type, (unsigned int)stat_buf.st_size);
|
||||
|
||||
libwebsocket_write(wsi, (unsigned char *)buf, p - buf, LWS_WRITE_HTTP);
|
||||
|
||||
|
|
|
@ -29,9 +29,20 @@
|
|||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <netdb.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include <time.h >
|
||||
#include <winsock2.h>
|
||||
#include <ws2ipdef.h>
|
||||
#include <windows.h>
|
||||
|
||||
#else
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/socket.h>
|
||||
#ifndef LWS_NO_FORK
|
||||
#include <sys/prctl.h>
|
||||
|
@ -43,6 +54,8 @@
|
|||
#include <sys/mman.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef LWS_OPENSSL_SUPPORT
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/evp.h>
|
||||
|
@ -59,7 +72,12 @@
|
|||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
static inline void debug(const char *format, ...)
|
||||
#ifdef WIN32
|
||||
static
|
||||
#else
|
||||
static inline
|
||||
#endif
|
||||
void debug(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap);
|
||||
|
@ -271,7 +289,7 @@ libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
|
|||
unsigned char *buf, size_t len);
|
||||
|
||||
extern int
|
||||
libwebsocket_read(struct libwebsocket_context *this, struct libwebsocket *wsi,
|
||||
libwebsocket_read(struct libwebsocket_context *context, struct libwebsocket *wsi,
|
||||
unsigned char * buf, size_t len);
|
||||
|
||||
extern int
|
||||
|
@ -293,18 +311,22 @@ extern unsigned char
|
|||
xor_mask_05(struct libwebsocket *wsi, unsigned char c);
|
||||
|
||||
extern struct libwebsocket *
|
||||
wsi_from_fd(struct libwebsocket_context *this, int fd);
|
||||
wsi_from_fd(struct libwebsocket_context *context, int fd);
|
||||
|
||||
extern int
|
||||
insert_wsi(struct libwebsocket_context *this, struct libwebsocket *wsi);
|
||||
insert_wsi(struct libwebsocket_context *context, struct libwebsocket *wsi);
|
||||
|
||||
extern int
|
||||
delete_from_fd(struct libwebsocket_context *this, int fd);
|
||||
delete_from_fd(struct libwebsocket_context *context, int fd);
|
||||
|
||||
extern void
|
||||
libwebsocket_set_timeout(struct libwebsocket *wsi,
|
||||
enum pending_timeout reason, int secs);
|
||||
|
||||
extern int
|
||||
libwebsockets_get_random(struct libwebsocket_context *context,
|
||||
void *buf, int len);
|
||||
|
||||
#ifndef LWS_OPENSSL_SUPPORT
|
||||
|
||||
unsigned char *
|
||||
|
|
21
lib/sha-1.c
21
lib/sha-1.c
|
@ -33,8 +33,29 @@
|
|||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef WIN32
|
||||
|
||||
typedef unsigned char u_int8_t;
|
||||
typedef unsigned int u_int32_t;
|
||||
typedef unsigned __int64 u_int64_t;
|
||||
typedef void* caddr_t;
|
||||
|
||||
#undef __P
|
||||
#ifndef __P
|
||||
#if __STDC__
|
||||
#define __P(protos) protos
|
||||
#else
|
||||
#define __P(protos) ()
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||
|
||||
#else
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
||||
struct sha1_ctxt {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<h2>libwebsockets_hangup_on_client - Server calls to terminate client connection</h2>
|
||||
<i>void</i>
|
||||
<b>libwebsockets_hangup_on_client</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>,
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>,
|
||||
<i>int</i> <b>fd</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>libwebsockets context
|
||||
<dt><b>fd</b>
|
||||
<dd>Connection socket descriptor
|
||||
|
@ -43,11 +43,11 @@ determined, they will be returned as valid zero-length strings.
|
|||
<h2>libwebsocket_service_fd - Service polled socket with something waiting</h2>
|
||||
<i>int</i>
|
||||
<b>libwebsocket_service_fd</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>,
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>,
|
||||
<i>struct pollfd *</i> <b>pollfd</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>Websocket context
|
||||
<dt><b>pollfd</b>
|
||||
<dd>The pollfd entry describing the socket fd and which events
|
||||
|
@ -63,10 +63,10 @@ undefined.
|
|||
<h2>libwebsocket_context_destroy - Destroy the websocket context</h2>
|
||||
<i>void</i>
|
||||
<b>libwebsocket_context_destroy</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>)
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>Websocket context
|
||||
</dl>
|
||||
<h3>Description</h3>
|
||||
|
@ -79,11 +79,11 @@ undefined.
|
|||
<h2>libwebsocket_service - Service any pending websocket activity</h2>
|
||||
<i>int</i>
|
||||
<b>libwebsocket_service</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>,
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>,
|
||||
<i>int</i> <b>timeout_ms</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>Websocket context
|
||||
<dt><b>timeout_ms</b>
|
||||
<dd>Timeout for poll; 0 means return immediately if nothing needed
|
||||
|
@ -123,11 +123,11 @@ nothing is pending, or as soon as it services whatever was pending.
|
|||
<h2>libwebsocket_callback_on_writable - Request a callback when this socket becomes able to be written to without blocking</h2>
|
||||
<i>int</i>
|
||||
<b>libwebsocket_callback_on_writable</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>,
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>,
|
||||
<i>struct libwebsocket *</i> <b>wsi</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>libwebsockets context
|
||||
<dt><b>wsi</b>
|
||||
<dd>Websocket connection instance to get callback for
|
||||
|
@ -201,10 +201,10 @@ control for the input side.
|
|||
<h2>libwebsocket_canonical_hostname - returns this host's hostname</h2>
|
||||
<i>const char *</i>
|
||||
<b>libwebsocket_canonical_hostname</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>)
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>Websocket context
|
||||
</dl>
|
||||
<h3>Description</h3>
|
||||
|
@ -219,7 +219,7 @@ has been created.
|
|||
<i>struct libwebsocket_context *</i>
|
||||
<b>libwebsocket_create_context</b>
|
||||
(<i>int</i> <b>port</b>,
|
||||
<i>const char *</i> <b>interface</b>,
|
||||
<i>const char *</i> <b>interf</b>,
|
||||
<i>struct libwebsocket_protocols *</i> <b>protocols</b>,
|
||||
<i>const char *</i> <b>ssl_cert_filepath</b>,
|
||||
<i>const char *</i> <b>ssl_private_key_filepath</b>,
|
||||
|
@ -232,7 +232,7 @@ has been created.
|
|||
<dd>Port to listen on... you can use 0 to suppress listening on
|
||||
any port, that's what you want if you are not running a
|
||||
websocket server at all but just using it as a client
|
||||
<dt><b>interface</b>
|
||||
<dt><b>interf</b>
|
||||
<dd>NULL to bind the listen socket to all interfaces, or the
|
||||
interface name, eg, "eth2"
|
||||
<dt><b>protocols</b>
|
||||
|
@ -285,10 +285,10 @@ one place; they're all handled in the user callback.
|
|||
<h2>libwebsockets_fork_service_loop - Optional helper function forks off a process for the websocket server loop. You don't have to use this but if not, you have to make sure you are calling libwebsocket_service periodically to service the websocket traffic</h2>
|
||||
<i>int</i>
|
||||
<b>libwebsockets_fork_service_loop</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>)
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>server context returned by creation function
|
||||
</dl>
|
||||
<hr>
|
||||
|
@ -425,7 +425,7 @@ Many protocols won't care becuse their packets are always small.
|
|||
<h2>libwebsocket_client_connect - Connect to another websocket server</h2>
|
||||
<i>struct libwebsocket *</i>
|
||||
<b>libwebsocket_client_connect</b>
|
||||
(<i>struct libwebsocket_context *</i> <b>this</b>,
|
||||
(<i>struct libwebsocket_context *</i> <b>context</b>,
|
||||
<i>const char *</i> <b>address</b>,
|
||||
<i>int</i> <b>port</b>,
|
||||
<i>int</i> <b>ssl_connection</b>,
|
||||
|
@ -436,7 +436,7 @@ Many protocols won't care becuse their packets are always small.
|
|||
<i>int</i> <b>ietf_version_or_minus_one</b>)
|
||||
<h3>Arguments</h3>
|
||||
<dl>
|
||||
<dt><b>this</b>
|
||||
<dt><b>context</b>
|
||||
<dd>Websocket context
|
||||
<dt><b>address</b>
|
||||
<dd>Remote server address, eg, "myserver.com"
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "../lib/libwebsockets.h"
|
||||
#include <poll.h>
|
||||
|
||||
static unsigned int opts;
|
||||
static int was_closed;
|
||||
|
@ -147,17 +146,20 @@ callback_lws_mirror(struct libwebsocket_context * this,
|
|||
/* list of supported protocols and callbacks */
|
||||
|
||||
static struct libwebsocket_protocols protocols[] = {
|
||||
|
||||
[PROTOCOL_DUMB_INCREMENT] = {
|
||||
.name = "dumb-increment-protocol",
|
||||
.callback = callback_dumb_increment,
|
||||
{
|
||||
"dumb-increment-protocol",
|
||||
callback_dumb_increment,
|
||||
0,
|
||||
},
|
||||
[PROTOCOL_LWS_MIRROR] = {
|
||||
.name = "lws-mirror-protocol",
|
||||
.callback = callback_lws_mirror,
|
||||
{
|
||||
"lws-mirror-protocol",
|
||||
callback_lws_mirror,
|
||||
0,
|
||||
},
|
||||
[DEMO_PROTOCOL_COUNT] = { /* end of list */
|
||||
.callback = NULL
|
||||
{ /* end of list */
|
||||
NULL,
|
||||
NULL,
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -393,24 +393,24 @@ callback_lws_mirror(struct libwebsocket_context * this,
|
|||
|
||||
static struct libwebsocket_protocols protocols[] = {
|
||||
/* first protocol must always be HTTP handler */
|
||||
[PROTOCOL_HTTP] = {
|
||||
.name = "http-only",
|
||||
.callback = callback_http,
|
||||
|
||||
{
|
||||
"http-only", /* name */
|
||||
callback_http, /* callback */
|
||||
0 /* per_session_data_size */
|
||||
},
|
||||
[PROTOCOL_DUMB_INCREMENT] = {
|
||||
.name = "dumb-increment-protocol",
|
||||
.callback = callback_dumb_increment,
|
||||
.per_session_data_size =
|
||||
sizeof(struct per_session_data__dumb_increment),
|
||||
{
|
||||
"dumb-increment-protocol",
|
||||
callback_dumb_increment,
|
||||
sizeof(struct per_session_data__dumb_increment),
|
||||
},
|
||||
[PROTOCOL_LWS_MIRROR] = {
|
||||
.name = "lws-mirror-protocol",
|
||||
.callback = callback_lws_mirror,
|
||||
.per_session_data_size =
|
||||
sizeof(struct per_session_data__lws_mirror),
|
||||
{
|
||||
"lws-mirror-protocol",
|
||||
callback_lws_mirror,
|
||||
sizeof(struct per_session_data__lws_mirror)
|
||||
},
|
||||
[DEMO_PROTOCOL_COUNT] = { /* end of list */
|
||||
.callback = NULL
|
||||
{
|
||||
NULL, NULL, 0 /* End of list */
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ enum demo_protocols {
|
|||
|
||||
/* this protocol server (always the first one) just knows how to do HTTP */
|
||||
|
||||
static int callback_http(struct libwebsocket_context * this,
|
||||
static int callback_http(struct libwebsocket_context * context,
|
||||
struct libwebsocket *wsi,
|
||||
enum libwebsocket_callback_reasons reason, void *user,
|
||||
void *in, size_t len)
|
||||
|
@ -124,29 +124,29 @@ dump_handshake_info(struct lws_tokens *lwst)
|
|||
{
|
||||
int n;
|
||||
static const char *token_names[] = {
|
||||
[WSI_TOKEN_GET_URI] = "GET URI",
|
||||
[WSI_TOKEN_HOST] = "Host",
|
||||
[WSI_TOKEN_CONNECTION] = "Connection",
|
||||
[WSI_TOKEN_KEY1] = "key 1",
|
||||
[WSI_TOKEN_KEY2] = "key 2",
|
||||
[WSI_TOKEN_PROTOCOL] = "Protocol",
|
||||
[WSI_TOKEN_UPGRADE] = "Upgrade",
|
||||
[WSI_TOKEN_ORIGIN] = "Origin",
|
||||
[WSI_TOKEN_DRAFT] = "Draft",
|
||||
[WSI_TOKEN_CHALLENGE] = "Challenge",
|
||||
/*[WSI_TOKEN_GET_URI] =*/ "GET URI",
|
||||
/*[WSI_TOKEN_HOST] =*/ "Host",
|
||||
/*[WSI_TOKEN_CONNECTION] =*/ "Connection",
|
||||
/*[WSI_TOKEN_KEY1] =*/ "key 1",
|
||||
/*[WSI_TOKEN_KEY2] =*/ "key 2",
|
||||
/*[WSI_TOKEN_PROTOCOL] =*/ "Protocol",
|
||||
/*[WSI_TOKEN_UPGRADE] =*/ "Upgrade",
|
||||
/*[WSI_TOKEN_ORIGIN] =*/ "Origin",
|
||||
/*[WSI_TOKEN_DRAFT] =*/ "Draft",
|
||||
/*[WSI_TOKEN_CHALLENGE] =*/ "Challenge",
|
||||
|
||||
/* new for 04 */
|
||||
[WSI_TOKEN_KEY] = "Key",
|
||||
[WSI_TOKEN_VERSION] = "Version",
|
||||
[WSI_TOKEN_SWORIGIN] = "Sworigin",
|
||||
/*[WSI_TOKEN_KEY] =*/ "Key",
|
||||
/*[WSI_TOKEN_VERSION] =*/ "Version",
|
||||
/*[WSI_TOKEN_SWORIGIN] =*/ "Sworigin",
|
||||
|
||||
/* new for 05 */
|
||||
[WSI_TOKEN_EXTENSIONS] = "Extensions",
|
||||
/*[WSI_TOKEN_EXTENSIONS] =*/ "Extensions",
|
||||
|
||||
/* client receives these */
|
||||
[WSI_TOKEN_ACCEPT] = "Accept",
|
||||
[WSI_TOKEN_NONCE] = "Nonce",
|
||||
[WSI_TOKEN_HTTP] = "Http",
|
||||
/*[WSI_TOKEN_ACCEPT] =*/ "Accept",
|
||||
/*[WSI_TOKEN_NONCE] =*/ "Nonce",
|
||||
/*[WSI_TOKEN_HTTP] =*/ "Http",
|
||||
};
|
||||
|
||||
for (n = 0; n < WSI_TOKEN_COUNT; n++) {
|
||||
|
@ -172,7 +172,7 @@ struct per_session_data__dumb_increment {
|
|||
};
|
||||
|
||||
static int
|
||||
callback_dumb_increment(struct libwebsocket_context * this,
|
||||
callback_dumb_increment(struct libwebsocket_context * context,
|
||||
struct libwebsocket *wsi,
|
||||
enum libwebsocket_callback_reasons reason,
|
||||
void *user, void *in, size_t len)
|
||||
|
@ -249,7 +249,7 @@ static int ringbuffer_head;
|
|||
|
||||
|
||||
static int
|
||||
callback_lws_mirror(struct libwebsocket_context * this,
|
||||
callback_lws_mirror(struct libwebsocket_context * context,
|
||||
struct libwebsocket *wsi,
|
||||
enum libwebsocket_callback_reasons reason,
|
||||
void *user, void *in, size_t len)
|
||||
|
@ -286,7 +286,7 @@ callback_lws_mirror(struct libwebsocket_context * this,
|
|||
MAX_MESSAGE_QUEUE) < (MAX_MESSAGE_QUEUE - 15))
|
||||
libwebsocket_rx_flow_control(wsi, 1);
|
||||
|
||||
libwebsocket_callback_on_writable(this, wsi);
|
||||
libwebsocket_callback_on_writable(context, wsi);
|
||||
|
||||
}
|
||||
break;
|
||||
|
@ -343,24 +343,24 @@ callback_lws_mirror(struct libwebsocket_context * this,
|
|||
|
||||
static struct libwebsocket_protocols protocols[] = {
|
||||
/* first protocol must always be HTTP handler */
|
||||
[PROTOCOL_HTTP] = {
|
||||
.name = "http-only",
|
||||
.callback = callback_http,
|
||||
|
||||
{
|
||||
"http-only", /* name */
|
||||
callback_http, /* callback */
|
||||
0 /* per_session_data_size */
|
||||
},
|
||||
[PROTOCOL_DUMB_INCREMENT] = {
|
||||
.name = "dumb-increment-protocol",
|
||||
.callback = callback_dumb_increment,
|
||||
.per_session_data_size =
|
||||
sizeof(struct per_session_data__dumb_increment),
|
||||
{
|
||||
"dumb-increment-protocol",
|
||||
callback_dumb_increment,
|
||||
sizeof(struct per_session_data__dumb_increment),
|
||||
},
|
||||
[PROTOCOL_LWS_MIRROR] = {
|
||||
.name = "lws-mirror-protocol",
|
||||
.callback = callback_lws_mirror,
|
||||
.per_session_data_size =
|
||||
sizeof(struct per_session_data__lws_mirror),
|
||||
{
|
||||
"lws-mirror-protocol",
|
||||
callback_lws_mirror,
|
||||
sizeof(struct per_session_data__lws_mirror)
|
||||
},
|
||||
[DEMO_PROTOCOL_COUNT] = { /* end of list */
|
||||
.callback = NULL
|
||||
{
|
||||
NULL, NULL, 0 /* End of list */
|
||||
}
|
||||
};
|
||||
|
||||
|
|
98
win32port/client/client.vcxproj
Normal file
98
win32port/client/client.vcxproj
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\test-server\test-client.c" />
|
||||
<ClCompile Include="..\win32helpers\getopt.c" />
|
||||
<ClCompile Include="..\win32helpers\getopt_long.c" />
|
||||
<ClCompile Include="..\win32helpers\gettimeofday.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\libwebsocketswin32\libwebsocketswin32.vcxproj">
|
||||
<Project>{332bf17e-fd30-4363-975a-aa731a827b4f}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\win32helpers\getopt.h" />
|
||||
<ClInclude Include="..\win32helpers\gettimeofday.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{6265650C-4799-451C-A687-94DE48759A8B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>client</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../win32helpers</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../win32helpers</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
39
win32port/client/client.vcxproj.filters
Normal file
39
win32port/client/client.vcxproj.filters
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\test-server\test-client.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32helpers\getopt.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32helpers\getopt_long.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32helpers\gettimeofday.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\win32helpers\getopt.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\win32helpers\gettimeofday.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
7
win32port/client/client.vcxproj.user
Normal file
7
win32port/client/client.vcxproj.user
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommandArguments>127.0.0.1</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
89
win32port/libwebsocketswin32/libwebsocketswin32.vcxproj
Normal file
89
win32port/libwebsocketswin32/libwebsocketswin32.vcxproj
Normal file
|
@ -0,0 +1,89 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{332BF17E-FD30-4363-975A-AA731A827B4F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>libwebsocketswin32</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../win32helpers</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../win32helpers</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\lib\base64-decode.c" />
|
||||
<ClCompile Include="..\..\lib\client-handshake.c" />
|
||||
<ClCompile Include="..\..\lib\handshake.c" />
|
||||
<ClCompile Include="..\..\lib\libwebsockets.c" />
|
||||
<ClCompile Include="..\..\lib\md5.c" />
|
||||
<ClCompile Include="..\..\lib\parsers.c" />
|
||||
<ClCompile Include="..\..\lib\sha-1.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\lib\libwebsockets.h" />
|
||||
<ClInclude Include="..\..\lib\private-libwebsockets.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\lib\base64-decode.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\lib\client-handshake.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\lib\handshake.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\lib\libwebsockets.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\lib\md5.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\lib\parsers.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\lib\sha-1.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\lib\libwebsockets.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\lib\private-libwebsockets.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
106
win32port/server/server.vcxproj
Normal file
106
win32port/server/server.vcxproj
Normal file
|
@ -0,0 +1,106 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\test-server\test-server.c">
|
||||
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">../win32helpers</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32helpers\getopt.c" />
|
||||
<ClCompile Include="..\win32helpers\getopt_long.c" />
|
||||
<ClCompile Include="..\win32helpers\gettimeofday.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\win32helpers\getopt.h" />
|
||||
<ClInclude Include="..\win32helpers\gettimeofday.h" />
|
||||
<ClInclude Include="..\win32helpers\netdb.h" />
|
||||
<ClInclude Include="..\win32helpers\strings.h" />
|
||||
<ClInclude Include="..\win32helpers\unistd.h" />
|
||||
<ClInclude Include="..\win32helpers\websock-w32.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\libwebsocketswin32\libwebsocketswin32.vcxproj">
|
||||
<Project>{332bf17e-fd30-4363-975a-aa731a827b4f}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{E585B64F-9365-4C58-9EF8-56393EB27F8B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>server</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../win32helpers</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<IgnoreSpecificDefaultLibraries>
|
||||
</IgnoreSpecificDefaultLibraries>
|
||||
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>../win32helpers</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
51
win32port/server/server.vcxproj.filters
Normal file
51
win32port/server/server.vcxproj.filters
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\test-server\test-server.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32helpers\getopt.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32helpers\getopt_long.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\win32helpers\gettimeofday.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\win32helpers\getopt.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\win32helpers\netdb.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\win32helpers\strings.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\win32helpers\unistd.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\win32helpers\websock-w32.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\win32helpers\gettimeofday.h">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
3
win32port/server/server.vcxproj.user
Normal file
3
win32port/server/server.vcxproj.user
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
</Project>
|
153
win32port/win32helpers/getopt.c
Normal file
153
win32port/win32helpers/getopt.c
Normal file
|
@ -0,0 +1,153 @@
|
|||
/* $NetBSD: getopt.c,v 1.16 1999/12/02 13:15:56 kleink Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)getopt.c 8.3 (Berkeley) 4/27/95";
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define __P(x) x
|
||||
#define _DIAGASSERT(x) assert(x)
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(getopt,_getopt);
|
||||
#endif
|
||||
|
||||
|
||||
int opterr = 1, /* if error message should be printed */
|
||||
optind = 1, /* index into parent argv vector */
|
||||
optopt, /* character checked for validity */
|
||||
optreset; /* reset getopt */
|
||||
char *optarg; /* argument associated with option */
|
||||
|
||||
static char * _progname __P((char *));
|
||||
int getopt_internal __P((int, char * const *, const char *));
|
||||
|
||||
static char *
|
||||
_progname(nargv0)
|
||||
char * nargv0;
|
||||
{
|
||||
char * tmp;
|
||||
|
||||
_DIAGASSERT(nargv0 != NULL);
|
||||
|
||||
tmp = strrchr(nargv0, '/');
|
||||
if (tmp)
|
||||
tmp++;
|
||||
else
|
||||
tmp = nargv0;
|
||||
return(tmp);
|
||||
}
|
||||
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG (int)':'
|
||||
#define EMSG ""
|
||||
|
||||
/*
|
||||
* getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt(nargc, nargv, ostr)
|
||||
int nargc;
|
||||
char * const nargv[];
|
||||
const char *ostr;
|
||||
{
|
||||
static char *__progname = 0;
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
__progname = __progname?__progname:_progname(*nargv);
|
||||
|
||||
_DIAGASSERT(nargv != NULL);
|
||||
_DIAGASSERT(ostr != NULL);
|
||||
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
if (place[1] && *++place == '-' /* found "--" */
|
||||
&& place[1] == '\0') {
|
||||
++optind;
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((optopt = (int)*place++) == (int)':' ||
|
||||
!(oli = strchr(ostr, optopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means -1.
|
||||
*/
|
||||
if (optopt == (int)'-')
|
||||
return (-1);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (opterr && *ostr != ':')
|
||||
(void)fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __progname, optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++optind;
|
||||
}
|
||||
else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if (*ostr == ':')
|
||||
return (BADARG);
|
||||
if (opterr)
|
||||
(void)fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
__progname, optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
else /* white space */
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
return (optopt); /* dump back option letter */
|
||||
}
|
||||
|
33
win32port/win32helpers/getopt.h
Normal file
33
win32port/win32helpers/getopt.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef __GETOPT_H__
|
||||
#define __GETOPT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int opterr; /* if error message should be printed */
|
||||
extern int optind; /* index into parent argv vector */
|
||||
extern int optopt; /* character checked for validity */
|
||||
extern int optreset; /* reset getopt */
|
||||
extern char *optarg; /* argument associated with option */
|
||||
|
||||
struct option
|
||||
{
|
||||
const char *name;
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
#define no_argument 0
|
||||
#define required_argument 1
|
||||
#define optional_argument 2
|
||||
|
||||
int getopt(int, char**, char*);
|
||||
int getopt_long(int, char**, char*, struct option*, int*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __GETOPT_H__ */
|
237
win32port/win32helpers/getopt_long.c
Normal file
237
win32port/win32helpers/getopt_long.c
Normal file
|
@ -0,0 +1,237 @@
|
|||
|
||||
/*
|
||||
* Copyright (c) 1987, 1993, 1994, 1996
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "getopt.h"
|
||||
|
||||
extern int opterr; /* if error message should be printed */
|
||||
extern int optind; /* index into parent argv vector */
|
||||
extern int optopt; /* character checked for validity */
|
||||
extern int optreset; /* reset getopt */
|
||||
extern char *optarg; /* argument associated with option */
|
||||
|
||||
#define __P(x) x
|
||||
#define _DIAGASSERT(x) assert(x)
|
||||
|
||||
static char * __progname __P((char *));
|
||||
int getopt_internal __P((int, char * const *, const char *));
|
||||
|
||||
static char *
|
||||
__progname(nargv0)
|
||||
char * nargv0;
|
||||
{
|
||||
char * tmp;
|
||||
|
||||
_DIAGASSERT(nargv0 != NULL);
|
||||
|
||||
tmp = strrchr(nargv0, '/');
|
||||
if (tmp)
|
||||
tmp++;
|
||||
else
|
||||
tmp = nargv0;
|
||||
return(tmp);
|
||||
}
|
||||
|
||||
#define BADCH (int)'?'
|
||||
#define BADARG (int)':'
|
||||
#define EMSG ""
|
||||
|
||||
/*
|
||||
* getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt_internal(nargc, nargv, ostr)
|
||||
int nargc;
|
||||
char * const *nargv;
|
||||
const char *ostr;
|
||||
{
|
||||
static char *place = EMSG; /* option letter processing */
|
||||
char *oli; /* option letter list index */
|
||||
|
||||
_DIAGASSERT(nargv != NULL);
|
||||
_DIAGASSERT(ostr != NULL);
|
||||
|
||||
if (optreset || !*place) { /* update scanning pointer */
|
||||
optreset = 0;
|
||||
if (optind >= nargc || *(place = nargv[optind]) != '-') {
|
||||
place = EMSG;
|
||||
return (-1);
|
||||
}
|
||||
if (place[1] && *++place == '-') { /* found "--" */
|
||||
/* ++optind; */
|
||||
place = EMSG;
|
||||
return (-2);
|
||||
}
|
||||
} /* option letter okay? */
|
||||
if ((optopt = (int)*place++) == (int)':' ||
|
||||
!(oli = strchr(ostr, optopt))) {
|
||||
/*
|
||||
* if the user didn't specify '-' as an option,
|
||||
* assume it means -1.
|
||||
*/
|
||||
if (optopt == (int)'-')
|
||||
return (-1);
|
||||
if (!*place)
|
||||
++optind;
|
||||
if (opterr && *ostr != ':')
|
||||
(void)fprintf(stderr,
|
||||
"%s: illegal option -- %c\n", __progname(nargv[0]), optopt);
|
||||
return (BADCH);
|
||||
}
|
||||
if (*++oli != ':') { /* don't need argument */
|
||||
optarg = NULL;
|
||||
if (!*place)
|
||||
++optind;
|
||||
} else { /* need an argument */
|
||||
if (*place) /* no white space */
|
||||
optarg = place;
|
||||
else if (nargc <= ++optind) { /* no arg */
|
||||
place = EMSG;
|
||||
if ((opterr) && (*ostr != ':'))
|
||||
(void)fprintf(stderr,
|
||||
"%s: option requires an argument -- %c\n",
|
||||
__progname(nargv[0]), optopt);
|
||||
return (BADARG);
|
||||
} else /* white space */
|
||||
optarg = nargv[optind];
|
||||
place = EMSG;
|
||||
++optind;
|
||||
}
|
||||
return (optopt); /* dump back option letter */
|
||||
}
|
||||
|
||||
#if 0
|
||||
/*
|
||||
* getopt --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt2(nargc, nargv, ostr)
|
||||
int nargc;
|
||||
char * const *nargv;
|
||||
const char *ostr;
|
||||
{
|
||||
int retval;
|
||||
|
||||
if ((retval = getopt_internal(nargc, nargv, ostr)) == -2) {
|
||||
retval = -1;
|
||||
++optind;
|
||||
}
|
||||
return(retval);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* getopt_long --
|
||||
* Parse argc/argv argument vector.
|
||||
*/
|
||||
int
|
||||
getopt_long(nargc, nargv, options, long_options, index)
|
||||
int nargc;
|
||||
char ** nargv;
|
||||
char * options;
|
||||
struct option * long_options;
|
||||
int * index;
|
||||
{
|
||||
int retval;
|
||||
|
||||
_DIAGASSERT(nargv != NULL);
|
||||
_DIAGASSERT(options != NULL);
|
||||
_DIAGASSERT(long_options != NULL);
|
||||
/* index may be NULL */
|
||||
|
||||
if ((retval = getopt_internal(nargc, nargv, options)) == -2) {
|
||||
char *current_argv = nargv[optind++] + 2, *has_equal;
|
||||
int i, current_argv_len, match = -1;
|
||||
|
||||
if (*current_argv == '\0') {
|
||||
return(-1);
|
||||
}
|
||||
if ((has_equal = strchr(current_argv, '=')) != NULL) {
|
||||
current_argv_len = has_equal - current_argv;
|
||||
has_equal++;
|
||||
} else
|
||||
current_argv_len = strlen(current_argv);
|
||||
|
||||
for (i = 0; long_options[i].name; i++) {
|
||||
if (strncmp(current_argv, long_options[i].name, current_argv_len))
|
||||
continue;
|
||||
|
||||
if (strlen(long_options[i].name) == (unsigned)current_argv_len) {
|
||||
match = i;
|
||||
break;
|
||||
}
|
||||
if (match == -1)
|
||||
match = i;
|
||||
}
|
||||
if (match != -1) {
|
||||
if (long_options[match].has_arg == required_argument ||
|
||||
long_options[match].has_arg == optional_argument) {
|
||||
if (has_equal)
|
||||
optarg = has_equal;
|
||||
else
|
||||
optarg = nargv[optind++];
|
||||
}
|
||||
if ((long_options[match].has_arg == required_argument)
|
||||
&& (optarg == NULL)) {
|
||||
/*
|
||||
* Missing argument, leading :
|
||||
* indicates no error should be generated
|
||||
*/
|
||||
if ((opterr) && (*options != ':'))
|
||||
(void)fprintf(stderr,
|
||||
"%s: option requires an argument -- %s\n",
|
||||
__progname(nargv[0]), current_argv);
|
||||
return (BADARG);
|
||||
}
|
||||
} else { /* No matching argument */
|
||||
if ((opterr) && (*options != ':'))
|
||||
(void)fprintf(stderr,
|
||||
"%s: illegal option -- %s\n", __progname(nargv[0]), current_argv);
|
||||
return (BADCH);
|
||||
}
|
||||
if (long_options[match].flag) {
|
||||
*long_options[match].flag = long_options[match].val;
|
||||
retval = 0;
|
||||
} else
|
||||
retval = long_options[match].val;
|
||||
if (index)
|
||||
*index = match;
|
||||
}
|
||||
return(retval);
|
||||
}
|
48
win32port/win32helpers/gettimeofday.c
Normal file
48
win32port/win32helpers/gettimeofday.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
#include < time.h >
|
||||
#include <windows.h> //I've ommited context line.
|
||||
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
||||
#else
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
||||
#endif
|
||||
|
||||
struct timezone
|
||||
{
|
||||
int tz_minuteswest; /* minutes W of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||
{
|
||||
FILETIME ft;
|
||||
unsigned __int64 tmpres = 0;
|
||||
static int tzflag;
|
||||
|
||||
if (NULL != tv)
|
||||
{
|
||||
GetSystemTimeAsFileTime(&ft);
|
||||
|
||||
tmpres |= ft.dwHighDateTime;
|
||||
tmpres <<= 32;
|
||||
tmpres |= ft.dwLowDateTime;
|
||||
|
||||
/*converting file time to unix epoch*/
|
||||
tmpres -= DELTA_EPOCH_IN_MICROSECS;
|
||||
tmpres /= 10; /*convert into microseconds*/
|
||||
tv->tv_sec = (long)(tmpres / 1000000UL);
|
||||
tv->tv_usec = (long)(tmpres % 1000000UL);
|
||||
}
|
||||
|
||||
if (NULL != tz)
|
||||
{
|
||||
if (!tzflag)
|
||||
{
|
||||
_tzset();
|
||||
tzflag++;
|
||||
}
|
||||
tz->tz_minuteswest = _timezone / 60;
|
||||
tz->tz_dsttime = _daylight;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
21
win32port/win32helpers/gettimeofday.h
Normal file
21
win32port/win32helpers/gettimeofday.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef _GET_TIME_OF_DAY_H
|
||||
#define _GET_TIME_OF_DAY_H
|
||||
|
||||
#include < time.h >
|
||||
#include <windows.h> //I've ommited context line.
|
||||
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
||||
#else
|
||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
||||
#endif
|
||||
|
||||
struct timezone
|
||||
{
|
||||
int tz_minuteswest; /* minutes W of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||
|
||||
|
||||
#endif
|
1
win32port/win32helpers/netdb.h
Normal file
1
win32port/win32helpers/netdb.h
Normal file
|
@ -0,0 +1 @@
|
|||
// Left blank for win32
|
0
win32port/win32helpers/strings.h
Normal file
0
win32port/win32helpers/strings.h
Normal file
1
win32port/win32helpers/sys/time.h
Normal file
1
win32port/win32helpers/sys/time.h
Normal file
|
@ -0,0 +1 @@
|
|||
// left blank
|
0
win32port/win32helpers/unistd.h
Normal file
0
win32port/win32helpers/unistd.h
Normal file
21
win32port/win32helpers/websock-w32.h
Normal file
21
win32port/win32helpers/websock-w32.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef __WEB_SOCK_W32_H__
|
||||
#define __WEB_SOCK_W32_H__
|
||||
|
||||
// Windows uses _DEBUG and NDEBUG
|
||||
#ifdef _DEBUG
|
||||
#undef DEBUG
|
||||
#define DEBUG 1
|
||||
#endif
|
||||
|
||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
||||
|
||||
#define MSG_NOSIGNAL 0
|
||||
#define SHUT_RDWR SD_BOTH
|
||||
|
||||
#define poll WSAPoll
|
||||
|
||||
#define LWS_NO_FORK
|
||||
|
||||
#define DATADIR "."
|
||||
|
||||
#endif
|
35
win32port/win32port.sln
Normal file
35
win32port/win32port.sln
Normal file
|
@ -0,0 +1,35 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 11.00
|
||||
# Visual Studio 2010
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "server\server.vcxproj", "{E585B64F-9365-4C58-9EF8-56393EB27F8B}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{332BF17E-FD30-4363-975A-AA731A827B4F} = {332BF17E-FD30-4363-975A-AA731A827B4F}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libwebsocketswin32", "libwebsocketswin32\libwebsocketswin32.vcxproj", "{332BF17E-FD30-4363-975A-AA731A827B4F}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client\client.vcxproj", "{6265650C-4799-451C-A687-94DE48759A8B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{E585B64F-9365-4C58-9EF8-56393EB27F8B}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{E585B64F-9365-4C58-9EF8-56393EB27F8B}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{E585B64F-9365-4C58-9EF8-56393EB27F8B}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{E585B64F-9365-4C58-9EF8-56393EB27F8B}.Release|Win32.Build.0 = Release|Win32
|
||||
{332BF17E-FD30-4363-975A-AA731A827B4F}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{332BF17E-FD30-4363-975A-AA731A827B4F}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{332BF17E-FD30-4363-975A-AA731A827B4F}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{332BF17E-FD30-4363-975A-AA731A827B4F}.Release|Win32.Build.0 = Release|Win32
|
||||
{6265650C-4799-451C-A687-94DE48759A8B}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{6265650C-4799-451C-A687-94DE48759A8B}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{6265650C-4799-451C-A687-94DE48759A8B}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{6265650C-4799-451C-A687-94DE48759A8B}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
BIN
win32port/win32port.suo
Normal file
BIN
win32port/win32port.suo
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue