Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

upnphandler.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "fast_merge_sort.h"
#include "upnphandler.h"

Defines

#define LESS_THAN_OR_EQUAL_DEV(a, b)   ( strcmp( (a)->key, (b)->key) <= 0 )
#define MSEARCH_DELAY   10
 Method:.

#define MSEARCH_DELAY_STRING   "10"
#define REAPER_CYCLE_TIME   ((AW_TIMESTAMP_PER_SEC)*5)
#define UPNP_URL_MAX_SIZE   1024
#define UUID_PREFIX_LEN   (sizeof(UUID_PREFIX)-1)

Functions

aw_upnphandler_t * aw_create_upnphandler (u_int32_t nregexs, const aw_upnphandler_regex_t *regexs, const byte_t *mcinterface, u_int32_t mcloopback, const aw_alarm_sched_t *sched, aw_logger_t *logger)
 Create a upnphandler.

void aw_free_upnphandler (aw_upnphandler_t *h)
 Free handler and all associated resources.

aw_handler_t * aw_wire_upnphandler (aw_wire_mkhandler_args_t *args)
 Create a upnp handler using "wire". See header doc for keyword documentation.


Define Documentation

#define LESS_THAN_OR_EQUAL_DEV (  a,
b   )     ( strcmp( (a)->key, (b)->key) <= 0 )
 

#define MSEARCH_DELAY   10
 

Method:.

At start, create a sorted list of all USNs, these become the 'up' list. This is done by sending an M-SEARCH message and waiting MSEARCH_DELAY for responses. Since the same record may come multiple times, keep sure the list has all unique records.

Regex match the 'up' list, remember those that matched and their 'command' in a 'watch' list.

Each poll interval:

  • get an update of the sorted group of all USNS via M-SEARCH, call it 'new up' list

  • compute the set difference of a='up' and b='new up'
    • USN in a && in b -> still up, call this the 'old USN' list
    • USN in a && ! in b -> was up, now down, call this the 'dead USN' list
    • USN ! in a && in b -> new up, call this the 'new USN' list

  • loop thru 'dead USN' list, for every USN in 'watch' list, generate an event, use stored 'command', remove from watch list

  • regex match the 'new USN' list, generate events if regex matches, add to 'watch' list

  • set 'up' to be 'new up'

  • free list elements in 'old USN' and 'dead USN'

Between poll intervals:

  • scan watch lists, remove 'old' records

Register to receive signals when there is new data on the 239.255.255.250:1900 socket:

M-SEARCH (*) -> reply with appropriate Search Response with URL w/configured IP/name to deliver device description on this system

NOTIFY (ssdb:alive) -> generate an 'up' event, add to 'up' list, if match regex, add to watch list

NOTIFY (ssdb:byebye) -> generate an 'down' event, remove from 'up' list, if match regex, remove from watch list

[NOTE: Still to do ] Register to receive signals when there is new data on the device description socket:

GET w/URL -> xml data

#define MSEARCH_DELAY_STRING   "10"
 

#define REAPER_CYCLE_TIME   ((AW_TIMESTAMP_PER_SEC)*5)
 

#define UPNP_URL_MAX_SIZE   1024
 

#define UUID_PREFIX_LEN   (sizeof(UUID_PREFIX)-1)
 


Function Documentation

aw_upnphandler_t* aw_create_upnphandler (  u_int32_t  nregexs,
const aw_upnphandler_regex_t *  regexs,
const byte_t *  mcinterface,
u_int32_t  mcloopback,
const aw_alarm_sched_t *  sched,
aw_logger_t *  logger
) 
 

Create a upnphandler.

aw_create_upnphandler

Parameters:
nregexs How many regex strings
regexs Array of regex strings
mcinterface Interface name to send multicast, may be NULL to default
mcloopback If nonzero, then enable multicast to current machine (this is encouraged). If zero, then do not.
sched Run schedule
logger Logger object
Returns:
Handler object

void aw_free_upnphandler (  aw_upnphandler_t *  p  ) 
 

Free handler and all associated resources.

aw_free_upnphandler

Parameters:
p The handler

aw_handler_t* aw_wire_upnphandler (  aw_wire_mkhandler_args_t *  args  ) 
 

Create a upnp handler using "wire". See header doc for keyword documentation.

aw_wire_upnphandler

Aware 0.11.1 Copyright (C) 1998-2005 Russell Leighton (russ@elegant-software.com)