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

📄 slp_compare.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 2 页
字号:
/***************************************************************************//*                                                                         *//* Project:     OpenSLP - OpenSource implementation of Service Location    *//*              Protocol                                                   *//*                                                                         *//* File:        slp_string.c                                               *//*                                                                         *//* Abstract:    Various functions that deal with SLP strings and           *//*              string-lists                                               *//*                                                                         *//*-------------------------------------------------------------------------*//*                                                                         *//*     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 <string.h>#include <ctype.h>#include "slp_compare.h"#ifndef _WIN32# ifndef HAVE_STRNCASECMPintstrncasecmp(const char *s1, const char *s2, size_t len){    while ( *s1 && (*s1 == *s2 || tolower(*s1) == tolower(*s2)) )    {        len--;        if(len == 0) return 0;        s1++;        s2++;    }    return(int) *(unsigned char *)s1 - (int) *(unsigned char *)s2;}# endif# ifndef HAVE_STRCASECMPintstrcasecmp(const char *s1, const char *s2){    while ( *s1 && (*s1 == *s2 || tolower(*s1) == tolower(*s2)) )    {        s1++;        s2++;    }    return(int) *(unsigned char *)s1 - (int) *(unsigned char *)s2;}# endif#endif /*=========================================================================*/int SLPCompareString(int str1len,                     const char* str1,                     int str2len,                     const char* str2)/* Does a lexical string compare as described in RFC 2608 section 6.4.     *//*                                                                         *//* TODO: Handle the whole utf8 spec                                        *//*                                                                         *//* str1 -       pointer to string to be compared                           *//*                                                                         *//* str1len -    length of str1 in bytes                                    *//*                                                                         *//* str2 -       pointer to string to be compared                           *//*                                                                         *//* str2len -    length of str2 in bytes                                    *//*                                                                         *//* Returns -    zero if strings are equal. >0 if str1 is greater than str2 *//*              <0 if s1 is less than str2                                 *//*=========================================================================*/{    /* TODO: fold whitespace and handle escapes*/    if(str1len == str2len)    {    	if (str1len <= 0)	    return(0);        return strncasecmp(str1,str2,str1len);    }    else if(str1len > str2len)    {        return -1;    }    return 1;}/*=========================================================================*/int SLPCompareNamingAuth(int srvtypelen,                         const char* srvtype,                         int namingauthlen,                         const char* namingauth)/* Does srvtype match namingauth                                           *//*                                                                         *//* TODO: Handle the whole utf8 spec                                        *//*                                                                         *//* srvtype -        pointer to service type to be compared                 *//*                                                                         *//* srvtypelen -     length of srvtype in bytes                             *//*                                                                         *//* namingauth -     pointer to naming authority to be matched              *//*                                                                         *//* namingauthlen -  length of naming authority in bytes                    *//*                                                                         *//* Returns -    zero if srvtype matches the naming authority. Nonzero if   *//*              it doesn't                                                 *//*=========================================================================*/{    const char *dot;    if(namingauthlen == 0xffff) /* match all naming authorities */        return 0;    /* Skip "service:" */    if ((srvtypelen > 8) && (strncasecmp(srvtype,"service:",8) == 0))    {        srvtypelen -= 8;        srvtype += 8;    }    /* stop search at colon after naming authority (if there is one) */    dot = memchr(srvtype,':',srvtypelen);    if (dot)	srvtypelen = dot - srvtype;     dot = memchr(srvtype,'.',srvtypelen);    if(!namingauthlen)     /* IANA naming authority */        return dot ? 1 : 0;    if (dot)    {	    	int srvtypenalen = srvtypelen - (dot + 1 - srvtype);	if(srvtypenalen != namingauthlen)	    return 1;	if(strncasecmp(dot + 1, namingauth, namingauthlen) == 0)	    return 0;    }	    return 1;}/*=========================================================================*/int SLPCompareSrvType(int lsrvtypelen,                      const char* lsrvtype,                      int rsrvtypelen,                      const char* rsrvtype)/* Does lsrvtype = rsrvtype?                                               *//*                                                                         *//* TODO: Handle the whole utf8 spec                                        *//*                                                                         *//* lsrvtype -       pointer to string to be compared                       *//*                                                                         *//* lsrvtypelen -    length of str1 in bytes                                *//*                                                                         *//* rsrvtype -       pointer to string to be compared                       *//*                                                                         *//* rsrvtypelen -    length of str2 in bytes                                *//*                                                                         *//* Returns -    zero if srvtypes are equal. Nonzero if they are not        *//*=========================================================================*/{    char* colon;    /* Skip "service:" */    if(strncasecmp(lsrvtype,"service:",lsrvtypelen > 8 ? 8 : lsrvtypelen) == 0)    {        lsrvtypelen = lsrvtypelen - 8;        lsrvtype = lsrvtype + 8;    }    if(strncasecmp(rsrvtype,"service:",rsrvtypelen > 8 ? 8 : rsrvtypelen) == 0)    {        rsrvtypelen = rsrvtypelen - 8;        rsrvtype = rsrvtype + 8;    }    if(memchr(lsrvtype,':',lsrvtypelen))    {        /* lsrvtype is uses concrete type so strings must be identical */        if(lsrvtypelen == rsrvtypelen)        {            return strncasecmp(lsrvtype,rsrvtype,lsrvtypelen);        }        return 1;    }    colon = memchr(rsrvtype,':',rsrvtypelen);    if(colon)    {        /* lsrvtype is abstract only and rsrvtype is concrete */        if(lsrvtypelen == (colon - rsrvtype))        {            return strncasecmp(lsrvtype,rsrvtype,lsrvtypelen);        }        return 1;    }    /* lsrvtype and rsrvtype are  abstract only */    if(lsrvtypelen == rsrvtypelen)    {        return strncasecmp(lsrvtype,rsrvtype,lsrvtypelen);    }    return 1;}/*=========================================================================*/int SLPContainsStringList(int listlen,                           const char* list,                          int stringlen,                          const char* string) /* Checks a string-list for the occurence of a string                      *//*                                                                         *//* list -       pointer to the string-list to be checked                   *//*                                                                         *//* listlen -    length in bytes of the list to be checked                  *//*                                                                         *//* string -     pointer to a string to find in the string-list             *//*                                                                         *//* stringlen -  the length of the string in bytes                          *//*                                                                         *//* Returns -    zero if string is NOT contained in the list. non-zero if it*//*              is.                                                        *//*=========================================================================*/{    char* listend = (char*)list + listlen;    char* itembegin = (char*)list;    char* itemend = itembegin;    while(itemend < listend)    {        itembegin = itemend;        /* seek to the end of the next list item */        while(1)        {            if(itemend == listend || *itemend == ',')            {                if(*(itemend - 1) != '\\')                {                    break;                }            }            itemend ++;        }        if(SLPCompareString(itemend - itembegin,                            itembegin,                            stringlen,                            string) == 0)        {            return 1;        }        itemend ++;    

⌨️ 快捷键说明

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