use name server from query in SOAP responses

to be finished :)
This commit is contained in:
Thomas Bernard 2015-09-15 00:02:56 +02:00
parent fde90d221b
commit a4b97cf105
2 changed files with 63 additions and 42 deletions

View File

@ -1,5 +1,8 @@
$Id: Changelog.txt,v 1.400 2015/08/26 07:32:31 nanard Exp $ $Id: Changelog.txt,v 1.400 2015/08/26 07:32:31 nanard Exp $
2015/09/15:
use name server from query in SOAP responses
2015/08/25: 2015/08/25:
better bind socket to right interface(s), better bind socket to right interface(s),
using struct ip_mreqn, SO_BINDTODEVICE using struct ip_mreqn, SO_BINDTODEVICE

View File

@ -65,21 +65,32 @@ BuildSendAndCloseSoapResp(struct upnphttp * h,
} }
static void static void
GetConnectionTypeInfo(struct upnphttp * h, const char * action) GetConnectionTypeInfo(struct upnphttp * h, const char * action, const char * ns)
{ {
#if 0
static const char resp[] = static const char resp[] =
"<u:GetConnectionTypeInfoResponse " "<u:GetConnectionTypeInfoResponse "
"xmlns:u=\"" SERVICE_TYPE_WANIPC "\">" "xmlns:u=\"" SERVICE_TYPE_WANIPC "\">"
"<NewConnectionType>IP_Routed</NewConnectionType>" "<NewConnectionType>IP_Routed</NewConnectionType>"
"<NewPossibleConnectionTypes>IP_Routed</NewPossibleConnectionTypes>" "<NewPossibleConnectionTypes>IP_Routed</NewPossibleConnectionTypes>"
"</u:GetConnectionTypeInfoResponse>"; "</u:GetConnectionTypeInfoResponse>";
UNUSED(action); #endif
static const char resp[] =
"<u:%sResponse "
"xmlns:u=\"%s\">"
"<NewConnectionType>IP_Routed</NewConnectionType>"
"<NewPossibleConnectionTypes>IP_Routed</NewPossibleConnectionTypes>"
"</u:%sResponse>";
char body[512];
int bodylen;
BuildSendAndCloseSoapResp(h, resp, sizeof(resp)-1); bodylen = snprintf(body, sizeof(body), resp,
action, ns, action);
BuildSendAndCloseSoapResp(h, body, bodylen);
} }
static void static void
GetTotalBytesSent(struct upnphttp * h, const char * action) GetTotalBytesSent(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -95,13 +106,13 @@ GetTotalBytesSent(struct upnphttp * h, const char * action)
r = getifstats(ext_if_name, &data); r = getifstats(ext_if_name, &data);
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1", action, ns,
r<0?0:data.obytes, action); r<0?0:data.obytes, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
static void static void
GetTotalBytesReceived(struct upnphttp * h, const char * action) GetTotalBytesReceived(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -117,13 +128,13 @@ GetTotalBytesReceived(struct upnphttp * h, const char * action)
r = getifstats(ext_if_name, &data); r = getifstats(ext_if_name, &data);
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1", action, ns,
r<0?0:data.ibytes, action); r<0?0:data.ibytes, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
static void static void
GetTotalPacketsSent(struct upnphttp * h, const char * action) GetTotalPacketsSent(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -139,13 +150,13 @@ GetTotalPacketsSent(struct upnphttp * h, const char * action)
r = getifstats(ext_if_name, &data); r = getifstats(ext_if_name, &data);
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1", action, ns,/*"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1",*/
r<0?0:data.opackets, action); r<0?0:data.opackets, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
static void static void
GetTotalPacketsReceived(struct upnphttp * h, const char * action) GetTotalPacketsReceived(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -161,13 +172,13 @@ GetTotalPacketsReceived(struct upnphttp * h, const char * action)
r = getifstats(ext_if_name, &data); r = getifstats(ext_if_name, &data);
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1", action, ns,
r<0?0:data.ipackets, action); r<0?0:data.ipackets, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
static void static void
GetCommonLinkProperties(struct upnphttp * h, const char * action) GetCommonLinkProperties(struct upnphttp * h, const char * action, const char * ns)
{ {
/* WANAccessType : set depending on the hardware : /* WANAccessType : set depending on the hardware :
* DSL, POTS (plain old Telephone service), Cable, Ethernet */ * DSL, POTS (plain old Telephone service), Cable, Ethernet */
@ -200,7 +211,7 @@ GetCommonLinkProperties(struct upnphttp * h, const char * action)
status = "Down"; status = "Down";
} }
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1", action, ns,
wan_access_type, wan_access_type,
upstream_bitrate, downstream_bitrate, upstream_bitrate, downstream_bitrate,
status, action); status, action);
@ -208,7 +219,7 @@ GetCommonLinkProperties(struct upnphttp * h, const char * action)
} }
static void static void
GetStatusInfo(struct upnphttp * h, const char * action) GetStatusInfo(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp[] = static const char resp[] =
"<u:%sResponse " "<u:%sResponse "
@ -229,13 +240,13 @@ GetStatusInfo(struct upnphttp * h, const char * action)
status = get_wan_connection_status_str(ext_if_name); status = get_wan_connection_status_str(ext_if_name);
uptime = (time(NULL) - startup_time); uptime = (time(NULL) - startup_time);
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, SERVICE_TYPE_WANIPC, action, ns, /*SERVICE_TYPE_WANIPC,*/
status, (long)uptime, action); status, (long)uptime, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
static void static void
GetNATRSIPStatus(struct upnphttp * h, const char * action) GetNATRSIPStatus(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp[] = static const char resp[] =
"<u:GetNATRSIPStatusResponse " "<u:GetNATRSIPStatusResponse "
@ -256,7 +267,7 @@ GetNATRSIPStatus(struct upnphttp * h, const char * action)
} }
static void static void
GetExternalIPAddress(struct upnphttp * h, const char * action) GetExternalIPAddress(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp[] = static const char resp[] =
"<u:%sResponse " "<u:%sResponse "
@ -296,7 +307,7 @@ GetExternalIPAddress(struct upnphttp * h, const char * action)
} }
#endif #endif
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, SERVICE_TYPE_WANIPC, action, ns, /*SERVICE_TYPE_WANIPC,*/
ext_ip_addr, action); ext_ip_addr, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
@ -304,7 +315,7 @@ GetExternalIPAddress(struct upnphttp * h, const char * action)
/* AddPortMapping method of WANIPConnection Service /* AddPortMapping method of WANIPConnection Service
* Ignored argument : NewEnabled */ * Ignored argument : NewEnabled */
static void static void
AddPortMapping(struct upnphttp * h, const char * action) AddPortMapping(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -464,7 +475,7 @@ AddPortMapping(struct upnphttp * h, const char * action)
/* AddAnyPortMapping was added in WANIPConnection v2 */ /* AddAnyPortMapping was added in WANIPConnection v2 */
static void static void
AddAnyPortMapping(struct upnphttp * h, const char * action) AddAnyPortMapping(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
static const char resp[] = static const char resp[] =
@ -574,7 +585,7 @@ AddAnyPortMapping(struct upnphttp * h, const char * action)
{ {
case 0: /* success */ case 0: /* success */
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, SERVICE_TYPE_WANIPC, action, ns, /*SERVICE_TYPE_WANIPC,*/
eport, action); eport, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
break; break;
@ -590,7 +601,7 @@ AddAnyPortMapping(struct upnphttp * h, const char * action)
} }
static void static void
GetSpecificPortMappingEntry(struct upnphttp * h, const char * action) GetSpecificPortMappingEntry(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -672,7 +683,7 @@ GetSpecificPortMappingEntry(struct upnphttp * h, const char * action)
} }
static void static void
DeletePortMapping(struct upnphttp * h, const char * action) DeletePortMapping(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -766,7 +777,7 @@ DeletePortMapping(struct upnphttp * h, const char * action)
/* DeletePortMappingRange was added in IGD spec v2 */ /* DeletePortMappingRange was added in IGD spec v2 */
static void static void
DeletePortMappingRange(struct upnphttp * h, const char * action) DeletePortMappingRange(struct upnphttp * h, const char * action, const char * ns)
{ {
int r = -1; int r = -1;
static const char resp[] = static const char resp[] =
@ -833,7 +844,7 @@ DeletePortMappingRange(struct upnphttp * h, const char * action)
} }
static void static void
GetGenericPortMappingEntry(struct upnphttp * h, const char * action) GetGenericPortMappingEntry(struct upnphttp * h, const char * action, const char * ns)
{ {
int r; int r;
@ -904,7 +915,7 @@ GetGenericPortMappingEntry(struct upnphttp * h, const char * action)
int bodylen; int bodylen;
char body[2048]; char body[2048];
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, SERVICE_TYPE_WANIPC, rhost, action, ns, /*SERVICE_TYPE_WANIPC,*/ rhost,
(unsigned int)eport, protocol, (unsigned int)iport, iaddr, desc, (unsigned int)eport, protocol, (unsigned int)iport, iaddr, desc,
leaseduration, action); leaseduration, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
@ -915,7 +926,7 @@ GetGenericPortMappingEntry(struct upnphttp * h, const char * action)
/* GetListOfPortMappings was added in the IGD v2 specification */ /* GetListOfPortMappings was added in the IGD v2 specification */
static void static void
GetListOfPortMappings(struct upnphttp * h, const char * action) GetListOfPortMappings(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp_start[] = static const char resp_start[] =
"<u:%sResponse " "<u:%sResponse "
@ -1019,7 +1030,7 @@ http://www.upnp.org/schemas/gw/WANIPConnection-v2.xsd">
return; return;
} }
bodylen = snprintf(body, bodyalloc, resp_start, bodylen = snprintf(body, bodyalloc, resp_start,
action, SERVICE_TYPE_WANIPC); action, ns/*SERVICE_TYPE_WANIPC*/);
if(bodylen < 0) if(bodylen < 0)
{ {
SoapError(h, 501, "ActionFailed"); SoapError(h, 501, "ActionFailed");
@ -1093,7 +1104,7 @@ http://www.upnp.org/schemas/gw/WANIPConnection-v2.xsd">
#ifdef ENABLE_L3F_SERVICE #ifdef ENABLE_L3F_SERVICE
static void static void
SetDefaultConnectionService(struct upnphttp * h, const char * action) SetDefaultConnectionService(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp[] = static const char resp[] =
"<u:SetDefaultConnectionServiceResponse " "<u:SetDefaultConnectionServiceResponse "
@ -1128,11 +1139,11 @@ SetDefaultConnectionService(struct upnphttp * h, const char * action)
} }
static void static void
GetDefaultConnectionService(struct upnphttp * h, const char * action) GetDefaultConnectionService(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp[] = static const char resp[] =
"<u:%sResponse " "<u:%sResponse "
"xmlns:u=\"urn:schemas-upnp-org:service:Layer3Forwarding:1\">" "xmlns:u=\"%s\">"
"<NewDefaultConnectionService>%s:WANConnectionDevice:1," "<NewDefaultConnectionService>%s:WANConnectionDevice:1,"
SERVICE_ID_WANIPC "</NewDefaultConnectionService>" SERVICE_ID_WANIPC "</NewDefaultConnectionService>"
"</u:%sResponse>"; "</u:%sResponse>";
@ -1143,20 +1154,21 @@ GetDefaultConnectionService(struct upnphttp * h, const char * action)
int bodylen; int bodylen;
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, uuidvalue_wcd, action); action, ns, uuidvalue_wcd, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
#endif #endif
/* Added for compliance with WANIPConnection v2 */ /* Added for compliance with WANIPConnection v2 */
static void static void
SetConnectionType(struct upnphttp * h, const char * action) SetConnectionType(struct upnphttp * h, const char * action, const char * ns)
{ {
#ifdef UPNP_STRICT #ifdef UPNP_STRICT
const char * connection_type; const char * connection_type;
#endif /* UPNP_STRICT */ #endif /* UPNP_STRICT */
struct NameValueParserData data; struct NameValueParserData data;
UNUSED(action); UNUSED(action);
UNUSED(ns);
ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data); ParseNameValue(h->req_buf + h->req_contentoff, h->req_contentlen, &data);
#ifdef UPNP_STRICT #ifdef UPNP_STRICT
@ -1175,17 +1187,19 @@ SetConnectionType(struct upnphttp * h, const char * action)
/* Added for compliance with WANIPConnection v2 */ /* Added for compliance with WANIPConnection v2 */
static void static void
RequestConnection(struct upnphttp * h, const char * action) RequestConnection(struct upnphttp * h, const char * action, const char * ns)
{ {
UNUSED(action); UNUSED(action);
UNUSED(ns);
SoapError(h, 606, "Action not authorized"); SoapError(h, 606, "Action not authorized");
} }
/* Added for compliance with WANIPConnection v2 */ /* Added for compliance with WANIPConnection v2 */
static void static void
ForceTermination(struct upnphttp * h, const char * action) ForceTermination(struct upnphttp * h, const char * action, const char * ns)
{ {
UNUSED(action); UNUSED(action);
UNUSED(ns);
SoapError(h, 606, "Action not authorized"); SoapError(h, 606, "Action not authorized");
} }
@ -1198,7 +1212,7 @@ QueryStateVariable remains useful as a limited test tool but may not be
part of some future versions of UPnP. part of some future versions of UPnP.
*/ */
static void static void
QueryStateVariable(struct upnphttp * h, const char * action) QueryStateVariable(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp[] = static const char resp[] =
"<u:%sResponse " "<u:%sResponse "
@ -1228,7 +1242,7 @@ QueryStateVariable(struct upnphttp * h, const char * action)
status = get_wan_connection_status_str(ext_if_name); status = get_wan_connection_status_str(ext_if_name);
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:control-1-0", action, ns,/*"urn:schemas-upnp-org:control-1-0",*/
status, action); status, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
@ -1251,7 +1265,7 @@ QueryStateVariable(struct upnphttp * h, const char * action)
snprintf(strn, sizeof(strn), "%i", snprintf(strn, sizeof(strn), "%i",
upnp_get_portmapping_number_of_entries()); upnp_get_portmapping_number_of_entries());
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:control-1-0", action, ns,/*"urn:schemas-upnp-org:control-1-0",*/
strn, action); strn, action);
BuildSendAndCloseSoapResp(h, body, bodylen); BuildSendAndCloseSoapResp(h, body, bodylen);
} }
@ -1270,7 +1284,7 @@ QueryStateVariable(struct upnphttp * h, const char * action)
#endif #endif
/* WANIPv6FirewallControl actions */ /* WANIPv6FirewallControl actions */
static void static void
GetFirewallStatus(struct upnphttp * h, const char * action) GetFirewallStatus(struct upnphttp * h, const char * action, const char * ns)
{ {
static const char resp[] = static const char resp[] =
"<u:%sResponse " "<u:%sResponse "
@ -1283,7 +1297,7 @@ GetFirewallStatus(struct upnphttp * h, const char * action)
int bodylen; int bodylen;
bodylen = snprintf(body, sizeof(body), resp, bodylen = snprintf(body, sizeof(body), resp,
action, "urn:schemas-upnp-org:service:WANIPv6FirewallControl:1", action, ns, /*"urn:schemas-upnp-org:service:WANIPv6FirewallControl:1",*/
GETFLAG(IPV6FCFWDISABLEDMASK) ? 0 : 1, GETFLAG(IPV6FCFWDISABLEDMASK) ? 0 : 1,
GETFLAG(IPV6FCINBOUNDDISALLOWEDMASK) ? 0 : 1, GETFLAG(IPV6FCINBOUNDDISALLOWEDMASK) ? 0 : 1,
action); action);
@ -2013,7 +2027,7 @@ GetAssignedRoles(struct upnphttp * h, const char * action)
static const struct static const struct
{ {
const char * methodName; const char * methodName;
void (*methodImpl)(struct upnphttp *, const char *); void (*methodImpl)(struct upnphttp *, const char *, const char *);
} }
soapMethods[] = soapMethods[] =
{ {
@ -2070,11 +2084,15 @@ ExecuteSoapAction(struct upnphttp * h, const char * action, int n)
char * p; char * p;
char * p2; char * p2;
int i, len, methodlen; int i, len, methodlen;
char namespace[256];
/* SoapAction example : /* SoapAction example :
* urn:schemas-upnp-org:service:WANIPConnection:1#GetStatusInfo */ * urn:schemas-upnp-org:service:WANIPConnection:1#GetStatusInfo */
p = strchr(action, '#'); p = strchr(action, '#');
if(p && (p - action) < n) { if(p && (p - action) < n) {
for(i = 0; i < ((int)sizeof(namespace) - 1) && (action + i) < p; i++)
namespace[i] = action[i];
namespace[i] = '\0';
p++; p++;
p2 = strchr(p, '"'); p2 = strchr(p, '"');
if(p2 && (p2 - action) <= n) if(p2 && (p2 - action) <= n)
@ -2090,7 +2108,7 @@ ExecuteSoapAction(struct upnphttp * h, const char * action, int n)
syslog(LOG_DEBUG, "Remote Call of SoapMethod '%s'", syslog(LOG_DEBUG, "Remote Call of SoapMethod '%s'",
soapMethods[i].methodName); soapMethods[i].methodName);
#endif /* DEBUG */ #endif /* DEBUG */
soapMethods[i].methodImpl(h, soapMethods[i].methodName); soapMethods[i].methodImpl(h, soapMethods[i].methodName, namespace);
return; return;
} }
} }