mirror of
https://github.com/curl/curl.git
synced 2026-04-14 22:31:41 +03:00
ws: use uint8_t
Convert `unsigned char` use to `uint8_t`. Closes #19721
This commit is contained in:
parent
c4f29cc508
commit
fd5a117a67
1 changed files with 41 additions and 41 deletions
82
lib/ws.c
82
lib/ws.c
|
|
@ -91,7 +91,7 @@ struct ws_decoder {
|
|||
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;
|
||||
|
|
@ -103,8 +103,8 @@ struct ws_encoder {
|
|||
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 */
|
||||
};
|
||||
|
||||
|
|
@ -114,7 +114,7 @@ struct ws_encoder {
|
|||
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
|
||||
|
|
@ -131,7 +131,7 @@ struct websocket {
|
|||
};
|
||||
|
||||
|
||||
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:
|
||||
|
|
@ -152,7 +152,7 @@ static const char *ws_frame_name_of_op(unsigned char firstbyte)
|
|||
}
|
||||
|
||||
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 */
|
||||
|
|
@ -233,7 +233,7 @@ static int ws_frame_firstbyte2flags(struct Curl_easy *data,
|
|||
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) {
|
||||
|
|
@ -326,7 +326,7 @@ static CURLcode ws_send_raw_blocking(struct Curl_easy *data,
|
|||
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,
|
||||
|
|
@ -364,7 +364,7 @@ static CURLcode ws_dec_read_head(struct ws_decoder *dec,
|
|||
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)) {
|
||||
|
|
@ -486,7 +486,7 @@ static CURLcode ws_dec_pass_payload(struct ws_decoder *dec,
|
|||
ws_write_payload *write_cb,
|
||||
void *write_ctx)
|
||||
{
|
||||
const unsigned char *inbuf;
|
||||
const uint8_t *inbuf;
|
||||
size_t inlen;
|
||||
size_t nwritten;
|
||||
CURLcode result;
|
||||
|
|
@ -544,7 +544,7 @@ static CURLcode ws_dec_pass(struct ws_decoder *dec,
|
|||
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);
|
||||
|
|
@ -617,7 +617,7 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws,
|
|||
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,
|
||||
|
|
@ -627,7 +627,7 @@ static CURLcode ws_enc_add_pending(struct Curl_easy *data,
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
@ -663,7 +663,7 @@ static curl_off_t ws_payload_remain(curl_off_t payload_total,
|
|||
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,
|
||||
|
|
@ -729,7 +729,7 @@ static CURLcode ws_cw_write(struct Curl_easy *data,
|
|||
|
||||
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);
|
||||
|
|
@ -827,8 +827,8 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data,
|
|||
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;
|
||||
|
||||
|
|
@ -871,24 +871,24 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data,
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
@ -897,7 +897,7 @@ static CURLcode ws_enc_add_frame(struct Curl_easy *data,
|
|||
|
||||
/* 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;
|
||||
|
||||
|
|
@ -943,7 +943,7 @@ static CURLcode ws_enc_write_head(struct Curl_easy *data,
|
|||
|
||||
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;
|
||||
|
|
@ -960,7 +960,7 @@ static CURLcode ws_enc_write_payload(struct ws_encoder *enc,
|
|||
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)
|
||||
|
|
@ -1020,7 +1020,7 @@ out:
|
|||
|
||||
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,
|
||||
|
|
@ -1198,7 +1198,7 @@ static CURLcode cr_ws_read(struct Curl_easy *data,
|
|||
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;
|
||||
|
|
@ -1244,7 +1244,7 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req)
|
|||
{
|
||||
unsigned int i;
|
||||
CURLcode result = CURLE_OK;
|
||||
unsigned char rand[16];
|
||||
uint8_t rand[16];
|
||||
char *randstr;
|
||||
size_t randlen;
|
||||
char keyval[40];
|
||||
|
|
@ -1273,7 +1273,7 @@ CURLcode Curl_ws_request(struct Curl_easy *data, struct dynbuf *req)
|
|||
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);
|
||||
|
|
@ -1393,7 +1393,7 @@ CURLcode Curl_ws_accept(struct Curl_easy *data,
|
|||
/* 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;
|
||||
|
|
@ -1452,7 +1452,7 @@ 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;
|
||||
|
|
@ -1462,7 +1462,7 @@ struct ws_collect {
|
|||
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,
|
||||
|
|
@ -1519,7 +1519,7 @@ static CURLcode ws_client_collect(const unsigned char *buf, size_t buflen,
|
|||
}
|
||||
|
||||
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;
|
||||
|
|
@ -1628,7 +1628,7 @@ static CURLcode ws_flush(struct Curl_easy *data, struct websocket *ws,
|
|||
{
|
||||
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 */
|
||||
|
|
@ -1766,7 +1766,7 @@ CURLcode curl_ws_send(CURL *d, const void *buffer_arg,
|
|||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue