int frame_flags; /* See the CURLWS_* defines */
curl_off_t payload_offset; /* the offset parsing is at */
curl_off_t payload_len;
- unsigned char head[10];
+ uint8_t head[10];
int head_len, head_total;
enum ws_dec_state state;
int cont_flags;
curl_off_t payload_len; /* payload length of current frame */
curl_off_t payload_remain; /* remaining payload of current */
unsigned int xori; /* xor index */
- unsigned char mask[4]; /* 32-bit mask for this connection */
- unsigned char firstbyte; /* first byte of frame we encode */
+ uint8_t mask[4]; /* 32-bit mask for this connection */
+ uint8_t firstbyte; /* first byte of frame we encode */
BIT(contfragment); /* set TRUE if the previous fragment sent was not final */
};
struct ws_cntrl_frame {
unsigned int type;
size_t payload_len;
- unsigned char payload[WS_MAX_CNTRL_LEN];
+ uint8_t payload[WS_MAX_CNTRL_LEN];
};
/* A websocket connection with en- and decoder that treat frames
};
-static const char *ws_frame_name_of_op(unsigned char firstbyte)
+static const char *ws_frame_name_of_op(uint8_t firstbyte)
{
switch(firstbyte & WSBIT_OPCODE_MASK) {
case WSBIT_OPCODE_CONT:
}
static int ws_frame_firstbyte2flags(struct Curl_easy *data,
- unsigned char firstbyte, int cont_flags)
+ uint8_t firstbyte, int cont_flags)
{
switch(firstbyte) {
/* 0x00 - intermediate TEXT/BINARY fragment */
static CURLcode ws_frame_flags2firstbyte(struct Curl_easy *data,
unsigned int flags,
bool contfragment,
- unsigned char *pfirstbyte)
+ uint8_t *pfirstbyte)
{
*pfirstbyte = 0;
switch(flags & ~CURLWS_OFFSET) {
struct websocket *ws,
const char *buffer, size_t buflen);
-typedef CURLcode ws_write_payload(const unsigned char *buf, size_t buflen,
+typedef CURLcode ws_write_payload(const uint8_t *buf, size_t buflen,
int frame_age, int frame_flags,
curl_off_t payload_offset,
curl_off_t payload_len,
struct Curl_easy *data,
struct bufq *inraw)
{
- const unsigned char *inbuf;
+ const uint8_t *inbuf;
size_t inlen;
while(Curl_bufq_peek(inraw, &inbuf, &inlen)) {
ws_write_payload *write_cb,
void *write_ctx)
{
- const unsigned char *inbuf;
+ const uint8_t *inbuf;
size_t inlen;
size_t nwritten;
CURLcode result;
dec->state = WS_DEC_PAYLOAD;
if(dec->payload_len == 0) {
size_t nwritten;
- const unsigned char tmp = '\0';
+ const uint8_t tmp = '\0';
/* special case of a 0 length frame, need to write once */
result = write_cb(&tmp, 0, dec->frame_age, dec->frame_flags,
0, 0, write_ctx, &nwritten);
bool blocking);
static CURLcode ws_enc_send(struct Curl_easy *data,
struct websocket *ws,
- const unsigned char *buffer,
+ const uint8_t *buffer,
size_t buflen,
curl_off_t fragsize,
unsigned int flags,
static CURLcode ws_enc_add_cntrl(struct Curl_easy *data,
struct websocket *ws,
- const unsigned char *payload,
+ const uint8_t *payload,
size_t plen,
unsigned int frame_type)
{
return remain - buffered;
}
-static CURLcode ws_cw_dec_next(const unsigned char *buf, size_t buflen,
+static CURLcode ws_cw_dec_next(const uint8_t *buf, size_t buflen,
int frame_age, int frame_flags,
curl_off_t payload_offset,
curl_off_t payload_len,
if(nbytes) {
size_t nwritten;
- result = Curl_bufq_write(&ctx->buf, (const unsigned char *)buf,
+ result = Curl_bufq_write(&ctx->buf, (const uint8_t *)buf,
nbytes, &nwritten);
if(result) {
infof(data, "[WS] error adding data to buffer %d", result);
curl_off_t payload_len,
struct bufq *out)
{
- unsigned char firstb = 0;
- unsigned char head[14];
+ uint8_t firstb = 0;
+ uint8_t head[14];
CURLcode result;
size_t hlen, nwritten;
head[0] = enc->firstbyte = firstb;
if(payload_len > 65535) {
head[1] = 127 | WSBIT_MASK;
- head[2] = (unsigned char)((payload_len >> 56) & 0xff);
- head[3] = (unsigned char)((payload_len >> 48) & 0xff);
- head[4] = (unsigned char)((payload_len >> 40) & 0xff);
- head[5] = (unsigned char)((payload_len >> 32) & 0xff);
- head[6] = (unsigned char)((payload_len >> 24) & 0xff);
- head[7] = (unsigned char)((payload_len >> 16) & 0xff);
- head[8] = (unsigned char)((payload_len >> 8) & 0xff);
- head[9] = (unsigned char)(payload_len & 0xff);
+ head[2] = (uint8_t)((payload_len >> 56) & 0xff);
+ head[3] = (uint8_t)((payload_len >> 48) & 0xff);
+ head[4] = (uint8_t)((payload_len >> 40) & 0xff);
+ head[5] = (uint8_t)((payload_len >> 32) & 0xff);
+ head[6] = (uint8_t)((payload_len >> 24) & 0xff);
+ head[7] = (uint8_t)((payload_len >> 16) & 0xff);
+ head[8] = (uint8_t)((payload_len >> 8) & 0xff);
+ head[9] = (uint8_t)(payload_len & 0xff);
hlen = 10;
}
else if(payload_len >= 126) {
head[1] = 126 | WSBIT_MASK;
- head[2] = (unsigned char)((payload_len >> 8) & 0xff);
- head[3] = (unsigned char)(payload_len & 0xff);
+ head[2] = (uint8_t)((payload_len >> 8) & 0xff);
+ head[3] = (uint8_t)(payload_len & 0xff);
hlen = 4;
}
else {
- head[1] = (unsigned char)payload_len | WSBIT_MASK;
+ head[1] = (uint8_t)payload_len | WSBIT_MASK;
hlen = 2;
}
/* 4 bytes random */
- result = Curl_rand(data, (unsigned char *)&enc->mask, sizeof(enc->mask));
+ result = Curl_rand(data, (uint8_t *)&enc->mask, sizeof(enc->mask));
if(result)
return result;
static CURLcode ws_enc_write_payload(struct ws_encoder *enc,
struct Curl_easy *data,
- const unsigned char *buf, size_t buflen,
+ const uint8_t *buf, size_t buflen,
struct bufq *out, size_t *pnwritten)
{
CURLcode result;
len = remain;
for(i = 0; i < len; ++i) {
- unsigned char c = buf[i] ^ enc->mask[enc->xori];
+ uint8_t c = buf[i] ^ enc->mask[enc->xori];
result = Curl_bufq_write(out, &c, 1, &n);
if(result) {
if((result != CURLE_AGAIN) || !i)
static CURLcode ws_enc_send(struct Curl_easy *data,
struct websocket *ws,
- const unsigned char *buffer,
+ const uint8_t *buffer,
size_t buflen,
curl_off_t fragsize,
unsigned int flags,
goto out;
}
- result = ws_enc_write_payload(&ws->enc, data, (unsigned char *)buf,
+ result = ws_enc_write_payload(&ws->enc, data, (uint8_t *)buf,
nread, &ws->sendbuf, &n);
if(result)
goto out;
{
unsigned int i;
CURLcode result = CURLE_OK;
- unsigned char rand[16];
+ uint8_t rand[16];
char *randstr;
size_t randlen;
char keyval[40];
heads[2].val = &keyval[0];
/* 16 bytes random */
- result = Curl_rand(data, (unsigned char *)rand, sizeof(rand));
+ result = Curl_rand(data, rand, sizeof(rand));
if(result)
return result;
result = curlx_base64_encode((char *)rand, sizeof(rand), &randstr, &randlen);
/* In CONNECT_ONLY setup, the payloads from `mem` need to be received
* when using `curl_ws_recv` later on after this transfer is already
* marked as DONE. */
- result = Curl_bufq_write(&ws->recvbuf, (const unsigned char *)mem,
+ result = Curl_bufq_write(&ws->recvbuf, (const uint8_t *)mem,
nread, &nwritten);
if(result)
goto out;
struct ws_collect {
struct Curl_easy *data;
struct websocket *ws;
- unsigned char *buffer;
+ uint8_t *buffer;
size_t buflen;
size_t bufidx;
int frame_age;
bool written;
};
-static CURLcode ws_client_collect(const unsigned char *buf, size_t buflen,
+static CURLcode ws_client_collect(const uint8_t *buf, size_t buflen,
int frame_age, int frame_flags,
curl_off_t payload_offset,
curl_off_t payload_len,
}
static CURLcode nw_in_recv(void *reader_ctx,
- unsigned char *buf, size_t buflen,
+ uint8_t *buf, size_t buflen,
size_t *pnread)
{
struct Curl_easy *data = reader_ctx;
{
if(!Curl_bufq_is_empty(&ws->sendbuf)) {
CURLcode result;
- const unsigned char *out;
+ const uint8_t *out;
size_t outlen, n;
#ifdef DEBUGBUILD
/* Simulate a blocking send after this chunk has been sent */
unsigned int flags)
{
struct websocket *ws;
- const unsigned char *buffer = buffer_arg;
+ const uint8_t *buffer = buffer_arg;
CURLcode result = CURLE_OK;
struct Curl_easy *data = d;
size_t ndummy;