⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 service_table.c

📁 Upnp开发包文件
💻 C
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////// Copyright (c) 2000-2003 Intel Corporation // All rights reserved. //// Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: //// * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // * Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // * Neither name of Intel Corporation nor the names of its contributors // may be used to endorse or promote products derived from this software // without specific prior written permission.// // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.//////////////////////////////////////////////////////////////////////////////************************************************************************* Purpose: This file defines the functions for services. It defines * functions for adding and removing services to and from the service table, * adding and accessing subscription and other attributes pertaining to the * service ************************************************************************/#include "config.h"#include "service_table.h"#ifdef INCLUDE_DEVICE_APIS/*************************************************************************	Function :	copy_subscription**	Parameters :*		subscription *in ;	Source subscription*		subscription *out ;	Destination subscription**	Description :	Makes a copy of the subscription**	Return : int ;*		HTTP_SUCCESS - On Sucess**	Note :************************************************************************/intcopy_subscription( subscription * in,                   subscription * out ){    int return_code = HTTP_SUCCESS;    memcpy( out->sid, in->sid, SID_SIZE );    out->sid[SID_SIZE] = 0;    out->eventKey = in->eventKey;    out->ToSendEventKey = in->ToSendEventKey;    out->expireTime = in->expireTime;    out->active = in->active;    if( ( return_code =          copy_URL_list( &in->DeliveryURLs, &out->DeliveryURLs ) )        != HTTP_SUCCESS )        return return_code;    out->next = NULL;    return HTTP_SUCCESS;}/*************************************************************************	Function :	RemoveSubscriptionSID**	Parameters :*		Upnp_SID sid ;	subscription ID*		service_info * service ;	service object providing the list of*						subscriptions**	Description :	Remove the subscription represented by the*		const Upnp_SID sid parameter from the service table and update *		the service table.**	Return : void ;**	Note :************************************************************************/voidRemoveSubscriptionSID( Upnp_SID sid,                       service_info * service ){    subscription *finger = service->subscriptionList;    subscription *previous = NULL;    while( finger ) {        if( !( strcmp( sid, finger->sid ) ) ) {            if( previous )                previous->next = finger->next;            else                service->subscriptionList = finger->next;            finger->next = NULL;            freeSubscriptionList( finger );            finger = NULL;            service->TotalSubscriptions--;        } else {            previous = finger;            finger = finger->next;        }    }}/*************************************************************************	Function :	GetSubscriptionSID**	Parameters :*		Upnp_SID sid ;	subscription ID*		service_info * service ;	service object providing the list of*						subscriptions**	Description :	Return the subscription from the service table *		that matches const Upnp_SID sid value. **	Return : subscription * - Pointer to the matching subscription *		node;**	Note :************************************************************************/subscription *GetSubscriptionSID( Upnp_SID sid,                    service_info * service ){    subscription *next = service->subscriptionList;    subscription *previous = NULL;    subscription *found = NULL;    time_t current_time;    while( ( next ) && ( found == NULL ) ) {        if( !strcmp( next->sid, sid ) )            found = next;        else {            previous = next;            next = next->next;        }    }    if( found ) {        //get the current_time        time( &current_time );        if( ( found->expireTime != 0 )            && ( found->expireTime < current_time ) ) {            if( previous )                previous->next = found->next;            else                service->subscriptionList = found->next;            found->next = NULL;            freeSubscriptionList( found );            found = NULL;            service->TotalSubscriptions--;        }    }    return found;}/*************************************************************************	Function :	GetNextSubscription**	Parameters :*		service_info * service ; service object providing the list of*						subscriptions*		subscription *current ;	current subscription object**	Description :	Get current and valid subscription from the service *		table.**	Return : subscription * - Pointer to the next subscription node;**	Note :************************************************************************/subscription *GetNextSubscription( service_info * service,                     subscription * current ){    time_t current_time;    subscription *next = NULL;    subscription *previous = NULL;    int notDone = 1;    //get the current_time    time( &current_time );    while( ( notDone ) && ( current ) ) {        previous = current;        current = current->next;        if( current == NULL ) {            notDone = 0;            next = current;        } else            if( ( current->expireTime != 0 )                && ( current->expireTime < current_time ) ) {            previous->next = current->next;            current->next = NULL;            freeSubscriptionList( current );            current = previous;            service->TotalSubscriptions--;        } else if( current->active ) {            notDone = 0;            next = current;        }    }    return next;}/*************************************************************************	Function :	GetFirstSubscription**	Parameters :*		service_info *service ;	service object providing the list of*						subscriptions**	Description :	Gets pointer to the first subscription node in the *		service table.**	Return : subscription * - pointer to the first subscription node ;**	Note :************************************************************************/subscription *GetFirstSubscription( service_info * service ){    subscription temp;    subscription *next = NULL;    temp.next = service->subscriptionList;    next = GetNextSubscription( service, &temp );    service->subscriptionList = temp.next;    //  service->subscriptionList=next;    return next;}/*************************************************************************	Function :	freeSubscription**	Parameters :*		subscription * sub ;	subscription to be freed**	Description :	Free's the memory allocated for storing the URL of *		the subscription.**	Return : void ;**	Note :************************************************************************/voidfreeSubscription( subscription * sub ){    if( sub ) {        free_URL_list( &sub->DeliveryURLs );    }}/*************************************************************************	Function :	freeSubscriptionList**	Parameters :*		subscription * head ;	head of the subscription list**	Description :	Free's memory allocated for all the subscriptions *		in the service table. **	Return : void ;**	Note :************************************************************************/voidfreeSubscriptionList( subscription * head ){    subscription *next = NULL;    while( head ) {        next = head->next;        freeSubscription( head );        free( head );        head = next;    }}/*************************************************************************	Function :	FindServiceId**	Parameters :*		service_table *table ;	service table*		const char * serviceId ;string representing the service id *								to be found among those in the table	*		const char * UDN ;		string representing the UDN *								to be found among those in the table	**	Description :	Traverses through the service table and returns a *		pointer to the service node that matches a known service  id *		and a known UDN**	Return : service_info * - pointer to the matching service_info node;**	Note :************************************************************************/service_info *FindServiceId( service_table * table,               const char *serviceId,               const char *UDN ){    service_info *finger = NULL;    if( table ) {        finger = table->serviceList;        while( finger ) {            if( ( !strcmp( serviceId, finger->serviceId ) ) &&                ( !strcmp( UDN, finger->UDN ) ) ) {                return finger;            }            finger = finger->next;        }    }    return NULL;}/*************************************************************************	Function :	FindServiceEventURLPath**	Parameters :*		service_table *table ;	service table*		char * eventURLPath ;	event URL path used to find a service *								from the table  **	Description :	Traverses the service table and finds the node whose*		event URL Path matches a know value **	Return : service_info * - pointer to the service list node from the *		service table whose event URL matches a known event URL;**	Note :************************************************************************/service_info *FindServiceEventURLPath( service_table * table,                         char *eventURLPath ){    service_info *finger = NULL;    uri_type parsed_url;    uri_type parsed_url_in;    if( ( table )        &&        ( parse_uri          ( eventURLPath, strlen( eventURLPath ), &parsed_url_in ) ) ) {        finger = table->serviceList;        while( finger ) {            if( finger->eventURL )                if( ( parse_uri                      ( finger->eventURL, strlen( finger->eventURL ),                        &parsed_url ) ) ) {                    if( !token_cmp                        ( &parsed_url.pathquery,                          &parsed_url_in.pathquery ) )                        return finger;                }            finger = finger->next;        }    }    return NULL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -