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
*******************************************************************************

View File

@ -9,7 +9,7 @@
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 # *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:
@ -144,9 +144,25 @@ dnl #AC_SUBST([LT_VERSION_THREADUTIL], [4:3:2])
dnl #AC_SUBST([LT_VERSION_UPNP], [3:5:0])
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_THREADUTIL], [4:3:2])
AC_SUBST([LT_VERSION_UPNP], [3:5:0])
AC_SUBST([LT_VERSION_UPNP], [4:0:0])
dnl ############################################################################
dnl # Repeating the algorithm to place it closer to the modificatin place:
dnl # - library code modified: revision++

View File

@ -19,6 +19,14 @@ LDADD = \
upnpincludedir = $(includedir)/upnp
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/upnpdebug.h
@ -76,6 +84,8 @@ libupnp_la_SOURCES = \
# ssdp
libupnp_la_SOURCES += \
src/ssdp/ssdp_ResultData.c \
src/ssdp/ssdp_ResultData.h \
src/ssdp/ssdp_device.c \
src/ssdp/ssdp_ctrlpt.c \
src/ssdp/ssdp_server.c
@ -110,6 +120,14 @@ libupnp_la_SOURCES += \
src/gena/gena_callback2.c
# 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
if ENABLE_TOOLS
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 SERL_NUMR_SIZE 64
#define MODL_DESC_SIZE 64
#define UPNP_INFINITE -1
#define UPNP_USING_CHUNKED -3
#define UPNP_UNTIL_CLOSE -4
#define UPNP_INFINITE -1
#define UPNP_USING_CHUNKED -3
#define UPNP_UNTIL_CLOSE -4
/** @name Error codes
@ -504,7 +504,22 @@
#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 */
/*! @{ */
@ -536,26 +551,26 @@ enum Upnp_EventType_e {
/** Received by a device when a control point issues a control
* 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. */
UPNP_CONTROL_ACTION_REQUEST,
/** 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. */
UPNP_CONTROL_ACTION_COMPLETE,
/** Received by a device when a query for a single service variable
* 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. */
UPNP_CONTROL_GET_VAR_REQUEST,
/** 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. */
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.
* 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. */
UPNP_DISCOVERY_ADVERTISEMENT_ALIVE,
/** 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
* service. */
@ -580,7 +595,7 @@ enum Upnp_EventType_e {
/** Received by a control point when a matching device or service responds.
* 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. */
UPNP_DISCOVERY_SEARCH_RESULT,
@ -627,12 +642,12 @@ enum Upnp_EventType_e {
/** A {\bf UpnpUnSubscribeAsync} call completed. The status of the
* subscription is in the {\bf Event} parameter as a {\bf
* Upnp_Event_Subscribe} structure. */
* EventSubscribe} structure. */
UPNP_EVENT_UNSUBSCRIBE_COMPLETE,
/** 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
* valid. */
@ -640,7 +655,7 @@ enum Upnp_EventType_e {
/** A client subscription has expired. This will only occur
* 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. */
UPNP_EVENT_SUBSCRIPTION_EXPIRED
@ -708,109 +723,8 @@ enum Upnp_DescType_e {
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. */
struct Upnp_Event
{
/** The subscription ID for this subscription. */
@ -821,76 +735,9 @@ struct Upnp_Event
/** The DOM tree representing the changes generating the event. */
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}
* callback. */
@ -904,37 +751,9 @@ struct Upnp_Subscription_Request
/** The assigned subscription ID for this subscription. */
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. */
typedef void *UpnpWebFileHandle;
@ -945,22 +764,22 @@ typedef void *UpnpWebFileHandle;
*/
struct UpnpVirtualDirCallbacks
{
/** Called by the web server to query information on a file. The callback
* should return 0 on success or -1 on an error. */
int (*get_info) (
IN const char *filename, /** The name of the file to query. */
OUT struct File_Info *info /** Pointer to a structure to store the
/** Called by the web server to query information on a file. The callback
* should return 0 on success or -1 on an error. */
int (*get_info) (
IN const char *filename, /** The name of the file to query. */
OUT UpnpFileInfo *info /** Pointer to a structure to store the
information on the file. */
);
/** 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
* {\tt NULL} to signify an error. */
UpnpWebFileHandle (*open)(
IN const char *filename, /** The name of the file to open. */
IN enum UpnpOpenFileMode Mode /** The mode in which to open the file.
Valid values are {\tt UPNP_READ} or
{\tt UPNP_WRITE}. */
/** 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
* {\tt NULL} to signify an error. */
UpnpWebFileHandle (*open)(
IN const char *filename, /** The name of the file to open. */
IN enum UpnpOpenFileMode Mode /** The mode in which to open the file.
Valid values are {\tt UPNP_READ} or
{\tt UPNP_WRITE}. */
);
/** 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.
*/
typedef int (*Upnp_FunPtr) (
IN Upnp_EventType EventType,
IN void *Event,
IN void *Cookie
);
typedef int (*Upnp_FunPtr)(IN Upnp_EventType EventType, IN void *Event, IN void *Cookie);
/*! @} */ /* Constants, Structures, and Types */
@ -1891,16 +1706,16 @@ EXPORT_SPEC int UpnpRenewSubscription(
INOUT int *TimeOut, /** Pointer to a variable containing the
requested subscription time. Upon return,
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
* to expire, generating a callback when the operation is complete.
*
* 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
* 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.
*
* @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
* complete this operation.
* \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).
* \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).
* \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading
* 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).
* \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).
* \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to
* {\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 (
* returned in the {\bf Upnp_Event_Subscribe.ErrCode} field as
* returned in the {\bf EventSubscribe.ErrCode} field as
* part of the callback).
* \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from
* 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
* 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}
*/
@ -2048,9 +1863,9 @@ EXPORT_SPEC int UpnpSubscribe(
* callback function when the operation is complete.
*
* 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
* 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.
*
* @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
* complete this operation.
* \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).
* \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing
* 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).
* \item {\tt UPNP_E_SOCKET_READ}: An error or timeout occurred reading
* 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).
* \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).
* \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to
* {\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
* socket (returned in the {\bf Upnp_Event_Subscribe.ErrCode}
* socket (returned in the {\bf EventSubscribe.ErrCode}
* field as part of the callback).
* \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from
* 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
* 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}
*/
@ -2141,7 +1956,7 @@ EXPORT_SPEC int UpnpSubscribeAsync(
EXPORT_SPEC int UpnpUnSubscribe(
IN UpnpClient_Handle Hnd, /** The handle of the subscribed 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. */
);
@ -2151,9 +1966,9 @@ EXPORT_SPEC int UpnpUnSubscribe(
* when the operation is complete.
*
* 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
* 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.
*
* @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
* complete this operation.
* \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).
* \item {\tt UPNP_E_SOCKET_WRITE}: An error or timeout occurred writing
* 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
* 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).
* \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).
* \item {\tt UPNP_E_SOCKET_CONNECT}: An error occurred connecting to
* {\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 (
* returned in the {\bf Upnp_Event_Subscribe.ErrCode} field as
* returned in the {\bf EventSubscribe.ErrCode} field as
* part of the callback).
* \item {\tt UPNP_E_BAD_RESPONSE}: An error occurred in response from
* 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
* 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} */
EXPORT_SPEC int UpnpUnSubscribeAsync(

View File

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

View File

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

View File

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

View File

@ -110,11 +110,11 @@ extern ithread_mutex_t DeviceListMutex;
extern UpnpClient_Handle ctrlpt_handle;
void TvCtrlPointPrintHelp( void );
void TvCtrlPointPrintHelp();
int TvCtrlPointDeleteNode(struct TvDeviceNode*);
int TvCtrlPointRemoveDevice(char*);
int TvCtrlPointRemoveAll( void );
int TvCtrlPointRefresh( void );
int TvCtrlPointRemoveDevice(const char *);
int TvCtrlPointRemoveAll();
int TvCtrlPointRefresh();
int TvCtrlPointSendAction(int, int, char *, char **, char **, int);
@ -140,11 +140,11 @@ int TvCtrlPointGetBrightness(int);
int TvCtrlPointGetDevice(int, struct TvDeviceNode **);
int TvCtrlPointPrintList( void );
int TvCtrlPointPrintDevice(int);
void TvCtrlPointAddDevice (IXML_Document *, char *, int);
void TvCtrlPointHandleGetVar(char *,char *,DOMString);
void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
void TvStateUpdate(char*,int, IXML_Document * , char **);
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 *);
void TvCtrlPointVerifyTimeouts(int);
void TvCtrlPointPrintCommands( void );

View File

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

View File

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

View File

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

View File

@ -110,11 +110,11 @@ extern ithread_mutex_t DeviceListMutex;
extern UpnpClient_Handle ctrlpt_handle;
void TvCtrlPointPrintHelp( void );
void TvCtrlPointPrintHelp();
int TvCtrlPointDeleteNode(struct TvDeviceNode*);
int TvCtrlPointRemoveDevice(char*);
int TvCtrlPointRemoveAll( void );
int TvCtrlPointRefresh( void );
int TvCtrlPointRemoveDevice(const char *);
int TvCtrlPointRemoveAll();
int TvCtrlPointRefresh();
int TvCtrlPointSendAction(int, int, char *, char **, char **, int);
@ -140,11 +140,11 @@ int TvCtrlPointGetBrightness(int);
int TvCtrlPointGetDevice(int, struct TvDeviceNode **);
int TvCtrlPointPrintList( void );
int TvCtrlPointPrintDevice(int);
void TvCtrlPointAddDevice (IXML_Document *, char *, int);
void TvCtrlPointHandleGetVar(char *,char *,DOMString);
void TvCtrlPointAddDevice(IXML_Document *, const char *, int);
void TvCtrlPointHandleGetVar(const char *, const char *, const DOMString);
void TvStateUpdate(char*,int, IXML_Document * , char **);
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 *);
void TvCtrlPointVerifyTimeouts(int);
void TvCtrlPointPrintCommands( void );

View File

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

View File

@ -148,8 +148,7 @@ extern char *TvServiceType[];
*
*****************************************************************************/
typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out,
char **errorString);
typedef int (*upnp_action) (IXML_Document *request, IXML_Document **out, char **errorString);
/* Structure for storing Tv Service
identifiers and state table */
@ -193,7 +192,7 @@ extern ithread_mutex_t TVDevMutex;
* struct TvService *out - service containing action table to set.
*
*****************************************************************************/
int SetActionTable(int serviceType, struct TvService * out);
int SetActionTable(int serviceType, struct TvService *out);
/******************************************************************************
* TvDeviceStateTableInit
@ -241,7 +240,7 @@ int TvDeviceHandleSubscriptionRequest(struct Upnp_Subscription_Request *);
* cgv_event -- The control get variable request event structure
*
*****************************************************************************/
int TvDeviceHandleGetVarRequest(struct Upnp_State_Var_Request *);
int TvDeviceHandleGetVarRequest(UpnpStateVarRequest *);
/******************************************************************************
* TvDeviceHandleActionRequest
@ -255,7 +254,7 @@ int TvDeviceHandleGetVarRequest(struct Upnp_State_Var_Request *);
* ca_event -- The control action request event structure
*
*****************************************************************************/
int TvDeviceHandleActionRequest(struct Upnp_Action_Request *);
int TvDeviceHandleActionRequest(UpnpActionRequest *);
/******************************************************************************
* TvDeviceCallbackEventHandler
@ -313,8 +312,7 @@ int TvDeviceSetServiceTableVar(unsigned int, unsigned int, char*);
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out,
OUT char **errorString);
int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDevicePowerOff
@ -329,8 +327,7 @@ int TvDevicePowerOn(IN IXML_Document * in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceSetChannel
@ -347,8 +344,7 @@ int TvDevicePowerOff(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceIncreaseChannel
@ -363,8 +359,7 @@ int TvDeviceSetChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceDecreaseChannel
*
@ -378,8 +373,7 @@ int TvDeviceIncreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceSetVolume
*
@ -395,8 +389,7 @@ int TvDeviceDecreaseChannel(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceIncreaseVolume
@ -411,8 +404,7 @@ int TvDeviceSetVolume(IN IXML_Document *in, OUT IXML_Document **out,
* IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/
int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document**out,
OUT char **errorString);
int TvDeviceIncreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, 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)
*
*****************************************************************************/
int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document**out,
OUT char **errorString);
int TvDeviceDecreaseVolume(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
//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)
*
*****************************************************************************/
int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
@ -465,8 +455,7 @@ int TvDeviceSetColor(IN IXML_Document *in, OUT IXML_Document **out,
* IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/
int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceDecreaseColor
@ -480,8 +469,7 @@ int TvDeviceIncreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
* IXML_Document **out - action result document
* char **errorString - errorString (in case action was unsuccessful)
*****************************************************************************/
int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceSetTint
@ -498,8 +486,7 @@ int TvDeviceDecreaseColor(IN IXML_Document * in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceIncreaseTint
@ -514,8 +501,7 @@ int TvDeviceSetTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceDecreaseTint
@ -530,8 +516,7 @@ int TvDeviceIncreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/*****************************************************************************
* TvDeviceSetContrast
@ -548,8 +533,7 @@ int TvDeviceDecreaseTint(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
****************************************************************************/
int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceIncreaseContrast
@ -565,8 +549,7 @@ int TvDeviceSetContrast(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceDecreaseContrast
*
@ -580,8 +563,7 @@ int TvDeviceIncreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceSetBrightness
@ -595,8 +577,7 @@ int TvDeviceDecreaseContrast(IN IXML_Document *in, OUT IXML_Document **out,
* brightness -- The brightness value to change to.
*
*****************************************************************************/
int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceIncreaseBrightness
@ -611,8 +592,7 @@ int TvDeviceSetBrightness(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
/******************************************************************************
* TvDeviceDecreaseBrightness
@ -626,8 +606,7 @@ int TvDeviceIncreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out,
* char **errorString - errorString (in case action was unsuccessful)
*
*****************************************************************************/
int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out,
OUT char **errorString);
int TvDeviceDecreaseBrightness(IN IXML_Document *in, OUT IXML_Document **out, OUT char **errorString);
int TvDeviceStart(char * ip_address, unsigned short port,char * desc_doc_name,
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
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpSubscribe( IN UpnpClient_Handle Hnd,
IN const char *EvtUrl_const,
INOUT int *TimeOut,
OUT Upnp_SID SubsId )
int UpnpSubscribe(
IN UpnpClient_Handle Hnd,
IN const char *EvtUrl_const,
INOUT int *TimeOut,
OUT Upnp_SID SubsId)
{
struct Handle_Info *SInfo = NULL;
int RetVal;
char *EvtUrl = ( char * )EvtUrl_const;
int retVal;
struct Handle_Info *SInfo = NULL;
UpnpString *EvtUrl = UpnpString_new();
UpnpString *SubsIdTmp = UpnpString_new();
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpSubscribe\n");
if( UpnpSdkInit != 1 ) {
return UPNP_E_FINISH;
}
if (UpnpSdkInit != 1) {
retVal = UPNP_E_FINISH;
goto exit_function;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpSubscribe \n" );
if (EvtUrl == NULL) {
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( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
HandleUnlock();
return UPNP_E_INVALID_HANDLE;
}
if( EvtUrl == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
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 );
if (SubsIdTmp == NULL) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
if (SubsId == NULL) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
UpnpString_set_String(SubsIdTmp, SubsId);
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpSubscribe \n" );
if (TimeOut == NULL) {
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
@ -1872,7 +1893,7 @@ UpnpSubscribe( IN UpnpClient_Handle Hnd,
*
* Parameters:
* 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.
*
* Description:
@ -1883,39 +1904,49 @@ UpnpSubscribe( IN UpnpClient_Handle Hnd,
* Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpUnSubscribe( IN UpnpClient_Handle Hnd,
IN Upnp_SID SubsId )
int UpnpUnSubscribe(IN UpnpClient_Handle Hnd, IN const Upnp_SID SubsId)
{
struct Handle_Info *SInfo = NULL;
int RetVal;
struct Handle_Info *SInfo = NULL;
int retVal;
UpnpString *SubsIdTmp = UpnpString_new();
if( UpnpSdkInit != 1 ) {
return UPNP_E_FINISH;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpUnSubscribe\n");
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpUnSubscribe \n" );
if (UpnpSdkInit != 1) {
retVal = UPNP_E_FINISH;
goto exit_function;
}
HandleReadLock();
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
HandleUnlock();
return UPNP_E_INVALID_HANDLE;
}
if( SubsId == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
HandleUnlock();
RetVal = genaUnSubscribe( Hnd, SubsId );
if (SubsIdTmp == NULL) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
if (SubsId == NULL) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
UpnpString_set_String(SubsIdTmp, SubsId);
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpUnSubscribe \n" );
HandleReadLock();
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
@ -1939,61 +1970,64 @@ UpnpUnSubscribe( IN UpnpClient_Handle Hnd,
* Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd,
IN Upnp_SID SubsId,
IN Upnp_FunPtr Fun,
IN const void *Cookie_const )
int UpnpUnSubscribeAsync(
IN UpnpClient_Handle Hnd,
IN Upnp_SID SubsId,
IN Upnp_FunPtr Fun,
IN const void *Cookie_const )
{
ThreadPoolJob job;
struct Handle_Info *SInfo = NULL;
struct UpnpNonblockParam *Param;
int retVal;
ThreadPoolJob job;
struct Handle_Info *SInfo = NULL;
struct UpnpNonblockParam *Param;
if( UpnpSdkInit != 1 ) {
return UPNP_E_FINISH;
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpUnSubscribeAsync\n");
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpUnSubscribeAsync \n" );
if (UpnpSdkInit != 1) {
retVal = UPNP_E_FINISH;
goto exit_function;
}
HandleReadLock();
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
HandleUnlock();
return UPNP_E_INVALID_HANDLE;
}
if( SubsId == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
if( Fun == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
if (SubsId == NULL) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
if (Fun == NULL) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
HandleUnlock();
Param =
( struct UpnpNonblockParam * )
malloc( sizeof( struct UpnpNonblockParam ) );
if( Param == NULL )
return UPNP_E_OUTOF_MEMORY;
HandleReadLock();
if (GetHandleInfo(Hnd, &SInfo) != HND_CLIENT) {
HandleUnlock();
retVal = UPNP_E_INVALID_HANDLE;
goto exit_function;
}
HandleUnlock();
Param->FunName = UNSUBSCRIBE;
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 );
Param = (struct UpnpNonblockParam *)malloc(sizeof(struct UpnpNonblockParam));
if (Param == NULL) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpUnSubscribeAsync \n" );
Param->FunName = UNSUBSCRIBE;
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
@ -2006,7 +2040,7 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd,
* INOUT int *TimeOut: Pointer to a variable containing the
* requested subscription time. Upon return,
* 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:
* This function renews a subscription that is about to
@ -2015,44 +2049,56 @@ UpnpUnSubscribeAsync( IN UpnpClient_Handle Hnd,
* Return Values: int
* UPNP_E_SUCCESS if successful else sends appropriate error.
***************************************************************************/
int
UpnpRenewSubscription( IN UpnpClient_Handle Hnd,
INOUT int *TimeOut,
IN Upnp_SID SubsId )
int UpnpRenewSubscription(
IN UpnpClient_Handle Hnd,
INOUT int *TimeOut,
IN const Upnp_SID SubsId )
{
struct Handle_Info *SInfo = NULL;
int RetVal;
struct Handle_Info *SInfo = NULL;
int retVal;
UpnpString *SubsIdTmp = UpnpString_new();
if( UpnpSdkInit != 1 ) {
return UPNP_E_FINISH;
}
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "Inside UpnpRenewSubscription\n");
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpRenewSubscription \n" );
if (UpnpSdkInit != 1) {
return UPNP_E_FINISH;
}
HandleReadLock();
if( GetHandleInfo( Hnd, &SInfo ) != HND_CLIENT ) {
HandleUnlock();
return UPNP_E_INVALID_HANDLE;
}
if( TimeOut == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
if( SubsId == NULL ) {
HandleUnlock();
return UPNP_E_INVALID_PARAM;
}
HandleUnlock();
RetVal = genaRenewSubscription( Hnd, SubsId, TimeOut );
if (SubsIdTmp == NULL) {
retVal = UPNP_E_OUTOF_MEMORY;
goto exit_function;
}
if (SubsId == NULL) {
retVal = UPNP_E_INVALID_PARAM;
goto exit_function;
}
UpnpString_set_String(SubsIdTmp, SubsId);
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Exiting UpnpRenewSubscription \n" );
if (TimeOut == NULL) {
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
@ -3344,79 +3390,88 @@ UpnpDownloadXmlDoc( const char *url,
***************************************************************************/
#ifdef INCLUDE_CLIENT_APIS
void
UpnpThreadDistribution( struct UpnpNonblockParam *Param )
UpnpThreadDistribution(struct UpnpNonblockParam *Param)
{
int errCode = 0;
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpThreadDistribution \n" );
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"Inside UpnpThreadDistribution \n" );
switch ( Param->FunName ) {
switch ( Param->FunName ) {
#if EXCLUDE_GENA == 0
case SUBSCRIBE: {
struct Upnp_Event_Subscribe Evt;
Evt.ErrCode = genaSubscribe(
Param->Handle, Param->Url,
( int * )&( Param->TimeOut ),
( char * )Evt.Sid );
strcpy( Evt.PublisherUrl, Param->Url );
Evt.TimeOut = Param->TimeOut;
Param->Fun( UPNP_EVENT_SUBSCRIBE_COMPLETE, &Evt, Param->Cookie );
free( Param );
break;
case SUBSCRIBE: {
EventSubscribe *evt = UpnpEventSubscribe_new();
// cast away constness
UpnpString *sid = (UpnpString *)UpnpEventSubscribe_get_SID(evt);
UpnpEventSubscribe_strcpy_PublisherUrl(evt, Param->Url);
errCode = genaSubscribe(
Param->Handle,
UpnpEventSubscribe_get_PublisherUrl(evt),
(int *)&(Param->TimeOut),
sid);
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: {
struct Upnp_Event_Subscribe Evt;
Evt.ErrCode =
genaUnSubscribe( Param->Handle,
Param->SubsId );
strcpy( ( char * )Evt.Sid, Param->SubsId );
strcpy( Evt.PublisherUrl, "" );
Evt.TimeOut = 0;
Param->Fun( UPNP_EVENT_UNSUBSCRIBE_COMPLETE,
&Evt, Param->Cookie );
free( Param );
break;
EventSubscribe *evt = UpnpEventSubscribe_new();
UpnpEventSubscribe_strcpy_SID(evt, Param->SubsId);
errCode = genaUnSubscribe(
Param->Handle,
UpnpEventSubscribe_get_SID(evt));
UpnpEventSubscribe_set_ErrCode(evt, errCode);
UpnpEventSubscribe_strcpy_PublisherUrl(evt, "");
UpnpEventSubscribe_set_TimeOut(evt, 0);
Param->Fun(UPNP_EVENT_UNSUBSCRIBE_COMPLETE, evt, Param->Cookie);
UpnpEventSubscribe_delete(evt);
free(Param);
break;
}
case RENEW: {
struct Upnp_Event_Subscribe Evt;
Evt.ErrCode =
genaRenewSubscription( Param->Handle,
Param->SubsId,
&( Param->TimeOut ) );
Evt.TimeOut = Param->TimeOut;
strcpy( ( char * )Evt.Sid, Param->SubsId );
Param->Fun( UPNP_EVENT_RENEWAL_COMPLETE, &Evt,
Param->Cookie );
free( Param );
break;
EventSubscribe *evt = UpnpEventSubscribe_new();
UpnpEventSubscribe_strcpy_SID(evt, Param->SubsId);
errCode = genaRenewSubscription(
Param->Handle,
UpnpEventSubscribe_get_SID(evt),
&(Param->TimeOut));
UpnpEventSubscribe_set_ErrCode(evt, errCode);
UpnpEventSubscribe_set_TimeOut(evt, Param->TimeOut);
Param->Fun(UPNP_EVENT_RENEWAL_COMPLETE, evt, Param->Cookie);
UpnpEventSubscribe_delete(evt);
free(Param);
break;
}
#endif // EXCLUDE_GENA == 0
#if EXCLUDE_SOAP == 0
case ACTION: {
struct Upnp_Action_Complete Evt;
Evt.ActionResult = NULL;
Evt.ErrCode =
SoapSendAction( Param->Url, Param->ServiceType,
Param->Act, &Evt.ActionResult );
Evt.ActionRequest = Param->Act;
strcpy( Evt.CtrlUrl, Param->Url );
Param->Fun( UPNP_CONTROL_ACTION_COMPLETE, &Evt,
Param->Cookie );
ixmlDocument_free( Evt.ActionRequest );
ixmlDocument_free( Evt.ActionResult );
free( Param );
break;
UpnpActionComplete *Evt = UpnpActionComplete_new();
IXML_Document *actionResult = NULL;
int errCode = SoapSendAction(
Param->Url, Param->ServiceType, Param->Act, &actionResult );
UpnpActionComplete_set_ErrCode(Evt, errCode);
UpnpActionComplete_set_ActionRequest(Evt, Param->Act);
UpnpActionComplete_set_ActionResult(Evt, actionResult);
UpnpActionComplete_strcpy_CtrlUrl(Evt, Param->Url );
Param->Fun( UPNP_CONTROL_ACTION_COMPLETE, Evt, Param->Cookie );
free(Param);
UpnpActionComplete_delete(Evt);
break;
}
case STATUS: {
struct Upnp_State_Var_Complete Evt;
Evt.ErrCode = SoapGetServiceVarStatus(
Param->Url, Param->VarName, &( Evt.CurrentVal ) );
strcpy( Evt.StateVarName, Param->VarName );
strcpy( Evt.CtrlUrl, Param->Url );
Param->Fun( UPNP_CONTROL_GET_VAR_COMPLETE, &Evt,
Param->Cookie );
free( Evt.CurrentVal );
UpnpStateVarComplete *Evt = UpnpStateVarComplete_new();
DOMString currentVal = NULL;
int errCode = SoapGetServiceVarStatus(
Param->Url, Param->VarName, &currentVal );
UpnpStateVarComplete_set_ErrCode(Evt, errCode);
UpnpStateVarComplete_strcpy_CtrlUrl(Evt, Param->Url);
UpnpStateVarComplete_strcpy_StateVarName(Evt, Param->VarName);
UpnpStateVarComplete_set_CurrentVal(Evt, currentVal);
Param->Fun( UPNP_CONTROL_GET_VAR_COMPLETE, Evt, Param->Cookie );
free( Param );
UpnpStateVarComplete_delete(Evt);
break;
}
#endif // EXCLUDE_SOAP == 0
@ -3441,64 +3496,59 @@ UpnpThreadDistribution( struct UpnpNonblockParam *Param )
* Return Values: Upnp_FunPtr
*
***************************************************************************/
Upnp_FunPtr
GetCallBackFn( UpnpClient_Handle Hnd )
Upnp_FunPtr GetCallBackFn(UpnpClient_Handle Hnd)
{
return ( ( struct Handle_Info * )HandleTable[Hnd] )->Callback;
} /****************** End of GetCallBackFn *********************/
return ((struct Handle_Info *)HandleTable[Hnd])->Callback;
}
/**************************************************************************
* Function: InitHandleList
*
* Parameters: VOID
* Parameters:
*
* Description:
* This function is to initialize handle table
*
* Return Values: VOID
* Return Values:
*
***************************************************************************/
void
InitHandleList()
void InitHandleList()
{
int i;
int i;
for( i = 0; i < NUM_HANDLE; i++ )
HandleTable[i] = NULL;
} /****************** End of InitHandleList *********************/
for (i = 0; i < NUM_HANDLE; ++i) {
HandleTable[i] = NULL;
}
}
/**************************************************************************
* Function: GetFreeHandle
*
* Parameters: VOID
* Parameters:
*
* Description:
* This function is to get a free handle
*
* Return Values: VOID
* Return Values:
* integer greater than zero
* UPNP_E_OUTOF_HANDLE
*
***************************************************************************/
int
GetFreeHandle()
int GetFreeHandle()
{
int i = 1;
/* Handle 0 is not used as NULL translates to 0 when passed as a handle */
int i = 1;
/*
Handle 0 is not used as NULL translates to 0 when passed as a handle
*/
while( i < NUM_HANDLE ) {
if( HandleTable[i++] == NULL )
break;
}
while (i < NUM_HANDLE && HandleTable[i] != NULL) {
++i;
}
if( i == NUM_HANDLE )
return UPNP_E_OUTOF_HANDLE; //Error
else
return --i;
} /****************** End of GetFreeHandle *********************/
if (i == NUM_HANDLE) {
return UPNP_E_OUTOF_HANDLE;
} else {
return i;
}
}
/**************************************************************************
* Function: GetClientHandleInfo
@ -3512,58 +3562,64 @@ GetFreeHandle()
* Description:
* This function is to get client handle info
*
* Return Values: HND_CLIENT
* Return Values: HND_CLIENT, HND_INVALID
*
***************************************************************************/
//Assumes at most one client
Upnp_Handle_Type
GetClientHandleInfo( IN UpnpClient_Handle * client_handle_out,
OUT struct Handle_Info ** HndInfo )
Upnp_Handle_Type GetClientHandleInfo(
IN UpnpClient_Handle *client_handle_out,
OUT struct Handle_Info **HndInfo)
{
( *client_handle_out ) = 1;
if( GetHandleInfo( 1, HndInfo ) == HND_CLIENT ) {
return HND_CLIENT;
}
( *client_handle_out ) = 2;
if( GetHandleInfo( 2, HndInfo ) == HND_CLIENT ) {
return HND_CLIENT;
}
( *client_handle_out ) = -1;
return HND_INVALID;
Upnp_Handle_Type ret = HND_CLIENT;
UpnpClient_Handle client;
} /****************** 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
*
* Parameters:
* IN UpnpDevice_Handle * device_handle_out: device handle pointer
* (key for the client handle structure).
* OUT struct Handle_Info **HndInfo: Device handle structure passed by
* this function.
* IN UpnpDevice_Handle *device_handle_out:
* device handle pointer (key for the client handle structure).
* OUT struct Handle_Info **HndInfo:
* Device handle structure passed by this function.
*
* Description:
* This function is to get device handle info.
*
* Return Values: HND_DEVICE
* Return Values: HND_DEVICE, HND_INVALID
*
***************************************************************************/
Upnp_Handle_Type
GetDeviceHandleInfo( UpnpDevice_Handle * device_handle_out,
struct Handle_Info ** HndInfo )
Upnp_Handle_Type GetDeviceHandleInfo(
UpnpDevice_Handle *device_handle_out,
struct Handle_Info **HndInfo)
{
( *device_handle_out ) = 1;
if( GetHandleInfo( 1, HndInfo ) == HND_DEVICE )
return HND_DEVICE;
Upnp_Handle_Type ret = HND_DEVICE;
UpnpDevice_Handle device;
( *device_handle_out ) = 2;
if( GetHandleInfo( 2, HndInfo ) == HND_DEVICE )
return HND_DEVICE;
( *device_handle_out ) = -1;
if (GetHandleInfo(1, HndInfo) == HND_DEVICE) {
device = 1;
} else if (GetHandleInfo(2, HndInfo) == HND_DEVICE) {
device = 2;
} else {
device = -1;
ret = HND_INVALID;
}
return HND_INVALID;
} /****************** End of GetDeviceHandleInfo *********************/
*device_handle_out = device;
return ret;
}
/**************************************************************************
* Function: GetDeviceHandleInfo
@ -3577,32 +3633,34 @@ GetDeviceHandleInfo( UpnpDevice_Handle * device_handle_out,
* Description:
* This function is to get handle info.
*
* Return Values: HND_DEVICE
* Return Values: HND_DEVICE, UPNP_E_INVALID_HANDLE
*
***************************************************************************/
Upnp_Handle_Type
GetHandleInfo( UpnpClient_Handle Hnd,
struct Handle_Info ** HndInfo )
Upnp_Handle_Type GetHandleInfo(
UpnpClient_Handle Hnd,
struct Handle_Info **HndInfo)
{
Upnp_Handle_Type ret = UPNP_E_INVALID_HANDLE;
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"GetHandleInfo: Handle is %d\n", Hnd );
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"GetHandleInfo: entering, Handle is %d\n", Hnd);
if( Hnd < 1 || Hnd >= NUM_HANDLE ) {
UpnpPrintf( UPNP_INFO, API, __FILE__, __LINE__,
"GetHandleInfo : Handle out of range\n" );
return UPNP_E_INVALID_HANDLE;
}
if( HandleTable[Hnd] != NULL ) {
*HndInfo = ( struct Handle_Info * )HandleTable[Hnd];
return ( ( struct Handle_Info * )*HndInfo )->HType;
}
UpnpPrintf( UPNP_ALL, API, __FILE__, __LINE__,
"GetHandleInfo : exiting\n" );
if (Hnd < 1 || Hnd >= NUM_HANDLE) {
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"GetHandleInfo: Handle out of range\n");
} else if (HandleTable[Hnd] == NULL) {
UpnpPrintf(UPNP_CRITICAL, API, __FILE__, __LINE__,
"GetHandleInfo: HandleTable[%d] is NULL\n",
Hnd);
} else if (HandleTable[Hnd] != NULL) {
*HndInfo = (struct Handle_Info *)HandleTable[Hnd];
ret = ((struct Handle_Info *)*HndInfo)->HType;
}
return UPNP_E_INVALID_HANDLE;
UpnpPrintf(UPNP_ALL, API, __FILE__, __LINE__, "GetHandleInfo: exiting\n");
} /****************** End of GetHandleInfo *********************/
return ret;
}
/**************************************************************************
* Function: FreeHandle
@ -3614,25 +3672,34 @@ GetHandleInfo( UpnpClient_Handle Hnd,
* This function is to to free handle info.
*
* Return Values: int
* UPNP_E_SUCCESS if successful else return appropriate error
* UPNP_E_SUCCESS if successful
* UPNP_E_INVALID_HANDLE if not.
***************************************************************************/
int
FreeHandle( int Upnp_Handle )
int FreeHandle(int Upnp_Handle)
{
if( Upnp_Handle < 1 || Upnp_Handle >= NUM_HANDLE ) {
UpnpPrintf( UPNP_CRITICAL, API, __FILE__, __LINE__,
"FreeHandleInfo : Handle out of range\n" );
return UPNP_E_INVALID_HANDLE;
}
int ret = UPNP_E_INVALID_HANDLE;
if( HandleTable[Upnp_Handle] == NULL ) {
return UPNP_E_INVALID_HANDLE;
}
free( HandleTable[Upnp_Handle] );
HandleTable[Upnp_Handle] = NULL;
return UPNP_E_SUCCESS;
UpnpPrintf(UPNP_INFO, API, __FILE__, __LINE__,
"FreeHandleInfo: entering, Handle is %d\n", Upnp_Handle);
} /****************** 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;
}
/****************** End of PrintHandleInfo *********************/
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
* functions for adding and removing clients to and from the client table,
* adding and accessing subscription and other attributes pertaining to the
* client
************************************************************************/
* Purpose: This file defines the functions for clients. It defines
* functions for adding and removing clients to and from the client table,
* adding and accessing subscription and other attributes pertaining to the
* client
************************************************************************/
#include "config.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;}
/************************************************************************
* 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 );}
}
#ifdef INCLUDE_CLIENT_APIS
sub->RenewEventId = -1;}
}
/************************************************************************
* 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;}
}
#include <stdlib.h> // for calloc(), free()
/************************************************************************
* 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;}
}
}
/************************************************************************
* Function : GetClientSubClientSID
*
* Parameters :
* client_subscription *head ; Head of the subscription list
* const Upnp_SID sid ; Subscription ID to be matched
*
* 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;}
struct SClientSubscription {
int m_renewEventId;
UpnpString *m_SID;
UpnpString *m_actualSID;
UpnpString *m_eventURL;
struct SClientSubscription *m_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 ) )
break;
else
{
next = next->next;}
}
return next;}
/** Constructor */
ClientSubscription *UpnpClientSubscription_new()
{
struct SClientSubscription *p = calloc(1, sizeof (struct SClientSubscription));
#if 0
p->renewEventId = 0;
#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
*
* Parameters:
* IN char* urlstr ; Character string as a URL
* IN int urlstrlen ; Length of the character string
* OUT uri_type* fixed_url ; Fixed and corrected URL
* IN const char* urlstr; Character string as a URL
* IN int urlstrlen; Length of the character string
* OUT uri_type* fixed_url; Fixed and corrected URL
*
* Description:
* Parses URL and then validates URL
@ -138,7 +138,7 @@ http_FixUrl( IN uri_type * url,
* UPNP_E_SUCCESS
************************************************************************/
int
http_FixStrUrl( IN char *urlstr,
http_FixStrUrl( IN const char *urlstr,
IN int urlstrlen,
OUT uri_type * fixed_url )
{

View File

@ -35,22 +35,30 @@
******************************************************************************/
#include "config.h"
#include "webserver.h"
#include <assert.h>
#include <fcntl.h>
#ifndef UPNP_USE_BCBPP
#include <inttypes.h>
#include <stdint.h>
#endif
#include "util.h"
#include "strintmap.h"
#include "membuffer.h"
#endif /* !UPNP_USE_BCBPP */
#include "FileInfo.h"
#include "httpparser.h"
#include "httpreadwrite.h"
#include "membuffer.h"
#include "ssdplib.h"
#include "statcodes.h"
#include "webserver.h"
#include "strintmap.h"
#include "upnp.h"
#include "upnpapi.h"
#include "ssdplib.h"
#include "util.h"
#ifndef WIN32
#include <unistd.h>
@ -279,38 +287,39 @@ search_extension( IN const char *extension,
*
* Parameters:
* IN const char* filename,
* OUT DOMString* content_type
* OUT UpnpFileInfo *fileInfo
*
* Description: Based on the extension, clones an XML string based on
* type and content subtype. If content type and sub type are not
* found, unknown types are used
* Description: Based on the extension, sets the content type of fileInfo
* based on type and content subtype. If content type and sub type
* are not found, unknown types are used
*
* Returns:
* 0 - On Sucess
* UPNP_E_OUTOF_MEMORY - on memory allocation failures
************************************************************************/
UPNP_INLINE int
get_content_type( IN const char *filename,
OUT DOMString * content_type )
get_content_type(
IN const char *filename,
OUT UpnpFileInfo *fileInfo)
{
const char *extension;
const char *type,
*subtype;
const char *type;
const char *subtype;
xboolean ctype_found = FALSE;
char *temp = NULL;
int length = 0;
( *content_type ) = NULL;
UpnpFileInfo_set_ContentType(fileInfo, NULL);
// get ext
extension = strrchr( filename, '.' );
if( extension != NULL ) {
if (extension != NULL) {
if( search_extension( extension + 1, &type, &subtype ) == 0 ) {
ctype_found = TRUE;
}
}
if( !ctype_found ) {
if (!ctype_found) {
// unknown content type
type = gMediaTypes[APPLICATION_INDEX];
subtype = "octet-stream";
@ -318,17 +327,14 @@ get_content_type( IN const char *filename,
length = strlen( type ) + strlen( "/" ) + strlen( subtype ) + 1;
temp = ( char * )malloc( length );
if( !temp ) {
if (!temp) {
return UPNP_E_OUTOF_MEMORY;
}
sprintf( temp, "%s/%s", type, subtype );
( *content_type ) = ixmlCloneDOMString( temp );
UpnpFileInfo_set_ContentType(fileInfo, temp);
free(temp);
free( temp );
if( !content_type ) {
if (!UpnpFileInfo_get_ContentType(fileInfo)) {
return UPNP_E_OUTOF_MEMORY;
}
@ -586,8 +592,8 @@ web_server_destroy( void )
* Function: get_file_info
*
* Parameters:
* IN const char* filename ; Filename having the description document
* OUT struct File_Info * info ; File information object having file
* IN const char *filename; Filename having the description document
* OUT UpnpFileInfo *info; File information object having file
* attributes such as filelength, when was the file last
* modified, whether a file or a directory and whether the
* file or directory is readable.
@ -600,48 +606,50 @@ web_server_destroy( void )
* int
************************************************************************/
static int
get_file_info( IN const char *filename,
OUT struct File_Info *info )
get_file_info(
IN const char *filename,
OUT UpnpFileInfo *info)
{
int code;
struct stat s;
FILE *fp;
int rc = 0;
int code;
struct stat s;
FILE *fp;
int rc = 0;
info->content_type = NULL;
UpnpFileInfo_set_ContentType(info, NULL);
code = stat( filename, &s );
if( code == -1 ) {
return -1;
}
code = stat(filename, &s);
if (code == -1) {
return -1;
}
if( S_ISDIR( s.st_mode ) ) {
info->is_directory = TRUE;
} else if( S_ISREG( s.st_mode ) ) {
info->is_directory = FALSE;
} else {
return -1;
}
if (S_ISDIR(s.st_mode)) {
UpnpFileInfo_set_IsDirectory(info, TRUE);
} else if (S_ISREG(s.st_mode)) {
UpnpFileInfo_set_IsDirectory(info, FALSE);
} else {
return -1;
}
// check readable
fp = fopen( filename, "r" );
info->is_readable = ( fp != NULL );
if( fp ) {
fclose( fp );
}
// check readable
fp = fopen(filename, "r");
UpnpFileInfo_set_IsReadable(info, fp != NULL);
if (fp) {
fclose(fp);
}
info->file_length = s.st_size;
info->last_modified = s.st_mtime;
UpnpFileInfo_set_FileLength(info, s.st_size);
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__,
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
filename, (long long)info->file_length,
asctime( gmtime( &info->last_modified ) ),
info->is_readable );
UpnpPrintf( UPNP_INFO, HTTP, __FILE__, __LINE__,
"file info: %s, length: %lld, last_mod=%s readable=%d\n",
filename,
(long long)UpnpFileInfo_get_FileLength(info),
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
*
* 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
* 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
*
* 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
************************************************************************/
static UPNP_INLINE xboolean
get_alias( IN const char *request_file,
OUT struct xml_alias_t *alias,
OUT struct File_Info *info )
get_alias(
IN const char *request_file,
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 );
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;
return cmp == 0;
}
/************************************************************************
@ -1197,16 +1204,17 @@ process_request( IN http_message_t * req,
int err_code;
char *request_doc;
struct File_Info finfo;
UpnpFileInfo *finfo;
xboolean using_alias;
xboolean using_virtual_dir;
uri_type *url;
char *temp_str;
int resp_major,
resp_minor;
int resp_major;
int resp_minor;
xboolean alias_grabbed;
size_t dummy;
struct UpnpVirtualDirCallbacks *pVirtualDirCallback;
const char *extra_headers;
print_http_headers( req );
@ -1218,7 +1226,7 @@ process_request( IN http_message_t * req,
// init
request_doc = NULL;
finfo.content_type = NULL;
finfo = UpnpFileInfo_new();
alias_grabbed = FALSE;
err_code = HTTP_INTERNAL_SERVER_ERROR; // default error
using_virtual_dir = FALSE;
@ -1261,50 +1269,46 @@ process_request( IN http_message_t * req,
//
// try using alias
//
if( is_valid_alias( &gAliasDoc ) ) {
alias_grab( alias );
if (is_valid_alias(&gAliasDoc)) {
alias_grab(alias);
alias_grabbed = TRUE;
using_alias = get_alias( request_doc, alias, &finfo );
if( using_alias == TRUE ) {
finfo.content_type = ixmlCloneDOMString( "text/xml" );
if( finfo.content_type == NULL ) {
using_alias = get_alias(request_doc, alias, finfo);
if (using_alias == TRUE) {
UpnpFileInfo_set_ContentType(finfo, "text/xml");
if (UpnpFileInfo_get_ContentType(finfo) == NULL) {
goto error_handler;
}
}
}
}
if( using_virtual_dir ) {
if( req->method != HTTPMETHOD_POST ) {
if (using_virtual_dir) {
if (req->method != HTTPMETHOD_POST) {
// get file info
pVirtualDirCallback = &virtualDirCallback;
if( pVirtualDirCallback->get_info( filename->buf, &finfo ) !=
0 ) {
if (pVirtualDirCallback->get_info(filename->buf, finfo) != 0) {
err_code = HTTP_NOT_FOUND;
goto error_handler;
}
// try index.html if req is a dir
if( finfo.is_directory ) {
if( filename->buf[filename->length - 1] == '/' ) {
if (UpnpFileInfo_get_IsDirectory(finfo)) {
if (filename->buf[filename->length - 1] == '/') {
temp_str = "index.html";
} else {
temp_str = "/index.html";
}
if( membuffer_append_str( filename, temp_str ) != 0 ) {
if ( membuffer_append_str(filename, temp_str) != 0) {
goto error_handler;
}
// get info
if( ( pVirtualDirCallback->
get_info( filename->buf, &finfo ) != UPNP_E_SUCCESS )
|| finfo.is_directory ) {
if( pVirtualDirCallback->get_info(filename->buf, finfo) != UPNP_E_SUCCESS ||
UpnpFileInfo_get_IsDirectory(finfo)) {
err_code = HTTP_NOT_FOUND;
goto error_handler;
}
}
// not readable
if( !finfo.is_readable ) {
if (!UpnpFileInfo_get_IsReadable(finfo)) {
err_code = HTTP_FORBIDDEN;
goto error_handler;
}
@ -1314,7 +1318,7 @@ process_request( IN http_message_t * req,
// goto error_handler;
// }
}
} else if( !using_alias ) {
} else if (!using_alias) {
if( gDocumentRootDir.length == 0 ) {
goto error_handler;
}
@ -1335,12 +1339,12 @@ process_request( IN http_message_t * req,
if( req->method != HTTPMETHOD_POST ) {
// 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;
goto error_handler;
}
// try index.html if req is a dir
if( finfo.is_directory ) {
if (UpnpFileInfo_get_IsDirectory(finfo)) {
if( filename->buf[filename->length - 1] == '/' ) {
temp_str = "index.html";
} else {
@ -1350,14 +1354,14 @@ process_request( IN http_message_t * req,
goto error_handler;
}
// get info
if( get_file_info( filename->buf, &finfo ) != 0 ||
finfo.is_directory ) {
if (get_file_info(filename->buf, finfo) != 0 ||
UpnpFileInfo_get_IsDirectory(finfo)) {
err_code = HTTP_NOT_FOUND;
goto error_handler;
}
}
// not readable
if( !finfo.is_readable ) {
if (!UpnpFileInfo_get_IsReadable(finfo)) {
err_code = HTTP_FORBIDDEN;
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.
if( ( err_code =
CheckOtherHTTPHeaders( req, RespInstr,
finfo.file_length ) ) != HTTP_OK ) {
err_code =
CheckOtherHTTPHeaders(req, RespInstr, UpnpFileInfo_get_FileLength(finfo));
if ( err_code != HTTP_OK ) {
goto error_handler;
}
@ -1385,34 +1389,40 @@ process_request( IN http_message_t * req,
goto error_handler;
}
extra_headers = UpnpFileInfo_get_ExtraHeaders(finfo);
if (!extra_headers) {
extra_headers = "";
}
if( RespInstr->IsRangeActive && RespInstr->IsChunkActive ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "T" "GKD" "s" "tcS" "XcCc",
HTTP_PARTIAL_CONTENT, // status code
finfo.content_type, // content type
RespInstr, // range info
"R" "T" "GKD" "s" "tcS" "Xc" "sCc",
HTTP_PARTIAL_CONTENT, // status code
UpnpFileInfo_get_ContentType(finfo), // content type
RespInstr, // range info
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler;
}
} else if( RespInstr->IsRangeActive && !RespInstr->IsChunkActive ) {
// Content-Range: bytes 222-3333/4000 HTTP_PARTIAL_CONTENT
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "N" "T" "GD" "s" "tcS" "XcCc",
HTTP_PARTIAL_CONTENT, // status code
RespInstr->ReadSendSize, // content length
finfo.content_type, // content type
RespInstr, // range info
"R" "N" "T" "GD" "s" "tcS" "Xc" "sCc",
HTTP_PARTIAL_CONTENT, // status code
RespInstr->ReadSendSize, // content length
UpnpFileInfo_get_ContentType(finfo), // content type
RespInstr, // range info
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler;
}
@ -1421,12 +1431,13 @@ process_request( IN http_message_t * req,
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"RK" "TD" "s" "tcS" "XcCc",
HTTP_OK, // status code
finfo.content_type, // content type
"RK" "TD" "s" "tcS" "Xc" "sCc",
HTTP_OK, // status code
UpnpFileInfo_get_ContentType(finfo), // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler;
}
@ -1436,13 +1447,14 @@ process_request( IN http_message_t * req,
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "N" "TD" "s" "tcS" "XcCc",
HTTP_OK, // status code
RespInstr->ReadSendSize, // content length
finfo.content_type, // content type
"R" "N" "TD" "s" "tcS" "Xc" "sCc",
HTTP_OK, // status code
RespInstr->ReadSendSize, // content length
UpnpFileInfo_get_ContentType(finfo), // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler;
}
} else {
@ -1450,12 +1462,13 @@ process_request( IN http_message_t * req,
// Transfer-Encoding: chunked
if (http_MakeMessage(
headers, resp_major, resp_minor,
"R" "TD" "s" "tcS" "XcCc",
HTTP_OK, // status code
finfo.content_type, // content type
"R" "TD" "s" "tcS" "b" "Xc" "sCc",
HTTP_OK, // status code
UpnpFileInfo_get_ContentType(finfo), // content type
"LAST-MODIFIED: ",
&finfo.last_modified,
X_USER_AGENT) != 0 ) {
UpnpFileInfo_get_LastModified(finfo),
X_USER_AGENT,
extra_headers) != 0 ) {
goto error_handler;
}
}
@ -1481,11 +1494,11 @@ process_request( IN http_message_t * req,
err_code = UPNP_E_SUCCESS;
error_handler:
free( request_doc );
ixmlFreeDOMString( finfo.content_type );
if( err_code != UPNP_E_SUCCESS && alias_grabbed ) {
alias_release( alias );
error_handler:
free(request_doc);
UpnpFileInfo_delete(finfo);
if (err_code != UPNP_E_SUCCESS && alias_grabbed) {
alias_release(alias);
}
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
extern "C" {
#endif
#include "upnp.h"
#include <stdio.h>
//#include <malloc.h>
#include <stdlib.h>
#include <time.h>
#include "uri.h"
#include "service_table.h"
#include "service_table.h"
#include "String.h" // for UpnpString
#include "TimerThread.h"
#include "upnp.h"
#include "upnp_timeout.h"
#include "uri.h"
extern TimerThread gTimerThread;
CLIENTONLY(
typedef struct CLIENT_SUBSCRIPTION {
Upnp_SID sid;
char * ActualSID;
char * EventURL;
int RenewEventId;
struct CLIENT_SUBSCRIPTION * next;
} client_subscription;
/************************************************************************
* 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 :
************************************************************************/
int copy_client_subscription(client_subscription * in, client_subscription * out);
#ifdef INCLUDE_CLIENT_APIS
typedef struct {} ClientSubscription;
/** Constructor */
ClientSubscription *UpnpClientSubscription_new();
/** Destructor */
void UpnpClientSubscription_delete(ClientSubscription *p);
/** Copy Constructor */
ClientSubscription *UpnpClientSubscription_dup(const ClientSubscription *p);
/** 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
*
* Parameters :
* client_subscription * list ; Client subscription
*
* Description : Free the client subscription table.
*
* Return : void ;
*
* Note :
************************************************************************/
void freeClientSubList(client_subscription * list);
* Function: free_client_subscription
*
* Parameters:
* ClientSubscription *sub; - Client subscription to be freed
*
* Description: Free memory allocated for client subscription data.
* Remove timer thread associated with this subscription event.
************************************************************************/
void free_client_subscription(ClientSubscription * sub);
/************************************************************************
* 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);
* Function: freeClientSubList
*
* Parameters:
* ClientSubscription *list; Client subscription
*
* Description: Free the client subscription table.
*
* Return: void
************************************************************************/
void freeClientSubList(ClientSubscription *list);
/************************************************************************
* Function : GetClientSubClientSID
*
* Parameters :
* client_subscription *head ; Head of the subscription list
* const Upnp_SID sid ; Subscription ID to be matched
*
* 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);
* Function: RemoveClientSubClientSID
*
* Parameters:
* ClientSubscription **head; Head of the subscription list
* const UpnpString 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
************************************************************************/
void RemoveClientSubClientSID(ClientSubscription **head, const UpnpString *sid);
/************************************************************************
* 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);
)
* Function: GetClientSubClientSID
*
* Parameters:
* ClientSubscription *head; Head of the subscription list
* const UpnpString *sid; Subscription ID to be matched
*
* Description: Return the client subscription from the client table
* that matches const Upnp_SID sid subscrition id value.
*
* Return: ClientSubscription * The matching subscription
************************************************************************/
ClientSubscription *GetClientSubClientSID(
ClientSubscription *head,
const UpnpString *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
}
#endif
#endif /* __cplusplus */
#endif /* CLIENT_TABLE_H */
#endif /* _CLIENT_TABLE */

View File

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

View File

@ -88,7 +88,7 @@ struct Handle_Info
// Client only
#ifdef INCLUDE_CLIENT_APIS
client_subscription *ClientSubList; //client subscription list
ClientSubscription *ClientSubList; //client subscription list
LinkedList SsdpSearchList; // active ssdp searches
#endif
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"
#include "upnpapi.h"
#include "parsetools.h"
#include "statcodes.h"
#include "ActionRequest.h"
#include "httpparser.h"
#include "httpreadwrite.h"
#include "unixutil.h"
#include "parsetools.h"
#include "soaplib.h"
#include "ssdplib.h"
#include "statcodes.h"
#include "unixutil.h"
#include "upnpapi.h"
#ifdef WIN32
#define snprintf _snprintf
@ -569,10 +572,10 @@ check_soap_action_header( IN http_message_t * request,
* IN http_message_t* request : HTTP request
* IN int isQuery : flag for a querry
* IN IXML_Document *actionDoc : action request document
* OUT char device_udn[LINE_SIZE] : Device UDN string
* OUT char service_id[LINE_SIZE] : Service ID string
* OUT UpnpString *device_udn : Device UDN string
* OUT UpnpString *service_id : Service ID string
* OUT Upnp_FunPtr *callback : callback function of the device
* application
* application
* OUT void** cookie : cookie stored by device application
*
* Description : This function retrives all the information needed to
@ -586,12 +589,12 @@ check_soap_action_header( IN http_message_t * request,
* Note :
****************************************************************************/
static int
get_device_info( IN http_message_t * request,
get_device_info( IN http_message_t *request,
IN int isQuery,
IN IXML_Document * actionDoc,
OUT char device_udn[LINE_SIZE],
OUT char service_id[LINE_SIZE],
OUT Upnp_FunPtr * callback,
IN IXML_Document *actionDoc,
OUT UpnpString *device_udn,
OUT UpnpString *service_id,
OUT Upnp_FunPtr *callback,
OUT void **cookie )
{
struct Handle_Info *device_info;
@ -654,8 +657,8 @@ get_device_info( IN http_message_t * request,
}
}
namecopy( service_id, serv_info->serviceId );
namecopy( device_udn, serv_info->UDN );
UpnpString_set_String( device_udn, serv_info->UDN );
UpnpString_set_String( service_id, serv_info->serviceId );
*callback = device_info->Callback;
*cookie = device_info->Cookie;
@ -845,10 +848,10 @@ handle_query_variable( IN SOCKINFO * info,
IN http_message_t * request,
IN IXML_Document * xml_doc )
{
UpnpStateVarRequest *variable = UpnpStateVarRequest_new();
Upnp_FunPtr soap_event_callback;
void *cookie;
char var_name[LINE_SIZE];
struct Upnp_State_Var_Request variable;
const char *err_str;
int err_code;
@ -859,49 +862,50 @@ handle_query_variable( IN SOCKINFO * info,
return;
}
// get info for event
if( get_device_info( request, 1, xml_doc, variable.DevUDN,
variable.ServiceID,
&soap_event_callback, &cookie ) != 0 ) {
err_code = get_device_info(
request, 1, xml_doc,
(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,
Soap_Invalid_Var, request );
return;
}
linecopy( variable.ErrStr, "" );
variable.ErrCode = UPNP_E_SUCCESS;
namecopy( variable.StateVarName, var_name );
variable.CurrentVal = NULL;
variable.CtrlPtIPAddr = info->foreign_ip_addr;
UpnpStateVarRequest_set_ErrCode(variable, UPNP_E_SUCCESS);
UpnpStateVarRequest_strcpy_StateVarName(variable, var_name);
UpnpStateVarRequest_set_CtrlPtIPAddr(variable, &info->foreign_ip_addr);
// 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__,
"Return from callback for var request\n" );
// validate, and handle result
if( variable.CurrentVal == NULL ) {
if( UpnpStateVarRequest_get_CurrentVal(variable) == NULL ) {
err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed;
send_error_response( info, SOAP_INVALID_VAR,
Soap_Invalid_Var, request );
send_error_response( info, SOAP_INVALID_VAR, Soap_Invalid_Var, request );
return;
}
if( variable.ErrCode != UPNP_E_SUCCESS ) {
if( strlen( variable.ErrStr ) > 0 ) {
if( UpnpStateVarRequest_get_ErrCode(variable) != UPNP_E_SUCCESS ) {
if( UpnpString_get_Length(UpnpStateVarRequest_get_ErrStr(variable)) > 0 ) {
err_code = SOAP_INVALID_VAR;
err_str = Soap_Invalid_Var;
} else {
err_code = variable.ErrCode;
err_str = variable.ErrStr;
err_code = UpnpStateVarRequest_get_ErrCode(variable);
err_str = UpnpString_get_String(UpnpStateVarRequest_get_ErrStr(variable));
}
send_error_response( info, err_code, err_str, request );
return;
}
// send response
send_var_query_response( info, variable.CurrentVal, request );
ixmlFreeDOMString( variable.CurrentVal );
send_var_query_response( info, UpnpStateVarRequest_get_CurrentVal(variable), request );
UpnpStateVarRequest_delete(variable);
}
/****************************************************************************
@ -929,15 +933,16 @@ handle_invoke_action( IN SOCKINFO * info,
IN IXML_Document * xml_doc )
{
char save_char;
IXML_Document *resp_node = NULL;
struct Upnp_Action_Request action;
UpnpActionRequest *action = UpnpActionRequest_new();
UpnpString *devUDN = UpnpString_new();
UpnpString *serviceID = UpnpString_new();
IXML_Document *actionRequestDoc = NULL;
IXML_Document *actionResultDoc = NULL;
Upnp_FunPtr soap_event_callback;
void *cookie = NULL;
int err_code;
const char *err_str;
action.ActionResult = NULL;
// null-terminate
save_char = action_name.buf[action_name.length];
action_name.buf[action_name.length] = '\0';
@ -947,59 +952,66 @@ handle_invoke_action( IN SOCKINFO * info,
err_str = Soap_Invalid_Action;
// 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;
}
// get device info for action event
err_code = get_device_info( request, 0, xml_doc, action.DevUDN,
action.ServiceID, &soap_event_callback,
&cookie );
err_code = get_device_info(
request,
0,
xml_doc,
devUDN,
serviceID,
&soap_event_callback,
&cookie );
if( err_code != UPNP_E_SUCCESS ) {
goto error_handler;
}
namecopy( action.ActionName, action_name.buf );
linecopy( action.ErrStr, "" );
action.ActionRequest = resp_node;
action.ActionResult = NULL;
action.ErrCode = UPNP_E_SUCCESS;
action.CtrlPtIPAddr = info->foreign_ip_addr;
UpnpActionRequest_set_ErrCode(action, UPNP_E_SUCCESS);
UpnpActionRequest_strcpy_ErrStr(action, "");
UpnpActionRequest_strcpy_ActionName(action, action_name.buf);
UpnpActionRequest_set_DevUDN(action, devUDN);
UpnpActionRequest_set_ServiceID(action, serviceID);
UpnpActionRequest_set_ActionRequest(action, actionRequestDoc);
UpnpActionRequest_set_CtrlPtIPAddr(action, &info->foreign_ip_addr);
UpnpPrintf( UPNP_INFO, SOAP, __FILE__, __LINE__,
"Calling Callback\n" );
UpnpPrintf(UPNP_INFO, SOAP, __FILE__, __LINE__, "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 ) {
if( strlen( action.ErrStr ) <= 0 ) {
err_code = UpnpActionRequest_get_ErrCode(action);
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_str = Soap_Action_Failed;
} else {
err_code = action.ErrCode;
err_str = action.ErrStr;
}
goto error_handler;
}
// validate, and handle action error
if( action.ActionResult == NULL ) {
actionResultDoc = UpnpActionRequest_get_ActionResult(action);
if (actionResultDoc == NULL) {
err_code = SOAP_ACTION_FAILED;
err_str = Soap_Action_Failed;
goto error_handler;
}
// send response
send_action_response( info, action.ActionResult, request );
send_action_response(info, actionResultDoc, request);
err_code = 0;
// error handling and cleanup
error_handler:
ixmlDocument_free( action.ActionResult );
ixmlDocument_free( resp_node );
error_handler:
action_name.buf[action_name.length] = save_char; // restore
if( err_code != 0 ) {
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
#if EXCLUDE_SSDP == 0
#include "ssdp_ResultData.h"
#include "ssdplib.h"
#include "upnpapi.h"
#include <stdio.h>
@ -53,64 +54,67 @@
/************************************************************************
* Function : send_search_result
*
* Parameters:
* IN void *data: Search reply from the device
*
* Description:
* This function sends a callback to the control point application with
* a SEARCH result
*
* Returns: void
*
***************************************************************************/
void
send_search_result( IN void *data )
* Function: send_search_result
*
* Parameters:
* IN void *data: Search reply from the device
*
* Description:
* This function sends a callback to the control point application with
* a SEARCH result
*
* Returns: void
*
***************************************************************************/
void send_search_result(IN void *data)
{
ResultData *temp = ( ResultData * ) data;
SSDPResultData *temp = (SSDPResultData *)data;
temp->ctrlpt_callback( UPNP_DISCOVERY_SEARCH_RESULT,
&temp->param, temp->cookie );
free( temp );
SSDPResultData_Callback(temp);
SSDPResultData_delete(temp);
}
/************************************************************************
* Function : ssdp_handle_ctrlpt_msg
*
* Parameters:
* IN http_message_t* hmsg: SSDP message from the device
* IN struct sockaddr_in* dest_addr: Address of the device
* IN xboolean timeout: timeout kept by the control point while
* sending search message
* IN void* cookie: Cookie stored by the control point application.
* This cookie will be returned to the control point
* in the callback
*
* Description:
* This function handles the ssdp messages from the devices. These
* messages includes the search replies, advertisement of device coming
* alive and bye byes.
*
* Returns: void
*
***************************************************************************/
void
ssdp_handle_ctrlpt_msg( 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
* Function: ssdp_handle_ctrlpt_msg
*
* Parameters:
* IN http_message_t *hmsg:
* SSDP message from the device
* IN struct sockaddr_in *dest_addr:
* Address of the device
* IN xboolean timeout:
* timeout kept by the control point while
* sending search message
* IN void* cookie:
* Cookie stored by the control point application.
* This cookie will be returned to the control point
* in the callback
*
* Description:
* This function handles the ssdp messages from the devices. These
* messages includes the search replies, advertisement of device coming
* alive and bye byes.
*
* Returns: void
*
***************************************************************************/
void ssdp_handle_ctrlpt_msg(
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;
struct Handle_Info *ctrlpt_info = NULL;
memptr hdr_value;
xboolean is_byebye; // byebye or alive
struct Upnp_Discovery param;
UpnpDiscovery *param = UpnpDiscovery_new();
int expires;
int ret;
SsdpEvent event;
xboolean nt_found,
usn_found,
st_found;
xboolean nt_found;
xboolean usn_found;
xboolean st_found;
char save_char;
Upnp_EventType event_type;
Upnp_FunPtr ctrlpt_callback;
@ -118,16 +122,16 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
ListNode *node = NULL;
SsdpSearchArg *searchArg = NULL;
int matched = 0;
ResultData *threadData;
SSDPResultData *threadData = NULL;
ThreadPoolJob job;
// we are assuming that there can be only one client supported at a time
HandleReadLock();
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
if ( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
HandleUnlock();
return;
goto end_ssdp_handle_ctrlpt_msg;
}
// copy
ctrlpt_callback = ctrlpt_info->Callback;
@ -135,103 +139,95 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
HandleUnlock();
// search timeout
if( timeout ) {
if ( timeout ) {
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
param.Expires = -1; // assume error
if( httpmsg_find_hdr( hmsg, HDR_CACHE_CONTROL, &hdr_value ) != NULL ) {
if( matchstr( hdr_value.buf, hdr_value.length,
"%imax-age = %d%0", &param.Expires ) != PARSE_OK )
return;
// assume error
expires = -1;
UpnpDiscovery_set_Expires(param, expires);
if ( httpmsg_find_hdr( hmsg, HDR_CACHE_CONTROL, &hdr_value ) != NULL ) {
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
param.Date[0] = '\0';
if( httpmsg_find_hdr( hmsg, HDR_DATE, &hdr_value ) != NULL ) {
linecopylen( param.Date, hdr_value.buf, hdr_value.length );
if ( httpmsg_find_hdr( hmsg, HDR_DATE, &hdr_value ) != NULL ) {
UpnpDiscovery_strcpy_Date(param, hdr_value.buf);
}
// dest addr
memcpy(&param.DestAddr, dest_addr, sizeof(struct sockaddr_in) );
UpnpDiscovery_set_DestAddr(param, dest_addr);
// EXT
param.Ext[0] = '\0';
if( httpmsg_find_hdr( hmsg, HDR_EXT, &hdr_value ) != NULL ) {
linecopylen( param.Ext, hdr_value.buf, hdr_value.length );
if ( httpmsg_find_hdr( hmsg, HDR_EXT, &hdr_value ) != NULL ) {
UpnpDiscovery_strncpy_Ext(param, hdr_value.buf, hdr_value.length);
}
// LOCATION
param.Location[0] = '\0';
if( httpmsg_find_hdr( hmsg, HDR_LOCATION, &hdr_value ) != NULL ) {
linecopylen( param.Location, hdr_value.buf, hdr_value.length );
if ( httpmsg_find_hdr( hmsg, HDR_LOCATION, &hdr_value ) != NULL ) {
UpnpDiscovery_strncpy_Location(param, hdr_value.buf, hdr_value.length);
}
// 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 ) {
linecopylen( param.Os, hdr_value.buf, hdr_value.length );
UpnpDiscovery_strncpy_Os(param, hdr_value.buf, hdr_value.length);
}
// 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.DeviceType[0] = '\0';
event.ServiceType[0] = '\0';
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];
hdr_value.buf[hdr_value.length] = '\0';
nt_found = ( ssdp_request_type( hdr_value.buf, &event ) == 0 );
hdr_value.buf[hdr_value.length] = save_char;
}
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];
hdr_value.buf[hdr_value.length] = '\0';
usn_found = ( unique_service_name( hdr_value.buf, &event ) == 0 );
hdr_value.buf[hdr_value.length] = save_char;
}
if( nt_found || usn_found ) {
strcpy( param.DeviceId, event.UDN );
strcpy( param.DeviceType, event.DeviceType );
strcpy( param.ServiceType, event.ServiceType );
if ( nt_found || usn_found ) {
UpnpDiscovery_strcpy_DeviceID( param, event.UDN);
UpnpDiscovery_strcpy_DeviceType( param, event.DeviceType);
UpnpDiscovery_strcpy_ServiceType(param, event.ServiceType);
}
// ADVERT. OR BYEBYE
if( hmsg->is_request ) {
// use NTS hdr to determine advert., or byebye
//
if( httpmsg_find_hdr( hmsg, HDR_NTS, &hdr_value ) == NULL ) {
return; // error; NTS header not found
if ( httpmsg_find_hdr( hmsg, HDR_NTS, &hdr_value ) == NULL ) {
// 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;
} else if( memptr_cmp( &hdr_value, "ssdp:byebye" ) == 0 ) {
is_byebye = TRUE;
} else {
return; // bad value
// bad value
goto end_ssdp_handle_ctrlpt_msg;
}
if( is_byebye ) {
if ( is_byebye ) {
// check device byebye
if( !nt_found || !usn_found ) {
return; // bad byebye
// bad byebye
goto end_ssdp_handle_ctrlpt_msg;
}
event_type = UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE;
} else {
@ -240,18 +236,19 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
// only. Expires should be greater than 1800 (30 mins)
if( !nt_found ||
!usn_found ||
strlen( param.Location ) == 0 || param.Expires <= 0 ) {
return; // bad advertisement
UpnpString_get_Length(UpnpDiscovery_get_Location(param)) == 0 ||
UpnpDiscovery_get_Expires(param) <= 0 ) {
// bad advertisement
goto end_ssdp_handle_ctrlpt_msg;
}
event_type = UPNP_DISCOVERY_ADVERTISEMENT_ALIVE;
}
// call callback
ctrlpt_callback( event_type, &param, ctrlpt_cookie );
} else // reply (to a SEARCH)
{
ctrlpt_callback( event_type, param, ctrlpt_cookie );
} else {
// reply (to a SEARCH)
//
// only checking to see if there is a valid ST header
st_found = FALSE;
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;
}
if( hmsg->status_code != HTTP_OK ||
param.Expires <= 0 ||
strlen( param.Location ) == 0 || !usn_found || !st_found ) {
return; // bad reply
UpnpDiscovery_get_Expires(param) <= 0 ||
UpnpString_get_Length(UpnpDiscovery_get_Location(param)) == 0 ||
!usn_found ||
!st_found ) {
// bad reply
goto end_ssdp_handle_ctrlpt_msg;
}
// check each current search
HandleLock();
if( GetClientHandleInfo( &handle, &ctrlpt_info ) != HND_CLIENT ) {
HandleUnlock();
return;
goto end_ssdp_handle_ctrlpt_msg;
}
node = ListHead( &ctrlpt_info->SsdpSearchList );
@ -282,69 +282,58 @@ ssdp_handle_ctrlpt_msg( IN http_message_t * hmsg,
matched = 0;
// check for match of ST header and search target
switch ( searchArg->requestType ) {
case SSDP_ALL:
{
case SSDP_ALL:
matched = 1;
break;
}
case SSDP_ROOTDEVICE:
{
case SSDP_ROOTDEVICE:
matched = ( event.RequestType == SSDP_ROOTDEVICE );
break;
}
case SSDP_DEVICEUDN:
{
case SSDP_DEVICEUDN:
matched = !( strncmp( searchArg->searchTarget,
hdr_value.buf,
hdr_value.length ) );
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,
strlen( searchArg->searchTarget ) );
matched = !( strncmp( searchArg->searchTarget,
hdr_value.buf, m ) );
break;
}
case SSDP_SERVICE:
{
int m = min( hdr_value.length,
strlen( searchArg->searchTarget ) );
matched = !( strncmp( searchArg->searchTarget,
hdr_value.buf, m ) );
break;
}
default:
{
}
default:
matched = 0;
break;
}
}
if( matched ) {
if (matched) {
// schedule call back
threadData =
( ResultData * ) malloc( sizeof( ResultData ) );
if( threadData != NULL ) {
threadData->param = param;
threadData->cookie = searchArg->cookie;
threadData->ctrlpt_callback = ctrlpt_callback;
TPJobInit( &job, ( start_routine ) send_search_result,
threadData );
TPJobSetPriority( &job, MED_PRIORITY );
TPJobSetFreeFunction( &job, ( free_routine ) free );
ThreadPoolAdd( &gRecvThreadPool, &job, NULL );
threadData = SSDPResultData_new();
if (threadData != NULL) {
SSDPResultData_set_Param(threadData, param);
SSDPResultData_set_Cookie(threadData, searchArg->cookie);
SSDPResultData_set_CtrlptCallback(threadData, ctrlpt_callback);
TPJobInit(&job, (start_routine)send_search_result, threadData);
TPJobSetPriority(&job, MED_PRIORITY);
TPJobSetFreeFunction(&job, (free_routine)SSDPResultData_delete);
ThreadPoolAdd(&gRecvThreadPool, &job, NULL);
}
}
node = ListNext( &ctrlpt_info->SsdpSearchList, node );
}
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, "\r\n" );
}
/************************************************************************