cwebs 0.2
WebSocket wire protocol.
code/owire.h
Go to the documentation of this file.
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 
00043 typedef uint64(*ws_owire_state)
00044     (struct ws_owire*,const uint8*,uint64);
00045 
00046 enum ws_owire_error
00047 {
00048     ws_owire_eok,
00049     ws_owire_enotready,
00050 };
00051 
00055 struct ws_owire
00056 {
00057     // event callbacks.
00058     void(*accept_content)(struct ws_owire*,const void*,uint64);
00059     void(*rand)(struct ws_owire*,uint8 mask[4]);
00060 
00061     // for use by callbacks.
00062     void * baton;
00063     void * prng;
00064 
00065     // read-only fields.
00066     enum ws_owire_error error;
00067 
00068     // public fields.
00069     uint64 auto_fragment;
00070     int auto_mask;
00071 
00072     // internal state.
00073     uint8 data[14];
00074     uint64 used;
00075     uint64 pass;
00076     ws_owire_state state;
00077 };
00078 
00079 void ws_owire_init ( struct ws_owire * stream );
00080 
00081 void ws_owire_new_message ( struct ws_owire * stream );
00082 void ws_owire_end_message ( struct ws_owire * stream );
00083 
00084 void ws_owire_new_frame ( struct ws_owire * stream, uint64 size );
00085 void ws_owire_end_frame ( struct ws_owire * stream );
00086 
00087 void ws_owire_last ( struct ws_owire * stream );
00088 void ws_owire_eval ( struct ws_owire * stream, uint8 eval );
00089 void ws_owire_code ( struct ws_owire * stream, uint8 code );
00090 void ws_owire_mask ( struct ws_owire * stream );
00091 uint64 ws_owire_feed
00092     ( struct ws_owire * stream, const void * data, uint64 size );
00093 
00094   // Follow with calls to _feed(), _end_frame(), etc.
00095 void ws_owire_ping ( struct ws_owire * stream );
00096 void ws_owire_pong ( struct ws_owire * stream );
00097 void ws_owire_text ( struct ws_owire * stream );
00098 void ws_owire_data ( struct ws_owire * stream );
00099 void ws_owire_kill ( struct ws_owire * stream );
00100 
00101   // emit full frames in a single bundle.
00102 void ws_owire_put_text
00103     ( struct ws_owire * stream, const void * data, uint64 size );
00104 void ws_owire_put_data
00105     ( struct ws_owire * stream, const void * data, uint64 size );
00106 void ws_owire_put_ping
00107     ( struct ws_owire * stream, const void * data, uint64 size );
00108 void ws_owire_put_pong
00109     ( struct ws_owire * stream, const void * data, uint64 size );
00110 void ws_owire_put_kill
00111     ( struct ws_owire * stream, const void * data, uint64 size );
00112 
00113 #ifdef __cplusplus
00114 }
00115 #endif
00116 
00117 #endif /* _owire_h__ */
00118 
 All Classes Files Functions