DEADSOFTWARE

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