Exemple #1
0
/*=========================================================================*/
void SLPDDatabaseAge(int seconds)
/* Agea the database entries and clears new and deleted entry lists        */
/*                                                                         */
/* seconds  (IN) the number of seconds to age each entry by                */
/*                                                                         */
/* Returns  - None                                                         */
/*=========================================================================*/
{
    SLPDDatabaseEntry* entry;
    SLPDDatabaseEntry* del   = 0;

    /* Age the database */
    entry = (SLPDDatabaseEntry*)G_DatabaseList.head;
    while(entry)
    {
        /* don't age services with lifetime > SLP_LIFETIME_MAXIMUM */
        if(entry->lifetime < SLP_LIFETIME_MAXIMUM)
    	{
            entry->lifetime = entry->lifetime - seconds;
            if(entry->lifetime <= 0)
            {
                del = entry;
            }
    	}
        
        entry = (SLPDDatabaseEntry*)entry->listitem.next;

        if(del)
        {
            FreeEntry((SLPDDatabaseEntry*)SLPListUnlink(&G_DatabaseList,(SLPListItem*)del));
            del = 0;
        }                                                               
    }
}
Exemple #2
0
/*-------------------------------------------------------------------------*/
void FreeAllEntries(SLPList* list)
/*-------------------------------------------------------------------------*/
{
    while(list->count)
    {
        FreeEntry((SLPDDatabaseEntry*)SLPListUnlink(list,list->head));
    }
}
Exemple #3
0
int DfsInodeDelete(int handle) {
    int i;
    dfs_block indirect_table;
    uint32 *table;
  //  printf("In DfsInodeDelete\n");
    if (sb.valid == 0){
       printf("File system not open!\n");
       return DFS_FAIL;
    }
    if((handle<0)||(handle>DFS_INODE_MAX_NUM)){
       printf("Invalid inode handle = %d\n",handle);
       return DFS_FAIL;
    }
     if(inodes[handle].inuse == 0){
       printf("Inode not allocated!\n");
       return DFS_FAIL;
    }
    LockHandleAcquire(lock_inode);
    //Free direct table then check if there is indirect address
    for(i=0;i<10;i++){
      if(inodes[handle].direct[i]!=0){
      if(DfsFreeBlock((int)inodes[handle].direct[i])==DFS_FAIL){
         printf("Cannot free blocks in direct table!\n");
         return DFS_FAIL;
      }
      inodes[handle].direct[i]=0;
     }
    }
   //Free the indirect table
    if(inodes[handle].indirect != 0){
      table =(uint32 *)(&indirect_table);
      DfsReadBlock(inodes[handle].indirect,&indirect_table);
        for(i=0;i<(sb.filesys_blocksize)/sizeof(uint32);i++){
           if(table[i]!=0){
             if (DfsFreeBlock((int)table[i])== DFS_FAIL){
                 printf("Cannot free blocks in indirect table\n");
                 return DFS_FAIL;
               }
           }
        }
       if(DfsFreeBlock((int)inodes[handle].indirect)==DFS_FAIL){
          printf("Cannot free blocks in indirect table\n");
       }
       inodes[handle].indirect=0;
     }

    FreeEntry(handle);
    inodes[handle].filesize = 0;
  //  for(i=0;i< FILENAME_LENGTH;i++){
 //       inodes[handle].filename[i]='\0';
 //   }
    inodes[handle].permission = 0;
    inodes[handle].type = 0;
    inodes[handle].ownerid = 0;
    inodes[handle].inuse = 0;
    LockHandleRelease(lock_inode);
    return DFS_SUCCESS;
}
/*
 * Remove thread id from the map.
 */
void ThreadHandleMapDelete(ThreadHandleMap *map, DWORD thread_id) {
  int i;
  for (i = 0; i < map->size; ++i) {
    if (map->data[i].id == thread_id) {
      FreeEntry(map, i);
      return;
    }
  }
}
Exemple #5
0
/*=========================================================================*/
int SLPDDatabaseDeReg(SLPSrvDeReg* srvdereg)
/* Remove a service registration from the database                         */
/*                                                                         */
/* regfile  -   (IN) filename of the registration file to read into the    */
/*              database. Pass in NULL for no file.                        */
/*                                                                         */
/* Returns  -   Zero on success.  Non-zero if syntax error in registration */
/*              file.                                                      */
/*=========================================================================*/

{
    SLPDDatabaseEntry* del = 0;
    SLPDDatabaseEntry* entry = (SLPDDatabaseEntry*)G_DatabaseList.head;


    while(entry)
    {
        if(SLPCompareString(entry->urllen,
                            entry->url,
                            srvdereg->urlentry.urllen,
                            srvdereg->urlentry.url) == 0)
        {
            if(SLPIntersectStringList(entry->scopelistlen,
                                      entry->scopelist,
                                      srvdereg->scopelistlen,
                                      srvdereg->scopelist) > 0)
            {
                if(G_SlpdProperty.traceReg)
                {
                    SLPDLogTraceReg("SrvDeReg",entry);
                }
                
                del = entry;
                
                break;
            } 
        }             
        
        entry = (SLPDDatabaseEntry*) entry->listitem.next;

        if(del)
        {
            FreeEntry((SLPDDatabaseEntry*)SLPListUnlink(&G_DatabaseList,(SLPListItem*)del));
            del = 0;
        }
    }

    return 0;
}
Exemple #6
0
struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize)
{ struct Library *SysBase = *(struct Library **)4L;
  struct newMemList nml;
  struct MemList *ml;
  struct Task *newtask;
  APTR task2;

  stacksize=(stacksize+3)&~3;

  { long *p1,*p2;
    int i;

    for (p1=(long *)&nml,p2=(long*)&MemTemplate,i=7; i; *p1++=*p2++,i--) ;
    *p1=stacksize;
  }

  if (!(((unsigned int)ml=AllocEntry((struct MemList *)&nml)) & (1<<31))) {
    newtask=ml->ml_ME[0].me_Addr;
    newtask->tc_Node.ln_Type = NT_TASK;
    newtask->tc_Node.ln_Pri  = pri;
    newtask->tc_Node.ln_Name = name;
    newtask->tc_SPReg        = (APTR)((ULONG)ml->ml_ME[1].me_Addr+stacksize);
    newtask->tc_SPLower      = ml->ml_ME[1].me_Addr;
    newtask->tc_SPUpper      = newtask->tc_SPReg;
    NEWLIST(&newtask->tc_MemEntry);
    AddHead(&newtask->tc_MemEntry,&ml->ml_Node);
    task2=AddTask(newtask,initpc,0);
    if (SysBase->lib_Version>36 && !task2) {
      FreeEntry(ml); newtask = NULL;
    }
  }
  else
    newtask = NULL;

  return newtask;
}
Exemple #7
0
/*=========================================================================*/
int SLPDDatabaseReg(SLPSrvReg* srvreg,
                    int fresh,
                    pid_t pid,
                    uid_t uid)
/* Add a service registration to the database                              */
/*                                                                         */
/* srvreg   -   (IN) pointer to the SLPSrvReg to be added to the database  */
/*                                                                         */
/* fresh    -   (IN) pass in nonzero if the registration is fresh.         */
/*                                                                         */
/* pid      -   (IN) process id of the process that registered the service */
/*                                                                         */
/* uid      -   (IN) user id of the user that registered the service       */
/*                                                                         */
/* Returns  -   Zero on success.  non-zero on error                        */
/*                                                                         */
/* NOTE:        All registrations are treated as fresh regardless of the   */
/*              setting of the fresh parameter                             */
/*=========================================================================*/
{
    int                result = 0;
    SLPDDatabaseEntry* entry  = (SLPDDatabaseEntry*)G_DatabaseList.head;

    /* Check to see if there is already an identical entry */
    while(entry)
    {
        if(SLPCompareString(entry->urllen,
                            entry->url,
                            srvreg->urlentry.urllen,
                            srvreg->urlentry.url) == 0)
        {
            if(SLPIntersectStringList(entry->scopelistlen,
                                      entry->scopelist,
                                      srvreg->scopelistlen,
                                      srvreg->scopelist) > 0)
            {
                SLPListUnlink(&G_DatabaseList,(SLPListItem*)entry);
                break;
            } 
        }             
        
        entry = (SLPDDatabaseEntry*) entry->listitem.next;
    }
    

    /* if no identical entry are found, create a new one */
    if(entry == 0)
    {
        entry = (SLPDDatabaseEntry*)malloc(sizeof(SLPDDatabaseEntry));
        if(entry == 0)
        {
            return -1;
        }
        memset(entry,0,sizeof(SLPDDatabaseEntry));
    }
    
    /* copy info from the message from the wire to the database entry */
    entry->pid          = pid;
    entry->uid          = uid;
    entry->scopelistlen = srvreg->scopelistlen;
    entry->scopelist    = (char*)memdup(srvreg->scopelist,srvreg->scopelistlen);
    entry->lifetime     = srvreg->urlentry.lifetime;
    entry->urllen       = srvreg->urlentry.urllen;
    entry->url          = (char*)memdup(srvreg->urlentry.url, srvreg->urlentry.urllen);
    entry->srvtypelen   = srvreg->srvtypelen;
    entry->srvtype      = (char*)memdup(srvreg->srvtype,srvreg->srvtypelen);
    entry->attrlistlen  = srvreg->attrlistlen;
    if (entry->attrlistlen)
	entry->attrlist = (char*)memdup(srvreg->attrlist,srvreg->attrlistlen);
    
    /* check for malloc() failures */
    if(entry->scopelist == 0 ||
       entry->url == 0 ||
       entry->srvtype == 0 ||
       (entry->attrlistlen && entry->attrlist == 0))
    {
        FreeEntry(entry);
        return -1;
    }
    
    /* link the new (or modified) entry into the list */
    SLPListLinkHead(&G_DatabaseList,(SLPListItem*)entry);

    /* traceReg if necessary */
    if(G_SlpdProperty.traceReg)
    {
        SLPDLogTraceReg("SrvReg", entry);
    }

    return result;
}
Exemple #8
0
/*=========================================================================*/
SLPDDatabaseEntry* SLPDRegFileReadEntry(FILE* fd, SLPDDatabaseEntry** entry)
/* A really big and nasty function that reads an entry SLPDDatabase entry  */
/* from a file. Don't look at this too hard or you'll be sick              */
/*                                                                         */
/* fd       (IN) file to read from                                         */
/*                                                                         */
/* entry    (OUT) Address of a pointer that will be set to the location of */
/*                a dynamically allocated SLPDDatabase entry.  The entry   */
/*                must be freed                                            */
/*                                                                         */
/* Returns  *entry or null on SLPD_ERROR.                                       */
/*=========================================================================*/
{
    char*   slider1;
    char*   slider2;
    char    line[4096];

    /* give the out param a value */
    *entry = 0;

    /*----------------------------------------------------------*/
    /* read the next non-white non-comment line from the stream */
    /*----------------------------------------------------------*/
    do
    {
        slider1 = RegFileReadLine(fd,line,4096);
        if(slider1 == 0)
        {
            /* read through the whole file and found no entries */
            return 0;
        }
    } while(*slider1 == 0x0d ||  *slider1 == 0x0a);

    /*---------------------------*/
    /* Allocate a database entry */
    /*---------------------------*/
    *entry = SLPDDatabaseEntryAlloc();
    if(entry == 0)
    {
        SLPFatal("Out of memory!\n");
        return 0;
    }

    /*---------------------*/
    /* Parse the url-props */
    /*---------------------*/
    slider2 = strchr(slider1,',');
    if(slider2)
    {
        /* srvurl */
        *slider2 = 0; /* squash comma to null terminate srvurl */
        (*entry)->url = strdup(TrimWhitespace(slider1));
        if((*entry)->url == 0)
        {
            SLPLog("Out of memory reading srvurl from regfile line ->%s",line);
            goto SLPD_ERROR;
        }
        (*entry)->urllen = strlen((*entry)->url);

        /* derive srvtype from srvurl */
        (*entry)->srvtype = strstr(slider1,"://");
        if((*entry)->srvtype == 0)
        {
            SLPLog("Looks like a bad url on regfile line ->%s",line);
            goto SLPD_ERROR;
        }
        *(*entry)->srvtype = 0;
        (*entry)->srvtype=strdup(TrimWhitespace(slider1));
        (*entry)->srvtypelen = strlen((*entry)->srvtype);
        slider1 = slider2 + 1;

        /*lang*/
        slider2 = strchr(slider1,',');
        if(slider2)
        {
            *slider2 = 0; /* squash comma to null terminate lang */
            (*entry)->langtag = strdup(TrimWhitespace(slider1));
            if((*entry)->langtag == 0)
            {
                SLPLog("Out of memory reading langtag from regfile line ->%s",line);
                goto SLPD_ERROR;
            }            (*entry)->langtaglen = strlen((*entry)->langtag);
            slider1 = slider2 + 1;
        }
        else
        {
            SLPLog("Expected language tag near regfile line ->%s\n",line);
            goto SLPD_ERROR;
        }

        /* ltime */
        slider2 = strchr(slider1,',');
        if(slider2)
        {
            *slider2 = 0; /* squash comma to null terminate ltime */
            (*entry)->lifetime = atoi(slider1);
            slider1 = slider2 + 1;
        }
        else
        {
            (*entry)->lifetime = atoi(slider1);
            slider1 = slider2;
        }
        if((*entry)->lifetime < 1 || (*entry)->lifetime > 0xffff)
        {
            SLPLog("Invalid lifetime near regfile line ->%s\n",line);
            goto SLPD_ERROR;
        }

        /* get the srvtype if one was not derived by the srvurl*/
        if((*entry)->srvtype == 0)
        {
            (*entry)->srvtype = strdup(TrimWhitespace(slider1));
            if((*entry)->srvtype == 0)
            {
                SLPLog("Out of memory reading srvtype from regfile line ->%s",line);
                goto SLPD_ERROR;
            }
            (*entry)->srvtypelen = strlen((*entry)->srvtype);
            if((*entry)->srvtypelen == 0)
            {
                SLPLog("Expected to derive service-type near regfile line -> %s\n",line);
                goto SLPD_ERROR;
            }
        }

    }
    else
    {
        SLPLog("Expected to find srv-url near regfile line -> %s\n",line);
        goto SLPD_ERROR;
    }

    /*-------------------------------------------------*/
    /* Read all the attributes including the scopelist */
    /*-------------------------------------------------*/
    *line=0;
    while(1)
    {
        if(RegFileReadLine(fd,line,4096) == 0)
        {
            break;
        }
        if(*line == 0x0d || *line == 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(line,"scopes",6) == 0)
        {
            /* found scopes line */
            slider1 = line;
            slider2 = strchr(slider1,'=');
            if(slider2)
            {
                slider2++;
                if(*slider2)
                {
                    /* just in case some idiot puts multiple scopes lines */
                    if((*entry)->scopelist)
                    {
                        SLPLog("scopes already defined previous to regfile line ->%s",line);
                        goto SLPD_ERROR;
                    }

                    (*entry)->scopelist=strdup(TrimWhitespace(slider2));
                    if((*entry)->scopelist == 0)
                    {
                        SLPLog("Out of memory adding scopes from regfile line ->%s",line);
                        goto SLPD_ERROR;
                    }
                    (*entry)->scopelistlen = strlen((*entry)->scopelist);
                }
            }
        }
        else
        {
            char *tag; /* Will point to the start of the tag. */
            char *val; /* Will point to the start of the value. */
            char *end;
            char *tag_end;

            tag = line;
            /*** Elide ws. ***/
            while (isspace(*tag))
            {
                tag++;
            }
            tag_end = tag;

            /*** Find tag end. ***/
            while (*tag_end && (!isspace(*tag_end)) && (*tag_end != '=')) {
                tag_end++;
            }
            while (*tag_end && *tag_end != '=') {
                tag_end++;
            }
            *tag_end = 0;

            /*** Find value start. ***/
            val = tag_end + 1;
            /*** Elide ws. ***/
            while (isspace(*val))
            {
                val++;
            }

            /*** Elide trailing ws. ***/
            end = val;

            /** Find tag end. **/
            while (*end != 0) {
                end++;
            }

            /*** Back up over trailing whitespace. ***/
            end--;
            while(isspace(*end)) {
                *end = 0; /* Overwrite ws. */
                end--;
            }

            SLPAttrSet_guess((*entry)->attr, tag, val, SLP_ADD);
        }
    }

    /* Set the scope to default if not is set */
    if((*entry)->scopelist == 0)
    {
        (*entry)->scopelist=strdup("DEFAULT");
        if((*entry)->scopelist == 0)
        {
            SLPLog("Out of memory adding DEFAULT scope\n");
            goto SLPD_ERROR;
        }
        (*entry)->scopelistlen = 7;
    }

    return *entry;

SLPD_ERROR:
    if(*entry)
    {
//        if((*entry)->srvtype) free((*entry)->srvtype);
//        if((*entry)->url) free((*entry)->url);
//        if((*entry)->langtag) free((*entry)->langtag);
//        if((*entry)->scopelist) free((*entry)->scopelist);
//        if((*entry)->attrlist) free((*entry)->attrlist);
//        free(*entry);
        FreeEntry(*entry);
        *entry = 0;
    }

    return 0;
}