mUPnP for C
device.c File Reference

Functions

static void mupnp_device_initchildnodes (mUpnpDevice *dev)
 
static void mupnp_device_initdevicelist (mUpnpDevice *dev)
 
static void mupnp_device_initservicelist (mUpnpDevice *dev)
 
static void mupnp_device_initiconlist (mUpnpDevice *dev)
 
static void mupnp_device_notifywait (mUpnpDevice *dev)
 
mUpnpDevicemupnp_device_new ()
 
void mupnp_device_delete (mUpnpDevice *dev)
 
void mupnp_device_clear (mUpnpDevice *dev)
 
void mupnp_device_setdevicenode (mUpnpDevice *dev, mUpnpXmlNode *node)
 
mUpnpDevicemupnp_device_getrootdevice (mUpnpDevice *dev)
 
bool mupnp_device_parsedescription (mUpnpDevice *dev, const char *desciption, size_t descriptionLen)
 
bool mupnp_device_parsedescriptionurl (mUpnpDevice *dev, mUpnpNetURL *url)
 
bool mupnp_device_updatefromssdppacket (mUpnpDevice *dev, mUpnpSSDPPacket *ssdpPkt)
 
char * mupnp_devicetype_getidentifier (const char *deviceType)
 
char * mupnp_devicetype_geturn (const char *deviceType)
 
char * mupnp_devicetype_getdevice (const char *deviceType)
 
char * mupnp_devicetype_gettype (const char *deviceType)
 
char * mupnp_devicetype_getschematype (const char *deviceType)
 
char * mupnp_devicetype_getversion (const char *deviceType)
 
mUpnpDevicemupnp_device_getdevicebytype (mUpnpDevice *dev, const char *type)
 
mUpnpDevicemupnp_device_getdevicebyexacttype (mUpnpDevice *dev, const char *exacttype)
 
mUpnpDevicemupnp_device_getdevicebyudn (mUpnpDevice *dev, const char *udn)
 
mUpnpDevicemupnp_device_getdevicebydescriptionuri (mUpnpDevice *dev, const char *url)
 
const char * mupnp_device_getlocationurl (mUpnpDevice *dev, const char *host, char *buf, int bufSize)
 
char * mupnp_device_getnotifydevicent (mUpnpDevice *dev, char *buf, int bufSize)
 
char * mupnp_device_getnotifydeviceusn (mUpnpDevice *dev, char *buf, int bufSize)
 
char * mupnp_device_getnotifydevicetypent (mUpnpDevice *dev, char *buf, int bufSize)
 
char * mupnp_device_getnotifydevicetypeusn (mUpnpDevice *dev, char *buf, int bufSize)
 
bool mupnp_device_announcefrom (mUpnpDevice *dev, char *bindAddr)
 
void mupnp_device_announce (mUpnpDevice *dev)
 
bool mupnp_device_byebyefrom (mUpnpDevice *dev, char *bindAddr)
 
void mupnp_device_byebye (mUpnpDevice *dev)
 
bool mupnp_device_postsearchresponse (mUpnpDevice *dev, mUpnpSSDPPacket *ssdpPkt, const char *st, const char *usn)
 
bool mupnp_device_start (mUpnpDevice *dev)
 
bool mupnp_device_ipchanged (mUpnpDevice *dev)
 
bool mupnp_device_stop (mUpnpDevice *dev)
 
bool mupnp_device_isrunning (mUpnpDevice *dev)
 
mUpnpServicemupnp_device_getservicebyserviceid (mUpnpDevice *dev, const char *serviceId)
 
mUpnpServicemupnp_device_getservicebyexacttype (mUpnpDevice *dev, const char *type)
 
mUpnpServicemupnp_device_getservicebytype (mUpnpDevice *dev, const char *type)
 
mUpnpServicemupnp_device_getservicebyscpdurl (mUpnpDevice *dev, const char *url)
 
mUpnpServicemupnp_device_getservicebycontrolurl (mUpnpDevice *dev, const char *url)
 
mUpnpServicemupnp_device_getservicebysid (mUpnpDevice *dev, const char *sid)
 
void mupnp_device_setactionlistener (mUpnpDevice *dev, MUPNP_ACTION_LISTNER actionListner)
 
