tport 1.13.17
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 char *buffer;
96 char *bbuffer;
97 char *body;
98 char *uri;
99 size_t buflen;
100 size_t bbuflen;
101 ssize_t datalen;
102 char *payload;
103 ssize_t plen;
104 ssize_t rplen;
105 ssize_t packetlen;
106 SSL *ssl;
107 int handshake;
108 uint8_t down;
109 int secure;
110 uint8_t close_sock;
111 SSL_CTX *ssl_ctx;
112 int block;
113 int sanity;
114 int secure_established;
115 int logical_established;
116 int stay_open;
117 int x;
118 int ssl_io_error;
119 void *write_buffer;
120 size_t write_buffer_len;
121
122 ssize_t payload_size_max;
123} wsh_t;
124
125ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
126ssize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes);
127
128int establish_logical_layer(wsh_t *wsh);
129ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes, int block);
130ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
131ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
132ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
133void ws_set_global_payload_size_max(ssize_t bytes);
134int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock, int block, int stay_open);
135ssize_t ws_close(wsh_t *wsh, int16_t reason);
136void ws_destroy(wsh_t *wsh);
137void init_ssl(void);
138void deinit_ssl(void);
139int xp_errno(void);
140int xp_is_blocking(int errcode);
141void wss_log_errors(unsigned level, char const *s, unsigned long e);
142
143
144
145#ifndef _MSC_VER
146static inline uint64_t get_unaligned_uint64(const void *p)
147{
148 const struct { uint64_t d; } __attribute__((packed)) *pp = p;
149 return pp->d;
150}
151#endif
152
153#endif
SU_U64_T uint64_t
SU_S16_T int16_t
SU_U8_T uint8_t

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