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

📄 slpd_v1process.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 3 页
字号:
/***************************************************************************//*                                                                         *//* Project:     OpenSLP - OpenSource implementation of Service Location    *//*              Protocol Version 2                                         *//*                                                                         *//* File:        slpd_v1process.c                                           *//*                                                                         *//* Abstract:    Processes incoming SLP messages                            *//*                                                                         *//*-------------------------------------------------------------------------*//*                                                                         *//*     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.    *//*                                                                         *//***************************************************************************//*=========================================================================*//* slpd includes                                                           *//*=========================================================================*/#include "slpd_process.h"#include "slpd_property.h"#include "slpd_database.h"#include "slpd_knownda.h"#include "slpd_log.h"/*=========================================================================*//* common code includes                                                    *//*=========================================================================*/#include "slp_xmalloc.h"#include "slp_message.h"#include "slp_v1message.h"#include "slp_utf8.h"#include "slp_compare.h"#include <limits.h>/*-------------------------------------------------------------------------*/int v1ProcessDASrvRqst(struct sockaddr_in* peeraddr,                       SLPMessage message,                       SLPBuffer* sendbuf,                       int errorcode)/*-------------------------------------------------------------------------*/{    if (G_SlpdProperty.isDA)    {        if (message->body.srvrqst.scopelistlen == 0 ||            SLPIntersectStringList(message->body.srvrqst.scopelistlen,                               message->body.srvrqst.scopelist,                               G_SlpdProperty.useScopesLen,                               G_SlpdProperty.useScopes))        {            /* fill out real structure */            errorcode = SLPDKnownDAGenerateMyV1DAAdvert(errorcode,                                                    message->header.encoding,                                                    message->header.xid,                                                    sendbuf);        }        else        {            errorcode =  SLP_ERROR_SCOPE_NOT_SUPPORTED;        }    }    else    {	errorcode = SLP_ERROR_MESSAGE_NOT_SUPPORTED;    }    /* don't return errorcodes to multicast messages */    if (errorcode != 0)    {        if (message->header.flags & SLP_FLAG_MCAST ||            ISMCAST(peeraddr->sin_addr))        {            (*sendbuf)->end = (*sendbuf)->start;            return errorcode;        }    }    return errorcode;}/*-------------------------------------------------------------------------*/int v1ProcessSrvRqst(struct sockaddr_in* peeraddr,                     SLPMessage message,                     SLPBuffer* sendbuf,                     int errorcode)/*-------------------------------------------------------------------------*/{    int                         i;    int                         urllen;    int                         size        = 0;    SLPDDatabaseSrvRqstResult*  db          = 0;    SLPBuffer                   result      = *sendbuf;    /*--------------------------------------------------------------*/    /* If errorcode is set, we can not be sure that message is good */    /* Go directly to send response code                            */    /*--------------------------------------------------------------*/    if (errorcode)    {        goto RESPOND;    }    /*-------------------------------------------------*/    /* Check for one of our IP addresses in the prlist */    /*-------------------------------------------------*/    if (SLPIntersectStringList(message->body.srvrqst.prlistlen,                               message->body.srvrqst.prlist,                               G_SlpdProperty.interfacesLen,                               G_SlpdProperty.interfaces))    {        result->end = result->start;        goto FINISHED;    }    /*------------------------------------------------*/    /* Check to to see if a this is a special SrvRqst */    /*------------------------------------------------*/    if (SLPCompareString(message->body.srvrqst.srvtypelen,                         message->body.srvrqst.srvtype,                         15,                         "directory-agent") == 0)    {        errorcode = v1ProcessDASrvRqst(peeraddr, message, sendbuf, errorcode);        return errorcode;    }    /*------------------------------------*/    /* Make sure that we handle the scope */    /*------ -----------------------------*/    if (SLPIntersectStringList(message->body.srvrqst.scopelistlen,                               message->body.srvrqst.scopelist,                               G_SlpdProperty.useScopesLen,                               G_SlpdProperty.useScopes) != 0)    {        /*-------------------------------*/        /* Find services in the database */        /*-------------------------------*/        errorcode = SLPDDatabaseSrvRqstStart(message, &db);    }    else    {        errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED;    }    RESPOND:    /*----------------------------------------------------------------*/    /* Do not send error codes or empty replies to multicast requests */    /*----------------------------------------------------------------*/    if (message->header.flags & SLP_FLAG_MCAST)    {        if (errorcode != 0 || db->urlcount == 0)        {            result->end = result->start;            goto FINISHED;          }    }    /*-------------------------------------------------------------*/    /* ensure the buffer is big enough to handle the whole srvrply */    /*-------------------------------------------------------------*/    size = 16; /* 12 bytes for header, 2 bytes for error code, 2 bytes          for url count */    if (errorcode == 0)    {        for (i = 0; i < db->urlcount; i++)        {            urllen = INT_MAX;            errorcode = SLPv1ToEncoding(0,                                         &urllen,                                        message->header.encoding,                                          db->urlarray[i]->url,                                        db->urlarray[i]->urllen);            if (errorcode)                break;            size += urllen + 4; /* 2 bytes for lifetime, 2 bytes for urllen */        }         result = SLPBufferRealloc(result,size);        if (result == 0)        {            errorcode = SLP_ERROR_INTERNAL_ERROR;        }    }    /*----------------*/    /* Add the header */    /*----------------*/    /*version*/    *(result->start)       = 1;    /*function id*/    *(result->start + 1)   = SLP_FUNCT_SRVRPLY;    /*length*/    ToUINT16(result->start + 2, size);    /*flags - TODO set the flags correctly */    *(result->start + 4) = message->header.flags |                           (size > SLP_MAX_DATAGRAM_SIZE ? SLPv1_FLAG_OVERFLOW : 0);      /*dialect*/    *(result->start + 5) = 0;    /*language code*/    memcpy(result->start + 6, message->header.langtag, 2);    ToUINT16(result->start + 8, message->header.encoding);    /*xid*/    ToUINT16(result->start + 10, message->header.xid);    /*-------------------------*/    /* Add rest of the SrvRply */    /*-------------------------*/    result->curpos = result->start + 12;    /* error code*/    ToUINT16(result->curpos, errorcode);    result->curpos = result->curpos + 2;    if (errorcode == 0)    {        /* urlentry count */        ToUINT16(result->curpos, db->urlcount);        result->curpos = result->curpos + 2;        for (i = 0; i < db->urlcount; i++)        {            /* url-entry lifetime */            ToUINT16(result->curpos, db->urlarray[i]->lifetime);            result->curpos = result->curpos + 2;            /* url-entry url and urllen */            urllen = size;                  errorcode = SLPv1ToEncoding(result->curpos + 2,                                         &urllen,                                        message->header.encoding,                                          db->urlarray[i]->url,                                        db->urlarray[i]->urllen);            ToUINT16(result->curpos, urllen);            result->curpos = result->curpos + 2 + urllen;        }    }    else    {        /* urlentry count */        ToUINT16(result->curpos, 0);        result->curpos = result->curpos + 2;    }    FINISHED:       SLPDDatabaseSrvRqstEnd(db);    *sendbuf = result;    return errorcode;}/*-------------------------------------------------------------------------*/int v1ProcessSrvReg(struct sockaddr_in* peeraddr,                    SLPMessage message,                    SLPBuffer recvbuf,                    SLPBuffer* sendbuf,                    int errorcode)/*                                                                         *//* Returns: non-zero if message should be silently dropped                 *//*-------------------------------------------------------------------------*/{    SLPBuffer       result = *sendbuf;    /*--------------------------------------------------------------*/    /* If errorcode is set, we can not be sure that message is good */    /* Go directly to send response code  also do not process mcast */    /* srvreg or srvdereg messages                                  */    /*--------------------------------------------------------------*/    if (errorcode || message->header.flags & SLP_FLAG_MCAST)    {        goto RESPOND;    }

⌨️ 快捷键说明

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