libUPnP  1.6.17
gena.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *
00003  * Copyright (c) 2000-2003 Intel Corporation 
00004  * All rights reserved. 
00005  *
00006  * Redistribution and use in source and binary forms, with or without 
00007  * modification, are permitted provided that the following conditions are met: 
00008  *
00009  * - Redistributions of source code must retain the above copyright notice, 
00010  * this list of conditions and the following disclaimer. 
00011  * - Redistributions in binary form must reproduce the above copyright notice, 
00012  * this list of conditions and the following disclaimer in the documentation 
00013  * and/or other materials provided with the distribution. 
00014  * - Neither name of Intel Corporation nor the names of its contributors 
00015  * may be used to endorse or promote products derived from this software 
00016  * without specific prior written permission.
00017  * 
00018  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00019  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00020  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00021  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 
00022  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00023  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00024  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
00025  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
00026  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00027  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  ******************************************************************************/
00031 
00032 
00033 #ifndef GENA_H
00034 #define GENA_H
00035 
00036 
00042 #include "config.h"
00043 
00044 
00045 #include <string.h>
00046 #include <time.h>
00047 
00048 
00049 #include "client_table.h"
00050 #include "httpparser.h"
00051 #include "miniserver.h"
00052 #include "service_table.h"
00053 #include "sock.h"
00054 #include "ThreadPool.h"
00055 #include "upnp.h"
00056 #include "UpnpString.h"
00057 #include "uri.h"
00058 
00059 
00060 #ifdef __cplusplus
00061         #define EXTERN_C extern "C"
00062 #else /* __cplusplus */
00063         #ifndef EXTERN_C
00064                 #define EXTERN_C 
00065         #endif /* EXTERN_C */
00066 #endif /* __cplusplus */
00067 
00068 
00073 #define XML_VERSION "<?xml version='1.0' encoding='ISO-8859-1' ?>\n"
00074 #define XML_PROPERTYSET_HEADER \
00075         "<e:propertyset xmlns:e=\"urn:schemas-upnp-org:event-1-0\">\n"
00076 
00077 
00078 #define UNABLE_MEMORY "HTTP/1.1 500 Internal Server Error\r\n\r\n"
00079 #define UNABLE_SERVICE_UNKNOWN "HTTP/1.1 404 Not Found\r\n\r\n"
00080 #define UNABLE_SERVICE_NOT_ACCEPT "HTTP/1.1 503 Service Not Available\r\n\r\n"
00081 
00082 
00083 #define NOT_IMPLEMENTED "HTTP/1.1 501 Not Implemented\r\n\r\n"
00084 #define BAD_REQUEST "HTTP/1.1 400 Bad Request\r\n\r\n"
00085 #define INVALID_NT BAD_CALLBACK
00086 #define BAD_CALLBACK "HTTP/1.1 412 Precondition Failed\r\n\r\n" 
00087 #define HTTP_OK_CRLF "HTTP/1.1 200 OK\r\n\r\n"
00088 #define HTTP_OK_STR "HTTP/1.1 200 OK\r\n"
00089 #define INVALID_SID BAD_CALLBACK
00090 #define MISSING_SID BAD_CALLBACK
00091 #define MAX_CONTENT_LENGTH 20
00092 #define MAX_SECONDS 10
00093 #define MAX_EVENTS 20
00094 #define MAX_PORT_SIZE 10
00095 
00096 
00097 #define GENA_E_BAD_RESPONSE UPNP_E_BAD_RESPONSE
00098 #define GENA_E_BAD_SERVICE UPNP_E_INVALID_SERVICE
00099 #define GENA_E_SUBSCRIPTION_UNACCEPTED UPNP_E_SUBSCRIBE_UNACCEPTED
00100 #define GENA_E_BAD_SID UPNP_E_INVALID_SID
00101 #define GENA_E_UNSUBSCRIBE_UNACCEPTED UPNP_E_UNSUBSCRIBE_UNACCEPTED
00102 #define GENA_E_NOTIFY_UNACCEPTED UPNP_E_NOTIFY_UNACCEPTED
00103 #define GENA_E_NOTIFY_UNACCEPTED_REMOVE_SUB -9
00104 #define GENA_E_BAD_HANDLE UPNP_E_INVALID_HANDLE
00105 
00106 
00107 #define XML_ERROR -5
00108 #define XML_SUCCESS UPNP_E_SUCCESS
00109 #define GENA_SUCCESS UPNP_E_SUCCESS
00110 
00111 
00112 #define CALLBACK_SUCCESS 0
00113 #define DEFAULT_TIMEOUT 1801
00114 
00115 
00116 extern ithread_mutex_t GlobalClientSubscribeMutex;
00117 
00118 
00122 #define SubscribeLock() \
00123         UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
00124                 "Trying Subscribe Lock\n");  \
00125         ithread_mutex_lock(&GlobalClientSubscribeMutex); \
00126         UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
00127                 "Subscribe Lock\n");
00128 
00129 
00133 #define SubscribeUnlock() \
00134         UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
00135                 "Trying Subscribe UnLock\n"); \
00136         ithread_mutex_unlock(&GlobalClientSubscribeMutex); \
00137         UpnpPrintf(UPNP_INFO, GENA, __FILE__, __LINE__, \
00138                 "Subscribe UnLock\n");
00139 
00140 
00144 typedef struct NOTIFY_THREAD_STRUCT {
00145         char *headers;
00146         DOMString propertySet;
00147         char *servId;
00148         char *UDN;
00149         Upnp_SID sid;
00150         int eventKey;
00151         int *reference_count;
00152         UpnpDevice_Handle device_handle;
00153 } notify_thread_struct;
00154 
00155 
00162 EXTERN_C void genaCallback(
00164         http_parser_t *parser, 
00166         http_message_t* request,
00168         SOCKINFO *info);
00169 
00170  
00181 #ifdef INCLUDE_CLIENT_APIS
00182 EXTERN_C int genaSubscribe(
00184         UpnpClient_Handle client_handle,
00186         const UpnpString *PublisherURL,
00191         int *TimeOut,
00193         UpnpString *out_sid);
00194 #endif /* INCLUDE_CLIENT_APIS */
00195 
00196 
00207 #ifdef INCLUDE_CLIENT_APIS
00208 EXTERN_C int genaUnSubscribe(
00210         UpnpClient_Handle client_handle,
00212         const UpnpString *in_sid);
00213 #endif /* INCLUDE_CLIENT_APIS */
00214 
00215 
00225 #ifdef INCLUDE_CLIENT_APIS
00226 EXTERN_C int genaUnregisterClient(
00228         UpnpClient_Handle client_handle);
00229 #endif /* INCLUDE_CLIENT_APIS */
00230 
00231 
00232 /*
00233  * DEVICE
00234  */
00235 
00236 
00242 #ifdef INCLUDE_DEVICE_APIS
00243 EXTERN_C int genaUnregisterDevice(
00245         UpnpDevice_Handle device_handle);
00246 #endif /* INCLUDE_CLIENT_APIS */
00247 
00248 
00259 #ifdef INCLUDE_CLIENT_APIS
00260 EXTERN_C int genaRenewSubscription(
00262         UpnpClient_Handle client_handle,
00264         const UpnpString *in_sid,
00267         int *TimeOut);
00268 #endif /* INCLUDE_CLIENT_APIS */
00269 
00270 
00279 #ifdef INCLUDE_DEVICE_APIS
00280 EXTERN_C int genaNotifyAll(
00282         UpnpDevice_Handle device_handle,
00284         char *UDN,
00286         char *servId,
00288         char **VarNames,
00290         char **VarValues,
00292         int var_count);
00293 #endif /* INCLUDE_DEVICE_APIS */
00294 
00295 
00304 #ifdef INCLUDE_DEVICE_APIS
00305 EXTERN_C int genaNotifyAllExt(
00307         UpnpDevice_Handle device_handle, 
00309         char *UDN,
00311         char *servId,
00313         IXML_Document *PropSet);
00314 #endif /* INCLUDE_DEVICE_APIS */
00315 
00316 
00325 #ifdef INCLUDE_DEVICE_APIS
00326 EXTERN_C int genaInitNotify(
00328         UpnpDevice_Handle device_handle,
00330         char *UDN,
00332         char *servId,
00334         char **VarNames,
00336         char **VarValues,
00338         int var_count,
00340         const Upnp_SID sid);
00341 #endif /* INCLUDE_DEVICE_APIS */
00342 
00343 
00354 #ifdef INCLUDE_DEVICE_APIS
00355 EXTERN_C  int genaInitNotifyExt(
00357         UpnpDevice_Handle device_handle, 
00359         char *UDN, 
00361         char *servId,
00363         IXML_Document *PropSet, 
00365         const Upnp_SID sid);
00366 #endif /* INCLUDE_DEVICE_APIS */
00367 
00368 
00375 void error_respond(
00377         SOCKINFO *info,
00379         int error_code,
00381         http_message_t* hmsg);
00382 
00383 
00384 #endif /* GENA_H */
00385