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

📄 libslp_findsrvtypes.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//* Project:     OpenSLP - OpenSource implementation of Service Location    *//*              Protocol Version 2                                         *//*                                                                         *//* File:        slplib_findsrvtypes.c                                      *//*                                                                         *//* Abstract:    Implementation for SLPFindSrvType() call.                  *//*                                                                         *//*-------------------------------------------------------------------------*//*                                                                         *//*     Please submit patches to http://www.openslp.org                     *//*                                                                         *//*-------------------------------------------------------------------------*//*                                                                         *//* Copyright (C) 2000 Caldera Systems, Inc                                 *//* 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 the name of Caldera Systems 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 THE CALDERA      *//* SYSTEMS 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.    *//*                                                                         *//***************************************************************************/#include "slp.h"#include "libslp.h"/*----------------------------------------------------------------------------*/SLPBoolean ColateSrvTypeCallback(SLPHandle hSLP,                                 const char* pcSrvTypes,                                 SLPError errCode,                                 void *pvCookie)/*----------------------------------------------------------------------------*/{    PSLPHandleInfo          handle;    SLPBoolean              result;    int		                srvtypeslen;    char*                   srvtypes;        handle = (PSLPHandleInfo) hSLP;    handle->callbackcount ++;#ifdef ENABLE_ASYNC_API    /* Do not colate for async calls */    if(handle->isAsync)    {        return handle->params.findsrvtypes.callback(hSLP,                                                    pcSrvTypes,                                                    errCode,                                                    pvCookie);    }#endif    if(errCode == SLP_LAST_CALL ||        handle->callbackcount > SLPPropertyAsInteger(SLPGetProperty("net.slp.maxResults")))    {        /* We're done.  Send back the colated srvtype string */        result = SLP_TRUE;        if(handle->collatedsrvtypes)        {            result = handle->params.findsrvtypes.callback((SLPHandle)handle,                                                          handle->collatedsrvtypes,                                                          SLP_OK,                                                          handle->params.findsrvtypes.cookie);            if(result == SLP_TRUE)            {                handle->params.findsrvtypes.callback((SLPHandle)handle,                                                     NULL,                                                     SLP_LAST_CALL,                                                     handle->params.findsrvtypes.cookie);            }        }                /* Free the colatedsrvtype string */        if(handle->collatedsrvtypes)        {            xfree(handle->collatedsrvtypes);            handle->collatedsrvtypes = NULL;        }        handle->callbackcount = 0;                return SLP_FALSE;    }    else if(errCode != SLP_OK)    {        return SLP_TRUE;    }    /* Add the service types to the colation */    srvtypeslen = strlen(pcSrvTypes) + 1; /* +1 - terminator */    if(handle->collatedsrvtypes)    {        srvtypeslen += strlen(handle->collatedsrvtypes) + 1; /* +1 - comma */    }        srvtypes = xmalloc(srvtypeslen);    if(srvtypes)    {        if(handle->collatedsrvtypes)        {            if(SLPUnionStringList(strlen(handle->collatedsrvtypes),                                  handle->collatedsrvtypes,                                  strlen(pcSrvTypes),                                  pcSrvTypes,                                  &srvtypeslen,                                  srvtypes) != srvtypeslen)            {                xfree(handle->collatedsrvtypes);                handle->collatedsrvtypes = srvtypes;            }            else            {                #ifndef COLLATION_CHANGES                xfree(handle->collatedsrvtypes);                handle->collatedsrvtypes = srvtypes;                handle->collatedsrvtypes[srvtypeslen] = '\0';                #else                xfree(srvtypes);                #endif /* COLLATION_CHANGES */            }           }        else        {            strcpy(srvtypes,pcSrvTypes);            handle->collatedsrvtypes = srvtypes;        }    }    return SLP_TRUE;}/*----------------------------------------------------------------------------*/SLPBoolean ProcessSrvTypeRplyCallback(SLPError errorcode,                                       struct sockaddr_in* peerinfo,                                      SLPBuffer replybuf,                                      void* cookie)/*----------------------------------------------------------------------------*/{    SLPMessage      replymsg;    SLPSrvTypeRply* srvtyperply;    PSLPHandleInfo  handle      = (PSLPHandleInfo) cookie;    SLPBoolean      result      = SLP_TRUE;    /*-------------------------------------------*/    /* Check the errorcode and bail if it is set */    /*-------------------------------------------*/    if(errorcode)    {        return ColateSrvTypeCallback((SLPHandle)handle,                                     0,                                     errorcode,                                     handle->params.findsrvtypes.cookie);    }    /*--------------------*/    /* Parse the replybuf */    /*--------------------*/    replymsg = SLPMessageAlloc();    if(replymsg)    {        if(SLPMessageParseBuffer(peerinfo,replybuf,replymsg) == 0 &&           replymsg->header.functionid == SLP_FUNCT_SRVTYPERPLY &&           replymsg->body.srvtyperply.errorcode == 0)        {            srvtyperply = &(replymsg->body.srvtyperply);            if(srvtyperply->srvtypelistlen)            {                /*------------------------------------------*/                /* Send the service type list to the caller */                /*------------------------------------------*/                /* TRICKY: null terminate the srvtypelist by setting the last byte 0 */                ((char*)(srvtyperply->srvtypelist))[srvtyperply->srvtypelistlen] = 0;                                /* Call the callback function */                result = ColateSrvTypeCallback((SLPHandle)handle,                                               srvtyperply->srvtypelist,                                               srvtyperply->errorcode * - 1,                                               handle->params.findsrvtypes.cookie);            }        }                SLPMessageFree(replymsg);    }        return result;}/*-------------------------------------------------------------------------*/SLPError ProcessSrvTypeRqst(PSLPHandleInfo handle)/*-------------------------------------------------------------------------*/{    int                 sock;    struct sockaddr_in  peeraddr;    int                 bufsize     = 0;    char*               buf         = 0;    char*               curpos      = 0;    SLPError            result      = 0;    /*-------------------------------------------------------------------*/    /* determine the size of the fixed portion of the SRVTYPERQST            */    /*-------------------------------------------------------------------*/    bufsize  = handle->params.findsrvtypes.namingauthlen + 2;   /*  2 bytes for len field */    bufsize += handle->params.findsrvtypes.scopelistlen + 2; /*  2 bytes for len field */    /* TODO: make sure that we don't exceed the MTU */    buf = curpos = (char*)xmalloc(bufsize);    if(buf == 0)    {        result = SLP_MEMORY_ALLOC_FAILED;

⌨️ 快捷键说明

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