mUPnP for C
event.h File Reference
#include <mupnp/typedef.h>
#include <mupnp/http/http.h>
#include <mupnp/util/string.h>
#include <mupnp/util/list.h>
#include <mupnp/event/property.h>
#include <mupnp/service.h>
#include <mupnp/upnp_function.h>

Data Structures

struct  _mUpnpEventListenerList
 

Macros

#define MUPNP_SUBSCRIPTION_SID_SIZE   (MUPNP_UUID_MAX_LEN + 8)
 
#define MUPNP_SUBSCRIPTION_SID_HEADER_SIZE   (5 + MUPNP_SUBSCRIPTION_SID_SIZE)
 
#define MUPNP_SUBSCRIPTION_XMLNS   "urn:schemas-upnp-org:event-1-0"
 
#define MUPNP_SUBSCRIPTION_TIMEOUT_HEADER   "Second-"
 
#define MUPNP_SUBSCRIPTION_INFINITE_STRING   "infinite"
 
#define MUPNP_SUBSCRIPTION_INFINITE_VALUE   (-1)
 
#define MUPNP_SUBSCRIPTION_UUID   "uuid:"
 
#define MUPNP_SUBSCRIPTION_CALLBACK_START_WITH   "<"
 
#define MUPNP_SUBSCRIPTION_CALLBACK_END_WITH   ">"
 
#define MUPNP_SUBSCRIPTION_DELAY   30
 
#define MUPNP_EVENT_MAX_SEQ   2147483647
 
#define MUPNP_SUBSCRIPTION_MAX_TIMEOUT   300
 
#define mupnp_event_subscription_request_new()
 
#define mupnp_event_subscription_request_delete(subReq)
 
#define mupnp_event_subscription_issubscriberequest(subReq)
 
#define mupnp_event_subscription_isunsubscriberequest(subReq)
 
#define mupnp_event_subscription_request_getsid(subReq)
 
#define mupnp_event_subscription_request_hassid(subReq)
 
#define mupnp_event_subscription_request_setnt(subReq, value)
 
#define mupnp_event_subscription_request_getnt(subReq)
 
#define mupnp_event_subscription_request_hasnt(subReq)
 
#define mupnp_event_subscription_request_setcallback(subReq, value)
 
#define mupnp_event_subscription_request_getcallback(subReq)
 
#define mupnp_event_subscription_request_hascallback(subReq)
 
#define mupnp_event_subscription_request_gettimeout(subReq)
 
#define mupnp_event_subscription_request_sethost(subReq, value)
 
#define mupnp_event_subscription_request_gethost(subReq)
 
#define mupnp_event_subscription_request_post(subReq)
 
#define mupnp_event_subscription_request_postresponse(subReq, subRes)
 
#define mupnp_event_subscription_response_new()
 
#define mupnp_event_subscription_response_delete(subRes)
 
#define mupnp_event_subscription_response_issuccessful(subRes)
 
#define mupnp_event_subscription_response_setstatuscode(subRes, code)
 
#define mupnp_event_subscription_response_getstatuscode(subRes, code)
 
#define mupnp_event_subscription_response_getsid(subRes)
 
#define mupnp_event_subscription_response_gettimeout(subRes)
 
#define mupnp_eventlistenerlist_clear(eventListenerList)
 
#define mupnp_eventlistenerlist_size(eventListenerList)
 
#define mupnp_eventlistenerlist_gets(eventListenerList)
 
#define mupnp_eventlistenerlist_next(eventListenerList)
 

Typedefs

typedef mUpnpHttpRequest mUpnpSubscriptionRequest
 
typedef mUpnpHttpResponse mUpnpSubscriptionResponse
 
typedef void(* MUPNP_EVENT_LISTENER) (mUpnpProperty *)
 
typedef struct _mUpnpEventListenerList mUpnpEventListenerList
 

Functions

