tport 1.13.18
Loading...
Searching...
No Matches
ws.h
1#ifndef _WS_H
2#define _WS_H
3
4#include "tport_internal.h"
5
6//#define WSS_STANDALONE 1
7
8#define WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
9#define B64BUFFLEN 1024
10
11#include <sys/types.h>
12#ifndef _MSC_VER
13#include <arpa/inet.h>
14#include <sys/wait.h>
15#include <sys/socket.h>
16#include <unistd.h>
17#else
18#pragma warning(disable:4996)
19#endif
20#include <string.h>
21#include <string.h>
22#include <stdint.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <assert.h>
26#include <errno.h>
27//#include "sha1.h"
28#include <openssl/ssl.h>
29#include <openssl/err.h>
30
31#if defined(_MSC_VER) || defined(__APPLE__) || defined(__FreeBSD__) || (defined(__SVR4) && defined(__sun))
32#define __bswap_64(x) \
33 x = (x>>56) | \
34 ((x<<40) & 0x00FF000000000000) | \
35 ((x<<24) & 0x0000FF0000000000) | \
36 ((x<<8) & 0x000000FF00000000) | \
37 ((x>>8) & 0x00000000FF000000) | \
38 ((x>>24) & 0x0000000000FF0000) | \
39 ((x>>40) & 0x000000000000FF00) | \
40 (x<<56)
41#endif
42#ifdef _MSC_VER
43#ifndef strncasecmp
44#define strncasecmp _strnicmp
45#endif
46#if _MSC_VER < 1900
47#define snprintf _snprintf
48#endif
49#ifdef _WIN64
50#define WS_SSIZE_T __int64
51#elif _MSC_VER >= 1400
52#define WS_SSIZE_T __int32 __w64
53#else
54#define WS_SSIZE_T __int32
55#endif
56typedef WS_SSIZE_T ssize_t;
57#endif
58
59
60struct ws_globals_s {
61 const SSL_METHOD *ssl_method;
62 SSL_CTX *ssl_ctx;
63 char cert[512];
64 char key[512];
65};
66
67//extern struct ws_globals_s ws_globals;
68
69#ifndef WIN32
70typedef int ws_socket_t;
71#else
72typedef SOCKET ws_socket_t;
73#endif
74#define ws_sock_invalid (ws_socket_t)-1
75
76
77typedef enum {
78 WS_NONE = 0,
79 WS_NORMAL = 1000,
80 WS_PROTO_ERR = 1002,
81 WS_DATA_TOO_BIG = 1009
82} ws_cause_t;
83
84typedef enum {
85 WSOC_CONTINUATION = 0x0,
86 WSOC_TEXT = 0x1,
87 WSOC_BINARY = 0x2,
88 WSOC_CLOSE = 0x8,
89 WSOC_PING = 0x9,
90 WSOC_PONG = 0xA
91} ws_opcode_t;
92
93typedef struct wsh_s {
94 ws_socket_t sock;
95 /* buffer/bbuffer are allocated as buflen+1 / bbuflen+1; the trailing
96 * byte is reserved as a NUL terminator slot. buflen/bbuflen track
97 * usable content length, not allocation size. */
98 char *buffer;
99 char *bbuffer;
100 char *body;
101 char *uri;
102 size_t buflen;
103 size_t bbuflen;
104 ssize_t datalen;
105 char *payload;
106 ssize_t plen;
107 ssize_t rplen;
108 ssize_t packetlen;
109 SSL *ssl;
110 int handshake;
111 uint8_t down;
112 int secure;
113 uint8_t close_sock;
114 SSL_CTX *ssl_ctx;
115 int block;
116 int sanity;
117 int secure_established;
118 int logical_established;
119 int stay_open;
120 int x;
121 int ssl_io_error;
122 void *write_buffer;
123 size_t write_buffer_len;
124
125 ssize_t payload_size_max;
126} wsh_t;
127
128ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
129ssize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes);
130
131int establish_logical_layer(wsh_t *wsh);
132ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, int block);
133ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
134ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
135ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
136void ws_set_global_payload_size_max(ssize_t bytes);
137int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open);
138ssize_t ws_close(wsh_t *wsh, int16_t reason);
139void ws_destroy(wsh_t *wsh);
140void init_ssl(void);
141void deinit_ssl(void);
142int xp_errno(void);
143int xp_is_blocking(int errcode);
144void wss_log_errors(unsigned level, char const *s, unsigned long e);
145
146
147
148#ifndef _MSC_VER
149static inline uint64_t get_unaligned_uint64(const void *p)
150{
151 const struct { uint64_t d; } __attribute__((packed)) *pp = p;
152 return pp->d;
153}
154#endif
155
156#endif
SU_U64_T uint64_t
SU_S16_T int16_t
SU_U8_T uint8_t

Sofia-SIP 1.13.18 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.