void mupnp_device_setquerylistener (mUpnpDevice *dev, MUPNP_STATEVARIABLE_LISTNER queryListner)
 
mUpnpServicemupnp_device_getservicebyeventsuburl (mUpnpDevice *dev, const char *url)
 
mUpnpIconmupnp_device_getsmallesticonbymimetype (mUpnpDevice *dev, const char *mimeType)
 
mUpnpIconmupnp_device_getsmallesticon (mUpnpDevice *dev)
 
bool mupnp_device_getabsoluteiconurl (mUpnpDevice *dev, mUpnpIcon *icon, mUpnpString *buf)
 
mUpnpActionmupnp_device_getactionbyname (mUpnpDevice *dev, const char *name)
 
mUpnpStateVariablemupnp_device_getstatevariablebyname (mUpnpDevice *dev, const char *name)
 
bool mupnp_device_addicon (mUpnpDevice *dev, mUpnpIcon *icon)
 
void mupnp_device_updateudn (mUpnpDevice *dev)
 
void mupnp_device_setpresentationlistener (mUpnpDevice *dev, MUPNP_PRESENTATION_LISTNER func)
 

Function Documentation

◆ mupnp_device_addicon()

bool mupnp_device_addicon ( mUpnpDevice * dev,
mUpnpIcon * icon )

Get a smallest icon

Parameters
devDevice in question
iconIcon to add

◆ mupnp_device_announce()

void mupnp_device_announce ( mUpnpDevice * dev)

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

Parameters
devDevice in question

◆ mupnp_device_announcefrom()

bool mupnp_device_announcefrom ( mUpnpDevice * dev,
char * bindAddr )

◆ mupnp_device_byebye()

void mupnp_device_byebye ( mUpnpDevice * dev)

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

Parameters
devDevice in question

◆ mupnp_device_byebyefrom()

bool mupnp_device_byebyefrom ( mUpnpDevice * dev,
char * bindAddr )

◆ mupnp_device_clear()

void mupnp_device_clear ( mUpnpDevice * dev)

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

Parameters
devDevice in question

◆ mupnp_device_delete()

void mupnp_device_delete ( mUpnpDevice * dev)

Delete a UPnP device

Parameters
devDevice in question

◆ mupnp_device_getabsoluteiconurl()

bool mupnp_device_getabsoluteiconurl ( mUpnpDevice * dev,
mUpnpIcon * icon,
mUpnpString * buf )

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

Parameters
devDevice in question
iconIcon in question
bufBuffer to return the full icon's url
Returns
true if the absolute url is created, otherwise false.

◆ mupnp_device_getactionbyname()

mUpnpAction * mupnp_device_getactionbyname ( mUpnpDevice * dev,
const char * name )

Find an action from a device by its name

Parameters
devDevice in question
nameName of the action

◆ mupnp_device_getdevicebydescriptionuri()

mUpnpDevice * mupnp_device_getdevicebydescriptionuri ( mUpnpDevice * dev,
const char * url )

Find a child device by its description URI.

Parameters
devDevice in question
urlDescription URI

◆ mupnp_device_getdevicebyexacttype()

mUpnpDevice * mupnp_device_getdevicebyexacttype ( mUpnpDevice * dev,
const 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 mupnp_device_getdevicebytype

Parameters
devDevice in question
exacttypeType of the device

◆ mupnp_device_getdevicebytype()

mUpnpDevice * mupnp_device_getdevicebytype ( mUpnpDevice * dev,
const 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 mupnp_devicetype_getversion

Parameters
devDevice in question
typeType of the device

◆ mupnp_device_getdevicebyudn()

mUpnpDevice * mupnp_device_getdevicebyudn ( mUpnpDevice * dev,
const char * udn )

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

Parameters
devDevice in question
udnType of the device

◆ mupnp_device_getlocationurl()

const char * mupnp_device_getlocationurl ( mUpnpDevice * dev,
const 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
devDevice in question
hostThe device host
bufBuffer to store the resulting URL
bufSizeBuffer length

◆ mupnp_device_getnotifydevicent()

char * mupnp_device_getnotifydevicent ( mUpnpDevice * 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
devThe device in question
bufBuffer for the Notification Type
bufSizeBuffer length

◆ mupnp_device_getnotifydevicetypent()

char * mupnp_device_getnotifydevicetypent ( mUpnpDevice * dev,
char * buf,
int bufSize )

Get the device type

Parameters
devThe device in question
bufBuffer for the device type
bufSizeBuffer length

◆ mupnp_device_getnotifydevicetypeusn()

char * mupnp_device_getnotifydevicetypeusn ( mUpnpDevice * 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
devThe device in question
bufBuffer where USN is stored after call
bufSizeBuffer size
Returns
Pointer to buf

◆ mupnp_device_getnotifydeviceusn()

char * mupnp_device_getnotifydeviceusn ( mUpnpDevice * 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
devThe device in question

◆ mupnp_device_getrootdevice()

mUpnpDevice * mupnp_device_getrootdevice ( mUpnpDevice * dev)

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

Parameters
devTraverses the device tree upwards starting from this device

◆ mupnp_device_getservicebycontrolurl()

mUpnpService * mupnp_device_getservicebycontrolurl ( mUpnpDevice * dev,
const char * url )

Find a service from a device by its control URL

Parameters
devDevice in question
urlControl URL

◆ mupnp_device_getservicebyeventsuburl()

mUpnpService * mupnp_device_getservicebyeventsuburl ( mUpnpDevice * dev,
const char * url )

Find a service from a device by its event subscription URL

Parameters
devDevice in question
urlEvent Subscription URL

◆ mupnp_device_getservicebyexacttype()

mUpnpService * mupnp_device_getservicebyexacttype ( mUpnpDevice * dev,
const 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 mupnp_servicetype_getversion

Parameters
devDevice in question
typeType of the service

◆ mupnp_device_getservicebyscpdurl()

mUpnpService * mupnp_device_getservicebyscpdurl ( mUpnpDevice * dev,
const char * url )

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

Parameters
devDevice in question
urlSCPD URL

◆ mupnp_device_getservicebyserviceid()

mUpnpService * mupnp_device_getservicebyserviceid ( mUpnpDevice * dev,
const 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
devDevice in question
serviceIdserviceId of the service
Returns
service matching the given serviceId

◆ mupnp_device_getservicebysid()

mUpnpService * mupnp_device_getservicebysid ( mUpnpDevice * dev,
const char * sid )

Find a service from its Subscription ID

Parameters
devDevice in question
char*Subscription-ID (SID)

◆ mupnp_device_getservicebytype()

mUpnpService * mupnp_device_getservicebytype ( mUpnpDevice * dev,
const 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 mupnp_servicetype_getversion

Parameters
devDevice in question
typeType of the service

◆ mupnp_device_getsmallesticon()

mUpnpIcon * mupnp_device_getsmallesticon ( mUpnpDevice * dev)

Get a smallest icon

Parameters
devDevice in question
Returns
A smallest icon.

◆ mupnp_device_getsmallesticonbymimetype()

mUpnpIcon * mupnp_device_getsmallesticonbymimetype ( mUpnpDevice * dev,
const char * mimeType )

Get a smallest icon of a specified mime type

Parameters
devDevice in question
mimeTypeMime type to get
Returns
A smallest icon.

◆ mupnp_device_getstatevariablebyname()

mUpnpStateVariable * mupnp_device_getstatevariablebyname ( mUpnpDevice * dev,
const char * name )

Find a state variable from a device by its name

Parameters
devDevice in question
nameName of the state variable

◆ mupnp_device_initchildnodes()

static void mupnp_device_initchildnodes ( mUpnpDevice * dev)
static

◆ mupnp_device_initdevicelist()

static void mupnp_device_initdevicelist ( mUpnpDevice * dev)
static

◆ mupnp_device_initiconlist()

static void mupnp_device_initiconlist ( mUpnpDevice * dev)
static

◆ mupnp_device_initservicelist()

static void mupnp_device_initservicelist ( mUpnpDevice * dev)
static

◆ mupnp_device_ipchanged()

bool mupnp_device_ipchanged ( mUpnpDevice * dev)

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

Parameters
devdev The device in question
Returns
success of changing used interfaces

◆ mupnp_device_isrunning()

bool mupnp_device_isrunning ( mUpnpDevice * dev)

Check if the device] has been started

Parameters
devDevice that is being advertised

◆ mupnp_device_new()

mUpnpDevice * mupnp_device_new ( void )

Create a new UPnP device

◆ mupnp_device_notifywait()

static void mupnp_device_notifywait ( mUpnpDevice * dev)
static

◆ mupnp_device_parsedescription()

bool mupnp_device_parsedescription ( mUpnpDevice * dev,
const char * desciption,
size_t descriptionLen )

Parse the device description XML document.

Parameters
devDevice in question
descriptionBuffer containing the device description in XML format
descriptionLenBuffer length
Returns
true, if the buffer was successfully parsed; otherwise false

◆ mupnp_device_parsedescriptionurl()

bool mupnp_device_parsedescriptionurl ( mUpnpDevice * dev,
mUpnpNetURL * url )

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

Parameters
devDevice in question
urlAn internet resource
Returns
true, if the buffer was successfully parsed; otherwise false

◆ mupnp_device_postsearchresponse()

bool mupnp_device_postsearchresponse ( mUpnpDevice * dev,
mUpnpSSDPPacket * ssdpPkt,
const char * st,
const char * usn )

Post a response to an SSDP search message

Parameters
devThe device in question
ssdpPktReceived SSDP packet
stService Type (ST)
usnUnique Service Name (USN)

◆ mupnp_device_setactionlistener()

void mupnp_device_setactionlistener ( mUpnpDevice * dev,
MUPNP_ACTION_LISTNER actionListner )

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

Parameters
devDevice in question
actionListenerThe action listener

◆ mupnp_device_setdevicenode()

void mupnp_device_setdevicenode ( mUpnpDevice * dev,
mUpnpXmlNode * node )

Set the device description node and initialise its child nodes

Parameters
devDevice in question
nodeThe XML structure to be set as the device's description

◆ mupnp_device_setpresentationlistener()

void mupnp_device_setpresentationlistener ( mUpnpDevice * dev,
MUPNP_PRESENTATION_LISTNER func )

◆ mupnp_device_setquerylistener()

void mupnp_device_setquerylistener ( mUpnpDevice * dev,
MUPNP_STATEVARIABLE_LISTNER queryListner )

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

Parameters
devDevice in question
actionListenerThe query listener

◆ mupnp_device_start()

bool mupnp_device_start ( mUpnpDevice * dev)

Start the device. This essentially starts:

  • The HTTP server
  • The SSDP server
  • Advertising the device
  • Alive notification
Parameters
devDevice in question

◆ mupnp_device_stop()

bool mupnp_device_stop ( mUpnpDevice * dev)

Stop the device. This concerns:

  • The HTTP server
  • The SSDP server
  • Advertising the device
  • Byebye notification
Parameters
devDevice in question

◆ mupnp_device_updatefromssdppacket()

bool mupnp_device_updatefromssdppacket ( mUpnpDevice * dev,
mUpnpSSDPPacket * ssdpPkt )

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

Parameters
devThe device to potentially update
ssdpPktThe SSDP packet to make decisions on
Returns
true if the device was updated; otherwise false

◆ mupnp_device_updateudn()

void mupnp_device_updateudn ( mUpnpDevice * dev)

Update new Unique Device Name (UDN)

Parameters
devDevice in question

◆ mupnp_devicetype_getdevice()

char * mupnp_devicetype_getdevice ( const char * deviceType)

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

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

◆ mupnp_devicetype_getidentifier()

char * mupnp_devicetype_getidentifier ( const char * deviceType)

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

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

◆ mupnp_devicetype_getschematype()

char * mupnp_devicetype_getschematype ( const char * deviceType)

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

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

◆ mupnp_devicetype_gettype()

char * mupnp_devicetype_gettype ( const char * deviceType)

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

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

◆ mupnp_devicetype_geturn()

char * mupnp_devicetype_geturn ( const char * deviceType)

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

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

◆ mupnp_devicetype_getversion()

char * mupnp_devicetype_getversion ( const char * deviceType)

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

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