MCPcopy Create free account
hub / github.com/apache/httpd / lua_websocket_read

Function lua_websocket_read

modules/lua/lua_request.c:2276–2404  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2274}
2275
2276static int lua_websocket_read(lua_State *L)
2277{
2278 apr_status_t rv;
2279 int do_read = 1;
2280 int n = 0;
2281 apr_size_t plen = 0;
2282 unsigned short payload_short = 0;
2283 apr_uint64_t payload_long = 0;
2284 unsigned char *mask_bytes;
2285 char byte;
2286 apr_bucket_brigade *brigade;
2287 conn_rec* c;
2288
2289 request_rec *r = ap_lua_check_request_rec(L, 1);
2290 c = r->connection;
2291
2292 mask_bytes = apr_pcalloc(r->pool, 4);
2293
2294 brigade = apr_brigade_create(r->pool, c->bucket_alloc);
2295
2296 while (do_read) {
2297 do_read = 0;
2298 /* Get opcode and FIN bit */
2299 rv = lua_websocket_readbytes(c, brigade, &byte, 1);
2300 if (rv == APR_SUCCESS) {
2301 unsigned char ubyte, fin, opcode, mask, payload;
2302 ubyte = (unsigned char)byte;
2303 /* fin bit is the first bit */
2304 fin = ubyte >> (CHAR_BIT - 1);
2305 /* opcode is the last four bits (there's 3 reserved bits we don't care about) */
2306 opcode = ubyte & 0xf;
2307
2308 /* Get the payload length and mask bit */
2309 rv = lua_websocket_readbytes(c, brigade, &byte, 1);
2310 if (rv == APR_SUCCESS) {
2311 ubyte = (unsigned char)byte;
2312 /* Mask is the first bit */
2313 mask = ubyte >> (CHAR_BIT - 1);
2314 /* Payload is the last 7 bits */
2315 payload = ubyte & 0x7f;
2316 plen = payload;
2317
2318 /* Extended payload? */
2319 if (payload == 126) {
2320 rv = lua_websocket_readbytes(c, brigade,
2321 (char*) &payload_short, 2);
2322
2323 if (rv != APR_SUCCESS) {
2324 return 0;
2325 }
2326
2327 plen = ntohs(payload_short);
2328 }
2329 /* Super duper extended payload? */
2330 if (payload == 127) {
2331 rv = lua_websocket_readbytes(c, brigade,
2332 (char*) &payload_long, 8);
2333

Callers

nothing calls this directly

Calls 4

lua_websocket_readbytesFunction · 0.85
ap_ntoh64Function · 0.85
ap_pass_brigadeFunction · 0.85
ap_lua_check_request_recFunction · 0.70

Tested by

no test coverage detected