libUPnP  1.8.4
sample_util.h
Go to the documentation of this file.
1 #ifndef SAMPLE_UTIL_H
2 #define SAMPLE_UTIL_H
3 
4 /*******************************************************************************
5  *
6  * Copyright (c) 2000-2003 Intel Corporation
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * - Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  * - Redistributions in binary form must reproduce the above copyright notice,
15  * this list of conditions and the following disclaimer in the documentation
16  * and/or other materials provided with the distribution.
17  * - Neither name of Intel Corporation nor the names of its contributors
18  * may be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
25  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
29  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  ******************************************************************************/
34 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif /* __cplusplus */
46 
47 #include "ithread.h"
48 #include "ixml.h" /* for IXML_Document, IXML_Element */
49 #include "upnp.h" /* for Upnp_EventType */
50 #include "upnptools.h"
51 
52 #include <stdlib.h>
53 #include <string.h>
54 
55 #ifdef SAMPLE_UTIL_C
56 
57  const char *TvServiceType[] = {
58  "urn:schemas-upnp-org:service:tvcontrol:1",
59  "urn:schemas-upnp-org:service:tvpicture:1"
60  };
61 #else /* SAMPLE_UTIL_C */
62  extern const char *TvServiceType[];
63 #endif /* SAMPLE_UTIL_C */
64 
65 /* mutex to control displaying of events */
66 extern ithread_mutex_t display_mutex;
67 
68 typedef enum {
69  STATE_UPDATE = 0,
70  DEVICE_ADDED = 1,
71  DEVICE_REMOVED = 2,
72  GET_VAR_COMPLETE = 3
73 } eventType;
74 
84  IXML_Element *element);
85 
97  IXML_Document *doc);
98 
106  IXML_Document *doc,
108  const char *item);
109 
117  IXML_Element *element,
119  const char *item);
120 
126  Upnp_EventType S);
127 
133  Upnp_EventType EventType,
135  const void *Event);
136 
145  IXML_Document *DescDoc,
147  const char *location,
149  const char *serviceType,
151  char **serviceId,
153  char **eventURL,
155  char **controlURL);
156 
162 typedef void (*print_string)(
164  const char *string,
166  ...)
167 #if (__GNUC__ >= 3)
168  /* This enables printf like format checking by the compiler */
169  __attribute__((format (__printf__, 1, 2)))
170 #endif
171 ;
172 
174 extern print_string gPrintFun;
175 
179 typedef void (*state_update)(
181  const char *varName,
183  const char *varValue,
185  const char *UDN,
187  eventType type);
188 
191 
198  print_string print_function);
199 
203 int SampleUtil_Finish();
204 
216 int SampleUtil_Print(
218  const char *fmt,
220  ...)
221 #if (__GNUC__ >= 3)
222  /* This enables printf like format checking by the compiler */
223  __attribute__((format (__printf__, 1, 2)))
224 #endif
225 ;
226 
232  state_update update_function);
233 
239  const char *varName,
241  const char *varValue,
243  const char *UDN,
245  eventType type);
246 
250 void linux_print(const char *format, ...)
251 #if (__GNUC__ >= 3)
252  /* This enables printf like format checking by the compiler */
253  __attribute__((format (__printf__, 1, 2)))
254 #endif
255 ;
256 
257 #ifdef __cplusplus
258 };
259 #endif /* __cplusplus */
260 
261 #ifdef _WIN32
262  #define snprintf _snprintf
263  #define strcasecmp stricmp
264 #endif
265 
268 #endif /* SAMPLE_UTIL_H */
269 
ixmlNodeList_free
EXPORT_SPEC void ixmlNodeList_free(IXML_NodeList *nList)
Frees a NodeList object.
Definition: nodeList.c:143
UPNP_EVENT_SUBSCRIPTION_REQUEST
@ UPNP_EVENT_SUBSCRIPTION_REQUEST
Definition: Callback.h:83
UPNP_DISCOVERY_SEARCH_RESULT
@ UPNP_DISCOVERY_SEARCH_RESULT
Definition: Callback.h:63
SampleUtil_GetFirstServiceList
IXML_NodeList * SampleUtil_GetFirstServiceList(IXML_Document *doc)
Given a DOM node representing a UPnP Device Description Document, this routine parses the document an...
Definition: sample_util.c:114
UPNP_CONTROL_ACTION_REQUEST
@ UPNP_CONTROL_ACTION_REQUEST
Definition: Callback.h:25
ixmlPrintNode
EXPORT_SPEC char * ixmlPrintNode(IXML_Node *doc)
Renders a Node and all sub-elements into an XML text representation.
Definition: ixml.c:365
ixmlNode_getFirstChild
EXPORT_SPEC IXML_Node * ixmlNode_getFirstChild(IXML_Node *nodeptr)
Retrieves the first child Node of a Node.
Definition: node.c:307
ixmlFreeDOMString
EXPORT_SPEC void ixmlFreeDOMString(char *buf)
Frees a DOMString.
SampleUtil_PrintEvent
int SampleUtil_PrintEvent(Upnp_EventType EventType, const void *Event)
Prints callback event structure details.
Definition: sample_util.c:317
SampleUtil_GetFirstDocumentItem
char * SampleUtil_GetFirstDocumentItem(IXML_Document *doc, const char *item)
Given a document node, this routine searches for the first element named by the input string item,...
Definition: sample_util.c:192
UPNP_CONTROL_GET_VAR_REQUEST
@ UPNP_CONTROL_GET_VAR_REQUEST
Definition: Callback.h:36
SampleUtil_GetFirstElementItem
char * SampleUtil_GetFirstElementItem(IXML_Element *element, const char *item)
Given a DOM element, this routine searches for the first element named by the input string item,...
Definition: sample_util.c:230
UPNP_EVENT_RENEWAL_COMPLETE
@ UPNP_EVENT_RENEWAL_COMPLETE
Definition: Callback.h:93
ixmlNode_getNodeValue
EXPORT_SPEC const char * ixmlNode_getNodeValue(IXML_Node *nodeptr)
Returns the value of the Node as a string.
Definition: node.c:253
print_string
void(* print_string)(const char *string,...)
Prototype for displaying strings. All printing done by the device, control point, and sample util,...
Definition: sample_util.h:162
UPNP_EVENT_UNSUBSCRIBE_COMPLETE
@ UPNP_EVENT_UNSUBSCRIBE_COMPLETE
Definition: Callback.h:103
_IXML_Document
Data structure representing the DOM Document.
Definition: ixml.h:198
UPNP_EVENT_SUBSCRIPTION_EXPIRED
@ UPNP_EVENT_SUBSCRIPTION_EXPIRED
Definition: Callback.h:115
UpnpActionComplete_get_ActionRequest
IXML_Document * UpnpActionComplete_get_ActionRequest(const UpnpActionComplete *p)
SampleUtil_Initialize
int SampleUtil_Initialize(print_string print_function)
Initializes the sample util. Must be called before any sample util functions. May be called multiple ...
Definition: sample_util.c:62
state_update
void(* state_update)(const char *varName, const char *varValue, const char *UDN, eventType type)
Prototype for passing back state changes.
Definition: sample_util.h:179
gStateUpdateFun
state_update gStateUpdateFun
Definition: sample_util.c:57
gPrintFun
print_string gPrintFun
Definition: sample_util.c:56
UPNP_DISCOVERY_SEARCH_TIMEOUT
@ UPNP_DISCOVERY_SEARCH_TIMEOUT
Definition: Callback.h:68
SampleUtil_GetElementValue
char * SampleUtil_GetElementValue(IXML_Element *element)
Given a DOM node such as <Channel>11</Channel>, this routine extracts the value (e....
Definition: sample_util.c:103
UPNP_E_SUCCESS
#define UPNP_E_SUCCESS
The operation completed successfully.
Definition: upnp.h:97
UPNP_EVENT_RECEIVED
@ UPNP_EVENT_RECEIVED
Definition: Callback.h:88
upnp.h
UPNP_CONTROL_GET_VAR_COMPLETE
@ UPNP_CONTROL_GET_VAR_COMPLETE
Definition: Callback.h:41
UpnpActionComplete
struct s_UpnpActionComplete UpnpActionComplete
Definition: TemplateInclude.h:136
UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE
@ UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE
Definition: Callback.h:57
ixml.h
SampleUtil_RegisterUpdateFunction
int SampleUtil_RegisterUpdateFunction(state_update update_function)
Definition: sample_util.c:82
ixmlNodeList_item
EXPORT_SPEC IXML_Node * ixmlNodeList_item(IXML_NodeList *nList, unsigned long index)
Retrieves a Node from a NodeList specified by a numerical index.
Definition: nodeList.c:54
_IXML_Node
Data structure common to all types of nodes.
Definition: ixml.h:173
UpnpString_get_String
const char * UpnpString_get_String(const UpnpString *p)
Returns the pointer to char.
Definition: UpnpString.c:159
UpnpActionComplete_get_ErrCode
int UpnpActionComplete_get_ErrCode(const UpnpActionComplete *p)
sample_util.h
SampleUtil_StateUpdate
void SampleUtil_StateUpdate(const char *varName, const char *varValue, const char *UDN, eventType type)
Definition: sample_util.c:655
SampleUtil_Print
int SampleUtil_Print(const char *fmt,...)
Function emulating printf that ultimately calls the registered print function with the formatted stri...
Definition: sample_util.c:634
linux_print
void linux_print(const char *format,...)
Prints a string to standard out.
Definition: sample_util.c:666
display_mutex
ithread_mutex_t display_mutex
Definition: sample_util.c:60
SampleUtil_PrintEventType
void SampleUtil_PrintEventType(Upnp_EventType S)
Prints a callback event type as a string.
Definition: sample_util.c:263
upnptools.h
ixmlNode_getNodeType
EXPORT_SPEC unsigned short ixmlNode_getNodeType(IXML_Node *nodeptr)
Retrieves the type of a Node. Note that not all possible return values are actually implemented.
Definition: node.c:287
SampleUtil_FindAndParseService
int SampleUtil_FindAndParseService(IXML_Document *DescDoc, const char *location, const char *serviceType, char **serviceId, char **eventURL, char **controlURL)
This routine finds the first occurance of a service in a DOM representation of a description document...
Definition: sample_util.c:550
ithread.h
UpnpActionComplete_get_CtrlUrl
const UpnpString * UpnpActionComplete_get_CtrlUrl(const UpnpActionComplete *p)
_IXML_NodeList
Data structure representing a list of nodes.
Definition: ixml.h:246
ixmlDocument_getElementsByTagName
EXPORT_SPEC IXML_NodeList * ixmlDocument_getElementsByTagName(IXML_Document *doc, const char *tagName)
Returns a NodeList of all Elements that match the given tag name in the order in which they were enco...
ixmlNodeList_length
EXPORT_SPEC unsigned long ixmlNodeList_length(IXML_NodeList *nList)
Returns the number of Nodes in a NodeList.
Definition: nodeList.c:128
UPNP_EVENT_SUBSCRIBE_COMPLETE
@ UPNP_EVENT_SUBSCRIBE_COMPLETE
Definition: Callback.h:98
UpnpResolveURL
EXPORT_SPEC int UpnpResolveURL(const char *BaseURL, const char *RelURL, char *AbsURL)
Combines a base URL and a relative URL into a single absolute URL.
Definition: upnptools.c:144
UPNP_CONTROL_ACTION_COMPLETE
@ UPNP_CONTROL_ACTION_COMPLETE
Definition: Callback.h:30
UPNP_DISCOVERY_ADVERTISEMENT_ALIVE
@ UPNP_DISCOVERY_ADVERTISEMENT_ALIVE
Definition: Callback.h:51
_IXML_Element
Data structure representing an Element node.
Definition: ixml.h:216
UPNP_EVENT_AUTORENEWAL_FAILED
@ UPNP_EVENT_AUTORENEWAL_FAILED
Definition: Callback.h:109
UpnpActionComplete_get_ActionResult
IXML_Document * UpnpActionComplete_get_ActionResult(const UpnpActionComplete *p)
ixmlElement_getElementsByTagName
EXPORT_SPEC IXML_NodeList * ixmlElement_getElementsByTagName(IXML_Element *element, const char *tagName)
Returns a NodeList of all descendant Elements with a given tag name, in the order in which they are e...
SampleUtil_Finish
int SampleUtil_Finish()
Releases Resources held by sample util.
Definition: sample_util.c:92