]> rtime.felk.cvut.cz Git - coffee/mt-apps.git/blob - mt_server.h
mt_server: Use "%s" format string in syslog()
[coffee/mt-apps.git] / mt_server.h
1 #ifndef MT_SERVER_H
2 #define MT_SERVER_H
3
4 #include <ev.h>
5 #include <libwebsockets.h>
6
7 // set these two according to your data
8 // rx buf size must be >= permessage-deflate rx size
9 #define MT_PROTOCOL_RX_BUFFER_SIZE 128
10 #define INPUT_LINE_LENGTH          MT_PROTOCOL_RX_BUFFER_SIZE
11
12 #if defined(SIM)
13 #define HTTP_PORT       8080                    // listen here
14 #define HTTP_ORIGIN     "html" // where the html files are
15 #else
16 #define HTTP_PORT       80                    // listen here
17 #define HTTP_ORIGIN     "/usr/share/mtserver" // where the html files are
18 #endif
19 #define HTTP_MOUNTPOINT "/"                   // mountpoint URL
20 #define HTTP_DEFAULT    "index.html"          // default filename
21
22 typedef struct node {
23     char *line;
24     struct node *next;
25 } node;
26
27 typedef struct list {
28     struct node *first;
29     struct node *last;
30 } list;
31
32 typedef struct ev_io_ws {
33     ev_io w;                     // input watcher
34     struct lws_context *context;
35     list *lines;
36     char *text;                  // input buffer pointer
37     char *pos;                   // input buffer current position pointer
38 } ev_io_ws;
39
40 typedef struct mt_server_t {
41     struct lws_context *context;
42     ev_io_ws fd_watcher;         // input watcher
43 } mt_server_t;
44
45 // init self, add it to loop and make it read data from fd
46 // return 0 on success, -1 otherwise
47 int mt_server_init(mt_server_t *self, struct ev_loop *loop, int fd);
48
49 // gett drunc an kil sellf
50 void mt_server_deinit(mt_server_t *self);
51
52 #endif