Electroneum
miniupnpc-libevent.h
Go to the documentation of this file.
1 /* $Id: miniupnpc-libevent.h,v 1.13 2015/07/22 13:48:37 nanard Exp $ */
2 /* miniupnpc-libevent
3  * Copyright (c) 2008-2015, Thomas BERNARD <miniupnp@free.fr>
4  * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
17 #ifndef MINIUPNPC_LIBEVENT_H_INCLUDED
18 #define MINIUPNPC_LIBEVENT_H_INCLUDED
19 
20 #include <event2/event.h>
21 
22 #include "declspec.h"
23 #include "upnpreplyparse.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #define MINIUPNPC_LIBEVENT_API_VERSION 1
30 
31 #define UPNPC_OK 0
32 #define UPNPC_ERR_INVALID_ARGS (-1)
33 #define UPNPC_ERR_SOCKET_FAILED (-2)
34 #define UPNPC_ERR_BIND_FAILED (-3)
35 #define UPNPC_ERR_REQ_IN_PROGRESS (-4)
36 
37 #define UPNPC_ERR_NO_DEVICE_FOUND (-100)
38 #define UPNPC_ERR_ROOT_DESC_ERROR (-101)
39 #define UPNPC_ERR_NOT_IGD (-102)
40 #define UPNPC_ERR_NOT_CONNECTED (-103)
41 
42 /* device->state masks */
43 #define UPNPC_DEVICE_SOAP_REQ (0x0001)
44 #define UPNPC_DEVICE_GETSTATUS (0x0002)
45 #define UPNPC_DEVICE_CONNECTED (0x4000)
46 #define UPNPC_DEVICE_READY (0x8000)
47 
49 typedef struct upnpc upnpc_t;
50 
51 typedef void(* upnpc_callback_fn)(int, upnpc_t *, upnpc_device_t *, void *);
52 #ifdef ENABLE_UPNP_EVENTS
53 typedef void(* upnpc_event_callback_fn)(upnpc_t *, upnpc_device_t *, void *, const char *, const char *, const char *);
54 #endif /* ENABLE_UPNP_EVENTS */
55 
56 struct upnpc_device {
59  char * root_desc_location;
60  struct evhttp_connection * desc_conn;
61  char * control_cif_url;
62  char * event_cif_url;
64  char * control_conn_url;
67  struct evhttp_connection * soap_conn;
69  unsigned int state;
70 #ifdef ENABLE_UPNP_EVENTS
71  char * event_conn_sid;
72 #endif /* ENABLE_UPNP_EVENTS */
73 };
74 
75 struct upnpc {
76  struct event_base * base;
77  evutil_socket_t ssdp_socket;
78  struct event * ev_ssdp_recv;
79  struct event * ev_ssdp_writable;
84  void * cb_data;
85 #ifdef ENABLE_UPNP_EVENTS
86  struct evhttp * http_server;
87  upnpc_event_callback_fn value_changed_cb;
88 #endif /* ENABLE_UPNP_EVENTS */
89  char * local_address;
91  unsigned char ttl;
92 };
93 
94 int upnpc_init(upnpc_t * p, struct event_base * base, const char * multicastif,
95  upnpc_callback_fn ready_cb, upnpc_callback_fn soap_cb, void * cb_data);
96 
97 int upnpc_set_local_address(upnpc_t * p, const char * address, uint16_t port);
98 
99 #ifdef ENABLE_UPNP_EVENTS
100 int upnpc_set_event_callback(upnpc_t * p, upnpc_event_callback_fn cb);
101 #endif /* ENABLE_UPNP_EVENTS */
102 
103 int upnpc_start(upnpc_t * p);
104 
105 int upnpc_finalize(upnpc_t * p);
106 
107 #ifdef ENABLE_UPNP_EVENTS
108 int upnpc_event_subscribe(upnpc_device_t * p);
109 #endif /* ENABLE_UPNP_EVENTS */
110 
112 
114 
116  const char * remote_host, unsigned short ext_port,
117  unsigned short int_port, const char * int_client,
118  const char * proto, const char * description,
119  unsigned int lease_duration);
120 
122  const char * remote_host, unsigned short ext_port,
123  const char * proto);
124 
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif /* MINIUPNPC_LIBEVENT_H_INCLUDED */
132 
int upnpc_finalize(upnpc_t *p)
struct evhttp_connection * soap_conn
int upnpc_init(upnpc_t *p, struct event_base *base, const char *multicastif, upnpc_callback_fn ready_cb, upnpc_callback_fn soap_cb, void *cb_data)
upnpc_callback_fn ready_cb
struct event_base * base
char * conn_service_type
void(* upnpc_callback_fn)(int, upnpc_t *, upnpc_device_t *, void *)
unsigned short uint16_t
Definition: stdint.h:125
upnpc_callback_fn soap_cb
upnpc_device_t * next
char * control_cif_url
unsigned int state
struct NameValueParserData soap_response_data
upnpc_device_t * devices
struct event * ev_ssdp_recv
evutil_socket_t ssdp_socket
unsigned char ttl
void * cb_data
int upnpc_get_link_layer_max_rate(upnpc_device_t *p)
struct event * ev_ssdp_writable
char * local_address
char * control_conn_url
struct evhttp_connection * desc_conn
boost::endian::big_uint16_t port
Definition: socks.cpp:60
uint16_t local_port
int upnpc_set_local_address(upnpc_t *p, const char *address, uint16_t port)
char * root_desc_location
int upnpc_delete_port_mapping(upnpc_device_t *p, const char *remote_host, unsigned short ext_port, const char *proto)
int upnpc_start(upnpc_t *p)
int upnpc_add_port_mapping(upnpc_device_t *p, const char *remote_host, unsigned short ext_port, unsigned short int_port, const char *int_client, const char *proto, const char *description, unsigned int lease_duration)
const char * address
Definition: multisig.cpp:37
int upnpc_get_status_info(upnpc_device_t *p)
int upnpc_get_external_ip_address(upnpc_device_t *p)
int discover_device_index