1 /* 2 * Copyright (c) 2014 - 2019 Oleh Kulykov <info@resident.name> 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a copy 5 * of this software and associated documentation files (the "Software"), to deal 6 * in the Software without restriction, including without limitation the rights 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 * copies of the Software, and to permit persons to whom the Software is 9 * furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 * THE SOFTWARE. 21 */ 22 23 24 #ifndef __RWS_FRAME_H__ 25 #define __RWS_FRAME_H__ 1 26 27 #include "librws.h" 28 #include "rws_common.h" 29 30 typedef enum _rws_opcode { 31 rws_opcode_continuation = 0x0, // %x0 denotes a continuation frame 32 rws_opcode_text_frame = 0x1, // %x1 denotes a text frame 33 rws_opcode_binary_frame = 0x2, // %x2 denotes a binary frame 34 rws_opcode_connection_close = 0x8, // %x8 denotes a connection close 35 rws_opcode_ping = 0x9, // %x9 denotes a ping 36 rws_opcode_pong = 0xA // %xA denotes a pong 37 } rws_opcode; 38 39 typedef enum _rws_binary { 40 rws_binary_start, 41 rws_binary_continue, 42 rws_binary_finish 43 } rws_binary; 44 45 typedef struct _rws_frame_struct { 46 void * data; 47 size_t data_size; 48 rws_opcode opcode; 49 unsigned char mask[4]; 50 rws_bool is_masked; 51 rws_bool is_finished; 52 unsigned char header_size; 53 } _rws_frame; 54 55 size_t rws_check_recv_frame_size(const void * data, const size_t data_size); 56 57 _rws_frame * rws_frame_create_with_recv_data(const void * data, const size_t data_size); 58 59 // data - should be null, and setted by newly created. 'data' & 'data_size' can be null 60 void rws_frame_fill_with_send_data(_rws_frame * f, const void * data, const size_t data_size, rws_bool is_finish); 61 62 void litews_frame_fill_with_send_bin_data(_rws_frame * f, const void * data, const size_t data_size, rws_binary bin_type); 63 64 // combine datas of 2 frames. combined is 'to' 65 void rws_frame_combine_datas(_rws_frame * to, _rws_frame * from); 66 67 _rws_frame * rws_frame_create(void); 68 69 void rws_frame_delete(_rws_frame * f); 70 71 void rws_frame_delete_clean(_rws_frame ** f); 72 73 #endif 74