Start of 1.8.x development. Sorry for the big commit, but in fact it should have been bigger.

The fact that we now have an active developer on branch ipv6 made me do this before I would like to.
The idea here is to hide libupnp internal data structures from the outside world so that
developers can be free to change them without breaking the interface. There is still some work to do
before a formal release, but the samples (device and control point) should be working.


git-svn-id: https://pupnp.svn.sourceforge.net/svnroot/pupnp/trunk@353 119443c7-1b9e-41f8-b6fc-b9c35fce742c
This commit is contained in:
Marcelo Roberto Jimenez 2008-04-26 01:20:09 +00:00
parent 5e742f04e3
commit 7206e80127
44 changed files with 5229 additions and 3259 deletions

View File

@ -1,3 +1,14 @@
*******************************************************************************
Version 1.8.0
*******************************************************************************
2008-02-06 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Breaking API so that we now hide internal data structures.
2008-02-06 Marcelo Jimenez <mroberto(at)users.sourceforge.net>
* Rewrote Peter Hartley's patch to include a new extra header field in
FileInfo.
******************************************************************************* *******************************************************************************
Version 1.6.6 Version 1.6.6
******************************************************************************* *******************************************************************************

View File

@ -9,7 +9,7 @@
AC_PREREQ(2.60) AC_PREREQ(2.60)
AC_INIT([libupnp], [1.6.6], [mroberto@users.sourceforge.net]) AC_INIT([libupnp], [1.8.0], [mroberto@users.sourceforge.net])
dnl ############################################################################ dnl ############################################################################
dnl # *Independently* of the above libupnp package version, the libtool version dnl # *Independently* of the above libupnp package version, the libtool version
dnl # of the 3 libraries need to be updated whenever there is a change released: dnl # of the 3 libraries need to be updated whenever there is a change released:
@ -144,9 +144,25 @@ dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:3:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:5:0]) dnl #AC_SUBST([LT_VERSION_UPNP], [3:5:0])
dnl # dnl #
dnl ############################################################################ dnl ############################################################################
dnl # Release 1.8.0:
dnl # "current:revision:age"
dnl #
dnl # - Code has changed in upnp
dnl # revision: 5 -> 6
dnl # - Interface has changed in upnp
dnl # current: 3 -> 4
dnl # revision: 6 -> 0
dnl # - Interface has been removed in upnp
dnl # age = 0
dnl #
dnl #AC_SUBST([LT_VERSION_IXML], [2:4:0])
dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:3:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [4:0:0])
dnl #
dnl ############################################################################
AC_SUBST([LT_VERSION_IXML], [2:4:0]) AC_SUBST([LT_VERSION_IXML], [2:4:0])
AC_SUBST([LT_VERSION_THREADUTIL], [4:3:2]) AC_SUBST([LT_VERSION_THREADUTIL], [4:3:2])
AC_SUBST([LT_VERSION_UPNP], [3:5:0]) AC_SUBST([LT_VERSION_UPNP], [4:0:0])
dnl ############################################################################ dnl ############################################################################
dnl # Repeating the algorithm to place it closer to the modificatin place: dnl # Repeating the algorithm to place it closer to the modificatin place:
dnl # - library code modified: revision++ dnl # - library code modified: revision++

View File

@ -19,6 +19,14 @@ LDADD = \
upnpincludedir = $(includedir)/upnp upnpincludedir = $(includedir)/upnp
upnpinclude_HEADERS = \ upnpinclude_HEADERS = \
inc/ActionComplete.h \
inc/ActionRequest.h \
inc/Discovery.h \
inc/EventSubscribe.h \
inc/FileInfo.h \
inc/StateVarComplete.h \
inc/StateVarRequest.h \
inc/String.h \
inc/upnp.h \ inc/upnp.h \
inc/upnpdebug.h inc/upnpdebug.h
@ -76,6 +84,8 @@ libupnp_la_SOURCES = \
# ssdp # ssdp
libupnp_la_SOURCES += \ libupnp_la_SOURCES += \
src/ssdp/ssdp_ResultData.c \
src/ssdp/ssdp_ResultData.h \
src/ssdp/ssdp_device.c \ src/ssdp/ssdp_device.c \
src/ssdp/ssdp_ctrlpt.c \ src/ssdp/ssdp_ctrlpt.c \
src/ssdp/ssdp_server.c src/ssdp/ssdp_server.c
@ -110,6 +120,14 @@ libupnp_la_SOURCES += \
src/gena/gena_callback2.c src/gena/gena_callback2.c
# api # api
libupnp_la_SOURCES += src/api/ActionComplete.c
libupnp_la_SOURCES += src/api/ActionRequest.c
libupnp_la_SOURCES += src/api/Discovery.c
libupnp_la_SOURCES += src/api/EventSubscribe.c
libupnp_la_SOURCES += src/api/FileInfo.c
libupnp_la_SOURCES += src/api/StateVarComplete.c
libupnp_la_SOURCES += src/api/StateVarRequest.c
libupnp_la_SOURCES += src/api/String.c
libupnp_la_SOURCES += src/api/upnpapi.c libupnp_la_SOURCES += src/api/upnpapi.c
if ENABLE_TOOLS if ENABLE_TOOLS
libupnp_la_SOURCES += src/api/upnptools.c libupnp_la_SOURCES += src/api/upnptools.c

57
upnp/inc/ActionComplete.h Normal file
View File

@ -0,0 +1,57 @@
#ifndef ACTIONCOMPLETE_H
#define ACTIONCOMPLETE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct {} UpnpActionComplete;
#include "String.h" // for UpnpString
#include "ixml.h" // for IXML_Document
/** Constructor */
UpnpActionComplete *UpnpActionComplete_new();
/** Destructor */
void UpnpActionComplete_delete(UpnpActionComplete *p);
/** Copy Constructor */
UpnpActionComplete *UpnpActionComplete_dup(const UpnpActionComplete *p);
/** Assignment operator */
void UpnpActionComplete_assign(UpnpActionComplete *q, const UpnpActionComplete *p);
/** The result of the operation */
int UpnpActionComplete_get_ErrCode(const UpnpActionComplete *p);
void UpnpActionComplete_set_ErrCode(UpnpActionComplete *p, int n);
/** The control URL for service. */
const UpnpString *UpnpActionComplete_get_CtrlUrl(const UpnpActionComplete *p);
void UpnpActionComplete_set_CtrlUrl(UpnpActionComplete *p, const UpnpString *s);
void UpnpActionComplete_strcpy_CtrlUrl(UpnpActionComplete *p, const char *s);
/** The DOM document describing the action */
IXML_Document *UpnpActionComplete_get_ActionRequest(const UpnpActionComplete *p);
void UpnpActionComplete_set_ActionRequest(UpnpActionComplete *p, IXML_Document *d);
/** The DOM document describing the result of the action */
IXML_Document *UpnpActionComplete_get_ActionResult(const UpnpActionComplete *p);
void UpnpActionComplete_set_ActionResult(UpnpActionComplete *p, IXML_Document *d);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* ACTIONCOMPLETE_H */

86
upnp/inc/ActionRequest.h Normal file
View File

@ -0,0 +1,86 @@
#ifndef ACTIONREQUEST_H
#define ACTIONREQUEST_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Returned as part of a {\bf UPNP_CONTROL_ACTION_COMPLETE} callback. */
typedef struct {} UpnpActionRequest;
#include "String.h" // for UpnpString
#include "ixml.h" // for IXML_Document
#include <netinet/in.h> // for in_addr
/** Constructor */
UpnpActionRequest *UpnpActionRequest_new();
/** Destructor */
void UpnpActionRequest_delete(UpnpActionRequest *p);
/** Copy Constructor */
UpnpActionRequest *UpnpActionRequest_dup(const UpnpActionRequest *p);
/** Assignment operator */
void UpnpActionRequest_assign(UpnpActionRequest *q, const UpnpActionRequest *p);
/** The result of the operation */
int UpnpActionRequest_get_ErrCode(const UpnpActionRequest *p);
void UpnpActionRequest_set_ErrCode(UpnpActionRequest *p, int n);
/** The socket number of the connection to the requestor */
int UpnpActionRequest_get_Socket(const UpnpActionRequest *p);
void UpnpActionRequest_set_Socket(UpnpActionRequest *p, int n);
/** The error string in case of error */
const UpnpString *UpnpActionRequest_get_ErrStr(const UpnpActionRequest *p);
void UpnpActionRequest_set_ErrStr(UpnpActionRequest *p, const UpnpString *s);
void UpnpActionRequest_strcpy_ErrStr(UpnpActionRequest *p, const char *s);
/** The Action Name */
const UpnpString *UpnpActionRequest_get_ActionName(const UpnpActionRequest *p);
void UpnpActionRequest_set_ActionName(UpnpActionRequest *p, const UpnpString *s);
void UpnpActionRequest_strcpy_ActionName(UpnpActionRequest *p, const char *s);
/** The unique device ID */
const UpnpString *UpnpActionRequest_get_DevUDN(const UpnpActionRequest *p);
void UpnpActionRequest_set_DevUDN(UpnpActionRequest *p, const UpnpString *s);
/** The service ID */
const UpnpString *UpnpActionRequest_get_ServiceID(const UpnpActionRequest *p);
void UpnpActionRequest_set_ServiceID(UpnpActionRequest *p, const UpnpString *s);
/** The DOM document describing the action */
IXML_Document *UpnpActionRequest_get_ActionRequest(const UpnpActionRequest *p);
void UpnpActionRequest_set_ActionRequest(UpnpActionRequest *p, IXML_Document *d);
/** The DOM document describing the result of the action */
IXML_Document *UpnpActionRequest_get_ActionResult(const UpnpActionRequest *p);
void UpnpActionRequest_set_ActionResult(UpnpActionRequest *p, IXML_Document *d);
/** IP address of the control point requesting this action */
struct in_addr *UpnpActionRequest_get_CtrlPtIPAddr(const UpnpActionRequest *p);
void UpnpActionRequest_set_CtrlPtIPAddr(UpnpActionRequest *p, struct in_addr *ia);
/** The DOM document containing the information from the SOAP header */
IXML_Document *UpnpActionRequest_get_SoapHeader(const UpnpActionRequest *p);
void UpnpActionRequest_set_SoapHeader(UpnpActionRequest *p, IXML_Document *d);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* ACTIONREQUEST_H */

96
upnp/inc/Discovery.h Normal file
View File

