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