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

93 lines
1.8 KiB
C
Raw Normal View History

2013-01-24 20:13:45 +00:00
#ifndef _WS_H
#define _WS_H
#define MAXLEN 0x10000
#define WEBSOCKET_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
#define B64BUFFLEN 1024
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/wait.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <assert.h>
#include <errno.h>
//#include "sha1.h"
#include <openssl/ssl.h>
struct globals_s {
const SSL_METHOD *ssl_method;
SSL_CTX *ssl_ctx;
char cert[512];
char key[512];
};
extern struct globals_s globals;
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;
2013-01-26 03:19:22 +00:00
char *wbuffer;
2013-01-24 20:13:45 +00:00
size_t buflen;
ssize_t datalen;
2013-01-26 03:19:22 +00:00
ssize_t wdatalen;
2013-01-24 20:13:45 +00:00
char *payload;
ssize_t plen;
ssize_t rplen;
SSL *ssl;
int handshake;
uint8_t down;
int secure;
2013-01-26 03:19:22 +00:00
unsigned close_sock:1;
unsigned :0;
2013-01-24 20:13:45 +00:00
} wsh_t;
2013-01-26 03:19:22 +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-24 20:13:45 +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);
2013-01-26 03:19:22 +00:00
int ws_init(wsh_t *wsh, ws_socket_t sock, size_t buflen, SSL_CTX *ssl_ctx, int close_sock);
2013-01-24 20:13:45 +00:00
ssize_t ws_close(wsh_t *wsh, int16_t reason);
void init_ssl(void);
void deinit_ssl(void);
static inline uint64_t get_unaligned_uint64(const void *p)
{
const struct { uint64_t d; } __attribute__((packed)) *pp = p;
return pp->d;
}
#endif