cdevice.c File Reference

#include <cybergarage/upnp/cdevice.h>
#include <cybergarage/upnp/ccontrolpoint.h>
#include <cybergarage/upnp/cupnp_limit.h>
#include <cybergarage/util/ctime.h>
#include <cybergarage/net/cinterface.h>
#include <cybergarage/net/curl.h>
#include <cybergarage/upnp/cupnp_function.h>
#include <cybergarage/upnp/ssdp/cssdp.h>
#include <cybergarage/upnp/ssdp/cssdp_server.h>
#include <cybergarage/upnp/control/ccontrol.h>
#include <cybergarage/io/cfile.h>
#include <cybergarage/util/clog.h>
#include <cybergarage/util/cstring.h>

Functions

static void cg_upnp_device_initchildnodes (CgUpnpDevice *dev)
static void cg_upnp_device_initdevicelist (CgUpnpDevice *dev)
static void cg_upnp_device_initservicelist (CgUpnpDevice *dev)
static void cg_upnp_device_initiconlist (CgUpnpDevice *dev)
static void cg_upnp_device_notifywait (CgUpnpDevice *dev)
CgUpnpDevicecg_upnp_device_new ()
void cg_upnp_device_delete (CgUpnpDevice *dev)
void cg_upnp_device_clear (CgUpnpDevice *dev)
void cg_upnp_device_setdevicenode (CgUpnpDevice *dev, CgXmlNode *node)
CgUpnpDevicecg_upnp_device_getrootdevice (CgUpnpDevice *dev)
BOOL cg_upnp_device_parsedescription (CgUpnpDevice *dev, char *desciption, int descriptionLen)
BOOL cg_upnp_device_parsedescriptionurl (CgUpnpDevice *dev, CgNetURL *url)
BOOL cg_upnp_device_updatefromssdppacket (CgUpnpDevice *dev, CgUpnpSSDPPacket *ssdpPkt)
char * cg_upnp_devicetype_getidentifier (char *deviceType)
char * cg_upnp_devicetype_geturn (char *deviceType)
char * cg_upnp_devicetype_getdevice (char *deviceType)
char * cg_upnp_devicetype_gettype (char *deviceType)
char * cg_upnp_devicetype_getschematype (char *deviceType)
char * cg_upnp_devicetype_getversion (char *deviceType)
CgUpnpDevicecg_upnp_device_getdevicebytype (CgUpnpDevice *dev, char *type)
CgUpnpDevicecg_upnp_device_getdevicebyexacttype (CgUpnpDevice *dev, char *exacttype)
CgUpnpDevicecg_upnp_device_getdevicebyudn (CgUpnpDevice *dev, char *udn)
CgUpnpDevicecg_upnp_device_getdevicebydescriptionuri (CgUpnpDevice *dev, char *url)
char * cg_upnp_device_getlocationurl (CgUpnpDevice *dev, char *host, char *buf, int bufSize)
char * cg_upnp_device_getnotifydevicent (CgUpnpDevice *dev, char *buf, int bufSize)
char * cg_upnp_device_getnotifydeviceusn (CgUpnpDevice *dev, char *buf, int bufSize)
char * cg_upnp_device_getnotifydevicetypent (CgUpnpDevice *dev, char *buf, int bufSize)
char * cg_upnp_device_getnotifydevicetypeusn (CgUpnpDevice *dev, char *buf, int bufSize)
BOOL cg_upnp_device_announcefrom (CgUpnpDevice *dev, char *bindAddr)
void cg_upnp_device_announce (CgUpnpDevice *dev)
BOOL cg_upnp_device_byebyefrom (CgUpnpDevice *dev, char *bindAddr)
void cg_upnp_device_byebye (CgUpnpDevice *dev)
BOOL cg_upnp_device_postsearchresponse (CgUpnpDevice *dev, CgUpnpSSDPPacket *ssdpPkt, char *st, char *usn)
BOOL cg_upnp_device_start (CgUpnpDevice *dev)
BOOL cg_upnp_device_ipchanged (CgUpnpDevice *dev)
BOOL cg_upnp_device_stop (CgUpnpDevice *dev)
BOOL cg_upnp_device_isrunning (CgUpnpDevice *dev)
CgUpnpServicecg_upnp_device_getservicebyserviceid (CgUpnpDevice *dev, char *serviceId)
CgUpnpServicecg_upnp_device_getservicebyexacttype (CgUpnpDevice *dev, char *type)
CgUpnpServicecg_upnp_device_getservicebytype (CgUpnpDevice *dev, char *type)
CgUpnpServicecg_upnp_device_getservicebyscpdurl (CgUpnpDevice *dev, char *url)
CgUpnpServicecg_upnp_device_getservicebycontrolurl (CgUpnpDevice *dev, char *url)
CgUpnpServicecg_upnp_device_getservicebysid (CgUpnpDevice *dev, char *sid)
void cg_upnp_device_setactionlistener (CgUpnpDevice *dev, CG_UPNP_ACTION_LISTNER actionListner)
void cg_upnp_device_setquerylistener (CgUpnpDevice *dev, CG_UPNP_STATEVARIABLE_LISTNER queryListner)
CgUpnpServicecg_upnp_device_getservicebyeventsuburl (CgUpnpDevice *dev, char *url)
CgUpnpIconcg_upnp_device_getsmallesticonbymimetype (CgUpnpDevice *dev, char *mimeType)
CgUpnpIconcg_upnp_device_getsmallesticon (CgUpnpDevice *dev)
BOOL cg_upnp_device_getabsoluteiconurl (CgUpnpDevice *dev, CgUpnpIcon *icon, CgString *buf)
CgUpnpActioncg_upnp_device_getactionbyname (CgUpnpDevice *dev, char *name)
CgUpnpStateVariablecg_upnp_device_getstatevariablebyname (CgUpnpDevice *dev, char *name)
BOOL cg_upnp_device_addicon (CgUpnpDevice *dev, CgUpnpIcon *icon)
void cg_upnp_device_updateudn (CgUpnpDevice *dev)

Function Documentation

BOOL cg_upnp_device_addicon ( CgUpnpDevice dev,
CgUpnpIcon icon 
)

Get a smallest icon

Parameters:
dev Device in question
icon Icon to add
void cg_upnp_device_announce ( CgUpnpDevice dev  ) 

Broadcast an SSDP:alive to notify control points that the device is available.

Parameters:
dev Device in question
BOOL cg_upnp_device_announcefrom ( CgUpnpDevice dev,
char *  bindAddr 
)
void cg_upnp_device_byebye ( CgUpnpDevice dev  ) 

Broadcast an SSDP:byebye message to notify control points that the device is no longer available.

Parameters:
dev Device in question
BOOL cg_upnp_device_byebyefrom ( CgUpnpDevice dev,
char *  bindAddr 
)
void cg_upnp_device_clear ( CgUpnpDevice dev  ) 

Clear a UPnP device structure. This is an internal function and should not be called from outside.

Parameters:
dev Device in question
void cg_upnp_device_delete ( CgUpnpDevice dev  ) 

Delete a UPnP device

Parameters:
dev Device in question
BOOL cg_upnp_device_getabsoluteiconurl ( CgUpnpDevice dev,
CgUpnpIcon icon,
CgString buf 
)

Get an icon by its index from the device's list of icons

Parameters:
dev Device in question
icon Icon in question
buf Buffer to return the full icon's url
Returns:
TRUE if the absolute url is created, otherwise FALSE.
CgUpnpAction* cg_upnp_device_getactionbyname ( CgUpnpDevice dev,
char *  name 
)

Find an action from a device by its name

Parameters:
dev Device in question
name Name of the action
CgUpnpDevice* cg_upnp_device_getdevicebydescriptionuri ( CgUpnpDevice dev,
char *  url 
)

Find a child device by its description URI.

Parameters:
dev Device in question
url Description URI
CgUpnpDevice* cg_upnp_device_getdevicebyexacttype ( CgUpnpDevice dev,
char *  exacttype 
)

Find a device from the device's children by the type of the device. This function searches for devices, whose *complete type string* matches the given string, including version number. For example: "urn:schemas-upnp-org:device:FooDevice:1". If you need to disregard the version number, use cg_upnp_device_getdevicebytype

Parameters:
dev Device in question
exacttype Type of the device
CgUpnpDevice* cg_upnp_device_getdevicebytype ( CgUpnpDevice dev,
char *  type 
)

Find a device from the device's children by the type of the device. This function searches for devices, whose *type part* (i.e. not including the version) of the device type string matches the given string. For example: "urn:schemas-upnp-org:device:FooDevice". If you need to know the version of a device, use cg_upnp_devicetype_getversion

Parameters:
dev Device in question
type Type of the device
CgUpnpDevice* cg_upnp_device_getdevicebyudn ( CgUpnpDevice dev,
char *  udn 
)

Find a device from the device's children by the UDN of the device.

Parameters:
dev Device in question
udn Type of the device
char* cg_upnp_device_getlocationurl ( CgUpnpDevice dev,
char *  host,
char *  buf,
int  bufSize 
)

Get device's location URL. Transforms the given <host> address to URL form: "http://<host>:<port>/description.xml". Port is usually 80 or 38400. If <host> is an IPv6 address, the address is "http://[<host>]:<port>/description.xml".

Parameters:
dev Device in question
host The device host
buf Buffer to store the resulting URL
bufSize Buffer length
char* cg_upnp_device_getnotifydevicent ( CgUpnpDevice dev,
char *  buf,
int  bufSize 
)

Get the device's Notification Type (NT). For the root device this is "upnp:rootdevice", otherwise the device's UDN (Unique Device Name).

Parameters:
dev The device in question
buf Buffer for the Notification Type
bufSize Buffer length
char* cg_upnp_device_getnotifydevicetypent ( CgUpnpDevice dev,
char *  buf,
int  bufSize 
)

Get the device type

Parameters:
dev The device in question
buf Buffer for the device type
bufSize Buffer length
char* cg_upnp_device_getnotifydevicetypeusn ( CgUpnpDevice dev,
char *  buf,
int  bufSize 
)

Get the device's USN (Unique Service Name). For the root device this is "<UDN>::upnp:rootdevice", otherwise the UDN (Unique Device Name).

Parameters:
dev The device in question
buf Buffer where USN is stored after call
bufSize Buffer size
Returns:
Pointer to buf
char* cg_upnp_device_getnotifydeviceusn ( CgUpnpDevice dev,
char *  buf,
int  bufSize 
)

Get the device's USN (Unique Service Name). For the root device this is "<UDN>::upnp:rootdevice", otherwise the UDN (Unique Device Name).

Parameters:
dev The device in question
CgUpnpDevice* cg_upnp_device_getrootdevice ( CgUpnpDevice dev  ) 

Return the root (i.e. the topmost) device in the device structure

Parameters:
dev Traverses the device tree upwards starting from this device
CgUpnpService* cg_upnp_device_getservicebycontrolurl ( CgUpnpDevice dev,
char *  url 
)

Find a service from a device by its control URL

Parameters:
dev Device in question
url Control URL
CgUpnpService* cg_upnp_device_getservicebyeventsuburl ( CgUpnpDevice dev,
char *  url 
)

Find a service from a device by its event subscription URL

Parameters:
dev Device in question
url Event Subscription URL
CgUpnpService* cg_upnp_device_getservicebyexacttype ( CgUpnpDevice dev,
char *  type 
)

Find a service from the device by the type of the service. This function searches for services, whose *complete type string* matches the given string, including version number. For example: "urn:schemas-upnp-org:service:ContentDirectory:1". If you need to know the version of a service, use cg_upnp_servicetype_getversion

Parameters:
dev Device in question
type Type of the service
CgUpnpService* cg_upnp_device_getservicebyscpdurl ( CgUpnpDevice dev,
char *  url 
)

Find a service from the device by the SCPD (Service Control Protocol Definition) URL of the service.

Parameters:
dev Device in question
url SCPD URL
CgUpnpService* cg_upnp_device_getservicebyserviceid ( CgUpnpDevice dev,
char *  serviceId 
)

Find service from the device by a given serviceId. This function searches recursively device and its subdevices for a service with a given serviceId

Parameters:
dev Device in question
serviceId serviceId of the service
Returns:
service matching the given serviceId
CgUpnpService * cg_upnp_device_getservicebysid ( CgUpnpDevice dev,
char *  sid 
)

Find a service from its Subscription ID

Parameters:
dev Device in question
char* Subscription-ID (SID)
CgUpnpService* cg_upnp_device_getservicebytype ( CgUpnpDevice dev,
char *  type 
)

Find a service from the device by the type of the service. This function searches for services, whose *type part* (i.e. not including the version) of the service type string matches the given string. For example: "urn:schemas-upnp-org:service:ContentDirectory". If you need to know the version of a service, use cg_upnp_servicetype_getversion

Parameters:
dev Device in question
type Type of the service
CgUpnpIcon* cg_upnp_device_getsmallesticon ( CgUpnpDevice dev  ) 

Get a smallest icon

Parameters:
dev Device in question
Returns:
A smallest icon.
CgUpnpIcon* cg_upnp_device_getsmallesticonbymimetype ( CgUpnpDevice dev,
char *  mimeType 
)

Get a smallest icon of a specified mime type

Parameters:
dev Device in question
mimeType Mime type to get
Returns:
A smallest icon.
CgUpnpStateVariable* cg_upnp_device_getstatevariablebyname ( CgUpnpDevice dev,
char *  name 
)

Find a state variable from a device by its name

Parameters:
dev Device in question
name Name of the state variable
static void cg_upnp_device_initchildnodes ( CgUpnpDevice dev  )  [static]
static void cg_upnp_device_initdevicelist ( CgUpnpDevice dev  )  [static]
static void cg_upnp_device_initiconlist ( CgUpnpDevice dev  )  [static]
static void cg_upnp_device_initservicelist ( CgUpnpDevice dev  )  [static]
BOOL cg_upnp_device_ipchanged ( CgUpnpDevice dev  ) 

Notify device that IP address of the host has been changed.

Parameters:
dev dev The device in question
Returns:
success of changing used interfaces
BOOL cg_upnp_device_isrunning ( CgUpnpDevice dev  ) 

Check if the device] has been started

Parameters:
dev Device that is being advertised
CgUpnpDevice* cg_upnp_device_new (  ) 

Create a new UPnP device

static void cg_upnp_device_notifywait ( CgUpnpDevice dev  )  [static]
BOOL cg_upnp_device_parsedescription ( CgUpnpDevice dev,
char *  desciption,
int  descriptionLen 
)

Parse the device description XML document.

Parameters:
dev Device in question
description Buffer containing the device description in XML format
descriptionLen Buffer length
Returns:
TRUE, if the buffer was successfully parsed; otherwise FALSE
BOOL cg_upnp_device_parsedescriptionurl ( CgUpnpDevice dev,
CgNetURL url 
)

Fetch and parse the device description XML file, located in the given URL.

Parameters:
dev Device in question
url An internet resource
Returns:
TRUE, if the buffer was successfully parsed; otherwise FALSE
BOOL cg_upnp_device_postsearchresponse ( CgUpnpDevice dev,
CgUpnpSSDPPacket ssdpPkt,
char *  st,
char *  usn 
)

Post a response to an SSDP search message

Parameters:
dev The device in question
ssdpPkt Received SSDP packet
st Service Type (ST)
usn Unique Service Name (USN)
void cg_upnp_device_setactionlistener ( CgUpnpDevice dev,
CG_UPNP_ACTION_LISTNER  actionListner 
)

Set an action listener to the device. Actions are basically commands, that the device (service) responds to.

Parameters:
dev Device in question
actionListener The action listener
void cg_upnp_device_setdevicenode ( CgUpnpDevice dev,
CgXmlNode node 
)

Set the device description node and initialise its child nodes

Parameters:
dev Device in question
node The XML structure to be set as the device's description
void cg_upnp_device_setquerylistener ( CgUpnpDevice dev,
CG_UPNP_STATEVARIABLE_LISTNER  queryListner 
)

Set a query listener to the device. Queries are meant for state variables.

Parameters:
dev Device in question
actionListener The query listener
BOOL cg_upnp_device_start ( CgUpnpDevice dev  ) 

Start the device. This essentially starts:

  • The HTTP server
  • The SSDP server
  • Advertising the device
  • Alive notification
Parameters:
dev Device in question
BOOL cg_upnp_device_stop ( CgUpnpDevice dev  ) 

Stop the device. This concerns:

  • The HTTP server
  • The SSDP server
  • Advertising the device
  • Byebye notification
Parameters:
dev Device in question
BOOL cg_upnp_device_updatefromssdppacket ( CgUpnpDevice dev,
CgUpnpSSDPPacket ssdpPkt 
)

Update the device's contents from an SSDP packet if necessary.

Parameters:
dev The device to potentially update
ssdpPkt The SSDP packet to make decisions on
Returns:
TRUE if the device was updated; otherwise FALSE
void cg_upnp_device_updateudn ( CgUpnpDevice dev  ) 

Update new Unique Device Name (UDN)

Parameters:
dev Device in question
char* cg_upnp_devicetype_getdevice ( char *  deviceType  ) 

Get the device part of a device type string (usually just "device")

Parameters:
deviceType A device type string (usually the result from cg_upnp_device_getdevicetype)
Returns:
A newly-created char* if successful; otherwise NULL
char* cg_upnp_devicetype_getidentifier ( char *  deviceType  ) 

Get the identifier-part of a device type string (usually "urn")

Parameters:
deviceType A device type string (usually the result from cg_upnp_device_getdevicetype)
Returns:
A newly-created char* if successful; otherwise NULL
char* cg_upnp_devicetype_getschematype ( char *  deviceType  ) 

Get the schema type part of a device type string (without last colon) (ex. "urn:schemas-upnp-org:device:ContentDirectory")

Parameters:
deviceType A device type string (usually the result from cg_upnp_device_getdevicetype)
Returns:
A newly-created char* if successful; otherwise NULL
char* cg_upnp_devicetype_gettype ( char *  deviceType  ) 

Get the type part of a device type string (ex. "ContentDirectory")

Parameters:
deviceType A device type string (usually the result from cg_upnp_device_getdevicetype)
Returns:
A newly-created char* if successful; otherwise NULL
char* cg_upnp_devicetype_geturn ( char *  deviceType  ) 

Get the URN part of a device type string (usually "schemas-upnp-org")

Parameters:
deviceType A device type string (usually the result from cg_upnp_device_getdevicetype)
Returns:
A newly-created char* if successful; otherwise NULL
char* cg_upnp_devicetype_getversion ( char *  deviceType  ) 

Get the version part of a device type string (ex. "1")

Parameters:
deviceType A device type string (usually the result from cg_upnp_device_getdevicetype)
Returns:
A newly-created char* if successful; otherwise NULL

Generated on Tue Feb 23 23:14:24 2010 for CyberLink for C by  doxygen 1.6.1