UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
gena.hpp File Reference

Manage Eventing with GENA, the General Event Notification Architecture. More...

#include <time.h>
#include <client_table.hpp>
#include <httpparser.hpp>
#include <sock.hpp>
+ Include dependency graph for gena.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  NOTIFY_THREAD_STRUCT
 

Macros

#define XML_VERSION   "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
 XML version comment. Not used because it is not interoperable with other UPnP vendors.
 
#define XML_PROPERTYSET_HEADER    "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n"
 
#define UNABLE_MEMORY   "HTTP/1.1 500 Internal Server Error\r\n\r\n"
 
#define UNABLE_SERVICE_UNKNOWN   "HTTP/1.1 404 Not Found\r\n\r\n"
 
#define UNABLE_SERVICE_NOT_ACCEPT   "HTTP/1.1 503 Service Not Available\r\n\r\n"
 
#define NOT_IMPLEMENTED   "HTTP/1.1 501 Not Implemented\r\n\r\n"
 
#define BAD_REQUEST   "HTTP/1.1 400 Bad Request\r\n\r\n"
 
#define INVALID_NT   BAD_CALLBACK
 
#define BAD_CALLBACK   "HTTP/1.1 412 Precondition Failed\r\n\r\n"
 
#define HTTP_OK_CRLF   "HTTP/1.1 200 OK\r\n\r\n"
 
#define HTTP_OK_STR   "HTTP/1.1 200 OK\r\n"
 
#define INVALID_SID   BAD_CALLBACK
 
#define MISSING_SID   BAD_CALLBACK
 
#define MAX_CONTENT_LENGTH   20
 
#define MAX_SECONDS   10
 
#define MAX_EVENTS   20
 
#define MAX_PORT_SIZE   10
 
#define GENA_E_BAD_RESPONSE   UPNP_E_BAD_RESPONSE
 
#define GENA_E_BAD_SERVICE   UPNP_E_INVALID_SERVICE
 
#define GENA_E_SUBSCRIPTION_UNACCEPTED   UPNP_E_SUBSCRIBE_UNACCEPTED
 
#define GENA_E_BAD_SID   UPNP_E_INVALID_SID
 
#define GENA_E_UNSUBSCRIBE_UNACCEPTED   UPNP_E_UNSUBSCRIBE_UNACCEPTED
 
#define GENA_E_NOTIFY_UNACCEPTED   UPNP_E_NOTIFY_UNACCEPTED
 
#define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB   -9
 
#define GENA_E_BAD_HANDLE   UPNP_E_INVALID_HANDLE
 
#define XML_ERROR   -5
 
#define XML_SUCCESS   UPNP_E_SUCCESS
 
#define GENA_SUCCESS   UPNP_E_SUCCESS
 
#define CALLBACK_SUCCESS   0
 
#define DEFAULT_TIMEOUT   1801
 

Typedefs

typedef struct NOTIFY_THREAD_STRUCT notify_thread_struct
 

Functions

int clientSubscribeMutexInit ()
 Initialize the client subsribe mutex.
 
int clientSubscribeMutexDestroy ()
 Destroy the client subsribe mutex.
 
void genaCallback (http_parser_t *parser, http_message_t *request, SOCKINFO *info)
 This is the callback function called by the miniserver to handle incoming GENA requests.
 
int genaSubscribe (UpnpClient_Handle client_handle, const UpnpString *PublisherURL, int *TimeOut, UpnpString *out_sid)
 This function subscribes to a PublisherURL (also mentioned as EventURL in some places).
 
int genaUnSubscribe (UpnpClient_Handle client_handle, const UpnpString *in_sid)
 Unsubscribes a SID.
 
int genaUnregisterClient (UpnpClient_Handle client_handle)
 Unsubcribes all the outstanding subscriptions and cleans the subscription list.
 
int genaUnregisterDevice (UpnpDevice_Handle device_handle)
 Cleans the service table of the device.
 
int genaRenewSubscription (UpnpClient_Handle client_handle, const UpnpString *in_sid, int *TimeOut)
 Renews a SID.
 
int genaNotifyAll (UpnpDevice_Handle device_handle, char *UDN, char *servId, char **VarNames, char **VarValues, int var_count)
 Sends a notification to all the subscribed control points.
 
int genaNotifyAllExt (UpnpDevice_Handle device_handle, char *UDN, char *servId, IXML_Document *PropSet)
 Sends a notification to all the subscribed control points.
 
int genaInitNotify (UpnpDevice_Handle device_handle, char *UDN, char *servId, char **VarNames, char **VarValues, int var_count, const Upnp_SID sid)
 Sends the intial state table dump to newly subscribed control point.
 
