Statistics
| Branch: | Revision:

peerstreamer-src / src / router.h @ 9eb656e7

History | View | Annotate | Download (1.82 KB)

1 9eb656e7 Luca Baldesi
/*******************************************************************
2
* PeerStreamer-ng is a P2P video streaming application exposing a ReST
3
* interface.
4
* Copyright (C) 2016 Luca Baldesi <luca.baldesi@unitn.it>
5
*
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU Affero General Public License for more details.
15
*
16
* You should have received a copy of the GNU Affero General Public License
17
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
*******************************************************************/
19
20
#ifndef _ROUTER_H_ 
21
#define _ROUTER_H_ 
22
23
#include <stdint.h>
24
25
#include <mongoose.h>
26
27
28
typedef void (*http_handle_t)(struct mg_connection *nc, struct http_message *hm);
29
30
/** Create a router object with initial capability <size>. 
31
 *  Capability is automatically increased when needed.
32
 *  Returns: the newly created structure.
33
 **/
34
struct router * router_create(uint32_t size);
35
36
void router_destroy(struct router ** r);
37
38
/** Add a new route handler.
39
 *        <method>: HTTP verb, e.g., GET, POST,...
40
 *        <regex>: path matching regex, e.g., /users/[a-d]+/posts/[0-9]+
41
 *        Returns: 0 on success
42
 **/
43
uint8_t router_add_route(struct router *r, const char * method, const char * regex, http_handle_t handler);
44
45
/** Launch the handler whose handler matches the message URL.
46
 *  Returns: 0 on success (handler found and launched)
47
 **/
48
uint8_t router_handle(const struct router * r, struct mg_connection *nc, struct http_message *hm);
49
50
#endif