Implements the functionality and utility functions used by the Miniserver module. More...
#include <miniserver.hpp>
#include <httpreadwrite.hpp>
#include <ssdp_common.hpp>
#include <statcodes.hpp>
#include <upnpapi.hpp>
#include <umock/sys_socket.hpp>
#include <umock/stdlib.hpp>
#include <umock/pupnp_miniserver.hpp>
#include <umock/pupnp_ssdp.hpp>
Go to the source code of this file.
Classes | |
struct | anonymous_namespace{miniserver.cpp}::mserv_request_t |
miniserver received request message. More... | |
Functions | |
void | SetSoapCallback (MiniServerCallback callback) |
Set SOAP Callback. | |
void | SetGenaCallback (MiniServerCallback callback) |
Set GENA 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. | |
Scope restricted to file | |
int | anonymous_namespace{miniserver.cpp}::host_header_is_numeric (char *a_host_port, size_t a_host_port_len) |
Check if a network address is numeric. | |
int | anonymous_namespace{miniserver.cpp}::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. | |
int | anonymous_namespace{miniserver.cpp}::dispatch_request (SOCKINFO *a_info, http_parser_t *a_hparser) |
Based on the type of message, appropriate callback is issued. | |
void | anonymous_namespace{miniserver.cpp}::free_handle_request_arg (void *args) |
Free memory assigned for handling request and unitialize socket functionality. | |
void | anonymous_namespace{miniserver.cpp}::handle_request (void *args) |
Receive the request and dispatch it for handling. | |
void | anonymous_namespace{miniserver.cpp}::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 to the thread pool. | |
void | anonymous_namespace{miniserver.cpp}::fdset_if_valid (SOCKET a_sock, fd_set *a_set) |
Add a socket file descriptor to an 'fd_set' structure as needed for ::select() . | |
int | anonymous_namespace{miniserver.cpp}::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 | anonymous_namespace{miniserver.cpp}::ssdp_read (SOCKET *rsock, fd_set *set) |
Read data from the SSDP socket. | |
int | anonymous_namespace{miniserver.cpp}::receive_from_stopSock (SOCKET ssock, fd_set *set) |
Check if we have received a packet that shall stop the miniserver. | |
void | anonymous_namespace{miniserver.cpp}::RunMiniServer (MiniServerSockArray *miniSock) |
Run the miniserver. | |
void | anonymous_namespace{miniserver.cpp}::RunMiniServer_f (MiniServerSockArray *miniSock) |
Check if a network address is numeric. | |
int | anonymous_namespace{miniserver.cpp}::get_port (SOCKET sockfd, uint16_t *port) |
Returns port to which socket, sockfd, is bound. | |
int | anonymous_namespace{miniserver.cpp}::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. | |
int | anonymous_namespace{miniserver.cpp}::get_miniserver_stopsock (MiniServerSockArray *out) |
Creates the miniserver STOP socket, usable to listen for stopping the miniserver. | |
void | anonymous_namespace{miniserver.cpp}::InitMiniServerSockArray (MiniServerSockArray *miniSocket) |
Initialize a miniserver Socket Array. | |
Variables | |
in_port_t | anonymous_namespace{miniserver.cpp}::miniStopSockPort |
Port of the stop socket. | |
MiniServerState | anonymous_namespace{miniserver.cpp}::gMServState {MSERV_IDLE} |
miniserver state | |
MiniServerCallback | anonymous_namespace{miniserver.cpp}::gSoapCallback {nullptr} |
SOAP callback. | |
MiniServerCallback | anonymous_namespace{miniserver.cpp}::gGenaCallback {nullptr} |
GENA callback. | |
Implements the functionality and utility functions used by the Miniserver module.
The miniserver is a central point for processing all network requests. It is made of:
Definition in file miniserver.cpp.
struct anonymous_namespace{miniserver.cpp}::mserv_request_t |
miniserver received request message.
This defines the structure of a UPnP request that has income from a remote control point.
Definition at line 70 of file miniserver.cpp.
Class Members | ||
---|---|---|
SOCKET | connfd | Connection socket file descriptor. |
sockaddr_storage | foreign_sockaddr | Socket address of the remote control point. |
void SetSoapCallback | ( | MiniServerCallback | callback | ) |
Set SOAP Callback.
[in] | callback | SOAP Callback to be invoked. |
Definition at line 1029 of file miniserver.cpp.
void SetGenaCallback | ( | MiniServerCallback | callback | ) |
Set GENA Callback.
[in] | callback | GENA Callback to be invoked. |
Definition at line 1036 of file miniserver.cpp.
int StartMiniServer | ( | in_port_t * | listen_port4, |
in_port_t * | listen_port6, | ||
in_port_t * | listen_port6UlaGua | ||
) |
Initialize the sockets functionality for the Miniserver.
Initialize a thread pool job to run the MiniServer and the job to the thread pool. If a listening port is specified to 0, then the port number is dynamically picked. Use timer mechanism to start the MiniServer, failure to meet the allowed delay aborts the attempt to launch the MiniServer.
The three parameter are only used if we have also a webserver built in. The miniserver does not need them.
I use a simple random number generator for unspecified port numbers. This is needed because I do not reuse addresses before TIME_WAIT has expired (socket option SO_REUSEADDR = false). I must use different socket addresses to be able to restart a device immediately without TIME_WAIT and that is already given with different port numbers on the same ip address.
[in,out] | listen_port4 | Port on which the server listens for incoming IPv4 connections. |
[in,out] | listen_port6 | Port on which the server listens for incoming IPv6 LLA connections. |
[in,out] | listen_port6UlaGua | Port on which the server listens for incoming IPv6 ULA or GUA connections. |
Definition at line 1042 of file miniserver.cpp.
int StopMiniServer | ( | ) |
Stop and Shutdown the MiniServer and free socket resources.
Definition at line 1156 of file miniserver.cpp.