const char * mupnp_event_subscription_totimeoutheaderstring (mUpnpTime time, mUpnpString *buf)
 
mUpnpTime mupnp_event_subscription_gettimeout (const char *headerValue)
 
const char * mupnp_event_subscription_createsid (char *buf, size_t bufSize)
 
const char * mupnp_event_subscription_tosidheaderstring (const char *sid, char *buf, size_t bufSize)
 
const char * mupnp_event_subscription_getsid (const char *headerValue)
 
void mupnp_event_subscription_request_setsid (mUpnpSubscriptionRequest *subReq, const char *sid)
 
void mupnp_event_subscription_request_settimeout (mUpnpSubscriptionRequest *subReq, mUpnpTime timeout)
 
void mupnp_event_subscription_request_setnewsubscription (mUpnpSubscriptionRequest *subReq, mUpnpService *service, const char *callback, mUpnpTime timeout)
 
void mupnp_event_subscription_request_setrenewsubscription (mUpnpSubscriptionRequest *subReq, mUpnpService *service, const char *uuid, mUpnpTime timeout)
 
void mupnp_event_subscription_request_setunsubscription (mUpnpSubscriptionRequest *subReq, mUpnpService *service)
 
void mupnp_event_subscription_response_setsid (mUpnpSubscriptionResponse *subRes, const char *sid)
 
void mupnp_event_subscription_response_settimeout (mUpnpSubscriptionResponse *subRes, long value)
 
void mupnp_event_subscription_subscriberesponse_setresponse (mUpnpSubscriptionResponse *subRes, int code)
 
mUpnpEventListenerListmupnp_eventlistenerlist_new (void)
 
void mupnp_eventlistenerlist_delete (mUpnpEventListenerList *eventListenerList)
 
void mupnp_eventlistenerlist_remove (mUpnpEventListenerList *eventListenerList, MUPNP_EVENT_LISTENER listener)
 
void mupnp_eventlistenerlist_add (mUpnpEventListenerList *eventListenerList, MUPNP_EVENT_LISTENER listener)
 
void mupnp_eventlistenerlist_notify (mUpnpEventListenerList *eventListenerList, mUpnpProperty *property)
 

Macro Definition Documentation

◆ MUPNP_EVENT_MAX_SEQ

#define MUPNP_EVENT_MAX_SEQ   2147483647

Definition for maximum event sequence number

◆ mupnp_event_subscription_issubscriberequest

#define mupnp_event_subscription_issubscriberequest ( subReq)
Value:
#define MUPNP_HTTP_SUBSCRIBE
Definition http.h:101
char * mupnp_http_request_getmethod(mUpnpHttpRequest *httpReq)
Definition http_request.c:182
bool mupnp_streq(const char *str1, const char *str2)
Definition string_function.c:158

Checks if request type is subscription request

Parameters
subReqThe request to be checked
Returns
True if request is subscription request, false otherwise

◆ mupnp_event_subscription_isunsubscriberequest

#define mupnp_event_subscription_isunsubscriberequest ( subReq)
Value:
#define MUPNP_HTTP_UNSUBSCRIBE
Definition http.h:102

Checks if request type is unsubscription request

Parameters
subReqThe request to be checked
Returns
True if request is unsubscription request

◆ mupnp_event_subscription_request_delete

#define mupnp_event_subscription_request_delete ( subReq)
Value:
void mupnp_http_request_delete(mUpnpHttpRequest *httpReq)
Definition http_request.c:75

Subscription request destructor

Parameters
subReqReference to the subscription request to be deleted

◆ mupnp_event_subscription_request_getcallback

#define mupnp_event_subscription_request_getcallback ( subReq)
Value:
#define MUPNP_HTTP_CALLBACK
Definition http.h:113
const char * mupnp_http_packet_getheadervalue(mUpnpHttpPacket *httpPkt, const char *name)
Definition http_packet.c:179
Definition http.h:178

Get subscription callback URL

Parameters
subReqSubscription request
Returns
Character array containing the callback URL

◆ mupnp_event_subscription_request_gethost

#define mupnp_event_subscription_request_gethost ( subReq)
Value:
#define MUPNP_HTTP_HOST
Definition http.h:73

Get host header value from subscription request

Parameters
subReqSubscription request

◆ mupnp_event_subscription_request_getnt

#define mupnp_event_subscription_request_getnt ( subReq)
Value:
#define MUPNP_HTTP_NT
Definition http.h:107

Get NT from subscription request

Parameters
subReqSubscription request
Returns
Character array containing the NT header value

◆ mupnp_event_subscription_request_getsid

#define mupnp_event_subscription_request_getsid ( subReq)
Value:
const char * mupnp_event_subscription_getsid(const char *headerValue)
Definition subscription.c:120
#define MUPNP_HTTP_SID
Definition http.h:111

Get sid from subscription request

Parameters
subReqSubscription request
Returns
Character array containing the requested SID

◆ mupnp_event_subscription_request_gettimeout

#define mupnp_event_subscription_request_gettimeout ( subReq)
Value:
mUpnpTime mupnp_event_subscription_gettimeout(const char *headerValue)
Definition subscription.c:54
#define MUPNP_HTTP_TIMEOUT
Definition http.h:114

Get timeout value from subscription request

Parameters
subReqSubscription request

◆ mupnp_event_subscription_request_hascallback

#define mupnp_event_subscription_request_hascallback ( subReq)
Value:
#define mupnp_http_packet_hasheader(httpPkt, name)
Definition http.h:278

Checks if subscription request has callback URL

Parameters
subReqSubscription request
Returns
True if subscription request has callback URL, false otherwise

◆ mupnp_event_subscription_request_hasnt

#define mupnp_event_subscription_request_hasnt ( subReq)
Value:

Checks if subscription request has NT

Parameters
subReqSubscription request
Returns
True if subscription request contains NT, false otherwise

◆ mupnp_event_subscription_request_hassid

#define mupnp_event_subscription_request_hassid ( subReq)
Value:

Checks if subscription object has SID

Parameters
subReqSubscription request
Returns
True if subscription has SID, false otherwise

◆ mupnp_event_subscription_request_new

#define mupnp_event_subscription_request_new ( void)
Value:
mUpnpHttpRequest * mupnp_http_request_new()
Definition http_request.c:40

Subscription request constructor

Returns
Pointer to newly created subsription request

◆ mupnp_event_subscription_request_post

#define mupnp_event_subscription_request_post ( subReq)
Value:
#define mupnp_http_request_getposturl(httpReq)
Definition http.h:427
mUpnpHttpResponse * mupnp_http_request_post(mUpnpHttpRequest *httpReq, const char *ipaddr, int port)
Definition http_request.c:347
#define mupnp_net_url_gethost(urip)
Definition url.h:62
#define mupnp_net_url_getport(urip)
Definition url.h:63

Send subscription request to device

Parameters
subReqSubscription request

◆ mupnp_event_subscription_request_postresponse

#define mupnp_event_subscription_request_postresponse ( subReq,
subRes )
Value:
bool mupnp_http_request_postresponse(mUpnpHttpRequest *httpReq, mUpnpHttpResponse *httpRes)
Definition http_request.c:756

Send response to subscription request

Parameters
subReqSubscription request
subResSubscription response

◆ mupnp_event_subscription_request_setcallback

#define mupnp_event_subscription_request_setcallback ( subReq,
value )
Value:
void mupnp_http_packet_setheadervalue(mUpnpHttpPacket *httpPkt, const char *name, const char *value)
Definition http_packet.c:106

Set subscription request callback URL

Parameters
subReqSubscription request
valueCallback URL string

◆ mupnp_event_subscription_request_sethost

#define mupnp_event_subscription_request_sethost ( subReq,
value )
Value:

Set HTTP host header value

Parameters
subReqSubscription request
valueHTTP Host: header content

◆ mupnp_event_subscription_request_setnt

#define mupnp_event_subscription_request_setnt ( subReq,
value )
Value:

Set NT (Notification target) for subscription request

Parameters
subReqSubscription request
valueNotification type

◆ mupnp_event_subscription_response_delete

#define mupnp_event_subscription_response_delete ( subRes)
Value:
void mupnp_http_response_delete(mUpnpHttpResponse *httpRes)
Definition http_response.c:49

Destructor for subscription response

Parameters
subResSubscription response

◆ mupnp_event_subscription_response_getsid

#define mupnp_event_subscription_response_getsid ( subRes)
Value:

Get SID

Parameters
subResSubscription request
Returns
C string containing SID

◆ mupnp_event_subscription_response_getstatuscode

#define mupnp_event_subscription_response_getstatuscode ( subRes,
code )
Value:
int mupnp_http_response_getstatuscode(mUpnpHttpResponse *httpRes)
Definition http_response.c:123

Get status code from subscription response object

Parameters
subResSubscription response
codeStatus code
Returns
Status code
Bug
Status code is not needed here! (It is not even passed to the wrapped function)

◆ mupnp_event_subscription_response_gettimeout

#define mupnp_event_subscription_response_gettimeout ( subRes)
Value:

Get timeout value from subscription response

Parameters
subResSubscription response
Returns
C string containing the timeout

◆ mupnp_event_subscription_response_issuccessful

#define mupnp_event_subscription_response_issuccessful ( subRes)
Value:
#define mupnp_http_response_issuccessful(httpRes)
Definition http.h:452

Checks if subscription was successfull by checking status code from subscription response

Parameters
subResSubscription response

◆ mupnp_event_subscription_response_new

#define mupnp_event_subscription_response_new ( )
Value:
mUpnpHttpResponse * mupnp_http_response_new()
Definition http_response.c:20

Constructor for subscription response

◆ mupnp_event_subscription_response_setstatuscode

#define mupnp_event_subscription_response_setstatuscode ( subRes,
code )
Value:
void mupnp_http_response_setstatuscode(mUpnpHttpResponse *httpRes, int value)
Definition http_response.c:108

Set status code for subscription response

Parameters
subResSubscription response
codeStatus code

◆ mupnp_eventlistenerlist_clear

#define mupnp_eventlistenerlist_clear ( eventListenerList)
Value:
void mupnp_list_clear(mUpnpList *headList, MUPNP_LIST_DESTRUCTORFUNC destructorFunc)
Definition list.c:257
void(* MUPNP_LIST_DESTRUCTORFUNC)(void *)
Definition list.h:29
The generic list interface in mUPnP.
Definition list.h:56

Clear the contents of a event listener list.

Parameters
eventListenerListThe device list to clear

◆ mupnp_eventlistenerlist_gets

#define mupnp_eventlistenerlist_gets ( eventListenerList)
Value:
mUpnpList * mupnp_list_next(mUpnpList *list)
Definition list.c:234
Definition event.h:114

Fetches next list element from event listener list

Parameters
eventListenerListEvent listener list

◆ mupnp_eventlistenerlist_next

#define mupnp_eventlistenerlist_next ( eventListenerList)
Value:

Fetches next list element from event listener list

Parameters
eventListenerListEvent listener list

◆ mupnp_eventlistenerlist_size

#define mupnp_eventlistenerlist_size ( eventListenerList)
Value:
mupnp_list_size((mUpnpList*)eventListenerList)
int mupnp_list_size(mUpnpList *headList)
Definition list.c:53

Get the size of the device list

Parameters
eventListenerListThe device list

◆ MUPNP_SUBSCRIPTION_CALLBACK_END_WITH

#define MUPNP_SUBSCRIPTION_CALLBACK_END_WITH   ">"

