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

📄 slpd_v1process.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 3 页
字号:
    /*------------------------------------*/    /* Make sure that we handle the scope */    /*------ -----------------------------*/    if (SLPIntersectStringList(message->body.srvreg.scopelistlen,                               message->body.srvreg.scopelist,                               G_SlpdProperty.useScopesLen,                               G_SlpdProperty.useScopes))    {        /*---------------------------------*/        /* put the service in the database */        /*---------------------------------*/        if (ISLOCAL(message->peer.sin_addr))        {            message->body.srvreg.source= SLP_REG_SOURCE_LOCAL;        }        else        {            message->body.srvreg.source = SLP_REG_SOURCE_REMOTE;        }        errorcode = SLPDDatabaseReg(message,recvbuf);    }    else    {        errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED;    }    RESPOND:        /*--------------------------------------------------------------------*/    /* don't send back reply anything multicast SrvReg (set result empty) */    /*--------------------------------------------------------------------*/    if (message->header.flags & SLP_FLAG_MCAST)    {        result->end = result->start;        goto FINISHED;    }    /*------------------------------------------------------------*/    /* ensure the buffer is big enough to handle the whole srvack */    /*------------------------------------------------------------*/    result = SLPBufferRealloc(result, 14);    if (result == 0)    {        errorcode = SLP_ERROR_INTERNAL_ERROR;        goto FINISHED;    }    /*----------------*/    /* Add the header */    /*----------------*/    /*version*/    *(result->start)       = 1;    /*function id*/    *(result->start + 1)   = SLP_FUNCT_SRVACK;    /*length*/    ToUINT16(result->start + 2, 14);    /*flags - TODO set the flags correctly */    *(result->start + 4) = 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 the errorcode */    /*-------------------*/    ToUINT16(result->start + 12, errorcode);    FINISHED:    *sendbuf = result;    return errorcode;}/*-------------------------------------------------------------------------*/int v1ProcessSrvDeReg(struct sockaddr_in* peeraddr,                      SLPMessage message,                      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;    }    /*------------------------------------*/    /* Make sure that we handle the scope */    /*------------------------------------*/    if (SLPIntersectStringList(message->body.srvdereg.scopelistlen,                               message->body.srvdereg.scopelist,                               G_SlpdProperty.useScopesLen,                               G_SlpdProperty.useScopes))    {        /*--------------------------------------*/        /* remove the service from the database */        /*--------------------------------------*/        errorcode = SLPDDatabaseDeReg(message);    }    else    {        errorcode = SLP_ERROR_SCOPE_NOT_SUPPORTED;    }    RESPOND:    /*---------------------------------------------------------*/    /* don't do anything multicast SrvDeReg (set result empty) */    /*---------------------------------------------------------*/    if (message->header.flags & SLP_FLAG_MCAST)    {        result->end = result->start;        goto FINISHED;    }    /*------------------------------------------------------------*/    /* ensure the buffer is big enough to handle the whole srvack */    /*------------------------------------------------------------*/    result = SLPBufferRealloc(result, 14);    if (result == 0)    {        errorcode = SLP_ERROR_INTERNAL_ERROR;        goto FINISHED;    }    /*----------------*/    /* Add the header */    /*----------------*/    /*version*/    *(result->start)       = 1;    /*function id*/    *(result->start + 1)   = SLP_FUNCT_SRVACK;    /*length*/    ToUINT16(result->start + 2, 14);    /*flags - TODO set the flags correctly */    *(result->start + 4) = 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 the errorcode */    /*-------------------*/    ToUINT16(result->start + 12, errorcode);    FINISHED:    *sendbuf = result;    return errorcode;}/*-------------------------------------------------------------------------*/int v1ProcessAttrRqst(struct sockaddr_in* peeraddr,                      SLPMessage message,                      SLPBuffer* sendbuf,                      int errorcode)/*-------------------------------------------------------------------------*/{    SLPDDatabaseAttrRqstResult* db              = 0;    int                         attrlen     = 0;    int                         size        = 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.attrrqst.prlistlen,                               message->body.attrrqst.prlist,                               G_SlpdProperty.interfacesLen,                               G_SlpdProperty.interfaces))    {        result->end = result->start;        goto FINISHED;    }    /*------------------------------------*/    /* Make sure that we handle the scope */    /*------ -----------------------------*/    if (SLPIntersectStringList(message->body.attrrqst.scopelistlen,                               message->body.attrrqst.scopelist,                               G_SlpdProperty.useScopesLen,                               G_SlpdProperty.useScopes))    {        /*---------------------------------*/        /* Find attributes in the database */        /*---------------------------------*/        errorcode = SLPDDatabaseAttrRqstStart(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->attrlistlen == 0)        {            result->end = result->start;            goto FINISHED;          }    }    /*--------------------------------------------------------------*/    /* ensure the buffer is big enough to handle the whole attrrply */    /*--------------------------------------------------------------*/    size = 16; /* 12 bytes for header, 2 bytes for error code, 2 bytes                for attr-list len */    if (errorcode == 0)    {        attrlen = INT_MAX;        errorcode = SLPv1ToEncoding(0, &attrlen,                                    message->header.encoding,                                      db->attrlist,                                    db->attrlistlen);        size += attrlen;    }    /*-------------------*/    /* Alloc the  buffer */    /*-------------------*/    result = SLPBufferRealloc(result,size);    if (result == 0)    {        errorcode = SLP_ERROR_INTERNAL_ERROR;        goto FINISHED;    }    /*----------------*/    /* Add the header */    /*----------------*/    /*version*/    *(result->start)       = 1;    /*function id*/    *(result->start + 1)   = SLP_FUNCT_ATTRRPLY;    /*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 AttrRply */    /*--------------------------*/    result->curpos = result->start + 12;    /* error code*/    ToUINT16(result->curpos, errorcode);    result->curpos = result->curpos + 2;     if (errorcode == 0)    {        /* attr-list len */        ToUINT16(result->curpos, attrlen);        result->curpos = result->curpos + 2;        attrlen = size;        SLPv1ToEncoding(result->curpos, &attrlen,                        message->header.encoding,                        db->attrlist,                        db->attrlistlen);        result->curpos = result->curpos + attrlen;     }    FINISHED:    *sendbuf = result;    if (db) SLPDDatabaseAttrRqstEnd(db);    return errorcode;}        /*-------------------------------------------------------------------------*/

⌨️ 快捷键说明

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