chenqiyang
2021-08-27 6a63c4281fbe7e17103115320cd276397d733081
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
/*
mediastreamer2 library - modular sound and video processing and streaming
Copyright (C) 2012  Belledonne Communications
 
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
 
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.
 
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/
 
#ifndef _UPNP_IGD_H__
#define _UPNP_IGD_H__
 
#include <stdarg.h>
 
#if defined(_MSC_VER)
#define MS2_PUBLIC    __declspec(dllexport)
#else
#define MS2_PUBLIC
#endif
 
typedef enum _upnp_igd_print_level {
    UPNP_IGD_DEBUG = 0,
    UPNP_IGD_MESSAGE,
    UPNP_IGD_WARNING,
    UPNP_IGD_ERROR
} upnp_igd_print_level;
 
typedef enum _upnp_igd_ip_protocol {
    UPNP_IGD_IP_PROTOCOL_UDP = 0,
    UPNP_IGD_IP_PROTOCOL_TCP
} upnp_igd_ip_protocol;
 
typedef enum _upnp_igd_event {
    UPNP_IGD_EXTERNAL_IPADDRESS_CHANGED = 0,
    UPNP_IGD_NAT_ENABLED_CHANGED,
    UPNP_IGD_CONNECTION_STATUS_CHANGED,
    UPNP_IGD_PORT_MAPPING_ADD_SUCCESS,
    UPNP_IGD_PORT_MAPPING_ADD_FAILURE,
    UPNP_IGD_PORT_MAPPING_REMOVE_SUCCESS,
    UPNP_IGD_PORT_MAPPING_REMOVE_FAILURE,
    UPNP_IGD_DEVICE_ADDED = 100,
    UPNP_IGD_DEVICE_REMOVED,
} upnp_igd_event;
 
typedef struct _upnp_igd_port_mapping {
    upnp_igd_ip_protocol protocol;
 
    const char* local_host;
    int local_port;
 
    const char* remote_host;
    int remote_port;
 
    const char* description;
 
    void *cookie;
    int retvalue;
} upnp_igd_port_mapping;
 
typedef void (*upnp_igd_callback_function)(void *cookie, upnp_igd_event event, void *arg);
typedef void (*upnp_igd_print_function)(void *cookie, upnp_igd_print_level level, const char *fmt, va_list list);
 
typedef struct _upnp_igd_context upnp_igd_context;
 
MS2_PUBLIC upnp_igd_context* upnp_igd_create(upnp_igd_callback_function cb_fct, upnp_igd_print_function print_fct, const char* address, void *cookie);
MS2_PUBLIC int upnp_igd_start(upnp_igd_context*igd_ctxt);
int upnp_igd_is_started(upnp_igd_context *igd_ctxt);
int upnp_igd_stop(upnp_igd_context*igd_ctxt);
MS2_PUBLIC void upnp_igd_destroy(upnp_igd_context *igd_ctxt);
MS2_PUBLIC char *upnp_igd_get_local_ipaddress(upnp_igd_context *igd_ctxt);
MS2_PUBLIC const char *upnp_igd_get_device_id(upnp_igd_context *igd_ctxt);
MS2_PUBLIC const char *upnp_igd_get_device_name(upnp_igd_context *igd_ctxt);
MS2_PUBLIC const char *upnp_igd_get_device_model_name(upnp_igd_context *igd_ctxt);
MS2_PUBLIC const char *upnp_igd_get_device_model_number(upnp_igd_context *igd_ctxt);
MS2_PUBLIC const char *upnp_igd_get_external_ipaddress(upnp_igd_context *igd_ctxt);
MS2_PUBLIC const char *upnp_igd_get_connection_status(upnp_igd_context *igd_ctxt);
MS2_PUBLIC int upnp_igd_get_nat_enabled(upnp_igd_context *igd_ctxt);
 
MS2_PUBLIC int upnp_igd_add_port_mapping(upnp_igd_context *igd_ctxt, const upnp_igd_port_mapping *mapping);
MS2_PUBLIC int upnp_igd_delete_port_mapping(upnp_igd_context *igd_ctxt, const upnp_igd_port_mapping *mapping);
 
MS2_PUBLIC int upnp_igd_refresh(upnp_igd_context *igd_ctxt);
MS2_PUBLIC void upnp_igd_set_devices_timeout(upnp_igd_context *igd_ctxt, int seconds);
MS2_PUBLIC int upnp_igd_get_devices_timeout(upnp_igd_context *igd_ctxt);
 
#endif //_UPNP_IGD_H__