TUIO C++ Developer API
WebSockSender.h
1 /*
2  TUIO C++ Library
3  Copyright (c) 2009-2017 Martin Kaltenbrunner <martin@tuio.org>
4  WebSockSender (c) 2015 Florian Echtler <floe@butterbrot.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 3.0 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library.
18 */
19 
20 #ifndef INCLUDED_WEBSOCKSENDER_H
21 #define INCLUDED_WEBSOCKSENDER_H
22 
23 #if defined(_MSC_VER) && _MSC_VER < 1900
24 #include <Windows.h>
25 #include <stdio.h>
26 #define snprintf c99_snprintf
27 #define vsnprintf c99_vsnprintf
28 
29 __inline int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
30 {
31  int count = -1;
32 
33  if (size != 0)
34  count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
35  if (count == -1)
36  count = _vscprintf(format, ap);
37 
38  return count;
39 }
40 
41 __inline int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
42 {
43  int count;
44  va_list ap;
45 
46  va_start(ap, format);
47  count = c99_vsnprintf(outBuf, size, format, ap);
48  va_end(ap);
49 
50  return count;
51 }
52 
53 #endif
54 
55 
56 /* All of these macros assume use on a 32-bit variable.
57  Additionally, SWAP assumes we're little-endian. */
58 #define SWAP(a) ((((a) >> 24) & 0x000000ff) | (((a) >> 8) & 0x0000ff00) | \
59 (((a) << 8) & 0x00ff0000) | (((a) << 24) & 0xff000000))
60 #define ROL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
61 #define ROR(a, b) ROL((a), (32 - (b)))
62 #define SHA1_HASH_SIZE (160/8)
63 
64 #include "TcpSender.h"
65 #include <stdio.h>
66 #include <stdint.h>
67 #include <string.h>
68 #include <vector>
69 
70 namespace TUIO {
71 
78  class LIBDECL WebSockSender : public TcpSender {
79 
80  public:
81 
85  WebSockSender();
86 
92  WebSockSender(int port);
93 
97  virtual ~WebSockSender() {}
98 
105  bool sendOscPacket (osc::OutboundPacketStream *bundle);
106 
112  void newClient( int tcp_client );
113 
114  const char* tuio_type() { return "TUIO/WEB"; }
115  private:
116 
117  void sha1( uint8_t digest[SHA1_HASH_SIZE], const uint8_t* inbuf, size_t length );
118  std::string base64( uint8_t* buffer, size_t size );
119  };
120 }
121 #endif /* INCLUDED_WEBSOCKSENDER_H */
virtual ~WebSockSender()
Definition: WebSockSender.h:97
Definition: WebSockSender.h:78
Definition: FlashSender.h:166
Definition: TcpSender.h:48