File: websocket.h

package info (click to toggle)
rtpengine 13.5.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,676 kB
  • sloc: ansic: 86,764; perl: 59,422; python: 3,193; sh: 1,030; makefile: 693; asm: 211
file content (59 lines) | stat: -rw-r--r-- 1,514 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef __WEBSOCKET_H__
#define __WEBSOCKET_H__

#include <stdbool.h>

#include "str.h"

struct websocket_conn;
struct websocket_message;
enum lws_write_protocol;
struct janus_session;

typedef const char *(*websocket_message_func_t)(struct websocket_message *);


struct websocket_message {
	struct websocket_conn *wc;
	char *uri;
	enum {
		M_UNKNOWN = 0,
		M_WEBSOCKET,
		M_GET,
		M_POST,
		M_OPTIONS,
	} method;
	enum {
		CT_UNKNOWN = 0,
		CT_JSON,
		CT_NG,
		CT_TEXT,
	} content_type;
	GString *body;

	websocket_message_func_t func;
};


int websocket_init(void);
void websocket_start(void);
void websocket_stop(void);

// adds data to output buffer (can be null) and triggers specified response: http or binary websocket
//void websocket_write_http_len(struct websocket_conn *wc, const char *msg, size_t len);
//void websocket_write_http(struct websocket_conn *wc, const char *msg);
void websocket_write_text(struct websocket_conn *wc, const char *msg);
//void websocket_write_binary(struct websocket_conn *wc, const char *msg, size_t len);

// single shot HTTP response
void websocket_http_complete(struct websocket_conn *wc, int status, const char *content_type,
		ssize_t content_length, const char *content);

// write HTTP response headers
void websocket_http_response(struct websocket_conn *wc, int status, const char *content_type,
		ssize_t content_length);

// mark a janus session as owned by this transport
void websocket_conn_add_session(struct websocket_conn *, struct janus_session *);

#endif