UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
anonymous_namespace{miniserver.cpp} Namespace Reference

Classes

struct  mserv_request_t
 miniserver received request message. More...
 

Enumerations

enum  MiniServerState { MSERV_IDLE , MSERV_RUNNING , MSERV_STOPPING }
 miniserver state More...
 

Functions

Scope restricted to file
int host_header_is_numeric (char *a_host_port, size_t a_host_port_len)
 Check if a network address is numeric.
 
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.
 
int dispatch_request (SOCKINFO *a_info, http_parser_t *a_hparser)
 Based on the type of message, appropriate callback is issued.
 
void free_handle_request_arg (void *args)
 Free memory assigned for handling request and unitialize socket functionality.
 
void handle_request (void *args)
 Receive the request and dispatch it for handling.
 
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 to the thread pool.
 
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().
 
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 ssdp_read (SOCKET *rsock, fd_set *set)
 Read data from the SSDP socket.
 
int receive_from_stopSock (SOCKET ssock, fd_set *set)
 Check if we have received a packet that shall stop the miniserver.
 
void RunMiniServer (MiniServerSockArray *miniSock)
 Run the miniserver.
 
void RunMiniServer_f (MiniServerSockArray *miniSock)
 Check if a network address is numeric.
 
int get_port (SOCKET sockfd, uint16_t *port)
 Returns port to which socket, sockfd, is bound.
 
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.
 
int get_miniserver_stopsock (MiniServerSockArray *out)
 Creates the miniserver STOP socket, usable to listen for stopping the miniserver.
 
void InitMiniServerSockArray (MiniServerSockArray *miniSocket)
 Initialize a miniserver Socket Array.
 

Variables

in_port_t miniStopSockPort
 Port of the stop socket.
 
MiniServerState gMServState {MSERV_IDLE}
 miniserver state
 
MiniServerCallback gSoapCallback {nullptr}
 SOAP callback.
 
MiniServerCallback gGenaCallback {nullptr}
 GENA callback.
 

Class Documentation

◆ anonymous_namespace{miniserver.cpp}::mserv_request_t

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.

Enumeration Type Documentation

◆ MiniServerState

enum anonymous_namespace{miniserver.cpp}::MiniServerState

miniserver state

Enumerator
MSERV_IDLE 

miniserver is idle.

MSERV_RUNNING 

miniserver is running.

MSERV_STOPPING 

miniserver is running to stop.

Definition at line 78 of file miniserver.cpp.

Function Documentation

◆ host_header_is_numeric()

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.

An empty netaddress or an unspecified one ("[::]", "0.0.0.0") is not valid.

Parameters
a_host_portnetwork address
a_host_port_lenlength of a_host_port excl. terminating '\0'.

Definition at line 107 of file miniserver.cpp.

+ Here is the caller graph for this function:

◆ getNumericHostRedirection()

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.

Example: may return "[2001:db8::ab]:50044" or "192.168.1.2:54321".

Returns
On success: true
On error: false, The result buffer remains unmodified.
Parameters
[in]a_socketSocket file descriptor.
[in,out]a_host_portPointer to buffer that will be filled.
[in]a_hp_sizesize of the buffer.

Definition at line 134 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dispatch_request()

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.

Returns
On success: 0
On error: HTTP_INTERNAL_SERVER_ERROR if Callback is NULL.
Parameters
[in]a_infoSocket Information object.
[in]a_hparserHTTP parser object.

Definition at line 161 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ free_handle_request_arg()

void anonymous_namespace{miniserver.cpp}::free_handle_request_arg ( void *  args)

Free memory assigned for handling request and unitialize socket functionality.

Parameters
[in]argsRequest Message to be freed.

Definition at line 265 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ handle_request()

void anonymous_namespace{miniserver.cpp}::handle_request ( void *  args)

Receive the request and dispatch it for handling.

Parameters
[in]argsPointer to Received Request Message to be handled. It's expected to be mserv_request_t*

Definition at line 279 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ schedule_request_job()

void anonymous_namespace{miniserver.cpp}::schedule_request_job ( SOCKET  a_connfd,
UPnPsdk::SSockaddr clientAddr 
)
inline

Initilize the thread pool to handle an incomming request, sets priority for the job and adds the job to the thread pool.

Parameters
[in]a_connfdSocket Descriptor on which connection is accepted.
[in]clientAddrCtrlpnt address object.

Definition at line 350 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fdset_if_valid()

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().

a_set may already contain file descriptors. The given a_sock is added to the set. It is ensured that ::select() is not fed with invalid socket file descriptors, in particular with the EBADF error. That could mean: closed socket, or an other network error was detected before adding to the set. It checks that we do not use closed or unbind sockets. It also has a guard that we do not exceed the maximum number FD_SETSIZE (1024) of selectable file descriptors, as noted in "man select".

Returns

  • Nothing. Not good, but needed for compatibility.
    You can check if a_sock was added to a_set. There are messages to stderr if verbose logging is enabled.
Parameters
[in]a_socksocket file descriptor.
[out]a_setPointer to an 'fd_set' structure as needed for ::select(). The structure is modified as documented for ::select().

Definition at line 410 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ web_server_accept()

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.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_NO_WEB_SERVER
  • UPNP_E_SOCKET_ERROR
  • UPNP_E_SOCKET_ACCEPT
Parameters
[in]listen_sockFile descriptor of socket that is listening on incomming requests.
[out]setReference to a file descriptor set as needed for ::select().

Definition at line 459 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ssdp_read()

void anonymous_namespace{miniserver.cpp}::ssdp_read ( SOCKET *  rsock,
fd_set *  set 
)

