|
cwebs 0.2.1
WebSocket wire protocol
|
00001 #ifndef _owire_h__ 00002 #define _owire_h__ 00003 00004 // Copyright (c) 2011-2012, Andre Caron (andre.l.caron@gmail.com) 00005 // All rights reserved. 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are 00009 // met: 00010 // 00011 // Redistributions of source code must retain the above copyright 00012 // notice, this list of conditions and the following disclaimer. 00013 // 00014 // Redistributions in binary form must reproduce the above copyright 00015 // notice, this list of conditions and the following disclaimer in the 00016 // documentation and/or other materials provided with the distribution. 00017 // 00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00022 // HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00023 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00024 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00025 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00026 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00028 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 00037 #include "types.h" 00038 00039 #ifdef __cplusplus 00040 extern "C" { 00041 #endif 00042 00057 typedef uint64(*ws_owire_state) 00058 (struct ws_owire * wire, const uint8 * data, uint64 size); 00059 00063 enum ws_owire_error 00064 { 00068 ws_owire_eok, 00069 00072 ws_owire_enotready, 00073 }; 00074 00082 struct ws_owire 00083 { 00094 void(*accept_content) 00095 (struct ws_owire * wire, const void * data, uint64 size); 00096 00117 void(*rand)(struct ws_owire * wire, uint8 mask[4]); 00118 00125 void * baton; 00126 00136 void * prng; 00137 00149 enum ws_owire_error error; 00150 00162 uint64 auto_fragment; 00163 00172 int auto_mask; 00173 00179 uint8 data[14]; 00180 00189 uint64 used; 00190 00200 uint64 pass; 00201 00207 ws_owire_state state; 00208 }; 00209 00216 void ws_owire_init ( struct ws_owire * stream ); 00217 00224 void ws_owire_new_message ( struct ws_owire * stream ); 00225 00232 void ws_owire_end_message ( struct ws_owire * stream ); 00233 00245 void ws_owire_new_frame ( struct ws_owire * stream, uint64 size ); 00246 00254 void ws_owire_end_frame ( struct ws_owire * stream ); 00255 00263 void ws_owire_last ( struct ws_owire * stream ); 00264 00270 void ws_owire_eval ( struct ws_owire * stream, uint8 eval ); 00271 00287 void ws_owire_code ( struct ws_owire * stream, uint8 code ); 00288 00299 void ws_owire_mask ( struct ws_owire * stream ); 00300 00314 uint64 ws_owire_feed 00315 ( struct ws_owire * stream, const void * data, uint64 size ); 00316 00328 void ws_owire_ping ( struct ws_owire * stream ); 00329 00341 void ws_owire_pong ( struct ws_owire * stream ); 00342 00356 void ws_owire_text ( struct ws_owire * stream ); 00357 00365 void ws_owire_data ( struct ws_owire * stream ); 00366 00378 void ws_owire_kill ( struct ws_owire * stream ); 00379 00388 void ws_owire_put_text 00389 ( struct ws_owire * stream, const void * data, uint64 size ); 00390 00399 void ws_owire_put_data 00400 ( struct ws_owire * stream, const void * data, uint64 size ); 00401 00411 void ws_owire_put_ping 00412 ( struct ws_owire * stream, const void * data, uint64 size ); 00413 00423 void ws_owire_put_pong 00424 ( struct ws_owire * stream, const void * data, uint64 size ); 00425 00440 void ws_owire_put_kill 00441 ( struct ws_owire * stream, const void * data, uint64 size ); 00442 00443 #ifdef __cplusplus 00444 } 00445 #endif 00446 00447 #endif /* _owire_h__ */ 00448