Exemple #1
0
/*-------------------------------------------------------------------------*/
SLPDAEntry* KnownDAFromCache(int scopelistlen,
                             const char* scopelist)
/* Ask Slpd if it knows about a DA                                         */ 
/*                                                                         */
/* Returns: pointer to a new DA entry. Caller must NOT free()              */
/*-------------------------------------------------------------------------*/
{
    time_t      curtime;
    SLPDAEntry* entry;

    entry = KnownDAListFindByScope(&G_KnownDACache,scopelistlen,scopelist);
    if(entry == 0)
    {
        curtime = time(&curtime);
        if(G_KnownDALastCacheRefresh == 0 ||
           curtime - G_KnownDALastCacheRefresh > MINIMUM_DISCOVERY_INTERVAL)
        {
            G_KnownDALastCacheRefresh = curtime;

            /* discover DAs */

            if(KnownDADiscoverFromIPC() == 0)
                if(KnownDADiscoverFromProperties() == 0)
                    if(KnownDADiscoverFromDHCP() == 0)
                        KnownDADiscoverFromMulticast(scopelistlen,
                                                     scopelist);
        }

        entry = KnownDAListFindByScope(&G_KnownDACache,scopelistlen,scopelist);
    }

    return entry; 
}
Exemple #2
0
/*-------------------------------------------------------------------------*/
SLPBoolean KnownDAFromCache(int scopelistlen,
                            const char* scopelist,
                            int spistrlen,
                            const char* spistr,
                            struct in_addr* daaddr)
/* Ask Slpd if it knows about a DA                                         */ 
/*                                                                         */
/* Returns: non-zero on success, zero if DA can not be found               */
/*-------------------------------------------------------------------------*/
{
    time_t          curtime;
    
    if(KnownDAListFind(scopelistlen,
                       scopelist,
                       spistrlen,
                       spistr,
                       daaddr) == SLP_FALSE)
    {
        curtime = time(&curtime);
        if(G_KnownDALastCacheRefresh == 0 ||
           curtime - G_KnownDALastCacheRefresh > MINIMUM_DISCOVERY_INTERVAL)
        {
            G_KnownDALastCacheRefresh = curtime;

            /* discover DAs */

            if(KnownDADiscoverFromIPC() == 0)
                if(KnownDADiscoverFromProperties() == 0)
                    if(KnownDADiscoverFromDHCP() == 0)
                        KnownDADiscoverFromMulticast(scopelistlen,
                                                     scopelist);
        }

        return KnownDAListFind(scopelistlen,
                               scopelist,
                               spistrlen,
                               spistr,
                               daaddr);
    }

    return SLP_TRUE; 
}
Exemple #3
0
/*=========================================================================*/
int KnownDAGetScopes(int* scopelistlen,
                     char** scopelist)
/* Gets a list of scopes from the known DA list                            */
/*                                                                         */
/* scopelistlen (OUT) stringlen of the scopelist                           */
/*                                                                         */
/* scopelist (OUT) NULL terminated list of scopes                          */
/*                                                                         */
/* returns: zero on success, non-zero on failure                           */
/*=========================================================================*/
{
    time_t      curtime;
    SLPDAEntry* entry; 
    int         newlen;

    /* Refresh the cache if necessary */
    curtime = time(&curtime);
    if(G_KnownDALastCacheRefresh == 0 ||
       curtime - G_KnownDALastCacheRefresh > MINIMUM_DISCOVERY_INTERVAL)
    {
        G_KnownDALastCacheRefresh = curtime;

        /* discover DAs */
        if(KnownDADiscoverFromIPC() == 0)
        {
            KnownDADiscoverFromDHCP();
            KnownDADiscoverFromProperties();
            KnownDADiscoverFromMulticast(0,"");
        }

        /* TODO: */
        /* enumerate through all the knownda entries and generate a */
        /* scopelist                                                */
        entry = (SLPDAEntry*)G_KnownDACache.head;
        while(entry)
        {
            newlen = G_KnownDAScopesLen;
            while(SLPUnionStringList(G_KnownDAScopesLen,
                                     G_KnownDAScopes,
                                     entry->scopelistlen,
                                     entry->scopelist,
                                     &newlen,
                                     G_KnownDAScopes) < 0)
            {
                G_KnownDAScopes = realloc(G_KnownDAScopes,newlen);
                if(G_KnownDAScopes == 0)
                {
                    G_KnownDAScopesLen = 0;
                    break;
                }
            }
            G_KnownDAScopesLen = newlen;

            entry = (SLPDAEntry*) entry->listitem.next;
        }

        /* Explicitly add in the useScopes property */
        newlen = G_KnownDAScopesLen;
        while(SLPUnionStringList(G_KnownDAScopesLen,
                                 G_KnownDAScopes,
                                 strlen(SLPPropertyGet("net.slp.useScopes")),
                                 SLPPropertyGet("net.slp.useScopes"),
                                 &newlen,
                                 G_KnownDAScopes) < 0)
        {
            G_KnownDAScopes = realloc(G_KnownDAScopes,newlen);
            if(G_KnownDAScopes == 0)
            {
                G_KnownDAScopesLen = 0;
                break;
            }
        }
        G_KnownDAScopesLen = newlen;
    }


    if(G_KnownDAScopesLen)
    {
        *scopelist = malloc(G_KnownDAScopesLen + 1);
        if(*scopelist == 0)
        {
            return -1;
        }
        memcpy(*scopelist,G_KnownDAScopes, G_KnownDAScopesLen);
        (*scopelist)[G_KnownDAScopesLen] = 0; 
        *scopelistlen = G_KnownDAScopesLen;
    }
    else
    {
        *scopelist = strdup("");
        if(*scopelist == 0)
        {
            return -1;
        }
        *scopelistlen = 0; 
    }

    return 0;
}
Exemple #4
0
/*=========================================================================*/
int KnownDAGetScopes(int* scopelistlen,
                     char** scopelist)
/* Gets a list of scopes from the known DA list                            */
/*                                                                         */
/* scopelistlen (OUT) stringlen of the scopelist                           */
/*                                                                         */
/* scopelist (OUT) NULL terminated list of scopes                          */
/*                                                                         */
/* returns: zero on success, non-zero on failure                           */
/*=========================================================================*/
{
    int                 newlen;
    time_t              curtime;
    SLPDatabaseHandle   dh;
    SLPDatabaseEntry*   entry;
    
    /* Refresh the cache if necessary */
    curtime = time(&curtime);
    if(G_KnownDALastCacheRefresh == 0 ||
       curtime - G_KnownDALastCacheRefresh > MINIMUM_DISCOVERY_INTERVAL)
    {
        G_KnownDALastCacheRefresh = curtime;

        /* discover DAs */
        if(KnownDADiscoverFromIPC() == 0)
        {
            KnownDADiscoverFromDHCP();
            KnownDADiscoverFromProperties();
            KnownDADiscoverFromMulticast(0,"");
        }
    }

    /* enumerate through all the knownda entries and generate a */
    /* scopelist                                                */
    dh = SLPDatabaseOpen(&G_KnownDACache);
    if(dh)
    {
        /*-----------------------------------*/
        /* Check to find the requested entry */
        /*-----------------------------------*/
        while(1)
        {
            entry = SLPDatabaseEnum(dh);
            if(entry == NULL) break;
            newlen = G_KnownDAScopesLen;
            while(SLPUnionStringList(G_KnownDAScopesLen,
                                     G_KnownDAScopes,
                                     entry->msg->body.daadvert.scopelistlen,
                                     entry->msg->body.daadvert.scopelist,
                                     &newlen,
                                     G_KnownDAScopes) < 0)
            {
                G_KnownDAScopes = xrealloc(G_KnownDAScopes,newlen);
                if(G_KnownDAScopes == 0)
                {
                    G_KnownDAScopesLen = 0;
                    break;
                }
            }
            G_KnownDAScopesLen = newlen;

        }

        SLPDatabaseClose(dh);
    }

    /* Explicitly add in the useScopes property */
    newlen = G_KnownDAScopesLen;
    while(SLPUnionStringList(G_KnownDAScopesLen,
                             G_KnownDAScopes,
                             strlen(SLPPropertyGet("net.slp.useScopes")),
                             SLPPropertyGet("net.slp.useScopes"),
                             &newlen,
                             G_KnownDAScopes) < 0)
    {
        G_KnownDAScopes = xrealloc(G_KnownDAScopes,newlen);
        if(G_KnownDAScopes == 0)
        {
            G_KnownDAScopesLen = 0;
            break;
        }
    }
    G_KnownDAScopesLen = newlen;


    if(G_KnownDAScopesLen)
    {
        *scopelist = xmalloc(G_KnownDAScopesLen + 1);
        if(*scopelist == 0)
        {
            return -1;
        }
        memcpy(*scopelist,G_KnownDAScopes, G_KnownDAScopesLen);
        (*scopelist)[G_KnownDAScopesLen] = 0; 
        *scopelistlen = G_KnownDAScopesLen;
    }
    else
    {
        *scopelist = xstrdup("");
        if(*scopelist == 0)
        {
            return -1;
        }
        *scopelistlen = 0; 
    }

    return 0;
}