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

📄 libslp_findattrs.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//* Project:     OpenSLP - OpenSource implementation of Service Location    *//*              Protocol Version 2                                         *//*                                                                         *//* File:        slplib_findattrs.c                                         *//*                                                                         *//* Abstract:    Implementation for SLPFindAttrs() 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"/* TODO: do we need to add anything for collation here? *//*-------------------------------------------------------------------------*/SLPBoolean ProcessAttrRplyCallback(SLPError errorcode,                                    struct sockaddr_in* peerinfo,                                   SLPBuffer replybuf,                                   void* cookie)/*-------------------------------------------------------------------------*/{    SLPMessage      replymsg;    SLPAttrRply*    attrrply;    PSLPHandleInfo  handle      = (PSLPHandleInfo) cookie;    SLPBoolean      result      = SLP_TRUE;#ifdef ENABLE_SLPv2_SECURITY     int             securityenabled;    securityenabled = SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled"));#endif    /*-------------------------------------------*/    /* Check the errorcode and bail if it is set */    /*-------------------------------------------*/    if(errorcode)    {        handle->params.findattrs.callback((SLPHandle)handle,                                          0,                                          errorcode,                                          handle->params.findattrs.cookie);        return SLP_FALSE;    }    /*--------------------*/    /* Parse the replybuf */    /*--------------------*/    replymsg = SLPMessageAlloc();    if(replymsg)    {        if(SLPMessageParseBuffer(peerinfo,replybuf,replymsg) == 0 &&           replymsg->header.functionid == SLP_FUNCT_ATTRRPLY &&           replymsg->body.attrrply.errorcode == 0)        {            attrrply = &(replymsg->body.attrrply);                        if(attrrply->attrlistlen)            {     #ifdef ENABLE_SLPv2_SECURITY                /*-------------------------------*/                /* Validate the authblocks       */                /*-------------------------------*/                if(SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled")) &&                   SLPAuthVerifyString(handle->hspi,                                       1,                                       attrrply->attrlistlen,                                       attrrply->attrlist,                                       attrrply->authcount,                                       attrrply->autharray))                {                    /* Could not verify the attr auth block */                    SLPMessageFree(replymsg);                    return result;                }#endif                /*---------------------------------------*/                /* Send the attribute list to the caller */                /*---------------------------------------*/                /* TRICKY: null terminate the attrlist by setting the authcount to 0 */                ((char*)(attrrply->attrlist))[attrrply->attrlistlen] = 0;                                /* Call the callback function */                result = handle->params.findattrs.callback((SLPHandle)handle,                                                           attrrply->attrlist,                                                           attrrply->errorcode * -1,                                                           handle->params.findattrs.cookie);            }        }                SLPMessageFree(replymsg);    }        return result;}/*-------------------------------------------------------------------------*/SLPError ProcessAttrRqst(PSLPHandleInfo handle)/*-------------------------------------------------------------------------*/{    int                 sock;    struct sockaddr_in  peeraddr;    int                 bufsize     = 0;    char*               buf         = 0;    char*               curpos      = 0;    SLPError            result      = 0;#ifdef ENABLE_SLPv2_SECURITY    int                 spistrlen   = 0;    char*               spistr      = 0;    if(SLPPropertyAsBoolean(SLPGetProperty("net.slp.securityEnabled")))    {        SLPSpiGetDefaultSPI(handle->hspi,                            SLPSPI_KEY_TYPE_PUBLIC,                            &spistrlen,                            &spistr);    }#endif    /*-------------------------------------------------------------------*/    /* determine the size of the fixed portion of the ATTRRQST           */    /*-------------------------------------------------------------------*/    bufsize  = handle->params.findattrs.urllen + 2;       /*  2 bytes for len field */    bufsize += handle->params.findattrs.scopelistlen + 2; /*  2 bytes for len field */    bufsize += handle->params.findattrs.taglistlen + 2;   /*  2 bytes for len field */    bufsize += 2;    /*  2 bytes for spistr len*/#ifdef ENABLE_SLPv2_SECURITY    bufsize += spistrlen;#endif    buf = curpos = (char*)xmalloc(bufsize);    if(buf == 0)    {        result = SLP_MEMORY_ALLOC_FAILED;        goto FINISHED;    }    /*------------------------------------------------------------*/    /* Build a buffer containing the fixed portion of the ATTRRQST*/    /*------------------------------------------------------------*/    /* url */    ToUINT16(curpos,handle->params.findattrs.urllen);    curpos = curpos + 2;    memcpy(curpos,           handle->params.findattrs.url,           handle->params.findattrs.urllen);    curpos = curpos + handle->params.findattrs.urllen;    /* scope list */    ToUINT16(curpos,handle->params.findattrs.scopelistlen);    curpos = curpos + 2;    memcpy(curpos,           handle->params.findattrs.scopelist,           handle->params.findattrs.scopelistlen);    curpos = curpos + handle->params.findattrs.scopelistlen;    /* taglist  */    ToUINT16(curpos,handle->params.findattrs.taglistlen);    curpos = curpos + 2;    memcpy(curpos,           handle->params.findattrs.taglist,           handle->params.findattrs.taglistlen);    curpos = curpos + handle->params.findattrs.taglistlen;#ifdef ENABLE_SLPv2_SECURITY    ToUINT16(curpos,spistrlen);    curpos = curpos + 2;    memcpy(curpos,spistr,spistrlen);    curpos = curpos + spistrlen;#else    ToUINT16(curpos,0);#endif    /*--------------------------*/    /* Call the RqstRply engine */    /*--------------------------*/    do    {        #ifndef UNICAST_NOT_SUPPORTED	if ( handle->dounicast == 1 ) 	{	    void *cookie = (PSLPHandleInfo) handle;	    result = NetworkUcastRqstRply(handle,                                          buf,                                          SLP_FUNCT_ATTRRQST,					  bufsize,                                          ProcessAttrRplyCallback,

⌨️ 快捷键说明

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