Exemple #1
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Delete a profile. If there is a file associated with the profile,
 *	it is also deleted.
 *
 * AUTHOR
 * 	lsh & mlb
 *
 * DATE CREATED
 *	May 4, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileDelete (
    SpProfile_t FAR *Profile)
{
    KpChar_t		*fileName;
    SpProfileData_t	FAR *ProfileData;
    KpFileProps_t		Props;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (*Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* lock FileName handle and return  ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);

#if defined (KPMAC)
    /* Convert SpIOFileChar_t to KpFileProps_t */
    SpCvrtSpFileProps (&(ProfileData->Props), &Props);
#endif

    /* delete associated file name */
    if (NULL != fileName)
        KpFileDelete (fileName, &Props);

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (*Profile);
    return SpProfileFree (Profile);
}
Exemple #2
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Public)
 *	Return the List of Profiles with those that pass the new
 *	search criteria in the front.  foundCount is the number
 *      of Profiles that were found that passed the search criteria
 *
 * AUTHOR
 * 	doro
 *
 * DATE CREATED
 *	November 20, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileSearchRefine(
                                SpSearch_t	*SearchCriterion,
                                SpProfile_t	*profileList,
                                KpInt32_t	listSize,
                                KpInt32_t	*foundCount)
{

SpProfileData_t		*Pf;
SpProfile_t		ThisProfile;
SpStatus_t		status;
KpInt32_t		i, j, critSize;
SpSearchCriterion_t *criterion;

   *foundCount = 0;

   /* Loop thru those profiles given and test header information
    * against search criteria
    */
   for (i = 0; i < listSize; i++)
   {
      Pf = SpProfileLock(profileList[i]);
      if (Pf == NULL)
         return SpStatBadProfile;

      if ((status = SpProfileCheck(SearchCriterion, &Pf->Header)) ==
          SpStatSuccess)
      {
         if (*foundCount == i)
            (*foundCount)++;
         else
         {
            ThisProfile = profileList[i];
            for (j = i; j > *foundCount;  j--)
            {
               profileList[j] = profileList[j - 1];
            }
            profileList[(*foundCount)++] = ThisProfile;
         }
      }
      SpProfileUnlock(profileList[i]);
   }
   if ((*foundCount > 0) &&
       (SearchCriterion != (SpSearch_t *)NULL))
   {
		critSize = SearchCriterion->critSize;
		criterion = SearchCriterion->criterion;
		for (i = 0; i < SearchCriterion->critCount; i++)
		{
			if (criterion->SearchElement == SPSEARCH_TIMEORDER) 
			{
				status = SpProfileOrderList(profileList, *foundCount);
				break;
			}
			criterion = (SpSearchCriterion_t *)(critSize + (KpUInt8_p)criterion);
		}
   }

   return SpStatSuccess;
}
Exemple #3
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Public)
 *	Return the name of the currently associated file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	September 20, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileGetDiskName (
    SpProfile_t		Profile,
    size_t			BufferSize,
    KpChar_t		*Buffer,
    SpIOFileChar_t	*Props)
{
    char				FAR *fileName;
    SpProfileData_t		FAR *ProfileData;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* lock FileName handle and return  ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);

    /* check for case of no file name */
    if (NULL == fileName) {
        *Buffer = '\0';
        SpProfileUnlock (Profile);
        return SpStatNoFileName;
    }

    /* check for buffer large enough */
    if (BufferSize < strlen (fileName) + 1) {
        unlockBuffer (ProfileData->FileName);
        SpProfileUnlock (Profile);
        return SpStatBufferTooSmall;
    }

    strcpy (Buffer, fileName);

    /* Get file properties */
#if defined (KPMAC)
    SpProfSetSpFileData (&(ProfileData->Props), Props);
#endif

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);

    return SpStatSuccess;
}
Exemple #4
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Private -- phase out 5/4/95)
 *	Return the name of the currently associated file.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	September 20, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileGetFileName (
    SpProfile_t		Profile,
    size_t			BufferSize,
    char			FAR *Buffer)
{
    char				FAR *fileName;
    SpProfileData_t		FAR *ProfileData;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* lock FileName handle and return  ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);

    /* check for case of no file name */
    if (NULL == fileName) {
        *Buffer = '\0';
        SpProfileUnlock (Profile);
        return SpStatNoFileName;
    }

    /* check for buffer large enough */
    if (BufferSize < strlen (fileName) + 1) {
        unlockBuffer (ProfileData->FileName);
        SpProfileUnlock (Profile);
        return SpStatBufferTooSmall;
    }

    strcpy (Buffer, fileName);

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);

    return SpStatSuccess;
}
Exemple #5
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Set the header for the profile.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	March 18, 1994
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileSetHeader (
				SpProfile_t		Profile,
				SpHeader_t		FAR *Header)
{
	SpProfileData_t FAR *ProfileData;
	
/* convert profile handle to data pointer */
	ProfileData = SpProfileLock (Profile);
	if (NULL == ProfileData)
		return SpStatBadProfile;

	ProfileData->Header = *Header;
	SpProfileUnlock (Profile);
	return SpStatSuccess;
}
Exemple #6
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Public)
 *	Set the name of the file to associate with the profile.
 *	If the Name is NULL no file will be associated with the profile.
 *
 * AUTHOR
 * 	lsh & mlb
 *
 * DATE Copied
 *	November 15, 1995
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileSetName (
    SpProfile_t		Profile,
    KpChar_t		*FileName,
    SpFileProps_t	*Props)
{
    char			FAR *fileName;
    SpProfileData_t		FAR *ProfileData;
    SpStatus_t		status;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* Free current FileName if one is there */
    if (ProfileData->FileName != NULL)
    {
        if (ProfileData->TagArray == NULL)
            status = SpProfilePopTagArray(ProfileData);

        freeBuffer(ProfileData->FileName);
    }

    /* create the FileName handle */
    ProfileData->FileName = allocBufferHandle (strlen (FileName) + 1);
    if (ProfileData->FileName == NULL)
        return SpStatMemory;

    /* lock FileName handle and return ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);
    if (fileName == NULL)
        return SpStatMemory;

    /* copy text data into the newly allocated space */
    strcpy (fileName, FileName);

    /* Copy props information into internal profile data structure */
#if defined (KPMAC)
    SpProfSetSpFileProps (Props, &(ProfileData->Props));
#endif

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);
    return SpStatSuccess;
}
Exemple #7
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Iterate over all the tags in a profile.  Call user supplied
 *	function with the Id of each tag.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	July 7, 1994
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpTagIter (
				SpProfile_t		Profile,
				SpTagIter_t		TagIterFunc,
				void			FAR *Data)
{
	KpInt32_t		index;
	SpProfileData_t		FAR *ProfileData;
	SpTagDirEntry_t	FAR *tagArray;
	SpStatus_t			Status;

/* convert profile handle to pointer to locked memory */
	ProfileData = SpProfileLock (Profile);
	if (NULL == ProfileData)
		return SpStatBadProfile;

	Status = SpDoIter ( TagIterFunc, SpIterInit, NULL, 0, Data);

	/* Check if Profile found via Search function */
	if (ProfileData->TagArray == NULL)
		/* If so, it needs the Tag Array Loaded */
		SpProfilePopTagArray(ProfileData);

	for (index = 0; (index < ProfileData->TotalCount) && (Status == SpStatSuccess); index++)
	{
		/* User Callback Function could unlock since the
		   Profile is available, so lock before calling */
		/* lock TagArray handle and return ptr */
		tagArray = (SpTagDirEntry_t FAR *) 
				lockBuffer (ProfileData->TagArray);

		/* call users function ONLY IF VALID ENTRY */	
		if (tagArray[index].TagDataSize != -1)
			Status = SpDoIter(TagIterFunc,
					SpIterProcessing, 
					Profile, 
					tagArray[index].TagId, 
					Data);
	}

	unlockBuffer (ProfileData->TagArray);

	SpDoIter ( TagIterFunc, SpIterTerm, NULL, 0, Data);

	SpProfileUnlock (Profile);
	return Status;
}
Exemple #8
0
/*--------------------------------------------------------------------
 * DESCRIPTION  (Semi-Private)
 *      Valid the handle points to memory with Sig set correctly
 *
 * AUTHOR
 *      doro
 *
 * DATE CREATED
 *      January 31, 1996
 *------------------------------------------------------------------*/
KpBool_t KSPAPI SpProfileValidHandle(SpProfile_t SpProf)
{
    SpProfileData_t		*Pf;
    KpBool_t		Result = KPFALSE;

    if (SpProf != NULL)
    {

        Pf = SpProfileLock(SpProf);
        if (Pf != NULL)
        {
            if (Pf->Signature == SpProfileDataSig)
                Result = KPTRUE;
            SpProfileUnlock(SpProf);
        }
    }
    return Result;
}
Exemple #9
0
/*--------------------------------------------------------------------
 * DESCRIPTION	(Private -- phase out 5/4/95)
 *	Set the name of the file to associate with the profile.
 *	If the Name is NULL no file will be associated with the profile.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	Octorber 22, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileSetFileName (
    SpProfile_t		Profile,
    char			FAR *FileName)
{
    char			FAR *fileName;
    SpProfileData_t	FAR *ProfileData;

    /* convert profile handle to data pointer */
    ProfileData = SpProfileLock (Profile);
    if (NULL == ProfileData)
        return SpStatBadProfile;

    /* Free current FileName if one is there */
    if (ProfileData->FileName != NULL)
        freeBuffer(ProfileData->FileName);

    /* create the FileName handle */
    ProfileData->FileName = allocBufferHandle (strlen (FileName) + 1);
    if (ProfileData->FileName == NULL)
        return (SpStatMemory);

    /* lock FileName handle and return ptr */
    fileName = (char *) lockBuffer (ProfileData->FileName);
    if (fileName == NULL)
        return (SpStatMemory);

    /* copy text data into the newly allocated space */
    strcpy (fileName, FileName);

#if defined (KPMAC)
    SpProfileClearProps(&(ProfileData->Props));
#endif

    /* unlock handles */
    unlockBuffer (ProfileData->FileName);
    SpProfileUnlock (Profile);
    return SpStatSuccess;
}
Exemple #10
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Create profile that uses supplied buffer as the profile data.
 *
 * AUTHOR
 * 	lsh
 *
 * DATE CREATED
 *	October 20, 1993
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileLoadFromBuffer (
				SpCallerId_t	CallerId,
				void			FAR *Buffer,
				SpProfile_t		FAR *Profile)
{
	SpStatus_t		Status;
	SpProfileData_t	FAR *ProfileData;
	
	Status = SpProfileAlloc (CallerId, Profile, &ProfileData);
	if (SpStatSuccess != Status)
		return Status;

/* get profile header into internal format */
	Status = SpProfileLoadFromBufferImp (ProfileData,  Buffer);

	SpProfileUnlock (*Profile);

/* free profile if an error occurred */
	if (SpStatSuccess != Status)
		SpProfileFree (Profile);

	return Status;
}
Exemple #11
0
static KpBool_t TestFile(KpfileDirEntry_t FAR *fileSearch,
		  SpCallerId_t	CallerId,
		  SpStatus_t	*ReturnStatus,
                  SpSearch_t	*SearchCriterion,
		  SpProfile_t	*profileList,
		  KpInt32_t	listSize,
		  KpInt32_t	TotalAvailable,
		  KpInt32_t	*CurrentIndex)
{

SpProfile_t		*profPtr;
SpHeader_t		Header;
SpStatus_t		Status;
SpFileProps_t	FileProp;
SpProfileData_t FAR	*ProfData;
KpBool_t		returnBool = KPTRUE;	/* assume we will continue */
char			*filename;
KpInt32_t		searchMode = SEARCH_RECURSIVE | SPSEARCHFORALL;
SpDataBase_t		DataBase;
char			Dir1[MAX_PATH];
SpDataBaseEntry_t	List[1];

#if defined (KPMAC)
KpUInt16_t		vRefNumSave;
KpUInt32_t		dirIDSave;
int			i;
#endif

if ((fileSearch->opStatus == IOFILE_FINISHED) ||
    (fileSearch->opStatus == IOFILE_STARTED) ||
	(fileSearch->opStatus == IOFILE_ERROR))
{
   return returnBool;
}

#if defined (KPMAC)
   FileProp.vRefNum = fileSearch->osfPrivate.parm.dirInfo.ioVRefNum;
   FileProp.dirID   = fileSearch->osfPrivate.parm.dirInfo.ioDrParID;
#endif

   /* Search into sub-directories */
   if (IsDirectory(fileSearch))
   {
      DataBase.numEntries = 1;
      if (fileSearch->nwAttr & ATTR_DIRECTORY)
      	searchMode |= SEARCH_NOT_RECURSIVE;
      if (fileSearch->nwAttr & ATTR_LINK)
      	searchMode |= SEARCH_NOT_RESOLVE_ALIAS;
      	
#if defined (KPMAC)
	// Setup vRefNum/DirID of subdirectory.  Save original and restore vefore returning
  	 List[0].fileProps.vRefNum = fileSearch->osfPrivate.parm.dirInfo.ioVRefNum;
   	List[0].fileProps.dirID   = fileSearch->osfPrivate.parm.dirInfo.ioDrParID;
	vRefNumSave = fileSearch->osfPrivate.vRefNum;
	dirIDSave = fileSearch->osfPrivate.dirID;
	
	// Only search one level of subdirectory on Mac
	searchMode |= SEARCH_NOT_RECURSIVE;
#endif
#if defined (KPUNIX)
      strcpy(Dir1, fileSearch->osfPrivate.base_Dir);
      strcat(Dir1, "/");
      strcat(Dir1, fileSearch->fileName);
#else
      strcpy(Dir1, fileSearch->fileName);
#endif

      List[0].dirName  = (char *)Dir1;
      DataBase.Entries = List;
      Status = SpSearchEngine(CallerId, &DataBase, SearchCriterion, KPFALSE,
                    profileList, listSize, CurrentIndex, searchMode,
                    (KpfileCallBack_t)TestFileCB);
#if defined (KPMAC)
	 fileSearch->osfPrivate.vRefNum = vRefNumSave;
	 fileSearch->osfPrivate.dirID = dirIDSave;
#endif
      if (Status == SpStatSuccess)
         return KPTRUE;
      else
         return KPFALSE;
   }

   Status = SpProfileLoadHeader(fileSearch->fileName,
                                    &FileProp, &Header);
   if (Status == SpStatSuccess)
   {
      Status = SpProfileCheck(SearchCriterion, &Header);
      if (Status == SpStatSuccess)
      {
         if (*CurrentIndex < listSize)
         {
            profPtr = &profileList[*CurrentIndex];

            Status = SpProfileAlloc(CallerId,
                                    profPtr,
                                    &ProfData);
            if (Status == SpStatSuccess)
            {
               if ((Status = SpProfileSetHeader(*profPtr,
                                                &Header)) ==
                    SpStatSuccess)
               {
                  ProfData->FileName = allocBufferHandle(
                     strlen(fileSearch->fileName) + 1);
                  if (ProfData->FileName == 0)
                  {
                     SpProfileFree(profPtr);
                     return KPFALSE;
                  }
                  filename = (char *)lockBuffer(ProfData->FileName);
                  if (filename == 0)
                  {
                     freeBuffer(ProfData->FileName);
                     SpProfileFree(profPtr);
                     return KPFALSE;
                  }
                  strcpy(filename, fileSearch->fileName);
	              unlockBuffer (ProfData->FileName);
                  ProfData->TotalCount = 0;
                  freeBuffer(ProfData->TagArray);
                  ProfData->TagArray   = NULL;
#if defined (KPMAC)
                  ProfData->Props.vRefNum     = fileSearch->osfPrivate.vRefNum;
                  ProfData->Props.dirID       = fileSearch->osfPrivate.dirID;
                  for (i= 0; i < 5; i++)
                  {
                     ProfData->Props.fileType[i]    = NULL;
                     ProfData->Props.creatorType[i] = NULL;
                  }
#endif

                  (*CurrentIndex)++;
                  if ((*CurrentIndex >= listSize) &&
                      (TotalAvailable == 0))
                     returnBool = KPFALSE;
               } else 
               {
                  *ReturnStatus = Status;
                  returnBool = KPFALSE;
               } /* if SpProfileSetHeader */
               SpProfileUnlock(*profPtr);
            } else
            {
               *ReturnStatus = (KpInt32_t)Status;
               returnBool = KPFALSE;
            } /* if SpProfileAlloc */
         } else
            (*CurrentIndex)++;
      } /* if SpProfileCheck */
   } /* if SpProfileLoadHeader */
   return returnBool;
}