| 1 |
|
| #pragma once |
| 2 |
|
| #include <xs.h> |
| 3 |
|
| #include <xs/protocol/http.h> |
| 4 |
|
| #include <panda/protocol/websocket.h> |
| 5 |
|
| |
| 6 |
|
| namespace xs { namespace protocol { namespace websocket { |
| 7 |
|
| |
| 8 |
|
| using namespace panda::protocol::websocket; |
| 9 |
|
| |
| 10 |
|
| struct XSFrameIterator : FrameIterator { |
| 11 |
|
| XSFrameIterator (Parser* parser, const FrameSP& start_frame) : FrameIterator(parser, start_frame), nexted(false) { parser->retain(); } |
| 12 |
|
| XSFrameIterator (const XSFrameIterator& oth) : FrameIterator(oth), nexted(oth.nexted) { parser->retain(); } |
| 13 |
|
| XSFrameIterator (const FrameIterator& oth) : FrameIterator(oth), nexted(false) { parser->retain(); } |
| 14 |
|
| |
| 15 |
|
| FrameSP next () { |
| 16 |
|
| if (nexted) operator++(); |
| 17 |
|
| else nexted = true; |
| 18 |
|
| return cur; |
| 19 |
|
| } |
| 20 |
|
| |
| 21 |
|
| ~XSFrameIterator () { parser->release(); } |
| 22 |
|
| private: |
| 23 |
|
| bool nexted; |
| 24 |
|
| }; |
| 25 |
|
| |
| 26 |
|
| struct XSMessageIterator : MessageIterator { |
| 27 |
|
| XSMessageIterator (Parser* parser, const MessageSP& start_msg) : MessageIterator(parser, start_msg), nexted(false) { parser->retain(); } |
| 28 |
|
| XSMessageIterator (const XSMessageIterator& oth) : MessageIterator(oth), nexted(oth.nexted) { parser->retain(); } |
| 29 |
|
| XSMessageIterator (const MessageIterator& oth) : MessageIterator(oth), nexted(false) { parser->retain(); } |
| 30 |
|
| |
| 31 |
|
| MessageSP next () { |
| 32 |
|
| if (nexted) operator++(); |
| 33 |
|
| else nexted = true; |
| 34 |
|
| return cur; |
| 35 |
|
| } |
| 36 |
|
| |
| 37 |
|
| ~XSMessageIterator () { parser->release(); } |
| 38 |
|
| private: |
| 39 |
|
| bool nexted; |
| 40 |
|
| }; |
| 41 |
|
| |
| 42 |
|
| struct XSFrameSender : FrameSender { |
| 43 |
|
| XSFrameSender (FrameSender&& fb): FrameSender(std::move(fb)) { |
| 44 |
|
| // keep link to make XSFrameSender perl-safe |
| 45 |
|
| _parser.retain(); |
| 46 |
|
| } |
| 47 |
|
| ~XSFrameSender () { _parser.release(); } |
| 48 |
|
| }; |
| 49 |
|
| |
| 50 |
|
| void av_to_header_values (const Array& av, HeaderValues* vals); |
| 51 |
|
| Array header_values_to_av (const HeaderValues& vals); |
| 52 |
|
| |
| 53 |
|
| ConnectRequestSP make_request (const Hash& params, const ConnectRequestSP& = {}); |
| 54 |
|
| ConnectResponseSP make_response (const Hash& params, const ConnectResponseSP& = {}); |
| 55 |
|
| |
| 56 |
|
| void parser_config_in (Parser::Config&, const Hash&); |
| 57 |
|
| Hash parser_config_out (const Parser::Config& cfg); |
| 58 |
|
| void deflate_config_in (DeflateExt::Config&, const Hash&); |
| 59 |
|
| Sv deflate_config_out (const DeflateExt::Config&); |
| 60 |
|
| |
| 61 |
|
| }}} |
| 62 |
|
| |
| 63 |
|
| namespace xs { |
| 64 |
|
| |
| 65 |
|
| template <class TYPE> |
| 66 |
|
| struct Typemap<panda::protocol::websocket::Parser*, TYPE> : TypemapObject<panda::protocol::websocket::Parser*, TYPE, ObjectTypeRefcntPtr, ObjectStorageMG> {}; |
| 67 |
|
| |
| 68 |
|
| template <class TYPE> |
| 69 |
|
| struct Typemap<panda::protocol::websocket::ClientParser*, TYPE> : Typemap<panda::protocol::websocket::Parser*, TYPE> { |
| 70 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::ClientParser"; } |
| 71 |
|
| }; |
| 72 |
|
| |
| 73 |
|
| template <class TYPE> |
| 74 |
|
| struct Typemap<panda::protocol::websocket::ServerParser*, TYPE> : Typemap<panda::protocol::websocket::Parser*, TYPE> { |
| 75 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::ServerParser"; } |
| 76 |
|
| }; |
| 77 |
|
| |
| 78 |
|
| template <class TYPE> |
| 79 |
|
| struct Typemap<panda::protocol::websocket::ConnectRequest*, TYPE> : Typemap<panda::protocol::http::Request*, TYPE> { |
| 80 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::ConnectRequest"; } |
| 81 |
|
| }; |
| 82 |
|
| |
| 83 |
|
| template <class TYPE> |
| 84 |
|
| struct Typemap<panda::protocol::websocket::ConnectRequestSP, panda::iptr<TYPE>> : Typemap<TYPE*> { |
| 85 |
|
| using Super = Typemap<TYPE*>; |
| 86 |
|
| static panda::iptr<TYPE> in (Sv arg) { |
| 87 |
|
| if (!arg.is_object_ref()) arg = Super::default_stash().call("new", arg); |
| 88 |
|
| return Super::in(arg); |
| 89 |
|
| } |
| 90 |
|
| }; |
| 91 |
|
| |
| 92 |
|
| template <class TYPE> |
| 93 |
|
| struct Typemap<panda::protocol::websocket::ConnectResponse*, TYPE> : Typemap<panda::protocol::http::Response*, TYPE> { |
| 94 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::ConnectResponse"; } |
| 95 |
|
| }; |
| 96 |
|
| |
| 97 |
|
| template <class TYPE> |
| 98 |
|
| struct Typemap<panda::protocol::websocket::ConnectResponseSP, panda::iptr<TYPE>> : Typemap<TYPE*> { |
| 99 |
|
| using Super = Typemap<TYPE*>; |
| 100 |
|
| static panda::iptr<TYPE> in (Sv arg) { |
| 101 |
|
| if (!arg.is_object_ref()) arg = Super::default_stash().call("new", arg); |
| 102 |
|
| return Super::in(arg); |
| 103 |
|
| } |
| 104 |
|
| }; |
| 105 |
|
| |
| 106 |
|
| template <class TYPE> |
| 107 |
|
| struct Typemap<panda::protocol::websocket::Frame*, TYPE> : TypemapObject<panda::protocol::websocket::Frame*, TYPE, ObjectTypeRefcntPtr, ObjectStorageMG> { |
| 108 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::Frame"; } |
| 109 |
|
| }; |
| 110 |
|
| |
| 111 |
|
| template <class TYPE> |
| 112 |
|
| struct Typemap<panda::protocol::websocket::Message*, TYPE> : TypemapObject<panda::protocol::websocket::Message*, TYPE, ObjectTypeRefcntPtr, ObjectStorageMG> { |
| 113 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::Message"; } |
| 114 |
|
| }; |
| 115 |
|
| |
| 116 |
|
| template <class TYPE> |
| 117 |
|
| struct Typemap<xs::protocol::websocket::XSFrameIterator*, TYPE> : TypemapObject<xs::protocol::websocket::XSFrameIterator*, TYPE, ObjectTypePtr, ObjectStorageMG> { |
| 118 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::FrameIterator"; } |
| 119 |
|
| }; |
| 120 |
|
| |
| 121 |
|
| template <class TYPE> |
| 122 |
|
| struct Typemap<xs::protocol::websocket::XSMessageIterator*, TYPE> : TypemapObject<xs::protocol::websocket::XSMessageIterator*, TYPE, ObjectTypePtr, ObjectStorageMG> { |
| 123 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::MessageIterator"; } |
| 124 |
|
| }; |
| 125 |
|
| |
| 126 |
|
| template <class TYPE> |
| 127 |
|
| struct Typemap<xs::protocol::websocket::XSFrameSender*, TYPE> : TypemapObject<xs::protocol::websocket::XSFrameSender*, TYPE, ObjectTypePtr, ObjectStorageMG> { |
| 128 |
|
| static std::string package () { return "Protocol::WebSocket::Fast::FrameSender"; } |
| 129 |
|
| }; |
| 130 |
|
| |
| 131 |
|
| template <class TYPE> struct Typemap<panda::protocol::websocket::DeflateExt::Config, TYPE> : TypemapBase<panda::protocol::websocket::DeflateExt::Config, TYPE> { |
| 132 |
0 |
| static TYPE in (SV* arg) { |
| 133 |
0 |
| TYPE cfg; |
| 134 |
0 |
▶ | xs::protocol::websocket::deflate_config_in(cfg, arg); |
Branch: 2 branches
| Branch | True | False | Total |
| xs::protocol::websocket::deflate_config_in(cfg, arg); |
0 |
0 |
0 |
| xs::protocol::websocket::deflate_config_in(cfg, arg); |
0 |
0 |
0 |
|
| 135 |
0 |
| return cfg; |
| 136 |
|
| } |
| 137 |
|
| |
| 138 |
|
| static Sv out (TYPE var, const Sv& = Sv()) { return xs::protocol::websocket::deflate_config_out(var); } |
| 139 |
|
| }; |
| 140 |
|
| |
| 141 |
|
| template <class TYPE> struct Typemap<panda::protocol::websocket::Parser::Config, TYPE> : TypemapBase<panda::protocol::websocket::Parser::Config, TYPE> { |
| 142 |
|
| static TYPE in (SV* arg) { |
| 143 |
|
| TYPE cfg; |
| 144 |
|
| xs::protocol::websocket::parser_config_in(cfg, arg); |
| 145 |
|
| return cfg; |
| 146 |
|
| } |
| 147 |
|
| |
| 148 |
|
| static Sv out (TYPE var, const Sv& = Sv()) { return Ref::create(xs::protocol::websocket::parser_config_out(var)); } |
| 149 |
|
| }; |
| 150 |
|
| |
| 151 |
|
| template <> struct Typemap<panda::protocol::websocket::IsFinal> : TypemapBase<panda::protocol::websocket::IsFinal> { |
| 152 |
|
| static panda::protocol::websocket::IsFinal in (SV* arg) { |
| 153 |
|
| return SvTRUE(arg) ? panda::protocol::websocket::IsFinal::YES : panda::protocol::websocket::IsFinal::NO; |
| 154 |
|
| } |
| 155 |
|
| }; |
| 156 |
|
| } |