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

📄 libslp_findsrvtypes.c

📁 SLP协议在linux下的实现。此版本为1.2.1版。官方网站为www.openslp.org
💻 C
📖 第 1 页 / 共 2 页
字号:
        goto FINISHED;    }    /*----------------------------------------------------------------*/    /* Build a buffer containing the fixed portion of the SRVTYPERQST */    /*----------------------------------------------------------------*/    /* naming authority */    if(strcmp(handle->params.findsrvtypes.namingauth, "*") == 0)    {        ToUINT16(curpos,0xffff); /* 0xffff indicates all service types */        curpos += 2;        bufsize--;      /* '*' is not put on the wire */    }    else    {        ToUINT16(curpos,handle->params.findsrvtypes.namingauthlen);        curpos += 2;        memcpy(curpos,               handle->params.findsrvtypes.namingauth,               handle->params.findsrvtypes.namingauthlen);        curpos += handle->params.findsrvtypes.namingauthlen;    }    /* scope list */    ToUINT16(curpos,handle->params.findsrvtypes.scopelistlen);    curpos = curpos + 2;    memcpy(curpos,           handle->params.findsrvtypes.scopelist,           handle->params.findsrvtypes.scopelistlen);    curpos = curpos + handle->params.findsrvtypes.scopelistlen;    /*--------------------------*/    /* Call the RqstRply engine */    /*--------------------------*/    do    {        #ifndef UNICAST_NOT_SUPPORTED        if ( handle->dounicast == 1 ) 	{            void *cookie = (PSLPHandleInfo) handle;	    result = NetworkUcastRqstRply(handle,                                          buf,                                          SLP_FUNCT_SRVTYPERQST,                                          bufsize,					  ProcessSrvTypeRplyCallback,					  cookie);	    break;        }	else	#endif	sock = NetworkConnectToDA(handle,                                  handle->params.findsrvtypes.scopelist,                                  handle->params.findsrvtypes.scopelistlen,                                  &peeraddr);        if(sock == -1)        {            /* use multicast as a last resort */            #ifndef MI_NOT_SUPPORTED            result = NetworkMcastRqstRply(handle,                                          buf,					  SLP_FUNCT_SRVTYPERQST,					  bufsize,                                          ProcessSrvTypeRplyCallback,					  NULL);            #else            result = NetworkMcastRqstRply(handle->langtag,                                          buf,                                          SLP_FUNCT_SRVTYPERQST,                                          bufsize,                                          ProcessSrvTypeRplyCallback,                                          handle);            #endif /* MI_NOT_SUPPORTED */            break;        }        result = NetworkRqstRply(sock,                                 &peeraddr,                                 handle->langtag,                                 0,                                 buf,                                 SLP_FUNCT_SRVTYPERQST,                                 bufsize,                                 ProcessSrvTypeRplyCallback,                                 handle);        if(result)        {            NetworkDisconnectDA(handle);        }    }while(result == SLP_NETWORK_ERROR);    FINISHED:    if(buf) xfree(buf);    return result;}                                   #ifdef ENABLE_ASYNC_API/*-------------------------------------------------------------------------*/ SLPError AsyncProcessSrvTypeRqst(PSLPHandleInfo handle)/*-------------------------------------------------------------------------*/{    SLPError result = ProcessSrvTypeRqst(handle);    xfree((void*)handle->params.findsrvtypes.namingauth);    xfree((void*)handle->params.findsrvtypes.scopelist);    handle->inUse = SLP_FALSE;    return result;}#endif/*=========================================================================*/SLPError SLPAPI SLPFindSrvTypes(SLPHandle    hSLP,                         const char  *pcNamingAuthority,                         const char  *pcScopeList,                         SLPSrvTypeCallback callback,                         void *pvCookie)/*                                                                         *//* Issue the query for service types on the language specific SLPHandle    *//* and return the results through the callback.  The parameters determine  *//* the results                                                             *//*                                                                         *//* hSLP              The language specific SLPHandle on which to search    *//*                   for service types.                                    *//*                                                                         *//* pcNamingAuthority The Naming Authority string for which service types   *//*                   for which service types are returned                  *//*                                                                         *//* pcScopeList      A pointer to a char containing comma separated list of *//*                  scope names.  Pass in the NULL or the empty string ""  *//*                  to find services in all the scopes the local host is   *//*                  configured query.                                      *//*                                                                         *//* callback         A callback function through which the results of the   *//*                  operation are reported. May not be NULL                *//*                                                                         *//* pvCookie         Memory passed to the callback code from the client.    *//*                  May be NULL.                                           *//*                                                                         *//* Returns:         If an error occurs in starting the operation, one of   *//*                  the SLPError codes is returned.                        *//*                                                                         *//*=========================================================================*/{    PSLPHandleInfo      handle;    SLPError            result;    /*------------------------------*/    /* check for invalid parameters */    /*------------------------------*/    if(hSLP == 0 ||       *(unsigned int*)hSLP != SLP_HANDLE_SIG ||       !pcNamingAuthority ||       strcmp(pcNamingAuthority, "IANA") == 0 ||       callback == 0)    {        return SLP_PARAMETER_BAD;    }    /*-----------------------------------------*/    /* cast the SLPHandle into a SLPHandleInfo */    /*-----------------------------------------*/    handle = (PSLPHandleInfo)hSLP;     /*-----------------------------------------*/    /* Check to see if the handle is in use    */    /*-----------------------------------------*/    if(handle->inUse == SLP_TRUE)    {        return SLP_HANDLE_IN_USE;    }    handle->inUse = SLP_TRUE;    /*-------------------------------------------*/    /* Set the handle up to reference parameters */    /*-------------------------------------------*/    handle->params.findsrvtypes.namingauthlen = strlen(pcNamingAuthority);    handle->params.findsrvtypes.namingauth = pcNamingAuthority;    if(pcScopeList && *pcScopeList)    {        handle->params.findsrvtypes.scopelist = pcScopeList;    }    else    {        handle->params.findsrvtypes.scopelist =        SLPGetProperty("net.slp.useScopes");     }    handle->params.findsrvtypes.scopelistlen =    strlen(handle->params.findsrvtypes.scopelist);     handle->params.findsrvtypes.callback     = callback;    handle->params.findsrvtypes.cookie       = pvCookie;     /*----------------------------------------------*/    /* Check to see if we should be async or sync   */    /*----------------------------------------------*/#ifdef ENABLE_ASYNC_API    if(handle->isAsync)    {        /* COPY all the referenced parameters */        handle->params.findsrvtypes.namingauth = xstrdup(handle->params.findsrvtypes.namingauth);        handle->params.findsrvtypes.scopelist = xstrdup(handle->params.findsrvtypes.scopelist);        /* make sure strdups did not fail */        if(handle->params.findsrvtypes.namingauth &&           handle->params.findsrvtypes.scopelist)        {            result = ThreadCreate((ThreadStartProc)AsyncProcessSrvTypeRqst,handle);        }        else        {            result = SLP_MEMORY_ALLOC_FAILED;            }        if(result)        {            if(handle->params.findsrvtypes.namingauth) xfree((void*)handle->params.findsrvtypes.namingauth);            if(handle->params.findsrvtypes.scopelist) xfree((void*)handle->params.findsrvtypes.scopelist);            handle->inUse = SLP_FALSE;        }    }    else#endif /*ifdef ENABLE_ASYNC_API*/    {        /* Leave all parameters REFERENCED */        result = ProcessSrvTypeRqst(handle);        handle->inUse = SLP_FALSE;    }    return result;}

⌨️ 快捷键说明

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