int genaInitNotifyExt (UpnpDevice_Handle device_handle, char *UDN, char *servId, IXML_Document *PropSet, const Upnp_SID sid)
 Similar to the genaInitNofity. The only difference is that it takes the xml document for the state table and sends the intial state table dump to newly subscribed control point.
 
void error_respond (SOCKINFO *info, int error_code, http_message_t *hmsg)
 Sends an error message to the control point in the case of incorrect GENA requests.
 

Detailed Description

Manage Eventing with GENA, the General Event Notification Architecture.

Definition in file gena.hpp.


Class Documentation

◆ NOTIFY_THREAD_STRUCT

struct NOTIFY_THREAD_STRUCT

Structure to send NOTIFY message to all subscribed control points

Definition at line 92 of file gena.hpp.

Class Members
char * headers

Member of notify thread structure

DOMString propertySet

Member of notify thread structure

char * servId

Member of notify thread structure

char * UDN

Member of notify thread structure

Upnp_SID sid

Member of notify thread structure

time_t ctime

Member of notify thread structure

int * reference_count

Member of notify thread structure

UpnpDevice_Handle device_handle

Member of notify thread structure

Macro Definition Documentation

◆ XML_VERSION

#define XML_VERSION   "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"

XML version comment. Not used because it is not interoperable with other UPnP vendors.

Definition at line 49 of file gena.hpp.

◆ XML_PROPERTYSET_HEADER

#define XML_PROPERTYSET_HEADER    "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n"

Constant for Eventing with GENA

Definition at line 52 of file gena.hpp.

◆ UNABLE_MEMORY

#define UNABLE_MEMORY   "HTTP/1.1 500 Internal Server Error\r\n\r\n"

Constant for Eventing with GENA

Definition at line 55 of file gena.hpp.

◆ UNABLE_SERVICE_UNKNOWN

#define UNABLE_SERVICE_UNKNOWN   "HTTP/1.1 404 Not Found\r\n\r\n"

Constant for Eventing with GENA

Definition at line 56 of file gena.hpp.

◆ UNABLE_SERVICE_NOT_ACCEPT

#define UNABLE_SERVICE_NOT_ACCEPT   "HTTP/1.1 503 Service Not Available\r\n\r\n"

Constant for Eventing with GENA

Definition at line 57 of file gena.hpp.

◆ NOT_IMPLEMENTED

#define NOT_IMPLEMENTED   "HTTP/1.1 501 Not Implemented\r\n\r\n"

Constant for Eventing with GENA

Definition at line 59 of file gena.hpp.

◆ BAD_REQUEST

#define BAD_REQUEST   "HTTP/1.1 400 Bad Request\r\n\r\n"

Constant for Eventing with GENA

Definition at line 60 of file gena.hpp.

◆ INVALID_NT

#define INVALID_NT   BAD_CALLBACK

Constant for Eventing with GENA

Definition at line 61 of file gena.hpp.

◆ BAD_CALLBACK

#define BAD_CALLBACK   "HTTP/1.1 412 Precondition Failed\r\n\r\n"

Constant for Eventing with GENA

Definition at line 62 of file gena.hpp.

◆ HTTP_OK_CRLF

#define HTTP_OK_CRLF   "HTTP/1.1 200 OK\r\n\r\n"

Constant for Eventing with GENA

Definition at line 63 of file gena.hpp.

◆ HTTP_OK_STR

#define HTTP_OK_STR   "HTTP/1.1 200 OK\r\n"

Constant for Eventing with GENA

Definition at line 64 of file gena.hpp.

◆ INVALID_SID

#define INVALID_SID   BAD_CALLBACK

Constant for Eventing with GENA

Definition at line 65 of file gena.hpp.

◆ MISSING_SID

#define MISSING_SID   BAD_CALLBACK

Constant for Eventing with GENA

Definition at line 66 of file gena.hpp.

◆ MAX_CONTENT_LENGTH

#define MAX_CONTENT_LENGTH   20

Constant for Eventing with GENA

Definition at line 67 of file gena.hpp.

◆ MAX_SECONDS

#define MAX_SECONDS   10

Constant for Eventing with GENA

Definition at line 68 of file gena.hpp.

◆ MAX_EVENTS

#define MAX_EVENTS   20

Constant for Eventing with GENA

Definition at line 69 of file gena.hpp.

◆ MAX_PORT_SIZE

#define MAX_PORT_SIZE   10

Constant for Eventing with GENA

Definition at line 70 of file gena.hpp.

◆ GENA_E_BAD_RESPONSE

