void t04_websocket_server_close_handshake() { INIT_LOCAL(); int length = 0; unsigned char *buffer = NULL, buffer2[8]; onion *o = websocket_server_new(); onion_request *req = websocket_start_handshake(o); req->connection.listen_point->read = (lpreader_sig_t *) websocket_data_buffer_read; req->connection.listen_point->write = (lpwriter_sig_t *) websocket_data_buffer_write; onion_response *res = onion_response_new(req); onion_websocket *ws = onion_websocket_new(req, res); length = websocket_forge_close_packet((char **)&buffer); websocket_data_buffer_write(req, (char *)buffer, length); onion_connection_status ret = onion_websocket_call(ws); FAIL_IF(ret != -2); websocket_data_buffer_read(req, (char *)&buffer2, 8); FAIL_IF_NOT(buffer2[0] == 0x88); FAIL_IF_NOT(buffer2[1] == 0x02); FAIL_IF_NOT(buffer2[2] == 0x03); FAIL_IF_NOT(buffer2[3] == 0xE8); onion_websocket_free(ws); onion_request_free(req); onion_free(o); END_LOCAL(); }
void t03_websocket_server_receive_small_packet() { INIT_LOCAL(); int length = 0; char *buffer = NULL, buffer2[115]; memset(&ws_status, 0, sizeof(ws_status)); onion *o = websocket_server_new(); onion_request *req = websocket_start_handshake(o); req->connection.listen_point->read = (lpreader_sig_t *) websocket_data_buffer_read; onion_response *res = onion_response_new(req); onion_websocket *ws = onion_websocket_new(req, res); length = websocket_forge_small_packet((char **)&buffer); websocket_data_buffer_write(req, buffer, length); onion_websocket_read(ws, (char *)&buffer2, 120); buffer2[114] = '\0'; FAIL_IF_NOT_EQUAL_STR(buffer2, "Some UTF-8-encoded chars which will be cut at the 117th char so I write some gap-filling text with no meaning unti"); onion_websocket_free(ws); onion_request_free(req); onion_free(o); END_LOCAL(); }
/** * @short Deletes a request and all its data * @memberof onion_request_t */ void onion_request_free(onion_request *req) { ONION_DEBUG0("Free request %p", req); onion_dict_free(req->headers); if (req->connection.listen_point!=NULL && req->connection.listen_point->close) req->connection.listen_point->close(req); if (req->fullpath) onion_low_free(req->fullpath); if (req->GET) onion_dict_free(req->GET); if (req->POST) onion_dict_free(req->POST); if (req->FILES) { onion_dict_preorder(req->FILES, unlink_files, NULL); onion_dict_free(req->FILES); } if (req->session) { if (onion_dict_count(req->session)==0) onion_request_session_free(req); else { onion_sessions_save(req->connection.listen_point->server->sessions, req->session_id, req->session); onion_dict_free(req->session); // Not really remove, just dereference onion_low_free(req->session_id); } } if (req->data) onion_block_free(req->data); if (req->connection.cli_info) onion_low_free(req->connection.cli_info); if (req->websocket) onion_websocket_free(req->websocket); if (req->parser_data) { onion_low_free(req->parser_data); } if (req->cookies) onion_dict_free(req->cookies); if (req->free_list) { onion_ptr_list_foreach(req->free_list, onion_low_free); onion_ptr_list_free(req->free_list); } onion_low_free(req); }