|
cwebs 0.2
WebSocket wire protocol.
|
00001 #ifndef _iwire_h__ 00002 #define _iwire_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 00043 struct ws_iwire; 00044 00045 typedef uint64(*ws_iwire_state) 00046 (struct ws_iwire*,const uint8*,uint64); 00047 00051 struct ws_iwire 00052 { 00053 // event callbacks. 00054 void(*new_message)(struct ws_iwire*); 00055 void(*end_message)(struct ws_iwire*); 00056 void(*new_fragment)(struct ws_iwire*,uint64); 00057 void(*end_fragment)(struct ws_iwire*); 00058 void(*accept_content)(struct ws_iwire*,const void*,uint64); 00059 00060 // for use by callbacks. 00061 void * baton; 00062 00063 // read-only fields. 00064 int code; 00065 int eval; 00066 int last; 00067 int usem; 00068 int good; 00069 00070 // internal state. 00071 ws_iwire_state state; 00072 uint8 data[8]; 00073 uint64 size; 00074 uint8 mask[4]; 00075 uint64 used; 00076 uint64 pass; 00077 }; 00078 00079 void ws_iwire_init ( struct ws_iwire * stream ); 00080 00081 uint64 ws_iwire_feed 00082 ( struct ws_iwire * stream, const void * data, uint64 size ); 00083 00084 int ws_iwire_mask ( const struct ws_iwire * stream ); 00085 int ws_iwire_last ( const struct ws_iwire * stream ); 00086 00087 int ws_iwire_ping ( const struct ws_iwire * stream ); 00088 int ws_iwire_pong ( const struct ws_iwire * stream ); 00089 00090 int ws_iwire_text ( const struct ws_iwire * stream ); 00091 int ws_iwire_data ( const struct ws_iwire * stream ); 00092 00093 int ws_iwire_dead ( const struct ws_iwire * stream ); 00094 00095 #ifdef __cplusplus 00096 } 00097 #endif 00098 00099 #endif /* _iwire_h__ */ 00100