Lines Matching refs:hctx

101 …if (hctx->gw.conf.debug >= MOD_WEBSOCKET_LOG_ERR) { log_error(hctx->errh, __FILE__, __LINE__, (for…
104 …if (hctx->gw.conf.debug >= MOD_WEBSOCKET_LOG_WARN) { log_error(hctx->errh, __FILE__, __LINE__, (fo…
107 …if (hctx->gw.conf.debug >= MOD_WEBSOCKET_LOG_INFO) { log_error(hctx->errh, __FILE__, __LINE__, (fo…
110 …if (hctx->gw.conf.debug >= MOD_WEBSOCKET_LOG_DEBUG) { log_error(hctx->errh, __FILE__, __LINE__, (f…
348 handler_ctx *hctx = (handler_ctx *)gwhctx; in wstunnel_create_env() local
349 request_st * const r = hctx->gw.r; in wstunnel_create_env()
355 rc = mod_wstunnel_handshake_create_response(hctx); in wstunnel_create_env()
363 hctx->ping_ts = log_monotonic_secs; in wstunnel_create_env()
364 gw_set_transparent(&hctx->gw); in wstunnel_create_env()
373 handler_ctx *hctx = (handler_ctx *)gwhctx; in wstunnel_stdin_append() local
374 if (0 == mod_wstunnel_frame_recv(hctx)) in wstunnel_stdin_append()
380 request_st * const r = hctx->gw.r; in wstunnel_stdin_append()
383 …mod_wstunnel_frame_send(hctx, MOD_WEBSOCKET_FRAME_TYPE_CLOSE, CONST_STR_LEN("1000")); /* 1000 Norm… in wstunnel_stdin_append()
384 gw_handle_request_reset(r, hctx->gw.plugin_data); in wstunnel_stdin_append()
390 handler_ctx *hctx = (handler_ctx *)opts->pdata; in wstunnel_recv_parse() local
391 DEBUG_LOG_DEBUG("recv data from backend (fd=%d), size=%zx", hctx->gw.fd, n); in wstunnel_recv_parse()
393 if (mod_wstunnel_frame_send(hctx,hctx->frame.type_backend,b->ptr,n) < 0) { in wstunnel_recv_parse()
402 static int wstunnel_is_allowed_origin(request_st * const r, handler_ctx * const hctx) { in wstunnel_is_allowed_origin() argument
406 const array * const allowed_origins = hctx->conf.origins; in wstunnel_is_allowed_origin()
443 static int wstunnel_check_request(request_st * const r, handler_ctx * const hctx) { in wstunnel_check_request() argument
462 if (!wstunnel_is_allowed_origin(r, hctx)) { in wstunnel_check_request()
470 handler_ctx *hctx = (handler_ctx *)gwhctx; in wstunnel_backend_error() local
471 if (hctx->gw.state == GW_STATE_WRITE || hctx->gw.state == GW_STATE_READ) { in wstunnel_backend_error()
472 …mod_wstunnel_frame_send(hctx, MOD_WEBSOCKET_FRAME_TYPE_CLOSE, CONST_STR_LEN("1001")); /* 1001 Goin… in wstunnel_backend_error()
477 handler_ctx *hctx = (handler_ctx *)gwhctx; in wstunnel_handler_ctx_free() local
478 chunk_buffer_release(hctx->frame.payload); in wstunnel_handler_ctx_free()
482 handler_ctx *hctx = r->plugin_ctx[p->id]; in wstunnel_handler_setup() local
484 hctx->errh = r->conf.errh;/*(for mod_wstunnel-specific DEBUG_* macros)*/ in wstunnel_handler_setup()
485 hctx->conf = p->conf; /*(copies struct)*/ in wstunnel_handler_setup()
486 hybivers = wstunnel_check_request(r, hctx); in wstunnel_handler_setup()
491 hctx->hybivers = hybivers; in wstunnel_handler_setup()
499 hctx->gw.opts.backend = BACKEND_PROXY; /*(act proxy-like)*/ in wstunnel_handler_setup()
500 hctx->gw.opts.pdata = hctx; in wstunnel_handler_setup()
501 hctx->gw.opts.parse = wstunnel_recv_parse; in wstunnel_handler_setup()
502 hctx->gw.stdin_append = wstunnel_stdin_append; in wstunnel_handler_setup()
503 hctx->gw.create_env = wstunnel_create_env; in wstunnel_handler_setup()
504 hctx->gw.handler_ctx_free = wstunnel_handler_ctx_free; in wstunnel_handler_setup()
505 hctx->gw.backend_error = wstunnel_backend_error; in wstunnel_handler_setup()
506 hctx->gw.response = chunk_buffer_acquire(); in wstunnel_handler_setup()
508 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_INIT; in wstunnel_handler_setup()
509 hctx->frame.ctl.siz = 0; in wstunnel_handler_setup()
510 hctx->frame.payload = chunk_buffer_acquire(); in wstunnel_handler_setup()
512 unsigned int binary = hctx->conf.frame_type; /*(0 = "text"; 1 = "binary")*/ in wstunnel_handler_setup()
523 hctx->subproto = 1; in wstunnel_handler_setup()
532 hctx->subproto = -1; in wstunnel_handler_setup()
544 hctx->frame.type = MOD_WEBSOCKET_FRAME_TYPE_BIN; in wstunnel_handler_setup()
545 hctx->frame.type_before = MOD_WEBSOCKET_FRAME_TYPE_BIN; in wstunnel_handler_setup()
546 hctx->frame.type_backend = MOD_WEBSOCKET_FRAME_TYPE_BIN; in wstunnel_handler_setup()
550 hctx->frame.type = MOD_WEBSOCKET_FRAME_TYPE_TEXT; in wstunnel_handler_setup()
551 hctx->frame.type_before = MOD_WEBSOCKET_FRAME_TYPE_TEXT; in wstunnel_handler_setup()
552 hctx->frame.type_backend = MOD_WEBSOCKET_FRAME_TYPE_TEXT; in wstunnel_handler_setup()
606 handler_ctx *hctx = r->plugin_ctx[p->id]; in TRIGGER_FUNC() local
607 if (NULL == hctx || r->handler_module != p->self) in TRIGGER_FUNC()
610 if (hctx->gw.state != GW_STATE_WRITE && hctx->gw.state != GW_STATE_READ) in TRIGGER_FUNC()
615 mod_wstunnel_frame_send(hctx,MOD_WEBSOCKET_FRAME_TYPE_CLOSE,NULL,0); in TRIGGER_FUNC()
624 if (0 != hctx->hybivers in TRIGGER_FUNC()
625 && hctx->conf.ping_interval > 0 in TRIGGER_FUNC()
626 && (int32_t)hctx->conf.ping_interval + hctx->ping_ts < cur_ts) { in TRIGGER_FUNC()
627 hctx->ping_ts = cur_ts; in TRIGGER_FUNC()
628 mod_wstunnel_frame_send(hctx, MOD_WEBSOCKET_FRAME_TYPE_PING, CONST_STR_LEN("ping")); in TRIGGER_FUNC()
728 static int create_response_ietf_00(handler_ctx *hctx) { in create_response_ietf_00() argument
729 request_st * const r = hctx->gw.r; in create_response_ietf_00()
790 static int create_response_rfc_6455(handler_ctx *hctx) { in create_response_rfc_6455() argument
791 request_st * const r = hctx->gw.r; in create_response_rfc_6455()
825 if (hctx->frame.type == MOD_WEBSOCKET_FRAME_TYPE_BIN) in create_response_rfc_6455()
829 else if (-1 == hctx->subproto) in create_response_rfc_6455()
840 handler_t mod_wstunnel_handshake_create_response(handler_ctx *hctx) { in mod_wstunnel_handshake_create_response() argument
841 request_st * const r = hctx->gw.r; in mod_wstunnel_handshake_create_response()
843 if (hctx->hybivers >= 8) { in mod_wstunnel_handshake_create_response()
845 if (0 != create_response_rfc_6455(hctx)) { in mod_wstunnel_handshake_create_response()
854 if (hctx->hybivers == 0 && r->http_version == HTTP_VERSION_1_1) { in mod_wstunnel_handshake_create_response()
864 if (0 != create_response_ietf_00(hctx)) { in mod_wstunnel_handshake_create_response()
892 static int send_ietf_00(handler_ctx *hctx, mod_wstunnel_frame_type_t type, const char *payload, siz… in send_ietf_00() argument
895 request_st * const r = hctx->gw.r; in send_ietf_00()
933 static int recv_ietf_00(handler_ctx *hctx) { in recv_ietf_00() argument
934 request_st * const r = hctx->gw.r; in recv_ietf_00()
936 buffer *payload = hctx->frame.payload; in recv_ietf_00()
947 switch (hctx->frame.state) { in recv_ietf_00()
949 hctx->frame.ctl.siz = 0; in recv_ietf_00()
951 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_READ_PAYLOAD; in recv_ietf_00()
967 hctx->frame.ctl.siz += flen - i; in recv_ietf_00()
968 if (hctx->frame.ctl.siz > MOD_WEBSOCKET_BUFMAX) { in recv_ietf_00()
979 hctx->frame.ctl.siz += (mem - (frame+i)); in recv_ietf_00()
980 if (hctx->frame.ctl.siz > MOD_WEBSOCKET_BUFMAX) { in recv_ietf_00()
987 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_INIT; in recv_ietf_00()
990 if (hctx->frame.type == MOD_WEBSOCKET_FRAME_TYPE_TEXT in recv_ietf_00()
992 hctx->frame.ctl.siz = 0; in recv_ietf_00()
993 chunkqueue_append_buffer(&hctx->gw.wb, payload); in recv_ietf_00()
997 if (hctx->frame.state == MOD_WEBSOCKET_FRAME_STATE_INIT in recv_ietf_00()
1002 chunkqueue_get_memory(&hctx->gw.wb, &len); in recv_ietf_00()
1003 b = hctx->gw.wb.last->mem; in recv_ietf_00()
1015 hctx->gw.wb.bytes_in += buffer_clen(b)-len; in recv_ietf_00()
1048 static int send_rfc_6455(handler_ctx *hctx, mod_wstunnel_frame_type_t type, const char *payload, si… in send_rfc_6455() argument
1105 request_st * const r = hctx->gw.r; in send_rfc_6455()
1113 static void unmask_payload(handler_ctx *hctx) { in unmask_payload() argument
1114 buffer * const b = hctx->frame.payload; in unmask_payload()
1116 b->ptr[i] ^= hctx->frame.ctl.mask[hctx->frame.ctl.mask_cnt]; in unmask_payload()
1117 hctx->frame.ctl.mask_cnt = (hctx->frame.ctl.mask_cnt + 1) % 4; in unmask_payload()
1121 static int recv_rfc_6455(handler_ctx *hctx) { in recv_rfc_6455() argument
1122 request_st * const r = hctx->gw.r; in recv_rfc_6455()
1124 buffer *payload = hctx->frame.payload; in recv_rfc_6455()
1134 switch (hctx->frame.state) { in recv_rfc_6455()
1139 hctx->frame.type = hctx->frame.type_before; in recv_rfc_6455()
1143 hctx->frame.type = MOD_WEBSOCKET_FRAME_TYPE_TEXT; in recv_rfc_6455()
1144 hctx->frame.type_before = hctx->frame.type; in recv_rfc_6455()
1148 hctx->frame.type = MOD_WEBSOCKET_FRAME_TYPE_BIN; in recv_rfc_6455()
1149 hctx->frame.type_before = hctx->frame.type; in recv_rfc_6455()
1153 hctx->frame.type = MOD_WEBSOCKET_FRAME_TYPE_PING; in recv_rfc_6455()
1157 hctx->frame.type = MOD_WEBSOCKET_FRAME_TYPE_PONG; in recv_rfc_6455()
1161 hctx->frame.type = MOD_WEBSOCKET_FRAME_TYPE_CLOSE; in recv_rfc_6455()
1170 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_READ_LENGTH; in recv_rfc_6455()
1177 hctx->frame.ctl.mask_cnt = 0; in recv_rfc_6455()
1178 hctx->frame.ctl.siz = (uint64_t)(frame[i] & 0x7f); in recv_rfc_6455()
1179 if (hctx->frame.ctl.siz == 0) { in recv_rfc_6455()
1181 (unsigned long long)hctx->frame.ctl.siz); in recv_rfc_6455()
1182 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_READ_MASK; in recv_rfc_6455()
1184 else if (hctx->frame.ctl.siz == MOD_WEBSOCKET_FRAME_LEN16) { in recv_rfc_6455()
1185 hctx->frame.ctl.siz = 0; in recv_rfc_6455()
1186 hctx->frame.ctl.siz_cnt = MOD_WEBSOCKET_FRAME_LEN16_CNT; in recv_rfc_6455()
1187 hctx->frame.state = in recv_rfc_6455()
1190 else if (hctx->frame.ctl.siz == MOD_WEBSOCKET_FRAME_LEN63) { in recv_rfc_6455()
1191 hctx->frame.ctl.siz = 0; in recv_rfc_6455()
1192 hctx->frame.ctl.siz_cnt = MOD_WEBSOCKET_FRAME_LEN63_CNT; in recv_rfc_6455()
1193 hctx->frame.state = in recv_rfc_6455()
1198 (unsigned long long)hctx->frame.ctl.siz); in recv_rfc_6455()
1199 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_READ_MASK; in recv_rfc_6455()
1204 hctx->frame.ctl.siz = in recv_rfc_6455()
1205 (hctx->frame.ctl.siz << 8) + (frame[i] & 0xff); in recv_rfc_6455()
1206 hctx->frame.ctl.siz_cnt--; in recv_rfc_6455()
1207 if (hctx->frame.ctl.siz_cnt <= 0) { in recv_rfc_6455()
1208 if (hctx->frame.type == MOD_WEBSOCKET_FRAME_TYPE_PING && in recv_rfc_6455()
1209 hctx->frame.ctl.siz > MOD_WEBSOCKET_BUFMAX) { in recv_rfc_6455()
1215 (unsigned long long)hctx->frame.ctl.siz); in recv_rfc_6455()
1216 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_READ_MASK; in recv_rfc_6455()
1221 hctx->frame.ctl.mask[hctx->frame.ctl.mask_cnt] = frame[i]; in recv_rfc_6455()
1222 hctx->frame.ctl.mask_cnt++; in recv_rfc_6455()
1223 if (hctx->frame.ctl.mask_cnt >= MOD_WEBSOCKET_MASK_CNT) { in recv_rfc_6455()
1224 hctx->frame.ctl.mask_cnt = 0; in recv_rfc_6455()
1225 if (hctx->frame.type == MOD_WEBSOCKET_FRAME_TYPE_PING && in recv_rfc_6455()
1226 hctx->frame.ctl.siz == 0) { in recv_rfc_6455()
1227 mod_wstunnel_frame_send(hctx, in recv_rfc_6455()
1231 if (hctx->frame.ctl.siz == 0) { in recv_rfc_6455()
1232 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_INIT; in recv_rfc_6455()
1235 hctx->frame.state = in recv_rfc_6455()
1243 if (hctx->frame.ctl.siz <= flen - i) { in recv_rfc_6455()
1245 (unsigned long long)hctx->frame.ctl.siz); in recv_rfc_6455()
1247 (hctx->frame.ctl.siz & SIZE_MAX)); in recv_rfc_6455()
1248 i += (size_t)(hctx->frame.ctl.siz & SIZE_MAX); in recv_rfc_6455()
1249 hctx->frame.ctl.siz = 0; in recv_rfc_6455()
1250 hctx->frame.state = MOD_WEBSOCKET_FRAME_STATE_INIT; in recv_rfc_6455()
1257 hctx->frame.ctl.siz -= flen - i; in recv_rfc_6455()
1260 (unsigned long long)hctx->frame.ctl.siz); in recv_rfc_6455()
1262 switch (hctx->frame.type) { in recv_rfc_6455()
1266 unmask_payload(hctx); in recv_rfc_6455()
1267 chunkqueue_append_buffer(&hctx->gw.wb, payload); in recv_rfc_6455()
1272 if (hctx->frame.ctl.siz == 0) { in recv_rfc_6455()
1273 unmask_payload(hctx); in recv_rfc_6455()
1274 mod_wstunnel_frame_send(hctx, in recv_rfc_6455()
1304 int mod_wstunnel_frame_send(handler_ctx *hctx, mod_wstunnel_frame_type_t type, in mod_wstunnel_frame_send() argument
1307 if (hctx->hybivers >= 8) return send_rfc_6455(hctx, type, payload, siz); in mod_wstunnel_frame_send()
1310 if (0 == hctx->hybivers) return send_ietf_00(hctx, type, payload, siz); in mod_wstunnel_frame_send()
1315 int mod_wstunnel_frame_recv(handler_ctx *hctx) { in mod_wstunnel_frame_recv() argument
1317 if (hctx->hybivers >= 8) return recv_rfc_6455(hctx); in mod_wstunnel_frame_recv()
1320 if (0 == hctx->hybivers) return recv_ietf_00(hctx); in mod_wstunnel_frame_recv()