lib/server.c: fix ipv6 support
[platform/upstream/libwebsockets.git] / lib / rewrite.c
1 #include "private-libwebsockets.h"
2
3
4 LWS_EXTERN struct lws_rewrite *
5 lws_rewrite_create(struct lws *wsi, hubbub_callback_t cb, const char *from, const char *to)
6 {
7         struct lws_rewrite *r = lws_malloc(sizeof(*r));
8
9         if (hubbub_parser_create("UTF-8", false, &r->parser) != HUBBUB_OK) {
10                 lws_free(r);
11
12                 return NULL;
13         }
14         r->from = from;
15         r->from_len = strlen(from);
16         r->to = to;
17         r->to_len = strlen(to);
18         r->params.token_handler.handler = cb;
19         r->wsi = wsi;
20         r->params.token_handler.pw = (void *)r;
21         if (hubbub_parser_setopt(r->parser, HUBBUB_PARSER_TOKEN_HANDLER,
22                                  &r->params) != HUBBUB_OK) {
23                 lws_free(r);
24
25                 return NULL;
26         }
27
28         return r;
29 }
30
31 LWS_EXTERN int
32 lws_rewrite_parse(struct lws_rewrite *r,
33                   const unsigned char *in, int in_len)
34 {
35         if (hubbub_parser_parse_chunk(r->parser, in, in_len) != HUBBUB_OK)
36                 return -1;
37
38         return 0;
39 }
40
41 LWS_EXTERN void
42 lws_rewrite_destroy(struct lws_rewrite *r)
43 {
44         hubbub_parser_destroy(r->parser);
45         lws_free(r);
46 }
47