1 module miniupnpc.upnpcommands; 2 3 import miniupnpc.upnpreplyparse; 4 import miniupnpc.portlistingparse; 5 6 /* MiniUPnPc return codes :*/ 7 enum UPNPCOMMAND_SUCCESS = 0; 8 enum UPNPCOMMAND_UNKNOWN_ERROR = -1; 9 enum UPNPCOMMAND_INVALID_ARGS = -2; 10 enum UPNPCOMMAND_HTTP_ERROR = -3; 11 12 extern(C) nothrow @nogc: 13 14 ulong UPNP_GetTotalBytesSent(const char* controlURL, 15 const char* servicetype); 16 17 ulong UPNP_GetTotalBytesReceived(const char* controlURL, 18 const char* servicetype); 19 20 ulong UPNP_GetTotalPacketsSent(const char* controlURL, 21 const char* servicetype); 22 23 ulong UPNP_GetTotalPacketsReceived(const char* controlURL, 24 const char* servicetype); 25 26 /* UPNP_GetStatusInfo() 27 * status and lastconnerror are 64 byte buffers 28 * Return values : 29 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR 30 * or a UPnP Error code*/ 31 int UPNP_GetStatusInfo(const char* controlURL, 32 const char* servicetype, 33 char* status, 34 uint* uptime, 35 char* lastconnerror); 36 37 /* UPNP_GetConnectionTypeInfo() 38 * argument connectionType is a 64 character buffer 39 * Return Values : 40 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR 41 * or a UPnP Error code*/ 42 int UPNP_GetConnectionTypeInfo(const char* controlURL, 43 const char* servicetype, 44 char* connectionType); 45 46 /* UPNP_GetExternalIPAddress() call the corresponding UPNP method. 47 * if the third arg is not null the value is copied to it. 48 * at least 16 bytes must be available 49 * 50 * Return values : 51 * 0 : SUCCESS 52 * NON ZERO : ERROR Either an UPnP error code or an unknown error. 53 * 54 * possible UPnP Errors : 55 * 402 Invalid Args - See UPnP Device Architecture section on Control. 56 * 501 Action Failed - See UPnP Device Architecture section on Control.*/ 57 int UPNP_GetExternalIPAddress(const char* controlURL, 58 const char* servicetype, 59 char* extIpAdd); 60 61 /* UPNP_GetLinkLayerMaxBitRates() 62 * call WANCommonInterfaceConfig:1#GetCommonLinkProperties 63 * 64 * return values : 65 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR 66 * or a UPnP Error Code.*/ 67 int UPNP_GetLinkLayerMaxBitRates(const char* controlURL, 68 const char* servicetype, 69 uint* bitrateDown, 70 uint* bitrateUp); 71 72 /* UPNP_AddPortMapping() 73 * if desc is NULL, it will be defaulted to "libminiupnpc" 74 * remoteHost is usually NULL because IGD don't support it. 75 * 76 * Return values : 77 * 0 : SUCCESS 78 * NON ZERO : ERROR. Either an UPnP error code or an unknown error. 79 * 80 * List of possible UPnP errors for AddPortMapping : 81 * errorCode errorDescription (short) - Description (long) 82 * 402 Invalid Args - See UPnP Device Architecture section on Control. 83 * 501 Action Failed - See UPnP Device Architecture section on Control. 84 * 715 WildCardNotPermittedInSrcIP - The source IP address cannot be 85 * wild-carded 86 * 716 WildCardNotPermittedInExtPort - The external port cannot be wild-carded 87 * 718 ConflictInMappingEntry - The port mapping entry specified conflicts 88 * with a mapping assigned previously to another client 89 * 724 SamePortValuesRequired - Internal and External port values 90 * must be the same 91 * 725 OnlyPermanentLeasesSupported - The NAT implementation only supports 92 * permanent lease times on port mappings 93 * 726 RemoteHostOnlySupportsWildcard - RemoteHost must be a wildcard 94 * and cannot be a specific IP address or DNS name 95 * 727 ExternalPortOnlySupportsWildcard - ExternalPort must be a wildcard and 96 * cannot be a specific port value*/ 97 int UPNP_AddPortMapping(const char* controlURL, const char* servicetype, 98 const char* extPort, 99 const char* inPort, 100 const char* inClient, 101 const char* desc, 102 const char* proto, 103 const char* remoteHost, 104 const char* leaseDuration); 105 106 /* UPNP_DeletePortMapping() 107 * Use same argument values as what was used for AddPortMapping(). 108 * remoteHost is usually NULL because IGD don't support it. 109 * Return Values : 110 * 0 : SUCCESS 111 * NON ZERO : error. Either an UPnP error code or an undefined error. 112 * 113 * List of possible UPnP errors for DeletePortMapping : 114 * 402 Invalid Args - See UPnP Device Architecture section on Control. 115 * 714 NoSuchEntryInArray - The specified value does not exist in the array*/ 116 int UPNP_DeletePortMapping(const char* controlURL, const char* servicetype, 117 const char* extPort, const char* proto, 118 const char* remoteHost); 119 120 /* UPNP_GetPortMappingNumberOfEntries() 121 * not supported by all routers*/ 122 int UPNP_GetPortMappingNumberOfEntries(const char* controlURL, 123 const char* servicetype, 124 uint* num); 125 126 /* UPNP_GetSpecificPortMappingEntry() 127 * retrieves an existing port mapping 128 * params : 129 * in extPort 130 * in proto 131 * out intClient (16 bytes) 132 * out intPort (6 bytes) 133 * out desc (80 bytes) 134 * out enabled (4 bytes) 135 * out leaseDuration (16 bytes) 136 * 137 * return value : 138 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR 139 * or a UPnP Error Code.*/ 140 int UPNP_GetSpecificPortMappingEntry(const char* controlURL, 141 const char* servicetype, 142 const char* extPort, 143 const char* proto, 144 char* intClient, 145 char* intPort, 146 char* desc, 147 char* enabled, 148 char* leaseDuration); 149 150 /* UPNP_GetGenericPortMappingEntry() 151 * params : 152 * in index 153 * out extPort (6 bytes) 154 * out intClient (16 bytes) 155 * out intPort (6 bytes) 156 * out protocol (4 bytes) 157 * out desc (80 bytes) 158 * out enabled (4 bytes) 159 * out rHost (64 bytes) 160 * out duration (16 bytes) 161 * 162 * return value : 163 * UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR 164 * or a UPnP Error Code. 165 * 166 * Possible UPNP Error codes : 167 * 402 Invalid Args - See UPnP Device Architecture section on Control. 168 * 713 SpecifiedArrayIndexInvalid - The specified array index is out of bounds 169 */ 170 int UPNP_GetGenericPortMappingEntry(const char* controlURL, 171 const char* servicetype, 172 const char* index, 173 char* extPort, 174 char* intClient, 175 char* intPort, 176 char* protocol, 177 char* desc, 178 char* enabled, 179 char* rHost, 180 char* duration); 181 182 /* UPNP_GetListOfPortMappings() Available in IGD v2 183 * 184 * 185 * Possible UPNP Error codes : 186 * 606 Action not Authorized 187 * 730 PortMappingNotFound - no port mapping is found in the specified range. 188 * 733 InconsistantParameters - NewStartPort and NewEndPort values are not 189 * consistent. 190 */ 191 int UPNP_GetListOfPortMappings(const char* controlURL, 192 const char* servicetype, 193 const char* startPort, 194 const char* endPort, 195 const char* protocol, 196 const char* numberOfPorts, 197 PortMappingParserData* data); 198 199 /* IGD:2, functions for service WANIPv6FirewallControl:1*/ 200 int UPNP_GetFirewallStatus(const char* controlURL, 201 const char* servicetype, 202 int* firewallEnabled, 203 int* inboundPinholeAllowed); 204 205 int UPNP_GetOutboundPinholeTimeout(const char* controlURL, const char* servicetype, 206 const char* remoteHost, 207 const char* remotePort, 208 const char* intClient, 209 const char* intPort, 210 const char* proto, 211 int* opTimeout); 212 213 int UPNP_AddPinhole(const char* controlURL, const char* servicetype, 214 const char* remoteHost, 215 const char* remotePort, 216 const char* intClient, 217 const char* intPort, 218 const char* proto, 219 const char* leaseTime, 220 char* uniqueID); 221 222 int UPNP_UpdatePinhole(const char* controlURL, const char* servicetype, 223 const char* uniqueID, 224 const char* leaseTime); 225 226 int UPNP_DeletePinhole(const char* controlURL, const char* servicetype, const char* uniqueID); 227 228 int UPNP_CheckPinholeWorking(const char* controlURL, const char* servicetype, 229 const char* uniqueID, int* isWorking); 230 231 int UPNP_GetPinholePackets(const char* controlURL, const char* servicetype, 232 const char* uniqueID, int* packets); 233