Ignore the version of devices while answering to requests
This commit is contained in:
parent
73304da571
commit
f9f3daa94d
|
@ -1,5 +1,9 @@
|
||||||
$Id: Changelog.txt,v 1.47 2016/12/16 09:22:35 nanard Exp $
|
$Id: Changelog.txt,v 1.47 2016/12/16 09:22:35 nanard Exp $
|
||||||
|
|
||||||
|
2018/02/03:
|
||||||
|
Properly parse several requests read() at once
|
||||||
|
Ignore the version of devices while answering to requests
|
||||||
|
|
||||||
2016/11/11:
|
2016/11/11:
|
||||||
Fix for Solaris build
|
Fix for Solaris build
|
||||||
|
|
||||||
|
|
|
@ -456,11 +456,11 @@ sendNotifications(int notif_type, const struct device * dev, const struct servic
|
||||||
* build and send response to M-SEARCH SSDP packets. */
|
* build and send response to M-SEARCH SSDP packets. */
|
||||||
static void
|
static void
|
||||||
SendSSDPMSEARCHResponse(int s, const struct sockaddr * sockname,
|
SendSSDPMSEARCHResponse(int s, const struct sockaddr * sockname,
|
||||||
const char * st, const char * usn,
|
const char * st, size_t st_len, const char * usn,
|
||||||
const char * server, const char * location)
|
const char * server, const char * location)
|
||||||
{
|
{
|
||||||
int l, n;
|
int l, n;
|
||||||
char buf[512];
|
char buf[1024];
|
||||||
socklen_t sockname_len;
|
socklen_t sockname_len;
|
||||||
/*
|
/*
|
||||||
* follow guideline from document "UPnP Device Architecture 1.0"
|
* follow guideline from document "UPnP Device Architecture 1.0"
|
||||||
|
@ -473,7 +473,7 @@ SendSSDPMSEARCHResponse(int s, const struct sockaddr * sockname,
|
||||||
l = snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\r\n"
|
l = snprintf(buf, sizeof(buf), "HTTP/1.1 200 OK\r\n"
|
||||||
"CACHE-CONTROL: max-age=120\r\n"
|
"CACHE-CONTROL: max-age=120\r\n"
|
||||||
/*"DATE: ...\r\n"*/
|
/*"DATE: ...\r\n"*/
|
||||||
"ST: %s\r\n"
|
"ST: %.*s\r\n"
|
||||||
"USN: %s\r\n"
|
"USN: %s\r\n"
|
||||||
"EXT:\r\n"
|
"EXT:\r\n"
|
||||||
"SERVER: %s\r\n"
|
"SERVER: %s\r\n"
|
||||||
|
@ -483,7 +483,7 @@ SendSSDPMSEARCHResponse(int s, const struct sockaddr * sockname,
|
||||||
"BOOTID.UPNP.ORG: %u\r\n" /* UDA v1.1 */
|
"BOOTID.UPNP.ORG: %u\r\n" /* UDA v1.1 */
|
||||||
"CONFIGID.UPNP.ORG: %u\r\n" /* UDA v1.1 */
|
"CONFIGID.UPNP.ORG: %u\r\n" /* UDA v1.1 */
|
||||||
"\r\n",
|
"\r\n",
|
||||||
st, usn,
|
(int)st_len, st, usn,
|
||||||
server, location,
|
server, location,
|
||||||
upnp_bootid, upnp_bootid, upnp_configid);
|
upnp_bootid, upnp_bootid, upnp_configid);
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
|
@ -501,7 +501,7 @@ SendSSDPMSEARCHResponse(int s, const struct sockaddr * sockname,
|
||||||
|
|
||||||
/* Process M-SEARCH requests */
|
/* Process M-SEARCH requests */
|
||||||
static void
|
static void
|
||||||
processMSEARCH(int s, const char * st, int st_len,
|
processMSEARCH(int s, const char * st, size_t st_len,
|
||||||
const struct sockaddr * addr)
|
const struct sockaddr * addr)
|
||||||
{
|
{
|
||||||
struct service * serv;
|
struct service * serv;
|
||||||
|
@ -514,12 +514,12 @@ processMSEARCH(int s, const char * st, int st_len,
|
||||||
#ifdef ENABLE_IPV6
|
#ifdef ENABLE_IPV6
|
||||||
sockaddr_to_string(addr, buf, sizeof(buf));
|
sockaddr_to_string(addr, buf, sizeof(buf));
|
||||||
syslog(LOG_INFO, "SSDP M-SEARCH from %s ST:%.*s",
|
syslog(LOG_INFO, "SSDP M-SEARCH from %s ST:%.*s",
|
||||||
buf, st_len, st);
|
buf, (int)st_len, st);
|
||||||
#else /* ENABLE_IPV6 */
|
#else /* ENABLE_IPV6 */
|
||||||
syslog(LOG_INFO, "SSDP M-SEARCH from %s:%d ST: %.*s",
|
syslog(LOG_INFO, "SSDP M-SEARCH from %s:%d ST: %.*s",
|
||||||
inet_ntoa(((const struct sockaddr_in *)addr)->sin_addr),
|
inet_ntoa(((const struct sockaddr_in *)addr)->sin_addr),
|
||||||
ntohs(((const struct sockaddr_in *)addr)->sin_port),
|
ntohs(((const struct sockaddr_in *)addr)->sin_port),
|
||||||
st_len, st);
|
(int)st_len, st);
|
||||||
#endif /* ENABLE_IPV6 */
|
#endif /* ENABLE_IPV6 */
|
||||||
if(st_len==8 && (0==memcmp(st, "ssdp:all", 8))) {
|
if(st_len==8 && (0==memcmp(st, "ssdp:all", 8))) {
|
||||||
/* send a response for all services */
|
/* send a response for all services */
|
||||||
|
@ -527,7 +527,7 @@ processMSEARCH(int s, const char * st, int st_len,
|
||||||
serv;
|
serv;
|
||||||
serv = serv->entries.le_next) {
|
serv = serv->entries.le_next) {
|
||||||
SendSSDPMSEARCHResponse(s, addr,
|
SendSSDPMSEARCHResponse(s, addr,
|
||||||
serv->st, serv->usn,
|
serv->st, strlen(serv->st), serv->usn,
|
||||||
serv->server, serv->location);
|
serv->server, serv->location);
|
||||||
}
|
}
|
||||||
} else if(st_len > 5 && (0==memcmp(st, "uuid:", 5))) {
|
} else if(st_len > 5 && (0==memcmp(st, "uuid:", 5))) {
|
||||||
|
@ -537,12 +537,12 @@ processMSEARCH(int s, const char * st, int st_len,
|
||||||
serv = serv->entries.le_next) {
|
serv = serv->entries.le_next) {
|
||||||
if(0 == strncmp(serv->usn, st, st_len)) {
|
if(0 == strncmp(serv->usn, st, st_len)) {
|
||||||
SendSSDPMSEARCHResponse(s, addr,
|
SendSSDPMSEARCHResponse(s, addr,
|
||||||
serv->st, serv->usn,
|
serv->st, strlen(serv->st), serv->usn,
|
||||||
serv->server, serv->location);
|
serv->server, serv->location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int l;
|
size_t l;
|
||||||
int st_ver = 0;
|
int st_ver = 0;
|
||||||
char atoi_buffer[8];
|
char atoi_buffer[8];
|
||||||
|
|
||||||
|
@ -550,12 +550,13 @@ processMSEARCH(int s, const char * st, int st_len,
|
||||||
for (l = st_len; l > 0; l--) {
|
for (l = st_len; l > 0; l--) {
|
||||||
if (st[l-1] == ':') {
|
if (st[l-1] == ':') {
|
||||||
memset(atoi_buffer, 0, sizeof(atoi_buffer));
|
memset(atoi_buffer, 0, sizeof(atoi_buffer));
|
||||||
memcpy(atoi_buffer, st + l, MIN((int)(sizeof(atoi_buffer) - 1), st_len - l));
|
memcpy(atoi_buffer, st + l, MIN((sizeof(atoi_buffer) - 1), st_len - l));
|
||||||
st_ver = atoi(atoi_buffer);
|
st_ver = atoi(atoi_buffer);
|
||||||
st_len = l - 1;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (l == 0)
|
||||||
|
l = st_len;
|
||||||
/* answer for each matching service */
|
/* answer for each matching service */
|
||||||
/* From UPnP Device Architecture v1.1 :
|
/* From UPnP Device Architecture v1.1 :
|
||||||
* 1.3.2 [...] Updated versions of device and service types
|
* 1.3.2 [...] Updated versions of device and service types
|
||||||
|
@ -570,10 +571,10 @@ processMSEARCH(int s, const char * st, int st_len,
|
||||||
for(serv = servicelisthead.lh_first;
|
for(serv = servicelisthead.lh_first;
|
||||||
serv;
|
serv;
|
||||||
serv = serv->entries.le_next) {
|
serv = serv->entries.le_next) {
|
||||||
if(0 == strncmp(serv->st, st, st_len)) {
|
if(0 == strncmp(serv->st, st, l)) {
|
||||||
syslog(LOG_DEBUG, "Found matching service : %s %s", serv->st, serv->usn);
|
syslog(LOG_DEBUG, "Found matching service : %s %s", serv->st, serv->location);
|
||||||
SendSSDPMSEARCHResponse(s, addr,
|
SendSSDPMSEARCHResponse(s, addr,
|
||||||
serv->st, serv->usn,
|
st, st_len, serv->usn,
|
||||||
serv->server, serv->location);
|
serv->server, serv->location);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue