Example #1
0
/*-------------------------------------------------------------------------*/
SLPBoolean KnownDADiscoveryCallback(SLPError errorcode, 
                                    SLPMessage msg, 
                                    void* cookie)
/*-------------------------------------------------------------------------*/
{
    SLPSrvURL*      srvurl;
    SLPDAEntry*     entry;
    struct hostent* he;
    int*            count = (int*)cookie;
    
    if(msg->header.functionid == SLP_FUNCT_DAADVERT)
    {
        if(msg->body.srvrply.errorcode == 0)
        {
            /* NULL terminate scopelist */ 
            *((char*)msg->body.daadvert.scopelist + msg->body.daadvert.scopelistlen) = 0;
            if(SLPParseSrvURL(msg->body.daadvert.url, &srvurl) == 0)
            {
                he = gethostbyname(srvurl->s_pcHost);
                if(he)
                {
                    entry = SLPDAEntryCreate((struct in_addr*)(he->h_addr_list[0]),
                                             msg->body.daadvert.scopelist,
                                             msg->body.daadvert.scopelistlen);
                    ListLink((PListItem*)&G_KnownDAListHead,(PListItem)entry);
                    *count = *count + 1;
                }
                
                SLPFree(srvurl);
            }
        }                
    }
    
    return 1;
}
Example #2
0
/*=========================================================================*/
SLPDAEntry* SLPDKnownDAAdd(struct in_addr* addr,
                           unsigned long bootstamp,
                           const char* scopelist,
                           int scopelistlen)
/* Adds a DA to the known DA list.  If DA already exists, entry is updated */
/*                                                                         */
/* addr     (IN) pointer to in_addr of the DA to add                       */
/*                                                                         */
/* scopelist (IN) scope list of the DA to add                              */
/*                                                                         */
/* scopelistlen (IN) the length of the scope list                          */
/*                                                                         */
/* returns  Pointer to the added or updated                                */
/*=========================================================================*/
{
    SLPDAEntry* entry;

    /* Iterate through the list looking for an identical entry */
    entry = G_KnownDAListHead;
    while(entry)
    {
        /* for now assume entries are the same if in_addrs match */
        if (memcmp(&entry->daaddr,addr,sizeof(struct in_addr)) == 0)
        {
            /* Update an existing entry */
            if(entry->bootstamp < bootstamp)
            {
                entry->bootstamp = bootstamp;
            }
            else
            {
                /* set bootstamp to zero so that slpd will re-register with */
                /* this DA                                                  */
                bootstamp = 0;
            }
            entry->scopelist = realloc(entry->scopelist,scopelistlen);
            if(entry->scopelist)
            {
                memcpy(entry->scopelist,scopelist,scopelistlen);
                entry->scopelistlen = scopelistlen;
            }
            else
            {
                free(entry);
                entry = 0;
            }

            return entry;
        }

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

    /* Create and link in a new entry */    
    bootstamp = 0;  /* make sure we re-register with new entries */
    entry = SLPDAEntryCreate(addr,bootstamp,scopelist,scopelistlen);
    ListLink((PListItem*)&G_KnownDAListHead,(PListItem)entry);
    
    return entry;
}
Example #3
0
/*=========================================================================*/
int SLPPropertySet(const char *pcName,
                    const char *pcValue)
/*=========================================================================*/
{
    int             pcNameSize; 
    int             pcValueSize;
    SLPProperty*    newProperty; 
    
    newProperty = Find(pcName);
    pcNameSize = strlen(pcName) + 1;
    pcValueSize = strlen(pcValue) + 1;
    
    if(newProperty == 0)
    {
        /* property does not exist in the list */
        newProperty = (SLPProperty*)malloc(sizeof(SLPProperty) + pcNameSize + pcValueSize);
        if(newProperty == 0)
        {
            /* out of memory */
            errno = ENOMEM;
            return -1;
        }
        
    }
    else
    {    
        /* property already exists in the list */
        newProperty = (SLPProperty*)realloc(newProperty,sizeof(SLPProperty) + pcNameSize + pcValueSize);    
        if(newProperty == 0)
        {
            /* out of memory */
            errno = ENOMEM;
            return -1;
        }
    }
    
    /* set the pointers in the SLPProperty structure to point to areas of    */
    /* the previously allocated block of memory                              */
    newProperty->propertyName   = ((char*)newProperty) + sizeof(SLPProperty); 
    newProperty->propertyValue  = newProperty->propertyName + pcNameSize;

    /* copy the passed in name and value */
    memcpy(newProperty->propertyName,pcName,pcNameSize);
    memcpy(newProperty->propertyValue,pcValue,pcValueSize);

    /* Link the new property into the list */
    ListLink((PListItem*)&G_SLPPropertyListHead,
             (PListItem)newProperty);

    return 0;
}
Example #4
0
/*=========================================================================*/
SLPDSocket* SLPDSocketListAdd(SLPDSocketList* list, SLPDSocket* addition) 
/* Adds a free()s the specified socket from the specified list             */
/*                                                                         */
/* list     - pointer to the SLPSocketList to add the socket to.           */
/*                                                                         */
/* addition - a pointer to the socket to add                               */
/*                                                                         */
/* Returns  - pointer to the added socket or NULL on error                 */
/*=========================================================================*/
{
    ListLink((PListItem*)&list->head,(PListItem)addition);
    list->count = list->count + 1;
    return addition;
}