HomePort
hpd_tcpd.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Aalborg University. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are
5  * permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this list of
8  * conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11  * of conditions and the following disclaimer in the documentation and/or other materials
12  * provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY Aalborg University ''AS IS'' AND ANY EXPRESS OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Aalborg University OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * The views and conclusions contained in the software and documentation are those of the
25  * authors and should not be interpreted as representing official policies, either expressed
26  */
27 
28 #ifndef HOMEPORT_HPD_TCPD_H
29 #define HOMEPORT_HPD_TCPD_H
30 
31 #include <stddef.h>
32 #include <stdarg.h>
33 #include <hpd/hpd_types.h>
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 // Structs
41 typedef struct hpd_tcpd hpd_tcpd_t;
44 
45 typedef enum hpd_tcpd_return {
49 
50 /**********************************************************************
51  * Callbacks *
52  **********************************************************************/
53 
55  void **conn_ctx);
56 typedef hpd_tcpd_return_t (*hpd_tcpd_data_f)(hpd_tcpd_t *instance, hpd_tcpd_conn_t *conn, void *ws_ctx, void **conn_ctx,
57  const char *buf, size_t len);
58 
96  int timeout;
98  size_t max_data_size;
102  void *tcpd_ctx;
103 };
104 
113 #define HPD_TCPD_SETTINGS_DEFAULT { \
114  .port = HPD_TCPD_P_HTTP, \
115  .timeout = 15, \
116  .retry_delay = 5, \
117  .max_data_size = 1024, \
118  .on_connect = NULL, \
119  .on_receive = NULL, \
120  .on_disconnect = NULL, \
121  .tcpd_ctx = NULL }
122 
123 // Webserver functions
129 
130 // Client functions
131 hpd_error_t hpd_tcpd_conn_get_ip(hpd_tcpd_conn_t *conn, const char **ip);
133 hpd_error_t hpd_tcpd_conn_sendf(hpd_tcpd_conn_t *conn, const char *fmt, ...);
134 hpd_error_t hpd_tcpd_conn_vsendf(hpd_tcpd_conn_t *conn, const char *fmt, va_list vp);
137 
138 #ifdef __cplusplus
139 }
140 #endif
141 
142 #endif // HOMEPORT_TCPD_H
143 
Instance of a tcpd.
Definition: tcpd_intern.h:45
enum hpd_tcpd_port hpd_tcpd_port_t
struct up * instance
hpd_tcpd_nodata_f on_connect
Definition: hpd_tcpd.h:99
hpd_error_t hpd_tcpd_create(hpd_tcpd_t **tcpd, hpd_tcpd_settings_t *settings, const hpd_module_t *context, hpd_ev_loop_t *loop)
Create new tcpd instance.
Definition: tcpd.c:269
hpd_tcpd_port_t port
Port number.
Definition: hpd_tcpd.h:95
struct hp_settings settings
hpd_error_t hpd_tcpd_conn_keep_open(hpd_tcpd_conn_t *conn)
Disable timeout on connection.
Definition: tcpd.c:479
hpd_error_t hpd_tcpd_conn_get_ip(hpd_tcpd_conn_t *conn, const char **ip)
Get the IP address of the client.
Definition: tcpd.c:459
hpd_error_t hpd_tcpd_stop(hpd_tcpd_t *tcpd)
Stop an already running tcpd.
Definition: tcpd.c:428
hpd_tcpd_nodata_f on_disconnect
Definition: hpd_tcpd.h:101
size_t max_data_size
Definition: hpd_tcpd.h:98
hpd_tcpd_return
Definition: hpd_tcpd.h:45
hpd_error_t hpd_tcpd_start(hpd_tcpd_t *tcpd)
Start the tcpd.
Definition: tcpd.c:318
enum hpd_error hpd_error_t
Definition: hpd_types.h:167
hpd_tcpd_return_t(* hpd_tcpd_nodata_f)(hpd_tcpd_t *instance, hpd_tcpd_conn_t *conn, void *ws_ctx, void **conn_ctx)
Definition: hpd_tcpd.h:54
All data to represent a connection.
Definition: tcpd_intern.h:56
hpd_error_t hpd_tcpd_conn_sendf(hpd_tcpd_conn_t *conn, const char *fmt,...)
Send message on connection.
Definition: tcpd.c:503
static struct ev_loop * loop
hpd_error_t hpd_tcpd_conn_kill(hpd_tcpd_conn_t *conn)
Kill and clean up after a connection.
Definition: tcpd.c:608
hpd_error_t hpd_tcpd_conn_close(hpd_tcpd_conn_t *conn)
Close a connection, after the remaining data has been sent.
Definition: tcpd.c:581
hpd_tcpd_data_f on_receive
Definition: hpd_tcpd.h:100
hpd_error_t hpd_tcpd_conn_vsendf(hpd_tcpd_conn_t *conn, const char *fmt, va_list vp)
Send message on connection.
Definition: tcpd.c:534
struct ev_loop hpd_ev_loop_t
Definition: hpd_types.h:51
hpd_error_t hpd_tcpd_destroy(hpd_tcpd_t *tcpd)
Destroy tcpd and free used memory.
Definition: tcpd.c:297
Settings struct for tcpd.
Definition: hpd_tcpd.h:94
hpd_tcpd_return_t(* hpd_tcpd_data_f)(hpd_tcpd_t *instance, hpd_tcpd_conn_t *conn, void *ws_ctx, void **conn_ctx, const char *buf, size_t len)
Definition: hpd_tcpd.h:56
enum hpd_tcpd_return hpd_tcpd_return_t