Apple / iOS build compatability patch
This allows build on iOS platform, thanks Darin!
Signed-off-by: Darin Willits <darin@willits.ca>
diff --git a/lib/client-handshake.c b/lib/client-handshake.c
index df91923..8c821ef 100644
--- a/lib/client-handshake.c
+++ b/lib/client-handshake.c
@@ -79,6 +79,8 @@
return NULL;
}
+ memset(wsi, 0, sizeof *wsi);
+
/* -1 means just use latest supported */
if (ietf_version_or_minus_one == -1)
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index ec1e482..7bec324 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -965,9 +965,14 @@
hostname[(sizeof hostname) - 1] = '\0';
gethostname(hostname, (sizeof hostname) - 1);
he = gethostbyname(hostname);
- strncpy(this->canonical_hostname, he->h_name,
+ if (he) {
+ strncpy(this->canonical_hostname, he->h_name,
sizeof this->canonical_hostname - 1);
- this->canonical_hostname[sizeof this->canonical_hostname - 1] = '\0';
+ this->canonical_hostname[sizeof this->canonical_hostname - 1] =
+ '\0';
+ } else
+ strncpy(this->canonical_hostname, hostname,
+ sizeof this->canonical_hostname - 1);
/* split the proxy ads:port if given */
diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h
index 7b73a6b..927d93d 100644
--- a/lib/libwebsockets.h
+++ b/lib/libwebsockets.h
@@ -236,7 +236,7 @@
* pollfd struct for this socket descriptor. If you are using the
* internal polling loop, you can just ignore it.
*/
-extern int callback(struct libwebsocket_context * this,
+extern int callback(struct libwebsocket_context * context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len);
@@ -271,7 +271,7 @@
struct libwebsocket_protocols {
const char *name;
- int (*callback)(struct libwebsocket_context * this,
+ int (*callback)(struct libwebsocket_context * context,
struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len);
@@ -296,16 +296,16 @@
unsigned int options);
extern void
-libwebsocket_context_destroy(struct libwebsocket_context *this);
+libwebsocket_context_destroy(struct libwebsocket_context *context);
extern int
-libwebsockets_fork_service_loop(struct libwebsocket_context *this);
+libwebsockets_fork_service_loop(struct libwebsocket_context *context);
extern int
-libwebsocket_service(struct libwebsocket_context *this, int timeout_ms);
+libwebsocket_service(struct libwebsocket_context *context, int timeout_ms);
extern int
-libwebsocket_service_fd(struct libwebsocket_context *this,
+libwebsocket_service_fd(struct libwebsocket_context *context,
struct pollfd *pollfd);
/*
@@ -355,7 +355,7 @@
libwebsockets_get_protocol(struct libwebsocket *wsi);
extern int
-libwebsocket_callback_on_writable(struct libwebsocket_context *this,
+libwebsocket_callback_on_writable(struct libwebsocket_context *context,
struct libwebsocket *wsi);
extern int
@@ -383,7 +383,7 @@
int ietf_version_or_minus_one);
extern const char *
-libwebsocket_canonical_hostname(struct libwebsocket_context *this);
+libwebsocket_canonical_hostname(struct libwebsocket_context *context);
extern void
@@ -391,10 +391,10 @@
char *rip, int rip_len);
extern void
-libwebsockets_hangup_on_client(struct libwebsocket_context *this, int fd);
+libwebsockets_hangup_on_client(struct libwebsocket_context *context, int fd);
extern void
-libwebsocket_close_and_free_session(struct libwebsocket_context *this,
+libwebsocket_close_and_free_session(struct libwebsocket_context *context,
struct libwebsocket *wsi);
#endif
diff --git a/lib/private-libwebsockets.h b/lib/private-libwebsockets.h
index a097d53..e4a6425 100644
--- a/lib/private-libwebsockets.h
+++ b/lib/private-libwebsockets.h
@@ -68,6 +68,16 @@
}
#endif
+
+/*
+ * Mac OSX as well as iOS do not define the MSG_NOSIGNAL flag,
+ * but happily have something equivalent in the SO_NOSIGPIPE flag.
+ */
+#ifdef __APPLE__
+#define MSG_NOSIGNAL SO_NOSIGPIPE
+#endif
+
+
#define FD_HASHTABLE_MODULUS 32
#define MAX_CLIENTS 100
#define LWS_MAX_HEADER_NAME_LENGTH 64
@@ -262,3 +272,13 @@
extern int
delete_from_fd(struct libwebsocket_context *this, int fd);
+
+#ifndef LWS_OPENSSL_SUPPORT
+
+unsigned char *
+SHA1(const unsigned char *d, size_t n, unsigned char *md);
+
+void
+MD5(const unsigned char *input, int ilen, unsigned char *output);
+
+#endif
diff --git a/libwebsockets-api-doc.html b/libwebsockets-api-doc.html
index 3f080b2..feb6638 100644
--- a/libwebsockets-api-doc.html
+++ b/libwebsockets-api-doc.html
@@ -440,7 +440,7 @@
<h2>callback - User server actions</h2>
<i>int</i>
<b>callback</b>
-(<i>struct libwebsocket_context *</i> <b>this</b>,
+(<i>struct libwebsocket_context *</i> <b>context</b>,
<i>struct libwebsocket *</i> <b>wsi</b>,
<i>enum libwebsocket_callback_reasons</i> <b>reason</b>,
<i>void *</i> <b>user</b>,
@@ -448,8 +448,6 @@
<i>size_t</i> <b>len</b>)
<h3>Arguments</h3>
<dl>
-<dt><b>this</b>
-<dd>Websockets context
<dt><b>wsi</b>
<dd>Opaque websocket instance pointer
<dt><b>reason</b>
@@ -604,7 +602,7 @@
<h2>struct libwebsocket_protocols - List of protocols and handlers server supports.</h2>
<b>struct libwebsocket_protocols</b> {<br>
<i>const char *</i> <b>name</b>;<br>
- <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context * this,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br>
+ <i>int (*</i><b>callback</b>) <i>(struct libwebsocket_context * context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len)</i>;<br>
<i>size_t</i> <b>per_session_data_size</b>;<br>
<i>struct libwebsocket_context *</i> <b>owning_server</b>;<br>
<i>int</i> <b>broadcast_socket_port</b>;<br>