Read data from the SSDP socket.

Parameters
[in]rsockPointer to a Socket file descriptor.
[in]setPointer to a file descriptor set as needed for ::select().

Definition at line 515 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ receive_from_stopSock()

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.

The received datagram must exactly match the shutdown_str from 127.0.0.1. This is a security issue to avoid that the UPnPlib can be terminated from a remote ip address. Receiving 0 bytes on a datagram (there's a datagram here) indicates that a zero-length datagram was successful sent. This will not stop the miniserver.

Returns
  • 1 - when the miniserver shall be stopped,
  • 0 - otherwise.
Parameters
[in]ssockSocket file descriptor.
[in]setPointer to a file descriptor set as needed for ::select().

Definition at line 551 of file miniserver.cpp.

+ Here is the caller graph for this function:

◆ RunMiniServer()

void anonymous_namespace{miniserver.cpp}::RunMiniServer ( MiniServerSockArray miniSock)

Run the miniserver.

The MiniServer accepts a new request and schedules a thread to handle the new request. It checks for socket state and invokes appropriate read and shutdown actions for the Miniserver and SSDP sockets. This function itself runs in its own thread.

Attention
The miniSock parameter must be allocated on the heap before calling the function because it is freed by it.
Parameters
[in]miniSockPointer to an Array containing valid sockets associated with different tasks like listen on a local interface for requests from control points or handle ssdp communication to a remote UPnP node.

Definition at line 614 of file miniserver.cpp.

+ Here is the call graph for this function:

◆ RunMiniServer_f()

void anonymous_namespace{miniserver.cpp}::RunMiniServer_f ( MiniServerSockArray miniSock)

Check if a network address is numeric.

An empty netaddress or an unspecified one ("[::]", "0.0.0.0") is not valid.

Definition at line 781 of file miniserver.cpp.

+ Here is the caller graph for this function:

◆ get_port()

int anonymous_namespace{miniserver.cpp}::get_port ( SOCKET  sockfd,
uint16_t *  port 
)

Returns port to which socket, sockfd, is bound.

Returns
On success: 0
On error: -1 with unmodified system error (errno or WSAGetLastError()).
Parameters
[in]sockfdSocket descriptor.
[out]portThe port value if successful, otherwise, untouched.

Definition at line 793 of file miniserver.cpp.

+ Here is the caller graph for this function:

◆ get_miniserver_sockets()

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.

This is part of starting the miniserver and only available with the webserver compiled in.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_OUTOF_SOCKET - Failed to create a socket.
  • UPNP_E_SOCKET_BIND - Bind() failed.
  • UPNP_E_LISTEN - Listen() failed.
  • UPNP_E_INTERNAL_ERROR - Port returned by the socket layer is < 0.
Parameters
[out]outPointer to a Socket Array that following members will be filled:
  • .miniServerSock6
  • .miniServerPort6
  • .miniServerSock6UlaGua
  • .miniServerPort6UlaGua
  • .miniServerSock4
  • .miniServerPort4
[in]listen_port4port on which the UPnP Device shall listen for incoming IPv4 connections. If 0 then an available port number from the operating system is returned in out.
[in]listen_port6port on which the UPnP Device shall listen for incoming IPv6 LLA connections. If 0 then an available port number from the operating system is returned in out.
[in]listen_port6UlaGuaport on which the UPnP Device shall listen for incoming IPv6 GUA connections. If 0 then an available port number from the operating system is returned in ***out**.

Definition at line 837 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_miniserver_stopsock()

int anonymous_namespace{miniserver.cpp}::get_miniserver_stopsock ( MiniServerSockArray out)

Creates the miniserver STOP socket, usable to listen for stopping the miniserver.

This datagram socket is created and bound to "localhost". It does not listen now but will later be used to listen on to know when it is time to stop the Miniserver.

Returns
On success: UPNP_E_SUCCESS
On error:
  • UPNP_E_OUTOF_SOCKET: Failed to create a socket.
  • UPNP_E_SOCKET_BIND: Bind() failed.
  • UPNP_E_INTERNAL_ERROR: Port returned by the socket layer is < 0.
Parameters
[out]outFills the socket file descriptor and the port it is bound to into the structure.

Definition at line 950 of file miniserver.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ InitMiniServerSockArray()

void anonymous_namespace{miniserver.cpp}::InitMiniServerSockArray ( MiniServerSockArray miniSocket)

Initialize a miniserver Socket Array.

Parameters
miniSocketPointer to a miniserver Socket Array.

Definition at line 998 of file miniserver.cpp.

+ Here is the caller graph for this function:

Variable Documentation

◆ miniStopSockPort

in_port_t anonymous_namespace{miniserver.cpp}::miniStopSockPort

Port of the stop socket.

With starting the miniserver there is also this port registered. Its socket is listing for a "ShutDown" message from a local network address (localhost). This is used to stop the miniserver from another thread.

Definition at line 89 of file miniserver.cpp.

◆ gMServState

MiniServerState anonymous_namespace{miniserver.cpp}::gMServState {MSERV_IDLE}

miniserver state

Definition at line 92 of file miniserver.cpp.

◆ gSoapCallback

MiniServerCallback anonymous_namespace{miniserver.cpp}::gSoapCallback {nullptr}

SOAP callback.

Definition at line 95 of file miniserver.cpp.

◆ gGenaCallback

MiniServerCallback anonymous_namespace{miniserver.cpp}::gGenaCallback {nullptr}

GENA callback.

Definition at line 97 of file miniserver.cpp.