#define GENA_E_BAD_RESPONSE   UPNP_E_BAD_RESPONSE

Constant for Eventing with GENA

Definition at line 72 of file gena.hpp.

◆ GENA_E_BAD_SERVICE

#define GENA_E_BAD_SERVICE   UPNP_E_INVALID_SERVICE

Constant for Eventing with GENA

Definition at line 73 of file gena.hpp.

◆ GENA_E_SUBSCRIPTION_UNACCEPTED

#define GENA_E_SUBSCRIPTION_UNACCEPTED   UPNP_E_SUBSCRIBE_UNACCEPTED

Constant for Eventing with GENA

Definition at line 74 of file gena.hpp.

◆ GENA_E_BAD_SID

#define GENA_E_BAD_SID   UPNP_E_INVALID_SID

Constant for Eventing with GENA

Definition at line 75 of file gena.hpp.

◆ GENA_E_UNSUBSCRIBE_UNACCEPTED

#define GENA_E_UNSUBSCRIBE_UNACCEPTED   UPNP_E_UNSUBSCRIBE_UNACCEPTED

Constant for Eventing with GENA

Definition at line 76 of file gena.hpp.

◆ GENA_E_NOTIFY_UNACCEPTED

#define GENA_E_NOTIFY_UNACCEPTED   UPNP_E_NOTIFY_UNACCEPTED

Constant for Eventing with GENA

Definition at line 77 of file gena.hpp.

◆ GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB

#define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB   -9

Constant for Eventing with GENA

Definition at line 78 of file gena.hpp.

◆ GENA_E_BAD_HANDLE

#define GENA_E_BAD_HANDLE   UPNP_E_INVALID_HANDLE

Constant for Eventing with GENA

Definition at line 79 of file gena.hpp.

◆ XML_ERROR

#define XML_ERROR   -5

Constant for Eventing with GENA

Definition at line 81 of file gena.hpp.

◆ XML_SUCCESS

#define XML_SUCCESS   UPNP_E_SUCCESS

Constant for Eventing with GENA

Definition at line 82 of file gena.hpp.

◆ GENA_SUCCESS

#define GENA_SUCCESS   UPNP_E_SUCCESS

Constant for Eventing with GENA

Definition at line 83 of file gena.hpp.

◆ CALLBACK_SUCCESS

#define CALLBACK_SUCCESS   0

Constant for Eventing with GENA

Definition at line 85 of file gena.hpp.

◆ DEFAULT_TIMEOUT

#define DEFAULT_TIMEOUT   1801

Constant for Eventing with GENA

Definition at line 86 of file gena.hpp.

Typedef Documentation

◆ notify_thread_struct

Structure to send NOTIFY message to all subscribed control points

Function Documentation

◆ clientSubscribeMutexInit()

int clientSubscribeMutexInit ( )

Initialize the client subsribe mutex.

Definition at line 415 of file gena_ctrlpt.cpp.

+ Here is the caller graph for this function:

◆ clientSubscribeMutexDestroy()

int clientSubscribeMutexDestroy ( )

Destroy the client subsribe mutex.

Definition at line 427 of file gena_ctrlpt.cpp.

+ Here is the caller graph for this function:

◆ genaCallback()

void genaCallback ( http_parser_t parser,
http_message_t request,
SOCKINFO info 
)

This is the callback function called by the miniserver to handle incoming GENA requests.

\ returns UPNP_E_SUCCESS if successful, otherwise appropriate error code.

Parameters
[in]parserRepresents the parse state of the request
[in]requestHTTP message containing GENA request
[in,out]infoStructure containing information about the socket

Definition at line 58 of file gena_callback2.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaSubscribe()

int genaSubscribe ( UpnpClient_Handle  client_handle,
const UpnpString PublisherURL,
int *  TimeOut,
UpnpString out_sid 
)

This function subscribes to a PublisherURL (also mentioned as EventURL in some places).

It sends SUBSCRIBE http request to service processes request. Finally adds a Subscription to the clients subscription list, if service responds with OK.

Returns
UPNP_E_SUCCESS if service response is OK, otherwise returns the appropriate error code
Parameters
[in]client_handleThe client handle.
[in]PublisherURLOf the form: "http://134.134.156.80:4000/RedBulb/Event"
[in,out]TimeOutrequested Duration:
  • if -1, then "infinite".
  • in the OUT case: actual Duration granted by Service, -1 for infinite.
[out]out_sidsid of subscription, memory passed in by caller.

Definition at line 517 of file gena_ctrlpt.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaUnSubscribe()

int genaUnSubscribe ( UpnpClient_Handle  client_handle,
const UpnpString in_sid 
)

