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

📄 slpd_regfile.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 2 页
字号:
    {        result = SLP_ERROR_INVALID_REGISTRATION;        goto CLEANUP;       }    /*-------------------------------------------------*/    /* Read all the attributes including the scopelist */    /*-------------------------------------------------*/    *line=0;    while(1)    {        slider1 = RegFileReadLine(fd,line,4096);        if(slider1 == 0)        {            /* Breathe a sigh of relief.  We're done */            result = -1;            break;        }        if(*slider1 == 0x0d || *slider1 == 0x0a)        {            break;        }        /* Check to see if it is the scopes line */        /* FIXME We can collapse the scope stuff into the value getting and          * just make it a special case (do strcmp on the tag as opposed to the          * line) of attribute getting.          */        if(strncasecmp(slider1,"scopes",6) == 0)        {            /* found scopes line */            slider2 = strchr(slider1,'=');            if(slider2)            {                slider2++;                if(*slider2)                {                    /* just in case some idiot puts multiple scopes lines */                    if(scopelist)                    {                        result = SLP_ERROR_SCOPE_NOT_SUPPORTED;                        goto CLEANUP;                    }                                        /* make sure there are no spaces in the scope list */                    if(strchr(slider2,' '))                    {                        result = SLP_ERROR_SCOPE_NOT_SUPPORTED;                        goto CLEANUP;                    }                    scopelist=xstrdup(TrimWhitespace(slider2));                    if(scopelist == 0)                    {                        result = SLP_ERROR_INTERNAL_ERROR;                        goto CLEANUP;                    }                    scopelistlen = strlen(scopelist);                }            }        }        else        {            /* line contains an attribute (slow but it works)*/            /* TODO Fix this so we do not have to realloc memory each time! */            TrimWhitespace(slider1);                         if(attrlist == 0)            {                attrlistlen += strlen(slider1) + 2;                attrlist = xmalloc(attrlistlen + 1);                *attrlist = 0;            }            else            {                attrlistlen += strlen(slider1) + 3;                attrlist = xrealloc(attrlist,                                   attrlistlen + 1);                strcat(attrlist,",");            }            if(attrlist == 0)            {                result = SLP_ERROR_INTERNAL_ERROR;                goto CLEANUP;            }	    	    /* we need special case for keywords (why do we need these)   */	    /* they seem like a waste of code.  Why not just use booleans */	    if(strchr(slider1,'='))	    {	        /* normal attribute (with '=') */	        strcat(attrlist,"(");                strcat(attrlist,slider1);                strcat(attrlist,")");	    }	    else	    {	        /* keyword (no '=') */	        attrlistlen -= 2; /* subtract 2 bytes for no '(' or ')' */	        strcat(attrlist,slider1);	       	    }		        }    }    /* Set the scope set in properties if not is set */    if(scopelist == 0)    {        scopelist=xstrdup(G_SlpdProperty.useScopes);        if(scopelist == 0)        {            result = SLP_ERROR_INTERNAL_ERROR;            goto CLEANUP;        }        scopelistlen = G_SlpdProperty.useScopesLen;    } #ifdef ENABLE_SLPv2_SECURITY    /*--------------------------------*/    /* Generate authentication blocks */    /*--------------------------------*/    if(G_SlpdProperty.securityEnabled)    {                SLPAuthSignUrl(G_SlpdSpiHandle,                       0,                       0,                       urllen,                       url,                       &urlauthlen,                       &urlauth);            SLPAuthSignString(G_SlpdSpiHandle,                          0,                          0,                          attrlistlen,                          attrlist,                          &attrauthlen,                          &attrauth);    }#endif    /*----------------------------------------*/    /* Allocate buffer for the SrvReg Message */    /*----------------------------------------*/    bufsize = 14 + langtaglen;  /* 14 bytes for header    */    bufsize += urllen + 6;      /*  1 byte for reserved   */                                /*  2 bytes for lifetime  */                                /*  2 bytes for urllen    */                                /*  1 byte for authcount  */    bufsize += srvtypelen + 2;  /*  2 bytes for len field */    bufsize += scopelistlen + 2;/*  2 bytes for len field */    bufsize += attrlistlen + 2; /*  2 bytes for len field */    bufsize += 1;               /*  1 byte for authcount  */    #ifdef ENABLE_SLPv2_SECURITY    bufsize += urlauthlen;    bufsize += attrauthlen;    #endif      *buf = SLPBufferAlloc(bufsize);    if(*buf == 0)    {        result = SLP_ERROR_INTERNAL_ERROR;        goto CLEANUP;    }        /*------------------------------*/    /* Now build the SrvReg Message */    /*------------------------------*/    /*version*/    *((*buf)->start)       = 2;    /*function id*/    *((*buf)->start + 1)   = SLP_FUNCT_SRVREG;    /*length*/    ToUINT24((*buf)->start + 2, bufsize);    /*flags*/    ToUINT16((*buf)->start + 5, 0);    /*ext offset*/    ToUINT24((*buf)->start + 7,0);    /*xid*/    ToUINT16((*buf)->start + 10, 0);    /*lang tag len*/    ToUINT16((*buf)->start + 12,langtaglen);    /*lang tag*/    memcpy((*buf)->start + 14, langtag, langtaglen);    (*buf)->curpos = (*buf)->start + langtaglen + 14 ;    /* url-entry reserved */    *(*buf)->curpos= 0;            (*buf)->curpos = (*buf)->curpos + 1;    /* url-entry lifetime */    ToUINT16((*buf)->curpos,lifetime);    (*buf)->curpos = (*buf)->curpos + 2;    /* url-entry urllen */    ToUINT16((*buf)->curpos,urllen);    (*buf)->curpos = (*buf)->curpos + 2;    /* url-entry url */    memcpy((*buf)->curpos,url,urllen);    (*buf)->curpos = (*buf)->curpos + urllen;    /* url-entry authblock */#ifdef ENABLE_SLPv2_SECURITY    if(urlauth)    {        /* authcount */        *(*buf)->curpos = 1;        (*buf)->curpos = (*buf)->curpos + 1;        /* authblock */        memcpy((*buf)->curpos,urlauth,urlauthlen);        (*buf)->curpos = (*buf)->curpos + urlauthlen;    }    else#endif    {        /* authcount */        *(*buf)->curpos = 0;        (*buf)->curpos += 1;    }     /* service type */    ToUINT16((*buf)->curpos,srvtypelen);    (*buf)->curpos = (*buf)->curpos + 2;    memcpy((*buf)->curpos,srvtype,srvtypelen);    (*buf)->curpos = (*buf)->curpos + srvtypelen;    /* scope list */    ToUINT16((*buf)->curpos,scopelistlen);    (*buf)->curpos = (*buf)->curpos + 2;    memcpy((*buf)->curpos,scopelist,scopelistlen);    (*buf)->curpos = (*buf)->curpos + scopelistlen;    /* attr list */    ToUINT16((*buf)->curpos,attrlistlen);    (*buf)->curpos = (*buf)->curpos + 2;    memcpy((*buf)->curpos,attrlist,attrlistlen);    (*buf)->curpos = (*buf)->curpos + attrlistlen;    /* attribute auth block */#ifdef ENABLE_SLPv2_SECURITY    if(attrauth)    {        /* authcount */        *(*buf)->curpos = 1;        (*buf)->curpos = (*buf)->curpos + 1;        /* authblock */        memcpy((*buf)->curpos,attrauth,attrauthlen);        (*buf)->curpos = (*buf)->curpos + attrauthlen;    }    else#endif    {        /* authcount */        *(*buf)->curpos = 0;        (*buf)->curpos = (*buf)->curpos + 1;    }    /*------------------------------------------------*/    /* Ok Now comes the really stupid (and lazy part) */    /*------------------------------------------------*/    *msg = SLPMessageAlloc();    if(*msg == 0)    {        SLPBufferFree(*buf);        *buf=0;        result = SLP_ERROR_INTERNAL_ERROR;        goto CLEANUP;    }    peer.sin_addr.s_addr = htonl(LOOPBACK_ADDRESS);    result = SLPMessageParseBuffer(&peer,*buf,*msg);    (*msg)->body.srvreg.source = SLP_REG_SOURCE_STATIC;        CLEANUP:        /*----------------------------------*/    /* Check for errors and free memory */    /*----------------------------------*/    switch(result)    {    case SLP_ERROR_INTERNAL_ERROR:        SLPDLog("\nERROR: Out of memory one reg file line:\n   %s\n",line);        break;    case SLP_ERROR_INVALID_REGISTRATION:        SLPDLog("\nERROR: Invalid reg file format near:\n   %s\n",line);        break;    case SLP_ERROR_SCOPE_NOT_SUPPORTED:        SLPDLog("\nERROR: Duplicate scopes or scope list with imbedded spaces near:\n   %s\n",line);        break;    default:        break;    }            if(langtag) xfree(langtag);    if(scopelist) xfree(scopelist);    if(url) xfree(url);    if(srvtype) xfree(srvtype);    if(attrlist)xfree(attrlist);#ifdef ENABLE_SLPv2_SECURITY    if(urlauth) xfree(urlauth);    if(attrauth) xfree(attrauth);#endif    return result;}

⌨️ 快捷键说明

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