DEADSOFTWARE

3a6f0834d64e7790cc3b691e28ace14081e0797a
[d2df-sdl.git] / src / lib / miniupnpc / miniupnpc.pas
1 {.$DEFINE LIBMINIUPNPC_WINDOZE_STATIC}
3 {$MODE OBJFPC}
4 {$PACKRECORDS C}
6 {$IFDEF WIN32}
7 {$DEFINE MSWINDOWS}
8 {$ENDIF}
10 {$LONGSTRINGS ON}
11 {$MACRO ON}
13 {$Z4} // Force four-byte enums
15 unit miniupnpc;
17 interface
19 {$IFDEF MSWINDOWS}
20 {$IFDEF LIBMINIUPNPC_WINDOZE_STATIC}
21 {$LINKLIB libminiupnpc.a}
22 {$LINKLIB libiphlpapi.a}
23 {$DEFINE MINIUPNPC_IMPL := cdecl; external}
24 {$ELSE}
25 {$DEFINE MINIUPNPC_IMPL := cdecl; external 'miniupnpc.dll'}
26 {$ENDIF}
27 {$ELSE}
28 {$DEFINE MINIUPNPC_IMPL := cdecl; external 'miniupnpc'}
29 {$ENDIF}
31 const MINIUPNPC_URL_MAXSIZE=128;
32 Type
33 PUPNPDev = ^TUPNPDev;
34 TUPNPDev = record
35 pNext:PUPNPDev;
36 descURL:pchar;
37 st:pchar;
38 scope_id:word;
39 buffer:array[0..1] of byte;
40 end;
42 PUPNPUrls = ^TUPNPUrls;
43 TUPNPUrls = record
44 controlURL:pchar;
45 ipcondescURL:pchar;
46 controlURL_CIF:pchar;
47 controlURL_6FC:pchar;
48 rootdescURL:pchar;
49 end;
50 TUrlStr = array [1..MINIUPNPC_URL_MAXSIZE] of char;
51 TIGDdatas_service = record
52 controlurl : TUrlStr;
53 eventsuburl: TUrlStr;
54 scpdurl: TUrlStr;
55 servicetype: TUrlStr;
56 //char devicetype[MINIUPNPC_URL_MAXSIZE];
57 end;
59 PIGDdatas = ^TIGDdatas;
60 TIGDdatas = record
61 cureltname: TUrlStr;
62 urlbase: TUrlStr;
63 presentationurl : TUrlStr;
64 level:integer;
65 //int state;
66 //"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"
67 CIF : TIGDdatas_service;
68 // "urn:schemas-upnp-org:service:WANIPConnection:1"
69 // "urn:schemas-upnp-org:service:WANPPPConnection:1"
70 first: TIGDdatas_service;
71 //if both WANIPConnection and WANPPPConnection are present
72 second: TIGDdatas_service;
73 //"urn:schemas-upnp-org:service:WANIPv6FirewallControl:1"
74 IPv6FC : TIGDdatas_service;
75 // tmp
76 tmp: TIGDdatas_service;
77 end;
79 (* upnpDiscover()
80 * discover UPnP devices on the network.
81 * The discovered devices are returned as a chained list.
82 * It is up to the caller to free the list with freeUPNPDevlist().
83 * delay (in millisecond) is the maximum time for waiting any device
84 * response.
85 * If available, device list will be obtained from MiniSSDPd.
86 * Default path for minissdpd socket will be used if minissdpdsock argument
87 * is NULL.
88 * If multicastif is not NULL, it will be used instead of the default
89 * multicast interface for sending SSDP discover packets.
90 * If sameport is not null, SSDP packets will be sent from the source port
91 * 1900 (same as destination port) otherwise system assign a source port. *)
92 function upnpDiscover(
93 delay:integer;
94 multicastif:pchar;
95 minissdpdsock:pchar;
96 sameport:integer;
97 IPV6:integer;
98 ttl:shortint;
99 error:pinteger):PUPNPDev; MINIUPNPC_IMPL;
102 (* UPNP_GetValidIGD() :
103 * return values :
104 * 0 = NO IGD found
105 * 1 = A valid connected IGD has been found
106 * 2 = A valid IGD has been found but it reported as
107 * not connected
108 * 3 = an UPnP device has been found but was not recognized as an IGD
110 * In any non zero return case, the urls and data structures
111 * passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
112 * free allocated memory.
113 *)
114 function UPNP_GetValidIGD(
115 devlist:PUPNPDev;
116 urls:PUPNPUrls;
117 data:PIGDdatas;
118 lanaddr:pchar;
119 lanaddrlen:integer):integer; MINIUPNPC_IMPL;
122 (* UPNP_GetExternalIPAddress() call the corresponding UPNP method.
123 * if the third arg is not null the value is copied to it.
124 * at least 16 bytes must be available
126 * Return values :
127 * 0 : SUCCESS
128 * NON ZERO : ERROR Either an UPnP error code or an unknown error.
129 *
130 * possible UPnP Errors :
131 * 402 Invalid Args - See UPnP Device Architecture section on Control.
132 * 501 Action Failed - See UPnP Device Architecture section on Control. *)
133 function UPNP_GetExternalIPAddress(
134 controlURL:pchar;
135 servicetype:pchar;
136 extIpAdd:pchar):integer; MINIUPNPC_IMPL;
139 (* UPNP_AddPortMapping()
140 * if desc is NULL, it will be defaulted to "libminiupnpc"
141 * remoteHost is usually NULL because IGD don't support it.
143 * Return values :
144 * 0 : SUCCESS
145 * NON ZERO : ERROR. Either an UPnP error code or an unknown error.
146 *
147 * List of possible UPnP errors for AddPortMapping :
148 * errorCode errorDescription (short) - Description (long)
149 * 402 Invalid Args - See UPnP Device Architecture section on Control.
150 * 501 Action Failed - See UPnP Device Architecture section on Control.
151 * 715 WildCardNotPermittedInSrcIP - The source IP address cannot be
152 * wild-carded
153 * 716 WildCardNotPermittedInExtPort - The external port cannot be wild-carded
154 * 718 ConflictInMappingEntry - The port mapping entry specified conflicts
155 * with a mapping assigned previously to another client
156 * 724 SamePortValuesRequired - Internal and External port values
157 * must be the same
158 * 725 OnlyPermanentLeasesSupported - The NAT implementation only supports
159 * permanent lease times on port mappings
160 * 726 RemoteHostOnlySupportsWildcard - RemoteHost must be a wildcard
161 * and cannot be a specific IP address or DNS name
162 * 727 ExternalPortOnlySupportsWildcard - ExternalPort must be a wildcard and
163 * cannot be a specific port value *)
165 function UPNP_AddPortMapping(
166 controlURL:pchar;
167 servicetype:pchar;
168 extPort:pchar;
169 inPort:pchar;
170 inClient:pchar;
171 desc:pchar;
172 proto:pchar;
173 remoteHost:pchar;
174 leaseDuration:pchar):integer; MINIUPNPC_IMPL;
176 (* UPNP_DeletePortMapping()
177 * Use same argument values as what was used for AddPortMapping().
178 * remoteHost is usually NULL because IGD don't support it.
179 * Return Values :
180 * 0 : SUCCESS
181 * NON ZERO : error. Either an UPnP error code or an undefined error.
183 * List of possible UPnP errors for DeletePortMapping :
184 * 402 Invalid Args - See UPnP Device Architecture section on Control.
185 * 714 NoSuchEntryInArray - The specified value does not exist in the array *)
187 function UPNP_DeletePortMapping(
188 controlURL:pchar;
189 servicetype:pchar;
190 extPort:pchar;
191 proto:pchar;
192 remoteHost:pchar):integer; MINIUPNPC_IMPL;
196 function UPNP_GetGenericPortMappingEntry(
197 const controlURL :pchar;
198 const servicetype:pchar;
199 index:pchar;
200 extPort:pchar;
201 intClient:pchar;
202 intPort:pchar;
203 protocol:pchar;
204 desc:pchar;
205 enabled:pchar;
206 rHost:pchar;
207 duration:pchar):integer; MINIUPNPC_IMPL;
209 procedure FreeUPNPUrls(urls: PUPNPUrls); MINIUPNPC_IMPL;
210 procedure freeUPNPDevlist(devl: PUPNPDev); MINIUPNPC_IMPL;
212 implementation
214 end.