Unsubscribes a SID.

It first validates the SID and client_handle,copies the subscription, sends UNSUBSCRIBE http request to service processes request and finally removes the subscription.

Returns
UPNP_E_SUCCESS if service response is OK, otherwise returns the appropriate error code.
Parameters
[in]client_handleUPnP client handle.
[in]in_sidThe subscription ID.

Definition at line 472 of file gena_ctrlpt.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaUnregisterClient()

int genaUnregisterClient ( UpnpClient_Handle  client_handle)

Unsubcribes all the outstanding subscriptions and cleans the subscription list.

This function is called when control point unregisters.

Returns
UPNP_E_SUCCESS if successful, otherwise returns the appropriate error code.
Parameters
[in]client_handleHandle containing all the control point related information.

Definition at line 431 of file gena_ctrlpt.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaUnregisterDevice()

int genaUnregisterDevice ( UpnpDevice_Handle  device_handle)

Cleans the service table of the device.

Returns
UPNP_E_SUCCESS if successful, otherwise returns GENA_E_BAD_HANDLE
Parameters
[in]device_handleHandle of the root device

Definition at line 887 of file gena_device.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaRenewSubscription()

int genaRenewSubscription ( UpnpClient_Handle  client_handle,
const UpnpString in_sid,
int *  TimeOut 
)

Renews a SID.

It first validates the SID and client_handle and copies the subscription. It sends RENEW (modified SUBSCRIBE) http request to service and processes the response.

Returns
UPNP_E_SUCCESS if service response is OK, otherwise the appropriate error code.
Parameters
[in]client_handleClient handle.
[in]in_sidSubscription ID.
[in,out]TimeOutrequested Duration, if -1, then "infinite". In the OUT case: actual Duration granted by Service, -1 for infinite.

Definition at line 614 of file gena_ctrlpt.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaNotifyAll()

int genaNotifyAll ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
char **  VarNames,
char **  VarValues,
int  var_count 
)

Sends a notification to all the subscribed control points.

Returns
int
Note
This function is similar to the genaNotifyAllExt. The only difference is it takes event variable array instead of xml document.
Parameters
[in]device_handleDevice handle.
[in]UDNDevice udn.
[in]servIdService ID.
[in]VarNamesArray of varible names.
[in]VarValuesArray of variable values.
[in]var_countNumber of variables.

Definition at line 1026 of file gena_device.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaNotifyAllExt()

int genaNotifyAllExt ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
IXML_Document PropSet 
)

Sends a notification to all the subscribed control points.

Returns
int
Note
This function is similar to the genaNotifyAll. the only difference is it takes the document instead of event variable array.
Parameters
[in]device_handleDevice handle.
[in]UDNDevice udn.
[in]servIdService ID.
[in]PropSetXML document Event varible property set.

Definition at line 997 of file gena_device.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaInitNotify()

int genaInitNotify ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
char **  VarNames,
char **  VarValues,
int  var_count,
const Upnp_SID  sid 
)

Sends the intial state table dump to newly subscribed control point.

Returns
GENA_E_SUCCESS if successful, otherwise the appropriate error code.
Note
No other event will be sent to this control point before the intial state table dump.
Parameters
[in]device_handleDevice handle.
[in]UDNDevice udn.
[in]servIdService ID.
[in]VarNamesArray of variable names.
[in]VarValuesArray of variable values.
[in]var_countArray size.
[in]sidSubscription ID.

Definition at line 928 of file gena_device.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ genaInitNotifyExt()

int genaInitNotifyExt ( UpnpDevice_Handle  device_handle,
char *  UDN,
char *  servId,
IXML_Document PropSet,
const Upnp_SID  sid 
)

Similar to the genaInitNofity. The only difference is that it takes the xml document for the state table and sends the intial state table dump to newly subscribed control point.

Returns
GENA_E_SUCCESS if successful, otherwise the appropriate error code.
Note
No other event will be sent to this control point before the intial state table dump.
Parameters
[in]device_handleDevice handle.
[in]UDNDevice udn.
[in]servIdService ID.
[in]PropSetDocument of the state table.
[in]sidsubscription ID.

Definition at line 962 of file gena_device.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ error_respond()

void error_respond ( SOCKINFO info,
int  error_code,
http_message_t hmsg 
)

Sends an error message to the control point in the case of incorrect GENA requests.

\ return UPNP_E_SUCCESS if successful, otherwise appropriate error code.

Parameters
[in]infoStructure containing information about the socket.
[in]error_codeerror code that will be in the GENA response.
[in]hmsgGENA request Packet.

Definition at line 47 of file gena_callback2.cpp.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: