1/* $Id: miniupnpc.h,v 1.38 2014/11/17 09:41:33 nanard Exp $ */
2/* Project: miniupnp
3 * http://miniupnp.free.fr/
4 * Author: Thomas Bernard
5 * Copyright (c) 2005-2014 Thomas Bernard
6 * This software is subjects to the conditions detailed
7 * in the LICENCE file provided within this distribution */
8#ifndef MINIUPNPC_H_INCLUDED
9#define MINIUPNPC_H_INCLUDED
10
11#include "declspec.h"
12#include "igd_desc_parse.h"
13
14/* error codes : */
15#define UPNPDISCOVER_SUCCESS (0)
16#define UPNPDISCOVER_UNKNOWN_ERROR (-1)
17#define UPNPDISCOVER_SOCKET_ERROR (-101)
18#define UPNPDISCOVER_MEMORY_ERROR (-102)
19
20/* versions : */
21#define MINIUPNPC_VERSION	"1.9.20141128"
22#define MINIUPNPC_API_VERSION	12
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28/* Structures definitions : */
29struct UPNParg { const char * elt; const char * val; };
30
31char *
32simpleUPnPcommand(int, const char *, const char *,
33                  const char *, struct UPNParg *,
34                  int *);
35
36struct UPNPDevInfo {
37        char hostname[65];
38        char type[32];
39        char friendlyName[32];
40        char iconUrl[128];
41};
42
43struct UPNPDev {
44	struct UPNPDev * pNext;
45	char * descURL;
46	char * st;
47	unsigned int scope_id;
48	char buffer[2];
49	struct UPNPDevInfo DevInfo;
50};
51
52/* upnpDiscover()
53 * discover UPnP devices on the network.
54 * The discovered devices are returned as a chained list.
55 * It is up to the caller to free the list with freeUPNPDevlist().
56 * delay (in millisecond) is the maximum time for waiting any device
57 * response.
58 * If available, device list will be obtained from MiniSSDPd.
59 * Default path for minissdpd socket will be used if minissdpdsock argument
60 * is NULL.
61 * If multicastif is not NULL, it will be used instead of the default
62 * multicast interface for sending SSDP discover packets.
63 * If sameport is not null, SSDP packets will be sent from the source port
64 * 1900 (same as destination port) otherwise system assign a source port. */
65MINIUPNP_LIBSPEC struct UPNPDev *
66upnpDiscover(int delay, const char * multicastif,
67             const char * minissdpdsock, int sameport,
68             int ipv6,
69             int * error);
70
71MINIUPNP_LIBSPEC struct UPNPDev *
72upnpDiscoverAll(int delay, const char * multicastif,
73                const char * minissdpdsock, int sameport,
74                int ipv6,
75                int * error);
76
77MINIUPNP_LIBSPEC struct UPNPDev *
78upnpDiscoverDevice(const char * device, int delay, const char * multicastif,
79                const char * minissdpdsock, int sameport,
80                int ipv6,
81                int * error);
82
83MINIUPNP_LIBSPEC struct UPNPDev *
84upnpDiscoverDevices(const char * const deviceTypes[],
85                    int delay, const char * multicastif,
86                    const char * minissdpdsock, int sameport,
87                    int ipv6,
88                    int * error);
89
90/* freeUPNPDevlist()
91 * free list returned by upnpDiscover() */
92MINIUPNP_LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);
93
94/* parserootdesc() :
95 * parse root XML description of a UPnP device and fill the IGDdatas
96 * structure. */
97MINIUPNP_LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *);
98
99/* structure used to get fast access to urls
100 * controlURL: controlURL of the WANIPConnection
101 * ipcondescURL: url of the description of the WANIPConnection
102 * controlURL_CIF: controlURL of the WANCommonInterfaceConfig
103 * controlURL_6FC: controlURL of the WANIPv6FirewallControl
104 */
105struct UPNPUrls {
106	char * controlURL;
107	char * ipcondescURL;
108	char * controlURL_CIF;
109	char * controlURL_6FC;
110	char * rootdescURL;
111};
112
113/* UPNP_GetValidIGD() :
114 * return values :
115 *     0 = NO IGD found
116 *     1 = A valid connected IGD has been found
117 *     2 = A valid IGD has been found but it reported as
118 *         not connected
119 *     3 = an UPnP device has been found but was not recognized as an IGD
120 *
121 * In any non zero return case, the urls and data structures
122 * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
123 * free allocated memory.
124 */
125MINIUPNP_LIBSPEC int
126UPNP_GetValidIGD(struct UPNPDev * devlist,
127                 struct UPNPUrls * urls,
128		 struct IGDdatas * data,
129		 char * lanaddr, int lanaddrlen);
130
131/* UPNP_GetIGDFromUrl()
132 * Used when skipping the discovery process.
133 * return value :
134 *   0 - Not ok
135 *   1 - OK */
136MINIUPNP_LIBSPEC int
137UPNP_GetIGDFromUrl(const char * rootdescurl,
138                   struct UPNPUrls * urls,
139                   struct IGDdatas * data,
140                   char * lanaddr, int lanaddrlen);
141
142MINIUPNP_LIBSPEC void
143GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *,
144            const char *, unsigned int);
145
146MINIUPNP_LIBSPEC void
147FreeUPNPUrls(struct UPNPUrls *);
148
149/* return 0 or 1 */
150MINIUPNP_LIBSPEC int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *);
151
152
153#ifdef __cplusplus
154}
155#endif
156
157#endif
158
159