/* Handle STREAM_OPEN */ void stream_on_open(const char *filename) { int err = STREAM_ERROR; stream_mgr_lock(); trigger_cpu_boost(); /* Open the video file */ if (disk_buf_open(filename) >= 0) { /* Initialize the parser */ err = parser_init_stream(); if (err >= STREAM_OK) { /* File ok - save the opened filename */ stream_mgr.filename = filename; } } /* If error - cleanup */ if (err < STREAM_OK) stream_on_close(); cancel_cpu_boost(); stream_mgr_unlock(); stream_mgr_reply_msg(err); }
subuser *checkrecv(ape_socket *co, acetables *g_ape) { unsigned int op; http_state *http = co->parser.data; subuser *user = NULL; clientget cget; if (http->host == NULL) { shutdown(co->fd, 2); return NULL; } if (gettransport(http->uri) == TRANSPORT_WEBSOCKET) { char *origin = get_header_line(http->hlines, "Origin"); websocket_state *websocket; if (origin == NULL) { shutdown(co->fd, 2); return NULL; } PACK_TCP(co->fd); sendbin(co->fd, CONST_STR_LEN(WEBSOCKET_HARDCODED_HEADERS), 0, g_ape); sendbin(co->fd, CONST_STR_LEN("WebSocket-Origin: "), 0, g_ape); sendbin(co->fd, origin, strlen(origin), 0, g_ape); sendbin(co->fd, CONST_STR_LEN("\r\nWebSocket-Location: ws://"), 0, g_ape); sendbin(co->fd, http->host, strlen(http->host), 0, g_ape); sendbin(co->fd, http->uri, strlen(http->uri), 0, g_ape); sendbin(co->fd, CONST_STR_LEN("\r\n\r\n"), 0, g_ape); FLUSH_TCP(co->fd); co->parser = parser_init_stream(co); websocket = co->parser.data; websocket->http = http; /* keep http data */ return NULL; } if (http->data == NULL) { sendbin(co->fd, HEADER_DEFAULT, HEADER_DEFAULT_LEN, 0, g_ape); sendbin(co->fd, CONST_STR_LEN(CONTENT_NOTFOUND), 0, g_ape); safe_shutdown(co->fd, g_ape); return NULL; } cget.client = co; cget.ip_get = co->ip_client; cget.get = http->data; cget.host = http->host; cget.hlines = http->hlines; op = checkcmd(&cget, gettransport(http->uri), &user, g_ape); switch (op) { case CONNECT_SHUTDOWN: safe_shutdown(co->fd, g_ape); break; case CONNECT_KEEPALIVE: break; } return user; }