void
libwebsocket_close_and_free_session(struct libwebsocket_context *this,
- struct libwebsocket *wsi)
+ struct libwebsocket *wsi, enum lws_close_status reason)
{
int n;
int old_state;
this->protocols[0].callback(this, wsi,
LWS_CALLBACK_DEL_POLL_FD, (void *)(long)wsi->sock, NULL, 0);
+ wsi->close_reason = reason;
+
/*
* signal we are closing, libsocket_write will
* add any necessary version-specific stuff. If the write fails,
this->fds_count--;
}
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi, 0);
}
*/
if (tv.tv_sec > wsi->pending_timeout_limit)
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
}
}
debug("Session Socket %p (fd=%d) dead\n",
(void *)wsi, pollfd->fd);
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NORMAL);
return 1;
}
fprintf(stderr, "Proxy connection %p (fd=%d) dead\n",
(void *)wsi, pollfd->fd);
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
n = recv(wsi->sock, pkt, sizeof pkt, 0);
if (n < 0) {
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
fprintf(stderr, "ERROR reading from proxy socket\n");
return 1;
}
pkt[13] = '\0';
if (strcmp(pkt, "HTTP/1.0 200 ") != 0) {
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
fprintf(stderr, "ERROR from proxy: %s\n", pkt);
return 1;
}
if (SSL_connect(wsi->ssl) <= 0) {
fprintf(stderr, "SSL connect error %s\n",
- ERR_error_string(ERR_get_error(), ssl_err_buf));
- libwebsocket_close_and_free_session(this, wsi);
+ ERR_error_string(ERR_get_error(),
+ ssl_err_buf));
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
n = SSL_get_verify_result(wsi->ssl);
- if (n != X509_V_OK) {
- if (n != X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT ||
- wsi->use_ssl != 2) {
-
- fprintf(stderr, "server's cert didn't "
- "look good %d\n", n);
- libwebsocket_close_and_free_session(this, wsi);
- return 1;
- }
+ if (n != X509_V_OK) && (
+ n != X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT ||
+ wsi->use_ssl != 2)) {
+
+ fprintf(stderr, "server's cert didn't "
+ "look good %d\n", n);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
+ return 1;
}
} else {
wsi->ssl = NULL;
free(wsi->c_origin);
if (wsi->c_protocol)
free(wsi->c_protocol);
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
if (n < 0) {
fprintf(stderr, "ERROR writing to client socket\n");
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
(!wsi->utf8_token[WSI_TOKEN_PROTOCOL].token_len &&
wsi->c_protocol != NULL)) {
fprintf(stderr, "libwebsocket_client_handshake "
- "missing required header(s)\n");
+ "missing required header(s)\n");
pkt[len] = '\0';
fprintf(stderr, "%s", pkt);
goto bail3;
free(wsi->c_protocol);
bail2:
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
fprintf(stderr, "Session Socket %p (fd=%d) dead\n",
(void *)wsi, pollfd->fd);
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
break;
}
if (!n) {
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
for (n = 0; n < FD_HASHTABLE_MODULUS; n++)
for (m = 0; m < this->fd_hashtable[n].length; m++) {
wsi = this->fd_hashtable[n].wsi[m];
- libwebsocket_close_and_free_session(this, wsi);
+ libwebsocket_close_and_free_session(this, wsi,
+ LWS_CLOSE_STATUS_GOINGAWAY);
}
close(this->fd_random);
WSI_PARSING_COMPLETE
};
+/*
+ * From 06 sped
+ 1000
+
+ 1000 indicates a normal closure, meaning whatever purpose the
+ connection was established for has been fulfilled.
+
+ 1001
+
+ 1001 indicates that an endpoint is "going away", such as a server
+ going down, or a browser having navigated away from a page.
+
+ 1002
+
+ 1002 indicates that an endpoint is terminating the connection due
+ to a protocol error.
+
+ 1003
+
+ 1003 indicates that an endpoint is terminating the connection
+ because it has received a type of data it cannot accept (e.g. an
+ endpoint that understands only text data may send this if it
+ receives a binary message.)
+
+ 1004
+
+ 1004 indicates that an endpoint is terminating the connection
+ because it has received a message that is too large.
+*/
+
+enum lws_close_status {
+ LWS_CLOSE_STATUS_NOSTATUS = 0,
+ LWS_CLOSE_STATUS_NORMAL = 1000,
+ LWS_CLOSE_STATUS_GOINGAWAY = 1001,
+ LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002,
+ LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003,
+ LWS_CLOSE_STATUS_PAYLOAD_TOO_LARGE = 1004,
+};
+
struct libwebsocket;
struct libwebsocket_context;
* use the whole buffer without taking care of the above.
*/
-/* this is the frame nonce plus two header plus 8 length */
+/*
+ * this is the frame nonce plus two header plus 8 length
+ * 2 byte prepend on close will already fit because control frames cannot use
+ * the big length style
+ */
#define LWS_SEND_BUFFER_PRE_PADDING (4 + 10)
#define LWS_SEND_BUFFER_POST_PADDING 1
extern void
libwebsocket_close_and_free_session(struct libwebsocket_context *context,
- struct libwebsocket *wsi);
+ struct libwebsocket *wsi, enum lws_close_status);
#endif
#define MAX_WEBSOCKET_04_KEY_LEN 128
#define SYSTEM_RANDOM_FILEPATH "/dev/urandom"
-/*
- * From 06 sped
- 1000
-
- 1000 indicates a normal closure, meaning whatever purpose the
- connection was established for has been fulfilled.
-
- 1001
-
- 1001 indicates that an endpoint is "going away", such as a server
- going down, or a browser having navigated away from a page.
-
- 1002
-
- 1002 indicates that an endpoint is terminating the connection due
- to a protocol error.
-
- 1003
-
- 1003 indicates that an endpoint is terminating the connection
- because it has received a type of data it cannot accept (e.g. an
- endpoint that understands only text data may send this if it
- receives a binary message.)
-
- 1004
-
- 1004 indicates that an endpoint is terminating the connection
- because it has received a message that is too large.
-*/
-
-enum lws_close_status {
- LWS_CLOSE_STATUS_NORMAL = 1000,
- LWS_CLOSE_STATUS_GOINGAWAY = 1001,
- LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002,
- LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003,
- LWS_CLOSE_STATUS_PAYLOAD_TOO_LARGE = 1004,
-};
-
enum lws_websocket_opcodes_04 {
LWS_WS_OPCODE_04__CONTINUATION = 0,
LWS_WS_OPCODE_04__CLOSE = 1,
unsigned char (*xor_mask)(struct libwebsocket *, unsigned char);
char all_zero_nonce;
+ enum lws_close_status close_reason;
+
/* client support */
char initial_handshake_hash_base64[30];
enum connection_mode mode;