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 // 00031 00032 #ifndef _SERVICE_TABLE 00033 #define _SERVICE_TABLE 00034 00035 #ifdef __cplusplus 00036 extern "C" { 00037 #endif 00038 00039 #include "config.h" 00040 #include "uri.h" 00041 #include "ixml.h" 00042 00043 #include "upnp.h" 00044 #include <stdio.h> 00045 #include <time.h> 00046 00047 #define SID_SIZE 41 00048 00049 DEVICEONLY( 00050 00051 typedef struct SUBSCRIPTION { 00052 Upnp_SID sid; 00053 int eventKey; 00054 int ToSendEventKey; 00055 time_t expireTime; 00056 int active; 00057 URL_list DeliveryURLs; 00058 struct SUBSCRIPTION *next; 00059 } subscription; 00060 00061 00062 typedef struct SERVICE_INFO { 00063 DOMString serviceType; 00064 DOMString serviceId; 00065 char *SCPDURL ; 00066 char *controlURL; 00067 char *eventURL; 00068 DOMString UDN; 00069 int active; 00070 int TotalSubscriptions; 00071 subscription *subscriptionList; 00072 struct SERVICE_INFO *next; 00073 } service_info; 00074 00075 typedef struct SERVICE_TABLE { 00076 DOMString URLBase; 00077 service_info *serviceList; 00078 service_info *endServiceList; 00079 } service_table; 00080 00081 00082 /* Functions for Subscriptions */ 00083 00084 /************************************************************************ 00085 * Function : copy_subscription 00086 * 00087 * Parameters : 00088 * subscription *in ; Source subscription 00089 * subscription *out ; Destination subscription 00090 * 00091 * Description : Makes a copy of the subscription 00092 * 00093 * Return : int ; 00094 * HTTP_SUCCESS - On Sucess 00095 * 00096 * Note : 00097 ************************************************************************/ 00098 int copy_subscription(subscription *in, subscription *out); 00099 00100 /************************************************************************ 00101 * Function : RemoveSubscriptionSID 00102 * 00103 * Parameters : 00104 * Upnp_SID sid ; subscription ID 00105 * service_info * service ; service object providing the list of 00106 * subscriptions 00107 * 00108 * Description : Remove the subscription represented by the 00109 * const Upnp_SID sid parameter from the service table and update 00110 * the service table. 00111 * 00112 * Return : void ; 00113 * 00114 * Note : 00115 ************************************************************************/ 00116 void RemoveSubscriptionSID(Upnp_SID sid, service_info * service); 00117 00118 /************************************************************************ 00119 * Function : GetSubscriptionSID 00120 * 00121 * Parameters : 00122 * Upnp_SID sid ; subscription ID 00123 * service_info * service ; service object providing the list of 00124 * subscriptions 00125 * 00126 * Description : Return the subscription from the service table 00127 * that matches const Upnp_SID sid value. 00128 * 00129 * Return : subscription * - Pointer to the matching subscription 00130 * node; 00131 * 00132 * Note : 00133 ************************************************************************/ 00134 subscription * GetSubscriptionSID(Upnp_SID sid,service_info * service); 00135 00136 //returns a pointer to the subscription with the SID, NULL if not found 00137 00138 subscription * CheckSubscriptionSID(Upnp_SID sid,service_info * service); 00139 00140 //returns a pointer to the first subscription 00141 subscription * GetFirstSubscription(service_info *service); 00142 00143 /************************************************************************ 00144 * Function : GetNextSubscription 00145 * 00146 * Parameters : 00147 * service_info * service ; service object providing the list of 00148 * subscriptions 00149 * subscription *current ; current subscription object 00150 * 00151 * Description : Get current and valid subscription from the service 00152 * table. 00153 * 00154 * Return : subscription * - Pointer to the next subscription node; 00155 * 00156 * Note : 00157 ************************************************************************/ 00158 subscription * GetNextSubscription(service_info * service, subscription *current); 00159 00160 /************************************************************************ 00161 * Function : freeSubscription 00162 * 00163 * Parameters : 00164 * subscription * sub ; subscription to be freed 00165 * 00166 * Description : Free's the memory allocated for storing the URL of 00167 * the subscription. 00168 * 00169 * Return : void ; 00170 * 00171 * Note : 00172 ************************************************************************/ 00173 void freeSubscription(subscription * sub); 00174 00175 /************************************************************************ 00176 * Function : freeSubscriptionList 00177 * 00178 * Parameters : 00179 * subscription * head ; head of the subscription list 00180 * 00181 * Description : Free's memory allocated for all the subscriptions 00182 * in the service table. 00183 * 00184 * Return : void ; 00185 * 00186 * Note : 00187 ************************************************************************/ 00188 void freeSubscriptionList(subscription * head); 00189 00190 /************************************************************************ 00191 * Function : FindServiceId 00192 * 00193 * Parameters : 00194 * service_table *table ; service table 00195 * const char * serviceId ;string representing the service id 00196 * to be found among those in the table 00197 * const char * UDN ; string representing the UDN 00198 * to be found among those in the table 00199 * 00200 * Description : Traverses through the service table and returns a 00201 * pointer to the service node that matches a known service id 00202 * and a known UDN 00203 * 00204 * Return : service_info * - pointer to the matching service_info node; 00205 * 00206 * Note : 00207 ************************************************************************/ 00208 service_info *FindServiceId( service_table * table, 00209 const char * serviceId, const char * UDN); 00210 00211 /************************************************************************ 00212 * Function : FindServiceEventURLPath 00213 * 00214 * Parameters : 00215 * service_table *table ; service table 00216 * char * eventURLPath ; event URL path used to find a service 00217 * from the table 00218 * 00219 * Description : Traverses the service table and finds the node whose 00220 * event URL Path matches a know value 00221 * 00222 * Return : service_info * - pointer to the service list node from the 00223 * service table whose event URL matches a known event URL; 00224 * 00225 * Note : 00226 ************************************************************************/ 00227 service_info * FindServiceEventURLPath( service_table *table, 00228 char * eventURLPath 00229 ); 00230 00231 /************************************************************************ 00232 * Function : FindServiceControlURLPath 00233 * 00234 * Parameters : 00235 * service_table * table ; service table 00236 * char * controlURLPath ; control URL path used to find a service 00237 * from the table 00238 * 00239 * Description : Traverses the service table and finds the node whose 00240 * control URL Path matches a know value 00241 * 00242 * Return : service_info * - pointer to the service list node from the 00243 * service table whose control URL Path matches a known value; 00244 * 00245 * Note : 00246 ************************************************************************/ 00247 service_info * FindServiceControlURLPath( service_table *table, 00248 const char * controlURLPath); 00249 00250 /************************************************************************ 00251 * Function : printService 00252 * 00253 * Parameters : 00254 * service_info *service ;Service whose information is to be printed 00255 * Dbg_Level level ; Debug level specified to the print function 00256 * Dbg_Module module ; Debug module specified to the print function 00257 * 00258 * Description : For debugging purposes prints information from the 00259 * service passed into the function. 00260 * 00261 * Return : void ; 00262 * 00263 * Note : 00264 ************************************************************************/ 00265 DBGONLY(void printService(service_info *service,Dbg_Level 00266 level, 00267 Dbg_Module module)); 00268 00269 /************************************************************************ 00270 * Function : printServiceList 00271 * 00272 * Parameters : 00273 * service_info *service ; Service whose information is to be printed 00274 * Dbg_Level level ; Debug level specified to the print function 00275 * Dbg_Module module ; Debug module specified to the print function 00276 * 00277 * Description : For debugging purposes prints information of each 00278 * service from the service table passed into the function. 00279 * 00280 * Return : void ; 00281 * 00282 * Note : 00283 ************************************************************************/ 00284 DBGONLY(void printServiceList(service_info *service, 00285 Dbg_Level level, Dbg_Module module)); 00286 00287 /************************************************************************ 00288 * Function : printServiceTable 00289 * 00290 * Parameters : 00291 * service_table * table ; Service table to be printed 00292 * Dbg_Level level ; Debug level specified to the print function 00293 * Dbg_Module module ; Debug module specified to the print function 00294 * 00295 * Description : For debugging purposes prints the URL base of the table 00296 * and information of each service from the service table passed into 00297 * the function. 00298 * 00299 * Return : void ; 00300 * 00301 * Note : 00302 ************************************************************************/ 00303 DBGONLY(void printServiceTable(service_table * 00304 table,Dbg_Level 00305 level,Dbg_Module module)); 00306 00307 /************************************************************************ 00308 * Function : freeService 00309 * 00310 * Parameters : 00311 * service_info *in ; service information that is to be freed 00312 * 00313 * Description : Free's memory allocated for the various components 00314 * of the service entry in the service table. 00315 * 00316 * Return : void ; 00317 * 00318 * Note : 00319 ************************************************************************/ 00320 void freeService(service_info * in); 00321 00322 /************************************************************************ 00323 * Function : freeServiceList 00324 * 00325 * Parameters : 00326 * service_info * head ; Head of the service list to be freed 00327 * 00328 * Description : Free's memory allocated for the various components 00329 * of each service entry in the service table. 00330 * 00331 * Return : void ; 00332 * 00333 * Note : 00334 ************************************************************************/ 00335 void freeServiceList(service_info * head); 00336 00337 00338 /************************************************************************ 00339 * Function : freeServiceTable 00340 * 00341 * Parameters : 00342 * service_table * table ; Service table whose memory needs to be 00343 * freed 00344 * 00345 * Description : Free's dynamic memory in table. 00346 * (does not free table, only memory within the structure) 00347 * 00348 * Return : void ; 00349 * 00350 * Note : 00351 ************************************************************************/ 00352 void freeServiceTable(service_table * table); 00353 00354 /************************************************************************ 00355 * Function : removeServiceTable 00356 * 00357 * Parameters : 00358 * IXML_Node *node ; XML node information 00359 * service_table *in ; service table from which services will be 00360 * removed 00361 * 00362 * Description : This function assumes that services for a particular 00363 * root device are placed linearly in the service table, and in the 00364 * order in which they are found in the description document 00365 * all services for this root device are removed from the list 00366 * 00367 * Return : int ; 00368 * 00369 * Note : 00370 ************************************************************************/ 00371 int removeServiceTable(IXML_Node *node, 00372 service_table *in); 00373 00374 00375 /************************************************************************ 00376 * Function : addServiceTable 00377 * 00378 * Parameters : 00379 * IXML_Node *node ; XML node information 00380 * service_table *in ; service table that will be initialized with 00381 * services 00382 * const char *DefaultURLBase ; Default base URL on which the URL 00383 * will be returned to the service list. 00384 * 00385 * Description : Add Service to the table. 00386 * 00387 * Return : int ; 00388 * 00389 * Note : 00390 ************************************************************************/ 00391 int addServiceTable(IXML_Node *node, service_table *in, const char *DefaultURLBase); 00392 00393 /************************************************************************ 00394 * Function : getServiceTable 00395 * 00396 * Parameters : 00397 * IXML_Node *node ; XML node information 00398 * service_table *out ; output parameter which will contain the 00399 * service list and URL 00400 * const char *DefaultURLBase ; Default base URL on which the URL 00401 * will be returned. 00402 * 00403 * Description : Retrieve service from the table 00404 * 00405 * Return : int ; 00406 * 00407 * Note : 00408 ************************************************************************/ 00409 int getServiceTable(IXML_Node *node, service_table * out, const char * DefaultURLBase); 00410 00411 00412 /* Misc helper functions */ 00413 00414 00415 /************************************************************************ 00416 * Function : getElementValue 00417 * 00418 * Parameters : 00419 * IXML_Node *node ; Input node which provides the list of child 00420 * nodes 00421 * 00422 * Description : Returns the clone of the element value 00423 * 00424 * Return : DOMString ; 00425 * 00426 * Note : value must be freed with DOMString_free 00427 ************************************************************************/ 00428 DOMString getElementValue(IXML_Node *node); 00429 00430 /************************************************************************ 00431 * Function : getSubElement 00432 * 00433 * Parameters : 00434 * const char *element_name ; sub element name to be searched for 00435 * IXML_Node *node ; Input node which provides the list of child 00436 * nodes 00437 * IXML_Node **out ; Ouput node to which the matched child node is 00438 * returned. 00439 * 00440 * Description : Traverses through a list of XML nodes to find the 00441 * node with the known element name. 00442 * 00443 * Return : int ; 00444 * 1 - On Success 00445 * 0 - On Failure 00446 * 00447 * Note : 00448 ************************************************************************/ 00449 int getSubElement(const char *element_name, IXML_Node *node, 00450 IXML_Node **out); 00451 00452 00453 ) /* DEVICEONLY */ 00454 00455 #ifdef __cplusplus 00456 } 00457 #endif 00458 00459 #endif /* _SERVICE_TABLE */
1.6.1