48#include <webserver.hpp>
53#include <umock/sys_socket.hpp>
54#include <umock/netdb.hpp>
56#ifndef COMPA_INTERNAL_CONFIG_HPP
57#error "No or wrong config.hpp header file included."
87 if (a_dest_saddr ==
nullptr || a_rq_packet ==
nullptr)
90 if (a_num_packet <= 0 || *a_rq_packet ==
nullptr) {
91 UPnPsdk_LOGINFO(
"MSG1163")
"nothing to send.\n";
97 sockObj.
bind(SOCK_DGRAM,
nullptr, AI_PASSIVE);
98 }
catch (
const std::exception& ex) {
99 UPnPsdk_LOGCATCH(
"MSG1166")
"catched next line...\n" << ex.what();
105 saObj = *
reinterpret_cast<sockaddr_storage*
>(a_dest_saddr);
106 UPnPsdk_LOGINFO(
"MSG1154")
"syscall ::sendto() \""
107 << saObj.
netaddrp() <<
"\", " << a_num_packet <<
" messages.\n";
110 for (
int index{0}; index < a_num_packet; index++) {
112 if ((*(a_rq_packet + index) ==
nullptr) ||
113 (**(a_rq_packet + index) ==
'\0'))
117 ssize_t bytes_sent = ::sendto(sockObj, *(a_rq_packet + index),
118 (SIZEP_T)strlen(*(a_rq_packet + index)),
119 0, a_dest_saddr,
sizeof(sockaddr_in6));
120 if (bytes_sent == SOCKET_ERROR) {
122 UPnPsdk_LOGERR(
"MSG1161")
"syscall ::sendto() fails with errid="
123 << serrObj <<
" - " << serrObj.
error_str() <<
'\n';
145 struct sockaddr* a_dest_saddr,
149 char** a_rq_packet) {
150 if (a_dest_saddr ==
nullptr)
153 switch (a_dest_saddr->sa_family) {
161 "MSG1158")
"Empty destination address specified. No stateless "
162 "message sent. Continue without error.\n";
166 "MSG1162")
"Invalid destination internet address-family="
167 << a_dest_saddr->sa_family <<
" specified.\n";
186 while (url[i] !=
'[' && url[i] !=
'\0') {
189 if (url[i] ==
'\0') {
195 while (url[i] !=
'\0' && url[i] !=
']') {
200 if (url[i] ==
'\0') {
222 char address[INET6_ADDRSTRLEN];
223 struct in6_addr v6_addr;
226 inet_pton(AF_INET6, address, &v6_addr);
227 return !IN6_IS_ADDR_LINKLOCAL(&v6_addr);
260 int RegistrationState) {
272 if (PowerState > 0) {
273#ifdef COMPA_HAVE_OPTION_SSDP
290 HTTP_OK,
"CACHE-CONTROL: max-age=", duration,
291 "EXT:",
"LOCATION: ", location,
292 "OPT: ",
"\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
294 "USN: ", usn,
"Powerstate: ", PowerState,
295 "SleepPeriod: ", SleepPeriod,
296 "RegistrationState: ", RegistrationState);
311 HTTP_OK,
"CACHE-CONTROL: max-age=", duration,
312 "EXT:",
"LOCATION: ", location,
"ST: ", nt,
"USN: ", usn,
313 "Powerstate: ", PowerState,
"SleepPeriod: ", SleepPeriod,
314 "RegistrationState: ", RegistrationState);
317#ifdef COMPA_HAVE_OPTION_SSDP
331 HTTP_OK,
"CACHE-CONTROL: max-age=", duration,
332 "EXT:",
"LOCATION: ", location,
333 "OPT: ",
"\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
347 HTTP_OK,
"CACHE-CONTROL: max-age=", duration,
348 "EXT:",
"LOCATION: ", location,
"ST: ", nt,
"USN: ", usn);
356 const char* host = NULL;
365 switch (AddressFamily) {
375 if (PowerState > 0) {
376#ifdef COMPA_HAVE_OPTION_SSDP
393 HTTPMETHOD_NOTIFY,
"*", (
size_t)1,
"HOST: ", host,
":",
394 SSDP_PORT,
"CACHE-CONTROL: max-age=", duration,
395 "LOCATION: ", location,
396 "OPT: ",
"\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
399 "SleepPeriod: ", SleepPeriod,
400 "RegistrationState: ", RegistrationState);
415 HTTPMETHOD_NOTIFY,
"*", (
size_t)1,
"HOST: ", host,
":",
416 SSDP_PORT,
"CACHE-CONTROL: max-age=", duration,
417 "LOCATION: ", location,
"NT: ", nt,
"NTS: ", nts,
"USN: ", usn,
418 "Powerstate: ", PowerState,
"SleepPeriod: ", SleepPeriod,
419 "RegistrationState: ", RegistrationState);
422#ifdef COMPA_HAVE_OPTION_SSDP
436 HTTPMETHOD_NOTIFY,
"*", (
size_t)1,
"HOST: ", host,
":",
437 SSDP_PORT,
"CACHE-CONTROL: max-age=", duration,
438 "LOCATION: ", location,
439 "OPT: ",
"\"http://schemas.upnp.org/upnp/1/0/\"; ns=01",
453 HTTPMETHOD_NOTIFY,
"*", (
size_t)1,
"HOST: ", host,
":",
454 SSDP_PORT,
"CACHE-CONTROL: max-age=", duration,
455 "LOCATION: ", location,
"NT: ", nt,
"NTS: ", nts,
"USN: ", usn);
475 struct sockaddr_storage* dest_addr) {
476 constexpr int MX_FUDGE_FACTOR{10};
489 memset(&job, 0,
sizeof(job));
493 memptr_cmp(&hdr_value,
"\"ssdp:discover\"") != 0)
503 save_char = hdr_value.
buf[hdr_value.
length];
507 hdr_value.
buf[hdr_value.
length] = save_char;
525 maxAge = dev_info->
MaxAge;
528 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"MAX-AGE = %d\n",
530 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"MX = %d\n",
532 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"DeviceType = %s\n",
534 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"DeviceUuid = %s\n",
536 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"ServiceType = %s\n",
539 if (threadArg == NULL)
541 threadArg->
handle = handle;
543 threadArg->
event = event;
544 threadArg->
MaxAge = maxAge;
553 mx -= std::max(1, mx / MX_FUDGE_FACTOR);
556 replyTime = rand() % mx;
566 struct sockaddr_storage __ss;
567 struct sockaddr_in* DestAddr4 = (
struct sockaddr_in*)&__ss;
568 struct sockaddr_in6* DestAddr6 = (
struct sockaddr_in6*)&__ss;
575 UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
576 "In function DeviceAdvertisement\n");
580 memset(&__ss, 0,
sizeof(__ss));
581 switch (AddressFamily) {
583 DestAddr4->sin_family = (sa_family_t)AF_INET;
584 inet_pton(AF_INET,
SSDP_IP, &DestAddr4->sin_addr);
588 DestAddr6->sin6_family = (sa_family_t)AF_INET6;
592 &DestAddr6->sin6_addr);
597 UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
598 "Invalid device address family.\n");
604 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::upnp:rootdevice", Udn);
605 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
608 Location,
Duration, &msgs[0], AddressFamily,
609 PowerState, SleepPeriod, RegistrationState);
613 &msgs[1], AddressFamily, PowerState, SleepPeriod,
615 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::%s", Udn, DevType);
616 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
619 Duration, &msgs[2], AddressFamily, PowerState,
620 SleepPeriod, RegistrationState);
622 if ((RootDev && msgs[0] == NULL) || msgs[1] == NULL || msgs[2] == NULL) {
644int SendReply(
struct sockaddr* DestAddr,
char* DevType,
int RootDev,
char* Udn,
645 char* Location,
int Duration,
int ByType,
int PowerState,
646 int SleepPeriod,
int RegistrationState) {
660 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::upnp:rootdevice", Udn);
661 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
664 Duration, &msgs[0], (
int)DestAddr->sa_family,
665 PowerState, SleepPeriod, RegistrationState);
673 &msgs[0], (
int)DestAddr->sa_family, PowerState,
674 SleepPeriod, RegistrationState);
676 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::%s", Udn, DevType);
677 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
680 Duration, &msgs[0], (
int)DestAddr->sa_family,
681 PowerState, SleepPeriod, RegistrationState);
685 for (i = 0; i < num_msgs; i++) {
686 if (msgs[i] == NULL) {
694 for (i = 0; i < num_msgs; i++) {
702int DeviceReply(
struct sockaddr* DestAddr,
char* DevType,
int RootDev,
703 char* Udn,
char* Location,
int Duration,
int PowerState,
704 int SleepPeriod,
int RegistrationState) {
715 memset(Mil_Nt, 0,
sizeof(Mil_Nt));
716 strncpy(Mil_Nt,
"upnp:rootdevice",
sizeof(Mil_Nt) - 1);
717 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::upnp:rootdevice", Udn);
718 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
721 &szReq[0], (
int)DestAddr->sa_family, PowerState,
722 SleepPeriod, RegistrationState);
724 rc = snprintf(Mil_Nt,
sizeof(Mil_Nt),
"%s", Udn);
725 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Nt))
727 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s", Udn);
728 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
731 &szReq[1], (
int)DestAddr->sa_family, PowerState,
732 SleepPeriod, RegistrationState);
733 rc = snprintf(Mil_Nt,
sizeof(Mil_Nt),
"%s", DevType);
734 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Nt))
736 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::%s", Udn, DevType);
737 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
740 &szReq[2], (
int)DestAddr->sa_family, PowerState,
741 SleepPeriod, RegistrationState);
743 if ((RootDev && szReq[0] == NULL) || szReq[1] == NULL || szReq[2] == NULL) {
763 int Duration,
int AddressFamily,
int PowerState,
764 int SleepPeriod,
int RegistrationState) {
768 struct sockaddr_storage __ss;
769 struct sockaddr_in* DestAddr4 = (
struct sockaddr_in*)&__ss;
770 struct sockaddr_in6* DestAddr6 = (
struct sockaddr_in6*)&__ss;
773 memset(&__ss, 0,
sizeof(__ss));
775 switch (AddressFamily) {
777 DestAddr4->sin_family = (sa_family_t)AddressFamily;
778 inet_pton(AF_INET,
SSDP_IP, &DestAddr4->sin_addr);
782 DestAddr6->sin6_family = (sa_family_t)AddressFamily;
786 &DestAddr6->sin6_addr);
791 UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
792 "Invalid device address family.\n");
794 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::%s", Udn, ServType);
795 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
800 Duration, &szReq[0], AddressFamily, PowerState,
801 SleepPeriod, RegistrationState);
802 if (szReq[0] == NULL) {
814 char* Location,
int Duration,
int PowerState,
int SleepPeriod,
815 int RegistrationState) {
822 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::%s", Udn, ServType);
823 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
826 &szReq[0], (
int)DestAddr->sa_family, PowerState,
827 SleepPeriod, RegistrationState);
828 if (szReq[0] == NULL)
839 int AddressFamily,
int PowerState,
int SleepPeriod,
840 int RegistrationState) {
843 struct sockaddr_storage __ss;
844 struct sockaddr_in* DestAddr4 = (
struct sockaddr_in*)&__ss;
845 struct sockaddr_in6* DestAddr6 = (
struct sockaddr_in6*)&__ss;
849 memset(&__ss, 0,
sizeof(__ss));
851 switch (AddressFamily) {
853 DestAddr4->sin_family = (sa_family_t)AddressFamily;
854 inet_pton(AF_INET,
SSDP_IP, &DestAddr4->sin_addr);
858 DestAddr6->sin6_family = (sa_family_t)AddressFamily;
862 &DestAddr6->sin6_addr);
867 UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
868 "Invalid device address family.\n");
871 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::%s", Udn, ServType);
872 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
877 &szReq[0], AddressFamily, PowerState, SleepPeriod,
879 if (szReq[0] == NULL)
890 int Duration,
int AddressFamily,
int PowerState,
891 int SleepPeriod,
int RegistrationState) {
892 struct sockaddr_storage __ss;
893 struct sockaddr_in* DestAddr4 = (
struct sockaddr_in*)&__ss;
894 struct sockaddr_in6* DestAddr6 = (
struct sockaddr_in6*)&__ss;
903 memset(&__ss, 0,
sizeof(__ss));
904 switch (AddressFamily) {
906 DestAddr4->sin_family = (sa_family_t)AddressFamily;
907 inet_pton(AF_INET,
SSDP_IP, &DestAddr4->sin_addr);
911 DestAddr6->sin6_family = (sa_family_t)AddressFamily;
915 &DestAddr6->sin6_addr);
920 UpnpPrintf(UPNP_CRITICAL, SSDP, __FILE__, __LINE__,
921 "Invalid device address family.\n");
925 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::upnp:rootdevice", Udn);
926 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
929 Location,
Duration, &msgs[0], AddressFamily,
930 PowerState, SleepPeriod, RegistrationState);
932 UpnpPrintf(UPNP_INFO, SSDP, __FILE__, __LINE__,
933 "In function DeviceShutdown\n");
936 &msgs[1], AddressFamily, PowerState, SleepPeriod,
938 rc = snprintf(Mil_Usn,
sizeof(Mil_Usn),
"%s::%s", Udn, DevType);
939 if (rc < 0 || (
unsigned int)rc >=
sizeof(Mil_Usn))
942 &msgs[2], AddressFamily, PowerState, SleepPeriod,
945 if ((RootDev && msgs[0] == NULL) || msgs[1] == NULL || msgs[2] == NULL) {
969 char* DeviceType,
char* DeviceUDN,
char* ServiceType,
971 constexpr char SERVICELIST_STR[] =
"serviceList";
989 memset(UDNstr, 0,
sizeof(UDNstr));
990 memset(devType, 0,
sizeof(devType));
991 memset(servType, 0,
sizeof(servType));
994 "Inside AdvertiseAndReply with AdFlag = %d\n", AdFlag);
1002 defaultExp = SInfo->
MaxAge;
1004 while (NumCopy == 0 || (AdFlag && NumCopy <
NUM_SSDP_COPY)) {
1006 std::this_thread::sleep_for(std::chrono::milliseconds(
SSDP_PAUSE));
1008 for (i = 0lu;; i++) {
1009 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1010 "Entering new device list with i = %lu\n\n", i);
1013 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1014 "Exiting new device list with i = "
1020 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1021 "Extracting device type once for %s\n", dbgStr);
1027 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1028 "Extracting UDN for %s\n", dbgStr);
1029 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1030 "Extracting device type\n");
1037 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1038 "Extracting device type \n");
1042 strncpy(devType, tmpStr,
sizeof(devType) - 1);
1043 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1044 "Extracting device type = %s\n", devType);
1046 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1047 "TempNode is NULL\n");
1050 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1051 "Extracting UDN for %s\n", dbgStr);
1056 UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
1057 "UDN not found!\n");
1062 UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
1063 "UDN not found!\n");
1068 UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
1069 "UDN not found!\n");
1074 UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
1075 "UDN not found!\n");
1078 strncpy(UDNstr, tmpStr,
sizeof(UDNstr) - 1);
1079 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1080 "Sending UDNStr = %s \n", UDNstr);
1096 switch (SearchType) {
1111 if (DeviceUDN && strlen(DeviceUDN) != (
size_t)0) {
1112 if (strcasecmp(DeviceUDN, UDNstr)) {
1113 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1114 "DeviceUDN=%s and search UDN=%s DID NOT match\n",
1117 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1118 "DeviceUDN=%s and search UDN=%s MATCH\n",
1131 if (!strncasecmp(DeviceType, devType, strlen(DeviceType) - (
size_t)2)) {
1132 if (atoi(strrchr(DeviceType,
':') + 1)
1133 < atoi(&devType[strlen(devType) - (
size_t)1])) {
1137 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1138 "DeviceType=%s and search devType=%s MATCH\n",
1139 devType, DeviceType);
1145 }
else if (atoi(strrchr(DeviceType,
':') + 1)
1146 == atoi(&devType[strlen(devType) - (
size_t)1])) {
1147 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1148 "DeviceType=%s and search devType=%s MATCH\n",
1149 devType, DeviceType);
1156 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1157 "DeviceType=%s and search devType=%s DID NOT MATCH\n",
1158 devType, DeviceType);
1161 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1162 "DeviceType=%s and search devType=%s DID NOT MATCH\n",
1163 devType, DeviceType);
1174 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1175 "Sending service Advertisement\n");
1183 if (!strncmp(dbgStr, SERVICELIST_STR,
sizeof SERVICELIST_STR)) {
1196 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1197 "Service not found 3\n");
1200 for (j = 0lu;; j++) {
1209 UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
1210 "ServiceType not found \n");
1224 strncpy(servType, tmpStr,
sizeof(servType) - 1);
1225 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1226 "ServiceType = %s\n", servType);
1230 UDNstr, servType, SInfo->
DescURL, Exp,
1241 switch (SearchType) {
1251 if (!strncasecmp(ServiceType, servType, strlen(ServiceType) - (
size_t)2)) {
1252 if (atoi(strrchr(ServiceType,
':') + 1) <
1253 atoi(&servType[strlen(servType) - (
size_t)1])) {
1257 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1258 "ServiceType=%s and search servType=%s MATCH\n",
1259 ServiceType, servType);
1265 }
else if (atoi(strrchr (ServiceType,
':') + 1) ==
1266 atoi(&servType[strlen(servType) - (
size_t)1])) {
1267 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1268 "ServiceType=%s and search servType=%s MATCH\n",
1269 ServiceType, servType);
1276 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1277 "ServiceType=%s and search servType=%s DID NOT MATCH\n",
1278 ServiceType, servType);
1281 UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
1282 "ServiceType=%s and search servType=%s DID NOT MATCH\n",
1283 ServiceType, servType);
1303 UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
1304 "Exiting AdvertiseAndReply.\n");
int UpnpDevice_Handle
Returned when a device application registers with UpnpRegisterRootDevice(),UpnpRegisterRootDevice2(),...
#define HDR_MX
Type of a HTTP header.
#define HDR_ST
Type of a HTTP header.
#define HDR_MAN
Type of a HTTP header.
Structure of an HTTP message.
#define X_USER_AGENT
Can be overwritten by configure CFLAGS argument.
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
Sets the jobs free function.
int TPJobInit(ThreadPoolJob *job, UPnPsdk::start_routine func, void *arg)
Initializes thread pool job.
void(* free_routine)(void *arg)
int TimerThreadSchedule(TimerThread *timer, time_t timeout, TimeoutType type, ThreadPoolJob *job, Duration duration, int *id)
Schedules an event to run at a specified time.
@ REL_SEC
seconds from current time.
Class for portable handling of network socket errors.
void catch_error()
Catch error for later use.
std::string error_str() const
Get human readable error description of the catched error.
Manage all aspects of a network socket.
void bind(const int a_socktype, const SSockaddr *const a_saddr=nullptr, const int a_flags=0)
Bind socket to an ip address of a local network adapter.
#define NUM_SSDP_COPY
This configuration parameter determines how many copies of each SSDP advertisement and search packets...
#define SSDP_PAUSE
This configuration parameter determines the pause between identical SSDP advertisement and search pac...
int ssdp_request_type(char *cmd, SsdpEvent *Evt)
Starts filling the SSDP event structure based upon the request received.
int AdvertiseAndReply(int AdFlag, UpnpDevice_Handle Hnd, enum SsdpSearchType SearchType, struct sockaddr *DestAddr, char *DeviceType, char *DeviceUDN, char *ServiceType, int Exp)
Sends SSDP advertisements, replies and shutdown messages.
Data structure common to all types of nodes.
Data structure representing a list of nodes.
Data structure representing an Element node.
#define DOMString
The type of DOM strings.
PUPNP_Api IXML_Node * ixmlNode_getNextSibling(IXML_Node *nodeptr)
Retrieves the sibling Node immediately following this Node.
PUPNP_Api const DOMString ixmlNode_getNodeValue(IXML_Node *nodeptr)
Returns the value of the Node as a string.
PUPNP_Api const DOMString ixmlNode_getNodeName(IXML_Node *nodeptr)
Returns the name of the Node, depending on what type of Node it is, in a read-only string.
PUPNP_Api void ixmlNodeList_free(IXML_NodeList *nList)
Frees a NodeList object.
PUPNP_Api IXML_Node * ixmlNode_getFirstChild(IXML_Node *nodeptr)
Retrieves the first child Node of a Node.
PUPNP_Api IXML_Node * ixmlNodeList_item(IXML_NodeList *nList, unsigned long index)
Retrieves a Node from a NodeList specified by a numerical index.
PUPNP_Api IXML_NodeList * ixmlElement_getElementsByTagName(IXML_Element *element, const DOMString tagName)
Returns a NodeList of all descendant Elements with a given tag name, in the order in which they are e...
http_header_t * httpmsg_find_hdr(http_message_t *msg, int header_name_id, memptr *value)
Finds header from a list, with the given 'name_id'.
int raw_to_int(memptr *raw_value, int base)
Converts raw character data to integer value.
int http_MakeMessage(membuffer *buf, int http_major_version, int http_minor_version, const char *fmt,...)
Generate an HTTP message based on the format that is specified in the input parameters.
Performs HTTP read and write messages.
int memptr_cmp(memptr *m, const char *s)
Compares characters of strings passed for number of bytes. If equal for the number of bytes,...
void membuffer_destroy(membuffer *m)
Free's memory allocated for membuffer* m.
void membuffer_init(membuffer *m)
Wrapper to membuffer_initialize().
char * membuffer_detach(membuffer *m)
Detaches current buffer and returns it. The caller must free the returned buffer using free()....
size_t size_inc
used to increase size; MUST be > 0; (read/write).
size_t length
length of memory without terminating '\0' (read-only).
char * buf
start of memory (read/write).
pointer to a chunk of memory.
Maintains a block of dynamically allocated memory.
#define UPNP_E_SOCKET_ERROR
Generic socket error code for conditions not covered by other error codes.
#define UPNP_E_NETWORK_ERROR
A network error occurred.
#define UPNP_E_INVALID_HANDLE
The handle passed to a function is not a recognized as a valid handle.
#define UPNP_E_SUCCESS
The operation completed successfully.
#define UPNP_E_OUTOF_MEMORY
Not enough resources are currently available to complete the operation.
#define UPNP_E_SOCKET_WRITE
An error happened while writing to a socket.
#define UPNP_E_INVALID_PARAM
One or more of the parameters passed to the function is not valid.
UPnPsdk_EXTERN bool g_dbug
Switch to enable verbose (debug) output.
int send_stateless(sockaddr *a_dest_saddr, int a_num_packet, char **a_rq_packet)
Works as a request handler which passes the HTTP request string to multicast channel.
int extractIPv6address(char *url, char *address)
Extract IPv6 address.
constexpr int MSGTYPE_REPLY
Message type.
int NewRequestHandler(struct sockaddr *a_dest_saddr, int a_num_packet, char **a_rq_packet)
Works as a request handler which passes the HTTP request string to multicast channel.
constexpr int MSGTYPE_SHUTDOWN
Message type.
void CreateServicePacket(int msg_type, const char *nt, char *usn, char *location, int duration, char **packet, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
Creates a HTTP request packet.
constexpr int MSGTYPE_ADVERTISEMENT
Message type.
int isUrlV6UlaGua(char *descdocUrl)
Test if a Url contains an ULA or GUA IPv6 address.
Declaration of the Sockaddr class and some free helper functions.
Socket Module: manage properties and methods but not connections of ONE network socket to handle IPv4...
#define SSDP_PORT
constant
struct sockaddr_storage dest_addr
part of search reply
char UDN[LINE_SIZE]
Part of SSDP Event.
int Mx
Part of SSDP Event.
#define SSDP_IPV6_SITELOCAL
constant
UpnpDevice_Handle handle
part of search reply
char ServiceType[LINE_SIZE]
Part of SSDP Event.
#define SSDP_IPV6_LINKLOCAL
constant
char DeviceType[LINE_SIZE]
Part of SSDP Event.
int MaxAge
part of search reply
enum SsdpSearchType RequestType
Part of SSDP Event.
SsdpEvent event
part of search reply
SsdpSearchType
Enumeration to define all different types of ssdp searches.
@ SSDP_DEVICEUDN
Part of SType.
@ SSDP_DEVICETYPE
Part of SType.
@ SSDP_ROOTDEVICE
Part of SType.
@ SSDP_SERVICE
Part of SType.
Structure to store the SSDP information.
int DeviceReply(struct sockaddr *DestAddr, char *DevType, int RootDev, char *Udn, char *Location, int Duration, int PowerState, int SleepPeriod, int RegistrationState)
Creates the reply packet and send it to the Control Point address.
int DeviceAdvertisement(char *DevType, int RootDev, char *Udn, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
Creates the device advertisement request.
int DeviceShutdown(char *DevType, int RootDev, char *Udn, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
Creates a HTTP device shutdown request packet and send it to the multicast channel through RequestHan...
void ssdp_handle_device_request(http_message_t *hmsg, struct sockaddr_storage *dest_addr)
Handles the search request.
void advertiseAndReplyThread(void *data)
Wrapper function to reply the search request coming from the control point.
int ServiceAdvertisement(char *Udn, char *ServType, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
Creates the advertisement packet and send it to the multicast channel.
int ServiceShutdown(char *Udn, char *ServType, char *Location, int Duration, int AddressFamily, int PowerState, int SleepPeriod, int RegistrationState)
Creates a HTTP service shutdown request packet and sends it to the multicast channel through RequestH...
int SendReply(struct sockaddr *DestAddr, char *DevType, int RootDev, char *Udn, char *Location, int Duration, int ByType, int PowerState, int SleepPeriod, int RegistrationState)
Creates the reply packet and send it to the Control Point addesss.
int ServiceReply(struct sockaddr *DestAddr, char *ServType, char *Udn, char *Location, int Duration, int PowerState, int SleepPeriod, int RegistrationState)
Creates the advertisement packet and send it to the multicast channel.
Manage "Step 1: Discovery" of the UPnP+™ specification for UPnP Devices with SSDP.
Trivial ::sockaddr structures enhanced with methods.
const std::string netaddrp() noexcept
Get the assosiated netaddress with port.
Upnp_Handle_Type GetHandleInfo(UpnpClient_Handle Hnd, Handle_Info **HndInfo)
Get handle information.
Upnp_SID gUpnpSdkNLSuuid
Global variable used in discovery notifications.
Upnp_Handle_Type GetDeviceHandleInfo(UpnpDevice_Handle start, int AddressFamily, UpnpDevice_Handle *device_handle_out, struct Handle_Info **HndInfo)
Retrieves the device handle and information of the first device of the address family specified....
TimerThread gTimerThread
Global timer thread.
unsigned gIF_INDEX
Index/scope-id from the used network interface.
Inititalize the compatible library before it can be used.
#define HandleLock()
HandleLock.
#define DEFAULT_MAXAGE
DEFAULT_MAXAGE.
int SleepPeriod
Sleep Period as defined by UPnP Low Power.
char LowerDescURL[LINE_SIZE]
URL for the use of SSDP when answering to legacy CPs (CP searching for a v1 when the device is v2).
int RegistrationState
Registration State as defined by UPnP Low Power.
char DescURL[LINE_SIZE]
URL for the use of SSDP.
#define HandleUnlock()
HandleUnlock.
int PowerState
Power State as defined by UPnP Low Power.
IXML_NodeList * DeviceList
List of devices in the description document.
int MaxAge
Advertisement timeout.
int DeviceAf
Address family: AF_INET6 or AF_INET.
#define HandleReadLock()
HandleReadLock.
Data to be stored in handle table for Handle Info.
UPnPsdk_VIS void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module, const char *DbgFileName, int DbgLineNo, const char *FmtStr,...)
Prints the debug statement.