Lines Matching refs:dec

110 static void ws_dec_info(struct ws_decoder *dec, struct Curl_easy *data,
113 switch(dec->head_len) {
118 ws_frame_name_of_op(dec->head[0]),
119 (dec->head[0] & WSBIT_FIN)? "" : " NON-FINAL");
122 if(dec->head_len < dec->head_total) {
124 ws_frame_name_of_op(dec->head[0]),
125 (dec->head[0] & WSBIT_FIN)? "" : " NON-FINAL",
126 dec->head_len, dec->head_total);
131 msg, ws_frame_name_of_op(dec->head[0]),
132 (dec->head[0] & WSBIT_FIN)? "" : " NON-FINAL",
133 dec->payload_offset, dec->payload_len);
147 static void ws_dec_reset(struct ws_decoder *dec)
149 dec->frame_age = 0;
150 dec->frame_flags = 0;
151 dec->payload_offset = 0;
152 dec->payload_len = 0;
153 dec->head_len = dec->head_total = 0;
154 dec->state = WS_DEC_INIT;
157 static void ws_dec_init(struct ws_decoder *dec)
159 ws_dec_reset(dec);
162 static CURLcode ws_dec_read_head(struct ws_decoder *dec,
170 if(dec->head_len == 0) {
171 dec->head[0] = *inbuf;
174 dec->frame_flags = ws_frame_op2flags(dec->head[0]);
175 if(!dec->frame_flags) {
176 failf(data, "WS: unknown opcode: %x", dec->head[0]);
177 ws_dec_reset(dec);
180 dec->head_len = 1;
181 /* ws_dec_info(dec, data, "seeing opcode"); */
184 else if(dec->head_len == 1) {
185 dec->head[1] = *inbuf;
187 dec->head_len = 2;
189 if(dec->head[1] & WSBIT_MASK) {
192 ws_dec_reset(dec);
196 if(dec->head[1] == 126) {
197 dec->head_total = 4;
200 else if(dec->head[1] == 127) {
201 dec->head_total = 10;
205 dec->head_total = 2;
209 if(dec->head_len < dec->head_total) {
210 dec->head[dec->head_len] = *inbuf;
212 ++dec->head_len;
213 if(dec->head_len < dec->head_total) {
214 /* ws_dec_info(dec, data, "decoding head"); */
219 DEBUGASSERT(dec->head_len == dec->head_total);
220 switch(dec->head_total) {
222 dec->payload_len = dec->head[1];
225 dec->payload_len = (dec->head[2] << 8) | dec->head[3];
228 if(dec->head[2] > 127) {
232 dec->payload_len = ((curl_off_t)dec->head[2] << 56) |
233 (curl_off_t)dec->head[3] << 48 |
234 (curl_off_t)dec->head[4] << 40 |
235 (curl_off_t)dec->head[5] << 32 |
236 (curl_off_t)dec->head[6] << 24 |
237 (curl_off_t)dec->head[7] << 16 |
238 (curl_off_t)dec->head[8] << 8 |
239 dec->head[9];
248 dec->frame_age = 0;
249 dec->payload_offset = 0;
250 ws_dec_info(dec, data, "decoded");
256 static CURLcode ws_dec_pass_payload(struct ws_decoder *dec,
266 curl_off_t remain = dec->payload_len - dec->payload_offset;
272 nwritten = write_payload(inbuf, inlen, dec->frame_age, dec->frame_flags,
273 dec->payload_offset, dec->payload_len,
278 dec->payload_offset += (curl_off_t)nwritten;
279 remain = dec->payload_len - dec->payload_offset;
288 static CURLcode ws_dec_pass(struct ws_decoder *dec,
299 switch(dec->state) {
301 ws_dec_reset(dec);
302 dec->state = WS_DEC_HEAD;
305 result = ws_dec_read_head(dec, data, inraw);
316 dec->state = WS_DEC_PAYLOAD;
317 if(dec->payload_len == 0) {
321 nwritten = write_payload(&tmp, 0, dec->frame_age, dec->frame_flags,
325 dec->state = WS_DEC_INIT;
330 result = ws_dec_pass_payload(dec, data, inraw, write_payload, write_ctx);
331 ws_dec_info(dec, data, "passing");
335 dec->state = WS_DEC_INIT;
455 result = ws_dec_pass(&ws->dec, data, &ctx->buf,
765 ws_dec_init(&ws->dec);
770 ws_dec_reset(&ws->dec);
965 result = ws_dec_pass(&ws->dec, data, &ws->recvbuf,
969 ws_dec_info(&ws->dec, data, "need more input");