Lines Matching refs:ws
98 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_get_payload_transport_handle() local
102 ws->frame_state.bytes_remaining = 0; in ws_get_payload_transport_handle()
104 return ws->parent; in ws_get_payload_transport_handle()
145 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_connect() local
146 if (esp_transport_connect(ws->parent, host, port, timeout_ms) < 0) { in ws_connect()
157 const char *user_agent_ptr = (ws->user_agent)?(ws->user_agent):"ESP32 Websocket Client"; in ws_connect()
161 int len = snprintf(ws->buffer, WS_BUFFER_SIZE, in ws_connect()
169 ws->path, in ws_connect()
176 if (ws->sub_protocol) { in ws_connect()
177 ESP_LOGD(TAG, "sub_protocol: %s", ws->sub_protocol); in ws_connect()
178 …int r = snprintf(ws->buffer + len, WS_BUFFER_SIZE - len, "Sec-WebSocket-Protocol: %s\r\n", ws->sub… in ws_connect()
186 if (ws->headers) { in ws_connect()
187 ESP_LOGD(TAG, "headers: %s", ws->headers); in ws_connect()
188 int r = snprintf(ws->buffer + len, WS_BUFFER_SIZE - len, "%s", ws->headers); in ws_connect()
196 int r = snprintf(ws->buffer + len, WS_BUFFER_SIZE - len, "\r\n"); in ws_connect()
203 ESP_LOGD(TAG, "Write upgrade request\r\n%s", ws->buffer); in ws_connect()
204 if (esp_transport_write(ws->parent, ws->buffer, len, timeout_ms) <= 0) { in ws_connect()
205 ESP_LOGE(TAG, "Error write Upgrade header %s", ws->buffer); in ws_connect()
210 …if ((len = esp_transport_read(ws->parent, ws->buffer + header_len, WS_BUFFER_SIZE - header_len, ti… in ws_connect()
211 ESP_LOGE(TAG, "Error read response for Upgrade header %s", ws->buffer); in ws_connect()
215 ws->buffer[header_len] = '\0'; in ws_connect()
217 } while (NULL == strstr(ws->buffer, "\r\n\r\n") && header_len < WS_BUFFER_SIZE); in ws_connect()
219 char *server_key = get_http_header(ws->buffer, "Sec-WebSocket-Accept:"); in ws_connect()
249 transport_ws_t *ws = esp_transport_get_context_data(t); in _ws_write() local
256 if ((poll_write = esp_transport_poll_write(ws->parent, timeout_ms)) <= 0) { in _ws_write()
291 if (esp_transport_write(ws->parent, ws_header, header_len, timeout_ms) != header_len) { in _ws_write()
299 int ret = esp_transport_write(ws->parent, buffer, len, timeout_ms); in _ws_write()
337 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_read_payload() local
342 if (ws->frame_state.bytes_remaining > len) { in ws_read_payload()
343 …ESP_LOGD(TAG, "Actual data to receive (%d) are longer than ws buffer (%d)", ws->frame_state.bytes_… in ws_read_payload()
347 bytes_to_read = ws->frame_state.bytes_remaining; in ws_read_payload()
351 …if (bytes_to_read != 0 && (rlen = esp_transport_read(ws->parent, buffer, bytes_to_read, timeout_ms… in ws_read_payload()
355 ws->frame_state.bytes_remaining -= rlen; in ws_read_payload()
357 if (ws->frame_state.mask_key) { in ws_read_payload()
359 buffer[i] = (buffer[i] ^ ws->frame_state.mask_key[i % 4]); in ws_read_payload()
369 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_read_header() local
376 ws->frame_state.header_received = false; in ws_read_header()
377 if ((poll_read = esp_transport_poll_read(ws->parent, timeout_ms)) <= 0) { in ws_read_header()
384 if ((rlen = esp_transport_read(ws->parent, data_ptr, header, timeout_ms)) <= 0) { in ws_read_header()
388 ws->frame_state.header_received = true; in ws_read_header()
389 ws->frame_state.opcode = (*data_ptr & 0x0F); in ws_read_header()
394 ESP_LOGD(TAG, "Opcode: %d, mask: %d, len: %d\r\n", ws->frame_state.opcode, mask, payload_len); in ws_read_header()
397 if ((rlen = esp_transport_read(ws->parent, data_ptr, header, timeout_ms)) <= 0) { in ws_read_header()
405 if ((rlen = esp_transport_read(ws->parent, data_ptr, header, timeout_ms)) <= 0) { in ws_read_header()
420 …if (payload_len != 0 && (rlen = esp_transport_read(ws->parent, buffer, mask_len, timeout_ms)) <= 0… in ws_read_header()
424 memcpy(ws->frame_state.mask_key, buffer, mask_len); in ws_read_header()
426 memset(ws->frame_state.mask_key, 0, mask_len); in ws_read_header()
429 ws->frame_state.payload_len = payload_len; in ws_read_header()
430 ws->frame_state.bytes_remaining = payload_len; in ws_read_header()
437 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_handle_control_frame_internal() local
440 int payload_len = ws->frame_state.payload_len; in ws_handle_control_frame_internal()
445 if (ws->frame_state.header_received == false || in ws_handle_control_frame_internal()
446 !(ws->frame_state.opcode & WS_OPCODE_CONTROL_FRAME)) { in ws_handle_control_frame_internal()
452 ws->frame_state.payload_len, WS_TRANSPORT_MAX_CONTROL_FRAME_BUFFER_LEN); in ws_handle_control_frame_internal()
472 ws->frame_state.opcode, payload_len, actual_len); in ws_handle_control_frame_internal()
488 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_read() local
491 if (ws->frame_state.bytes_remaining <= 0) { in ws_read()
495 ws->frame_state.bytes_remaining = 0; in ws_read()
501 if (ws->frame_state.header_received && (ws->frame_state.opcode & WS_OPCODE_CONTROL_FRAME) && in ws_read()
502 ws->propagate_control_frames == false) { in ws_read()
509 ws->frame_state.bytes_remaining = 0; in ws_read()
514 if (ws->frame_state.payload_len) { in ws_read()
517 ws->frame_state.bytes_remaining = 0; in ws_read()
528 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_poll_read() local
529 return esp_transport_poll_read(ws->parent, timeout_ms); in ws_poll_read()
534 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_poll_write() local
535 return esp_transport_poll_write(ws->parent, timeout_ms);; in ws_poll_write()
540 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_close() local
541 return esp_transport_close(ws->parent); in ws_close()
546 transport_ws_t *ws = esp_transport_get_context_data(t); in ws_destroy() local
547 free(ws->buffer); in ws_destroy()
548 free(ws->path); in ws_destroy()
549 free(ws->sub_protocol); in ws_destroy()
550 free(ws->user_agent); in ws_destroy()
551 free(ws->headers); in ws_destroy()
552 free(ws); in ws_destroy()
560 transport_ws_t *ws = esp_transport_get_context_data(t); in internal_esp_transport_ws_set_path() local
561 if (ws->path) { in internal_esp_transport_ws_set_path()
562 free(ws->path); in internal_esp_transport_ws_set_path()
565 ws->path = NULL; in internal_esp_transport_ws_set_path()
568 ws->path = strdup(path); in internal_esp_transport_ws_set_path()
569 if (ws->path == NULL) { in internal_esp_transport_ws_set_path()
586 transport_ws_t *ws = t->data; in ws_get_socket() local
587 if (ws && ws->parent && ws->parent->_get_socket) { in ws_get_socket()
588 return ws->parent->_get_socket(ws->parent); in ws_get_socket()
600 transport_ws_t *ws = calloc(1, sizeof(transport_ws_t)); in esp_transport_ws_init() local
601 ESP_TRANSPORT_MEM_CHECK(TAG, ws, return NULL); in esp_transport_ws_init()
602 ws->parent = parent_handle; in esp_transport_ws_init()
604 ws->path = strdup("/"); in esp_transport_ws_init()
605 ESP_TRANSPORT_MEM_CHECK(TAG, ws->path, { in esp_transport_ws_init()
606 free(ws); in esp_transport_ws_init()
610 ws->buffer = malloc(WS_BUFFER_SIZE); in esp_transport_ws_init()
611 ESP_TRANSPORT_MEM_CHECK(TAG, ws->buffer, { in esp_transport_ws_init()
612 free(ws->path); in esp_transport_ws_init()
613 free(ws); in esp_transport_ws_init()
622 esp_transport_set_context_data(t, ws); in esp_transport_ws_init()
632 transport_ws_t *ws = esp_transport_get_context_data(t); in esp_transport_ws_set_subprotocol() local
633 if (ws->sub_protocol) { in esp_transport_ws_set_subprotocol()
634 free(ws->sub_protocol); in esp_transport_ws_set_subprotocol()
637 ws->sub_protocol = NULL; in esp_transport_ws_set_subprotocol()
640 ws->sub_protocol = strdup(sub_protocol); in esp_transport_ws_set_subprotocol()
641 if (ws->sub_protocol == NULL) { in esp_transport_ws_set_subprotocol()
652 transport_ws_t *ws = esp_transport_get_context_data(t); in esp_transport_ws_set_user_agent() local
653 if (ws->user_agent) { in esp_transport_ws_set_user_agent()
654 free(ws->user_agent); in esp_transport_ws_set_user_agent()
657 ws->user_agent = NULL; in esp_transport_ws_set_user_agent()
660 ws->user_agent = strdup(user_agent); in esp_transport_ws_set_user_agent()
661 if (ws->user_agent == NULL) { in esp_transport_ws_set_user_agent()
672 transport_ws_t *ws = esp_transport_get_context_data(t); in esp_transport_ws_set_headers() local
673 if (ws->headers) { in esp_transport_ws_set_headers()
674 free(ws->headers); in esp_transport_ws_set_headers()
677 ws->headers = NULL; in esp_transport_ws_set_headers()
680 ws->headers = strdup(headers); in esp_transport_ws_set_headers()
681 if (ws->headers == NULL) { in esp_transport_ws_set_headers()
693 transport_ws_t *ws = esp_transport_get_context_data(t); in esp_transport_ws_set_config() local
710 ws->propagate_control_frames = config->propagate_control_frames; in esp_transport_ws_set_config()
717 transport_ws_t *ws = esp_transport_get_context_data(t); in esp_transport_ws_get_read_opcode() local
718 if (ws->frame_state.header_received) { in esp_transport_ws_get_read_opcode()
720 return (ws_transport_opcodes_t)ws->frame_state.opcode; in esp_transport_ws_get_read_opcode()
727 transport_ws_t *ws = esp_transport_get_context_data(t); in esp_transport_ws_get_read_payload_len() local
728 return ws->frame_state.payload_len; in esp_transport_ws_get_read_payload_len()
733 transport_ws_t *ws = esp_transport_get_context_data(t); in esp_transport_ws_handle_control_frames() local
737 if (ws->frame_state.header_received == false || in esp_transport_ws_handle_control_frames()
738 !(ws->frame_state.opcode & WS_OPCODE_CONTROL_FRAME)) { in esp_transport_ws_handle_control_frames()
742 int payload_len = ws->frame_state.payload_len; in esp_transport_ws_handle_control_frames()
747 ws->frame_state.bytes_remaining = payload_len - len; in esp_transport_ws_handle_control_frames()
751 if (ws->frame_state.opcode == WS_OPCODE_PING) { in esp_transport_ws_handle_control_frames()
762 ws->frame_state.header_received = false; in esp_transport_ws_handle_control_frames()
765 } else if (ws->frame_state.opcode == WS_OPCODE_CLOSE) { in esp_transport_ws_handle_control_frames()
782 ws->frame_state.header_received = false; in esp_transport_ws_handle_control_frames()
794 } else if (ws->frame_state.opcode == WS_OPCODE_PONG) { in esp_transport_ws_handle_control_frames()
798 ws->frame_state.header_received = false; in esp_transport_ws_handle_control_frames()