freeswitch/libs/sofia-sip/libsofia-sip-ua/tport/ws.h

115 lines
2.2 KiB
C
Raw Normal View History

2013-01-24 20:13:45 +00:00
#ifndef _WS_H
#define _WS_H
//#define WSS_STANDALONE 1
2013-01-24 20:13:45 +00:00
#define WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
#define B64BUFFLEN 1024
#include <sys/types.h>
2013-04-02 22:25:10 +00:00
#ifndef _MSC_VER
2013-01-24 20:13:45 +00:00
#include <arpa/inet.h>
#include <sys/wait.h>
2013-04-02 22:25:10 +00:00
#include <sys/socket.h>
#else
#pragma warning(disable:4996)
#endif
2013-01-24 20:13:45 +00:00
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
//#include "sha1.h"
#include <openssl/ssl.h>
2013-09-17 01:24:41 +00:00
#ifdef _MSC_VER
2013-10-23 04:23:48 +00:00
#define strncasecmp _strnicmp
#define snprintf _snprintf
2013-10-21 15:11:30 +00:00
#ifdef _WIN64
#define WS_SSIZE_T __int64
#elif _MSC_VER >= 1400
#define WS_SSIZE_T __int32 __w64
#else
#define WS_SSIZE_T __int32
#endif
2013-10-23 04:23:48 +00:00
typedef WS_SSIZE_T ssize_t;
2013-09-17 01:24:41 +00:00
#endif
2013-01-24 20:13:45 +00:00
2013-09-17 01:24:41 +00:00
struct ws_globals_s {
2013-01-24 20:13:45 +00:00
const SSL_METHOD *ssl_method;
SSL_CTX *ssl_ctx;
char cert[512];
char key[512];
};
2013-09-17 01:24:41 +00:00
extern struct ws_globals_s ws_globals;
2013-01-24 20:13:45 +00:00
typedef int ws_socket_t;
#define ws_sock_invalid -1
typedef enum {
WS_NONE = 0,
WS_NORMAL = 1000,
WS_PROTO_ERR = 1002,
WS_DATA_TOO_BIG = 1009
} ws_cause_t;
typedef enum {
WSOC_CONTINUATION = 0x0,
WSOC_TEXT = 0x1,
WSOC_BINARY = 0x2,
WSOC_CLOSE = 0x8,
WSOC_PING = 0x9,
WSOC_PONG = 0xA
} ws_opcode_t;
typedef struct wsh_s {
ws_socket_t sock;
char buffer[65536];
char wbuffer[65536];
2013-01-24 20:13:45 +00:00
size_t buflen;
2013-09-17 01:24:41 +00:00
ssize_t datalen;
ssize_t wdatalen;
2013-01-24 20:13:45 +00:00
char *payload;
2013-09-17 01:24:41 +00:00
ssize_t plen;
ssize_t rplen;
2013-01-24 20:13:45 +00:00
SSL *ssl;
int handshake;
uint8_t down;
int secure;
2013-06-27 19:04:13 +00:00
uint8_t close_sock;
2013-01-24 20:13:45 +00:00
} wsh_t;
2013-09-17 01:24:41 +00:00
ssize_t ws_send_buf(wsh_t *wsh, ws_opcode_t oc);
ssize_t ws_feed_buf(wsh_t *wsh, void *data, size_t bytes);
2013-01-26 03:19:22 +00:00
2013-09-17 01:24:41 +00:00
ssize_t ws_raw_read(wsh_t *wsh, void *data, size_t bytes);
ssize_t ws_raw_write(wsh_t *wsh, void *data, size_t bytes);
ssize_t ws_read_frame(wsh_t *wsh, ws_opcode_t *oc, uint8_t **data);
ssize_t ws_write_frame(wsh_t *wsh, ws_opcode_t oc, void *data, size_t bytes);
int ws_init(wsh_t *wsh, ws_socket_t sock, SSL_CTX *ssl_ctx, int close_sock);
2013-09-17 01:24:41 +00:00
ssize_t ws_close(wsh_t *wsh, int16_t reason);
2013-06-26 16:43:54 +00:00
void ws_destroy(wsh_t *wsh);
2013-01-24 20:13:45 +00:00
void init_ssl(void);
void deinit_ssl(void);
2013-10-18 19:00:28 +00:00
int xp_errno(void);
int xp_is_blocking(int errcode);
2013-01-24 20:13:45 +00:00
2013-10-21 15:11:30 +00:00
2013-04-02 22:25:10 +00:00
#ifndef _MSC_VER
2013-01-24 20:13:45 +00:00
static inline uint64_t get_unaligned_uint64(const void *p)
{
const struct { uint64_t d; } __attribute__((packed)) *pp = p;
return pp->d;
}
2013-04-02 22:25:10 +00:00
#endif
2013-01-24 20:13:45 +00:00
#endif