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

📄 slpd_regfile.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//* Project:     OpenSLP - OpenSource implementation of Service Location    *//*              Protocol Version 2                                         *//*                                                                         *//* File:        slpd_regfile.c                                             *//*                                                                         *//* Abstract:    Reads service registrations from a file                    *//*                                                                         *//* WARNING:     NOT thread safe!                                           *//*                                                                         *//*-------------------------------------------------------------------------*//*                                                                         *//*     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_regfile.h"#include "slpd_property.h"#include "slpd_log.h"#ifdef ENABLE_SLPv2_SECURITY#include "slpd_spi.h"#endif/*=========================================================================*//* common code includes                                                    *//*=========================================================================*/#include "slp_xmalloc.h"#include "slp_compare.h"#ifdef ENABLE_SLPv2_SECURITY#include "slp_auth.h"#endif/*-------------------------------------------------------------------------*/char* TrimWhitespace(char* str)/*-------------------------------------------------------------------------*/{    char* end;    end=str+strlen(str)-1;    while(*str && *str <= 0x20)    {        str++;    }    while(end >= str)    {        if(*end > 0x20)        {            break;        }        *end = 0;        end--;    }    return str;}/*-------------------------------------------------------------------------*/char* RegFileReadLine(FILE* fd, char* line, int linesize)/*-------------------------------------------------------------------------*/{    while(1)    {        if(fgets(line,linesize,fd) == 0)        {            return 0;        }                while(*line &&               *line <= 0x20 &&              *line != 0x0d &&              *line != 0x0a) line++;                if(*line == 0x0d ||            *line == 0x0a)        {            break;            }        if(*line != 0 && *line != '#' && *line != ';')        {            break;        }    }    return line;}/*=========================================================================*/int SLPDRegFileReadSrvReg(FILE* fd,                          SLPMessage* msg,                          SLPBuffer* buf)/* A really big and nasty function that reads an service registration from *//* from a file. Don't look at this too hard or you'll be sick.  This is by *//* the most horrible code in OpenSLP.  Please volunteer to rewrite it!     *//*                                                                         *//*  "THANK GOODNESS this function is only called at startup" -- Matt       *//*                                                                         *//*                                                                         *//* fd       (IN) file to read from                                         *//*                                                                         *//* msg      (OUT) message describing the SrvReg in buf                     *//*                                                                         *//* buf      (OUT) buffer containing the SrvReg                             *//*                                                                         *//* Returns:  zero on success. > 0 on error.  < 0 if EOF                    *//*                                                                         *//* Note:    Eventually the caller needs to call SLPBufferFree() and        *//*          SLPMessageFree() to free memory                                *//*=========================================================================*/{    char*   slider1;    char*   slider2;    char*   p;    char    line[4096];        struct  sockaddr_in     peer;    int     result          = 0;    int     bufsize         = 0;    int     langtaglen      = 0;    char*   langtag         = 0;    int     scopelistlen    = 0;    char*   scopelist       = 0;    int     urllen          = 0;    char*   url             = 0;    int     lifetime        = 0;    int     srvtypelen      = 0;    char*   srvtype         = 0;    int     attrlistlen     = 0;    char*   attrlist        = 0;#ifdef ENABLE_SLPv2_SECURITY    unsigned char*  urlauth         = 0;    int             urlauthlen      = 0;    unsigned char*  attrauth        = 0;    int             attrauthlen     = 0;#endif            /*-------------------------------------------*/    /* give the out params an initial NULL value */    /*-------------------------------------------*/    *buf = 0;    *msg = 0;    /*----------------------------------------------------------*/    /* read the next non-white non-comment line from the stream */    /*----------------------------------------------------------*/    do    {        slider1 = RegFileReadLine(fd,line,4096);        if(slider1 == 0)        {            /* Breath a sigh of relief.  We get out before really  */            /* horrid code                                         */            return -1;        }    }while(*slider1 == 0x0d ||  *slider1 == 0x0a);        /*---------------------*/    /* Parse the url-props */    /*---------------------*/    slider2 = strchr(slider1,',');    if(slider2)    {        /* srvurl */        *slider2 = 0; /* squash comma to null terminate srvurl */        url = xstrdup(TrimWhitespace(slider1));        if(url == 0)        {            result = SLP_ERROR_INTERNAL_ERROR;            goto CLEANUP;        }	/* replace "$HOSTNAME" string in url */	while ((p = strchr(url, '$')) && !strncmp(p, "$HOSTNAME", 9))	{	    char *_url = (char*)malloc(strlen(url) - 9 + G_SlpdProperty.myHostnameLen + 1);	    strncpy(_url, url, p - url);	    strncpy(_url + (p - url), G_SlpdProperty.myHostname, G_SlpdProperty.myHostnameLen);	    strcpy(_url + (p - url) + G_SlpdProperty.myHostnameLen, url + (p - url) + 9);	    free(url);	    url = _url;	}        urllen = strlen(url);        /* derive srvtype from srvurl */        srvtype = strstr(slider1,"://");        if(srvtype == 0)        {            result = SLP_ERROR_INVALID_REGISTRATION;            goto CLEANUP;           }        *srvtype = 0;        srvtype=xstrdup(TrimWhitespace(slider1));        if(srvtype == 0)        {            result = SLP_ERROR_INTERNAL_ERROR;            goto CLEANUP;        }        srvtypelen = strlen(srvtype);        slider1 = slider2 + 1;        /*lang*/        slider2 = strchr(slider1,',');        if(slider2)        {            *slider2 = 0; /* squash comma to null terminate lang */            langtag = xstrdup(TrimWhitespace(slider1));             if(langtag == 0)            {                result = SLP_ERROR_INVALID_REGISTRATION;                goto CLEANUP;               }            langtaglen = strlen(langtag);                 slider1 = slider2 + 1;                                          }        else        {            result = SLP_ERROR_INVALID_REGISTRATION;            goto CLEANUP;           }        /* ltime */        slider2 = strchr(slider1,',');        if(slider2)        {            *slider2 = 0; /* squash comma to null terminate ltime */            lifetime = atoi(slider1);            slider1 = slider2 + 1;        }        else        {            lifetime = atoi(slider1);            slider1 = slider2;        }        if(lifetime < 1 || lifetime > SLP_LIFETIME_MAXIMUM)        {            result = SLP_ERROR_INVALID_REGISTRATION;            goto CLEANUP;           }        /* get the srvtype if one was not derived by the srvurl*/        if(srvtype == 0)        {            srvtype = xstrdup(TrimWhitespace(slider1));            if(srvtype == 0)            {                result = SLP_ERROR_INTERNAL_ERROR;                goto CLEANUP;            }            srvtypelen = strlen(srvtype);            if(srvtypelen == 0)            {                result = SLP_ERROR_INVALID_REGISTRATION;                goto CLEANUP;               }        }    }    else

⌨️ 快捷键说明

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