Definition for subscription callback end tag

◆ MUPNP_SUBSCRIPTION_CALLBACK_START_WITH

#define MUPNP_SUBSCRIPTION_CALLBACK_START_WITH   "<"

Definition for subscription callback start tag

◆ MUPNP_SUBSCRIPTION_DELAY

#define MUPNP_SUBSCRIPTION_DELAY   30

Definition for subscription delay

◆ MUPNP_SUBSCRIPTION_INFINITE_STRING

#define MUPNP_SUBSCRIPTION_INFINITE_STRING   "infinite"

Definition for infinite string in subscription

◆ MUPNP_SUBSCRIPTION_INFINITE_VALUE

#define MUPNP_SUBSCRIPTION_INFINITE_VALUE   (-1)

Definition for infinite value in subscription

◆ MUPNP_SUBSCRIPTION_MAX_TIMEOUT

#define MUPNP_SUBSCRIPTION_MAX_TIMEOUT   300

Definition for maximum upnp subscription timeout

◆ MUPNP_SUBSCRIPTION_SID_HEADER_SIZE

#define MUPNP_SUBSCRIPTION_SID_HEADER_SIZE   (5 + MUPNP_SUBSCRIPTION_SID_SIZE)

Definition for SID header size

◆ MUPNP_SUBSCRIPTION_SID_SIZE

#define MUPNP_SUBSCRIPTION_SID_SIZE   (MUPNP_UUID_MAX_LEN + 8)

Definition for SID size

◆ MUPNP_SUBSCRIPTION_TIMEOUT_HEADER

#define MUPNP_SUBSCRIPTION_TIMEOUT_HEADER   "Second-"

Definition for subscription timeout header prefix

◆ MUPNP_SUBSCRIPTION_UUID

#define MUPNP_SUBSCRIPTION_UUID   "uuid:"

Definition for subscription uuid prefix

◆ MUPNP_SUBSCRIPTION_XMLNS

#define MUPNP_SUBSCRIPTION_XMLNS   "urn:schemas-upnp-org:event-1-0"

Definition for subscription xml namespace

Typedef Documentation

◆ MUPNP_EVENT_LISTENER

typedef void(* MUPNP_EVENT_LISTENER) (mUpnpProperty *)

Type definition for event listener callback

◆ mUpnpEventListenerList

Type definition for event listener list

◆ mUpnpSubscriptionRequest

Type definition for subsription request

Data type for subscription request

◆ mUpnpSubscriptionResponse

Type definition for subsrciption response

Function Documentation

◆ mupnp_event_subscription_createsid()

const char * mupnp_event_subscription_createsid ( char * buf,
size_t bufSize )

Create SID for subscription

Parameters
bufCharacter buffer where SID is created
bufSizeBuffer size.
Returns
Pointer to buffer containing SID

◆ mupnp_event_subscription_getsid()

const char * mupnp_event_subscription_getsid ( const char * headerValue)

Get SID

Parameters
headerValueRaw header C string
Returns
C string containing SID

◆ mupnp_event_subscription_gettimeout()

mUpnpTime mupnp_event_subscription_gettimeout ( const char * headerValue)

Get event subscription timeout

Parameters
headerValueHeader value
Returns
Timeout

◆ mupnp_event_subscription_request_setnewsubscription()

void mupnp_event_subscription_request_setnewsubscription ( mUpnpSubscriptionRequest * subReq,
mUpnpService * service,
const char * callback,
mUpnpTime timeout )

(Re)initializes subscription request

Parameters
subReqSubscription request
serviceService to be subscribed
callbackURL to be called when service state changes
timeoutSubscription timeout

◆ mupnp_event_subscription_request_setrenewsubscription()

void mupnp_event_subscription_request_setrenewsubscription ( mUpnpSubscriptionRequest * subReq,
mUpnpService * service,
const char * uuid,
mUpnpTime timeout )

