50#include <httpreadwrite.hpp>
55#include <umock/sys_socket.hpp>
56#include <umock/stdlib.hpp>
57#include <umock/pupnp_miniserver.hpp>
58#include <umock/pupnp_ssdp.hpp>
93#ifdef COMPA_HAVE_WEBSERVER
109 size_t a_host_port_len
111 TRACE(
"Executing host_header_is_numeric()");
112 if (a_host_port_len == 0 || strncmp(a_host_port,
"[::]", 4) == 0 ||
113 strncmp(a_host_port,
"0.0.0.0", 7) == 0)
118 saddrObj = std::string(a_host_port, a_host_port_len);
119 }
catch (
const std::exception& e) {
120 UPnPsdk_LOGCATCH(
"MSG1049") << e.what() <<
"\n";
139 TRACE(
"Executing getNumericHostRedirection()")
145 memcpy(a_host_port, sa.
netaddrp().c_str(), a_hp_size);
148 }
catch (
const std::exception& ex) {
149 UPnPsdk_LOGCATCH(
"MSG1093")
"catched next line...\n" << ex.what();
178 case SOAPMETHOD_POST:
179 case HTTPMETHOD_MPOST:
181 UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
182 "miniserver %d: got SOAP msg\n", a_info->
socket);
185 case HTTPMETHOD_NOTIFY:
186 case HTTPMETHOD_SUBSCRIBE:
187 case HTTPMETHOD_UNSUBSCRIBE:
189 UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
190 "miniserver %d: got GENA msg\n", a_info->
socket);
194 case HTTPMETHOD_POST:
195 case HTTPMETHOD_HEAD:
196 case HTTPMETHOD_SIMPLEGET:
200 UPnPsdk_LOGINFO(
"MSG1107")
"miniserver socket="
201 << a_info->
socket <<
": got WEB server msg.\n";
207 rc = HTTP_INTERNAL_SERVER_ERROR;
210 request = &a_hparser->
msg;
213 UPnPsdk_LOGINFO(
"MSG1113")
"Redirect host_port=\"" << host_port
221 min_size = header.
length < ((
sizeof host_port) - 1)
223 : (
sizeof host_port) - 1;
224 memcpy(host_port, header.
buf, min_size);
225 host_port[min_size] = 0;
226 if (host_validate_callback) {
227 rc = host_validate_callback(host_port, cookie);
234 UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
235 "Possible DNS Rebind attack prevented.\n");
239 static const char* redir_fmt =
"HTTP/1.1 307 Temporary Redirect\r\n"
240 "Location: http://%s\r\n\r\n";
247 snprintf(redir_str,
NAME_SIZE, redir_fmt, host_port);
255 callback(a_hparser, request, a_info);
268 TRACE(
"Executing free_handle_request_arg()")
283 TRACE(
"Executing handle_request()")
284 int http_major_version{1};
285 int http_minor_version{1};
288 SOCKET connfd = request_in->
connfd;
297 UPnPsdk_LOGINFO(
"MSG1027")
"UDevice socket="
298 << connfd <<
": READING request on local=\""
299 << local_saObj.
netaddrp() <<
"\" from control point remote=\""
300 << remote_saObj.
netaddrp() <<
"\".\n";
324 UPnPsdk_LOGINFO(
"MSG1106")
"miniserver socket=" << connfd
325 <<
": PROCESSING...\n";
330 if (http_error_code > 0) {
342 UPnPsdk_LOGINFO(
"MSG1058")
"miniserver socket(" << connfd
355 TRACE(
"Executing schedule_request_job()")
362 remote_saObj = clientAddr.
ss;
364 "MSG1042")
"Schedule UDevice to read incomming request with socket("
365 << a_connfd <<
") local=\"" << local_saObj.
netaddrp()
366 <<
"\" remote=\"" << remote_saObj.
netaddrp() <<
"\".\n";
372 if (request ==
nullptr) {
373 UPnPsdk_LOGCRIT(
"MSG1024")
"Socket(" << a_connfd
374 <<
"): out of memory.\n";
378 request->connfd = a_connfd;
379 memcpy(&request->foreign_sockaddr, &clientAddr.
ss,
380 sizeof(request->foreign_sockaddr));
385 UPnPsdk_LOGERR(
"MSG1025")
"Socket("
386 << a_connfd <<
"): failed to add job to miniserver threadpool.\n";
416 TRACE(
"Executing fdset_if_valid(): check sockfd=" + std::to_string(a_sock))
417 if (a_sock == INVALID_SOCKET)
421 if (a_sock < 3 || a_sock >= FD_SETSIZE) {
422 UPnPsdk_LOGERR(
"MSG1005")
423 << (a_sock < 0 ?
"Invalid" :
"Prohibited") <<
" socket " << a_sock
424 <<
" not set to be monitored by ::select()"
425 << (a_sock >= 3 ?
" because it violates FD_SETSIZE.\n" :
".\n");
434 FD_SET(a_sock, a_set);
437 UPnPsdk_LOGINFO(
"MSG1002")
"Unbound socket "
438 << a_sock <<
" not set to be monitored by ::select().\n";
440 }
catch (
const std::exception& e) {
442 std::cerr << e.what();
443 UPnPsdk_LOGCATCH(
"MSG1009")
"Invalid socket "
444 << a_sock <<
" not set to be monitored by ::select().\n";
461 [[maybe_unused]] SOCKET listen_sock,
463 [[maybe_unused]] fd_set& set) {
464#ifndef COMPA_HAVE_WEBSERVER
467 TRACE(
"Executing web_server_accept()")
468 if (listen_sock == INVALID_SOCKET || !FD_ISSET(listen_sock, &set)) {
469 UPnPsdk_LOGINFO(
"MSG1012")
"Socket("
470 << listen_sock <<
") invalid or not in file descriptor set.\n";
475 socklen_t ctrlpntLen =
sizeof(ctrlpnt_saObj.
ss);
479 umock::sys_socket_h.accept(listen_sock, &ctrlpnt_saObj.
sa, &ctrlpntLen);
480 if (conn_sock == INVALID_SOCKET) {
481 UPnPsdk_LOGERR(
"MSG1022")
"Error in ::accept(): "
482 << std::strerror(errno) <<
".\n";
489 listen_sockObj.
load();
498 UPnPsdk_LOGINFO(
"MSG1023")
"Listening socket("
499 << listen_sock <<
") on \"" << listen_saObj.
netaddrp()
500 <<
"\" accept connection socket(" << conn_sock <<
") local=\""
501 << conn_saObj.
netaddrp() <<
"\" to remote=\""
502 << ctrlpnt_saObj.
netaddrp() <<
"\".\n";
519 TRACE(
"Executing ssdp_read()")
520 if (*rsock == INVALID_SOCKET || !FD_ISSET(*rsock, set))
523#if defined(COMPA_HAVE_CTRLPT_SSDP) || defined(COMPA_HAVE_DEVICE_SSDP)
525 UpnpPrintf(UPNP_ERROR, MSERV, __FILE__, __LINE__,
526 "miniserver: Error in readFromSSDPSocket(%d): "
530 *rsock = INVALID_SOCKET;
534 *rsock = INVALID_SOCKET;
556 TRACE(
"Executing receive_from_stopSock()")
557 constexpr char shutdown_str[]{
"ShutDown"};
559 if (!FD_ISSET(ssock, set))
563 socklen_t clientLen{
sizeof(clientAddr)};
567 char receiveBuf[
sizeof(shutdown_str) + 1]{};
568 char buf_ntop[INET6_ADDRSTRLEN];
571 SSIZEP_T byteReceived = umock::sys_socket_h.recvfrom(
572 ssock, receiveBuf,
sizeof(shutdown_str), 0, &clientAddr.sa, &clientLen);
573 if (byteReceived == SOCKET_ERROR ||
574 inet_ntop(AF_INET, &clientAddr.sin.sin_addr, buf_ntop,
575 sizeof(buf_ntop)) ==
nullptr) {
576 UPnPsdk_LOGCRIT(
"MSG1038")
"Failed to receive data from socket "
577 << ssock <<
". Stop miniserver.\n";
582 if (clientAddr.sin.sin_addr.s_addr != htonl(2130706433) ||
583 strcmp(receiveBuf, shutdown_str) != 0)
585 char nullstr[]{
"\\0"};
586 if (byteReceived == 0 || receiveBuf[byteReceived - 1] !=
'\0')
588 UPnPsdk_LOGERR(
"MSG1039")
"Received \""
589 << receiveBuf << nullstr <<
"\" from " << buf_ntop <<
":"
590 << ntohs(clientAddr.sin.sin_port)
591 <<
", must be \"ShutDown\\0\" from 127.0.0.1:*. Don't "
592 "stopping miniserver.\n";
596 UPnPsdk_LOGINFO(
"MSG1040")
"On socket "
597 << ssock <<
" received ordinary datagram \"" << receiveBuf
598 <<
"\\0\" from " << buf_ntop <<
":" << ntohs(clientAddr.sin.sin_port)
599 <<
". Stop miniserver.\n";
619 UPnPsdk_LOGINFO(
"MSG1085")
"Executing...\n";
621#ifdef COMPA_HAVE_WEBSERVER
626 if (miniSock->pSockLlaObj !=
nullptr) {
627 sockLlaObj = std::move(*miniSock->pSockLlaObj);
628 miniSock->pSockLlaObj = &sockLlaObj;
631 if (miniSock->pSockGuaObj !=
nullptr) {
632 sockGuaObj = std::move(*miniSock->pSockGuaObj);
633 miniSock->pSockGuaObj = &sockGuaObj;
636 if (miniSock->pSockIp4Obj !=
nullptr) {
637 sockIp4Obj = std::move(*miniSock->pSockIp4Obj);
638 miniSock->pSockIp4Obj = &sockIp4Obj;
650 SOCKET maxMiniSock = 0;
668 std::max(maxMiniSock, miniSock->
ssdpSock4 == INVALID_SOCKET
672 std::max(maxMiniSock, miniSock->
ssdpSock6 == INVALID_SOCKET
679#ifdef COMPA_HAVE_CTRLPT_SSDP
681 std::max(maxMiniSock, miniSock->
ssdpReqSock4 == INVALID_SOCKET
685 std::max(maxMiniSock, miniSock->
ssdpReqSock6 == INVALID_SOCKET
704#ifdef COMPA_HAVE_CTRLPT_SSDP
710 int ret = umock::sys_socket_h.select(
static_cast<int>(maxMiniSock),
711 &rdSet, NULL, &expSet, NULL);
713 if (ret == SOCKET_ERROR) {
714 if (errno == EINTR) {
718 if (errno == EBADF) {
730 UPnPsdk_LOGCRIT(
"MSG1021")
"Error in ::select(): "
731 << std::strerror(errno) <<
".\n";
741 [[maybe_unused]]
int ret1 =
743 [[maybe_unused]]
int ret2 =
745 [[maybe_unused]]
int ret3 =
747#ifdef COMPA_HAVE_CTRLPT_SSDP
769#ifdef COMPA_HAVE_CTRLPT_SSDP
774 umock::stdlib_h.free(miniSock);
777 UPnPsdk_LOGINFO(
"MSG1060")
"Finished.\n";
782 umock::pupnp_miniserver.RunMiniServer(miniSock);
798 TRACE(
"Executing get_port(), calls system ::getsockname()")
800 socklen_t len(
sizeof sockinfo);
802 if (umock::sys_socket_h.getsockname(sockfd, &sockinfo.sa, &len) == -1)
806 switch (sockinfo.ss.ss_family) {
809 *port = ntohs(sockinfo.sin6.sin6_port);
815 UPnPsdk_LOGINFO(
"MSG1063")
"sockfd=" << sockfd <<
", port=" << *port
821#ifdef COMPA_HAVE_WEBSERVER
849 in_port_t listen_port4,
853 in_port_t listen_port6,
857 in_port_t listen_port6UlaGua) {
858 UPnPsdk_LOGINFO(
"MSG1109")
"Executing with listen_port4="
859 << listen_port4 <<
", listen_port6=" << listen_port6
860 <<
", listen_port6UlaGua=" << listen_port6UlaGua <<
".\n";
864 if (out->pSockLlaObj !=
nullptr &&
gIF_IPV6[0] !=
'\0') {
867 if (::strncmp(
gIF_IPV6,
"::1", 3) == 0)
870 saObj =
'[' + std::string(
gIF_IPV6) +
871 "]:" + std::to_string(listen_port6);
873 saObj =
'[' + std::string(
gIF_IPV6) +
'%' +
875 "]:" + std::to_string(listen_port6);
876 out->pSockLlaObj->
bind(SOCK_STREAM, &saObj, AI_PASSIVE);
877 out->pSockLlaObj->
listen();
882 }
catch (
const std::exception& ex) {
883 UPnPsdk_LOGCATCH(
"MSG1110")
"gIF_IPV6=\""
884 <<
gIF_IPV6 <<
"\", catched next line...\n"
897 "]:" + std::to_string(listen_port6UlaGua);
898 out->pSockGuaObj->
bind(SOCK_STREAM, &saObj, AI_PASSIVE);
899 out->pSockGuaObj->
listen();
904 }
catch (
const std::exception& ex) {
905 UPnPsdk_LOGCATCH(
"MSG1117")
"gIF_IPV6_ULA_GUA=\""
911 if (out->pSockIp4Obj !=
nullptr &&
gIF_IPV4[0] !=
'\0') {
914 saObj = std::string(
gIF_IPV4) +
':' + std::to_string(listen_port4);
915 out->pSockIp4Obj->
bind(SOCK_STREAM, &saObj, AI_PASSIVE);
916 out->pSockIp4Obj->
listen();
921 }
catch (
const std::exception& ex) {
922 UPnPsdk_LOGCATCH(
"MSG1114")
"gIF_IPV4=\""
923 <<
gIF_IPV4 <<
"\", catched next line...\n"
929 UPnPsdk_LOGERR(
"MSG1065")
"No valid IP address on a local network "
930 "adapter found for listening.\n";
954 TRACE(
"Executing get_miniserver_stopsock()");
955 sockaddr_in stop_sockaddr;
958 SOCKET miniServerStopSock =
959 umock::sys_socket_h.socket(AF_INET, SOCK_DGRAM, 0);
960 if (miniServerStopSock == INVALID_SOCKET) {
962 UPnPsdk_LOGCRIT(
"MSG1094")
"Error in socket(): "
967 memset(&stop_sockaddr, 0,
sizeof(stop_sockaddr));
968 stop_sockaddr.sin_family = AF_INET;
969 inet_pton(AF_INET,
"127.0.0.1", &stop_sockaddr.sin_addr);
970 int ret = umock::sys_socket_h.bind(
971 miniServerStopSock,
reinterpret_cast<sockaddr*
>(&stop_sockaddr),
972 sizeof(stop_sockaddr));
973 if (ret == SOCKET_ERROR) {
975 UPnPsdk_LOGCRIT(
"MSG1095")
"Error in binding localhost: "
988 UPnPsdk_LOGINFO(
"MSG1053")
"Bound stop socket="
1001 TRACE(
"Executing InitMiniServerSockArray()");
1013#ifdef COMPA_HAVE_CTRLPT_SSDP
1017#ifdef COMPA_HAVE_WEBSERVER
1018 miniSocket->pSockLlaObj =
nullptr;
1019 miniSocket->pSockGuaObj =
nullptr;
1020 miniSocket->pSockIp4Obj =
nullptr;
1028#ifdef COMPA_HAVE_DEVICE_SOAP
1030 TRACE(
"Executing SetSoapCallback()");
1035#ifdef COMPA_HAVE_DEVICE_GENA
1037 TRACE(
"Executing SetGenaCallback()");
1043 [[maybe_unused]] in_port_t* listen_port6,
1044 [[maybe_unused]] in_port_t* listen_port6UlaGua) {
1045 UPnPsdk_LOGINFO(
"MSG1068")
"Executing...\n";
1046 constexpr int max_count{10000};
1051 memset(&job, 0,
sizeof(job));
1055 UPnPsdk_LOGERR(
"MSG1087")
"Cannot start. Miniserver is running.\n";
1065#ifdef COMPA_HAVE_WEBSERVER
1069 miniSocket->pSockLlaObj = &sockLlaObj;
1071 miniSocket->pSockGuaObj = &sockGuaObj;
1073 miniSocket->pSockIp4Obj = &sockIp4Obj;
1077 *listen_port6UlaGua);
1093#if defined(COMPA_HAVE_CTRLPT_SSDP) || defined(COMPA_HAVE_DEVICE_SSDP)
1095 ret_code = umock::pupnp_ssdp.get_ssdp_sockets(miniSocket);
1110 if (ret_code != 0) {
1118#ifdef COMPA_HAVE_CTRLPT_SSDP
1129 std::this_thread::sleep_for(std::chrono::milliseconds(50));
1132 if (count >= max_count) {
1141#ifdef COMPA_HAVE_CTRLPT_SSDP
1147#ifdef COMPA_HAVE_WEBSERVER
1157 UpnpPrintf(UPNP_INFO, MSERV, __FILE__, __LINE__,
1158 "Inside StopMiniServer()\n");
1160 socklen_t socklen =
sizeof(
struct sockaddr_in);
1162 sockaddr_in ssdpAddr;
1163 char buf[256] =
"ShutDown";
1165 size_t bufLen = strlen(buf);
1174 sock = umock::sys_socket_h.socket(AF_INET, SOCK_DGRAM, 0);
1175 if (sock == INVALID_SOCKET) {
1176 UpnpPrintf(UPNP_ERROR, SSDP, __FILE__, __LINE__,
1177 "SSDP_SERVER: StopSSDPServer: Error in socket() %s\n",
1178 std::strerror(errno));
1182 ssdpAddr.sin_family = (sa_family_t)AF_INET;
1183 inet_pton(AF_INET,
"127.0.0.1", &ssdpAddr.sin_addr);
1185 umock::sys_socket_h.sendto(sock, buf, (SIZEP_T)bufLen, 0,
1186 reinterpret_cast<sockaddr*
>(&ssdpAddr),
1188 std::this_thread::sleep_for(std::chrono::milliseconds(1));
1192 std::this_thread::sleep_for(std::chrono::seconds(1));
#define UPNP_E_NO_WEB_SERVER
The operation completed successfully.
int http_SendMessage(SOCKINFO *info, int *TimeOut, const char *fmt,...)
Sends a message to the destination based on the format parameter.
int http_SendStatusResponse(SOCKINFO *info, int http_status_code, int request_major_version, int request_minor_version)
Generate a response message for the status query and send the status response.
int http_RecvMessage(SOCKINFO *info, http_parser_t *parser, http_method_t request_method, int *timeout_secs, int *http_error_code)
Get the data on the socket and take actions based on the read data to modify the parser objects buffe...
http_message_t msg
entire raw message
http_method_t method
Http method of an outgoing request.
int major_version
Http major version.
#define HDR_HOST
Type of a HTTP header.
int minor_version
Http minor version.
Structure of an HTTP parser object.
Structure of an HTTP message.
#define HTTP_DEFAULT_TIMEOUT
int ThreadPoolAdd(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a job to the thread pool.
int TPJobSetFreeFunction(ThreadPoolJob *job, free_routine func)
Sets the jobs free function.
int TPJobSetPriority(ThreadPoolJob *job, ThreadPriority priority)
Sets the priority of the threadpool job.
int TPJobInit(ThreadPoolJob *job, UPnPsdk::start_routine func, void *arg)
Initializes thread pool job.
int ThreadPoolAddPersistent(ThreadPool *tp, ThreadPoolJob *job, int *jobId)
Adds a persistent job to the thread pool.
void(* free_routine)(void *arg)
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.
Get information from a raw network socket file descriptor.
bool local_saddr(SSockaddr *a_saddr=nullptr) const
Get the local socket address the socket is bound to.
void load()
Load the raw socket file descriptor specified with the constructor into the object.
Manage all aspects of a network socket.
void listen()
Set socket to listen.
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.
int readFromSSDPSocket(SOCKET socket)
This function reads the data from the ssdp socket.
int(* WebCallback_HostValidate)(const char *hostname, void *cookie)
Callback for validating HTTP requests HOST header values.
Helpful union of the different socket address structures.
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'.
void httpmsg_destroy(http_message_t *msg)
Free memory allocated for the http message.
void membuffer_destroy(membuffer *m)
Free's memory allocated for membuffer* m.
void membuffer_init(membuffer *m)
Wrapper to membuffer_initialize().
int membuffer_append_str(membuffer *m, const char *c_str)
Invokes function to appends data from a constant string to the buffer.
size_t length
length of buffer without terminating null byte (read-only).
char * buf
mem buffer; must not write beyond buf[length-1] (read/write).
size_t length
length of memory (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_SOCKET_BIND
The SDK had a problem binding a socket to a network interface.
#define UPNP_E_BAD_HTTPMSG
The HTTP message contains invalid message headers.
#define UPNP_E_SUCCESS
The operation completed successfully.
#define UPNP_E_OUTOF_SOCKET
The SDK cannot create any more sockets.
#define UPNP_E_OUTOF_MEMORY
Not enough resources are currently available to complete the operation.
#define UPNP_E_SOCKET_ACCEPT
The SDK had a problem accepting a network connection.
#define UPNP_E_INTERNAL_ERROR
Generic error code for internal conditions not covered by other error codes.
void SetSoapCallback(MiniServerCallback callback)
Set SOAP Callback.
int StartMiniServer(in_port_t *listen_port4, in_port_t *listen_port6, in_port_t *listen_port6UlaGua)
Initialize the sockets functionality for the Miniserver.
int StopMiniServer()
Stop and Shutdown the MiniServer and free socket resources.
void SetGenaCallback(MiniServerCallback callback)
Set GENA Callback.
Manage "Step 0: Addressing" of the UPnP+™ specification.
in_port_t miniServerPort6
Corresponding port to miniServerSock6.
in_port_t miniServerPort6UlaGua
Corresponding port to miniServerSock6UlaGua.
SOCKET ssdpSock4
IPv4 SSDP datagram Socket for incoming advertisments and search requests.
void(* MiniServerCallback)(http_parser_t *parser, http_message_t *request, SOCKINFO *info)
For a miniserver callback function.
SOCKET miniServerSock6UlaGua
IPv6 ULA or GUA Socket for listening for miniserver requests.
in_port_t stopPort
Corresponding port to miniServerStopSock. This is set with miniStopSockPort but never used.
SOCKET miniServerSock4
IPv4 socket for listening for miniserver requests.
in_port_t miniServerPort4
Corresponding port to miniServerSock4.
MiniServerCallback gGetCallback
HTTP server callback.
SOCKET ssdpReqSock6
IPv6 SSDP socket for sending search requests and receiving search replies.
SOCKET ssdpReqSock4
IPv4 SSDP socket for sending search requests and receiving search replies.
SOCKET miniServerStopSock
Datagram Socket for stopping miniserver.
SOCKET ssdpSock6
IPv6 LLA SSDP Socket for incoming advertisments and search requests.
SOCKET miniServerSock6
IPv6 LLA Socket for listening for miniserver requests.
SOCKET ssdpSock6UlaGua
IPv6 ULA or GUA SSDP Socket for incoming advertisments and search requests.
Provides sockets for all network communications.
UPnPsdk_EXTERN bool g_dbug
Switch to enable verbose (debug) output.
void ssdp_read(SOCKET *rsock, fd_set *set)
Read data from the SSDP socket.
int host_header_is_numeric(char *a_host_port, size_t a_host_port_len)
Check if a network address is numeric.
int get_miniserver_stopsock(MiniServerSockArray *out)
Creates the miniserver STOP socket, usable to listen for stopping the miniserver.
SOCKET connfd
Connection socket file descriptor.
void RunMiniServer(MiniServerSockArray *miniSock)
Run the miniserver.
MiniServerCallback gSoapCallback
SOAP callback.
int web_server_accept(SOCKET listen_sock, fd_set &set)
Accept requested connection from a remote control point and run it in a new thread.
void InitMiniServerSockArray(MiniServerSockArray *miniSocket)
Initialize a miniserver Socket Array.
void schedule_request_job(SOCKET a_connfd, UPnPsdk::SSockaddr &clientAddr)
Initilize the thread pool to handle an incomming request, sets priority for the job and adds the job ...
void free_handle_request_arg(void *args)
Free memory assigned for handling request and unitialize socket functionality.
in_port_t miniStopSockPort
Port of the stop socket.
int getNumericHostRedirection(SOCKET a_socket, char *a_host_port, size_t a_hp_size)
Returns the ip address with port as text that is bound to a socket.
MiniServerCallback gGenaCallback
GENA callback.
int receive_from_stopSock(SOCKET ssock, fd_set *set)
Check if we have received a packet that shall stop the miniserver.
int get_miniserver_sockets(MiniServerSockArray *out, in_port_t listen_port4, in_port_t listen_port6, in_port_t listen_port6UlaGua)
Create STREAM sockets, binds to local network interfaces and listens for incoming connections.
void RunMiniServer_f(MiniServerSockArray *miniSock)
Check if a network address is numeric.
void fdset_if_valid(SOCKET a_sock, fd_set *a_set)
Add a socket file descriptor to an 'fd_set' structure as needed for ::select().
sockaddr_storage foreign_sockaddr
Socket address of the remote control point.
MiniServerState
miniserver state
@ MSERV_RUNNING
miniserver is running.
@ MSERV_IDLE
miniserver is idle.
@ MSERV_STOPPING
miniserver is running to stop.
void handle_request(void *args)
Receive the request and dispatch it for handling.
int dispatch_request(SOCKINFO *a_info, http_parser_t *a_hparser)
Based on the type of message, appropriate callback is issued.
MiniServerState gMServState
miniserver state
int get_port(SOCKET sockfd, uint16_t *port)
Returns port to which socket, sockfd, is bound.
miniserver received request message.
int sock_destroy(SOCKINFO *info, int ShutdownMethod)
Shutsdown the socket using the ShutdownMethod to indicate whether sends and receives on the socket wi...
int sock_init_with_ip(SOCKINFO *info, SOCKET sockfd, sockaddr *foreign_sockaddr)
Calls the sock_init function and assigns the passed in IP address and port to the IP address and port...
SOCKET socket
Handle/descriptor to a socket.
int sock_close(SOCKET sock)
Closes the socket if it is different from -1.
Additional socket information for connections and ssl.
Manage "Step 1: Discovery" of the UPnP+™ specification with SSDP.
Trivial ::sockaddr structures enhanced with methods.
const std::string netaddrp() noexcept
Get the assosiated netaddress with port.
sockaddr & sa
Reference to sockaddr struct.
in_port_t port() const
Get the numeric port.
sockaddr_storage & ss
Reference to sockaddr_storage struct.
WebCallback_HostValidate gWebCallback_HostValidate
webCallback for HOST validation.
char gIF_IPV6_ULA_GUA[INET6_ADDRSTRLEN]
Static buffer to contain interface IPv6 unique-local or globally-unique address (ULA or GUA)....
int gAllowLiteralHostRedirection
Allow literal host names redirection to numeric host names.
void * gWebCallback_HostValidateCookie
Cookie to the webCallback for HOST validation.
char gIF_IPV4[INET_ADDRSTRLEN]
Static buffer to contain interface IPv4 address. (extern'ed in upnp.h)
unsigned gIF_INDEX
Contains network interface index of the link local address gIF_IPV6 that is used as its scope_id.
ThreadPool gMiniServerThreadPool
Mini server thread pool.
char gIF_IPV6[INET6_ADDRSTRLEN]
Static buffer to contain interface IPv6 link-local address (LLA). (extern'ed in upnp....
Inititalize the compatible library before it can be used.
UPnPsdk_VIS void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module, const char *DbgFileName, int DbgLineNo, const char *FmtStr,...)
Prints the debug statement.