@ -0,0 +1,96 @@
#ifndef DISCOVERY_H
#define DISCOVERY_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Returned in a {\bf UPNP_DISCOVERY_RESULT} callback. */
typedef struct {} UpnpDiscovery;
#include "String.h" /* for UpnpString */
#include <netinet/in.h> /* for sockaddr_in */
/** Constructor */
UpnpDiscovery *UpnpDiscovery_new();
/** Destructor */
void UpnpDiscovery_delete(UpnpDiscovery *p);
/** Copy Constructor */
UpnpDiscovery *UpnpDiscovery_dup(const UpnpDiscovery *p);
/** Assignment operator */
void UpnpDiscovery_assign(UpnpDiscovery *q, const UpnpDiscovery *p);
/** The result code of the {\bf UpnpSearchAsync} call. */
int UpnpDiscovery_get_ErrCode(const UpnpDiscovery *p);
void UpnpDiscovery_set_ErrCode(UpnpDiscovery *p, int n);
/** The expiration time of the advertisement. */
int UpnpDiscovery_get_Expires(const UpnpDiscovery *p);
void UpnpDiscovery_set_Expires(UpnpDiscovery *p, int n);
/** The unique device identifier. */
const UpnpString *UpnpDiscovery_get_DeviceID(const UpnpDiscovery *p);
void UpnpDiscovery_set_DeviceID(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_DeviceID(UpnpDiscovery *p, const char *s);
/** The device type. */
const UpnpString *UpnpDiscovery_get_DeviceType(const UpnpDiscovery *p);
void UpnpDiscovery_set_DeviceType(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_DeviceType(UpnpDiscovery *p, const char *s);
/** The ServiceType. */
const UpnpString *UpnpDiscovery_get_ServiceType(const UpnpDiscovery *p);
void UpnpDiscovery_set_ServiceType(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_ServiceType(UpnpDiscovery *p, const char *s);
/** The service version. */
const UpnpString *UpnpDiscovery_get_ServiceVer(const UpnpDiscovery *p);
void UpnpDiscovery_set_ServiceVer(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_ServiceVer(UpnpDiscovery *p, const char *s);
/** The URL to the UPnP description document for the device. */
const UpnpString *UpnpDiscovery_get_Location(const UpnpDiscovery *p);
void UpnpDiscovery_set_Location(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_Location(UpnpDiscovery *p, const char *s);
void UpnpDiscovery_strncpy_Location(UpnpDiscovery *p, const char *s, int n);
/** The operating system the device is running. */
const UpnpString *UpnpDiscovery_get_Os(const UpnpDiscovery *p);
void UpnpDiscovery_set_Os(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_Os(UpnpDiscovery *p, const char *s);
void UpnpDiscovery_strncpy_Os(UpnpDiscovery *p, const char *s, int n);
/** Date when the response was generated. */
const UpnpString *UpnpDiscovery_get_Date(const UpnpDiscovery *p);
void UpnpDiscovery_set_Date(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_Date(UpnpDiscovery *p, const char *s);
/** Confirmation that the MAN header was understood by the device. */
const UpnpString *UpnpDiscovery_get_Ext(const UpnpDiscovery *p);
void UpnpDiscovery_set_Ext(UpnpDiscovery *p, const UpnpString *s);
void UpnpDiscovery_strcpy_Ext(UpnpDiscovery *p, const char *s);
void UpnpDiscovery_strncpy_Ext(UpnpDiscovery *p, const char *s, int n);
/** The host address of the device responding to the search. */
struct sockaddr_in *UpnpDiscovery_get_DestAddr(const UpnpDiscovery *p);
void UpnpDiscovery_set_DestAddr(UpnpDiscovery *p, struct sockaddr_in *sa);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* DISCOVERY_H */

63
upnp/inc/EventSubscribe.h Normal file
View File

@ -0,0 +1,63 @@
#ifndef EVENTSUBSCRIBE_H
#define EVENTSUBSCRIBE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Returned along with a {\bf UPNP_EVENT_SUBSCRIBE_COMPLETE} or
* {\bf UPNP_EVENT_UNSUBSCRIBE_COMPLETE} callback. */
typedef struct {} EventSubscribe;
#include "String.h" // for UpnpString
/** Constructor */
EventSubscribe *UpnpEventSubscribe_new();
/** Destructor */
void UpnpEventSubscribe_delete(EventSubscribe *p);
/** Copy Constructor */
EventSubscribe *UpnpEventSubscribe_dup(const EventSubscribe *p);
/** Assignment operator */
void UpnpEventSubscribe_assign(EventSubscribe *q, const EventSubscribe *p);
/** The result of the operation. */
int UpnpEventSubscribe_get_ErrCode(const EventSubscribe *p);
void UpnpEventSubscribe_set_ErrCode(EventSubscribe *p, int n);
/** The actual subscription time (for subscriptions only). */
int UpnpEventSubscribe_get_TimeOut(const EventSubscribe *p);
void UpnpEventSubscribe_set_TimeOut(EventSubscribe *p, int n);
/** The SID for this subscription. For subscriptions, this only
* contains a valid SID if the {\bf Upnp_EventSubscribe.result} field
* contains a {\tt UPNP_E_SUCCESS} result code. For unsubscriptions,
* this contains the SID from which the subscription is being
* unsubscribed. */
const UpnpString *UpnpEventSubscribe_get_SID(const EventSubscribe *p);
void UpnpEventSubscribe_set_SID(EventSubscribe *p, const UpnpString *s);
void UpnpEventSubscribe_strcpy_SID(EventSubscribe *p, const char *s);
/** The event URL being subscribed to or removed from. */
const UpnpString *UpnpEventSubscribe_get_PublisherUrl(const EventSubscribe *p);
void UpnpEventSubscribe_set_PublisherUrl(EventSubscribe *p, const UpnpString *s);
void UpnpEventSubscribe_strcpy_PublisherUrl(EventSubscribe *p, const char *s);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* EVENTSUBSCRIBE_H */

71
upnp/inc/FileInfo.h Normal file
View File

@ -0,0 +1,71 @@
#ifndef FILEINFO_H
#define FILEINFO_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct {} UpnpFileInfo;
#include "ixml.h" // for DOMString
#include <sys/types.h> // for off_t
#include <time.h> // for time_t
/** Constructor */
UpnpFileInfo *UpnpFileInfo_new();
/** Destructor */
void UpnpFileInfo_delete(UpnpFileInfo *p);
/** Copy Constructor */
UpnpFileInfo *UpnpFileInfo_dup(const UpnpFileInfo *p);
/** Assignment operator */
void UpnpFileInfo_assign(UpnpFileInfo *q, const UpnpFileInfo *p);
/** The length of the file. A length less than 0 indicates the size
* is unknown, and data will be sent until 0 bytes are returned from
* a read call. */
off_t UpnpFileInfo_get_FileLength(const UpnpFileInfo *p);
void UpnpFileInfo_set_FileLength(UpnpFileInfo *p, off_t l);
/** The time at which the contents of the file was modified;
* The time system is always local (not GMT). */
const time_t *UpnpFileInfo_get_LastModified(const UpnpFileInfo *p);
void UpnpFileInfo_set_LastModified(UpnpFileInfo *p, const time_t *t);
/** If the file is a directory, {\bf is_directory} contains
* a non-zero value. For a regular file, it should be 0. */
int UpnpFileInfo_get_IsDirectory(const UpnpFileInfo *p);
void UpnpFileInfo_set_IsDirectory(UpnpFileInfo *p, int b);
/** If the file or directory is readable, this contains
* a non-zero value. If unreadable, it should be set to 0. */
int UpnpFileInfo_get_IsReadable(const UpnpFileInfo *p);
void UpnpFileInfo_set_IsReadable(UpnpFileInfo *p, int b);
/** The content type of the file. */
const DOMString UpnpFileInfo_get_ContentType(const UpnpFileInfo *p);
void UpnpFileInfo_set_ContentType(UpnpFileInfo *p, const DOMString s);
/** Additional HTTP headers to return. Each header line should be
* followed by "\r\n". */
const DOMString UpnpFileInfo_get_ExtraHeaders(const UpnpFileInfo *p);
void UpnpFileInfo_set_ExtraHeaders(UpnpFileInfo *p, const DOMString s);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* FILEINFO_H */

View File

@ -0,0 +1,61 @@
#ifndef STATEVARCOMPLETE_H
#define STATEVARCOMPLETE_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Represents the reply for the current value of a state variable in an
asynchronous call. */
typedef struct {} UpnpStateVarComplete;
#include "String.h" // for UpnpString
#include "ixml.h" // for DOMString
/** Constructor */
UpnpStateVarComplete *UpnpStateVarComplete_new();
/** Destructor */
void UpnpStateVarComplete_delete(UpnpStateVarComplete *p);
/** Copy Constructor */
UpnpStateVarComplete *UpnpStateVarComplete_dup(const UpnpStateVarComplete *p);
/** Assignment operator */
void UpnpStateVarComplete_assign(UpnpStateVarComplete *q, const UpnpStateVarComplete *p);
/** The result of the operation */
int UpnpStateVarComplete_get_ErrCode(const UpnpStateVarComplete *p);
void UpnpStateVarComplete_set_ErrCode(UpnpStateVarComplete *p, int n);
/** The control URL for the service. */
const UpnpString *UpnpStateVarComplete_get_CtrlUrl(const UpnpStateVarComplete *p);
void UpnpStateVarComplete_set_CtrlUrl(UpnpStateVarComplete *p, const UpnpString *s);
void UpnpStateVarComplete_strcpy_CtrlUrl(UpnpStateVarComplete *p, const char *s);
/** The name of the variable. */
const UpnpString *UpnpStateVarComplete_get_StateVarName(const UpnpStateVarComplete *p);
void UpnpStateVarComplete_set_StateVarName(UpnpStateVarComplete *p, const UpnpString *s);
void UpnpStateVarComplete_strcpy_StateVarName(UpnpStateVarComplete *p, const char *s);
/** The current value of the variable. This needs to be allocated by
* the caller. When finished with it, the SDK frees this {\bf DOMString}. */
const DOMString UpnpStateVarComplete_get_CurrentVal(const UpnpStateVarComplete *p);
void UpnpStateVarComplete_set_CurrentVal(UpnpStateVarComplete *p, const DOMString s);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* STATEVARCOMPLETE_H */

View File

@ -0,0 +1,80 @@
#ifndef STATEVARREQUEST_H
#define STATEVARREQUEST_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** Represents the request for current value of a state variable in a service
* state table. */
typedef struct {} UpnpStateVarRequest;
#include "String.h" // for UpnpString
#include "ixml.h" // for DOMString
#include <netinet/in.h> // for in_addr
/** Constructor */
UpnpStateVarRequest *UpnpStateVarRequest_new();
/** Destructor */
void UpnpStateVarRequest_delete(UpnpStateVarRequest *p);
/** Copy Constructor */
UpnpStateVarRequest *UpnpStateVarRequest_dup(const UpnpStateVarRequest *p);
/** Assignment operator */
void UpnpStateVarRequest_assign(UpnpStateVarRequest *q, const UpnpStateVarRequest *p);
/** The result of the operation */
int UpnpStateVarRequest_get_ErrCode(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_ErrCode(UpnpStateVarRequest *p, int n);
/** The socket number of the connection to the requestor */
int UpnpStateVarRequest_get_Socket(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_Socket(UpnpStateVarRequest *p, int n);
/** The error string in case of error */
const UpnpString *UpnpStateVarRequest_get_ErrStr(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_ErrStr(UpnpStateVarRequest *p, const UpnpString *s);
void UpnpStateVarRequest_strcpy_ErrStr(UpnpStateVarRequest *p, const char *s);
/** The unique device ID */
const UpnpString *UpnpStateVarRequest_get_DevUDN(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_DevUDN(UpnpStateVarRequest *p, const UpnpString *s);
/** The service ID */
const UpnpString *UpnpStateVarRequest_get_ServiceID(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_ServiceID(UpnpStateVarRequest *p, const UpnpString *s);
/** The name of the variable. */
const UpnpString *UpnpStateVarRequest_get_StateVarName(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_StateVarName(UpnpStateVarRequest *p, const UpnpString *s);
void UpnpStateVarRequest_strcpy_StateVarName(UpnpStateVarRequest *p, const char *s);
/** IP address of sender requesting the state variable. */
struct in_addr *UpnpStateVarRequest_get_CtrlPtIPAddr(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_CtrlPtIPAddr(UpnpStateVarRequest *p, struct in_addr *ia);
/** The current value of the variable. This needs to be allocated by
* the caller. When finished with it, the SDK frees this {\bf DOMString}. */
const DOMString UpnpStateVarRequest_get_CurrentVal(const UpnpStateVarRequest *p);
void UpnpStateVarRequest_set_CurrentVal(UpnpStateVarRequest *p, const DOMString s);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* STATEVARREQUEST_H */

44
upnp/inc/String.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef STRING_H
#define STRING_H
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
typedef struct {} UpnpString;
/** Constructor */
UpnpString *UpnpString_new();
/** Destructor */
void UpnpString_delete(UpnpString *p);
/** Copy Constructor */
UpnpString *UpnpString_dup(const UpnpString *p);
/** Assignment operator */
void UpnpString_assign(UpnpString *q, const UpnpString *p);
/** The length of the string */
int UpnpString_get_Length(const UpnpString *p);
/** The pointer to char */
const char *UpnpString_get_String(const UpnpString *p);
void UpnpString_set_String(UpnpString *p, const char *s);
void UpnpString_set_StringN(UpnpString *p, const char *s, int n);
/* Clears the string, sets its size to zero */
void UpnpString_clear(UpnpString *p);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* STRING_H */

View File

@ -127,9 +127,9 @@
#define MODL_NAME_SIZE 32 #define MODL_NAME_SIZE 32
#define SERL_NUMR_SIZE 64 #define SERL_NUMR_SIZE 64
#define MODL_DESC_SIZE 64 #define MODL_DESC_SIZE 64
#define UPNP_INFINITE -1 #define UPNP_INFINITE -1
#define UPNP_USING_CHUNKED -3 #define UPNP_USING_CHUNKED -3
#define UPNP_UNTIL_CLOSE -4 #define UPNP_UNTIL_CLOSE -4
/** @name Error codes /** @name Error codes
@ -504,7 +504,22 @@
#include "upnpdebug.h" #include "upnpdebug.h"
enum UpnpOpenFileMode{UPNP_READ, UPNP_WRITE};
#include "ActionComplete.h"
#include "ActionRequest.h"
#include "Discovery.h"
#include "EventSubscribe.h"
#include "FileInfo.h"
#include "StateVarComplete.h"
#include "StateVarRequest.h"
enum UpnpOpenFileMode
{
UPNP_READ,
UPNP_WRITE
};
/*! @name Constants, Structures, and Types */ /*! @name Constants, Structures, and Types */
/*! @{ */ /*! @{ */
@ -536,26 +551,26 @@ enum Upnp_EventType_e {
/** Received by a device when a control point issues a control /** Received by a device when a control point issues a control
* request. The {\bf Event} parameter contains a pointer to a {\bf * request. The {\bf Event} parameter contains a pointer to a {\bf
* Upnp_Action_Request} structure containing the action. The application * UpnpActionRequest} structure containing the action. The application
* stores the results of the action in this structure. */ * stores the results of the action in this structure. */
UPNP_CONTROL_ACTION_REQUEST, UPNP_CONTROL_ACTION_REQUEST,
/** A {\bf UpnpSendActionAsync} call completed. The {\bf Event} /** A {\bf UpnpSendActionAsync} call completed. The {\bf Event}
* parameter contains a pointer to a {\bf Upnp_Action_Complete} structure * parameter contains a pointer to a {\bf UpnpActionComplete} structure
* with the results of the action. */ * with the results of the action. */
UPNP_CONTROL_ACTION_COMPLETE, UPNP_CONTROL_ACTION_COMPLETE,
/** Received by a device when a query for a single service variable /** Received by a device when a query for a single service variable
* arrives. The {\bf Event} parameter contains a pointer to a {\bf * arrives. The {\bf Event} parameter contains a pointer to a {\bf
* Upnp_State_Var_Request} structure containing the name of the variable * UpnpStateVarRequest} structure containing the name of the variable
* and value. */ * and value. */
UPNP_CONTROL_GET_VAR_REQUEST, UPNP_CONTROL_GET_VAR_REQUEST,
/** A {\bf UpnpGetServiceVarStatus} call completed. The {\bf Event} /** A {\bf UpnpGetServiceVarStatus} call completed. The {\bf Event}
* parameter contains a pointer to a {\bf Upnp_State_Var_Complete} structure * parameter contains a pointer to a {\bf UpnpStateVarComplete} structure
* containing the value for the variable. */ * containing the value for the variable. */
UPNP_CONTROL_GET_VAR_COMPLETE, UPNP_CONTROL_GET_VAR_COMPLETE,
@ -566,13 +581,13 @@ enum Upnp_EventType_e {
/** Received by a control point when a new device or service is available. /** Received by a control point when a new device or service is available.
* The {\bf Event} parameter contains a pointer to a {\bf * The {\bf Event} parameter contains a pointer to a {\bf
* Upnp_Discovery} structure with the information about the device * UpnpDiscovery} structure with the information about the device
* or service. */ * or service. */
UPNP_DISCOVERY_ADVERTISEMENT_ALIVE, UPNP_DISCOVERY_ADVERTISEMENT_ALIVE,
/** Received by a control point when a device or service shuts down. The {\bf /** Received by a control point when a device or service shuts down. The {\bf
* Event} parameter contains a pointer to a {\bf Upnp_Discovery} * Event} parameter contains a pointer to a {\bf UpnpDiscovery}
* structure containing the information about the device or * structure containing the information about the device or
* service. */ * service. */
@ -580,7 +595,7 @@ enum Upnp_EventType_e {
/** Received by a control point when a matching device or service responds. /** Received by a control point when a matching device or service responds.
* The {\bf Event} parameter contains a pointer to a {\bf * The {\bf Event} parameter contains a pointer to a {\bf
* Upnp_Discovery} structure containing the information about * UpnpDiscovery} structure containing the information about
* the reply to the search request. */ * the reply to the search request. */
UPNP_DISCOVERY_SEARCH_RESULT, UPNP_DISCOVERY_SEARCH_RESULT,
@ -627,12 +642,12 @@ enum Upnp_EventType_e {
/** A {\bf UpnpUnSubscribeAsync} call completed. The status of the /** A {\bf UpnpUnSubscribeAsync} call completed. The status of the
* subscription is in the {\bf Event} parameter as a {\bf * subscription is in the {\bf Event} parameter as a {\bf
* Upnp_Event_Subscribe} structure. */ * EventSubscribe} structure. */
UPNP_EVENT_UNSUBSCRIBE_COMPLETE, UPNP_EVENT_UNSUBSCRIBE_COMPLETE,
/** The auto-renewal of a client subscription failed. /** The auto-renewal of a client subscription failed.
* The {\bf Event} parameter is a {\bf Upnp_Event_Subscribe} structure * The {\bf Event} parameter is a {\bf EventSubscribe} structure
* with the error code set appropriately. The subscription is no longer * with the error code set appropriately. The subscription is no longer
* valid. */ * valid. */
@ -640,7 +655,7 @@ enum Upnp_EventType_e {
/** A client subscription has expired. This will only occur /** A client subscription has expired. This will only occur
* if auto-renewal of subscriptions is disabled. * if auto-renewal of subscriptions is disabled.
* The {\bf Event} parameter is a {\bf Upnp_Event_Subscribe} * The {\bf Event} parameter is a {\bf EventSubscribe}
* structure. The subscription is no longer valid. */ * structure. The subscription is no longer valid. */
UPNP_EVENT_SUBSCRIPTION_EXPIRED UPNP_EVENT_SUBSCRIPTION_EXPIRED
@ -708,109 +723,8 @@ enum Upnp_DescType_e {
typedef enum Upnp_DescType_e Upnp_DescType; typedef enum Upnp_DescType_e Upnp_DescType;
/** Returned as part of a {\bf UPNP_CONTROL_ACTION_COMPLETE} callback. */
struct Upnp_Action_Request
{
/** The result of the operation. */
int ErrCode;
/** The socket number of the connection to the requestor. */
int Socket;
/** The error string in case of error. */
char ErrStr[LINE_SIZE];
/** The Action Name. */
char ActionName[NAME_SIZE];
/** The unique device ID. */
char DevUDN[NAME_SIZE];
/** The service ID. */
char ServiceID[NAME_SIZE];
/** The DOM document describing the action. */
IXML_Document *ActionRequest;
/** The DOM document describing the result of the action. */
IXML_Document *ActionResult;
/** IP address of the control point requesting this action. */
struct in_addr CtrlPtIPAddr;
/** The DOM document containing the information from the
the SOAP header. */
IXML_Document *SoapHeader;
};
struct Upnp_Action_Complete
{
/** The result of the operation. */
int ErrCode;
/** The control URL for service. */
char CtrlUrl[NAME_SIZE];
/** The DOM document describing the action. */
IXML_Document *ActionRequest;
/** The DOM document describing the result of the action. */
IXML_Document *ActionResult;
};
/** Represents the request for current value of a state variable in a service
* state table. */
struct Upnp_State_Var_Request
{
/** The result of the operation. */
int ErrCode;
/** The socket number of the connection to the requestor. */
int Socket;
/** The error string in case of error. */
char ErrStr[LINE_SIZE];
/** The unique device ID. */
char DevUDN[NAME_SIZE];
/** The service ID. */
char ServiceID[NAME_SIZE];
/** The name of the variable. */
char StateVarName[NAME_SIZE];
/** IP address of sender requesting the state variable. */
struct in_addr CtrlPtIPAddr;
/** The current value of the variable. This needs to be allocated by
* the caller. When finished with it, the SDK frees this {\bf DOMString}. */
DOMString CurrentVal;
};
/** Represents the reply for the current value of a state variable in an
asynchronous call. */
struct Upnp_State_Var_Complete
{
/** The result of the operation. */
int ErrCode;
/** The control URL for the service. */
char CtrlUrl[NAME_SIZE];
/** The name of the variable. */
char StateVarName[NAME_SIZE];
/** The current value of the variable or error string in case of error. */
DOMString CurrentVal;
};
/** Returned along with a {\bf UPNP_EVENT_RECEIVED} callback. */ /** Returned along with a {\bf UPNP_EVENT_RECEIVED} callback. */
struct Upnp_Event struct Upnp_Event
{ {
/** The subscription ID for this subscription. */ /** The subscription ID for this subscription. */
@ -821,76 +735,9 @@ struct Upnp_Event
/** The DOM tree representing the changes generating the event. */ /** The DOM tree representing the changes generating the event. */
IXML_Document *ChangedVariables; IXML_Document *ChangedVariables;
}; };
/*
* This typedef is required by Doc++ to parse the last entry of the
* Upnp_Discovery structure correctly.
*/
/** Returned in a {\bf UPNP_DISCOVERY_RESULT} callback. */
struct Upnp_Discovery
{
/** The result code of the {\bf UpnpSearchAsync} call. */
int ErrCode;
/** The expiration time of the advertisement. */
int Expires;
/** The unique device identifier. */
char DeviceId[LINE_SIZE];
/** The device type. */
char DeviceType[LINE_SIZE];
/** The service type. */
char ServiceType[LINE_SIZE];
/** The service version. */
char ServiceVer[LINE_SIZE];
/** The URL to the UPnP description document for the device. */
char Location[LINE_SIZE];
/** The operating system the device is running. */
char Os[LINE_SIZE];
/** Date when the response was generated. */
char Date[LINE_SIZE];
/** Confirmation that the MAN header was understood by the device. */
char Ext[LINE_SIZE];
/** The host address of the device responding to the search. */
struct sockaddr_in DestAddr;
};
/** Returned along with a {\bf UPNP_EVENT_SUBSCRIBE_COMPLETE} or {\bf
* UPNP_EVENT_UNSUBSCRIBE_COMPLETE} callback. */
struct Upnp_Event_Subscribe {
/** The SID for this subscription. For subscriptions, this only
* contains a valid SID if the {\bf Upnp_EventSubscribe.result} field
* contains a {\tt UPNP_E_SUCCESS} result code. For unsubscriptions,
* this contains the SID from which the subscription is being
* unsubscribed. */
Upnp_SID Sid;
/** The result of the operation. */
int ErrCode;
/** The event URL being subscribed to or removed from. */
char PublisherUrl[NAME_SIZE];
/** The actual subscription time (for subscriptions only). */
int TimeOut;
};
/** Returned along with a {\bf UPNP_EVENT_SUBSCRIPTION_REQUEST} /** Returned along with a {\bf UPNP_EVENT_SUBSCRIPTION_REQUEST}
* callback. */ * callback. */
@ -904,37 +751,9 @@ struct Upnp_Subscription_Request
/** The assigned subscription ID for this subscription. */ /** The assigned subscription ID for this subscription. */
Upnp_SID Sid; Upnp_SID Sid;
}; };
struct File_Info
{
/** The length of the file. A length less than 0 indicates the size
* is unknown, and data will be sent until 0 bytes are returned from
* a read call. */
off_t file_length;
/** The time at which the contents of the file was modified;
* The time system is always local (not GMT). */
time_t last_modified;
/** If the file is a directory, {\bf is_directory} contains
* a non-zero value. For a regular file, it should be 0. */
int is_directory;
/** If the file or directory is readable, this contains
* a non-zero value. If unreadable, it should be set to 0. */
int is_readable;
/** The content type of the file. This string needs to be allocated
* by the caller using {\bf ixmlCloneDOMString}. When finished
* with it, the SDK frees the {\bf DOMString}. */
DOMString content_type;
};
/* The type of handle returned by the web server for open requests. */ /* The type of handle returned by the web server for open requests. */
typedef void *UpnpWebFileHandle; typedef void *UpnpWebFileHandle;
@ -945,22 +764,22 @@ typedef void *UpnpWebFileHandle;
*/ */
struct UpnpVirtualDirCallbacks struct UpnpVirtualDirCallbacks
{ {
/** Called by the web server to query information on a file. The callback /** Called by the web server to query information on a file. The callback
* should return 0 on success or -1 on an error. */ * should return 0 on success or -1 on an error. */
int (*get_info) ( int (*get_info) (
IN const char *filename, /** The name of the file to query. */ IN const char *filename, /** The name of the file to query. */
OUT struct File_Info *info /** Pointer to a structure to store the OUT UpnpFileInfo *info /** Pointer to a structure to store the
information on the file. */ information on the file. */
); );
/** Called by the web server to open a file. The callback should return /** Called by the web server to open a file. The callback should return
* a valid handle if the file can be opened. Otherwise, it should return * a valid handle if the file can be opened. Otherwise, it should return
* {\tt NULL} to signify an error. */ * {\tt NULL} to signify an error. */
UpnpWebFileHandle (*open)( UpnpWebFileHandle (*open)(
IN const char *filename, /** The name of the file to open. */ IN const char *filename, /** The name of the file to open. */
IN enum UpnpOpenFileMode Mode /** The mode in which to open the file. IN enum UpnpOpenFileMode Mode /** The mode in which to open the file.
Valid values are {\tt UPNP_READ} or Valid values are {\tt UPNP_READ} or
{\tt UPNP_WRITE}. */ {\tt UPNP_WRITE}. */
); );
/** Called by the web server to perform a sequential read from an open /** Called by the web server to perform a sequential read from an open
@ -1062,11 +881,7 @@ typedef struct virtual_Dir_List
* in the future to communicate results back to the SDK. * in the future to communicate results back to the SDK.
*/ */
typedef int (*Upnp_FunPtr) ( typedef int (*Upnp_FunPtr)(IN Upnp_EventType EventType, IN void *Event, IN void *Cookie);
IN Upnp_EventType EventType,
IN void *Event,
IN void *Cookie
);
/*! @} */ /* Constants, Structures, and Types */ /*! @} */ /* Constants, Structures, and Types */
@ -1891,16 +1706,16 @@ EXPORT_SPEC int UpnpRenewSubscription(
INOUT int *TimeOut, /** Pointer to a variable containing the INOUT int *TimeOut, /** Pointer to a variable containing the
requested subscription time. Upon return, requested subscription time. Upon return,
it contains the actual renewal time. */ it contains the actual renewal time. */
IN Upnp_SID SubsId /** The ID for the subscription to renew. */ IN const Upnp_SID SubsId /** The ID for the subscription to renew. */
); );
/** {\bf UpnpRenewSubscriptionAsync} renews a subscription that is about /** {\bf UpnpRenewSubscriptionAsync} renews a subscription that is about
* to expire, generating a callback when the operation is complete. * to expire, generating a callback when the operation is complete.
* *
* Note that many of the error codes for this function are returned in * Note that many of the error codes for this function are returned in
* the {\bf Upnp_Event_Subscribe} structure. In those cases, the function * the {\bf EventSubscribe} structure. In those cases, the function
* returns {\tt UPNP_E_SUCCESS} and the appropriate error code will * returns {\tt UPNP_E_SUCCESS} and the appropriate error code will
* be in the {\bf Upnp_Event_Subscribe.ErrCode} field in the {\bf Event} * be in the {\bf EventSubscribe.ErrCode} field in the {\bf Event}
* structure passed to the callback. * structure passed to the callback.
* *
* @return [int] An integer representing one of the following: * @return [int] An integer representing one of the following:
@ -1916,30 +1731,30 @@ EXPORT_SPEC int UpnpRenewSubscription(
* \item {\tt UPNP_E_OUTOF_MEMORY}: Insufficient resources exist to * \item {\tt UPNP_E_OUTOF_MEMORY}: Insufficient resources exist to
* complete this operation. * complete this operation.
* \item {\tt UPNP_E_NETWORK_ERROR}: A network error occured (returned in * \item {\tt UPNP_E_NETWORK_ERROR}: A network error occured (returned in
* the {\bf Upnp_Event_Subscribe.ErrCode} field as part of the * the {\bf EventSubscribe.ErrCode} field as part of the
* callback). * callback).
* \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing * \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing
* to a socket (returned in the {\bf Upnp_Event_Subscribe.ErrCode} * to a socket (returned in the {\bf EventSubscribe.ErrCode}
* field as part of the callback). * field as part of the callback).
* \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading * \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading
* from a socket (returned in the * from a socket (returned in the
* {\bf Upnp_Event_Subscribe.ErrCode} field as part of the * {\bf EventSubscribe.ErrCode} field as part of the
* callback). * callback).
* \item {\tt UPNP_E_SOCKET_BIND}: An error occurred binding the socket * \item {\tt UPNP_E_SOCKET_BIND}: An error occurred binding the socket
* (returned in the {\bf Upnp_Event_Subscribe.ErrCode} field as * (returned in the {\bf EventSubscribe.ErrCode} field as
* part of the callback). * part of the callback).
* \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to * \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to
* {\bf PublisherUrl} (returned in the {\bf * {\bf PublisherUrl} (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \item {\tt UPNP_E_OUTOF_SOCKET}: An error occurred creating socket ( * \item {\tt UPNP_E_OUTOF_SOCKET}: An error occurred creating socket (
* returned in the {\bf Upnp_Event_Subscribe.ErrCode} field as * returned in the {\bf EventSubscribe.ErrCode} field as
* part of the callback). * part of the callback).
* \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from * \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from
* the publisher (returned in the {\bf * the publisher (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \item {\tt UPNP_E_SUBSCRIBE_UNACCEPTED}: The publisher refused * \item {\tt UPNP_E_SUBSCRIBE_UNACCEPTED}: The publisher refused
* the subscription request (returned in the {\bf * the subscription request (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \end{itemize} * \end{itemize}
*/ */
@ -2048,9 +1863,9 @@ EXPORT_SPEC int UpnpSubscribe(
* callback function when the operation is complete. * callback function when the operation is complete.
* *
* Note that many of the error codes for this function are returned in * Note that many of the error codes for this function are returned in
* the {\bf Upnp_Event_Subscribe} structure. In those cases, the function * the {\bf EventSubscribe} structure. In those cases, the function
* returns {\tt UPNP_E_SUCCESS} and the appropriate error code will * returns {\tt UPNP_E_SUCCESS} and the appropriate error code will
* be in the {\bf Upnp_Event_Subscribe.ErrCode} field in the {\bf Event} * be in the {\bf EventSubscribe.ErrCode} field in the {\bf Event}
* structure passed to the callback. * structure passed to the callback.
* *
* @return [int] An integer representing one of the following: * @return [int] An integer representing one of the following:
@ -2065,31 +1880,31 @@ EXPORT_SPEC int UpnpSubscribe(
* \item {\tt UPNP_E_OUTOF_MEMORY}: Insufficient resources exist to * \item {\tt UPNP_E_OUTOF_MEMORY}: Insufficient resources exist to
* complete this operation. * complete this operation.
* \item {\tt UPNP_E_NETWORK_ERROR}: A network error occured (returned in * \item {\tt UPNP_E_NETWORK_ERROR}: A network error occured (returned in
* the {\bf Upnp_Event_Subscribe.ErrCode} field as part of the * the {\bf EventSubscribe.ErrCode} field as part of the
* callback). * callback).
* \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing * \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing
* to a socket (returned in the * to a socket (returned in the
* {\bf Upnp_Event_Subscribe.ErrCode} field as part of the * {\bf EventSubscribe.ErrCode} field as part of the
* callback). * callback).
* \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading * \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading
* from a socket (returned in the * from a socket (returned in the
* {\bf Upnp_Event_Subscribe.ErrCode} field as part of the * {\bf EventSubscribe.ErrCode} field as part of the
* callback). * callback).
* \item {\tt UPNP_E_SOCKET_BIND}: An error occurred binding the socket * \item {\tt UPNP_E_SOCKET_BIND}: An error occurred binding the socket
* (returned in the {\bf Upnp_Event_Subscribe.ErrCode} field as * (returned in the {\bf EventSubscribe.ErrCode} field as
* part of the callback). * part of the callback).
* \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to * \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to
* {\bf PublisherUrl} (returned in the {\bf * {\bf PublisherUrl} (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \item {\tt UPNP_E_OUTOF_SOCKET}: An error occurred creating the * \item {\tt UPNP_E_OUTOF_SOCKET}: An error occurred creating the
* socket (returned in the {\bf Upnp_Event_Subscribe.ErrCode} * socket (returned in the {\bf EventSubscribe.ErrCode}
* field as part of the callback). * field as part of the callback).
* \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from * \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from
* the publisher (returned in the {\bf * the publisher (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \item {\tt UPNP_E_SUBSCRIBE_UNACCEPTED}: The publisher refused * \item {\tt UPNP_E_SUBSCRIBE_UNACCEPTED}: The publisher refused
* the subscription request (returned in the {\bf * the subscription request (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \end{itemize} * \end{itemize}
*/ */
@ -2141,7 +1956,7 @@ EXPORT_SPEC int UpnpSubscribeAsync(
EXPORT_SPEC int UpnpUnSubscribe( EXPORT_SPEC int UpnpUnSubscribe(
IN UpnpClient_Handle Hnd, /** The handle of the subscribed control IN UpnpClient_Handle Hnd, /** The handle of the subscribed control
point. */ point. */
IN Upnp_SID SubsId /** The ID returned when the control point IN const Upnp_SID SubsId /** The ID returned when the control point
subscribed to the service. */ subscribed to the service. */
); );
@ -2151,9 +1966,9 @@ EXPORT_SPEC int UpnpUnSubscribe(
* when the operation is complete. * when the operation is complete.
* *
* Note that many of the error codes for this function are returned in * Note that many of the error codes for this function are returned in
* the {\bf Upnp_Event_Subscribe} structure. In those cases, the function * the {\bf EventSubscribe} structure. In those cases, the function
* returns {\tt UPNP_E_SUCCESS} and the appropriate error code will * returns {\tt UPNP_E_SUCCESS} and the appropriate error code will
* be in the {\bf Upnp_Event_Subscribe.ErrCode} field in the {\bf Event} * be in the {\bf EventSubscribe.ErrCode} field in the {\bf Event}
* structure passed to the callback. * structure passed to the callback.
* *
* @return [int] An integer representing one of the following: * @return [int] An integer representing one of the following:
@ -2167,30 +1982,30 @@ EXPORT_SPEC int UpnpUnSubscribe(
* \item {\tt UPNP_E_OUTOF_MEMORY}: Insufficient resources exist to * \item {\tt UPNP_E_OUTOF_MEMORY}: Insufficient resources exist to
* complete this operation. * complete this operation.
* \item {\tt UPNP_E_NETWORK_ERROR}: A network error occured (returned in * \item {\tt UPNP_E_NETWORK_ERROR}: A network error occured (returned in
* the {\bf Upnp_Event_Subscribe.ErrCode} field as part of the * the {\bf EventSubscribe.ErrCode} field as part of the
* callback). * callback).
* \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing * \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing
* to a socket (returned in the {\bf * to a socket (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading * \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading
* from a socket (returned in the * from a socket (returned in the
* {\bf Upnp_Event_Subscribe.ErrCode} field as part of the * {\bf EventSubscribe.ErrCode} field as part of the
* callback). * callback).
* \item {\tt UPNP_E_SOCKET_BIND}: An error occurred binding the socket * \item {\tt UPNP_E_SOCKET_BIND}: An error occurred binding the socket
* (returned in the {\bf Upnp_Event_Subscribe.ErrCode} field as * (returned in the {\bf EventSubscribe.ErrCode} field as
* part of the callback). * part of the callback).
* \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to * \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to
* {\bf PublisherUrl} (returned in the {\bf * {\bf PublisherUrl} (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \item {\tt UPNP_E_OUTOF_SOCKET}: An error occurred creating a socket ( * \item {\tt UPNP_E_OUTOF_SOCKET}: An error occurred creating a socket (
* returned in the {\bf Upnp_Event_Subscribe.ErrCode} field as * returned in the {\bf EventSubscribe.ErrCode} field as
* part of the callback). * part of the callback).
* \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from * \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from
* the publisher (returned in the {\bf * the publisher (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \item {\tt UPNP_E_UNSUBSCRIBE_UNACCEPTED}: The publisher refused * \item {\tt UPNP_E_UNSUBSCRIBE_UNACCEPTED}: The publisher refused
* the subscription request (returned in the {\bf * the subscription request (returned in the {\bf
* Upnp_Event_Subscribe.ErrCode} field as part of the callback). * EventSubscribe.ErrCode} field as part of the callback).
* \end{itemize} */ * \end{itemize} */
EXPORT_SPEC int UpnpUnSubscribeAsync( EXPORT_SPEC int UpnpUnSubscribeAsync(

View File

@ -379,26 +379,28 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE:
case UPNP_DISCOVERY_SEARCH_RESULT: case UPNP_DISCOVERY_SEARCH_RESULT:
{ {
struct Upnp_Discovery *d_event = UpnpDiscovery *d_event = (UpnpDiscovery *)Event;
( struct Upnp_Discovery * )Event; SampleUtil_Print(
"ErrCode = %d\n"
SampleUtil_Print( "ErrCode = %d\n", "Expires = %d\n"
d_event->ErrCode ); "DeviceId = %s\n"
SampleUtil_Print( "Expires = %d\n", "DeviceType = %s\n"
d_event->Expires ); "ServiceType = %s\n"
SampleUtil_Print( "DeviceId = %s\n", "ServiceVer = %s\n"
d_event->DeviceId ); "Location = %s\n"
SampleUtil_Print( "DeviceType = %s\n", "OS = %s\n"
d_event->DeviceType ); "Date = %s\n"
SampleUtil_Print( "ServiceType = %s\n", "Ext = %s\n",
d_event->ServiceType ); UpnpDiscovery_get_ErrCode(d_event),
SampleUtil_Print( "ServiceVer = %s\n", UpnpDiscovery_get_Expires(d_event),
d_event->ServiceVer ); UpnpString_get_String(UpnpDiscovery_get_DeviceID(d_event)),
SampleUtil_Print( "Location = %s\n", UpnpString_get_String(UpnpDiscovery_get_DeviceType(d_event)),
d_event->Location ); UpnpString_get_String(UpnpDiscovery_get_ServiceType(d_event)),
SampleUtil_Print( "OS = %s\n", d_event->Os ); UpnpString_get_String(UpnpDiscovery_get_ServiceVer(d_event)),
SampleUtil_Print( "Ext = %s\n", d_event->Ext ); UpnpString_get_String(UpnpDiscovery_get_Location(d_event)),
UpnpString_get_String(UpnpDiscovery_get_Os(d_event)),
UpnpString_get_String(UpnpDiscovery_get_Date(d_event)),
UpnpString_get_String(UpnpDiscovery_get_Ext(d_event)));
} }
break; break;
@ -411,35 +413,41 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
*/ */
case UPNP_CONTROL_ACTION_REQUEST: case UPNP_CONTROL_ACTION_REQUEST:
{ {
struct Upnp_Action_Request *a_event = UpnpActionRequest *a_event = (UpnpActionRequest *)Event;
( struct Upnp_Action_Request * )Event; IXML_Document *actionRequestDoc = NULL;
IXML_Document *actionResultDoc = NULL;
char *xmlbuff = NULL; char *xmlbuff = NULL;
SampleUtil_Print( "ErrCode = %d\n", SampleUtil_Print(
a_event->ErrCode ); "ErrCode = %d\n"
SampleUtil_Print( "ErrStr = %s\n", a_event->ErrStr ); "ErrStr = %s\n"
SampleUtil_Print( "ActionName = %s\n", "ActionName = %s\n"
a_event->ActionName ); "UDN = %s\n"
SampleUtil_Print( "UDN = %s\n", a_event->DevUDN ); "ServiceID = %s\n",
SampleUtil_Print( "ServiceID = %s\n", UpnpActionRequest_get_ErrCode(a_event),
a_event->ServiceID ); UpnpString_get_String(UpnpActionRequest_get_ErrStr(a_event)),
if( a_event->ActionRequest ) { UpnpString_get_String(UpnpActionRequest_get_ActionName(a_event)),
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest ); UpnpString_get_String(UpnpActionRequest_get_DevUDN(a_event)),
if( xmlbuff ) UpnpString_get_String(UpnpActionRequest_get_ServiceID(a_event)));
actionRequestDoc = UpnpActionRequest_get_ActionRequest(a_event);
if ( actionRequestDoc ) {
xmlbuff = ixmlPrintNode( (IXML_Node *)actionRequestDoc );
if ( xmlbuff ) {
SampleUtil_Print( "ActRequest = %s\n", xmlbuff ); SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActRequest = (null)\n" ); SampleUtil_Print( "ActRequest = (null)\n" );
} }
actionResultDoc = UpnpActionRequest_get_ActionResult(a_event);
if( a_event->ActionResult ) { if ( actionResultDoc ) {
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult ); xmlbuff = ixmlPrintNode( (IXML_Node *)actionResultDoc );
if( xmlbuff ) if ( xmlbuff ) {
SampleUtil_Print( "ActResult = %s\n", xmlbuff ); SampleUtil_Print( "ActResult = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActResult = (null)\n" ); SampleUtil_Print( "ActResult = (null)\n" );
@ -449,31 +457,37 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
case UPNP_CONTROL_ACTION_COMPLETE: case UPNP_CONTROL_ACTION_COMPLETE:
{ {
struct Upnp_Action_Complete *a_event = UpnpActionComplete *a_event = (UpnpActionComplete *)Event;
( struct Upnp_Action_Complete * )Event;
char *xmlbuff = NULL; char *xmlbuff = NULL;
int errCode = UpnpActionComplete_get_ErrCode(a_event);
const char *ctrlURL = UpnpString_get_String(
UpnpActionComplete_get_CtrlUrl(a_event));
IXML_Document *actionRequest =
UpnpActionComplete_get_ActionRequest(a_event);
IXML_Document *actionResult =
UpnpActionComplete_get_ActionResult(a_event);
SampleUtil_Print( "ErrCode = %d\n", SampleUtil_Print(
a_event->ErrCode ); "ErrCode = %d\n"
SampleUtil_Print( "CtrlUrl = %s\n", "CtrlUrl = %s\n",
a_event->CtrlUrl ); errCode, ctrlURL);
if( a_event->ActionRequest ) { if( actionRequest ) {
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionRequest ); xmlbuff = ixmlPrintNode((IXML_Node *)actionRequest);
if( xmlbuff ) if( xmlbuff ) {
SampleUtil_Print( "ActRequest = %s\n", xmlbuff ); SampleUtil_Print( "ActRequest = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActRequest = (null)\n" ); SampleUtil_Print( "ActRequest = (null)\n" );
} }
if( a_event->ActionResult ) { if( actionResult ) {
xmlbuff = ixmlPrintNode( ( IXML_Node * ) a_event->ActionResult ); xmlbuff = ixmlPrintNode((IXML_Node *)actionResult);
if( xmlbuff ) if( xmlbuff ) {
SampleUtil_Print( "ActResult = %s\n", xmlbuff ); SampleUtil_Print( "ActResult = %s\n", xmlbuff );
if( xmlbuff )
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
}
xmlbuff = NULL; xmlbuff = NULL;
} else { } else {
SampleUtil_Print( "ActResult = (null)\n" ); SampleUtil_Print( "ActResult = (null)\n" );
@ -483,37 +497,35 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:
{ {
struct Upnp_State_Var_Request *sv_event = UpnpStateVarRequest *sv_event = (UpnpStateVarRequest *)Event;
( struct Upnp_State_Var_Request * )Event; SampleUtil_Print(
"ErrCode = %d\n"
SampleUtil_Print( "ErrCode = %d\n", "ErrStr = %s\n"
sv_event->ErrCode ); "UDN = %s\n"
SampleUtil_Print( "ErrStr = %s\n", "ServiceID = %s\n"
sv_event->ErrStr ); "StateVarName= %s\n"
SampleUtil_Print( "UDN = %s\n", "CurrentVal = %s\n",
sv_event->DevUDN ); UpnpStateVarRequest_get_ErrCode(sv_event),
SampleUtil_Print( "ServiceID = %s\n", UpnpString_get_String(UpnpStateVarRequest_get_ErrStr(sv_event)),
sv_event->ServiceID ); UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(sv_event)),
SampleUtil_Print( "StateVarName= %s\n", UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(sv_event)),
sv_event->StateVarName ); UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(sv_event)),
SampleUtil_Print( "CurrentVal = %s\n", UpnpStateVarRequest_get_CurrentVal(sv_event));
sv_event->CurrentVal );
} }
break; break;
case UPNP_CONTROL_GET_VAR_COMPLETE: case UPNP_CONTROL_GET_VAR_COMPLETE:
{ {
struct Upnp_State_Var_Complete *sv_event = UpnpStateVarComplete *sv_event = (UpnpStateVarComplete *)Event;
( struct Upnp_State_Var_Complete * )Event; SampleUtil_Print(
"ErrCode = %d\n"
SampleUtil_Print( "ErrCode = %d\n", "CtrlUrl = %s\n"
sv_event->ErrCode ); "StateVarName= %s\n"
SampleUtil_Print( "CtrlUrl = %s\n", "CurrentVal = %s\n",
sv_event->CtrlUrl ); UpnpStateVarComplete_get_ErrCode(sv_event),
SampleUtil_Print( "StateVarName= %s\n", UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)),
sv_event->StateVarName ); UpnpString_get_String(UpnpStateVarComplete_get_StateVarName(sv_event)),
SampleUtil_Print( "CurrentVal = %s\n", UpnpStateVarComplete_get_CurrentVal(sv_event));
sv_event->CurrentVal );
} }
break; break;
@ -523,83 +535,85 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
{ {
struct Upnp_Subscription_Request *sr_event = struct Upnp_Subscription_Request *sr_event =
( struct Upnp_Subscription_Request * )Event; (struct Upnp_Subscription_Request *)Event;
SampleUtil_Print(
SampleUtil_Print( "ServiceID = %s\n", "ServiceID = %s\n"
sr_event->ServiceId ); "UDN = %s\n"
SampleUtil_Print( "UDN = %s\n", sr_event->UDN ); "SID = %s\n",
SampleUtil_Print( "SID = %s\n", sr_event->Sid ); sr_event->ServiceId,
sr_event->UDN,
sr_event->Sid );
} }
break; break;
case UPNP_EVENT_RECEIVED: case UPNP_EVENT_RECEIVED:
{ {
struct Upnp_Event *e_event = ( struct Upnp_Event * )Event; struct Upnp_Event *e_event = (struct Upnp_Event *)Event;
char *xmlbuff = NULL; char *xmlbuff = NULL;
xmlbuff = ixmlPrintNode( (IXML_Node *) e_event->ChangedVariables );
SampleUtil_Print( "SID = %s\n", e_event->Sid ); SampleUtil_Print(
SampleUtil_Print( "EventKey = %d\n", "SID = %s\n"
e_event->EventKey ); "EventKey = %d\n"
xmlbuff = ixmlPrintNode( ( IXML_Node * ) e_event->ChangedVariables ); "ChangedVars = %s\n",
SampleUtil_Print( "ChangedVars = %s\n", xmlbuff ); e_event->Sid,
e_event->EventKey,
xmlbuff );
ixmlFreeDOMString( xmlbuff ); ixmlFreeDOMString( xmlbuff );
xmlbuff = NULL;
} }
break; break;
case UPNP_EVENT_RENEWAL_COMPLETE: case UPNP_EVENT_RENEWAL_COMPLETE:
{ {
struct Upnp_Event_Subscribe *es_event = EventSubscribe *es_event = (EventSubscribe *)Event;
( struct Upnp_Event_Subscribe * )Event; SampleUtil_Print(
"SID = %s\n"
SampleUtil_Print( "SID = %s\n", es_event->Sid ); "ErrCode = %d\n"
SampleUtil_Print( "ErrCode = %d\n", "TimeOut = %d\n",
es_event->ErrCode ); UpnpString_get_String(UpnpEventSubscribe_get_SID(es_event)),
SampleUtil_Print( "TimeOut = %d\n", UpnpEventSubscribe_get_ErrCode(es_event),
es_event->TimeOut ); UpnpEventSubscribe_get_TimeOut(es_event));
} }
break; break;
case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_SUBSCRIBE_COMPLETE:
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
{ {
struct Upnp_Event_Subscribe *es_event = EventSubscribe *es_event = (EventSubscribe *)Event;
( struct Upnp_Event_Subscribe * )Event; SampleUtil_Print(
"SID = %s\n"
SampleUtil_Print( "SID = %s\n", es_event->Sid ); "ErrCode = %d\n"
SampleUtil_Print( "ErrCode = %d\n", "PublisherURL= %s\n"
es_event->ErrCode ); "TimeOut = %d\n",
SampleUtil_Print( "PublisherURL= %s\n", UpnpString_get_String(UpnpEventSubscribe_get_SID(es_event)),
es_event->PublisherUrl ); UpnpEventSubscribe_get_ErrCode(es_event),
SampleUtil_Print( "TimeOut = %d\n", UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
es_event->TimeOut ); UpnpEventSubscribe_get_TimeOut(es_event));
} }
break; break;
case UPNP_EVENT_AUTORENEWAL_FAILED: case UPNP_EVENT_AUTORENEWAL_FAILED:
case UPNP_EVENT_SUBSCRIPTION_EXPIRED: case UPNP_EVENT_SUBSCRIPTION_EXPIRED:
{ {
struct Upnp_Event_Subscribe *es_event = EventSubscribe *es_event = (EventSubscribe *)Event;
( struct Upnp_Event_Subscribe * )Event; SampleUtil_Print(
"SID = %s\n"
SampleUtil_Print( "SID = %s\n", es_event->Sid ); "ErrCode = %d\n"
SampleUtil_Print( "ErrCode = %d\n", "PublisherURL= %s\n"
es_event->ErrCode ); "TimeOut = %d\n",
SampleUtil_Print( "PublisherURL= %s\n", UpnpString_get_String(UpnpEventSubscribe_get_SID(es_event)),
es_event->PublisherUrl ); UpnpEventSubscribe_get_ErrCode(es_event),
SampleUtil_Print( "TimeOut = %d\n", UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
es_event->TimeOut ); UpnpEventSubscribe_get_TimeOut(es_event));
} }
break; break;
} }
SampleUtil_Print SampleUtil_Print(
( "----------------------------------------------------------------------\n" ); "----------------------------------------------------------------------\n"
SampleUtil_Print "======================================================================\n\n\n\n" );
( "======================================================================\n\n\n\n" );
ithread_mutex_unlock( &display_mutex ); ithread_mutex_unlock( &display_mutex );
return ( 0 ); return 0;
} }
/******************************************************************************** /********************************************************************************
@ -620,7 +634,7 @@ SampleUtil_PrintEvent( IN Upnp_EventType EventType,
********************************************************************************/ ********************************************************************************/
int int
SampleUtil_FindAndParseService( IN IXML_Document * DescDoc, SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
IN char *location, IN const char *location,
IN char *serviceType, IN char *serviceType,
OUT char **serviceId, OUT char **serviceId,
OUT char **eventURL, OUT char **eventURL,
@ -632,18 +646,18 @@ SampleUtil_FindAndParseService( IN IXML_Document * DescDoc,
int ret; int ret;
char *tempServiceType = NULL; char *tempServiceType = NULL;
char *baseURL = NULL; char *baseURL = NULL;
char *base; const char *base = NULL;
char *relcontrolURL = NULL, char *relcontrolURL = NULL,
*releventURL = NULL; *releventURL = NULL;
IXML_NodeList *serviceList = NULL; IXML_NodeList *serviceList = NULL;
IXML_Element *service = NULL; IXML_Element *service = NULL;
baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" ); baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" );
if (baseURL) {
if( baseURL )
base = baseURL; base = baseURL;
else } else {
base = location; base = location;
}
serviceList = SampleUtil_GetFirstServiceList( DescDoc ); serviceList = SampleUtil_GetFirstServiceList( DescDoc );
length = ixmlNodeList_length( serviceList ); length = ixmlNodeList_length( serviceList );
@ -753,22 +767,23 @@ uprint1( char *fmt,
* Same as printf() * Same as printf()
* *
********************************************************************************/ ********************************************************************************/
int int SampleUtil_Print(char *fmt, ...)
SampleUtil_Print( char *fmt,
... )
{ {
#define MAX_BUF 1024
va_list ap; va_list ap;
char buf[200]; static char buf[MAX_BUF];
int rc; int rc;
va_start( ap, fmt ); /* Protect both the display and the static buffer with the mutex */
rc = vsnprintf( buf, 200, fmt, ap ); ithread_mutex_lock(&display_mutex);
va_end( ap ); va_start(ap, fmt);
rc = vsnprintf(buf, MAX_BUF, fmt, ap);
va_end(ap);
ithread_mutex_lock( &display_mutex ); if (gPrintFun) {
if( gPrintFun ) gPrintFun(buf);
gPrintFun( buf ); }
ithread_mutex_unlock( &display_mutex ); ithread_mutex_unlock(&display_mutex);
return rc; return rc;
} }

View File

@ -166,7 +166,7 @@ int SampleUtil_PrintEvent(IN Upnp_EventType EventType,
********************************************************************************/ ********************************************************************************/
int SampleUtil_FindAndParseService ( int SampleUtil_FindAndParseService (
IN IXML_Document *DescDoc, IN IXML_Document *DescDoc,
IN char* location, IN const char* location,
IN char *serviceType, IN char *serviceType,
OUT char **serviceId, OUT char **serviceId,
OUT char **eventURL, OUT char **eventURL,

View File

@ -139,10 +139,10 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
* *
********************************************************************************/ ********************************************************************************/
int int
TvCtrlPointRemoveDevice( char *UDN ) TvCtrlPointRemoveDevice(const char *UDN)
{ {
struct TvDeviceNode *curdevnode, struct TvDeviceNode *curdevnode;
*prevdevnode; struct TvDeviceNode *prevdevnode;
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
@ -668,8 +668,8 @@ TvCtrlPointPrintDevice( int devnum )
* *
********************************************************************************/ ********************************************************************************/
void void
TvCtrlPointAddDevice( IXML_Document * DescDoc, TvCtrlPointAddDevice( IXML_Document *DescDoc,
char *location, const char *location,
int expires ) int expires )
{ {
char *deviceType = NULL; char *deviceType = NULL;
@ -682,20 +682,19 @@ TvCtrlPointAddDevice( IXML_Document * DescDoc,
char *eventURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL }; char *eventURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL };
char *controlURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL }; char *controlURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL };
Upnp_SID eventSID[TV_SERVICE_SERVCOUNT]; Upnp_SID eventSID[TV_SERVICE_SERVCOUNT];
int TimeOut[TV_SERVICE_SERVCOUNT] = int TimeOut[TV_SERVICE_SERVCOUNT] = {
{ default_timeout, default_timeout }; default_timeout,
default_timeout };
struct TvDeviceNode *deviceNode; struct TvDeviceNode *deviceNode;
struct TvDeviceNode *tmpdevnode; struct TvDeviceNode *tmpdevnode;
int ret = 1; int ret = 1;
int found = 0; int found = 0;
int service, int service;
var; int var;
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
/* /* Read key elements from description document */
Read key elements from description document
*/
UDN = SampleUtil_GetFirstDocumentItem( DescDoc, "UDN" ); UDN = SampleUtil_GetFirstDocumentItem( DescDoc, "UDN" );
deviceType = SampleUtil_GetFirstDocumentItem( DescDoc, "deviceType" ); deviceType = SampleUtil_GetFirstDocumentItem( DescDoc, "deviceType" );
friendlyName = friendlyName =
@ -703,9 +702,8 @@ TvCtrlPointAddDevice( IXML_Document * DescDoc,
baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" ); baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" );
relURL = SampleUtil_GetFirstDocumentItem( DescDoc, "presentationURL" ); relURL = SampleUtil_GetFirstDocumentItem( DescDoc, "presentationURL" );
ret = ret = UpnpResolveURL(
UpnpResolveURL( ( baseURL ? baseURL : location ), relURL, ( baseURL ? baseURL : location ), relURL, presURL);
presURL );
if( UPNP_E_SUCCESS != ret ) if( UPNP_E_SUCCESS != ret )
SampleUtil_Print( "Error generating presURL from %s + %s", baseURL, SampleUtil_Print( "Error generating presURL from %s + %s", baseURL,
@ -983,10 +981,10 @@ TvCtrlPointHandleEvent( Upnp_SID sid,
* timeout -- The new timeout for the subscription * timeout -- The new timeout for the subscription
* *
********************************************************************************/ ********************************************************************************/
void void TvCtrlPointHandleSubscribeUpdate(
TvCtrlPointHandleSubscribeUpdate( char *eventURL, const char *eventURL,
Upnp_SID sid, const Upnp_SID sid,
int timeout ) int timeout)
{ {
struct TvDeviceNode *tmpdevnode; struct TvDeviceNode *tmpdevnode;
int service; int service;
@ -1015,9 +1013,9 @@ TvCtrlPointHandleSubscribeUpdate( char *eventURL,
} }
void void
TvCtrlPointHandleGetVar( char *controlURL, TvCtrlPointHandleGetVar( const char *controlURL,
char *varName, const char *varName,
DOMString varValue ) const DOMString varValue )
{ {
struct TvDeviceNode *tmpdevnode; struct TvDeviceNode *tmpdevnode;
@ -1026,14 +1024,11 @@ TvCtrlPointHandleGetVar( char *controlURL,
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while (tmpdevnode) {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for (service = 0; service < TV_SERVICE_SERVCOUNT; service++) {
if( strcmp if (strcmp(tmpdevnode->device.TvService[service].ControlURL, controlURL ) == 0 ) {
( tmpdevnode->device.TvService[service].ControlURL, SampleUtil_StateUpdate(
controlURL ) == 0 ) { varName, varValue, tmpdevnode->device.UDN, GET_VAR_COMPLETE );
SampleUtil_StateUpdate( varName, varValue,
tmpdevnode->device.UDN,
GET_VAR_COMPLETE );
break; break;
} }
} }
@ -1057,186 +1052,159 @@ TvCtrlPointHandleGetVar( char *controlURL,
* Cookie -- Optional data specified during callback registration * Cookie -- Optional data specified during callback registration
* *
********************************************************************************/ ********************************************************************************/
int int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
TvCtrlPointCallbackEventHandler( Upnp_EventType EventType,
void *Event,
void *Cookie )
{ {
SampleUtil_PrintEvent( EventType, Event ); int errCode = 0;
switch ( EventType ) { SampleUtil_PrintEvent(EventType, Event);
/* switch ( EventType ) {
SSDP Stuff /* SSDP Stuff */
*/ case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_SEARCH_RESULT: {
case UPNP_DISCOVERY_SEARCH_RESULT: UpnpDiscovery *d_event = (UpnpDiscovery *)Event;
{ IXML_Document *DescDoc = NULL;
struct Upnp_Discovery *d_event = const char *location = NULL;
( struct Upnp_Discovery * )Event; int errCode = UpnpDiscovery_get_ErrCode(d_event);
IXML_Document *DescDoc = NULL; if (errCode != UPNP_E_SUCCESS) {
int ret; SampleUtil_Print(
"Error in Discovery Callback -- %d", errCode);
}
if( d_event->ErrCode != UPNP_E_SUCCESS ) { location = UpnpString_get_String(
SampleUtil_Print( "Error in Discovery Callback -- %d", UpnpDiscovery_get_Location(d_event));
d_event->ErrCode ); errCode = UpnpDownloadXmlDoc(location, &DescDoc);
} if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error obtaining device description from %s -- error = %d",
location, errCode);
} else {
TvCtrlPointAddDevice(
DescDoc, location, UpnpDiscovery_get_Expires(d_event));
}
if( ( ret = if( DescDoc ) {
UpnpDownloadXmlDoc( d_event->Location, ixmlDocument_free(DescDoc);
&DescDoc ) ) != }
UPNP_E_SUCCESS ) {
SampleUtil_Print
( "Error obtaining device description from %s -- error = %d",
d_event->Location, ret );
} else {
TvCtrlPointAddDevice( DescDoc, d_event->Location,
d_event->Expires );
}
if( DescDoc ) TvCtrlPointPrintList();
ixmlDocument_free( DescDoc ); break;
}
TvCtrlPointPrintList(); case UPNP_DISCOVERY_SEARCH_TIMEOUT:
break; /* Nothing to do here... */
} break;
case UPNP_DISCOVERY_SEARCH_TIMEOUT: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: {
/* UpnpDiscovery *d_event = (UpnpDiscovery *)Event;
Nothing to do here... int errCode = UpnpDiscovery_get_ErrCode(d_event);
*/ const char *deviceId = UpnpString_get_String(
break; UpnpDiscovery_get_DeviceID(d_event));
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: if (errCode != UPNP_E_SUCCESS) {
{ SampleUtil_Print(
struct Upnp_Discovery *d_event = "Error in Discovery ByeBye Callback -- %d", errCode);
( struct Upnp_Discovery * )Event; }
if( d_event->ErrCode != UPNP_E_SUCCESS ) { SampleUtil_Print("Received ByeBye for Device: %s", deviceId);
SampleUtil_Print TvCtrlPointRemoveDevice(deviceId);
( "Error in Discovery ByeBye Callback -- %d",
d_event->ErrCode );
}
SampleUtil_Print( "Received ByeBye for Device: %s", SampleUtil_Print("After byebye:");
d_event->DeviceId ); TvCtrlPointPrintList();
TvCtrlPointRemoveDevice( d_event->DeviceId );
SampleUtil_Print( "After byebye:" ); break;
TvCtrlPointPrintList(); }
break; /* SOAP Stuff */
} case UPNP_CONTROL_ACTION_COMPLETE: {
UpnpActionComplete *a_event = (UpnpActionComplete *)Event;
int errCode = UpnpActionComplete_get_ErrCode(a_event);
if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error in Action Complete Callback -- %d",
errCode);
}
/* /* No need for any processing here, just print out results.
SOAP Stuff * Service state table updates are handled by events. */
*/
case UPNP_CONTROL_ACTION_COMPLETE:
{
struct Upnp_Action_Complete *a_event =
( struct Upnp_Action_Complete * )Event;
if( a_event->ErrCode != UPNP_E_SUCCESS ) { break;
SampleUtil_Print }
( "Error in Action Complete Callback -- %d",
a_event->ErrCode );
}
/* case UPNP_CONTROL_GET_VAR_COMPLETE: {
No need for any processing here, just print out results. Service state UpnpStateVarComplete *sv_event = (UpnpStateVarComplete *)Event;
table updates are handled by events. int errCode = UpnpStateVarComplete_get_ErrCode(sv_event);
*/ if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error in Get Var Complete Callback -- %d",
errCode );
} else {
TvCtrlPointHandleGetVar(
UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)),
UpnpString_get_String(UpnpStateVarComplete_get_StateVarName(sv_event)),
UpnpStateVarComplete_get_CurrentVal(sv_event) );
}
break;
}
break; /* GENA Stuff */
} case UPNP_EVENT_RECEIVED: {
struct Upnp_Event *e_event = ( struct Upnp_Event * )Event;
TvCtrlPointHandleEvent( e_event->Sid, e_event->EventKey,
e_event->ChangedVariables );
break;
}
case UPNP_CONTROL_GET_VAR_COMPLETE: case UPNP_EVENT_SUBSCRIBE_COMPLETE:
{ case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
struct Upnp_State_Var_Complete *sv_event = case UPNP_EVENT_RENEWAL_COMPLETE: {
( struct Upnp_State_Var_Complete * )Event; EventSubscribe *es_event = (EventSubscribe *)Event;
errCode = UpnpEventSubscribe_get_ErrCode(es_event);
if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error in Event Subscribe Callback -- %d",
errCode);
} else {
TvCtrlPointHandleSubscribeUpdate(
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
UpnpString_get_String(UpnpEventSubscribe_get_SID(es_event)),
UpnpEventSubscribe_get_TimeOut(es_event));
}
if( sv_event->ErrCode != UPNP_E_SUCCESS ) { break;
SampleUtil_Print }
( "Error in Get Var Complete Callback -- %d",
sv_event->ErrCode );
} else {
TvCtrlPointHandleGetVar( sv_event->CtrlUrl,
sv_event->StateVarName,
sv_event->CurrentVal );
}
break; case UPNP_EVENT_AUTORENEWAL_FAILED:
} case UPNP_EVENT_SUBSCRIPTION_EXPIRED: {
EventSubscribe *es_event = (EventSubscribe *)Event;
int TimeOut = default_timeout;
Upnp_SID newSID;
/* errCode = UpnpSubscribe(
GENA Stuff ctrlpt_handle,
*/ UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
case UPNP_EVENT_RECEIVED: &TimeOut,
{ newSID);
struct Upnp_Event *e_event = ( struct Upnp_Event * )Event;
TvCtrlPointHandleEvent( e_event->Sid, e_event->EventKey, if (errCode == UPNP_E_SUCCESS) {
e_event->ChangedVariables ); SampleUtil_Print("Subscribed to EventURL with SID=%s", newSID);
break; TvCtrlPointHandleSubscribeUpdate(
} UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
newSID,
TimeOut);
} else {
SampleUtil_Print("Error Subscribing to EventURL -- %d", errCode);
}
break;
}
case UPNP_EVENT_SUBSCRIBE_COMPLETE: /* ignore these cases, since this is not a device */
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
case UPNP_EVENT_RENEWAL_COMPLETE: case UPNP_CONTROL_GET_VAR_REQUEST:
{ case UPNP_CONTROL_ACTION_REQUEST:
struct Upnp_Event_Subscribe *es_event = break;
( struct Upnp_Event_Subscribe * )Event; }
if( es_event->ErrCode != UPNP_E_SUCCESS ) { return 0;
SampleUtil_Print
( "Error in Event Subscribe Callback -- %d",
es_event->ErrCode );
} else {
TvCtrlPointHandleSubscribeUpdate( es_event->
PublisherUrl,
es_event->Sid,
es_event->TimeOut );
}
break;
}
case UPNP_EVENT_AUTORENEWAL_FAILED:
case UPNP_EVENT_SUBSCRIPTION_EXPIRED:
{
int TimeOut = default_timeout;
Upnp_SID newSID;
int ret;
struct Upnp_Event_Subscribe *es_event =
( struct Upnp_Event_Subscribe * )Event;
ret =
UpnpSubscribe( ctrlpt_handle, es_event->PublisherUrl,
&TimeOut, newSID );
if( ret == UPNP_E_SUCCESS ) {
SampleUtil_Print( "Subscribed to EventURL with SID=%s",
newSID );
TvCtrlPointHandleSubscribeUpdate( es_event->
PublisherUrl, newSID,
TimeOut );
} else {
SampleUtil_Print
( "Error Subscribing to EventURL -- %d", ret );
}
break;
}
/*
ignore these cases, since this is not a device
*/
case UPNP_EVENT_SUBSCRIPTION_REQUEST:
case UPNP_CONTROL_GET_VAR_REQUEST:
case UPNP_CONTROL_ACTION_REQUEST:
break;
}
return 0;
} }
/******************************************************************************** /********************************************************************************
@ -1374,12 +1342,8 @@ TvCtrlPointStart( print_string printFunctionPtr,
//return TV_ERROR; //return TV_ERROR;
} }
if( NULL == ip_address ) { ip_address = UpnpGetServerIpAddress();
ip_address = UpnpGetServerIpAddress(); port = UpnpGetServerPort();
}
if( 0 == port ) {
port = UpnpGetServerPort();
}
SampleUtil_Print( SampleUtil_Print(
"UPnP Initialized\n" "UPnP Initialized\n"
@ -1406,7 +1370,7 @@ TvCtrlPointStart( print_string printFunctionPtr,
} }
int int
TvCtrlPointStop( void ) TvCtrlPointStop()
{ {
TvCtrlPointRemoveAll(); TvCtrlPointRemoveAll();
UpnpUnRegisterClient( ctrlpt_handle ); UpnpUnRegisterClient( ctrlpt_handle );

View File

@ -110,11 +110,11 @@ extern ithread_mutex_t DeviceListMutex;
extern UpnpClient_Handle ctrlpt_handle; extern UpnpClient_Handle ctrlpt_handle;
void TvCtrlPointPrintHelp( void ); void TvCtrlPointPrintHelp();
int TvCtrlPointDeleteNode(struct TvDeviceNode*); int TvCtrlPointDeleteNode(struct TvDeviceNode*);
int TvCtrlPointRemoveDevice(char*); int TvCtrlPointRemoveDevice(const char *);
int TvCtrlPointRemoveAll( void ); int TvCtrlPointRemoveAll();
int TvCtrlPointRefresh( void ); int TvCtrlPointRefresh();
int TvCtrlPointSendAction(int, int, char *, char **, char **, int); int TvCtrlPointSendAction(int, int, char *, char **, char **, int);
@ -140,11 +140,11 @@ int TvCtrlPointGetBrightness(int);
int TvCtrlPointGetDevice(int, struct TvDeviceNode **); int TvCtrlPointGetDevice(int, struct TvDeviceNode **);
int TvCtrlPointPrintList( void ); int TvCtrlPointPrintList( void );
int TvCtrlPointPrintDevice(int); int TvCtrlPointPrintDevice(int);
void TvCtrlPointAddDevice (IXML_Document *, char *, int); void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
void TvCtrlPointHandleGetVar(char *,char *,DOMString); void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
void TvStateUpdate(char*,int, IXML_Document * , char **); void TvStateUpdate(char*,int, IXML_Document * , char **);
void TvCtrlPointHandleEvent(Upnp_SID, int, IXML_Document *); void TvCtrlPointHandleEvent(Upnp_SID, int, IXML_Document *);
void TvCtrlPointHandleSubscribeUpdate(char *, Upnp_SID, int); void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int);
int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *); int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *);
void TvCtrlPointVerifyTimeouts(int); void TvCtrlPointVerifyTimeouts(int);
void TvCtrlPointPrintCommands( void ); void TvCtrlPointPrintCommands( void );

View File

@ -178,7 +178,6 @@ SetServiceTable( IN int serviceType,
} }
return SetActionTable( serviceType, out ); return SetActionTable( serviceType, out );
} }
/****************************************************************************** /******************************************************************************
@ -249,7 +248,6 @@ SetActionTable( IN int serviceType,
} }
return 0; return 0;
} }
/****************************************************************************** /******************************************************************************
@ -434,31 +432,32 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
*cgv_event )
{ {
unsigned int i = 0, unsigned int i = 0;
j = 0; unsigned int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
cgv_event->CurrentVal = NULL; UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
//check udn and service id // check udn and service id
if( ( strcmp( cgv_event->DevUDN, tv_service_table[i].UDN ) == 0 ) const char *devUDN =
&& UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event));
( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId ) const char *serviceID =
== 0 ) ) { UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event));
//check variable name if( ( strcmp( devUDN, tv_service_table[i].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[i].ServiceId ) == 0 ) ) {
// check variable name
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) { for( j = 0; j < tv_service_table[i].VariableCount; j++ ) {
if( strcmp( cgv_event->StateVarName, const char *stateVarName =
tv_service_table[i].VariableName[j] ) == 0 ) { UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event));
if( strcmp( stateVarName, tv_service_table[i].VariableName[j] ) == 0 ) {
getvar_succeeded = 1; getvar_succeeded = 1;
cgv_event->CurrentVal = UpnpStateVarRequest_set_CurrentVal(cgv_event,
ixmlCloneDOMString( tv_service_table[i]. tv_service_table[i].VariableStrVal[j] );
VariableStrVal[j] );
break; break;
} }
} }
@ -466,19 +465,19 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
} }
if( getvar_succeeded ) { if( getvar_succeeded ) {
cgv_event->ErrCode = UPNP_E_SUCCESS; UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else { } else {
SampleUtil_Print SampleUtil_Print(
( "Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n" ); "Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"
SampleUtil_Print( " Unknown variable name = %s\n", " Unknown variable name = %s\n",
cgv_event->StateVarName ); UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)) );
cgv_event->ErrCode = 404; UpnpStateVarRequest_set_ErrCode(cgv_event, 404);
strcpy( cgv_event->ErrStr, "Invalid Variable" ); UpnpStateVarRequest_strcpy_ErrStr(cgv_event, "Invalid Variable" );
} }
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( cgv_event->ErrCode == UPNP_E_SUCCESS ); return UpnpStateVarRequest_get_ErrCode(cgv_event) == UPNP_E_SUCCESS;
} }
/****************************************************************************** /******************************************************************************
@ -494,9 +493,8 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event ) TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
{ {
/* /*
Defaults if action not found Defaults if action not found
*/ */
@ -505,51 +503,38 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
int service = -1; int service = -1;
int retCode = 0; int retCode = 0;
char *errorString = NULL; char *errorString = NULL;
const char *devUDN = NULL;
const char *serviceID = NULL;
const char *actionName = NULL;
IXML_Document *actionResult = NULL;
ca_event->ErrCode = 0; UpnpActionRequest_set_ErrCode(ca_event, 0);
ca_event->ActionResult = NULL; UpnpActionRequest_set_ActionResult(ca_event, NULL);
if( ( strcmp( ca_event->DevUDN, devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event));
tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) && serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event));
( strcmp actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event));
( ca_event->ServiceID, if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) &&
tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) { ( strcmp( serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) {
/* /* Request for action in the TvDevice Control Service */
Request for action in the TvDevice Control Service
*/
service = TV_SERVICE_CONTROL; service = TV_SERVICE_CONTROL;
} else if( ( strcmp( ca_event->DevUDN, } else if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) &&
tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) ( strcmp( serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId ) == 0 ) ) {
&& /* Request for action in the TvDevice Picture Service */
( strcmp
( ca_event->ServiceID,
tv_service_table[TV_SERVICE_PICTURE].ServiceId ) ==
0 ) ) {
/*
Request for action in the TvDevice Picture Service
*/
service = TV_SERVICE_PICTURE; service = TV_SERVICE_PICTURE;
} }
//Find and call appropriate procedure based on action name /* Find and call appropriate procedure based on action name
//Each action name has an associated procedure stored in the * Each action name has an associated procedure stored in the
//service table. These are set at initialization. * service table. These are set at initialization. */
for( i = 0; i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL; i++ ) {
for( i = 0; ( ( i < TV_MAXACTIONS ) && if( !strcmp( actionName, tv_service_table[service].ActionNames[i] ) ) {
( tv_service_table[service].ActionNames[i] != NULL ) ); if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_POWER], "1" ) ) ||
i++ ) { ( !strcmp( actionName, "PowerOn" ) ) ) {
retCode = tv_service_table[service].actions[i](
if( !strcmp( ca_event->ActionName, UpnpActionRequest_get_ActionRequest(ca_event),
tv_service_table[service].ActionNames[i] ) ) { &actionResult,
&errorString );
if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL]. UpnpActionRequest_set_ActionResult(ca_event, actionResult);
VariableStrVal[TV_CONTROL_POWER], "1" ) )
|| ( !strcmp( ca_event->ActionName, "PowerOn" ) ) ) {
retCode =
tv_service_table[service].actions[i] ( ca_event->
ActionRequest,
&ca_event->
ActionResult,
&errorString );
} else { } else {
errorString = "Power is Off"; errorString = "Power is Off";
retCode = UPNP_E_INTERNAL_ERROR; retCode = UPNP_E_INTERNAL_ERROR;
@ -560,25 +545,25 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
} }
if( !action_found ) { if( !action_found ) {
ca_event->ActionResult = NULL; UpnpActionRequest_set_ActionResult(ca_event, NULL);
strcpy( ca_event->ErrStr, "Invalid Action" ); UpnpActionRequest_strcpy_ErrStr(ca_event, "Invalid Action" );
ca_event->ErrCode = 401; UpnpActionRequest_set_ErrCode(ca_event, 401);
} else { } else {
if( retCode == UPNP_E_SUCCESS ) { if( retCode == UPNP_E_SUCCESS ) {
ca_event->ErrCode = UPNP_E_SUCCESS; UpnpActionRequest_set_ErrCode(ca_event, UPNP_E_SUCCESS);
} else { } else {
//copy the error string // copy the error string
strcpy( ca_event->ErrStr, errorString ); UpnpActionRequest_strcpy_ErrStr(ca_event, errorString );
switch ( retCode ) { switch ( retCode ) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
{ {
ca_event->ErrCode = 402; UpnpActionRequest_set_ErrCode(ca_event, 402);
break; break;
} }
case UPNP_E_INTERNAL_ERROR: case UPNP_E_INTERNAL_ERROR:
default: default:
{ {
ca_event->ErrCode = 501; UpnpActionRequest_set_ErrCode(ca_event, 501);
break; break;
} }
@ -586,7 +571,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
} }
} }
return ( ca_event->ErrCode ); return UpnpActionRequest_get_ErrCode(ca_event);
} }
/****************************************************************************** /******************************************************************************
@ -649,7 +634,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return ( 1 );
} }
/****************************************************************************** /******************************************************************************
@ -672,7 +656,7 @@ TvDeviceSetPower( IN int on )
if( on != POWER_ON && on != POWER_OFF ) { if( on != POWER_ON && on != POWER_OFF ) {
SampleUtil_Print( "error: can't set power to value %d\n", on ); SampleUtil_Print( "error: can't set power to value %d\n", on );
return ( 0 ); return 0;
} }
/* /*
@ -683,7 +667,7 @@ TvDeviceSetPower( IN int on )
ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER, ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
value ); value );
return ( ret ); return ret;
} }
/****************************************************************************** /******************************************************************************
@ -700,9 +684,7 @@ TvDeviceSetPower( IN int on )
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOn( IN IXML_Document * in, TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = NULL; ( *errorString ) = NULL;
@ -722,7 +704,6 @@ TvDevicePowerOn( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -740,7 +721,7 @@ TvDevicePowerOn( IN IXML_Document * in,
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOff( IN IXML_Document * in, TvDevicePowerOff( IN IXML_Document * in,
OUT IXML_Document ** out, OUT IXML_Document **out,
OUT char **errorString ) OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
@ -779,11 +760,8 @@ TvDevicePowerOff( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetChannel( IN IXML_Document * in, TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int channel = 0; int channel = 0;
@ -828,7 +806,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -846,13 +823,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementChannel( IN int incr, IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curchannel, int curchannel;
newchannel; int newchannel;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -914,12 +888,9 @@ IncrementChannel( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseChannel( IN IXML_Document * in, TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( -1, in, out, errorString ); return IncrementChannel( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -936,12 +907,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseChannel( IN IXML_Document * in, TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( 1, in, out, errorString ); return IncrementChannel( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -960,13 +928,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetVolume( IN IXML_Document * in, TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int volume = 0; int volume = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1007,7 +971,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1026,10 +989,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
IncrementVolume( IN int incr, IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curvolume, int curvolume,
newvolume; newvolume;
@ -1066,8 +1026,7 @@ IncrementVolume( IN int incr,
TV_CONTROL_VOLUME, value ) ) { TV_CONTROL_VOLUME, value ) ) {
if( UpnpAddToActionResponse( out, actionName, if( UpnpAddToActionResponse( out, actionName,
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
"Volume", value ) != UPNP_E_SUCCESS ) "Volume", value ) != UPNP_E_SUCCESS ) {
{
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
@ -1077,7 +1036,6 @@ IncrementVolume( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1094,13 +1052,9 @@ IncrementVolume( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseVolume( IN IXML_Document * in, TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( 1, in, out, errorString ); return IncrementVolume( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1117,13 +1071,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseVolume( IN IXML_Document * in, TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( -1, in, out, errorString ); return IncrementVolume( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1142,13 +1092,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetColor( IN IXML_Document * in, TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int color = 0; int color = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1188,7 +1134,6 @@ TvDeviceSetColor( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1205,16 +1150,11 @@ TvDeviceSetColor( IN IXML_Document * in,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementColor( IN int incr, IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcolor, int curcolor;
newcolor; int newcolor;
char *actionName; char *actionName;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1272,11 +1212,8 @@ IncrementColor( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseColor( IN IXML_Document * in, TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( -1, in, out, errorString ); return IncrementColor( -1, in, out, errorString );
} }
@ -1293,11 +1230,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseColor( IN IXML_Document * in, TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( 1, in, out, errorString ); return IncrementColor( 1, in, out, errorString );
} }
@ -1317,13 +1251,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetTint( IN IXML_Document * in, TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int tint = -1; int tint = -1;
( *out ) = NULL; ( *out ) = NULL;
@ -1382,14 +1312,10 @@ TvDeviceSetTint( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementTint( IN int incr, IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curtint, int curtint;
newtint; int newtint;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1432,7 +1358,6 @@ IncrementTint( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1449,11 +1374,8 @@ IncrementTint( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseTint( IN IXML_Document * in, TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( 1, in, out, errorString ); return IncrementTint( 1, in, out, errorString );
} }
@ -1471,11 +1393,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseTint( IN IXML_Document * in, TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( -1, in, out, errorString ); return IncrementTint( -1, in, out, errorString );
} }
@ -1495,11 +1414,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
* *
****************************************************************************/ ****************************************************************************/
int int
TvDeviceSetContrast( IN IXML_Document * in, TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int contrast = -1; int contrast = -1;
@ -1560,14 +1476,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementContrast( IN int incr, IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcontrast, int curcontrast;
newcontrast; int newcontrast;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1629,11 +1541,8 @@ IncrementContrast( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseContrast( IN IXML_Document * in, TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementContrast( 1, in, out, errorString ); return IncrementContrast( 1, in, out, errorString );
} }
@ -1651,9 +1560,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseContrast( IXML_Document * in, TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IXML_Document ** out,
char **errorString )
{ {
return IncrementContrast( -1, in, out, errorString ); return IncrementContrast( -1, in, out, errorString );
} }
@ -1671,11 +1578,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetBrightness( IN IXML_Document * in, TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int brightness = -1; int brightness = -1;
@ -1718,7 +1622,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1736,13 +1639,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementBrightness( IN int incr, IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curbrightness, int curbrightness;
newbrightness; int newbrightness;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1803,9 +1703,7 @@ IncrementBrightness( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseBrightness( IN IXML_Document * in, TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( 1, in, out, errorString ); return IncrementBrightness( 1, in, out, errorString );
} }
@ -1823,9 +1721,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseBrightness( IN IXML_Document * in, TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( -1, in, out, errorString ); return IncrementBrightness( -1, in, out, errorString );
} }
@ -1850,28 +1746,19 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceCallbackEventHandler( Upnp_EventType EventType, TvDeviceCallbackEventHandler( Upnp_EventType EventType, void *Event, void *Cookie )
void *Event,
void *Cookie )
{ {
switch ( EventType ) { switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest( (struct Upnp_Subscription_Request *)Event );
TvDeviceHandleSubscriptionRequest( ( struct
Upnp_Subscription_Request
* )Event );
break; break;
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:
TvDeviceHandleGetVarRequest( ( struct Upnp_State_Var_Request TvDeviceHandleGetVarRequest( (UpnpStateVarRequest *)Event );
* )Event );
break; break;
case UPNP_CONTROL_ACTION_REQUEST: case UPNP_CONTROL_ACTION_REQUEST:
TvDeviceHandleActionRequest( ( struct Upnp_Action_Request * ) TvDeviceHandleActionRequest( (UpnpActionRequest *)Event );
Event );
break; break;
/* /*
@ -1890,17 +1777,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
break; break;
default: default:
SampleUtil_Print SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n", EventType );
EventType );
} }
/* /* Print a summary of the event received */
Print a summary of the event received
*/
SampleUtil_PrintEvent( EventType, Event ); SampleUtil_PrintEvent( EventType, Event );
return ( 0 ); return 0;
} }
/****************************************************************************** /******************************************************************************
@ -1919,6 +1803,7 @@ TvDeviceStop()
UpnpFinish(); UpnpFinish();
SampleUtil_Finish(); SampleUtil_Finish();
ithread_mutex_destroy( &TVDevMutex ); ithread_mutex_destroy( &TVDevMutex );
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
@ -1951,7 +1836,6 @@ TvDeviceStart( char *ip_address,
print_string pfun ) print_string pfun )
{ {
int ret = UPNP_E_SUCCESS; int ret = UPNP_E_SUCCESS;
char desc_doc_url[DESC_URL_SIZE]; char desc_doc_url[DESC_URL_SIZE];
ithread_mutex_init( &TVDevMutex, NULL ); ithread_mutex_init( &TVDevMutex, NULL );
@ -1963,19 +1847,15 @@ TvDeviceStart( char *ip_address,
"\tipaddress = %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address, port ); ip_address, port );
if( ( ret = UpnpInit( ip_address, port ) ) != UPNP_E_SUCCESS ) { ret = UpnpInit( ip_address, port );
if( ret != UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error with UpnpInit -- %d\n", ret ); SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
if( ip_address == NULL ) { ip_address = UpnpGetServerIpAddress();
ip_address = UpnpGetServerIpAddress(); port = UpnpGetServerPort();
}
if( port == 0 ) {
port = UpnpGetServerPort();
}
SampleUtil_Print( SampleUtil_Print(
"UPnP Initialized\n" "UPnP Initialized\n"
@ -1995,12 +1875,12 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print( "Specifying the webserver root directory -- %s\n", SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
web_dir_path ); web_dir_path );
if( ( ret = ret = UpnpSetWebServerRootDir( web_dir_path );
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) { if( ret != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
( "Error specifying webserver root directory -- %s: %d\n",
web_dir_path, ret ); web_dir_path, ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
@ -2009,12 +1889,12 @@ TvDeviceStart( char *ip_address,
"\t with desc_doc_url: %s\n", "\t with desc_doc_url: %s\n",
desc_doc_url ); desc_doc_url );
if( ( ret = UpnpRegisterRootDevice( desc_doc_url, ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
TvDeviceCallbackEventHandler, &device_handle, &device_handle );
&device_handle, &device_handle ) ) if( ret != UPNP_E_SUCCESS ) {
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret ); SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} else { } else {
SampleUtil_Print( SampleUtil_Print(
@ -2022,17 +1902,17 @@ TvDeviceStart( char *ip_address,
"Initializing State Table\n"); "Initializing State Table\n");
TvDeviceStateTableInit( desc_doc_url ); TvDeviceStateTableInit( desc_doc_url );
SampleUtil_Print("State Table Initialized\n"); SampleUtil_Print("State Table Initialized\n");
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
if( ( ret = if( ret != UPNP_E_SUCCESS ) {
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error sending advertisements : %d\n", ret ); SampleUtil_Print( "Error sending advertisements : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
SampleUtil_Print("Advertisements Sent\n"); SampleUtil_Print("Advertisements Sent\n");
} }
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }

View File

@ -148,8 +148,7 @@ extern char *TvServiceType[];
* *
*****************************************************************************/ *****************************************************************************/
typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out, typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out, char **errorString);
char **errorString);
/* Structure for storing Tv Service /* Structure for storing Tv Service
identifiers and state table */ identifiers and state table */
@ -193,7 +192,7 @@ extern ithread_mutex_t TVDevMutex;
* struct TvService *out - service containing action table to set. * struct TvService *out - service containing action table to set.
* *
*****************************************************************************/ *****************************************************************************/
int SetActionTable(int serviceType, struct TvService * out); int SetActionTable(int serviceType, struct TvService *out);
/****************************************************************************** /******************************************************************************
* TvDeviceStateTableInit * TvDeviceStateTableInit
@ -241,7 +240,7 @@ int TvDeviceHandleSubscriptionRequest(struct Upnp_Subscription_Request *);
* cgv_event -- The control get variable request event structure * cgv_event -- The control get variable request event structure
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceHandleGetVarRequest(struct Upnp_State_Var_Request *); int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *);
/****************************************************************************** /******************************************************************************
* TvDeviceHandleActionRequest * TvDeviceHandleActionRequest
@ -255,7 +254,7 @@ int TvDeviceHandleGetVarRequest(struct Upnp_State_Var_Request *);
* ca_event -- The control action request event structure * ca_event -- The control action request event structure
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceHandleActionRequest(struct Upnp_Action_Request *); int TvDeviceHandleActionRequest(UpnpActionRequest *);
/****************************************************************************** /******************************************************************************
* TvDeviceCallbackEventHandler * TvDeviceCallbackEventHandler
@ -313,8 +312,7 @@ int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*);
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out, int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDevicePowerOff * TvDevicePowerOff
@ -329,8 +327,7 @@ int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out, int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetChannel * TvDeviceSetChannel
@ -347,8 +344,7 @@ int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseChannel * TvDeviceIncreaseChannel
@ -363,8 +359,7 @@ int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseChannel * TvDeviceDecreaseChannel
* *
@ -378,8 +373,7 @@ int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetVolume * TvDeviceSetVolume
* *
@ -395,8 +389,7 @@ int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseVolume * TvDeviceIncreaseVolume
@ -411,8 +404,7 @@ int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document**out, int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
@ -428,8 +420,7 @@ int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document**out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document**out, int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
//Picture Service Actions //Picture Service Actions
@ -449,8 +440,7 @@ int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document**out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
@ -465,8 +455,7 @@ int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out, int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseColor * TvDeviceDecreaseColor
@ -480,8 +469,7 @@ int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out, int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetTint * TvDeviceSetTint
@ -498,8 +486,7 @@ int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseTint * TvDeviceIncreaseTint
@ -514,8 +501,7 @@ int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseTint * TvDeviceDecreaseTint
@ -530,8 +516,7 @@ int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/***************************************************************************** /*****************************************************************************
* TvDeviceSetContrast * TvDeviceSetContrast
@ -548,8 +533,7 @@ int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
****************************************************************************/ ****************************************************************************/
int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseContrast * TvDeviceIncreaseContrast
@ -565,8 +549,7 @@ int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseContrast * TvDeviceDecreaseContrast
* *
@ -580,8 +563,7 @@ int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetBrightness * TvDeviceSetBrightness
@ -595,8 +577,7 @@ int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
* brightness -- The brightness value to change to. * brightness -- The brightness value to change to.
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseBrightness * TvDeviceIncreaseBrightness
@ -611,8 +592,7 @@ int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseBrightness * TvDeviceDecreaseBrightness
@ -626,8 +606,7 @@ int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name, int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name,
char *web_dir_path, print_string pfun); char *web_dir_path, print_string pfun);

View File

@ -139,10 +139,10 @@ TvCtrlPointDeleteNode( struct TvDeviceNode *node )
* *
********************************************************************************/ ********************************************************************************/
int int
TvCtrlPointRemoveDevice( char *UDN ) TvCtrlPointRemoveDevice(const char *UDN)
{ {
struct TvDeviceNode *curdevnode, struct TvDeviceNode *curdevnode;
*prevdevnode; struct TvDeviceNode *prevdevnode;
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
@ -668,8 +668,8 @@ TvCtrlPointPrintDevice( int devnum )
* *
********************************************************************************/ ********************************************************************************/
void void
TvCtrlPointAddDevice( IXML_Document * DescDoc, TvCtrlPointAddDevice( IXML_Document *DescDoc,
char *location, const char *location,
int expires ) int expires )
{ {
char *deviceType = NULL; char *deviceType = NULL;
@ -682,20 +682,19 @@ TvCtrlPointAddDevice( IXML_Document * DescDoc,
char *eventURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL }; char *eventURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL };
char *controlURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL }; char *controlURL[TV_SERVICE_SERVCOUNT] = { NULL, NULL };
Upnp_SID eventSID[TV_SERVICE_SERVCOUNT]; Upnp_SID eventSID[TV_SERVICE_SERVCOUNT];
int TimeOut[TV_SERVICE_SERVCOUNT] = int TimeOut[TV_SERVICE_SERVCOUNT] = {
{ default_timeout, default_timeout }; default_timeout,
default_timeout };
struct TvDeviceNode *deviceNode; struct TvDeviceNode *deviceNode;
struct TvDeviceNode *tmpdevnode; struct TvDeviceNode *tmpdevnode;
int ret = 1; int ret = 1;
int found = 0; int found = 0;
int service, int service;
var; int var;
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
/* /* Read key elements from description document */
Read key elements from description document
*/
UDN = SampleUtil_GetFirstDocumentItem( DescDoc, "UDN" ); UDN = SampleUtil_GetFirstDocumentItem( DescDoc, "UDN" );
deviceType = SampleUtil_GetFirstDocumentItem( DescDoc, "deviceType" ); deviceType = SampleUtil_GetFirstDocumentItem( DescDoc, "deviceType" );
friendlyName = friendlyName =
@ -703,9 +702,8 @@ TvCtrlPointAddDevice( IXML_Document * DescDoc,
baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" ); baseURL = SampleUtil_GetFirstDocumentItem( DescDoc, "URLBase" );
relURL = SampleUtil_GetFirstDocumentItem( DescDoc, "presentationURL" ); relURL = SampleUtil_GetFirstDocumentItem( DescDoc, "presentationURL" );
ret = ret = UpnpResolveURL(
UpnpResolveURL( ( baseURL ? baseURL : location ), relURL, ( baseURL ? baseURL : location ), relURL, presURL);
presURL );
if( UPNP_E_SUCCESS != ret ) if( UPNP_E_SUCCESS != ret )
SampleUtil_Print( "Error generating presURL from %s + %s", baseURL, SampleUtil_Print( "Error generating presURL from %s + %s", baseURL,
@ -983,10 +981,10 @@ TvCtrlPointHandleEvent( Upnp_SID sid,
* timeout -- The new timeout for the subscription * timeout -- The new timeout for the subscription
* *
********************************************************************************/ ********************************************************************************/
void void TvCtrlPointHandleSubscribeUpdate(
TvCtrlPointHandleSubscribeUpdate( char *eventURL, const char *eventURL,
Upnp_SID sid, const Upnp_SID sid,
int timeout ) int timeout)
{ {
struct TvDeviceNode *tmpdevnode; struct TvDeviceNode *tmpdevnode;
int service; int service;
@ -1015,9 +1013,9 @@ TvCtrlPointHandleSubscribeUpdate( char *eventURL,
} }
void void
TvCtrlPointHandleGetVar( char *controlURL, TvCtrlPointHandleGetVar( const char *controlURL,
char *varName, const char *varName,
DOMString varValue ) const DOMString varValue )
{ {
struct TvDeviceNode *tmpdevnode; struct TvDeviceNode *tmpdevnode;
@ -1026,14 +1024,11 @@ TvCtrlPointHandleGetVar( char *controlURL,
ithread_mutex_lock( &DeviceListMutex ); ithread_mutex_lock( &DeviceListMutex );
tmpdevnode = GlobalDeviceList; tmpdevnode = GlobalDeviceList;
while( tmpdevnode ) { while (tmpdevnode) {
for( service = 0; service < TV_SERVICE_SERVCOUNT; service++ ) { for (service = 0; service < TV_SERVICE_SERVCOUNT; service++) {
if( strcmp if (strcmp(tmpdevnode->device.TvService[service].ControlURL, controlURL ) == 0 ) {
( tmpdevnode->device.TvService[service].ControlURL, SampleUtil_StateUpdate(
controlURL ) == 0 ) { varName, varValue, tmpdevnode->device.UDN, GET_VAR_COMPLETE );
SampleUtil_StateUpdate( varName, varValue,
tmpdevnode->device.UDN,
GET_VAR_COMPLETE );
break; break;
} }
} }
@ -1057,186 +1052,159 @@ TvCtrlPointHandleGetVar( char *controlURL,
* Cookie -- Optional data specified during callback registration * Cookie -- Optional data specified during callback registration
* *
********************************************************************************/ ********************************************************************************/
int int TvCtrlPointCallbackEventHandler(Upnp_EventType EventType, void *Event, void *Cookie)
TvCtrlPointCallbackEventHandler( Upnp_EventType EventType,
void *Event,
void *Cookie )
{ {
SampleUtil_PrintEvent( EventType, Event ); int errCode = 0;
switch ( EventType ) { SampleUtil_PrintEvent(EventType, Event);
/* switch ( EventType ) {
SSDP Stuff /* SSDP Stuff */
*/ case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE:
case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_SEARCH_RESULT: {
case UPNP_DISCOVERY_SEARCH_RESULT: UpnpDiscovery *d_event = (UpnpDiscovery *)Event;
{ IXML_Document *DescDoc = NULL;
struct Upnp_Discovery *d_event = const char *location = NULL;
( struct Upnp_Discovery * )Event; int errCode = UpnpDiscovery_get_ErrCode(d_event);
IXML_Document *DescDoc = NULL; if (errCode != UPNP_E_SUCCESS) {
int ret; SampleUtil_Print(
"Error in Discovery Callback -- %d", errCode);
}
if( d_event->ErrCode != UPNP_E_SUCCESS ) { location = UpnpString_get_String(
SampleUtil_Print( "Error in Discovery Callback -- %d", UpnpDiscovery_get_Location(d_event));
d_event->ErrCode ); errCode = UpnpDownloadXmlDoc(location, &DescDoc);
} if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error obtaining device description from %s -- error = %d",
location, errCode);
} else {
TvCtrlPointAddDevice(
DescDoc, location, UpnpDiscovery_get_Expires(d_event));
}
if( ( ret = if( DescDoc ) {
UpnpDownloadXmlDoc( d_event->Location, ixmlDocument_free(DescDoc);
&DescDoc ) ) != }
UPNP_E_SUCCESS ) {
SampleUtil_Print
( "Error obtaining device description from %s -- error = %d",
d_event->Location, ret );
} else {
TvCtrlPointAddDevice( DescDoc, d_event->Location,
d_event->Expires );
}
if( DescDoc ) TvCtrlPointPrintList();
ixmlDocument_free( DescDoc ); break;
}
TvCtrlPointPrintList(); case UPNP_DISCOVERY_SEARCH_TIMEOUT:
break; /* Nothing to do here... */
} break;
case UPNP_DISCOVERY_SEARCH_TIMEOUT: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: {
/* UpnpDiscovery *d_event = (UpnpDiscovery *)Event;
Nothing to do here... int errCode = UpnpDiscovery_get_ErrCode(d_event);
*/ const char *deviceId = UpnpString_get_String(
break; UpnpDiscovery_get_DeviceID(d_event));
case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: if (errCode != UPNP_E_SUCCESS) {
{ SampleUtil_Print(
struct Upnp_Discovery *d_event = "Error in Discovery ByeBye Callback -- %d", errCode);
( struct Upnp_Discovery * )Event; }
if( d_event->ErrCode != UPNP_E_SUCCESS ) { SampleUtil_Print("Received ByeBye for Device: %s", deviceId);
SampleUtil_Print TvCtrlPointRemoveDevice(deviceId);
( "Error in Discovery ByeBye Callback -- %d",
d_event->ErrCode );
}
SampleUtil_Print( "Received ByeBye for Device: %s", SampleUtil_Print("After byebye:");
d_event->DeviceId ); TvCtrlPointPrintList();
TvCtrlPointRemoveDevice( d_event->DeviceId );
SampleUtil_Print( "After byebye:" ); break;
TvCtrlPointPrintList(); }
break; /* SOAP Stuff */
} case UPNP_CONTROL_ACTION_COMPLETE: {
UpnpActionComplete *a_event = (UpnpActionComplete *)Event;
int errCode = UpnpActionComplete_get_ErrCode(a_event);
if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error in Action Complete Callback -- %d",
errCode);
}
/* /* No need for any processing here, just print out results.
SOAP Stuff * Service state table updates are handled by events. */
*/
case UPNP_CONTROL_ACTION_COMPLETE:
{
struct Upnp_Action_Complete *a_event =
( struct Upnp_Action_Complete * )Event;
if( a_event->ErrCode != UPNP_E_SUCCESS ) { break;
SampleUtil_Print }
( "Error in Action Complete Callback -- %d",
a_event->ErrCode );
}
/* case UPNP_CONTROL_GET_VAR_COMPLETE: {
No need for any processing here, just print out results. Service state UpnpStateVarComplete *sv_event = (UpnpStateVarComplete *)Event;
table updates are handled by events. int errCode = UpnpStateVarComplete_get_ErrCode(sv_event);
*/ if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error in Get Var Complete Callback -- %d",
errCode );
} else {
TvCtrlPointHandleGetVar(
UpnpString_get_String(UpnpStateVarComplete_get_CtrlUrl(sv_event)),
UpnpString_get_String(UpnpStateVarComplete_get_StateVarName(sv_event)),
UpnpStateVarComplete_get_CurrentVal(sv_event) );
}
break;
}
break; /* GENA Stuff */
} case UPNP_EVENT_RECEIVED: {
struct Upnp_Event *e_event = ( struct Upnp_Event * )Event;
TvCtrlPointHandleEvent( e_event->Sid, e_event->EventKey,
e_event->ChangedVariables );
break;
}
case UPNP_CONTROL_GET_VAR_COMPLETE: case UPNP_EVENT_SUBSCRIBE_COMPLETE:
{ case UPNP_EVENT_UNSUBSCRIBE_COMPLETE:
struct Upnp_State_Var_Complete *sv_event = case UPNP_EVENT_RENEWAL_COMPLETE: {
( struct Upnp_State_Var_Complete * )Event; EventSubscribe *es_event = (EventSubscribe *)Event;
errCode = UpnpEventSubscribe_get_ErrCode(es_event);
if (errCode != UPNP_E_SUCCESS) {
SampleUtil_Print(
"Error in Event Subscribe Callback -- %d",
errCode);
} else {
TvCtrlPointHandleSubscribeUpdate(
UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
UpnpString_get_String(UpnpEventSubscribe_get_SID(es_event)),
UpnpEventSubscribe_get_TimeOut(es_event));
}
if( sv_event->ErrCode != UPNP_E_SUCCESS ) { break;
SampleUtil_Print }
( "Error in Get Var Complete Callback -- %d",
sv_event->ErrCode );
} else {
TvCtrlPointHandleGetVar( sv_event->CtrlUrl,
sv_event->StateVarName,
sv_event->CurrentVal );
}
break; case UPNP_EVENT_AUTORENEWAL_FAILED:
} case UPNP_EVENT_SUBSCRIPTION_EXPIRED: {
EventSubscribe *es_event = (EventSubscribe *)Event;
int TimeOut = default_timeout;
Upnp_SID newSID;
/* errCode = UpnpSubscribe(
GENA Stuff ctrlpt_handle,
*/ UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
case UPNP_EVENT_RECEIVED: &TimeOut,
{ newSID);
struct Upnp_Event *e_event = ( struct Upnp_Event * )Event;
TvCtrlPointHandleEvent( e_event->Sid, e_event->EventKey, if (errCode == UPNP_E_SUCCESS) {
e_event->ChangedVariables ); SampleUtil_Print("Subscribed to EventURL with SID=%s", newSID);
break; TvCtrlPointHandleSubscribeUpdate(
} UpnpString_get_String(UpnpEventSubscribe_get_PublisherUrl(es_event)),
newSID,
TimeOut);
} else {
SampleUtil_Print("Error Subscribing to EventURL -- %d", errCode);
}
break;
}
case UPNP_EVENT_SUBSCRIBE_COMPLETE: /* ignore these cases, since this is not a device */
case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
case UPNP_EVENT_RENEWAL_COMPLETE: case UPNP_CONTROL_GET_VAR_REQUEST:
{ case UPNP_CONTROL_ACTION_REQUEST:
struct Upnp_Event_Subscribe *es_event = break;
( struct Upnp_Event_Subscribe * )Event; }
if( es_event->ErrCode != UPNP_E_SUCCESS ) { return 0;
SampleUtil_Print
( "Error in Event Subscribe Callback -- %d",
es_event->ErrCode );
} else {
TvCtrlPointHandleSubscribeUpdate( es_event->
PublisherUrl,
es_event->Sid,
es_event->TimeOut );
}
break;
}
case UPNP_EVENT_AUTORENEWAL_FAILED:
case UPNP_EVENT_SUBSCRIPTION_EXPIRED:
{
int TimeOut = default_timeout;
Upnp_SID newSID;
int ret;
struct Upnp_Event_Subscribe *es_event =
( struct Upnp_Event_Subscribe * )Event;
ret =
UpnpSubscribe( ctrlpt_handle, es_event->PublisherUrl,
&TimeOut, newSID );
if( ret == UPNP_E_SUCCESS ) {
SampleUtil_Print( "Subscribed to EventURL with SID=%s",
newSID );
TvCtrlPointHandleSubscribeUpdate( es_event->
PublisherUrl, newSID,
TimeOut );
} else {
SampleUtil_Print
( "Error Subscribing to EventURL -- %d", ret );
}
break;
}
/*
ignore these cases, since this is not a device
*/
case UPNP_EVENT_SUBSCRIPTION_REQUEST:
case UPNP_CONTROL_GET_VAR_REQUEST:
case UPNP_CONTROL_ACTION_REQUEST:
break;
}
return 0;
} }
/******************************************************************************** /********************************************************************************
@ -1374,12 +1342,8 @@ TvCtrlPointStart( print_string printFunctionPtr,
return TV_ERROR; return TV_ERROR;
} }
if( NULL == ip_address ) { ip_address = UpnpGetServerIpAddress();
ip_address = UpnpGetServerIpAddress(); port = UpnpGetServerPort();
}
if( 0 == port ) {
port = UpnpGetServerPort();
}
SampleUtil_Print( SampleUtil_Print(
"UPnP Initialized\n" "UPnP Initialized\n"
@ -1406,7 +1370,7 @@ TvCtrlPointStart( print_string printFunctionPtr,
} }
int int
TvCtrlPointStop( void ) TvCtrlPointStop()
{ {
TvCtrlPointRemoveAll(); TvCtrlPointRemoveAll();
UpnpUnRegisterClient( ctrlpt_handle ); UpnpUnRegisterClient( ctrlpt_handle );

View File

@ -110,11 +110,11 @@ extern ithread_mutex_t DeviceListMutex;
extern UpnpClient_Handle ctrlpt_handle; extern UpnpClient_Handle ctrlpt_handle;
void TvCtrlPointPrintHelp( void ); void TvCtrlPointPrintHelp();
int TvCtrlPointDeleteNode(struct TvDeviceNode*); int TvCtrlPointDeleteNode(struct TvDeviceNode*);
int TvCtrlPointRemoveDevice(char*); int TvCtrlPointRemoveDevice(const char *);
int TvCtrlPointRemoveAll( void ); int TvCtrlPointRemoveAll();
int TvCtrlPointRefresh( void ); int TvCtrlPointRefresh();
int TvCtrlPointSendAction(int, int, char *, char **, char **, int); int TvCtrlPointSendAction(int, int, char *, char **, char **, int);
@ -140,11 +140,11 @@ int TvCtrlPointGetBrightness(int);
int TvCtrlPointGetDevice(int, struct TvDeviceNode **); int TvCtrlPointGetDevice(int, struct TvDeviceNode **);
int TvCtrlPointPrintList( void ); int TvCtrlPointPrintList( void );
int TvCtrlPointPrintDevice(int); int TvCtrlPointPrintDevice(int);
void TvCtrlPointAddDevice (IXML_Document *, char *, int); void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
void TvCtrlPointHandleGetVar(char *,char *,DOMString); void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
void TvStateUpdate(char*,int, IXML_Document * , char **); void TvStateUpdate(char*,int, IXML_Document * , char **);
void TvCtrlPointHandleEvent(Upnp_SID, int, IXML_Document *); void TvCtrlPointHandleEvent(Upnp_SID, int, IXML_Document *);
void TvCtrlPointHandleSubscribeUpdate(char *, Upnp_SID, int); void TvCtrlPointHandleSubscribeUpdate(const char *, const Upnp_SID, int);
int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *); int TvCtrlPointCallbackEventHandler(Upnp_EventType, void *, void *);
void TvCtrlPointVerifyTimeouts(int); void TvCtrlPointVerifyTimeouts(int);
void TvCtrlPointPrintCommands( void ); void TvCtrlPointPrintCommands( void );

View File

@ -180,7 +180,6 @@ SetServiceTable( IN int serviceType,
} }
return SetActionTable( serviceType, out ); return SetActionTable( serviceType, out );
} }
/****************************************************************************** /******************************************************************************
@ -251,7 +250,6 @@ SetActionTable( IN int serviceType,
} }
return 0; return 0;
} }
/****************************************************************************** /******************************************************************************
@ -436,31 +434,32 @@ TvDeviceHandleSubscriptionRequest( IN struct Upnp_Subscription_Request
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request TvDeviceHandleGetVarRequest( INOUT UpnpStateVarRequest *cgv_event )
*cgv_event )
{ {
unsigned int i = 0, unsigned int i = 0;
j = 0; unsigned int j = 0;
int getvar_succeeded = 0; int getvar_succeeded = 0;
cgv_event->CurrentVal = NULL; UpnpStateVarRequest_set_CurrentVal(cgv_event, NULL);
ithread_mutex_lock( &TVDevMutex ); ithread_mutex_lock( &TVDevMutex );
for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) { for( i = 0; i < TV_SERVICE_SERVCOUNT; i++ ) {
//check udn and service id // check udn and service id
if( ( strcmp( cgv_event->DevUDN, tv_service_table[i].UDN ) == 0 ) const char *devUDN =
&& UpnpString_get_String(UpnpStateVarRequest_get_DevUDN(cgv_event));
( strcmp( cgv_event->ServiceID, tv_service_table[i].ServiceId ) const char *serviceID =
== 0 ) ) { UpnpString_get_String(UpnpStateVarRequest_get_ServiceID(cgv_event));
//check variable name if( ( strcmp( devUDN, tv_service_table[i].UDN ) == 0 ) &&
( strcmp( serviceID, tv_service_table[i].ServiceId ) == 0 ) ) {
// check variable name
for( j = 0; j < tv_service_table[i].VariableCount; j++ ) { for( j = 0; j < tv_service_table[i].VariableCount; j++ ) {
if( strcmp( cgv_event->StateVarName, const char *stateVarName =
tv_service_table[i].VariableName[j] ) == 0 ) { UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event));
if( strcmp( stateVarName, tv_service_table[i].VariableName[j] ) == 0 ) {
getvar_succeeded = 1; getvar_succeeded = 1;
cgv_event->CurrentVal = UpnpStateVarRequest_set_CurrentVal(cgv_event,
ixmlCloneDOMString( tv_service_table[i]. tv_service_table[i].VariableStrVal[j] );
VariableStrVal[j] );
break; break;
} }
} }
@ -468,19 +467,19 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
} }
if( getvar_succeeded ) { if( getvar_succeeded ) {
cgv_event->ErrCode = UPNP_E_SUCCESS; UpnpStateVarRequest_set_ErrCode(cgv_event, UPNP_E_SUCCESS);
} else { } else {
SampleUtil_Print SampleUtil_Print(
( "Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n" ); "Error in UPNP_CONTROL_GET_VAR_REQUEST callback:\n"
SampleUtil_Print( " Unknown variable name = %s\n", " Unknown variable name = %s\n",
cgv_event->StateVarName ); UpnpString_get_String(UpnpStateVarRequest_get_StateVarName(cgv_event)) );
cgv_event->ErrCode = 404; UpnpStateVarRequest_set_ErrCode(cgv_event, 404);
strcpy( cgv_event->ErrStr, "Invalid Variable" ); UpnpStateVarRequest_strcpy_ErrStr(cgv_event, "Invalid Variable" );
} }
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( cgv_event->ErrCode == UPNP_E_SUCCESS ); return UpnpStateVarRequest_get_ErrCode(cgv_event) == UPNP_E_SUCCESS;
} }
/****************************************************************************** /******************************************************************************
@ -496,9 +495,8 @@ TvDeviceHandleGetVarRequest( INOUT struct Upnp_State_Var_Request
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event ) TvDeviceHandleActionRequest( INOUT UpnpActionRequest *ca_event )
{ {
/* /*
Defaults if action not found Defaults if action not found
*/ */
@ -507,51 +505,38 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
int service = -1; int service = -1;
int retCode = 0; int retCode = 0;
char *errorString = NULL; char *errorString = NULL;
const char *devUDN = NULL;
const char *serviceID = NULL;
const char *actionName = NULL;
IXML_Document *actionResult = NULL;
ca_event->ErrCode = 0; UpnpActionRequest_set_ErrCode(ca_event, 0);
ca_event->ActionResult = NULL; UpnpActionRequest_set_ActionResult(ca_event, NULL);
if( ( strcmp( ca_event->DevUDN, devUDN = UpnpString_get_String(UpnpActionRequest_get_DevUDN( ca_event));
tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) && serviceID = UpnpString_get_String(UpnpActionRequest_get_ServiceID( ca_event));
( strcmp actionName = UpnpString_get_String(UpnpActionRequest_get_ActionName(ca_event));
( ca_event->ServiceID, if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_CONTROL].UDN ) == 0 ) &&
tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) { ( strcmp( serviceID, tv_service_table[TV_SERVICE_CONTROL].ServiceId ) == 0 ) ) {
/* /* Request for action in the TvDevice Control Service */
Request for action in the TvDevice Control Service
*/
service = TV_SERVICE_CONTROL; service = TV_SERVICE_CONTROL;
} else if( ( strcmp( ca_event->DevUDN, } else if( ( strcmp( devUDN, tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) &&
tv_service_table[TV_SERVICE_PICTURE].UDN ) == 0 ) ( strcmp( serviceID, tv_service_table[TV_SERVICE_PICTURE].ServiceId ) == 0 ) ) {
&& /* Request for action in the TvDevice Picture Service */
( strcmp
( ca_event->ServiceID,
tv_service_table[TV_SERVICE_PICTURE].ServiceId ) ==
0 ) ) {
/*
Request for action in the TvDevice Picture Service
*/
service = TV_SERVICE_PICTURE; service = TV_SERVICE_PICTURE;
} }
//Find and call appropriate procedure based on action name /* Find and call appropriate procedure based on action name
//Each action name has an associated procedure stored in the * Each action name has an associated procedure stored in the
//service table. These are set at initialization. * service table. These are set at initialization. */
for( i = 0; i < TV_MAXACTIONS && tv_service_table[service].ActionNames[i] != NULL; i++ ) {
for( i = 0; ( ( i < TV_MAXACTIONS ) && if( !strcmp( actionName, tv_service_table[service].ActionNames[i] ) ) {
( tv_service_table[service].ActionNames[i] != NULL ) ); if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL].VariableStrVal[TV_CONTROL_POWER], "1" ) ) ||
i++ ) { ( !strcmp( actionName, "PowerOn" ) ) ) {
retCode = tv_service_table[service].actions[i](
if( !strcmp( ca_event->ActionName, UpnpActionRequest_get_ActionRequest(ca_event),
tv_service_table[service].ActionNames[i] ) ) { &actionResult,
&errorString );
if( ( !strcmp( tv_service_table[TV_SERVICE_CONTROL]. UpnpActionRequest_set_ActionResult(ca_event, actionResult);
VariableStrVal[TV_CONTROL_POWER], "1" ) )
|| ( !strcmp( ca_event->ActionName, "PowerOn" ) ) ) {
retCode =
tv_service_table[service].actions[i] ( ca_event->
ActionRequest,
&ca_event->
ActionResult,
&errorString );
} else { } else {
errorString = "Power is Off"; errorString = "Power is Off";
retCode = UPNP_E_INTERNAL_ERROR; retCode = UPNP_E_INTERNAL_ERROR;
@ -562,25 +547,25 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
} }
if( !action_found ) { if( !action_found ) {
ca_event->ActionResult = NULL; UpnpActionRequest_set_ActionResult(ca_event, NULL);
strcpy( ca_event->ErrStr, "Invalid Action" ); UpnpActionRequest_strcpy_ErrStr(ca_event, "Invalid Action" );
ca_event->ErrCode = 401; UpnpActionRequest_set_ErrCode(ca_event, 401);
} else { } else {
if( retCode == UPNP_E_SUCCESS ) { if( retCode == UPNP_E_SUCCESS ) {
ca_event->ErrCode = UPNP_E_SUCCESS; UpnpActionRequest_set_ErrCode(ca_event, UPNP_E_SUCCESS);
} else { } else {
//copy the error string // copy the error string
strcpy( ca_event->ErrStr, errorString ); UpnpActionRequest_strcpy_ErrStr(ca_event, errorString );
switch ( retCode ) { switch ( retCode ) {
case UPNP_E_INVALID_PARAM: case UPNP_E_INVALID_PARAM:
{ {
ca_event->ErrCode = 402; UpnpActionRequest_set_ErrCode(ca_event, 402);
break; break;
} }
case UPNP_E_INTERNAL_ERROR: case UPNP_E_INTERNAL_ERROR:
default: default:
{ {
ca_event->ErrCode = 501; UpnpActionRequest_set_ErrCode(ca_event, 501);
break; break;
} }
@ -588,7 +573,7 @@ TvDeviceHandleActionRequest( INOUT struct Upnp_Action_Request *ca_event )
} }
} }
return ( ca_event->ErrCode ); return UpnpActionRequest_get_ErrCode(ca_event);
} }
/****************************************************************************** /******************************************************************************
@ -651,7 +636,6 @@ TvDeviceSetServiceTableVar( IN unsigned int service,
ithread_mutex_unlock( &TVDevMutex ); ithread_mutex_unlock( &TVDevMutex );
return ( 1 ); return ( 1 );
} }
/****************************************************************************** /******************************************************************************
@ -674,7 +658,7 @@ TvDeviceSetPower( IN int on )
if( on != POWER_ON && on != POWER_OFF ) { if( on != POWER_ON && on != POWER_OFF ) {
SampleUtil_Print( "error: can't set power to value %d\n", on ); SampleUtil_Print( "error: can't set power to value %d\n", on );
return ( 0 ); return 0;
} }
/* /*
@ -685,7 +669,7 @@ TvDeviceSetPower( IN int on )
ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER, ret = TvDeviceSetServiceTableVar( TV_SERVICE_CONTROL, TV_CONTROL_POWER,
value ); value );
return ( ret ); return ret;
} }
/****************************************************************************** /******************************************************************************
@ -702,9 +686,7 @@ TvDeviceSetPower( IN int on )
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOn( IN IXML_Document * in, TvDevicePowerOn( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = NULL; ( *errorString ) = NULL;
@ -724,7 +706,6 @@ TvDevicePowerOn( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -742,7 +723,7 @@ TvDevicePowerOn( IN IXML_Document * in,
*****************************************************************************/ *****************************************************************************/
int int
TvDevicePowerOff( IN IXML_Document * in, TvDevicePowerOff( IN IXML_Document * in,
OUT IXML_Document ** out, OUT IXML_Document **out,
OUT char **errorString ) OUT char **errorString )
{ {
( *out ) = NULL; ( *out ) = NULL;
@ -781,11 +762,8 @@ TvDevicePowerOff( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetChannel( IN IXML_Document * in, TvDeviceSetChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int channel = 0; int channel = 0;
@ -830,7 +808,6 @@ TvDeviceSetChannel( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -848,13 +825,10 @@ TvDeviceSetChannel( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementChannel( IN int incr, IncrementChannel( IN int incr, IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curchannel, int curchannel;
newchannel; int newchannel;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -916,12 +890,9 @@ IncrementChannel( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseChannel( IN IXML_Document * in, TvDeviceDecreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( -1, in, out, errorString ); return IncrementChannel( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -938,12 +909,9 @@ TvDeviceDecreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseChannel( IN IXML_Document * in, TvDeviceIncreaseChannel( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementChannel( 1, in, out, errorString ); return IncrementChannel( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -962,13 +930,9 @@ TvDeviceIncreaseChannel( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetVolume( IN IXML_Document * in, TvDeviceSetVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int volume = 0; int volume = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1009,7 +973,6 @@ TvDeviceSetVolume( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1028,10 +991,7 @@ TvDeviceSetVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
IncrementVolume( IN int incr, IncrementVolume( IN int incr, IN IXML_Document *in,OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curvolume, int curvolume,
newvolume; newvolume;
@ -1068,8 +1028,7 @@ IncrementVolume( IN int incr,
TV_CONTROL_VOLUME, value ) ) { TV_CONTROL_VOLUME, value ) ) {
if( UpnpAddToActionResponse( out, actionName, if( UpnpAddToActionResponse( out, actionName,
TvServiceType[TV_SERVICE_CONTROL], TvServiceType[TV_SERVICE_CONTROL],
"Volume", value ) != UPNP_E_SUCCESS ) "Volume", value ) != UPNP_E_SUCCESS ) {
{
( *out ) = NULL; ( *out ) = NULL;
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
@ -1079,7 +1038,6 @@ IncrementVolume( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1096,13 +1054,9 @@ IncrementVolume( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseVolume( IN IXML_Document * in, TvDeviceIncreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( 1, in, out, errorString ); return IncrementVolume( 1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1119,13 +1073,9 @@ TvDeviceIncreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseVolume( IN IXML_Document * in, TvDeviceDecreaseVolume( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementVolume( -1, in, out, errorString ); return IncrementVolume( -1, in, out, errorString );
} }
/****************************************************************************** /******************************************************************************
@ -1144,13 +1094,9 @@ TvDeviceDecreaseVolume( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetColor( IN IXML_Document * in, TvDeviceSetColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int color = 0; int color = 0;
( *out ) = NULL; ( *out ) = NULL;
@ -1190,7 +1136,6 @@ TvDeviceSetColor( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1207,16 +1152,11 @@ TvDeviceSetColor( IN IXML_Document * in,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementColor( IN int incr, IncrementColor( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcolor, int curcolor;
newcolor; int newcolor;
char *actionName; char *actionName;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1274,11 +1214,8 @@ IncrementColor( IN int incr,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseColor( IN IXML_Document * in, TvDeviceDecreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( -1, in, out, errorString ); return IncrementColor( -1, in, out, errorString );
} }
@ -1295,11 +1232,8 @@ TvDeviceDecreaseColor( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseColor( IN IXML_Document * in, TvDeviceIncreaseColor( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementColor( 1, in, out, errorString ); return IncrementColor( 1, in, out, errorString );
} }
@ -1319,13 +1253,9 @@ TvDeviceIncreaseColor( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetTint( IN IXML_Document * in, TvDeviceSetTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int tint = -1; int tint = -1;
( *out ) = NULL; ( *out ) = NULL;
@ -1384,14 +1314,10 @@ TvDeviceSetTint( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementTint( IN int incr, IncrementTint( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curtint, int curtint;
newtint; int newtint;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1434,7 +1360,6 @@ IncrementTint( IN int incr,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1451,11 +1376,8 @@ IncrementTint( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseTint( IN IXML_Document * in, TvDeviceIncreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( 1, in, out, errorString ); return IncrementTint( 1, in, out, errorString );
} }
@ -1473,11 +1395,8 @@ TvDeviceIncreaseTint( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseTint( IN IXML_Document * in, TvDeviceDecreaseTint( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementTint( -1, in, out, errorString ); return IncrementTint( -1, in, out, errorString );
} }
@ -1497,11 +1416,8 @@ TvDeviceDecreaseTint( IN IXML_Document * in,
* *
****************************************************************************/ ****************************************************************************/
int int
TvDeviceSetContrast( IN IXML_Document * in, TvDeviceSetContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int contrast = -1; int contrast = -1;
@ -1562,14 +1478,10 @@ TvDeviceSetContrast( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementContrast( IN int incr, IncrementContrast( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curcontrast, int curcontrast;
newcontrast; int newcontrast;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1631,11 +1543,8 @@ IncrementContrast( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseContrast( IN IXML_Document * in, TvDeviceIncreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementContrast( 1, in, out, errorString ); return IncrementContrast( 1, in, out, errorString );
} }
@ -1653,9 +1562,7 @@ TvDeviceIncreaseContrast( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseContrast( IXML_Document * in, TvDeviceDecreaseContrast( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IXML_Document ** out,
char **errorString )
{ {
return IncrementContrast( -1, in, out, errorString ); return IncrementContrast( -1, in, out, errorString );
} }
@ -1673,11 +1580,8 @@ TvDeviceDecreaseContrast( IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceSetBrightness( IN IXML_Document * in, TvDeviceSetBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
char *value = NULL; char *value = NULL;
int brightness = -1; int brightness = -1;
@ -1720,7 +1624,6 @@ TvDeviceSetBrightness( IN IXML_Document * in,
( *errorString ) = "Internal Error"; ( *errorString ) = "Internal Error";
return UPNP_E_INTERNAL_ERROR; return UPNP_E_INTERNAL_ERROR;
} }
} }
/****************************************************************************** /******************************************************************************
@ -1738,13 +1641,10 @@ TvDeviceSetBrightness( IN IXML_Document * in,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int int
IncrementBrightness( IN int incr, IncrementBrightness( IN int incr, IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
IN IXML_Document * in,
OUT IXML_Document ** out,
OUT char **errorString )
{ {
int curbrightness, int curbrightness;
newbrightness; int newbrightness;
char *actionName = NULL; char *actionName = NULL;
char value[TV_MAX_VAL_LEN]; char value[TV_MAX_VAL_LEN];
@ -1805,9 +1705,7 @@ IncrementBrightness( IN int incr,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceIncreaseBrightness( IN IXML_Document * in, TvDeviceIncreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( 1, in, out, errorString ); return IncrementBrightness( 1, in, out, errorString );
} }
@ -1825,9 +1723,7 @@ TvDeviceIncreaseBrightness( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceDecreaseBrightness( IN IXML_Document * in, TvDeviceDecreaseBrightness( IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString )
OUT IXML_Document ** out,
OUT char **errorString )
{ {
return IncrementBrightness( -1, in, out, errorString ); return IncrementBrightness( -1, in, out, errorString );
} }
@ -1852,28 +1748,19 @@ TvDeviceDecreaseBrightness( IN IXML_Document * in,
* *
*****************************************************************************/ *****************************************************************************/
int int
TvDeviceCallbackEventHandler( Upnp_EventType EventType, TvDeviceCallbackEventHandler( Upnp_EventType EventType, void *Event, void *Cookie )
void *Event,
void *Cookie )
{ {
switch ( EventType ) { switch ( EventType ) {
case UPNP_EVENT_SUBSCRIPTION_REQUEST: case UPNP_EVENT_SUBSCRIPTION_REQUEST:
TvDeviceHandleSubscriptionRequest( (struct Upnp_Subscription_Request *)Event );
TvDeviceHandleSubscriptionRequest( ( struct
Upnp_Subscription_Request
* )Event );
break; break;
case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_GET_VAR_REQUEST:
TvDeviceHandleGetVarRequest( ( struct Upnp_State_Var_Request TvDeviceHandleGetVarRequest( (UpnpStateVarRequest *)Event );
* )Event );
break; break;
case UPNP_CONTROL_ACTION_REQUEST: case UPNP_CONTROL_ACTION_REQUEST:
TvDeviceHandleActionRequest( ( struct Upnp_Action_Request * ) TvDeviceHandleActionRequest( (UpnpActionRequest *)Event );
Event );
break; break;
/* /*
@ -1892,17 +1779,14 @@ TvDeviceCallbackEventHandler( Upnp_EventType EventType,
break; break;
default: default:
SampleUtil_Print SampleUtil_Print( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n",
( "Error in TvDeviceCallbackEventHandler: unknown event type %d\n", EventType );
EventType );
} }
/* /* Print a summary of the event received */
Print a summary of the event received
*/
SampleUtil_PrintEvent( EventType, Event ); SampleUtil_PrintEvent( EventType, Event );
return ( 0 ); return 0;
} }
/****************************************************************************** /******************************************************************************
@ -1921,6 +1805,7 @@ TvDeviceStop()
UpnpFinish(); UpnpFinish();
SampleUtil_Finish(); SampleUtil_Finish();
ithread_mutex_destroy( &TVDevMutex ); ithread_mutex_destroy( &TVDevMutex );
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
@ -1953,7 +1838,6 @@ TvDeviceStart( char *ip_address,
print_string pfun ) print_string pfun )
{ {
int ret = UPNP_E_SUCCESS; int ret = UPNP_E_SUCCESS;
char desc_doc_url[DESC_URL_SIZE]; char desc_doc_url[DESC_URL_SIZE];
ithread_mutex_init( &TVDevMutex, NULL ); ithread_mutex_init( &TVDevMutex, NULL );
@ -1965,16 +1849,14 @@ TvDeviceStart( char *ip_address,
"\tipaddress = %s port = %u\n", "\tipaddress = %s port = %u\n",
ip_address, port ); ip_address, port );
if( ( ret = UpnpInit( ip_address, port ) ) != UPNP_E_SUCCESS ) { ret = UpnpInit( ip_address, port );
if( ret != UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error with UpnpInit -- %d\n", ret ); SampleUtil_Print( "Error with UpnpInit -- %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
if( ip_address == NULL ) { ip_address = UpnpGetServerIpAddress();
ip_address = UpnpGetServerIpAddress();
}
port = UpnpGetServerPort(); port = UpnpGetServerPort();
SampleUtil_Print( SampleUtil_Print(
@ -1995,12 +1877,12 @@ TvDeviceStart( char *ip_address,
SampleUtil_Print( "Specifying the webserver root directory -- %s\n", SampleUtil_Print( "Specifying the webserver root directory -- %s\n",
web_dir_path ); web_dir_path );
if( ( ret = ret = UpnpSetWebServerRootDir( web_dir_path );
UpnpSetWebServerRootDir( web_dir_path ) ) != UPNP_E_SUCCESS ) { if( ret != UPNP_E_SUCCESS ) {
SampleUtil_Print SampleUtil_Print( "Error specifying webserver root directory -- %s: %d\n",
( "Error specifying webserver root directory -- %s: %d\n",
web_dir_path, ret ); web_dir_path, ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
@ -2009,12 +1891,12 @@ TvDeviceStart( char *ip_address,
"\t with desc_doc_url: %s\n", "\t with desc_doc_url: %s\n",
desc_doc_url ); desc_doc_url );
if( ( ret = UpnpRegisterRootDevice( desc_doc_url, ret = UpnpRegisterRootDevice( desc_doc_url, TvDeviceCallbackEventHandler,
TvDeviceCallbackEventHandler, &device_handle, &device_handle );
&device_handle, &device_handle ) ) if( ret != UPNP_E_SUCCESS ) {
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error registering the rootdevice : %d\n", ret ); SampleUtil_Print( "Error registering the rootdevice : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} else { } else {
SampleUtil_Print( SampleUtil_Print(
@ -2022,17 +1904,17 @@ TvDeviceStart( char *ip_address,
"Initializing State Table\n"); "Initializing State Table\n");
TvDeviceStateTableInit( desc_doc_url ); TvDeviceStateTableInit( desc_doc_url );
SampleUtil_Print("State Table Initialized\n"); SampleUtil_Print("State Table Initialized\n");
ret = UpnpSendAdvertisement( device_handle, default_advr_expire );
if( ( ret = if( ret != UPNP_E_SUCCESS ) {
UpnpSendAdvertisement( device_handle, default_advr_expire ) )
!= UPNP_E_SUCCESS ) {
SampleUtil_Print( "Error sending advertisements : %d\n", ret ); SampleUtil_Print( "Error sending advertisements : %d\n", ret );
UpnpFinish(); UpnpFinish();
return ret; return ret;
} }
SampleUtil_Print("Advertisements Sent\n"); SampleUtil_Print("Advertisements Sent\n");
} }
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }

View File

@ -148,8 +148,7 @@ extern char *TvServiceType[];
* *
*****************************************************************************/ *****************************************************************************/
typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out, typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out, char **errorString);
char **errorString);
/* Structure for storing Tv Service /* Structure for storing Tv Service
identifiers and state table */ identifiers and state table */
@ -193,7 +192,7 @@ extern ithread_mutex_t TVDevMutex;
* struct TvService *out - service containing action table to set. * struct TvService *out - service containing action table to set.
* *
*****************************************************************************/ *****************************************************************************/
int SetActionTable(int serviceType, struct TvService * out); int SetActionTable(int serviceType, struct TvService *out);
/****************************************************************************** /******************************************************************************
* TvDeviceStateTableInit * TvDeviceStateTableInit
@ -241,7 +240,7 @@ int TvDeviceHandleSubscriptionRequest(struct Upnp_Subscription_Request *);
* cgv_event -- The control get variable request event structure * cgv_event -- The control get variable request event structure
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceHandleGetVarRequest(struct Upnp_State_Var_Request *); int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *);
/****************************************************************************** /******************************************************************************
* TvDeviceHandleActionRequest * TvDeviceHandleActionRequest
@ -255,7 +254,7 @@ int TvDeviceHandleGetVarRequest(struct Upnp_State_Var_Request *);
* ca_event -- The control action request event structure * ca_event -- The control action request event structure
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceHandleActionRequest(struct Upnp_Action_Request *); int TvDeviceHandleActionRequest(UpnpActionRequest *);
/****************************************************************************** /******************************************************************************
* TvDeviceCallbackEventHandler * TvDeviceCallbackEventHandler
@ -313,8 +312,7 @@ int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*);
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out, int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDevicePowerOff * TvDevicePowerOff
@ -329,8 +327,7 @@ int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out, int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetChannel * TvDeviceSetChannel
@ -347,8 +344,7 @@ int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseChannel * TvDeviceIncreaseChannel
@ -363,8 +359,7 @@ int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseChannel * TvDeviceDecreaseChannel
* *
@ -378,8 +373,7 @@ int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetVolume * TvDeviceSetVolume
* *
@ -395,8 +389,7 @@ int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseVolume * TvDeviceIncreaseVolume
@ -411,8 +404,7 @@ int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document**out, int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
@ -428,8 +420,7 @@ int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document**out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document**out, int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
//Picture Service Actions //Picture Service Actions
@ -449,8 +440,7 @@ int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document**out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
@ -465,8 +455,7 @@ int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out, int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseColor * TvDeviceDecreaseColor
@ -480,8 +469,7 @@ int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
* IXML_Document **out - action result document * IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out, int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetTint * TvDeviceSetTint
@ -498,8 +486,7 @@ int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseTint * TvDeviceIncreaseTint
@ -514,8 +501,7 @@ int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseTint * TvDeviceDecreaseTint
@ -530,8 +516,7 @@ int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/***************************************************************************** /*****************************************************************************
* TvDeviceSetContrast * TvDeviceSetContrast
@ -548,8 +533,7 @@ int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
****************************************************************************/ ****************************************************************************/
int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseContrast * TvDeviceIncreaseContrast
@ -565,8 +549,7 @@ int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseContrast * TvDeviceDecreaseContrast
* *
@ -580,8 +563,7 @@ int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceSetBrightness * TvDeviceSetBrightness
@ -595,8 +577,7 @@ int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
* brightness -- The brightness value to change to. * brightness -- The brightness value to change to.
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceIncreaseBrightness * TvDeviceIncreaseBrightness
@ -611,8 +592,7 @@ int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
/****************************************************************************** /******************************************************************************
* TvDeviceDecreaseBrightness * TvDeviceDecreaseBrightness
@ -626,8 +606,7 @@ int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful) * char **errorString - errorString (in case action was unsuccessful)
* *
*****************************************************************************/ *****************************************************************************/
int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
OUT char **errorString);
int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name, int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name,
char *web_dir_path, print_string pfun); char *web_dir_path, print_string pfun);

View File

@ -0,0 +1,134 @@
#include "config.h"
#include "ActionComplete.h"
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for strlen(), strdup()
struct SUpnpActionComplete
{
int m_errCode;
UpnpString *m_ctrlUrl;
IXML_Document *m_actionRequest;
IXML_Document *m_actionResult;
};
UpnpActionComplete *UpnpActionComplete_new()
{
struct SUpnpActionComplete *p = calloc(1, sizeof (struct SUpnpActionComplete));
#if 0
p->m_errCode = 0;
#endif
p->m_ctrlUrl = UpnpString_new();
#if 0
p->m_actionRequest = NULL;
p->m_actionResult = NULL;
#endif
return (UpnpActionComplete *)p;
}
void UpnpActionComplete_delete(UpnpActionComplete *p)
{
struct SUpnpActionComplete *q = (struct SUpnpActionComplete *)p;
q->m_errCode = 0;
UpnpString_delete(q->m_ctrlUrl);
q->m_ctrlUrl = NULL;
UpnpActionComplete_set_ActionRequest(p, NULL);
UpnpActionComplete_set_ActionResult(p, NULL);
free(p);
}
UpnpActionComplete *UpnpActionComplete_dup(const UpnpActionComplete *p)
{
UpnpActionComplete *q = UpnpActionComplete_new();
UpnpActionComplete_assign(q, p);
return q;
}
void UpnpActionComplete_assign(UpnpActionComplete *q, const UpnpActionComplete *p)
{
if (q != p) {
UpnpActionComplete_set_ErrCode(q, UpnpActionComplete_get_ErrCode(p));
UpnpActionComplete_set_CtrlUrl(q, UpnpActionComplete_get_CtrlUrl(p));
UpnpActionComplete_set_ActionRequest(q, UpnpActionComplete_get_ActionRequest(p));
UpnpActionComplete_set_ActionResult(q, UpnpActionComplete_get_ActionResult(p));
}
}
int UpnpActionComplete_get_ErrCode(const UpnpActionComplete *p)
{
return ((struct SUpnpActionComplete *)p)->m_errCode;
}
void UpnpActionComplete_set_ErrCode(UpnpActionComplete *p, int n)
{
((struct SUpnpActionComplete *)p)->m_errCode = n;
}
const UpnpString *UpnpActionComplete_get_CtrlUrl(const UpnpActionComplete *p)
{
return ((struct SUpnpActionComplete *)p)->m_ctrlUrl;
}
void UpnpActionComplete_set_CtrlUrl(UpnpActionComplete *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpActionComplete *)p)->m_ctrlUrl);
((struct SUpnpActionComplete *)p)->m_ctrlUrl = UpnpString_dup(s);
}
void UpnpActionComplete_strcpy_CtrlUrl(UpnpActionComplete *p, const char *s)
{
UpnpString_delete(((struct SUpnpActionComplete *)p)->m_ctrlUrl);
((struct SUpnpActionComplete *)p)->m_ctrlUrl = UpnpString_new();
UpnpString_set_String(((struct SUpnpActionComplete *)p)->m_ctrlUrl, s);
}
IXML_Document *UpnpActionComplete_get_ActionRequest(const UpnpActionComplete *p)
{
return ((struct SUpnpActionComplete *)p)->m_actionRequest;
}
void UpnpActionComplete_set_ActionRequest(UpnpActionComplete *p, IXML_Document *d)
{
ixmlDocument_free(((struct SUpnpActionComplete *)p)->m_actionRequest);
((struct SUpnpActionComplete *)p)->m_actionRequest = d;
}
IXML_Document *UpnpActionComplete_get_ActionResult(const UpnpActionComplete *p)
{
return ((struct SUpnpActionComplete *)p)->m_actionResult;
}
void UpnpActionComplete_set_ActionResult(UpnpActionComplete *p, IXML_Document *d)
{
ixmlDocument_free(((struct SUpnpActionComplete *)p)->m_actionResult);
((struct SUpnpActionComplete *)p)->m_actionResult = d;
}

View File

@ -0,0 +1,250 @@
#include "config.h"
#include "ActionRequest.h"
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for memset(), strlen(), strdup()
struct SUpnpActionRequest
{
int m_errCode;
int m_socket;
UpnpString *m_errStr;
UpnpString *m_actionName;
UpnpString *m_devUDN;
UpnpString *m_serviceID;
IXML_Document *m_actionRequest;
IXML_Document *m_actionResult;
IXML_Document *m_soapHeader;
struct in_addr m_ctrlPtIPAddr;
};
UpnpActionRequest *UpnpActionRequest_new()
{
struct SUpnpActionRequest *p = calloc(1, sizeof (struct SUpnpActionRequest));
#if 0
p->m_errCode = 0;
p->m_socket = 0;
#endif
p->m_errStr = UpnpString_new();
p->m_actionName = UpnpString_new();
p->m_devUDN = UpnpString_new();
p->m_serviceID = UpnpString_new();
#if 0
p->m_actionRequest = NULL;
p->m_actionResult = NULL;
p->m_soapHeader = NULL;
memset(&p->m_ctrlPtIPAddr, 0, sizeof (struct in_addr));
#endif
return (UpnpActionRequest *)p;
}
void UpnpActionRequest_delete(UpnpActionRequest *p)
{
struct SUpnpActionRequest *q = (struct SUpnpActionRequest *)p;
q->m_errCode = 0;
q->m_socket = 0;
UpnpString_delete(q->m_errStr);
q->m_errStr = NULL;
UpnpString_delete(q->m_actionName);
q->m_actionName = NULL;
UpnpString_delete(q->m_devUDN);
q->m_devUDN = NULL;
UpnpString_delete(q->m_serviceID);
q->m_serviceID = NULL;
UpnpActionRequest_set_ActionRequest(p, NULL);
UpnpActionRequest_set_ActionResult(p, NULL);
UpnpActionRequest_set_SoapHeader(p, NULL);
memset(&q->m_ctrlPtIPAddr, 0, sizeof (struct in_addr));
free(p);
}
UpnpActionRequest *UpnpActionRequest_dup(const UpnpActionRequest *p)
{
UpnpActionRequest *q = UpnpActionRequest_new();
UpnpActionRequest_assign(q, p);
return q;
}
void UpnpActionRequest_assign(UpnpActionRequest *q, const UpnpActionRequest *p)
{
if (q != p) {
UpnpActionRequest_set_ErrCode(q, UpnpActionRequest_get_ErrCode(p));
UpnpActionRequest_set_Socket(q, UpnpActionRequest_get_Socket(p));
UpnpActionRequest_set_ErrStr(q, UpnpActionRequest_get_ErrStr(p));
UpnpActionRequest_set_ActionName(q, UpnpActionRequest_get_ActionName(p));
UpnpActionRequest_set_DevUDN(q, UpnpActionRequest_get_DevUDN(p));
UpnpActionRequest_set_ServiceID(q, UpnpActionRequest_get_ServiceID(p));
UpnpActionRequest_set_ActionRequest(q, UpnpActionRequest_get_ActionRequest(p));
UpnpActionRequest_set_ActionResult(q, UpnpActionRequest_get_ActionResult(p));
UpnpActionRequest_set_CtrlPtIPAddr(q, UpnpActionRequest_get_CtrlPtIPAddr(p));
UpnpActionRequest_set_SoapHeader(q, UpnpActionRequest_get_SoapHeader(p));
}
}
int UpnpActionRequest_get_ErrCode(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_errCode;
}
void UpnpActionRequest_set_ErrCode(UpnpActionRequest *p, int n)
{
((struct SUpnpActionRequest *)p)->m_errCode = n;
}
int UpnpActionRequest_get_Socket(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_socket;
}
void UpnpActionRequest_set_Socket(UpnpActionRequest *p, int n)
{
((struct SUpnpActionRequest *)p)->m_socket = n;
}
const UpnpString *UpnpActionRequest_get_ErrStr(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_errStr;
}
void UpnpActionRequest_set_ErrStr(UpnpActionRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpActionRequest *)p)->m_errStr);
((struct SUpnpActionRequest *)p)->m_errStr = UpnpString_dup(s);
}
void UpnpActionRequest_strcpy_ErrStr(UpnpActionRequest *p, const char *s)
{
UpnpString_delete(((struct SUpnpActionRequest *)p)->m_errStr);
((struct SUpnpActionRequest *)p)->m_errStr = UpnpString_new();
UpnpString_set_String(((struct SUpnpActionRequest *)p)->m_errStr, s);
}
const UpnpString *UpnpActionRequest_get_ActionName(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_actionName;
}
void UpnpActionRequest_set_ActionName(UpnpActionRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpActionRequest *)p)->m_actionName);
((struct SUpnpActionRequest *)p)->m_actionName = UpnpString_dup(s);
}
void UpnpActionRequest_strcpy_ActionName(UpnpActionRequest *p, const char *s)
{
UpnpString_delete(((struct SUpnpActionRequest *)p)->m_actionName);
((struct SUpnpActionRequest *)p)->m_actionName = UpnpString_new();
UpnpString_set_String(((struct SUpnpActionRequest *)p)->m_actionName, s);
}
const UpnpString *UpnpActionRequest_get_DevUDN(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_devUDN;
}
void UpnpActionRequest_set_DevUDN(UpnpActionRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpActionRequest *)p)->m_devUDN);
((struct SUpnpActionRequest *)p)->m_devUDN = UpnpString_dup(s);
}
const UpnpString *UpnpActionRequest_get_ServiceID(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_serviceID;
}
void UpnpActionRequest_set_ServiceID(UpnpActionRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpActionRequest *)p)->m_serviceID);
((struct SUpnpActionRequest *)p)->m_serviceID = UpnpString_dup(s);
}
IXML_Document *UpnpActionRequest_get_ActionRequest(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_actionRequest;
}
void UpnpActionRequest_set_ActionRequest(UpnpActionRequest *p, IXML_Document *d)
{
ixmlDocument_free(((struct SUpnpActionRequest *)p)->m_actionRequest);
((struct SUpnpActionRequest *)p)->m_actionRequest = d;
}
IXML_Document *UpnpActionRequest_get_ActionResult(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_actionResult;
}
void UpnpActionRequest_set_ActionResult(UpnpActionRequest *p, IXML_Document *d)
{
ixmlDocument_free(((struct SUpnpActionRequest *)p)->m_actionResult);
((struct SUpnpActionRequest *)p)->m_actionResult = d;
}
struct in_addr *UpnpActionRequest_get_CtrlPtIPAddr(const UpnpActionRequest *p)
{
return &((struct SUpnpActionRequest *)p)->m_ctrlPtIPAddr;
}
void UpnpActionRequest_set_CtrlPtIPAddr(UpnpActionRequest *p, struct in_addr *ia)
{
((struct SUpnpActionRequest *)p)->m_ctrlPtIPAddr = *ia;
}
IXML_Document *UpnpActionRequest_get_SoapHeader(const UpnpActionRequest *p)
{
return ((struct SUpnpActionRequest *)p)->m_soapHeader;
}
void UpnpActionRequest_set_SoapHeader(UpnpActionRequest *p, IXML_Document *d)
{
ixmlDocument_free(((struct SUpnpActionRequest *)p)->m_soapHeader);
((struct SUpnpActionRequest *)p)->m_soapHeader = d;
}

345
upnp/src/api/Discovery.c Normal file
View File

@ -0,0 +1,345 @@
#include "config.h"
#include "Discovery.h"
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for memset()
struct SUpnpDiscovery
{
int m_errCode;
int m_expires;
UpnpString *m_deviceID;
UpnpString *m_deviceType;
UpnpString *m_serviceType;
UpnpString *m_serviceVer;
UpnpString *m_location;
UpnpString *m_os;
UpnpString *m_date;
UpnpString *m_ext;
struct sockaddr_in m_destAddr;
};
UpnpDiscovery *UpnpDiscovery_new()
{
struct SUpnpDiscovery *p = calloc(1, sizeof (struct SUpnpDiscovery));
#if 0
p->errCode = 0;
p->m_expires = 0;
#endif
p->m_deviceID = UpnpString_new();
p->m_deviceType = UpnpString_new();
p->m_serviceType = UpnpString_new();
p->m_serviceVer = UpnpString_new();
p->m_location = UpnpString_new();
p->m_os = UpnpString_new();
p->m_date = UpnpString_new();
p->m_ext = UpnpString_new();
#if 0
memset(p->m_destAddr, 0, sizeof(struct sockaddr_in));
#endif
return (UpnpDiscovery *)p;
}
void UpnpDiscovery_delete(UpnpDiscovery *p)
{
struct SUpnpDiscovery *q = (struct SUpnpDiscovery *)p;
q->m_errCode = 0;
q->m_expires = 0;
UpnpString_delete(q->m_deviceID);
q->m_deviceID = NULL;
UpnpString_delete(q->m_deviceType);
q->m_deviceType = NULL;
UpnpString_delete(q->m_serviceType);
q->m_serviceType = NULL;
UpnpString_delete(q->m_serviceVer);
q->m_serviceVer = NULL;
UpnpString_delete(q->m_location);
q->m_location = NULL;
UpnpString_delete(q->m_os);
q->m_os = NULL;
UpnpString_delete(q->m_date);
q->m_date = NULL;
UpnpString_delete(q->m_ext);
q->m_ext = NULL;
memset(&q->m_destAddr, 0, sizeof(struct sockaddr_in));
free(p);
}
UpnpDiscovery *UpnpDiscovery_dup(const UpnpDiscovery *p)
{
UpnpDiscovery *q = UpnpDiscovery_new();
UpnpDiscovery_assign(q, p);
return q;
}
void UpnpDiscovery_assign(UpnpDiscovery *q, const UpnpDiscovery *p)
{
if (q != p) {
UpnpDiscovery_set_ErrCode(q, UpnpDiscovery_get_ErrCode(p));
UpnpDiscovery_set_Expires(q, UpnpDiscovery_get_Expires(p));
UpnpDiscovery_set_DeviceID(q, UpnpDiscovery_get_DeviceID(p));
UpnpDiscovery_set_DeviceType(q, UpnpDiscovery_get_DeviceType(p));
UpnpDiscovery_set_ServiceType(q, UpnpDiscovery_get_ServiceType(p));
UpnpDiscovery_set_ServiceVer(q, UpnpDiscovery_get_ServiceVer(p));
UpnpDiscovery_set_Location(q, UpnpDiscovery_get_Location(p));
UpnpDiscovery_set_Os(q, UpnpDiscovery_get_Os(p));
UpnpDiscovery_set_Date(q, UpnpDiscovery_get_Date(p));
UpnpDiscovery_set_Ext(q, UpnpDiscovery_get_Ext(p));
UpnpDiscovery_set_DestAddr(q, UpnpDiscovery_get_DestAddr(p));
}
}
int UpnpDiscovery_get_ErrCode(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_errCode;
}
void UpnpDiscovery_set_ErrCode(UpnpDiscovery *p, int n)
{
((struct SUpnpDiscovery *)p)->m_errCode = n;
}
int UpnpDiscovery_get_Expires(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_expires;
}
void UpnpDiscovery_set_Expires(UpnpDiscovery *p, int n)
{
((struct SUpnpDiscovery *)p)->m_expires = n;
}
const UpnpString *UpnpDiscovery_get_DeviceID(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_deviceID;
}
void UpnpDiscovery_set_DeviceID(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_deviceID);
((struct SUpnpDiscovery *)p)->m_deviceID = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_DeviceID(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_deviceID);
((struct SUpnpDiscovery *)p)->m_deviceID = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_deviceID, s);
}
const UpnpString *UpnpDiscovery_get_DeviceType(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_deviceType;
}
void UpnpDiscovery_set_DeviceType(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_deviceType);
((struct SUpnpDiscovery *)p)->m_deviceType = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_DeviceType(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_deviceID);
((struct SUpnpDiscovery *)p)->m_deviceID = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_deviceID, s);
}
const UpnpString *UpnpDiscovery_get_ServiceType(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_serviceType;
}
void UpnpDiscovery_set_ServiceType(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_serviceType);
((struct SUpnpDiscovery *)p)->m_serviceType = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_ServiceType(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_serviceType);
((struct SUpnpDiscovery *)p)->m_serviceType = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_serviceType, s);
}
const UpnpString *UpnpDiscovery_get_ServiceVer(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_serviceVer;
}
void UpnpDiscovery_set_ServiceVer(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_serviceVer);
((struct SUpnpDiscovery *)p)->m_serviceVer = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_ServiceVer(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_serviceVer);
((struct SUpnpDiscovery *)p)->m_serviceVer = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_serviceVer, s);
}
const UpnpString *UpnpDiscovery_get_Location(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_location;
}
void UpnpDiscovery_set_Location(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_location);
((struct SUpnpDiscovery *)p)->m_location = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_Location(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_location);
((struct SUpnpDiscovery *)p)->m_location = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_location, s);
}
void UpnpDiscovery_strncpy_Location(UpnpDiscovery *p, const char *s, int n)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_location);
((struct SUpnpDiscovery *)p)->m_location = UpnpString_new();
UpnpString_set_StringN(((struct SUpnpDiscovery *)p)->m_location, s, n);
}
const UpnpString *UpnpDiscovery_get_Os(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_os;
}
void UpnpDiscovery_set_Os(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_os);
((struct SUpnpDiscovery *)p)->m_os = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_Os(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_os);
((struct SUpnpDiscovery *)p)->m_os = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_os, s);
}
void UpnpDiscovery_strncpy_Os(UpnpDiscovery *p, const char *s, int n)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_os);
((struct SUpnpDiscovery *)p)->m_os = UpnpString_new();
UpnpString_set_StringN(((struct SUpnpDiscovery *)p)->m_os, s, n);
}
const UpnpString *UpnpDiscovery_get_Date(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_date;
}
void UpnpDiscovery_set_Date(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_date);
((struct SUpnpDiscovery *)p)->m_date = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_Date(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_date);
((struct SUpnpDiscovery *)p)->m_date = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_date, s);
}
const UpnpString *UpnpDiscovery_get_Ext(const UpnpDiscovery *p)
{
return ((struct SUpnpDiscovery *)p)->m_ext;
}
void UpnpDiscovery_set_Ext(UpnpDiscovery *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_ext);
((struct SUpnpDiscovery *)p)->m_ext = UpnpString_dup(s);
}
void UpnpDiscovery_strcpy_Ext(UpnpDiscovery *p, const char *s)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_ext);
((struct SUpnpDiscovery *)p)->m_ext = UpnpString_new();
UpnpString_set_String(((struct SUpnpDiscovery *)p)->m_ext, s);
}
void UpnpDiscovery_strncpy_Ext(UpnpDiscovery *p, const char *s, int n)
{
UpnpString_delete(((struct SUpnpDiscovery *)p)->m_ext);
((struct SUpnpDiscovery *)p)->m_ext = UpnpString_new();
UpnpString_set_StringN(((struct SUpnpDiscovery *)p)->m_ext, s, n);
}
struct sockaddr_in *UpnpDiscovery_get_DestAddr(const UpnpDiscovery *p)
{
return &((struct SUpnpDiscovery *)p)->m_destAddr;
}
void UpnpDiscovery_set_DestAddr(UpnpDiscovery *p, struct sockaddr_in *sa)
{
((struct SUpnpDiscovery *)p)->m_destAddr = *sa;
}

View File

@ -0,0 +1,138 @@
#include "config.h"
#include "EventSubscribe.h"
#include <stdlib.h> // for calloc(), free()
struct SEventSubscribe
{
int m_errCode;
int m_timeOut;
UpnpString *m_SID;
UpnpString *m_publisherUrl;
};
EventSubscribe *UpnpEventSubscribe_new()
{
struct SEventSubscribe *p = calloc(1, sizeof (struct SEventSubscribe));
#if 0
p->errCode = 0;
p->timeOut = 0;
#endif
p->m_SID = UpnpString_new();
p->m_publisherUrl = UpnpString_new();
return (EventSubscribe *)p;
}
void UpnpEventSubscribe_delete(EventSubscribe *p)
{
struct SEventSubscribe *q = (struct SEventSubscribe *)p;
q->m_errCode = 0;
q->m_timeOut = 0;
UpnpString_delete(q->m_publisherUrl);
q->m_publisherUrl = NULL;
UpnpString_delete(q->m_SID);
q->m_SID = NULL;
free(p);
}
EventSubscribe *UpnpEventSubscribe_dup(const EventSubscribe *p)
{
EventSubscribe *q = UpnpEventSubscribe_new();
UpnpEventSubscribe_assign(q, p);
return q;
}
void UpnpEventSubscribe_assign(EventSubscribe *q, const EventSubscribe *p)
{
if (q != p) {
UpnpEventSubscribe_set_ErrCode(q, UpnpEventSubscribe_get_ErrCode(p));
UpnpEventSubscribe_set_TimeOut(q, UpnpEventSubscribe_get_TimeOut(p));
UpnpEventSubscribe_set_SID(q, UpnpEventSubscribe_get_SID(p));
UpnpEventSubscribe_set_PublisherUrl(q, UpnpEventSubscribe_get_PublisherUrl(p));
}
}
int UpnpEventSubscribe_get_ErrCode(const EventSubscribe *p)
{
return ((struct SEventSubscribe *)p)->m_errCode;
}
void UpnpEventSubscribe_set_ErrCode(EventSubscribe *p, int n)
{
((struct SEventSubscribe *)p)->m_errCode = n;
}
int UpnpEventSubscribe_get_TimeOut(const EventSubscribe *p)
{
return ((struct SEventSubscribe *)p)->m_timeOut;
}
void UpnpEventSubscribe_set_TimeOut(EventSubscribe *p, int n)
{
((struct SEventSubscribe *)p)->m_timeOut = n;
}
const UpnpString *UpnpEventSubscribe_get_SID(const EventSubscribe *p)
{
return ((struct SEventSubscribe *)p)->m_SID;
}
void UpnpEventSubscribe_set_SID(EventSubscribe *p, const UpnpString *s)
{
UpnpString_delete(((struct SEventSubscribe *)p)->m_SID);
((struct SEventSubscribe *)p)->m_SID = UpnpString_dup(s);
}
void UpnpEventSubscribe_strcpy_SID(EventSubscribe *p, const char *s)
{
UpnpString_delete(((struct SEventSubscribe *)p)->m_SID);
((struct SEventSubscribe *)p)->m_SID = UpnpString_new();
UpnpString_set_String(((struct SEventSubscribe *)p)->m_SID, s);
}
const UpnpString *UpnpEventSubscribe_get_PublisherUrl(const EventSubscribe *p)
{
return ((struct SEventSubscribe *)p)->m_publisherUrl;
}
void UpnpEventSubscribe_set_PublisherUrl(EventSubscribe *p, const UpnpString *s)
{
UpnpString_delete(((struct SEventSubscribe *)p)->m_publisherUrl);
((struct SEventSubscribe *)p)->m_publisherUrl = UpnpString_dup(s);
}
void UpnpEventSubscribe_strcpy_PublisherUrl(EventSubscribe *p, const char *s)
{
UpnpString_delete(((struct SEventSubscribe *)p)->m_publisherUrl);
((struct SEventSubscribe *)p)->m_publisherUrl = UpnpString_new();
UpnpString_set_String(((struct SEventSubscribe *)p)->m_publisherUrl, s);
}

159
upnp/src/api/FileInfo.c Normal file
View File

@ -0,0 +1,159 @@
#include "config.h"
#include "FileInfo.h"
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for strlen(), strdup()
/** This is a private struct, it belongs only to this file. */
struct SUpnpFileInfo
{
off_t m_fileLength;
time_t m_lastModified;
int m_isDirectory;
int m_isReadable;
DOMString m_contentType;
DOMString m_extraHeaders;
};
UpnpFileInfo *UpnpFileInfo_new()
{
struct SUpnpFileInfo *p = calloc(1, sizeof (struct SUpnpFileInfo));
#if 0
p->m_fileLength = 0;
p->m_lastModified = 0;
p->m_isDirectory = 0;
p->m_isReadable = 0;
p->m_contentType = NULL;
p->m_extraHeaders = NULL;
#endif
return (UpnpFileInfo *)p;
}
void UpnpFileInfo_delete(UpnpFileInfo *p)
{
struct SUpnpFileInfo *q = (struct SUpnpFileInfo *)p;
q->m_fileLength = 0;
q->m_lastModified = 0;
q->m_isDirectory = 0;
q->m_isReadable = 0;
ixmlFreeDOMString(q->m_contentType);
q->m_contentType = NULL;
ixmlFreeDOMString(q->m_extraHeaders);
q->m_extraHeaders = NULL;
free(p);
}
UpnpFileInfo *UpnpFileInfo_dup(const UpnpFileInfo *p)
{
UpnpFileInfo *q = UpnpFileInfo_new();
UpnpFileInfo_assign(q, p);
return q;
}
void UpnpFileInfo_assign(UpnpFileInfo *q, const UpnpFileInfo *p)
{
if (q != p) {
UpnpFileInfo_set_FileLength(q, UpnpFileInfo_get_FileLength(p));
UpnpFileInfo_set_LastModified(q, UpnpFileInfo_get_LastModified(p));
UpnpFileInfo_set_IsDirectory(q, UpnpFileInfo_get_IsDirectory(p));
UpnpFileInfo_set_IsReadable(q, UpnpFileInfo_get_IsReadable(p));
UpnpFileInfo_set_ContentType(q, UpnpFileInfo_get_ContentType(p));
UpnpFileInfo_set_ExtraHeaders(q, UpnpFileInfo_get_ExtraHeaders(p));
}
}
off_t UpnpFileInfo_get_FileLength(const UpnpFileInfo *p)
{
return ((struct SUpnpFileInfo *)p)->m_fileLength;
}
void UpnpFileInfo_set_FileLength(UpnpFileInfo *p, off_t l)
{
((struct SUpnpFileInfo *)p)->m_fileLength = l;
}
const time_t *UpnpFileInfo_get_LastModified(const UpnpFileInfo *p)
{
return &((struct SUpnpFileInfo *)p)->m_lastModified;
}
void UpnpFileInfo_set_LastModified(UpnpFileInfo *p, const time_t *t)
{
((struct SUpnpFileInfo *)p)->m_lastModified = *t;
}
int UpnpFileInfo_get_IsDirectory(const UpnpFileInfo *p)
{
return ((struct SUpnpFileInfo *)p)->m_isDirectory;
}
void UpnpFileInfo_set_IsDirectory(UpnpFileInfo *p, int b)
{
((struct SUpnpFileInfo *)p)->m_isDirectory = b;
}
int UpnpFileInfo_get_IsReadable(const UpnpFileInfo *p)
{
return ((struct SUpnpFileInfo *)p)->m_isReadable;
}
void UpnpFileInfo_set_IsReadable(UpnpFileInfo *p, int b)
{
((struct SUpnpFileInfo *)p)->m_isReadable = b;
}
const DOMString UpnpFileInfo_get_ContentType(const UpnpFileInfo *p)
{
return ((struct SUpnpFileInfo *)p)->m_contentType;
}
void UpnpFileInfo_set_ContentType(UpnpFileInfo *p, const DOMString s)
{
ixmlFreeDOMString(((struct SUpnpFileInfo *)p)->m_contentType);
((struct SUpnpFileInfo *)p)->m_contentType = ixmlCloneDOMString(s);
}
const DOMString UpnpFileInfo_get_ExtraHeaders(const UpnpFileInfo *p)
{
return ((struct SUpnpFileInfo *)p)->m_extraHeaders;
}
void UpnpFileInfo_set_ExtraHeaders(UpnpFileInfo *p, const DOMString s)
{
ixmlFreeDOMString(((struct SUpnpFileInfo *)p)->m_extraHeaders);
((struct SUpnpFileInfo *)p)->m_extraHeaders = ixmlCloneDOMString(s);
}

View File

@ -0,0 +1,144 @@
#include "config.h"
#include "StateVarComplete.h"
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for strlen(), strdup()
struct SUpnpStateVarComplete
{
int m_errCode;
UpnpString *m_ctrlUrl;
UpnpString *m_stateVarName;
DOMString m_currentVal;
};
UpnpStateVarComplete *UpnpStateVarComplete_new()
{
struct SUpnpStateVarComplete *p = calloc(1, sizeof (struct SUpnpStateVarComplete));
#if 0
p->m_errCode = 0;
#endif
p->m_ctrlUrl = UpnpString_new();
p->m_stateVarName = UpnpString_new();
#if 0
p->m_currentVal = NULL;
#endif
return (UpnpStateVarComplete *)p;
}
void UpnpStateVarComplete_delete(UpnpStateVarComplete *p)
{
struct SUpnpStateVarComplete *q = (struct SUpnpStateVarComplete *)p;
q->m_errCode = 0;
UpnpString_delete(q->m_ctrlUrl);
q->m_ctrlUrl = NULL;
UpnpString_delete(q->m_stateVarName);
q->m_stateVarName = NULL;
ixmlFreeDOMString(q->m_currentVal);
q->m_currentVal = NULL;
free(p);
}
UpnpStateVarComplete *UpnpStateVarComplete_dup(const UpnpStateVarComplete *p)
{
UpnpStateVarComplete *q = UpnpStateVarComplete_new();
UpnpStateVarComplete_assign(q, p);
return q;
}
void UpnpStateVarComplete_assign(UpnpStateVarComplete *q, const UpnpStateVarComplete *p)
{
if (q != p) {
UpnpStateVarComplete_set_ErrCode(q, UpnpStateVarComplete_get_ErrCode(p));
UpnpStateVarComplete_set_CtrlUrl(q, UpnpStateVarComplete_get_CtrlUrl(p));
UpnpStateVarComplete_set_StateVarName(q, UpnpStateVarComplete_get_StateVarName(p));
UpnpStateVarComplete_set_CurrentVal(q, UpnpStateVarComplete_get_CurrentVal(p));
}
}
int UpnpStateVarComplete_get_ErrCode(const UpnpStateVarComplete *p)
{
return ((struct SUpnpStateVarComplete *)p)->m_errCode;
}
void UpnpStateVarComplete_set_ErrCode(UpnpStateVarComplete *p, int n)
{
((struct SUpnpStateVarComplete *)p)->m_errCode = n;
}
const UpnpString *UpnpStateVarComplete_get_CtrlUrl(const UpnpStateVarComplete *p)
{
return ((struct SUpnpStateVarComplete *)p)->m_ctrlUrl;
}
void UpnpStateVarComplete_set_CtrlUrl(UpnpStateVarComplete *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpStateVarComplete *)p)->m_ctrlUrl);
((struct SUpnpStateVarComplete *)p)->m_ctrlUrl = UpnpString_dup(s);
}
void UpnpStateVarComplete_strcpy_CtrlUrl(UpnpStateVarComplete *p, const char *s)
{
UpnpString_delete(((struct SUpnpStateVarComplete *)p)->m_ctrlUrl);
((struct SUpnpStateVarComplete *)p)->m_ctrlUrl = UpnpString_new();
UpnpString_set_String(((struct SUpnpStateVarComplete *)p)->m_ctrlUrl, s);
}
const UpnpString *UpnpStateVarComplete_get_StateVarName(const UpnpStateVarComplete *p)
{
return ((struct SUpnpStateVarComplete *)p)->m_stateVarName;
}
void UpnpStateVarComplete_set_StateVarName(UpnpStateVarComplete *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpStateVarComplete *)p)->m_stateVarName);
((struct SUpnpStateVarComplete *)p)->m_stateVarName = UpnpString_dup(s);
}
void UpnpStateVarComplete_strcpy_StateVarName(UpnpStateVarComplete *p, const char *s)
{
UpnpString_delete(((struct SUpnpStateVarComplete *)p)->m_ctrlUrl);
((struct SUpnpStateVarComplete *)p)->m_ctrlUrl = UpnpString_new();
UpnpString_set_String(((struct SUpnpStateVarComplete *)p)->m_ctrlUrl, s);
}
const DOMString UpnpStateVarComplete_get_CurrentVal(const UpnpStateVarComplete *p)
{
return ((struct SUpnpStateVarComplete *)p)->m_currentVal;
}
void UpnpStateVarComplete_set_CurrentVal(UpnpStateVarComplete *p, const DOMString s)
{
ixmlFreeDOMString(((struct SUpnpStateVarComplete *)p)->m_currentVal);
((struct SUpnpStateVarComplete *)p)->m_currentVal = ixmlCloneDOMString(s);
}

View File

@ -0,0 +1,216 @@
#include "config.h"
#include "StateVarRequest.h"
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for memset(), strlen(), strdup()
struct SUpnpStateVarRequest
{
int m_errCode;
int m_socket;
UpnpString *m_errStr;
UpnpString *m_devUDN;
UpnpString *m_serviceID;
UpnpString *m_stateVarName;
struct in_addr m_ctrlPtIPAddr;
DOMString m_currentVal;
};
UpnpStateVarRequest *UpnpStateVarRequest_new()
{
struct SUpnpStateVarRequest *p = calloc(1, sizeof (struct SUpnpStateVarRequest));
#if 0
p->m_errCode = 0;
p->m_socket = 0;
#endif
p->m_errStr = UpnpString_new();
p->m_devUDN = UpnpString_new();
p->m_serviceID = UpnpString_new();
p->m_stateVarName = UpnpString_new();
#if 0
memset(&q->m_ctrlPtIPAddr, 0, sizeof (struct in_addr));
p->m_currentVal = NULL;
#endif
return (UpnpStateVarRequest *)p;
}
void UpnpStateVarRequest_delete(UpnpStateVarRequest *p)
{
struct SUpnpStateVarRequest *q = (struct SUpnpStateVarRequest *)p;
q->m_errCode = 0;
q->m_socket = 0;
UpnpString_delete(q->m_errStr);
q->m_errStr = NULL;
UpnpString_delete(q->m_devUDN);
q->m_devUDN = NULL;
UpnpString_delete(q->m_serviceID);
q->m_serviceID = NULL;
UpnpString_delete(q->m_stateVarName);
q->m_stateVarName = NULL;
memset(&q->m_ctrlPtIPAddr, 0, sizeof (struct in_addr));
ixmlFreeDOMString(q->m_currentVal);
q->m_currentVal = NULL;
free(p);
}
UpnpStateVarRequest *UpnpStateVarRequest_dup(const UpnpStateVarRequest *p)
{
UpnpStateVarRequest *q = UpnpStateVarRequest_new();
UpnpStateVarRequest_assign(q, p);
return q;
}
void UpnpStateVarRequest_assign(UpnpStateVarRequest *q, const UpnpStateVarRequest *p)
{
if (q != p) {
UpnpStateVarRequest_set_ErrCode(q, UpnpStateVarRequest_get_ErrCode(p));
UpnpStateVarRequest_set_Socket(q, UpnpStateVarRequest_get_Socket(p));
UpnpStateVarRequest_set_ErrStr(q, UpnpStateVarRequest_get_ErrStr(p));
UpnpStateVarRequest_set_StateVarName(q, UpnpStateVarRequest_get_StateVarName(p));
UpnpStateVarRequest_set_DevUDN(q, UpnpStateVarRequest_get_DevUDN(p));
UpnpStateVarRequest_set_ServiceID(q, UpnpStateVarRequest_get_ServiceID(p));
UpnpStateVarRequest_set_CtrlPtIPAddr(q, UpnpStateVarRequest_get_CtrlPtIPAddr(p));
UpnpStateVarRequest_set_CurrentVal(q, UpnpStateVarRequest_get_CurrentVal(p));
}
}
int UpnpStateVarRequest_get_ErrCode(const UpnpStateVarRequest *p)
{
return ((struct SUpnpStateVarRequest *)p)->m_errCode;
}
void UpnpStateVarRequest_set_ErrCode(UpnpStateVarRequest *p, int n)
{
((struct SUpnpStateVarRequest *)p)->m_errCode = n;
}
int UpnpStateVarRequest_get_Socket(const UpnpStateVarRequest *p)
{
return ((struct SUpnpStateVarRequest *)p)->m_socket;
}
void UpnpStateVarRequest_set_Socket(UpnpStateVarRequest *p, int n)
{
((struct SUpnpStateVarRequest *)p)->m_socket = n;
}
const UpnpString *UpnpStateVarRequest_get_ErrStr(const UpnpStateVarRequest *p)
{
return ((struct SUpnpStateVarRequest *)p)->m_errStr;
}
void UpnpStateVarRequest_set_ErrStr(UpnpStateVarRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpStateVarRequest *)p)->m_errStr);
((struct SUpnpStateVarRequest *)p)->m_errStr = UpnpString_dup(s);
}
void UpnpStateVarRequest_strcpy_ErrStr(UpnpStateVarRequest *p, const char *s)
{
UpnpString_delete(((struct SUpnpStateVarRequest *)p)->m_errStr);
((struct SUpnpStateVarRequest *)p)->m_errStr = UpnpString_new();
UpnpString_set_String(((struct SUpnpStateVarRequest *)p)->m_errStr, s);
}
const UpnpString *UpnpStateVarRequest_get_DevUDN(const UpnpStateVarRequest *p)
{
return ((struct SUpnpStateVarRequest *)p)->m_devUDN;
}
void UpnpStateVarRequest_set_DevUDN(UpnpStateVarRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpStateVarRequest *)p)->m_devUDN);
((struct SUpnpStateVarRequest *)p)->m_devUDN = UpnpString_dup(s);
}
const UpnpString *UpnpStateVarRequest_get_ServiceID(const UpnpStateVarRequest *p)
{
return ((struct SUpnpStateVarRequest *)p)->m_serviceID;
}
void UpnpStateVarRequest_set_ServiceID(UpnpStateVarRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpStateVarRequest *)p)->m_serviceID);
((struct SUpnpStateVarRequest *)p)->m_serviceID = UpnpString_dup(s);
}
const UpnpString *UpnpStateVarRequest_get_StateVarName(const UpnpStateVarRequest *p)
{
return ((struct SUpnpStateVarRequest *)p)->m_stateVarName;
}
void UpnpStateVarRequest_set_StateVarName(UpnpStateVarRequest *p, const UpnpString *s)
{
UpnpString_delete(((struct SUpnpStateVarRequest *)p)->m_stateVarName);
((struct SUpnpStateVarRequest *)p)->m_stateVarName = UpnpString_dup(s);
}
void UpnpStateVarRequest_strcpy_StateVarName(UpnpStateVarRequest *p, const char *s)
{
UpnpString_delete(((struct SUpnpStateVarRequest *)p)->m_errStr);
((struct SUpnpStateVarRequest *)p)->m_errStr = UpnpString_new();
UpnpString_set_String(((struct SUpnpStateVarRequest *)p)->m_errStr, s);
}
struct in_addr *UpnpStateVarRequest_get_CtrlPtIPAddr(const UpnpStateVarRequest *p)
{
return &((struct SUpnpStateVarRequest *)p)->m_ctrlPtIPAddr;
}
void UpnpStateVarRequest_set_CtrlPtIPAddr(UpnpStateVarRequest *p, struct in_addr *ia)
{
((struct SUpnpStateVarRequest *)p)->m_ctrlPtIPAddr = *ia;
}
const DOMString UpnpStateVarRequest_get_CurrentVal(const UpnpStateVarRequest *p)
{
return ((struct SUpnpStateVarRequest *)p)->m_currentVal;
}
void UpnpStateVarRequest_set_CurrentVal(UpnpStateVarRequest *p, const DOMString s)
{
ixmlFreeDOMString(((struct SUpnpStateVarRequest *)p)->m_currentVal);
((struct SUpnpStateVarRequest *)p)->m_currentVal = ixmlCloneDOMString(s);
}

133
upnp/src/api/String.c Normal file
View File

@ -0,0 +1,133 @@
#include "config.h"
#include "String.h"
/*
* Due to its heavy use, this class is coded for efficiency, not for beauty.
* Do not use this as example to other classes. Please take a look at any
* other one.
*/
#include <stdlib.h> // for calloc(), free()
#include <string.h> // for strlen(), strdup()
struct SUpnpString
{
int m_length;
char *m_string;
};
UpnpString *UpnpString_new()
{
// All bytes are zero, and so is the length of the string.
struct SUpnpString *p = calloc(1, sizeof (struct SUpnpString));
if (p == NULL) {
goto error_handler1;
}
#if 0
p->m_length = 0;
#endif
// This byte is zero, calloc does initialize it.
p->m_string = calloc(1, 1);
if (p->m_string == NULL) {
goto error_handler2;
}
return (UpnpString *)p;
//free(p->m_string);
error_handler2:
free(p);
error_handler1:
return NULL;
}
void UpnpString_delete(UpnpString *p)
{
struct SUpnpString *q = (struct SUpnpString *)p;
q->m_length = 0;
free(q->m_string);
q->m_string = NULL;
free(p);
}
UpnpString *UpnpString_dup(const UpnpString *p)
{
struct SUpnpString *q = calloc(1, sizeof (struct SUpnpString));
if (q == NULL) {
goto error_handler1;
}
q->m_length = ((struct SUpnpString *)p)->m_length;
q->m_string = strdup(((struct SUpnpString *)p)->m_string);
if (q->m_string == NULL) {
goto error_handler2;
}
return (UpnpString *)q;
//free(q->m_string);
error_handler2:
free(q);
error_handler1:
return NULL;
}
void UpnpString_assign(UpnpString *q, const UpnpString *p)
{
if (q != p) {
UpnpString_set_String(q, UpnpString_get_String(p));
}
}
int UpnpString_get_Length(const UpnpString *p)
{
return ((struct SUpnpString *)p)->m_length;
}
const char *UpnpString_get_String(const UpnpString *p)
{
return ((struct SUpnpString *)p)->m_string;
}
void UpnpString_set_String(UpnpString *p, const char *s)
{
free(((struct SUpnpString *)p)->m_string);
((struct SUpnpString *)p)->m_length = strlen(s);
((struct SUpnpString *)p)->m_string = strdup(s);
}
void UpnpString_set_StringN(UpnpString *p, const char *s, int n)
{
free(((struct SUpnpString *)p)->m_string);
((struct SUpnpString *)p)->m_length = n;
((struct SUpnpString *)p)->m_string = (char *)malloc(n+1);
strncpy(((struct SUpnpString *)p)->m_string, s, n);
((struct SUpnpString *)p)->m_string[n] = 0;
}
void UpnpString_clear(UpnpString *p)
{
((struct SUpnpString *)p)->m_length = 0;
// No need to realloc now, will do later when needed
((struct SUpnpString *)p)->m_string[0] = 0;
}

View File

@ -1820,50 +1820,71 @@ UpnpSubscribeAsync( IN UpnpClient_Handle Hnd,
* Return Values: int * Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error. * UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/ ***************************************************************************/
int int UpnpSubscribe(
UpnpSubscribe( IN UpnpClient_Handle Hnd, IN UpnpClient_Handle Hnd,
IN const char *EvtUrl_const, IN const char *EvtUrl_const,
INOUT int *TimeOut, INOUT int *TimeOut,
OUT Upnp_SID SubsId ) OUT Upnp_SID SubsId)
{ {
struct Handle_Info *SInfo = NULL; int retVal;
int RetVal; struct Handle_Info *SInfo = NULL;
char *EvtUrl = ( char * )EvtUrl_const; UpnpString *EvtUrl = UpnpString_new();
UpnpString *SubsIdTmp = UpnpString_new();
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpSubscribe\n");
if( UpnpSdkInit != 1 ) { if (UpnpSdkInit != 1) {
return UPNP_E_FINISH; retVal = UPNP_E_FINISH;
} goto exit_function;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, if (EvtUrl == NULL) {
"Inside UpnpSubscribe \n" ); retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
if (EvtUrl_const == NULL) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
UpnpString_set_String(EvtUrl, EvtUrl_const);
HandleReadLock(); if (SubsIdTmp == NULL) {
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { retVal = UPNP_E_OUTOF_MEMORY;
HandleUnlock(); goto exit_function;
return UPNP_E_INVALID_HANDLE; }
} if (SubsId == NULL) {
if( EvtUrl == NULL ) { retVal = UPNP_E_INVALID_PARAM;
HandleUnlock(); goto exit_function;
return UPNP_E_INVALID_PARAM; }
} UpnpString_set_String(SubsIdTmp, SubsId);
if( TimeOut == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
if( SubsId == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
HandleUnlock();
RetVal = genaSubscribe( Hnd, EvtUrl, TimeOut, SubsId );
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, if (TimeOut == NULL) {
"Exiting UpnpSubscribe \n" ); retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
return RetVal; HandleReadLock();
if (GetHandleInfo(Hnd, &SInfo) != HND_CLIENT) {
HandleUnlock();
retVal = UPNP_E_INVALID_HANDLE;
goto exit_function;
}
HandleUnlock();
retVal = genaSubscribe(Hnd, EvtUrl, TimeOut, SubsIdTmp);
strcpy(SubsId, UpnpString_get_String(SubsIdTmp));
exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpSubscribe, retVal=%d\n", retVal);
UpnpString_delete(SubsIdTmp);
UpnpString_delete(EvtUrl);
return retVal;
}
#endif /* INCLUDE_CLIENT_APIS */
} /****************** End of UpnpSubscribe *********************/
#endif // INCLUDE_CLIENT_APIS
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
@ -1872,7 +1893,7 @@ UpnpSubscribe( IN UpnpClient_Handle Hnd,
* *
* Parameters: * Parameters:
* IN UpnpClient_Handle Hnd: The handle of the control point. * IN UpnpClient_Handle Hnd: The handle of the control point.
* IN Upnp_SID SubsId: The ID returned when the control point * IN const Upnp_SID SubsId: The ID returned when the control point
* subscribed to the service. * subscribed to the service.
* *
* Description: * Description:
@ -1883,39 +1904,49 @@ UpnpSubscribe( IN UpnpClient_Handle Hnd,
* Return Values: int * Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error. * UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/ ***************************************************************************/
int int UpnpUnSubscribe(IN UpnpClient_Handle Hnd, IN const Upnp_SID SubsId)
UpnpUnSubscribe( IN UpnpClient_Handle Hnd,
IN Upnp_SID SubsId )
{ {
struct Handle_Info *SInfo = NULL; struct Handle_Info *SInfo = NULL;
int RetVal; int retVal;
UpnpString *SubsIdTmp = UpnpString_new();
if( UpnpSdkInit != 1 ) { UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpUnSubscribe\n");
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, if (UpnpSdkInit != 1) {
"Inside UpnpUnSubscribe \n" ); retVal = UPNP_E_FINISH;
goto exit_function;
}
HandleReadLock(); if (SubsIdTmp == NULL) {
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { retVal = UPNP_E_OUTOF_MEMORY;
HandleUnlock(); goto exit_function;
return UPNP_E_INVALID_HANDLE; }
} if (SubsId == NULL) {
if( SubsId == NULL ) { HandleUnlock();
HandleUnlock(); return UPNP_E_INVALID_PARAM;
return UPNP_E_INVALID_PARAM; }
} UpnpString_set_String(SubsIdTmp, SubsId);
HandleUnlock();
RetVal = genaUnSubscribe( Hnd, SubsId );
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, HandleReadLock();
"Exiting UpnpUnSubscribe \n" ); if (GetHandleInfo(Hnd, &SInfo) != HND_CLIENT) {
HandleUnlock();
retVal = UPNP_E_INVALID_HANDLE;
goto exit_function;
}
HandleUnlock();
return RetVal; retVal = genaUnSubscribe(Hnd, SubsIdTmp);
exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpUnSubscribe, retVal=%d\n", retVal);
UpnpString_delete(SubsIdTmp);
return retVal;
}
#endif /* INCLUDE_CLIENT_APIS */
} /****************** End of UpnpUnSubscribe *********************/
#endif // INCLUDE_CLIENT_APIS
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
@ -1939,61 +1970,64 @@ UpnpUnSubscribe( IN UpnpClient_Handle Hnd,
* Return Values: int * Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error. * UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/ ***************************************************************************/
int int UpnpUnSubscribeAsync(
UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd, IN UpnpClient_Handle Hnd,
IN Upnp_SID SubsId, IN Upnp_SID SubsId,
IN Upnp_FunPtr Fun, IN Upnp_FunPtr Fun,
IN const void *Cookie_const ) IN const void *Cookie_const )
{ {
ThreadPoolJob job; int retVal;
struct Handle_Info *SInfo = NULL; ThreadPoolJob job;
struct UpnpNonblockParam *Param; struct Handle_Info *SInfo = NULL;
struct UpnpNonblockParam *Param;
if( UpnpSdkInit != 1 ) { UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpUnSubscribeAsync\n");
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, if (UpnpSdkInit != 1) {
"Inside UpnpUnSubscribeAsync \n" ); retVal = UPNP_E_FINISH;
goto exit_function;
}
HandleReadLock(); if (SubsId == NULL) {
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { retVal = UPNP_E_INVALID_PARAM;
HandleUnlock(); goto exit_function;
return UPNP_E_INVALID_HANDLE; }
} if (Fun == NULL) {
if( SubsId == NULL ) { retVal = UPNP_E_INVALID_PARAM;
HandleUnlock(); goto exit_function;
return UPNP_E_INVALID_PARAM; }
}
if( Fun == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
HandleUnlock(); HandleReadLock();
Param = if (GetHandleInfo(Hnd, &SInfo) != HND_CLIENT) {
( struct UpnpNonblockParam * ) HandleUnlock();
malloc( sizeof( struct UpnpNonblockParam ) ); retVal = UPNP_E_INVALID_HANDLE;
if( Param == NULL ) goto exit_function;
return UPNP_E_OUTOF_MEMORY; }
HandleUnlock();
Param->FunName = UNSUBSCRIBE; Param = (struct UpnpNonblockParam *)malloc(sizeof(struct UpnpNonblockParam));
Param->Handle = Hnd; if (Param == NULL) {
strcpy( Param->SubsId, SubsId ); retVal = UPNP_E_OUTOF_MEMORY;
Param->Fun = Fun; goto exit_function;
Param->Cookie = ( void * )Cookie_const; }
TPJobInit( &job, ( start_routine ) UpnpThreadDistribution, Param );
TPJobSetFreeFunction( &job, ( free_routine ) free );
TPJobSetPriority( &job, MED_PRIORITY );
ThreadPoolAdd( &gSendThreadPool, &job, NULL );
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, Param->FunName = UNSUBSCRIBE;
"Exiting UpnpUnSubscribeAsync \n" ); Param->Handle = Hnd;
strcpy( Param->SubsId, SubsId );
Param->Fun = Fun;
Param->Cookie = (void *)Cookie_const;
TPJobInit( &job, ( start_routine ) UpnpThreadDistribution, Param );
TPJobSetFreeFunction( &job, ( free_routine ) free );
TPJobSetPriority( &job, MED_PRIORITY );
ThreadPoolAdd( &gSendThreadPool, &job, NULL );
return UPNP_E_SUCCESS; exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Exiting UpnpUnSubscribeAsync\n");
return UPNP_E_SUCCESS;
}
#endif /* INCLUDE_CLIENT_APIS */
} /****************** End of UpnpUnSubscribeAsync *********************/
#endif // INCLUDE_CLIENT_APIS
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
@ -2006,7 +2040,7 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd,
* INOUT int *TimeOut: Pointer to a variable containing the * INOUT int *TimeOut: Pointer to a variable containing the
* requested subscription time. Upon return, * requested subscription time. Upon return,
* it contains the actual renewal time. * it contains the actual renewal time.
* IN Upnp_SID SubsId: The ID for the subscription to renew. * IN const Upnp_SID SubsId: The ID for the subscription to renew.
* *
* Description: * Description:
* This function renews a subscription that is about to * This function renews a subscription that is about to
@ -2015,44 +2049,56 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd,
* Return Values: int * Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error. * UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/ ***************************************************************************/
int int UpnpRenewSubscription(
UpnpRenewSubscription( IN UpnpClient_Handle Hnd, IN UpnpClient_Handle Hnd,
INOUT int *TimeOut, INOUT int *TimeOut,
IN Upnp_SID SubsId ) IN const Upnp_SID SubsId )
{ {
struct Handle_Info *SInfo = NULL; struct Handle_Info *SInfo = NULL;
int RetVal; int retVal;
UpnpString *SubsIdTmp = UpnpString_new();
if( UpnpSdkInit != 1 ) { UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpRenewSubscription\n");
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, if (UpnpSdkInit != 1) {
"Inside UpnpRenewSubscription \n" ); return UPNP_E_FINISH;
}
HandleReadLock(); if (SubsIdTmp == NULL) {
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) { retVal = UPNP_E_OUTOF_MEMORY;
HandleUnlock(); goto exit_function;
return UPNP_E_INVALID_HANDLE; }
} if (SubsId == NULL) {
if( TimeOut == NULL ) { retVal = UPNP_E_INVALID_PARAM;
HandleUnlock(); goto exit_function;
return UPNP_E_INVALID_PARAM; }
} UpnpString_set_String(SubsIdTmp, SubsId);
if( SubsId == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
HandleUnlock();
RetVal = genaRenewSubscription( Hnd, SubsId, TimeOut );
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, if (TimeOut == NULL) {
"Exiting UpnpRenewSubscription \n" ); retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
return RetVal; HandleReadLock();
if (GetHandleInfo(Hnd, &SInfo) != HND_CLIENT) {
HandleUnlock();
retVal = UPNP_E_INVALID_HANDLE;
goto exit_function;
}
HandleUnlock();
retVal = genaRenewSubscription(Hnd, SubsIdTmp, TimeOut);
exit_function:
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpRenewSubscription, retVal=%d\n", retVal);
UpnpString_delete(SubsIdTmp);
return retVal;
}
#endif /* INCLUDE_CLIENT_APIS */
} /****************** End of UpnpRenewSubscription *********************/
#endif // INCLUDE_CLIENT_APIS
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
@ -3344,79 +3390,88 @@ UpnpDownloadXmlDoc( const char *url,
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
void void
UpnpThreadDistribution( struct UpnpNonblockParam *Param ) UpnpThreadDistribution(struct UpnpNonblockParam *Param)
{ {
int errCode = 0;
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpThreadDistribution \n" ); "Inside UpnpThreadDistribution \n" );
switch ( Param->FunName ) { switch ( Param->FunName ) {
#if EXCLUDE_GENA == 0 #if EXCLUDE_GENA == 0
case SUBSCRIBE: { case SUBSCRIBE: {
struct Upnp_Event_Subscribe Evt; EventSubscribe *evt = UpnpEventSubscribe_new();
Evt.ErrCode = genaSubscribe( // cast away constness
Param->Handle, Param->Url, UpnpString *sid = (UpnpString *)UpnpEventSubscribe_get_SID(evt);
( int * )&( Param->TimeOut ), UpnpEventSubscribe_strcpy_PublisherUrl(evt, Param->Url);
( char * )Evt.Sid ); errCode = genaSubscribe(
strcpy( Evt.PublisherUrl, Param->Url ); Param->Handle,
Evt.TimeOut = Param->TimeOut; UpnpEventSubscribe_get_PublisherUrl(evt),
Param->Fun( UPNP_EVENT_SUBSCRIBE_COMPLETE, &Evt, Param->Cookie ); (int *)&(Param->TimeOut),
free( Param ); sid);
break; UpnpEventSubscribe_set_ErrCode(evt, errCode);
UpnpEventSubscribe_set_TimeOut(evt, Param->TimeOut);
Param->Fun(UPNP_EVENT_SUBSCRIBE_COMPLETE, evt, Param->Cookie);
UpnpEventSubscribe_delete(evt);
free(Param);
break;
} }
case UNSUBSCRIBE: { case UNSUBSCRIBE: {
struct Upnp_Event_Subscribe Evt; EventSubscribe *evt = UpnpEventSubscribe_new();
Evt.ErrCode = UpnpEventSubscribe_strcpy_SID(evt, Param->SubsId);
genaUnSubscribe( Param->Handle, errCode = genaUnSubscribe(
Param->SubsId ); Param->Handle,
strcpy( ( char * )Evt.Sid, Param->SubsId ); UpnpEventSubscribe_get_SID(evt));
strcpy( Evt.PublisherUrl, "" ); UpnpEventSubscribe_set_ErrCode(evt, errCode);
Evt.TimeOut = 0; UpnpEventSubscribe_strcpy_PublisherUrl(evt, "");
Param->Fun( UPNP_EVENT_UNSUBSCRIBE_COMPLETE, UpnpEventSubscribe_set_TimeOut(evt, 0);
&Evt, Param->Cookie ); Param->Fun(UPNP_EVENT_UNSUBSCRIBE_COMPLETE, evt, Param->Cookie);
free( Param ); UpnpEventSubscribe_delete(evt);
break; free(Param);
break;
} }
case RENEW: { case RENEW: {
struct Upnp_Event_Subscribe Evt; EventSubscribe *evt = UpnpEventSubscribe_new();
Evt.ErrCode = UpnpEventSubscribe_strcpy_SID(evt, Param->SubsId);
genaRenewSubscription( Param->Handle, errCode = genaRenewSubscription(
Param->SubsId, Param->Handle,
&( Param->TimeOut ) ); UpnpEventSubscribe_get_SID(evt),
Evt.TimeOut = Param->TimeOut; &(Param->TimeOut));
strcpy( ( char * )Evt.Sid, Param->SubsId ); UpnpEventSubscribe_set_ErrCode(evt, errCode);
Param->Fun( UPNP_EVENT_RENEWAL_COMPLETE, &Evt, UpnpEventSubscribe_set_TimeOut(evt, Param->TimeOut);
Param->Cookie ); Param->Fun(UPNP_EVENT_RENEWAL_COMPLETE, evt, Param->Cookie);
free( Param ); UpnpEventSubscribe_delete(evt);
break; free(Param);
break;
} }
#endif // EXCLUDE_GENA == 0 #endif // EXCLUDE_GENA == 0
#if EXCLUDE_SOAP == 0 #if EXCLUDE_SOAP == 0
case ACTION: { case ACTION: {
struct Upnp_Action_Complete Evt; UpnpActionComplete *Evt = UpnpActionComplete_new();
Evt.ActionResult = NULL; IXML_Document *actionResult = NULL;
Evt.ErrCode = int errCode = SoapSendAction(
SoapSendAction( Param->Url, Param->ServiceType, Param->Url, Param->ServiceType, Param->Act, &actionResult );
Param->Act, &Evt.ActionResult ); UpnpActionComplete_set_ErrCode(Evt, errCode);
Evt.ActionRequest = Param->Act; UpnpActionComplete_set_ActionRequest(Evt, Param->Act);
strcpy( Evt.CtrlUrl, Param->Url ); UpnpActionComplete_set_ActionResult(Evt, actionResult);
Param->Fun( UPNP_CONTROL_ACTION_COMPLETE, &Evt, UpnpActionComplete_strcpy_CtrlUrl(Evt, Param->Url );
Param->Cookie ); Param->Fun( UPNP_CONTROL_ACTION_COMPLETE, Evt, Param->Cookie );
ixmlDocument_free( Evt.ActionRequest ); free(Param);
ixmlDocument_free( Evt.ActionResult ); UpnpActionComplete_delete(Evt);
free( Param ); break;
break;
} }
case STATUS: { case STATUS: {
struct Upnp_State_Var_Complete Evt; UpnpStateVarComplete *Evt = UpnpStateVarComplete_new();
Evt.ErrCode = SoapGetServiceVarStatus( DOMString currentVal = NULL;
Param->Url, Param->VarName, &( Evt.CurrentVal ) ); int errCode = SoapGetServiceVarStatus(
strcpy( Evt.StateVarName, Param->VarName ); Param->Url, Param->VarName, &currentVal );
strcpy( Evt.CtrlUrl, Param->Url ); UpnpStateVarComplete_set_ErrCode(Evt, errCode);
Param->Fun( UPNP_CONTROL_GET_VAR_COMPLETE, &Evt, UpnpStateVarComplete_strcpy_CtrlUrl(Evt, Param->Url);
Param->Cookie ); UpnpStateVarComplete_strcpy_StateVarName(Evt, Param->VarName);
free( Evt.CurrentVal ); UpnpStateVarComplete_set_CurrentVal(Evt, currentVal);
Param->Fun( UPNP_CONTROL_GET_VAR_COMPLETE, Evt, Param->Cookie );
free( Param ); free( Param );
UpnpStateVarComplete_delete(Evt);
break; break;
} }
#endif // EXCLUDE_SOAP == 0 #endif // EXCLUDE_SOAP == 0
@ -3441,64 +3496,59 @@ UpnpThreadDistribution( struct UpnpNonblockParam *Param )
* Return Values: Upnp_FunPtr * Return Values: Upnp_FunPtr
* *
***************************************************************************/ ***************************************************************************/
Upnp_FunPtr Upnp_FunPtr GetCallBackFn(UpnpClient_Handle Hnd)
GetCallBackFn( UpnpClient_Handle Hnd )
{ {
return ( ( struct Handle_Info * )HandleTable[Hnd] )->Callback; return ((struct Handle_Info *)HandleTable[Hnd])->Callback;
}
} /****************** End of GetCallBackFn *********************/
/************************************************************************** /**************************************************************************
* Function: InitHandleList * Function: InitHandleList
* *
* Parameters: VOID * Parameters:
* *
* Description: * Description:
* This function is to initialize handle table * This function is to initialize handle table
* *
* Return Values: VOID * Return Values:
* *
***************************************************************************/ ***************************************************************************/
void void InitHandleList()
InitHandleList()
{ {
int i; int i;
for( i = 0; i < NUM_HANDLE; i++ ) for (i = 0; i < NUM_HANDLE; ++i) {
HandleTable[i] = NULL; HandleTable[i] = NULL;
}
} /****************** End of InitHandleList *********************/ }
/************************************************************************** /**************************************************************************
* Function: GetFreeHandle * Function: GetFreeHandle
* *
* Parameters: VOID * Parameters:
* *
* Description: * Description:
* This function is to get a free handle * This function is to get a free handle
* *
* Return Values: VOID * Return Values:
* integer greater than zero
* UPNP_E_OUTOF_HANDLE
* *
***************************************************************************/ ***************************************************************************/
int int GetFreeHandle()
GetFreeHandle()
{ {
int i = 1; /* Handle 0 is not used as NULL translates to 0 when passed as a handle */
int i = 1;
/* while (i < NUM_HANDLE && HandleTable[i] != NULL) {
Handle 0 is not used as NULL translates to 0 when passed as a handle ++i;
*/ }
while( i < NUM_HANDLE ) {
if( HandleTable[i++] == NULL )
break;
}
if( i == NUM_HANDLE ) if (i == NUM_HANDLE) {
return UPNP_E_OUTOF_HANDLE; //Error return UPNP_E_OUTOF_HANDLE;
else } else {
return --i; return i;
}
} /****************** End of GetFreeHandle *********************/ }
/************************************************************************** /**************************************************************************
* Function: GetClientHandleInfo * Function: GetClientHandleInfo
@ -3512,58 +3562,64 @@ GetFreeHandle()
* Description: * Description:
* This function is to get client handle info * This function is to get client handle info
* *
* Return Values: HND_CLIENT * Return Values: HND_CLIENT, HND_INVALID
* *
***************************************************************************/ ***************************************************************************/
//Assumes at most one client //Assumes at most one client
Upnp_Handle_Type Upnp_Handle_Type GetClientHandleInfo(
GetClientHandleInfo( IN UpnpClient_Handle * client_handle_out, IN UpnpClient_Handle *client_handle_out,
OUT struct Handle_Info ** HndInfo ) OUT struct Handle_Info **HndInfo)
{ {
( *client_handle_out ) = 1; Upnp_Handle_Type ret = HND_CLIENT;
if( GetHandleInfo( 1, HndInfo ) == HND_CLIENT ) { UpnpClient_Handle client;
return HND_CLIENT;
}
( *client_handle_out ) = 2;
if( GetHandleInfo( 2, HndInfo ) == HND_CLIENT ) {
return HND_CLIENT;
}
( *client_handle_out ) = -1;
return HND_INVALID;
} /****************** End of GetClientHandleInfo *********************/ if (GetHandleInfo(1, HndInfo) == HND_CLIENT) {
client = 1;
} else if (GetHandleInfo(2, HndInfo) == HND_CLIENT) {
client = 2;
} else {
client = -1;
ret = HND_INVALID;
}
*client_handle_out = client;
return ret;
}
/************************************************************************** /**************************************************************************
* Function: GetDeviceHandleInfo * Function: GetDeviceHandleInfo
* *
* Parameters: * Parameters:
* IN UpnpDevice_Handle * device_handle_out: device handle pointer * IN UpnpDevice_Handle *device_handle_out:
* (key for the client handle structure). * device handle pointer (key for the client handle structure).
* OUT struct Handle_Info **HndInfo: Device handle structure passed by * OUT struct Handle_Info **HndInfo:
* this function. * Device handle structure passed by this function.
* *
* Description: * Description:
* This function is to get device handle info. * This function is to get device handle info.
* *
* Return Values: HND_DEVICE * Return Values: HND_DEVICE, HND_INVALID
* *
***************************************************************************/ ***************************************************************************/
Upnp_Handle_Type Upnp_Handle_Type GetDeviceHandleInfo(
GetDeviceHandleInfo( UpnpDevice_Handle * device_handle_out, UpnpDevice_Handle *device_handle_out,
struct Handle_Info ** HndInfo ) struct Handle_Info **HndInfo)
{ {
( *device_handle_out ) = 1; Upnp_Handle_Type ret = HND_DEVICE;
if( GetHandleInfo( 1, HndInfo ) == HND_DEVICE ) UpnpDevice_Handle device;
return HND_DEVICE;
( *device_handle_out ) = 2; if (GetHandleInfo(1, HndInfo) == HND_DEVICE) {
if( GetHandleInfo( 2, HndInfo ) == HND_DEVICE ) device = 1;
return HND_DEVICE; } else if (GetHandleInfo(2, HndInfo) == HND_DEVICE) {
( *device_handle_out ) = -1; device = 2;
} else {
device = -1;
ret = HND_INVALID;
}
return HND_INVALID; *device_handle_out = device;
return ret;
} /****************** End of GetDeviceHandleInfo *********************/ }
/************************************************************************** /**************************************************************************
* Function: GetDeviceHandleInfo * Function: GetDeviceHandleInfo
@ -3577,32 +3633,34 @@ GetDeviceHandleInfo( UpnpDevice_Handle * device_handle_out,
* Description: * Description:
* This function is to get handle info. * This function is to get handle info.
* *
* Return Values: HND_DEVICE * Return Values: HND_DEVICE, UPNP_E_INVALID_HANDLE
* *
***************************************************************************/ ***************************************************************************/
Upnp_Handle_Type Upnp_Handle_Type GetHandleInfo(
GetHandleInfo( UpnpClient_Handle Hnd, UpnpClient_Handle Hnd,
struct Handle_Info ** HndInfo ) struct Handle_Info **HndInfo)
{ {
Upnp_Handle_Type ret = UPNP_E_INVALID_HANDLE;
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"GetHandleInfo: Handle is %d\n", Hnd ); "GetHandleInfo: entering, Handle is %d\n", Hnd);
if( Hnd < 1 || Hnd >= NUM_HANDLE ) { if (Hnd < 1 || Hnd >= NUM_HANDLE) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"GetHandleInfo : Handle out of range\n" ); "GetHandleInfo: Handle out of range\n");
return UPNP_E_INVALID_HANDLE; } else if (HandleTable[Hnd] == NULL) {
} UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
if( HandleTable[Hnd] != NULL ) { "GetHandleInfo: HandleTable[%d] is NULL\n",
*HndInfo = ( struct Handle_Info * )HandleTable[Hnd]; Hnd);
return ( ( struct Handle_Info * )*HndInfo )->HType; } else if (HandleTable[Hnd] != NULL) {
} *HndInfo = (struct Handle_Info *)HandleTable[Hnd];
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, ret = ((struct Handle_Info *)*HndInfo)->HType;
"GetHandleInfo : exiting\n" ); }
return UPNP_E_INVALID_HANDLE; UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "GetHandleInfo: exiting\n");
} /****************** End of GetHandleInfo *********************/ return ret;
}
/************************************************************************** /**************************************************************************
* Function: FreeHandle * Function: FreeHandle
@ -3614,25 +3672,34 @@ GetHandleInfo( UpnpClient_Handle Hnd,
* This function is to to free handle info. * This function is to to free handle info.
* *
* Return Values: int * Return Values: int
* UPNP_E_SUCCESS if successful else return appropriate error * UPNP_E_SUCCESS if successful
* UPNP_E_INVALID_HANDLE if not.
***************************************************************************/ ***************************************************************************/
int int FreeHandle(int Upnp_Handle)
FreeHandle( int Upnp_Handle )
{ {
if( Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE ) { int ret = UPNP_E_INVALID_HANDLE;
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
"FreeHandleInfo : Handle out of range\n" );
return UPNP_E_INVALID_HANDLE;
}
if( HandleTable[Upnp_Handle] == NULL ) { UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
return UPNP_E_INVALID_HANDLE; "FreeHandleInfo: entering, Handle is %d\n", Upnp_Handle);
}
free( HandleTable[Upnp_Handle] );
HandleTable[Upnp_Handle] = NULL;
return UPNP_E_SUCCESS;
} /****************** End of FreeHandle *********************/ if (Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE) {
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"FreeHandleInfo: Handle %d is out of range\n",
Upnp_Handle);
} else if (HandleTable[Upnp_Handle] == NULL) {
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"FreeHandleInfo: HandleTable[%d] is NULL\n",
Upnp_Handle);
} else {
free( HandleTable[Upnp_Handle] );
HandleTable[Upnp_Handle] = NULL;
ret = UPNP_E_SUCCESS;
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "FreeHandleInfo: exiting\n");
return ret;
}
/************************************************************************** /**************************************************************************
@ -3668,7 +3735,6 @@ int PrintHandleInfo( IN UpnpClient_Handle Hnd )
return UPNP_E_SUCCESS; return UPNP_E_SUCCESS;
} }
/****************** End of PrintHandleInfo *********************/
void printNodes( IXML_Node * tmpRoot, int depth ) void printNodes( IXML_Node * tmpRoot, int depth )
{ {

File diff suppressed because it is too large Load Diff

View File

@ -30,180 +30,281 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
/************************************************************************ /************************************************************************
* Purpose: This file defines the functions for clients. It defines * Purpose: This file defines the functions for clients. It defines
* functions for adding and removing clients to and from the client table, * functions for adding and removing clients to and from the client table,
* adding and accessing subscription and other attributes pertaining to the * adding and accessing subscription and other attributes pertaining to the
* client * client
************************************************************************/ ************************************************************************/
#include "config.h" #include "config.h"
#include "client_table.h" #include "client_table.h"
/************************************************************************
* Function : copy_client_subscription
*
* Parameters :
* client_subscription * in ; - source client subscription
* client_subscription * out ; - destination client subscription
*
* Description : Make a copy of the client subscription data
*
* Return : int ;
* UPNP_E_OUTOF_MEMORY - On Failure to allocate memory
* HTTP_SUCCESS - On Success
*
* Note :
************************************************************************/
CLIENTONLY( int copy_client_subscription( client_subscription * in,
client_subscription * out ) {
int len = strlen( in->ActualSID ) + 1;
int len1 = strlen( in->EventURL ) + 1;
memcpy( out->sid, in->sid, SID_SIZE );
out->sid[SID_SIZE] = 0;
out->ActualSID = ( char * )malloc( len );
if( out->ActualSID == NULL )
return UPNP_E_OUTOF_MEMORY;
out->EventURL = ( char * )malloc( len1 );
if( out->EventURL == NULL ) {
free(out->ActualSID);
return UPNP_E_OUTOF_MEMORY;
}
memcpy( out->ActualSID, in->ActualSID, len );
memcpy( out->EventURL, in->EventURL, len1 );
//copies do not get RenewEvent Ids or next
out->RenewEventId = -1; out->next = NULL; return HTTP_SUCCESS;}
/************************************************************************ #ifdef INCLUDE_CLIENT_APIS
* Function : free_client_subscription
*
* Parameters :
* client_subscription * sub ; - Client subscription to be freed
*
* Description : Free memory allocated for client subscription data.
* Remove timer thread associated with this subscription event.
*
* Return : void ;
*
* Note :
************************************************************************/
void free_client_subscription( client_subscription * sub ) {
upnp_timeout * event; ThreadPoolJob tempJob; if( sub ) {
if( sub->ActualSID )
free( sub->ActualSID ); if( sub->EventURL )
free( sub->EventURL ); if( sub->RenewEventId != -1 ) //do not remove timer event of copy
//invalid timer event id
{
if( TimerThreadRemove
( &gTimerThread, sub->RenewEventId, &tempJob ) == 0 ) {
event = ( upnp_timeout * ) tempJob.arg;
free_upnp_timeout( event );}
}
sub->RenewEventId = -1;}
}
/************************************************************************ #include <stdlib.h> // for calloc(), free()
* Function : freeClientSubList
*
* Parameters :
* client_subscription * list ; Client subscription
*
* Description : Free the client subscription table.
*
* Return : void ;
*
* Note :
************************************************************************/
void freeClientSubList( client_subscription * list ) {
client_subscription * next; while( list ) {
free_client_subscription( list );
next = list->next; free( list ); list = next;}
}
/************************************************************************
* Function : RemoveClientSubClientSID
*
* Parameters :
* client_subscription **head ; Head of the subscription list
* const Upnp_SID sid ; Subscription ID to be mactched
*
* Description : Remove the client subscription matching the
* subscritpion id represented by the const Upnp_SID sid parameter
* from the table and update the table.
*
* Return : void ;
*
* Note :
************************************************************************/
void RemoveClientSubClientSID( client_subscription ** head,
const Upnp_SID sid ) {
client_subscription * finger = ( *head );
client_subscription * previous = NULL; while( finger ) {
if( !( strcmp( sid, finger->sid ) ) ) {
if( previous )
previous->next = finger->next;
else
( *head ) = finger->next;
finger->next = NULL;
freeClientSubList( finger ); finger = NULL;}
else
{
previous = finger; finger = finger->next;}
}
}
/************************************************************************ struct SClientSubscription {
* Function : GetClientSubClientSID int m_renewEventId;
* UpnpString *m_SID;
* Parameters : UpnpString *m_actualSID;
* client_subscription *head ; Head of the subscription list UpnpString *m_eventURL;
* const Upnp_SID sid ; Subscription ID to be matched struct SClientSubscription *m_next;
* };
* Description : Return the client subscription from the client table
* that matches const Upnp_SID sid subscrition id value.
*
* Return : client_subscription * ; The matching subscription
*
* Note :
************************************************************************/
client_subscription *
GetClientSubClientSID( client_subscription * head,
const Upnp_SID sid ) {
client_subscription * next = head; while( next ) {
if( !strcmp( next->sid, sid ) )
break;
else
{
next = next->next;}
}
return next;}
/************************************************************************
* Function : GetClientSubActualSID
*
* Parameters :
* client_subscription *head ; Head of the subscription list
* token * sid ; Subscription ID to be matched
*
* Description : Returns the client subscription from the client
* subscription table that has the matching token * sid buffer
* value.
*
* Return : client_subscription * ; The matching subscription
*
* Note :
************************************************************************/
client_subscription *
GetClientSubActualSID( client_subscription * head,
token * sid ) {
client_subscription * next = head; while( next ) {
if( !memcmp( next->ActualSID, sid->buff, sid->size ) ) /** Constructor */
break; ClientSubscription *UpnpClientSubscription_new()
else {
{ struct SClientSubscription *p = calloc(1, sizeof (struct SClientSubscription));
next = next->next;} #if 0
} p->renewEventId = 0;
return next;} #endif
p->m_SID = UpnpString_new();
p->m_actualSID = UpnpString_new();
p->m_eventURL = UpnpString_new();
p->m_next = NULL;
return (ClientSubscription *)p;
}
/** Destructor */
void UpnpClientSubscription_delete(ClientSubscription *p)
{
struct SClientSubscription *q = (struct SClientSubscription *)p;
q->m_renewEventId = 0;
UpnpString_delete(q->m_SID);
q->m_SID = NULL;
UpnpString_delete(q->m_actualSID);
q->m_actualSID = NULL;
UpnpString_delete(q->m_eventURL);
q->m_eventURL = NULL;
q->m_next = NULL;
free(p);
}
/** Copy Constructor */
ClientSubscription *UpnpClientSubscription_dup(const ClientSubscription *p)
{
ClientSubscription *q = UpnpClientSubscription_new();
UpnpClientSubscription_assign(q, p);
return q;
}
/** Assignment operator */
void UpnpClientSubscription_assign(ClientSubscription *q, const ClientSubscription *p)
{
if (q != p) {
// Do not copy RenewEventId
((struct SClientSubscription *)q)->m_renewEventId = -1;
UpnpClientSubscription_set_SID(q, UpnpClientSubscription_get_SID(p));
UpnpClientSubscription_set_ActualSID(q, UpnpClientSubscription_get_ActualSID(p));
UpnpClientSubscription_set_EventURL(q, UpnpClientSubscription_get_EventURL(p));
// Do not copy m_next
((struct SClientSubscription *)q)->m_next = NULL;
}
}
int UpnpClientSubscription_get_RenewEventId(const ClientSubscription *p)
{
return ((struct SClientSubscription *)p)->m_renewEventId;
}
void UpnpClientSubscription_set_RenewEventId(ClientSubscription *p, int n)
{
((struct SClientSubscription *)p)->m_renewEventId = n;
}
const UpnpString *UpnpClientSubscription_get_SID(const ClientSubscription *p)
{
return ((struct SClientSubscription *)p)->m_SID;
}
void UpnpClientSubscription_set_SID(ClientSubscription *p, const UpnpString *s)
{
UpnpString_delete(((struct SClientSubscription *)p)->m_SID);
((struct SClientSubscription *)p)->m_SID = UpnpString_dup(s);
}
void UpnpClientSubscription_strcpy_SID(ClientSubscription *p, const char *s)
{
UpnpString_delete(((struct SClientSubscription *)p)->m_SID);
((struct SClientSubscription *)p)->m_SID = UpnpString_new();
UpnpString_set_String(((struct SClientSubscription *)p)->m_SID, s);
}
const UpnpString *UpnpClientSubscription_get_ActualSID(const ClientSubscription *p)
{
return ((struct SClientSubscription *)p)->m_actualSID;
}
void UpnpClientSubscription_set_ActualSID(ClientSubscription *p, const UpnpString *s)
{
UpnpString_delete(((struct SClientSubscription *)p)->m_actualSID);
((struct SClientSubscription *)p)->m_actualSID = UpnpString_dup(s);
}
void UpnpClientSubscription_strcpy_ActualSID(ClientSubscription *p, const char *s)
{
UpnpString_delete(((struct SClientSubscription *)p)->m_actualSID);
((struct SClientSubscription *)p)->m_actualSID = UpnpString_new();
UpnpString_set_String(((struct SClientSubscription *)p)->m_actualSID, s);
}
const UpnpString *UpnpClientSubscription_get_EventURL(const ClientSubscription *p)
{
return ((struct SClientSubscription *)p)->m_eventURL;
}
void UpnpClientSubscription_set_EventURL(ClientSubscription *p, const UpnpString *s)
{
UpnpString_delete(((struct SClientSubscription *)p)->m_eventURL);
((struct SClientSubscription *)p)->m_eventURL = UpnpString_dup(s);
}
void UpnpClientSubscription_strcpy_EventURL(ClientSubscription *p, const char *s)
{
UpnpString_delete(((struct SClientSubscription *)p)->m_eventURL);
((struct SClientSubscription *)p)->m_eventURL = UpnpString_new();
UpnpString_set_String(((struct SClientSubscription *)p)->m_eventURL, s);
}
ClientSubscription *UpnpClientSubscription_get_Next(const ClientSubscription *p)
{
return (ClientSubscription *)(((struct SClientSubscription *)p)->m_next);
}
void UpnpClientSubscription_set_Next(ClientSubscription *p, ClientSubscription *q)
{
((struct SClientSubscription *)p)->m_next = (struct SClientSubscription *)q;
}
void free_client_subscription(ClientSubscription *sub)
{
upnp_timeout *event;
ThreadPoolJob tempJob;
if (sub) {
int renewEventId = UpnpClientSubscription_get_RenewEventId(sub);
UpnpClientSubscription_strcpy_ActualSID(sub, "");
UpnpClientSubscription_strcpy_EventURL(sub, "");
if (renewEventId != -1) {
// do not remove timer event of copy
// invalid timer event id
if (TimerThreadRemove(&gTimerThread, renewEventId, &tempJob) == 0) {
event = (upnp_timeout *)tempJob.arg;
free_upnp_timeout(event);
}
}
UpnpClientSubscription_set_RenewEventId(sub, -1);
}
}
void freeClientSubList(ClientSubscription *list)
{
ClientSubscription *next;
while (list) {
free_client_subscription(list);
next = UpnpClientSubscription_get_Next(list);
UpnpClientSubscription_delete(list);
list = next;
}
}
void RemoveClientSubClientSID(ClientSubscription **head, const UpnpString *sid)
{
ClientSubscription *finger = *head;
ClientSubscription *previous = NULL;
int found = 0;
while (finger) {
found = !strcmp(
UpnpString_get_String(sid),
UpnpString_get_String(UpnpClientSubscription_get_SID(finger)));
if (found) {
if (previous) {
UpnpClientSubscription_set_Next(previous,
UpnpClientSubscription_get_Next(finger));
} else {
*head = UpnpClientSubscription_get_Next(finger);
}
UpnpClientSubscription_set_Next(finger, NULL);
freeClientSubList(finger);
finger = NULL;
} else {
previous = finger;
finger = UpnpClientSubscription_get_Next(finger);
}
}
}
ClientSubscription *GetClientSubClientSID(ClientSubscription *head, const UpnpString *sid)
{
ClientSubscription *next = head;
int found = 0;
while (next) {
found = !strcmp(
UpnpString_get_String(UpnpClientSubscription_get_SID(next)),
UpnpString_get_String(sid));
if(found) {
break;
} else {
next = UpnpClientSubscription_get_Next(next);
}
}
return next;
}
ClientSubscription *GetClientSubActualSID(ClientSubscription *head, token *sid)
{
ClientSubscription *next = head;
while (next) {
if (!memcmp(
UpnpString_get_String(UpnpClientSubscription_get_ActualSID(next)),
sid->buff, sid->size)) {
break;
} else {
next = UpnpClientSubscription_get_Next(next);
}
}
return next;
}
#endif /* INCLUDE_CLIENT_APIS */
)

View File

@ -126,9 +126,9 @@ http_FixUrl( IN uri_type * url,
* Function: http_FixStrUrl * Function: http_FixStrUrl
* *
* Parameters: * Parameters:
* IN char* urlstr ; Character string as a URL * IN const char* urlstr; Character string as a URL
* IN int urlstrlen ; Length of the character string * IN int urlstrlen; Length of the character string
* OUT uri_type* fixed_url ; Fixed and corrected URL * OUT uri_type* fixed_url; Fixed and corrected URL
* *
* Description: * Description:
* Parses URL and then validates URL * Parses URL and then validates URL
@ -138,7 +138,7 @@ http_FixUrl( IN uri_type * url,
* UPNP_E_SUCCESS * UPNP_E_SUCCESS
************************************************************************/ ************************************************************************/
int int
http_FixStrUrl( IN char *urlstr, http_FixStrUrl( IN const char *urlstr,
IN int urlstrlen, IN int urlstrlen,
OUT uri_type * fixed_url ) OUT uri_type * fixed_url )
{ {

View File

@ -35,22 +35,30 @@
******************************************************************************/ ******************************************************************************/
#include "config.h" #include "config.h"
#include "webserver.h"
#include <assert.h> #include <assert.h>
#include <fcntl.h> #include <fcntl.h>
#ifndef UPNP_USE_BCBPP #ifndef UPNP_USE_BCBPP
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h> #include <stdint.h>
#endif #endif /* !UPNP_USE_BCBPP */
#include "util.h"
#include "strintmap.h"
#include "membuffer.h" #include "FileInfo.h"
#include "httpparser.h" #include "httpparser.h"
#include "httpreadwrite.h" #include "httpreadwrite.h"
#include "membuffer.h"
#include "ssdplib.h"
#include "statcodes.h" #include "statcodes.h"
#include "webserver.h" #include "strintmap.h"
#include "upnp.h" #include "upnp.h"
#include "upnpapi.h" #include "upnpapi.h"
#include "ssdplib.h" #include "util.h"
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> #include <unistd.h>
@ -279,38 +287,39 @@ search_extension( IN const char *extension,
* *
* Parameters: * Parameters:
* IN const char* filename, * IN const char* filename,
* OUT DOMString* content_type * OUT UpnpFileInfo *fileInfo
* *
* Description: Based on the extension, clones an XML string based on * Description: Based on the extension, sets the content type of fileInfo
* type and content subtype. If content type and sub type are not * based on type and content subtype. If content type and sub type
* found, unknown types are used * are not found, unknown types are used
* *
* Returns: * Returns:
* 0 - On Sucess * 0 - On Sucess
* UPNP_E_OUTOF_MEMORY - on memory allocation failures * UPNP_E_OUTOF_MEMORY - on memory allocation failures
************************************************************************/ ************************************************************************/
UPNP_INLINE int UPNP_INLINE int
get_content_type( IN const char *filename, get_content_type(
OUT DOMString * content_type ) IN const char *filename,
OUT UpnpFileInfo *fileInfo)
{ {
const char *extension; const char *extension;
const char *type, const char *type;
*subtype; const char *subtype;
xboolean ctype_found = FALSE; xboolean ctype_found = FALSE;
char *temp = NULL; char *temp = NULL;
int length = 0; int length = 0;
( *content_type ) = NULL; UpnpFileInfo_set_ContentType(fileInfo, NULL);
// get ext // get ext
extension = strrchr( filename, '.' ); extension = strrchr( filename, '.' );
if( extension != NULL ) { if (extension != NULL) {
if( search_extension( extension + 1, &type, &subtype ) == 0 ) { if( search_extension( extension + 1, &type, &subtype ) == 0 ) {
ctype_found = TRUE; ctype_found = TRUE;
} }
} }
if( !ctype_found ) { if (!ctype_found) {
// unknown content type // unknown content type
type = gMediaTypes[APPLICATION_INDEX]; type = gMediaTypes[APPLICATION_INDEX];
subtype = "octet-stream"; subtype = "octet-stream";
@ -318,17 +327,14 @@ get_content_type( IN const char *filename,
length = strlen( type ) + strlen( "/" ) + strlen( subtype ) + 1; length = strlen( type ) + strlen( "/" ) + strlen( subtype ) + 1;
temp = ( char * )malloc( length ); temp = ( char * )malloc( length );
if (!temp) {
if( !temp ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
sprintf( temp, "%s/%s", type, subtype ); sprintf( temp, "%s/%s", type, subtype );
( *content_type ) = ixmlCloneDOMString( temp ); UpnpFileInfo_set_ContentType(fileInfo, temp);
free(temp);
free( temp ); if (!UpnpFileInfo_get_ContentType(fileInfo)) {
if( !content_type ) {
return UPNP_E_OUTOF_MEMORY; return UPNP_E_OUTOF_MEMORY;
} }
@ -586,8 +592,8 @@ web_server_destroy( void )
* Function: get_file_info * Function: get_file_info
* *
* Parameters: * Parameters:
* IN const char* filename ; Filename having the description document * IN const char *filename; Filename having the description document
* OUT struct File_Info * info ; File information object having file * OUT UpnpFileInfo *info; File information object having file
* attributes such as filelength, when was the file last * attributes such as filelength, when was the file last
* modified, whether a file or a directory and whether the * modified, whether a file or a directory and whether the
* file or directory is readable. * file or directory is readable.
@ -600,48 +606,50 @@ web_server_destroy( void )
* int * int
************************************************************************/ ************************************************************************/
static int static int
get_file_info( IN const char *filename, get_file_info(
OUT struct File_Info *info ) IN const char *filename,
OUT UpnpFileInfo *info)
{ {
int code; int code;
struct stat s; struct stat s;
FILE *fp; FILE *fp;
int rc = 0; int rc = 0;
info->content_type = NULL; UpnpFileInfo_set_ContentType(info, NULL);
code = stat( filename, &s ); code = stat(filename, &s);
if( code == -1 ) { if (code == -1) {
return -1; return -1;
} }
if( S_ISDIR( s.st_mode ) ) { if (S_ISDIR(s.st_mode)) {
info->is_directory = TRUE; UpnpFileInfo_set_IsDirectory(info, TRUE);
} else if( S_ISREG( s.st_mode ) ) { } else if (S_ISREG(s.st_mode)) {
info->is_directory = FALSE; UpnpFileInfo_set_IsDirectory(info, FALSE);
} else { } else {
return -1; return -1;
} }
// check readable // check readable
fp = fopen( filename, "r" ); fp = fopen(filename, "r");
info->is_readable = ( fp != NULL ); UpnpFileInfo_set_IsReadable(info, fp != NULL);
if( fp ) { if (fp) {
fclose( fp ); fclose(fp);
} }
info->file_length = s.st_size; UpnpFileInfo_set_FileLength(info, s.st_size);
info->last_modified = s.st_mtime; UpnpFileInfo_set_LastModified(info, &s.st_mtime);
rc = get_content_type( filename, &info->content_type ); rc = get_content_type(filename, info);
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
"file info: %s, length: %lld, last_mod=%s readable=%d\n", "file info: %s, length: %lld, last_mod=%s readable=%d\n",
filename, (long long)info->file_length, filename,
asctime( gmtime( &info->last_modified ) ), (long long)UpnpFileInfo_get_FileLength(info),
info->is_readable ); asctime(gmtime(UpnpFileInfo_get_LastModified(info))),
UpnpFileInfo_get_IsReadable(info));
return rc; return rc;
} }
/************************************************************************ /************************************************************************
@ -683,10 +691,10 @@ web_server_set_root_dir( IN const char *root_dir )
* Function: get_alias * Function: get_alias
* *
* Parameters: * Parameters:
* IN const char* request_file ; request file passed in to be compared with * IN const char *request_file; request file passed in to be compared with
* OUT struct xml_alias_t* alias ; xml alias object which has a file name * OUT struct xml_alias_t* alias ; xml alias object which has a file name
* stored * stored
* OUT struct File_Info * info ; File information object which will be * OUT UpnpFileInfo *info; File information object which will be
* filled up if the file comparison succeeds * filled up if the file comparison succeeds
* *
* Description: Compare the files names between the one on the XML alias * Description: Compare the files names between the one on the XML alias
@ -698,22 +706,21 @@ web_server_set_root_dir( IN const char *root_dir )
* FALSE if request is not an alias * FALSE if request is not an alias
************************************************************************/ ************************************************************************/
static UPNP_INLINE xboolean static UPNP_INLINE xboolean
get_alias( IN const char *request_file, get_alias(
OUT struct xml_alias_t *alias, IN const char *request_file,
OUT struct File_Info *info ) OUT struct xml_alias_t *alias,
OUT UpnpFileInfo *info)
{ {
int cmp; int cmp = strcmp(alias->name.buf, request_file);
if (cmp == 0) {
// fill up info
UpnpFileInfo_set_FileLength(info, alias->doc.length);
UpnpFileInfo_set_IsDirectory(info, FALSE);
UpnpFileInfo_set_IsReadable(info, TRUE);
UpnpFileInfo_set_LastModified(info, &alias->last_modified);
}
cmp = strcmp( alias->name.buf, request_file ); return cmp == 0;
if( cmp == 0 ) {
// fill up info
info->file_length = alias->doc.length;
info->is_readable = TRUE;
info->is_directory = FALSE;
info->last_modified = alias->last_modified;
}
return cmp == 0;
} }
/************************************************************************ /************************************************************************
@ -1197,16 +1204,17 @@ process_request( IN http_message_t * req,
int err_code; int err_code;
char *request_doc; char *request_doc;
struct File_Info finfo; UpnpFileInfo *finfo;
xboolean using_alias; xboolean using_alias;
xboolean using_virtual_dir; xboolean using_virtual_dir;
uri_type *url; uri_type *url;
char *temp_str; char *temp_str;
int resp_major, int resp_major;
resp_minor; int resp_minor;
xboolean alias_grabbed; xboolean alias_grabbed;
size_t dummy; size_t dummy;
struct UpnpVirtualDirCallbacks *pVirtualDirCallback; struct UpnpVirtualDirCallbacks *pVirtualDirCallback;
const char *extra_headers;
print_http_headers( req ); print_http_headers( req );
@ -1218,7 +1226,7 @@ process_request( IN http_message_t * req,
// init // init
request_doc = NULL; request_doc = NULL;
finfo.content_type = NULL; finfo = UpnpFileInfo_new();
alias_grabbed = FALSE; alias_grabbed = FALSE;
err_code = HTTP_INTERNAL_SERVER_ERROR; // default error err_code = HTTP_INTERNAL_SERVER_ERROR; // default error
using_virtual_dir = FALSE; using_virtual_dir = FALSE;
@ -1261,50 +1269,46 @@ process_request( IN http_message_t * req,
// //
// try using alias // try using alias
// //
if( is_valid_alias( &gAliasDoc ) ) { if (is_valid_alias(&gAliasDoc)) {
alias_grab( alias ); alias_grab(alias);
alias_grabbed = TRUE; alias_grabbed = TRUE;
using_alias = get_alias(request_doc, alias, finfo);
using_alias = get_alias( request_doc, alias, &finfo ); if (using_alias == TRUE) {
if( using_alias == TRUE ) { UpnpFileInfo_set_ContentType(finfo, "text/xml");
finfo.content_type = ixmlCloneDOMString( "text/xml" ); if (UpnpFileInfo_get_ContentType(finfo) == NULL) {
if( finfo.content_type == NULL ) {
goto error_handler; goto error_handler;
} }
} }
} }
} }
if( using_virtual_dir ) { if (using_virtual_dir) {
if( req->method != HTTPMETHOD_POST ) { if (req->method != HTTPMETHOD_POST) {
// get file info // get file info
pVirtualDirCallback = &virtualDirCallback; pVirtualDirCallback = &virtualDirCallback;
if( pVirtualDirCallback->get_info( filename->buf, &finfo ) != if (pVirtualDirCallback->get_info(filename->buf, finfo) != 0) {
0 ) {
err_code = HTTP_NOT_FOUND; err_code = HTTP_NOT_FOUND;
goto error_handler; goto error_handler;
} }
// try index.html if req is a dir // try index.html if req is a dir
if( finfo.is_directory ) { if (UpnpFileInfo_get_IsDirectory(finfo)) {
if( filename->buf[filename->length - 1] == '/' ) { if (filename->buf[filename->length - 1] == '/') {
temp_str = "index.html"; temp_str = "index.html";
} else { } else {
temp_str = "/index.html"; temp_str = "/index.html";
} }
if( membuffer_append_str( filename, temp_str ) != 0 ) { if ( membuffer_append_str(filename, temp_str) != 0) {
goto error_handler; goto error_handler;
} }
// get info // get info
if( ( pVirtualDirCallback-> if( pVirtualDirCallback->get_info(filename->buf, finfo) != UPNP_E_SUCCESS ||
get_info( filename->buf, &finfo ) != UPNP_E_SUCCESS ) UpnpFileInfo_get_IsDirectory(finfo)) {
|| finfo.is_directory ) {
err_code = HTTP_NOT_FOUND; err_code = HTTP_NOT_FOUND;
goto error_handler; goto error_handler;
} }
} }
// not readable // not readable
if( !finfo.is_readable ) { if (!UpnpFileInfo_get_IsReadable(finfo)) {
err_code = HTTP_FORBIDDEN; err_code = HTTP_FORBIDDEN;
goto error_handler; goto error_handler;
} }
@ -1314,7 +1318,7 @@ process_request( IN http_message_t * req,
// goto error_handler; // goto error_handler;
// } // }
} }
} else if( !using_alias ) { } else if (!using_alias) {
if( gDocumentRootDir.length == 0 ) { if( gDocumentRootDir.length == 0 ) {
goto error_handler; goto error_handler;
} }
@ -1335,12 +1339,12 @@ process_request( IN http_message_t * req,
if( req->method != HTTPMETHOD_POST ) { if( req->method != HTTPMETHOD_POST ) {
// get info on file // get info on file
if( get_file_info( filename->buf, &finfo ) != 0 ) { if (get_file_info(filename->buf, finfo) != 0) {
err_code = HTTP_NOT_FOUND; err_code = HTTP_NOT_FOUND;
goto error_handler; goto error_handler;
} }
// try index.html if req is a dir // try index.html if req is a dir
if( finfo.is_directory ) { if (UpnpFileInfo_get_IsDirectory(finfo)) {
if( filename->buf[filename->length - 1] == '/' ) { if( filename->buf[filename->length - 1] == '/' ) {
temp_str = "index.html"; temp_str = "index.html";
} else { } else {
@ -1350,14 +1354,14 @@ process_request( IN http_message_t * req,
goto error_handler; goto error_handler;
} }
// get info // get info
if( get_file_info( filename->buf, &finfo ) != 0 || if (get_file_info(filename->buf, finfo) != 0 ||
finfo.is_directory ) { UpnpFileInfo_get_IsDirectory(finfo)) {
err_code = HTTP_NOT_FOUND; err_code = HTTP_NOT_FOUND;
goto error_handler; goto error_handler;
} }
} }
// not readable // not readable
if( !finfo.is_readable ) { if (!UpnpFileInfo_get_IsReadable(finfo)) {
err_code = HTTP_FORBIDDEN; err_code = HTTP_FORBIDDEN;
goto error_handler; goto error_handler;
} }
@ -1370,12 +1374,12 @@ process_request( IN http_message_t * req,
// } // }
} }
RespInstr->ReadSendSize = finfo.file_length; RespInstr->ReadSendSize = UpnpFileInfo_get_FileLength(finfo);
// Check other header field. // Check other header field.
if( ( err_code = err_code =
CheckOtherHTTPHeaders( req, RespInstr, CheckOtherHTTPHeaders(req, RespInstr, UpnpFileInfo_get_FileLength(finfo));
finfo.file_length ) ) != HTTP_OK ) { if ( err_code != HTTP_OK ) {
goto error_handler; goto error_handler;
} }
@ -1385,34 +1389,40 @@ process_request( IN http_message_t * req,
goto error_handler; goto error_handler;
} }
extra_headers = UpnpFileInfo_get_ExtraHeaders(finfo);
if (!extra_headers) {
extra_headers = "";
}
if( RespInstr->IsRangeActive && RespInstr->IsChunkActive ) { if( RespInstr->IsRangeActive && RespInstr->IsChunkActive ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT // Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked // Transfer-Encoding: chunked
if (http_MakeMessage( if (http_MakeMessage(
headers, resp_major, resp_minor, headers, resp_major, resp_minor,
"R" "T" "GKD" "s" "tcS" "XcCc", "R" "T" "GKD" "s" "tcS" "Xc" "sCc",
HTTP_PARTIAL_CONTENT, // status code HTTP_PARTIAL_CONTENT, // status code
finfo.content_type, // content type UpnpFileInfo_get_ContentType(finfo), // content type
RespInstr, // range info RespInstr, // range info
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT) != 0 ) { X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler; goto error_handler;
} }
} else if( RespInstr->IsRangeActive && !RespInstr->IsChunkActive ) { } else if( RespInstr->IsRangeActive && !RespInstr->IsChunkActive ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT // Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked // Transfer-Encoding: chunked
if (http_MakeMessage( if (http_MakeMessage(
headers, resp_major, resp_minor, headers, resp_major, resp_minor,
"R" "N" "T" "GD" "s" "tcS" "XcCc", "R" "N" "T" "GD" "s" "tcS" "Xc" "sCc",
HTTP_PARTIAL_CONTENT, // status code HTTP_PARTIAL_CONTENT, // status code
RespInstr->ReadSendSize, // content length RespInstr->ReadSendSize, // content length
finfo.content_type, // content type UpnpFileInfo_get_ContentType(finfo), // content type
RespInstr, // range info RespInstr, // range info
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT) != 0 ) { X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler; goto error_handler;
} }
@ -1421,12 +1431,13 @@ process_request( IN http_message_t * req,
// Transfer-Encoding: chunked // Transfer-Encoding: chunked
if (http_MakeMessage( if (http_MakeMessage(
headers, resp_major, resp_minor, headers, resp_major, resp_minor,
"RK" "TD" "s" "tcS" "XcCc", "RK" "TD" "s" "tcS" "Xc" "sCc",
HTTP_OK, // status code HTTP_OK, // status code
finfo.content_type, // content type UpnpFileInfo_get_ContentType(finfo), // content type
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT) != 0 ) { X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler; goto error_handler;
} }
@ -1436,13 +1447,14 @@ process_request( IN http_message_t * req,
// Transfer-Encoding: chunked // Transfer-Encoding: chunked
if (http_MakeMessage( if (http_MakeMessage(
headers, resp_major, resp_minor, headers, resp_major, resp_minor,
"R" "N" "TD" "s" "tcS" "XcCc", "R" "N" "TD" "s" "tcS" "Xc" "sCc",
HTTP_OK, // status code HTTP_OK, // status code
RespInstr->ReadSendSize, // content length RespInstr->ReadSendSize, // content length
finfo.content_type, // content type UpnpFileInfo_get_ContentType(finfo), // content type
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT) != 0 ) { X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler; goto error_handler;
} }
} else { } else {
@ -1450,12 +1462,13 @@ process_request( IN http_message_t * req,
// Transfer-Encoding: chunked // Transfer-Encoding: chunked
if (http_MakeMessage( if (http_MakeMessage(
headers, resp_major, resp_minor, headers, resp_major, resp_minor,
"R" "TD" "s" "tcS" "XcCc", "R" "TD" "s" "tcS" "b" "Xc" "sCc",
HTTP_OK, // status code HTTP_OK, // status code
finfo.content_type, // content type UpnpFileInfo_get_ContentType(finfo), // content type
"LAST-MODIFIED: ", "LAST-MODIFIED: ",
&finfo.last_modified, UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT) != 0 ) { X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler; goto error_handler;
} }
} }
@ -1481,11 +1494,11 @@ process_request( IN http_message_t * req,
err_code = UPNP_E_SUCCESS; err_code = UPNP_E_SUCCESS;
error_handler: error_handler:
free( request_doc ); free(request_doc);
ixmlFreeDOMString( finfo.content_type ); UpnpFileInfo_delete(finfo);
if( err_code != UPNP_E_SUCCESS && alias_grabbed ) { if (err_code != UPNP_E_SUCCESS && alias_grabbed) {
alias_release( alias ); alias_release(alias);
} }
return err_code; return err_code;

View File

@ -29,139 +29,155 @@
// //
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#ifndef _CLIENT_TABLE
#define _CLIENT_TABLE #ifndef CLIENT_TABLE_H
#define CLIENT_TABLE_H
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include "upnp.h"
#include <stdio.h> #include <stdio.h>
//#include <malloc.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
#include "uri.h"
#include "service_table.h"
#include "service_table.h"
#include "String.h" // for UpnpString
#include "TimerThread.h" #include "TimerThread.h"
#include "upnp.h"
#include "upnp_timeout.h" #include "upnp_timeout.h"
#include "uri.h"
extern TimerThread gTimerThread; extern TimerThread gTimerThread;
CLIENTONLY(
typedef struct CLIENT_SUBSCRIPTION {
Upnp_SID sid;
char * ActualSID;
char * EventURL;
int RenewEventId;
struct CLIENT_SUBSCRIPTION * next;
} client_subscription;
/************************************************************************ #ifdef INCLUDE_CLIENT_APIS
* Function : copy_client_subscription
*
* Parameters : typedef struct {} ClientSubscription;
* client_subscription * in ; - source client subscription
* client_subscription * out ; - destination client subscription
* /** Constructor */
* Description : Make a copy of the client subscription data ClientSubscription *UpnpClientSubscription_new();
*
* Return : int ; /** Destructor */
* UPNP_E_OUTOF_MEMORY - On Failure to allocate memory void UpnpClientSubscription_delete(ClientSubscription *p);
* HTTP_SUCCESS - On Success
* /** Copy Constructor */
* Note : ClientSubscription *UpnpClientSubscription_dup(const ClientSubscription *p);
************************************************************************/
int copy_client_subscription(client_subscription * in, client_subscription * out); /** Assignment operator */
void UpnpClientSubscription_assign(ClientSubscription *q, const ClientSubscription *p);
/* */
int UpnpClientSubscription_get_RenewEventId(const ClientSubscription *p);
void UpnpClientSubscription_set_RenewEventId(ClientSubscription *p, int n);
/* */
const UpnpString *UpnpClientSubscription_get_SID(const ClientSubscription *p);
void UpnpClientSubscription_set_SID(ClientSubscription *p, const UpnpString *s);
void UpnpClientSubscription_strcpy_SID(ClientSubscription *p, const char *s);
/* */
const UpnpString *UpnpClientSubscription_get_ActualSID(const ClientSubscription *p);
void UpnpClientSubscription_set_ActualSID(ClientSubscription *p, const UpnpString *s);
void UpnpClientSubscription_strcpy_ActualSID(ClientSubscription *p, const char *s);
/* */
const UpnpString *UpnpClientSubscription_get_EventURL(const ClientSubscription *p);
void UpnpClientSubscription_set_EventURL(ClientSubscription *p, const UpnpString *s);
void UpnpClientSubscription_strcpy_EventURL(ClientSubscription *p, const char *s);
/* */
ClientSubscription *UpnpClientSubscription_get_Next(const ClientSubscription *p);
void UpnpClientSubscription_set_Next(ClientSubscription *p, ClientSubscription *q);
/************************************************************************
* Function : free_client_subscription
*
* Parameters :
* client_subscription * sub ; - Client subscription to be freed
*
* Description : Free memory allocated for client subscription data.
* Remove timer thread associated with this subscription event.
*
* Return : void ;
*
* Note :
************************************************************************/
void free_client_subscription(client_subscription * sub);
/************************************************************************ /************************************************************************
* Function : freeClientSubList * Function: free_client_subscription
* *
* Parameters : * Parameters:
* client_subscription * list ; Client subscription * ClientSubscription *sub; - Client subscription to be freed
* *
* Description : Free the client subscription table. * Description: Free memory allocated for client subscription data.
* * Remove timer thread associated with this subscription event.
* Return : void ; ************************************************************************/
* void free_client_subscription(ClientSubscription * sub);
* Note :
************************************************************************/
void freeClientSubList(client_subscription * list);
/************************************************************************ /************************************************************************
* Function : RemoveClientSubClientSID * Function: freeClientSubList
* *
* Parameters : * Parameters:
* client_subscription **head ; Head of the subscription list * ClientSubscription *list; Client subscription
* const Upnp_SID sid ; Subscription ID to be mactched *
* * Description: Free the client subscription table.
* Description : Remove the client subscription matching the *
* subscritpion id represented by the const Upnp_SID sid parameter * Return: void
* from the table and update the table. ************************************************************************/
* void freeClientSubList(ClientSubscription *list);
* Return : void ;
*
* Note :
************************************************************************/
void RemoveClientSubClientSID(client_subscription **head,
const Upnp_SID sid);
/************************************************************************ /************************************************************************
* Function : GetClientSubClientSID * Function: RemoveClientSubClientSID
* *
* Parameters : * Parameters:
* client_subscription *head ; Head of the subscription list * ClientSubscription **head; Head of the subscription list
* const Upnp_SID sid ; Subscription ID to be matched * const UpnpString sid; Subscription ID to be mactched
* *
* Description : Return the client subscription from the client table * Description: Remove the client subscription matching the
* that matches const Upnp_SID sid subscrition id value. * subscritpion id represented by the const Upnp_SID sid parameter
* * from the table and update the table.
* Return : client_subscription * ; The matching subscription *
* * Return: void
* Note : ************************************************************************/
************************************************************************/ void RemoveClientSubClientSID(ClientSubscription **head, const UpnpString *sid);
client_subscription * GetClientSubClientSID(client_subscription *head
, const Upnp_SID sid);
/************************************************************************ /************************************************************************
* Function : GetClientSubActualSID * Function: GetClientSubClientSID
* *
* Parameters : * Parameters:
* client_subscription *head ; Head of the subscription list * ClientSubscription *head; Head of the subscription list
* token * sid ; Subscription ID to be matched * const UpnpString *sid; Subscription ID to be matched
* *
* Description : Returns the client subscription from the client * Description: Return the client subscription from the client table
* subscription table that has the matching token * sid buffer * that matches const Upnp_SID sid subscrition id value.
* value. *
* * Return: ClientSubscription * The matching subscription
* Return : client_subscription * ; The matching subscription ************************************************************************/
* ClientSubscription *GetClientSubClientSID(
* Note : ClientSubscription *head,
************************************************************************/ const UpnpString *sid);
client_subscription * GetClientSubActualSID(client_subscription *head
, token * sid);
) /************************************************************************
* Function: GetClientSubActualSID
*
* Parameters:
* ClientSubscription *head; Head of the subscription list
* token *sid; Subscription ID to be matched
*
* Description: Returns the client subscription from the client
* subscription table that has the matching token *sid buffer value.
*
* Return: ClientSubscription *; The matching subscription
************************************************************************/
ClientSubscription *GetClientSubActualSID(ClientSubscription *head, token *sid);
#endif /* INCLUDE_CLIENT_APIS */
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif /* __cplusplus */
#endif /* CLIENT_TABLE_H */
#endif /* _CLIENT_TABLE */

View File

@ -29,28 +29,36 @@
// //
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
#ifndef _GENA_ #ifndef GENA_H
#define _GENA_ #define GENA_H
#include "config.h" #include "config.h"
#include "service_table.h"
#include <string.h>
#include <time.h>
#include "client_table.h"
#include "httpparser.h"
#include "miniserver.h" #include "miniserver.h"
#include "service_table.h"
#include "sock.h"
#include "String.h"
#include "ThreadPool.h"
#include "uri.h" #include "uri.h"
#include "upnp.h" #include "upnp.h"
#include <time.h>
#include "ThreadPool.h"
#include <string.h>
#include "client_table.h"
#include "httpparser.h"
#include "sock.h"
#ifdef __cplusplus #ifdef __cplusplus
#define EXTERN_C extern "C" #define EXTERN_C extern "C"
#else #else /* __cplusplus */
#ifndef EXTERN_C #ifndef EXTERN_C
#define EXTERN_C #define EXTERN_C
#endif #endif /* EXTERN_C */
#endif #endif /* __cplusplus */
#define XML_VERSION "<?xml version='1.0' encoding='ISO-8859-1' ?>\n" #define XML_VERSION "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
#define XML_PROPERTYSET_HEADER \ #define XML_PROPERTYSET_HEADER \
@ -74,6 +82,7 @@
#define MAX_SECONDS 10 #define MAX_SECONDS 10
#define MAX_EVENTS 20 #define MAX_EVENTS 20
#define MAX_PORT_SIZE 10 #define MAX_PORT_SIZE 10
#define GENA_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE #define GENA_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE
#define GENA_E_BAD_SERVICE UPNP_E_INVALID_SERVICE #define GENA_E_BAD_SERVICE UPNP_E_INVALID_SERVICE
#define GENA_E_SUBSCRIPTION_UNACCEPTED UPNP_E_SUBSCRIBE_UNACCEPTED #define GENA_E_SUBSCRIPTION_UNACCEPTED UPNP_E_SUBSCRIBE_UNACCEPTED
@ -82,9 +91,11 @@
#define GENA_E_NOTIFY_UNACCEPTED UPNP_E_NOTIFY_UNACCEPTED #define GENA_E_NOTIFY_UNACCEPTED UPNP_E_NOTIFY_UNACCEPTED
#define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB -9 #define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB -9
#define GENA_E_BAD_HANDLE UPNP_E_INVALID_HANDLE #define GENA_E_BAD_HANDLE UPNP_E_INVALID_HANDLE
#define XML_ERROR -5 #define XML_ERROR -5
#define XML_SUCCESS UPNP_E_SUCCESS #define XML_SUCCESS UPNP_E_SUCCESS
#define GENA_SUCCESS UPNP_E_SUCCESS #define GENA_SUCCESS UPNP_E_SUCCESS
#define CALLBACK_SUCCESS 0 #define CALLBACK_SUCCESS 0
#define DEFAULT_TIMEOUT 1801 #define DEFAULT_TIMEOUT 1801
@ -110,171 +121,173 @@ extern ithread_mutex_t GlobalClientSubscribeMutex;
// Structure to send NOTIFY message to all subscribed control points // Structure to send NOTIFY message to all subscribed control points
typedef struct NOTIFY_THREAD_STRUCT { typedef struct NOTIFY_THREAD_STRUCT {
char * headers; char *headers;
DOMString propertySet; DOMString propertySet;
char * servId; char *servId;
char * UDN; char *UDN;
Upnp_SID sid; Upnp_SID sid;
int eventKey; int eventKey;
int *reference_count; int *reference_count;
UpnpDevice_Handle device_handle; UpnpDevice_Handle device_handle;
} notify_thread_struct; } notify_thread_struct;
/************************************************************************ /************************************************************************
* Function : genaCallback * Function : genaCallback
* *
* Parameters: * Parameters:
* IN http_parser_t *parser: represents the parse state of the request * IN http_parser_t *parser: represents the parse state of the request
* IN http_message_t* request: HTTP message containing GENA request * IN http_message_t* request: HTTP message containing GENA request
* INOUT SOCKINFO *info: Structure containing information about the socket * INOUT SOCKINFO *info: Structure containing information about the socket
* *
* Description: * Description:
* This is the callback function called by the miniserver to handle * This is the callback function called by the miniserver to handle
* incoming GENA requests. * incoming GENA requests.
* *
* Returns: int * Returns: int
* UPNP_E_SUCCESS if successful else appropriate error * UPNP_E_SUCCESS if successful else appropriate error
***************************************************************************/ ***************************************************************************/
EXTERN_C void genaCallback (IN http_parser_t *parser, EXTERN_C void genaCallback(
IN http_message_t* request, IN http_parser_t *parser,
IN SOCKINFO *info); IN http_message_t* request,
IN SOCKINFO *info);
/************************************************************************ /************************************************************************
* Function : genaSubscribe * Function: genaSubscribe
* *
* Parameters: * Parameters:
* IN UpnpClient_Handle client_handle: * IN UpnpClient_Handle client_handle:
* IN char * PublisherURL: NULL Terminated, of the form : * IN const UpnpString *PublisherURL: Of the form:
* "http://134.134.156.80:4000/RedBulb/Event" * "http://134.134.156.80:4000/RedBulb/Event"
* INOUT int * TimeOut: requested Duration, if -1, then "infinite". * INOUT int * TimeOut: requested Duration, if -1, then "infinite".
* in the OUT case: actual Duration granted * in the OUT case: actual Duration granted
* by Service, -1 for infinite * by Service, -1 for infinite
* OUT Upnp_SID out_sid:sid of subscription, memory passed in by caller * OUT UpnpString *out_sid: sid of subscription, memory passed in by caller
* *
* Description: * Description:
* This function subscribes to a PublisherURL ( also mentioned as EventURL * This function subscribes to a PublisherURL ( also mentioned as EventURL
* some places). It sends SUBSCRIBE http request to service processes * some places). It sends SUBSCRIBE http request to service processes
* request. Finally adds a Subscription to * request. Finally adds a Subscription to
* the clients subscription list, if service responds with OK * the clients subscription list, if service responds with OK
* *
* Returns: int * Returns: int
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaSubscribe( EXTERN_C int genaSubscribe(
UpnpClient_Handle client_handle, IN UpnpClient_Handle client_handle,
char * PublisherURL, IN const UpnpString *PublisherURL,
int * TimeOut, INOUT int *TimeOut,
Upnp_SID out_sid ); OUT UpnpString *out_sid);
#endif #endif /* INCLUDE_CLIENT_APIS */
/************************************************************************ /************************************************************************
* Function : genaUnSubscribe * Function: genaUnSubscribe
* *
* Parameters: * Parameters:
* IN UpnpClient_Handle client_handle: UPnP client handle * IN UpnpClient_Handle client_handle: UPnP client handle
* IN SID in_sid: The subscription ID * IN const UpnpString *in_sid: The subscription ID
* *
* Description: * Description:
* This function unsubscribes a SID. It first validates the SID and * This function unsubscribes a SID. It first validates the SID and
* client_handle,copies the subscription, sends UNSUBSCRIBE http request * client_handle,copies the subscription, sends UNSUBSCRIBE http request
* to service processes request and finally removes the subscription * to service processes request and finally removes the subscription
* *
* Returns: int * Returns: int
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaUnSubscribe( EXTERN_C int genaUnSubscribe(
UpnpClient_Handle client_handle, IN UpnpClient_Handle client_handle,
const Upnp_SID in_sid); IN const UpnpString *in_sid);
#endif #endif /* INCLUDE_CLIENT_APIS */
/************************************************************************ /************************************************************************
* Function : genaUnregisterClient * Function : genaUnregisterClient
* *
* Parameters: * Parameters:
* IN UpnpClient_Handle client_handle: Handle containing all the control * IN UpnpClient_Handle client_handle: Handle containing all the control
* point related information * point related information
* *
* Description: * Description:
* This function unsubcribes all the outstanding subscriptions and cleans * This function unsubcribes all the outstanding subscriptions and cleans
* the subscription list. This function is called when control point * the subscription list. This function is called when control point
* unregisters. * unregisters.
* *
* Returns: int * Returns: int
* return UPNP_E_SUCCESS if successful else returns appropriate error * return UPNP_E_SUCCESS if successful else returns appropriate error
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaUnregisterClient(UpnpClient_Handle client_handle); EXTERN_C int genaUnregisterClient(UpnpClient_Handle client_handle);
#endif #endif /* INCLUDE_CLIENT_APIS */
//server //server
/************************************************************************ /************************************************************************
* Function : genaUnregisterDevice * Function : genaUnregisterDevice
* *
* Parameters: * Parameters:
* IN UpnpDevice_Handle device_handle: Handle of the root device * IN UpnpDevice_Handle device_handle: Handle of the root device
* *
* Description: * Description:
* This function cleans the service table of the device. * This function cleans the service table of the device.
* *
* Returns: int * Returns: int
* returns UPNP_E_SUCCESS if successful else returns GENA_E_BAD_HANDLE * returns UPNP_E_SUCCESS if successful else returns GENA_E_BAD_HANDLE
****************************************************************************/ ****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaUnregisterDevice(UpnpDevice_Handle device_handle); EXTERN_C int genaUnregisterDevice(UpnpDevice_Handle device_handle);
#endif #endif /* INCLUDE_CLIENT_APIS */
/************************************************************************ /************************************************************************
* Function : genaRenewSubscription * Function : genaRenewSubscription
* *
* Parameters: * Parameters:
* IN UpnpClient_Handle client_handle: Client handle * IN UpnpClient_Handle client_handle: Client handle
* IN const Upnp_SID in_sid: subscription ID * IN const UpnpString *in_sid: subscription ID
* INOUT int * TimeOut: requested Duration, if -1, then "infinite". * INOUT int * TimeOut:
* in the OUT case: actual Duration granted * requested Duration, if -1, then "infinite".
* by Service, -1 for infinite * in the OUT case: actual Duration granted by Service, -1 for infinite
* *
* Description: * Description:
* This function renews a SID. It first validates the SID and * This function renews a SID. It first validates the SID and
* client_handle and copies the subscription. It sends RENEW * client_handle and copies the subscription. It sends RENEW
* (modified SUBSCRIBE) http request to service and processes * (modified SUBSCRIBE) http request to service and processes
* the response. * the response.
* *
* Returns: int * Returns: int
* return UPNP_E_SUCCESS if service response is OK else * return UPNP_E_SUCCESS if service response is OK else
* returns appropriate error * returns appropriate error
***************************************************************************/ ***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
EXTERN_C int genaRenewSubscription( EXTERN_C int genaRenewSubscription(
IN UpnpClient_Handle client_handle, IN UpnpClient_Handle client_handle,
IN const Upnp_SID in_sid, IN const UpnpString *in_sid,
OUT int * TimeOut); OUT int * TimeOut);
#endif #endif /* INCLUDE_CLIENT_APIS */
/**************************************************************************** /****************************************************************************
* Function : genaNotifyAll * Function: genaNotifyAll
* *
* Parameters : * Parameters:
* IN UpnpDevice_Handle device_handle : Device handle * IN UpnpDevice_Handle device_handle: Device handle
* IN char *UDN : Device udn * IN char *UDN: Device udn
* IN char *servId : Service ID * IN char *servId: Service ID
* IN char **VarNames : array of varible names * IN char **VarNames: array of varible names
* IN char **VarValues : array of variable values * IN char **VarValues: array of variable values
* IN int var_count : number of variables * IN int var_count: number of variables
* *
* Description : This function sends a notification to all the subscribed * Description: This function sends a notification to all the subscribed
* control points * control points
* *
* Return : int * Return: int
* *
* Note : This function is similar to the genaNotifyAllExt. The only difference * Note: This function is similar to the genaNotifyAllExt. The only difference
* is it takes event variable array instead of xml document. * is it takes event variable array instead of xml document.
****************************************************************************/ ****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaNotifyAll( EXTERN_C int genaNotifyAll(
UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
@ -283,54 +296,55 @@ EXTERN_C int genaNotifyAll(
char **VarNames, char **VarNames,
char **VarValues, char **VarValues,
int var_count); int var_count);
#endif #endif /* INCLUDE_DEVICE_APIS */
/**************************************************************************** /****************************************************************************
* Function : genaNotifyAllExt * Function: genaNotifyAllExt
* *
* Parameters : * Parameters:
* IN UpnpDevice_Handle device_handle : Device handle * IN UpnpDevice_Handle device_handle: Device handle
* IN char *UDN : Device udn * IN char *UDN: Device udn
* IN char *servId : Service ID * IN char *servId: Service ID
* IN IXML_Document *PropSet : XML document Event varible property set * IN IXML_Document *PropSet: XML document Event varible property set
* *
* Description : This function sends a notification to all the subscribed * Description : This function sends a notification to all the subscribed
* control points * control points
* *
* Return : int * Return: int
* *
* Note : This function is similar to the genaNotifyAll. the only difference * Note: This function is similar to the genaNotifyAll. the only difference
* is it takes the document instead of event variable array * is it takes the document instead of event variable array
****************************************************************************/ ****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaNotifyAllExt( EXTERN_C int genaNotifyAllExt(
UpnpDevice_Handle device_handle, UpnpDevice_Handle device_handle,
char *UDN, char *UDN,
char *servId, char *servId,
IN IXML_Document *PropSet); IN IXML_Document *PropSet);
#endif #endif /* INCLUDE_DEVICE_APIS */
/**************************************************************************** /****************************************************************************
* Function : genaInitNotify * Function: genaInitNotify
* *
* Parameters : * Parameters:
* IN UpnpDevice_Handle device_handle : Device handle * IN UpnpDevice_Handle device_handle: Device handle
* IN char *UDN : Device udn * IN char *UDN: Device udn
* IN char *servId : Service ID * IN char *servId: Service ID
* IN char **VarNames : Array of variable names * IN char **VarNames: Array of variable names
* IN char **VarValues : Array of variable values * IN char **VarValues: Array of variable values
* IN int var_count : array size * IN int var_count: array size
* IN Upnp_SID sid : subscription ID * IN Upnp_SID sid: subscription ID
* *
* Description : This function sends the intial state table dump to * Description: This function sends the intial state table dump to
* newly subscribed control point. * newly subscribed control point.
* *
* Return : int * Return: int
* returns GENA_E_SUCCESS if successful else returns appropriate error * returns GENA_E_SUCCESS if successful else returns appropriate error
* *
* Note : No other event will be sent to this control point before the * Note: No other event will be sent to this control point before the
* intial state table dump. * intial state table dump.
****************************************************************************/ ****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaInitNotify(IN UpnpDevice_Handle device_handle, EXTERN_C int genaInitNotify(IN UpnpDevice_Handle device_handle,
IN char *UDN, IN char *UDN,
@ -339,28 +353,29 @@ EXTERN_C int genaInitNotify(IN UpnpDevice_Handle device_handle,
IN char **VarValues, IN char **VarValues,
IN int var_count, IN int var_count,
IN Upnp_SID sid); IN Upnp_SID sid);
#endif #endif /* INCLUDE_DEVICE_APIS */
/**************************************************************************** /****************************************************************************
* Function : genaInitNotifyExt * Function : genaInitNotifyExt
* *
* Parameters : * Parameters :
* IN UpnpDevice_Handle device_handle : Device handle * IN UpnpDevice_Handle device_handle : Device handle
* IN char *UDN : Device udn * IN char *UDN : Device udn
* IN char *servId : Service ID * IN char *servId : Service ID
* IN IXML_Document *PropSet : Document of the state table * IN IXML_Document *PropSet : Document of the state table
* IN Upnp_SID sid : subscription ID * IN Upnp_SID sid : subscription ID
* *
* Description : This function is similar to the genaInitNofity. The only * Description : This function is similar to the genaInitNofity. The only
* difference is that it takes the xml document for the state table and * difference is that it takes the xml document for the state table and
* sends the intial state table dump to newly subscribed control point. * sends the intial state table dump to newly subscribed control point.
* *
* Return : int * Return : int
* returns GENA_E_SUCCESS if successful else returns appropriate error * returns GENA_E_SUCCESS if successful else returns appropriate error
* *
* Note : No other event will be sent to this control point before the * Note : No other event will be sent to this control point before the
* intial state table dump. * intial state table dump.
****************************************************************************/ ****************************************************************************/
#ifdef INCLUDE_DEVICE_APIS #ifdef INCLUDE_DEVICE_APIS
EXTERN_C int genaInitNotifyExt( EXTERN_C int genaInitNotifyExt(
IN UpnpDevice_Handle device_handle, IN UpnpDevice_Handle device_handle,
@ -368,35 +383,29 @@ EXTERN_C int genaInitNotifyExt(
IN char *servId, IN char *servId,
IN IXML_Document *PropSet, IN IXML_Document *PropSet,
IN Upnp_SID sid); IN Upnp_SID sid);
#endif #endif /* INCLUDE_DEVICE_APIS */
/************************************************************************ /************************************************************************
* Function : error_respond * Function : error_respond
* *
* Parameters: * Parameters:
* IN SOCKINFO *info: Structure containing information about the socket * IN SOCKINFO *info: Structure containing information about the socket
* IN int error_code: error code that will be in the GENA response * IN int error_code: error code that will be in the GENA response
* IN http_message_t* hmsg: GENA request Packet * IN http_message_t* hmsg: GENA request Packet
* *
* Description: * Description:
* This function send an error message to the control point in the case * This function send an error message to the control point in the case
* incorrect GENA requests. * incorrect GENA requests.
* *
* Returns: int * Returns: int
* UPNP_E_SUCCESS if successful else appropriate error * UPNP_E_SUCCESS if successful else appropriate error
***************************************************************************/ ***************************************************************************/
void error_respond( IN SOCKINFO *info, IN int error_code, void error_respond(
IN http_message_t* hmsg ); IN SOCKINFO *info,
IN int error_code,
IN http_message_t* hmsg);
#endif // GENA
#endif /* GENA_H */

View File

@ -81,7 +81,7 @@ int http_FixUrl( IN uri_type* url, OUT uri_type* fixed_url );
* UPNP_E_INVALID_URL * UPNP_E_INVALID_URL
* UPNP_E_SUCCESS * UPNP_E_SUCCESS
************************************************************************/ ************************************************************************/
int http_FixStrUrl( IN char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url ); int http_FixStrUrl( IN const char* urlstr, IN int urlstrlen, OUT uri_type* fixed_url );
/************************************************************************ /************************************************************************

View File

@ -129,15 +129,6 @@ typedef void (* SsdpFunPtr)(Event *);
typedef Event SsdpEvent ; typedef Event SsdpEvent ;
//Structure to contain Discovery response
typedef struct resultData
{
struct Upnp_Discovery param;
void *cookie;
Upnp_FunPtr ctrlpt_callback;
}ResultData;
typedef struct TData typedef struct TData
{ {
int Mx; int Mx;

View File

@ -88,7 +88,7 @@ struct Handle_Info
// Client only // Client only
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
client_subscription *ClientSubList; //client subscription list ClientSubscription *ClientSubList; //client subscription list
LinkedList SsdpSearchList; // active ssdp searches LinkedList SsdpSearchList; // active ssdp searches
#endif #endif
int aliasInstalled; // 0 = not installed; otherwise installed int aliasInstalled; // 0 = not installed; otherwise installed

View File

@ -38,14 +38,17 @@
#define QUERY_STATE_VAR_URN "urn:schemas-upnp-org:control-1-0" #define QUERY_STATE_VAR_URN "urn:schemas-upnp-org:control-1-0"
#include "upnpapi.h"
#include "parsetools.h" #include "ActionRequest.h"
#include "statcodes.h"
#include "httpparser.h" #include "httpparser.h"
#include "httpreadwrite.h" #include "httpreadwrite.h"
#include "unixutil.h" #include "parsetools.h"
#include "soaplib.h" #include "soaplib.h"
#include "ssdplib.h" #include "ssdplib.h"
#include "statcodes.h"
#include "unixutil.h"
#include "upnpapi.h"
#ifdef WIN32 #ifdef WIN32
#define snprintf _snprintf #define snprintf _snprintf
@ -569,10 +572,10 @@ check_soap_action_header( IN http_message_t * request,
* IN http_message_t* request : HTTP request * IN http_message_t* request : HTTP request
* IN int isQuery : flag for a querry * IN int isQuery : flag for a querry
* IN IXML_Document *actionDoc : action request document * IN IXML_Document *actionDoc : action request document
* OUT char device_udn[LINE_SIZE] : Device UDN string * OUT UpnpString *device_udn : Device UDN string
* OUT char service_id[LINE_SIZE] : Service ID string * OUT UpnpString *service_id : Service ID string
* OUT Upnp_FunPtr *callback : callback function of the device * OUT Upnp_FunPtr *callback : callback function of the device
* application * application
* OUT void** cookie : cookie stored by device application * OUT void** cookie : cookie stored by device application
* *
* Description : This function retrives all the information needed to * Description : This function retrives all the information needed to
@ -586,12 +589,12 @@ check_soap_action_header( IN http_message_t * request,
* Note : * Note :
****************************************************************************/ ****************************************************************************/
static int static int
get_device_info( IN http_message_t * request, get_device_info( IN http_message_t *request,
IN int isQuery, IN int isQuery,
IN IXML_Document * actionDoc, IN IXML_Document *actionDoc,
OUT char device_udn[LINE_SIZE], OUT UpnpString *device_udn,
OUT char service_id[LINE_SIZE], OUT UpnpString *service_id,
OUT Upnp_FunPtr * callback, OUT Upnp_FunPtr *callback,
OUT void **cookie ) OUT void **cookie )
{ {
struct Handle_Info *device_info; struct Handle_Info *device_info;
@ -654,8 +657,8 @@ get_device_info( IN http_message_t * request,
} }
} }
namecopy( service_id, serv_info->serviceId ); UpnpString_set_String( device_udn, serv_info->UDN );
namecopy( device_udn, serv_info->UDN ); UpnpString_set_String( service_id, serv_info->serviceId );
*callback = device_info->Callback; *callback = device_info->Callback;
*cookie = device_info->Cookie; *cookie = device_info->Cookie;
@ -845,10 +848,10 @@ handle_query_variable( IN SOCKINFO * info,
IN http_message_t * request, IN http_message_t * request,
IN IXML_Document * xml_doc ) IN IXML_Document * xml_doc )
{ {
UpnpStateVarRequest *variable = UpnpStateVarRequest_new();
Upnp_FunPtr soap_event_callback; Upnp_FunPtr soap_event_callback;
void *cookie; void *cookie;
char var_name[LINE_SIZE]; char var_name[LINE_SIZE];
struct Upnp_State_Var_Request variable;
const char *err_str; const char *err_str;
int err_code; int err_code;
@ -859,49 +862,50 @@ handle_query_variable( IN SOCKINFO * info,
return; return;
} }
// get info for event // get info for event
if( get_device_info( request, 1, xml_doc, variable.DevUDN, err_code = get_device_info(
variable.ServiceID, request, 1, xml_doc,
&soap_event_callback, &cookie ) != 0 ) { (UpnpString *)UpnpStateVarRequest_get_DevUDN(variable),
(UpnpString *)UpnpStateVarRequest_get_ServiceID(variable),
&soap_event_callback,
&cookie);
if( err_code != 0 ) {
send_error_response( info, SOAP_INVALID_VAR, send_error_response( info, SOAP_INVALID_VAR,
Soap_Invalid_Var, request ); Soap_Invalid_Var, request );
return; return;
} }
linecopy( variable.ErrStr, "" ); UpnpStateVarRequest_set_ErrCode(variable, UPNP_E_SUCCESS);
variable.ErrCode = UPNP_E_SUCCESS; UpnpStateVarRequest_strcpy_StateVarName(variable, var_name);
namecopy( variable.StateVarName, var_name ); UpnpStateVarRequest_set_CtrlPtIPAddr(variable, &info->foreign_ip_addr);
variable.CurrentVal = NULL;
variable.CtrlPtIPAddr = info->foreign_ip_addr;
// send event // send event
soap_event_callback( UPNP_CONTROL_GET_VAR_REQUEST, &variable, cookie ); soap_event_callback( UPNP_CONTROL_GET_VAR_REQUEST, variable, cookie );
UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
"Return from callback for var request\n" ); "Return from callback for var request\n" );
// validate, and handle result // validate, and handle result
if( variable.CurrentVal == NULL ) { if( UpnpStateVarRequest_get_CurrentVal(variable) == NULL ) {
err_code = SOAP_ACTION_FAILED; err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed; err_str = Soap_Action_Failed;
send_error_response( info, SOAP_INVALID_VAR, send_error_response( info, SOAP_INVALID_VAR, Soap_Invalid_Var, request );
Soap_Invalid_Var, request );
return; return;
} }
if( variable.ErrCode != UPNP_E_SUCCESS ) { if( UpnpStateVarRequest_get_ErrCode(variable) != UPNP_E_SUCCESS ) {
if( strlen( variable.ErrStr ) > 0 ) { if( UpnpString_get_Length(UpnpStateVarRequest_get_ErrStr(variable)) > 0 ) {
err_code = SOAP_INVALID_VAR; err_code = SOAP_INVALID_VAR;
err_str = Soap_Invalid_Var; err_str = Soap_Invalid_Var;
} else { } else {
err_code = variable.ErrCode; err_code = UpnpStateVarRequest_get_ErrCode(variable);
err_str = variable.ErrStr; err_str = UpnpString_get_String(UpnpStateVarRequest_get_ErrStr(variable));
} }
send_error_response( info, err_code, err_str, request ); send_error_response( info, err_code, err_str, request );
return; return;
} }
// send response // send response
send_var_query_response( info, variable.CurrentVal, request ); send_var_query_response( info, UpnpStateVarRequest_get_CurrentVal(variable), request );
ixmlFreeDOMString( variable.CurrentVal ); UpnpStateVarRequest_delete(variable);
} }
/**************************************************************************** /****************************************************************************
@ -929,15 +933,16 @@ handle_invoke_action( IN SOCKINFO * info,
IN IXML_Document * xml_doc ) IN IXML_Document * xml_doc )
{ {
char save_char; char save_char;
IXML_Document *resp_node = NULL; UpnpActionRequest *action = UpnpActionRequest_new();
struct Upnp_Action_Request action; UpnpString *devUDN = UpnpString_new();
UpnpString *serviceID = UpnpString_new();
IXML_Document *actionRequestDoc = NULL;
IXML_Document *actionResultDoc = NULL;
Upnp_FunPtr soap_event_callback; Upnp_FunPtr soap_event_callback;
void *cookie = NULL; void *cookie = NULL;
int err_code; int err_code;
const char *err_str; const char *err_str;
action.ActionResult = NULL;
// null-terminate // null-terminate
save_char = action_name.buf[action_name.length]; save_char = action_name.buf[action_name.length];
action_name.buf[action_name.length] = '\0'; action_name.buf[action_name.length] = '\0';
@ -947,59 +952,66 @@ handle_invoke_action( IN SOCKINFO * info,
err_str = Soap_Invalid_Action; err_str = Soap_Invalid_Action;
// get action node // get action node
if( get_action_node( xml_doc, action_name.buf, &resp_node ) == -1 ) { if( get_action_node( xml_doc, action_name.buf, &actionRequestDoc ) == -1 ) {
goto error_handler; goto error_handler;
} }
// get device info for action event // get device info for action event
err_code = get_device_info( request, 0, xml_doc, action.DevUDN, err_code = get_device_info(
action.ServiceID, &soap_event_callback, request,
&cookie ); 0,
xml_doc,
devUDN,
serviceID,
&soap_event_callback,
&cookie );
if( err_code != UPNP_E_SUCCESS ) { if( err_code != UPNP_E_SUCCESS ) {
goto error_handler; goto error_handler;
} }
namecopy( action.ActionName, action_name.buf ); UpnpActionRequest_set_ErrCode(action, UPNP_E_SUCCESS);
linecopy( action.ErrStr, "" ); UpnpActionRequest_strcpy_ErrStr(action, "");
action.ActionRequest = resp_node; UpnpActionRequest_strcpy_ActionName(action, action_name.buf);
action.ActionResult = NULL; UpnpActionRequest_set_DevUDN(action, devUDN);
action.ErrCode = UPNP_E_SUCCESS; UpnpActionRequest_set_ServiceID(action, serviceID);
action.CtrlPtIPAddr = info->foreign_ip_addr; UpnpActionRequest_set_ActionRequest(action, actionRequestDoc);
UpnpActionRequest_set_CtrlPtIPAddr(action, &info->foreign_ip_addr);
UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__, UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__, "Calling Callback\n");
"Calling Callback\n" );
soap_event_callback( UPNP_CONTROL_ACTION_REQUEST, &action, cookie ); soap_event_callback(UPNP_CONTROL_ACTION_REQUEST, action, cookie);
if( action.ErrCode != UPNP_E_SUCCESS ) { err_code = UpnpActionRequest_get_ErrCode(action);
if( strlen( action.ErrStr ) <= 0 ) { if (err_code != UPNP_E_SUCCESS) {
err_str = UpnpString_get_String(UpnpActionRequest_get_ErrStr(action));
if (strlen(err_str) <= 0) {
err_code = SOAP_ACTION_FAILED; err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed; err_str = Soap_Action_Failed;
} else {
err_code = action.ErrCode;
err_str = action.ErrStr;
} }
goto error_handler; goto error_handler;
} }
// validate, and handle action error // validate, and handle action error
if( action.ActionResult == NULL ) { actionResultDoc = UpnpActionRequest_get_ActionResult(action);
if (actionResultDoc == NULL) {
err_code = SOAP_ACTION_FAILED; err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed; err_str = Soap_Action_Failed;
goto error_handler; goto error_handler;
} }
// send response // send response
send_action_response( info, action.ActionResult, request ); send_action_response(info, actionResultDoc, request);
err_code = 0; err_code = 0;
// error handling and cleanup // error handling and cleanup
error_handler: error_handler:
ixmlDocument_free( action.ActionResult );
ixmlDocument_free( resp_node );
action_name.buf[action_name.length] = save_char; // restore action_name.buf[action_name.length] = save_char; // restore
if( err_code != 0 ) { if( err_code != 0 ) {
send_error_response( info, err_code, err_str, request ); send_error_response( info, err_code, err_str, request );
} }
UpnpString_delete(serviceID);
UpnpString_delete(devUDN);
UpnpActionRequest_delete(action);
} }
/**************************************************************************** /****************************************************************************

View File

@ -0,0 +1,113 @@
#include "config.h"
#include "ssdp_ResultData.h"
#include <stdlib.h> // for calloc(), free()
struct SSSDPResultData
{
UpnpDiscovery *m_param;
void *m_cookie;
Upnp_FunPtr m_ctrlpt_callback;
};
SSDPResultData *SSDPResultData_new()
{
struct SSSDPResultData *p = calloc(1, sizeof (struct SSSDPResultData));
p->m_param = UpnpDiscovery_new();
#if 0
p->m_cookie = NULL;
p->m_ctrlpt_callback = NULL;
#endif
return (SSDPResultData *)p;
}
void SSDPResultData_delete(SSDPResultData *p)
{
struct SSSDPResultData *q = (struct SSSDPResultData *)p;
UpnpDiscovery_delete(q->m_param);
q->m_param = NULL;
q->m_cookie = NULL;
q->m_ctrlpt_callback = NULL;
free(p);
}
SSDPResultData *SSDPResultData_dup(const SSDPResultData *p)
{
SSDPResultData *q = SSDPResultData_new();
SSDPResultData_assign(q, p);
return q;
}
void SSDPResultData_assign(SSDPResultData *q, const SSDPResultData *p)
{
if (q != p) {
SSDPResultData_set_Param(q, SSDPResultData_get_Param(p));
SSDPResultData_set_Cookie(q, SSDPResultData_get_Cookie(p));
SSDPResultData_set_CtrlptCallback(q, SSDPResultData_get_CtrlptCallback(p));
}
}
UpnpDiscovery *SSDPResultData_get_Param(const SSDPResultData *p)
{
return ((struct SSSDPResultData *)p)->m_param;
}
void SSDPResultData_set_Param(SSDPResultData *p, const UpnpDiscovery *d)
{
UpnpDiscovery_assign(((struct SSSDPResultData *)p)->m_param, d);
}
void *SSDPResultData_get_Cookie(const SSDPResultData *p)
{
return ((struct SSSDPResultData *)p)->m_cookie;
}
void SSDPResultData_set_Cookie(SSDPResultData *p, void *c)
{
((struct SSSDPResultData *)p)->m_cookie = c;
}
Upnp_FunPtr SSDPResultData_get_CtrlptCallback(const SSDPResultData *p)
{
return ((struct SSSDPResultData *)p)->m_ctrlpt_callback;
}
void SSDPResultData_set_CtrlptCallback(SSDPResultData *p, Upnp_FunPtr f)
{
((struct SSSDPResultData *)p)->m_ctrlpt_callback = f;
}
void SSDPResultData_Callback(const SSDPResultData *p)
{
struct SSSDPResultData *q = (struct SSSDPResultData *)p;
q->m_ctrlpt_callback(
UPNP_DISCOVERY_SEARCH_RESULT,
q->m_param,
q->m_cookie);
}

View File

@ -0,0 +1,43 @@
#ifndef SSDP_RESULTDATA_H
#define SSDP_RESULTDATA_H
/** Structure to contain Discovery response */
typedef struct {} SSDPResultData;
#include "Discovery.h" /* for UpnpDiscovery */
#include "upnp.h" /* for Upnp_FunPtr */
/** Constructor */
SSDPResultData *SSDPResultData_new();
/** Destructor */
void SSDPResultData_delete(SSDPResultData *p);
/** Copy Constructor */
SSDPResultData *SSDPResultData_dup(const SSDPResultData *p);
/** Assignment operator */
void SSDPResultData_assign(SSDPResultData *q, const SSDPResultData *p);
/** */
UpnpDiscovery *SSDPResultData_get_Param(const SSDPResultData *p);
void SSDPResultData_set_Param(SSDPResultData *p, const UpnpDiscovery *d);
/** */
void *SSDPResultData_get_Cookie(const SSDPResultData *p);
void SSDPResultData_set_Cookie(SSDPResultData *p, void *c);
/** */
Upnp_FunPtr SSDPResultData_get_CtrlptCallback(const SSDPResultData *p);
void SSDPResultData_set_CtrlptCallback(SSDPResultData *p, Upnp_FunPtr f);
/** */
void SSDPResultData_Callback(const SSDPResultData *p);
#endif /* SSDP_RESULTDATA_H */

View File

@ -34,6 +34,7 @@
#ifdef INCLUDE_CLIENT_APIS #ifdef INCLUDE_CLIENT_APIS
#if EXCLUDE_SSDP == 0 #if EXCLUDE_SSDP == 0
#include "ssdp_ResultData.h"
#include "ssdplib.h" #include "ssdplib.h"
#include "upnpapi.h" #include "upnpapi.h"
#include <stdio.h> #include <stdio.h>
@ -53,64 +54,67 @@
/************************************************************************ /************************************************************************
* Function : send_search_result * Function: send_search_result
* *
* Parameters: * Parameters:
* IN void *data: Search reply from the device * IN void *data: Search reply from the device
* *
* Description: * Description:
* This function sends a callback to the control point application with * This function sends a callback to the control point application with
* a SEARCH result * a SEARCH result
* *
* Returns: void * Returns: void
* *
***************************************************************************/ ***************************************************************************/
void void send_search_result(IN void *data)
send_search_result( IN void *data )
{ {
ResultData *temp = ( ResultData * ) data; SSDPResultData *temp = (SSDPResultData *)data;
temp->ctrlpt_callback( UPNP_DISCOVERY_SEARCH_RESULT, SSDPResultData_Callback(temp);
&temp->param, temp->cookie ); SSDPResultData_delete(temp);
free( temp );
} }
/************************************************************************ /************************************************************************
* Function : ssdp_handle_ctrlpt_msg * Function: ssdp_handle_ctrlpt_msg
* *
* Parameters: * Parameters:
* IN http_message_t* hmsg: SSDP message from the device * IN http_message_t *hmsg:
* IN struct sockaddr_in* dest_addr: Address of the device * SSDP message from the device
* IN xboolean timeout: timeout kept by the control point while * IN struct sockaddr_in *dest_addr:
* sending search message * Address of the device
* IN void* cookie: Cookie stored by the control point application. * IN xboolean timeout:
* This cookie will be returned to the control point * timeout kept by the control point while
* in the callback * sending search message
* * IN void* cookie:
* Description: * Cookie stored by the control point application.
* This function handles the ssdp messages from the devices. These * This cookie will be returned to the control point
* messages includes the search replies, advertisement of device coming * in the callback
* alive and bye byes. *
* * Description:
* Returns: void * This function handles the ssdp messages from the devices. These
* * messages includes the search replies, advertisement of device coming
***************************************************************************/ * alive and bye byes.
void *
ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg, * Returns: void
IN struct sockaddr_in *dest_addr, *
IN xboolean timeout, // only in search reply ***************************************************************************/
void ssdp_handle_ctrlpt_msg(
IN void *cookie ) // only in search reply IN http_message_t *hmsg,
IN struct sockaddr_in *dest_addr,
IN xboolean timeout, // only in search reply
IN void *cookie ) // only in search reply
{ {
int handle; int handle;
struct Handle_Info *ctrlpt_info = NULL; struct Handle_Info *ctrlpt_info = NULL;
memptr hdr_value; memptr hdr_value;
xboolean is_byebye; // byebye or alive xboolean is_byebye; // byebye or alive
struct Upnp_Discovery param; UpnpDiscovery *param = UpnpDiscovery_new();
int expires;
int ret;
SsdpEvent event; SsdpEvent event;
xboolean nt_found, xboolean nt_found;
usn_found, xboolean usn_found;
st_found; xboolean st_found;
char save_char; char save_char;
Upnp_EventType event_type; Upnp_EventType event_type;
Upnp_FunPtr ctrlpt_callback; Upnp_FunPtr ctrlpt_callback;
@ -118,16 +122,16 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
ListNode *node = NULL; ListNode *node = NULL;
SsdpSearchArg *searchArg = NULL; SsdpSearchArg *searchArg = NULL;
int matched = 0; int matched = 0;
ResultData *threadData; SSDPResultData *threadData = NULL;
ThreadPoolJob job; ThreadPoolJob job;
// we are assuming that there can be only one client supported at a time // we are assuming that there can be only one client supported at a time
HandleReadLock(); HandleReadLock();
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) { if ( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
HandleUnlock(); HandleUnlock();
return; goto end_ssdp_handle_ctrlpt_msg;
} }
// copy // copy
ctrlpt_callback = ctrlpt_info->Callback; ctrlpt_callback = ctrlpt_info->Callback;
@ -135,103 +139,95 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
HandleUnlock(); HandleUnlock();
// search timeout // search timeout
if( timeout ) { if ( timeout ) {
ctrlpt_callback( UPNP_DISCOVERY_SEARCH_TIMEOUT, NULL, cookie ); ctrlpt_callback( UPNP_DISCOVERY_SEARCH_TIMEOUT, NULL, cookie );
return; goto end_ssdp_handle_ctrlpt_msg;
} }
param.ErrCode = UPNP_E_SUCCESS; UpnpDiscovery_set_ErrCode(param, UPNP_E_SUCCESS);
// MAX-AGE // MAX-AGE
param.Expires = -1; // assume error // assume error
if( httpmsg_find_hdr( hmsg, HDR_CACHE_CONTROL, &hdr_value ) != NULL ) { expires = -1;
if( matchstr( hdr_value.buf, hdr_value.length, UpnpDiscovery_set_Expires(param, expires);
"%imax-age = %d%0", &param.Expires ) != PARSE_OK ) if ( httpmsg_find_hdr( hmsg, HDR_CACHE_CONTROL, &hdr_value ) != NULL ) {
return; ret = matchstr( hdr_value.buf, hdr_value.length, "%imax-age = %d%0", &expires );
UpnpDiscovery_set_Expires(param, expires);
if( ret != PARSE_OK ) {
goto end_ssdp_handle_ctrlpt_msg;
}
} }
// DATE // DATE
param.Date[0] = '\0'; if ( httpmsg_find_hdr( hmsg, HDR_DATE, &hdr_value ) != NULL ) {
if( httpmsg_find_hdr( hmsg, HDR_DATE, &hdr_value ) != NULL ) { UpnpDiscovery_strcpy_Date(param, hdr_value.buf);
linecopylen( param.Date, hdr_value.buf, hdr_value.length );
} }
// dest addr // dest addr
memcpy(&param.DestAddr, dest_addr, sizeof(struct sockaddr_in) ); UpnpDiscovery_set_DestAddr(param, dest_addr);
// EXT // EXT
param.Ext[0] = '\0'; if ( httpmsg_find_hdr( hmsg, HDR_EXT, &hdr_value ) != NULL ) {
if( httpmsg_find_hdr( hmsg, HDR_EXT, &hdr_value ) != NULL ) { UpnpDiscovery_strncpy_Ext(param, hdr_value.buf, hdr_value.length);
linecopylen( param.Ext, hdr_value.buf, hdr_value.length );
} }
// LOCATION // LOCATION
param.Location[0] = '\0'; if ( httpmsg_find_hdr( hmsg, HDR_LOCATION, &hdr_value ) != NULL ) {
if( httpmsg_find_hdr( hmsg, HDR_LOCATION, &hdr_value ) != NULL ) { UpnpDiscovery_strncpy_Location(param, hdr_value.buf, hdr_value.length);
linecopylen( param.Location, hdr_value.buf, hdr_value.length );
} }
// SERVER / USER-AGENT // SERVER / USER-AGENT
param.Os[0] = '\0'; if ( httpmsg_find_hdr( hmsg, HDR_SERVER, &hdr_value ) != NULL ||
if( httpmsg_find_hdr( hmsg, HDR_SERVER, &hdr_value ) != NULL ||
httpmsg_find_hdr( hmsg, HDR_USER_AGENT, &hdr_value ) != NULL ) { httpmsg_find_hdr( hmsg, HDR_USER_AGENT, &hdr_value ) != NULL ) {
linecopylen( param.Os, hdr_value.buf, hdr_value.length ); UpnpDiscovery_strncpy_Os(param, hdr_value.buf, hdr_value.length);
} }
// clear everything // clear everything
param.DeviceId[0] = '\0';
param.DeviceType[0] = '\0';
param.ServiceType[0] = '\0';
param.ServiceVer[0] = '\0'; // not used; version is in ServiceType
event.UDN[0] = '\0'; event.UDN[0] = '\0';
event.DeviceType[0] = '\0'; event.DeviceType[0] = '\0';
event.ServiceType[0] = '\0'; event.ServiceType[0] = '\0';
nt_found = FALSE; nt_found = FALSE;
if( httpmsg_find_hdr( hmsg, HDR_NT, &hdr_value ) != NULL ) { if ( httpmsg_find_hdr( hmsg, HDR_NT, &hdr_value ) != NULL ) {
save_char = hdr_value.buf[hdr_value.length]; save_char = hdr_value.buf[hdr_value.length];
hdr_value.buf[hdr_value.length] = '\0'; hdr_value.buf[hdr_value.length] = '\0';
nt_found = ( ssdp_request_type( hdr_value.buf, &event ) == 0 ); nt_found = ( ssdp_request_type( hdr_value.buf, &event ) == 0 );
hdr_value.buf[hdr_value.length] = save_char; hdr_value.buf[hdr_value.length] = save_char;
} }
usn_found = FALSE; usn_found = FALSE;
if( httpmsg_find_hdr( hmsg, HDR_USN, &hdr_value ) != NULL ) { if ( httpmsg_find_hdr( hmsg, HDR_USN, &hdr_value ) != NULL ) {
save_char = hdr_value.buf[hdr_value.length]; save_char = hdr_value.buf[hdr_value.length];
hdr_value.buf[hdr_value.length] = '\0'; hdr_value.buf[hdr_value.length] = '\0';
usn_found = ( unique_service_name( hdr_value.buf, &event ) == 0 ); usn_found = ( unique_service_name( hdr_value.buf, &event ) == 0 );
hdr_value.buf[hdr_value.length] = save_char; hdr_value.buf[hdr_value.length] = save_char;
} }
if( nt_found || usn_found ) { if ( nt_found || usn_found ) {
strcpy( param.DeviceId, event.UDN ); UpnpDiscovery_strcpy_DeviceID( param, event.UDN);
strcpy( param.DeviceType, event.DeviceType ); UpnpDiscovery_strcpy_DeviceType( param, event.DeviceType);
strcpy( param.ServiceType, event.ServiceType ); UpnpDiscovery_strcpy_ServiceType(param, event.ServiceType);
} }
// ADVERT. OR BYEBYE // ADVERT. OR BYEBYE
if( hmsg->is_request ) { if( hmsg->is_request ) {
// use NTS hdr to determine advert., or byebye // use NTS hdr to determine advert., or byebye
// if ( httpmsg_find_hdr( hmsg, HDR_NTS, &hdr_value ) == NULL ) {
if( httpmsg_find_hdr( hmsg, HDR_NTS, &hdr_value ) == NULL ) { // error; NTS header not found
return; // error; NTS header not found goto end_ssdp_handle_ctrlpt_msg;
} }
if( memptr_cmp( &hdr_value, "ssdp:alive" ) == 0 ) { if ( memptr_cmp( &hdr_value, "ssdp:alive" ) == 0 ) {
is_byebye = FALSE; is_byebye = FALSE;
} else if( memptr_cmp( &hdr_value, "ssdp:byebye" ) == 0 ) { } else if( memptr_cmp( &hdr_value, "ssdp:byebye" ) == 0 ) {
is_byebye = TRUE; is_byebye = TRUE;
} else { } else {
return; // bad value // bad value
goto end_ssdp_handle_ctrlpt_msg;
} }
if( is_byebye ) { if ( is_byebye ) {
// check device byebye // check device byebye
if( !nt_found || !usn_found ) { if( !nt_found || !usn_found ) {
return; // bad byebye // bad byebye
goto end_ssdp_handle_ctrlpt_msg;
} }
event_type = UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE; event_type = UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE;
} else { } else {
@ -240,18 +236,19 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
// only. Expires should be greater than 1800 (30 mins) // only. Expires should be greater than 1800 (30 mins)
if( !nt_found || if( !nt_found ||
!usn_found || !usn_found ||
strlen( param.Location ) == 0 || param.Expires <= 0 ) { UpnpString_get_Length(UpnpDiscovery_get_Location(param)) == 0 ||
return; // bad advertisement UpnpDiscovery_get_Expires(param) <= 0 ) {
// bad advertisement
goto end_ssdp_handle_ctrlpt_msg;
} }
event_type = UPNP_DISCOVERY_ADVERTISEMENT_ALIVE; event_type = UPNP_DISCOVERY_ADVERTISEMENT_ALIVE;
} }
// call callback // call callback
ctrlpt_callback( event_type, &param, ctrlpt_cookie ); ctrlpt_callback( event_type, param, ctrlpt_cookie );
} else {
} else // reply (to a SEARCH) // reply (to a SEARCH)
{ //
// only checking to see if there is a valid ST header // only checking to see if there is a valid ST header
st_found = FALSE; st_found = FALSE;
if( httpmsg_find_hdr( hmsg, HDR_ST, &hdr_value ) != NULL ) { if( httpmsg_find_hdr( hmsg, HDR_ST, &hdr_value ) != NULL ) {
@ -261,15 +258,18 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
hdr_value.buf[hdr_value.length] = save_char; hdr_value.buf[hdr_value.length] = save_char;
} }
if( hmsg->status_code != HTTP_OK || if( hmsg->status_code != HTTP_OK ||
param.Expires <= 0 || UpnpDiscovery_get_Expires(param) <= 0 ||
strlen( param.Location ) == 0 || !usn_found || !st_found ) { UpnpString_get_Length(UpnpDiscovery_get_Location(param)) == 0 ||
return; // bad reply !usn_found ||
!st_found ) {
// bad reply
goto end_ssdp_handle_ctrlpt_msg;
} }
// check each current search // check each current search
HandleLock(); HandleLock();
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) { if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
HandleUnlock(); HandleUnlock();
return; goto end_ssdp_handle_ctrlpt_msg;
} }
node = ListHead( &ctrlpt_info->SsdpSearchList ); node = ListHead( &ctrlpt_info->SsdpSearchList );
@ -282,69 +282,58 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
matched = 0; matched = 0;
// check for match of ST header and search target // check for match of ST header and search target
switch ( searchArg->requestType ) { switch ( searchArg->requestType ) {
case SSDP_ALL: case SSDP_ALL:
{
matched = 1; matched = 1;
break; break;
} case SSDP_ROOTDEVICE:
case SSDP_ROOTDEVICE:
{
matched = ( event.RequestType == SSDP_ROOTDEVICE ); matched = ( event.RequestType == SSDP_ROOTDEVICE );
break; break;
} case SSDP_DEVICEUDN:
case SSDP_DEVICEUDN:
{
matched = !( strncmp( searchArg->searchTarget, matched = !( strncmp( searchArg->searchTarget,
hdr_value.buf, hdr_value.buf,
hdr_value.length ) ); hdr_value.length ) );
break; break;
} case SSDP_DEVICETYPE: {
case SSDP_DEVICETYPE: int m = min( hdr_value.length,
{ strlen( searchArg->searchTarget ) );
matched = !( strncmp( searchArg->searchTarget,
hdr_value.buf, m ) );
break;
}
case SSDP_SERVICE: {
int m = min( hdr_value.length, int m = min( hdr_value.length,
strlen( searchArg->searchTarget ) ); strlen( searchArg->searchTarget ) );
matched = !( strncmp( searchArg->searchTarget, matched = !( strncmp( searchArg->searchTarget,
hdr_value.buf, m ) ); hdr_value.buf, m ) );
break; break;
} }
case SSDP_SERVICE: default:
{
int m = min( hdr_value.length,
strlen( searchArg->searchTarget ) );
matched = !( strncmp( searchArg->searchTarget,
hdr_value.buf, m ) );
break;
}
default:
{
matched = 0; matched = 0;
break; break;
}
} }
if( matched ) { if (matched) {
// schedule call back // schedule call back
threadData = threadData = SSDPResultData_new();
( ResultData * ) malloc( sizeof( ResultData ) ); if (threadData != NULL) {
if( threadData != NULL ) { SSDPResultData_set_Param(threadData, param);
threadData->param = param; SSDPResultData_set_Cookie(threadData, searchArg->cookie);
threadData->cookie = searchArg->cookie; SSDPResultData_set_CtrlptCallback(threadData, ctrlpt_callback);
threadData->ctrlpt_callback = ctrlpt_callback; TPJobInit(&job, (start_routine)send_search_result, threadData);
TPJobInit( &job, ( start_routine ) send_search_result, TPJobSetPriority(&job, MED_PRIORITY);
threadData ); TPJobSetFreeFunction(&job, (free_routine)SSDPResultData_delete);
TPJobSetPriority( &job, MED_PRIORITY ); ThreadPoolAdd(&gRecvThreadPool, &job, NULL);
TPJobSetFreeFunction( &job, ( free_routine ) free );
ThreadPoolAdd( &gRecvThreadPool, &job, NULL );
} }
} }
node = ListNext( &ctrlpt_info->SsdpSearchList, node ); node = ListNext( &ctrlpt_info->SsdpSearchList, node );
} }
HandleUnlock(); HandleUnlock();
//ctrlpt_callback( UPNP_DISCOVERY_SEARCH_RESULT, &param, cookie ); //ctrlpt_callback( UPNP_DISCOVERY_SEARCH_RESULT, param, cookie );
} }
end_ssdp_handle_ctrlpt_msg:
UpnpDiscovery_delete(param);
} }
/************************************************************************ /************************************************************************
@ -431,7 +420,6 @@ CreateClientRequestPacket( IN char *RqstBuf,
strcat( RqstBuf, TempBuf ); strcat( RqstBuf, TempBuf );
} }
strcat( RqstBuf, "\r\n" ); strcat( RqstBuf, "\r\n" );
} }
/************************************************************************ /************************************************************************