(Re)initializes subscription request to be renewal request

Parameters
subReqSubscription request
serviceService to be subscribed
uuidDevices unique identification string
timeoutSubscription timeout

◆ mupnp_event_subscription_request_setsid()

void mupnp_event_subscription_request_setsid ( mUpnpSubscriptionRequest * subReq,
const char * sid )

Set sid to subscription request

Parameters
subReqSubscription request
sidSID (Subscription id)

◆ mupnp_event_subscription_request_settimeout()

void mupnp_event_subscription_request_settimeout ( mUpnpSubscriptionRequest * subReq,
mUpnpTime timeout )

Set timeout for subscription request

Parameters
subReqSubscription request
timeoutTimeout value for subscription request

◆ mupnp_event_subscription_request_setunsubscription()

void mupnp_event_subscription_request_setunsubscription ( mUpnpSubscriptionRequest * subReq,
mUpnpService * service )

(Re)initializes subscription request to be unsubscription request

Parameters
subReqSubscription request
serviceService where to be unsubscribed

◆ mupnp_event_subscription_response_setsid()

void mupnp_event_subscription_response_setsid ( mUpnpSubscriptionResponse * subRes,
const char * sid )

Set SID (Subscription ID) for response

Parameters
subResSubscription response
sidSubscription ID

◆ mupnp_event_subscription_response_settimeout()

void mupnp_event_subscription_response_settimeout ( mUpnpSubscriptionResponse * subRes,
long value )

Set HTTP timeout for subscription response

Parameters
subResSubscription response
valueTimeout

◆ mupnp_event_subscription_subscriberesponse_setresponse()

void mupnp_event_subscription_subscriberesponse_setresponse ( mUpnpSubscriptionResponse * subRes,
int code )

Set response code for subscription response

Parameters
subResSubscription response
codeResponse code

◆ mupnp_event_subscription_tosidheaderstring()

const char * mupnp_event_subscription_tosidheaderstring ( const char * sid,
char * buf,
size_t bufSize )

Creates SID header string

Parameters
sidCharacter array containing the SID
bufA buffer where header string is created
bufSizeSize of the used buffer
Returns
Pointer to buffer containing SID header string

◆ mupnp_event_subscription_totimeoutheaderstring()

const char * mupnp_event_subscription_totimeoutheaderstring ( mUpnpTime time,
mUpnpString * buf )

Create timeout header string

Parameters
timeTimeout
bufBuffer used when creating header string
Returns
Timeout header C string

◆ mupnp_eventlistenerlist_add()

void mupnp_eventlistenerlist_add ( mUpnpEventListenerList * eventListenerList,
MUPNP_EVENT_LISTENER listener )

Add a listener to the event listener list

Parameters
eventListenerListThe event listener list
listenerThe listener to add

◆ mupnp_eventlistenerlist_delete()

void mupnp_eventlistenerlist_delete ( mUpnpEventListenerList * eventListenerList)

Delete a event listener list.

Parameters
eventListenerListThe event listener list to delete

◆ mupnp_eventlistenerlist_new()

mUpnpEventListenerList * mupnp_eventlistenerlist_new ( void )

Create a new event listener list

◆ mupnp_eventlistenerlist_notify()

void mupnp_eventlistenerlist_notify ( mUpnpEventListenerList * eventListenerList,
mUpnpProperty * property )

Call all event listeners in the list with the given data.

Parameters
eventListenerListThe list to iterate thru
propertyThe property that has been evented

Call all event listeners in the list with the given evented data.

Parameters
eventListenerListThe list to iterate thru
propertyThe property that has been evented

◆ mupnp_eventlistenerlist_remove()

void mupnp_eventlistenerlist_remove ( mUpnpEventListenerList * eventListenerList,
MUPNP_EVENT_LISTENER listener )

Remove a listener from the event listener list

Parameters
eventListenerListThe event listener list
listenerThe listener to remove