diff --git a/lib/client-handshake.c b/lib/client-handshake.c index df91923d..8c821efb 100644 --- a/lib/client-handshake.c +++ b/lib/client-handshake.c @@ -79,6 +79,8 @@ libwebsocket_client_connect(struct libwebsocket_context *this, 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 ec1e482f..7bec3245 100644 --- a/lib/libwebsockets.c +++ b/lib/libwebsockets.c @@ -965,9 +965,14 @@ libwebsocket_create_context(int port, 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'; + } else + strncpy(this->canonical_hostname, hostname, sizeof this->canonical_hostname - 1); - this->canonical_hostname[sizeof this->canonical_hostname - 1] = '\0'; /* split the proxy ads:port if given */ diff --git a/lib/libwebsockets.h b/lib/libwebsockets.h index 7b73a6bf..927d93df 100644 --- a/lib/libwebsockets.h +++ b/lib/libwebsockets.h @@ -236,7 +236,7 @@ struct libwebsocket_context; * 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 @@ extern int callback(struct libwebsocket_context * this, 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 @@ libwebsocket_create_context(int port, 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 @@ extern const struct libwebsocket_protocols * 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 @@ libwebsocket_client_connect(struct libwebsocket_context *clients, 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 @@ libwebsockets_get_peer_addresses(int fd, char *name, int name_len, 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 a097d538..e4a64258 100644 --- a/lib/private-libwebsockets.h +++ b/lib/private-libwebsockets.h @@ -68,6 +68,16 @@ static inline void debug(const char *format, ...) } #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 @@ insert_wsi(struct libwebsocket_context *this, struct libwebsocket *wsi); 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 3f080b20..feb6638e 100644 --- a/libwebsockets-api-doc.html +++ b/libwebsockets-api-doc.html @@ -440,7 +440,7 @@ This function creates a connection to a remote server

callback - User server actions

int callback -(struct libwebsocket_context * this, +(struct libwebsocket_context * context, struct libwebsocket * wsi, enum libwebsocket_callback_reasons reason, void * user, @@ -448,8 +448,6 @@ This function creates a connection to a remote server size_t len)

Arguments

-
this -
Websockets context
wsi
Opaque websocket instance pointer
reason @@ -604,7 +602,7 @@ internal polling loop, you can just ignore it.

struct libwebsocket_protocols - List of protocols and handlers server supports.

struct libwebsocket_protocols {
    const char * name;
-    int (*callback) (struct libwebsocket_context * this,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len);
+    int (*callback) (struct libwebsocket_context * context,struct libwebsocket *wsi,enum libwebsocket_callback_reasons reason, void *user,void *in, size_t len);
    size_t per_session_data_size;
    struct libwebsocket_context * owning_server;
    int broadcast_socket_port;