LIBSSDP
 All Classes Files Functions Variables Typedefs Macros
Macros | Functions
ssdp_listener.c File Reference
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <unistd.h>
#include "common_definitions.h"
#include "configuration.h"
#include "log.h"
#include "net_definitions.h"
#include "net_utils.h"
#include "socket_helpers.h"
#include "ssdp_filter.h"
#include "ssdp_cache.h"
#include "ssdp_cache_display.h"
#include "ssdp_cache_output_format.h"
#include "ssdp_common.h"
#include "ssdp_listener.h"
#include "ssdp_message.h"
#include "ssdp_static_defs.h"
Include dependency graph for ssdp_listener.c:

Go to the source code of this file.

Macros

#define LISTEN_QUEUE_LENGTH   5
 
#define SSDP_PASSIVE_LISTENER_TIMEOUT   10
 
#define SSDP_ACTIVE_LISTENER_TIMEOUT   2
 

Functions

static int ssdp_listener_init (ssdp_listener_s *listener, configuration_s *conf, BOOL is_active, int port, int recv_timeout)
 
int ssdp_passive_listener_init (ssdp_listener_s *listener, configuration_s *conf)
 
int ssdp_active_listener_init (ssdp_listener_s *listener, configuration_s *conf, int port)
 
void ssdp_listener_close (ssdp_listener_s *listener)
 
void ssdp_listener_read (ssdp_listener_s *listener, ssdp_recv_node_s *recv_node)
 
int ssdp_listener_start (ssdp_listener_s *listener, configuration_s *conf)
 
void ssdp_listener_stop (ssdp_listener_s *listener)
 

Detailed Description

Create, manage and delete a SSDP listener.

Definition in file ssdp_listener.c.

Macro Definition Documentation

#define LISTEN_QUEUE_LENGTH   5

The queue length for the listener (how many queued connections)

Definition at line 29 of file ssdp_listener.c.

#define SSDP_ACTIVE_LISTENER_TIMEOUT   2

The timeout after which the active SSDP listener will stop waiting for nodes to answer a SEARCH probe/message.

Definition at line 39 of file ssdp_listener.c.

#define SSDP_PASSIVE_LISTENER_TIMEOUT   10

The timeout after which the passive SSDP listener will stop a connection to a discovered node when fetching ewxtra information.

Definition at line 34 of file ssdp_listener.c.

Function Documentation

int ssdp_active_listener_init ( ssdp_listener_s listener,
configuration_s conf,
int  port 
)

Create an active (unicast) SSDP listener. This type of listener is used to listen to SSDP query responses. Sets errno to the error number on failure.

Parameters
listenerThe listener to init.
confThe global configuration.
portThe port to listen at.
Returns
A SSDP listener.

Definition at line 111 of file ssdp_listener.c.

void ssdp_listener_close ( ssdp_listener_s listener)

Destroy the passed SSDP listener.

Parameters
listenerThe SSDP listener to destroy.

Definition at line 118 of file ssdp_listener.c.

static int ssdp_listener_init ( ssdp_listener_s listener,
configuration_s conf,
BOOL  is_active,
int  port,
int  recv_timeout 
)
static

Initialize a SSDP listener. This parses and sets the forwarder address, creates a socket and sets all applicable configuration values to it.

Parameters
listenerThe listener to initialize.
confThe configuration to use.
activeTRUE if an active SSDP listener is to be initialized.
portThe port to listen on. 0 will set the port to the SSDP port.
recv_timeoutThe timeout to set for receiveing/waiting for SSDP nodes to respond to a SEARCH query.
Returns
0 on success, errno otherwise.

Definition at line 54 of file ssdp_listener.c.

void ssdp_listener_read ( ssdp_listener_s listener,
ssdp_recv_node_s recv_node 
)

Read from the listener. Blocks untill timeout if no data to read.

Parameters
listenerThe listener to read from.
recv_nodeInformation about the node (client) that sent data.

Definition at line 127 of file ssdp_listener.c.

int ssdp_listener_start ( ssdp_listener_s listener,
configuration_s conf 
)

Tells the SSDP listener to start listening to SSDP messages. This function should not be called on an active SSDP listener (call ssdp_listener_read() after ssdp_active_listener_init() instead).

Parameters
listenerThe SSDP listener to start.
confThe global configuration to use.

Non-0 value on error. This function does not return if no error ocurrs.

Definition at line 144 of file ssdp_listener.c.

void ssdp_listener_stop ( ssdp_listener_s listener)

Tells the SSDP listener to stop listening.

Parameters
Thelistener to stop.

Definition at line 287 of file ssdp_listener.c.

int ssdp_passive_listener_init ( ssdp_listener_s listener,
configuration_s conf 
)

Create a passive (multicast) SSDP listener. This type of listener is used to passively listen to SSDP messages sent over a network. Sets errno to the error number on failure.

Parameters
listenerThe listener to init.
confthe global configuration.
Returns
A SSDP listener.

Definition at line 104 of file ssdp_listener.c.