mirror of
https://github.com/libevent/libevent.git
synced 2025-01-09 00:56:20 +08:00
ws: fix compile error on centos 7 - very old compiler (#1359)
* http: fix typo * ws: fix comile error On CentOS: CC ws.lo ws.c: In function 'get_ws_frame': ws.c:244:3: error: 'for' loop initial declarations are only allowed in C99 mode for (int i = 0; i < payload_len; i++) { ^ ws.c:244:3: note: use option -std=c99 or -std=gnu99 to compile your code
This commit is contained in:
parent
f04a70f0fc
commit
3ec3b469b8
2
http.c
2
http.c
@ -741,7 +741,7 @@ evhttp_connection_incoming_fail(struct evhttp_request *req,
|
|||||||
* case may happen when a browser keeps a persistent
|
* case may happen when a browser keeps a persistent
|
||||||
* connection open and we timeout on the read. when
|
* connection open and we timeout on the read. when
|
||||||
* the request is still being used for sending, we
|
* the request is still being used for sending, we
|
||||||
* need to disassociated it from the connection here.
|
* need to disassociate it from the connection here.
|
||||||
*/
|
*/
|
||||||
if (!req->userdone) {
|
if (!req->userdone) {
|
||||||
/* remove it so that it will not be freed */
|
/* remove it so that it will not be freed */
|
||||||
|
@ -144,6 +144,7 @@ receive_ws_msg(struct evbuffer *buf, size_t *out_len, unsigned *options)
|
|||||||
const unsigned char *mask_key;
|
const unsigned char *mask_key;
|
||||||
char *out_buf = NULL;
|
char *out_buf = NULL;
|
||||||
size_t data_len = evbuffer_get_length(buf);
|
size_t data_len = evbuffer_get_length(buf);
|
||||||
|
size_t i;
|
||||||
|
|
||||||
data = evbuffer_pullup(buf, data_len);
|
data = evbuffer_pullup(buf, data_len);
|
||||||
|
|
||||||
@ -177,7 +178,7 @@ receive_ws_msg(struct evbuffer *buf, size_t *out_len, unsigned *options)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
mask_key = data + header_len - 4;
|
mask_key = data + header_len - 4;
|
||||||
for (size_t i = 0; mask && i < payload_len; i++)
|
for (i = 0; mask && i < payload_len; i++)
|
||||||
data[header_len + i] ^= mask_key[i % 4];
|
data[header_len + i] ^= mask_key[i % 4];
|
||||||
|
|
||||||
*out_len = payload_len;
|
*out_len = payload_len;
|
||||||
@ -205,6 +206,7 @@ send_ws_msg(struct evbuffer *buf, const char *msg, bool final)
|
|||||||
uint8_t a = 0, b = 0, c = 0, d = 0;
|
uint8_t a = 0, b = 0, c = 0, d = 0;
|
||||||
uint8_t mask_key[4] = {1, 2, 3, 4}; /* should be random */
|
uint8_t mask_key[4] = {1, 2, 3, 4}; /* should be random */
|
||||||
uint8_t m;
|
uint8_t m;
|
||||||
|
size_t i;
|
||||||
|
|
||||||
if (final)
|
if (final)
|
||||||
a |= 1 << 7; /* fin */
|
a |= 1 << 7; /* fin */
|
||||||
@ -233,7 +235,7 @@ send_ws_msg(struct evbuffer *buf, const char *msg, bool final)
|
|||||||
|
|
||||||
evbuffer_add(buf, &mask_key, 4);
|
evbuffer_add(buf, &mask_key, 4);
|
||||||
|
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
m = msg[i] ^ mask_key[i % 4];
|
m = msg[i] ^ mask_key[i % 4];
|
||||||
evbuffer_add(buf, &m, 1);
|
evbuffer_add(buf, &m, 1);
|
||||||
}
|
}
|
||||||
|
3
ws.c
3
ws.c
@ -236,13 +236,14 @@ get_ws_frame(unsigned char *in_buffer, int buf_len, unsigned char **payload_ptr,
|
|||||||
*/
|
*/
|
||||||
if (masked) {
|
if (masked) {
|
||||||
unsigned char *c;
|
unsigned char *c;
|
||||||
|
int i;
|
||||||
|
|
||||||
mask = *((unsigned int *)(in_buffer + pos));
|
mask = *((unsigned int *)(in_buffer + pos));
|
||||||
pos += 4;
|
pos += 4;
|
||||||
|
|
||||||
/* unmask data */
|
/* unmask data */
|
||||||
c = in_buffer + pos;
|
c = in_buffer + pos;
|
||||||
for (int i = 0; i < payload_len; i++) {
|
for (i = 0; i < payload_len; i++) {
|
||||||
c[i] = c[i] ^ ((unsigned char *)(&mask))[i % 4];
|
c[i] = c[i] ^ ((unsigned char *)(&mask))[i % 4];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user