Beispiel #1
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Test profile with header and or tag search criteria and report status
 *
 * AUTHOR
 * 	Sakey
 *
 * DATE CREATED
 *	July, 2002
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileCheckEx(
                                SpSearch_p              SearchValue,
                                char				*Filename,
								SpFileProps_t		*Props)
{
	SpStatus_t			status;
	SpHeader_t			Header;
	SpTagValue_t		tagValue;

	KpInt32_t			Passed[SPSEARCH_LIST];
	KpInt32_t			Tested[SPSEARCH_LIST];
	KpInt32_t			i, j, critSize;
	SpSearchCriterion_t *criterion;

#define	TAGID_LIST 5	
	SpTagId_t			TagIdsPassed[TAGID_LIST];
	SpTagId_t			TagIdsTested[TAGID_LIST];
	SpTagId_t			*pTagIdsPassed = TagIdsPassed;
	SpTagId_t			*pTagIdsTested = TagIdsTested;
	KpInt32_t			TagCount = 0;

	if (NULL == SearchValue)
		return SpStatIncompatibleArguments;

	critSize = SearchValue->critSize;
	criterion = SearchValue->criterion;

	status = SpProfileLoadHeader (Filename, Props, &Header);

	if (SpStatSuccess != status)
		return status;
	
	
	for (i = 0; i < SPSEARCH_LIST; i++)
	{
		 /* preset all entries in PassedEvalArray to Not Tested and failed . */
		Passed[i]  = 0;
		Tested[i]  = 0;
	}
	
	/* count up the number of tag checks requested. */
	for (i = 0; i < SearchValue->critCount; i++)
	{
		if ((SPSEARCH_ENUMTAGVALUE_EQUAL == criterion->SearchElement) ||
			(SPSEARCH_ENUMTAGVALUE_NOTEQUAL == criterion->SearchElement))
			TagCount++;

		 criterion = (SpSearchCriterion_t *)(critSize + (KpUInt8_p)criterion);
	}
	criterion = SearchValue->criterion;

	if (TAGID_LIST < TagCount)
	{
		/* allocate the tested/passed arrays */
		pTagIdsTested = allocBufferPtr( TagCount * sizeof(SpTagId_t));
		if (NULL == pTagIdsTested)
			return SpStatMemory;

		pTagIdsPassed = allocBufferPtr( TagCount * sizeof(SpTagId_t));
		if (NULL == pTagIdsPassed)
			return SpStatMemory;
	}

	/* preset all entries in Tag PassedEvalArrays to Not Tested and failed . */
	for (i = 0; i < TagCount; i++)
	{
		pTagIdsTested[i] = 0;
		pTagIdsPassed[i] = 0;
	}

   /* Loop thru the parameters, test the value based upon the Field
	*   Set that it Passed if it did.  Set that it was tested always
	*/
	for (i = 0; i < SearchValue->critCount; i++)
	{
		switch (criterion->SearchElement)
		{
		case SPSEARCH_PREFERREDCMM       :
			if (criterion->SearchValue.Signature ==
									(KpInt32_t) Header.CMMType)
			   Passed[SPSEARCH_PREFERREDCMM] = 1;
			Tested[SPSEARCH_PREFERREDCMM]    = 1;
			break;

		case SPSEARCH_VERSION            :
			if (criterion->SearchValue.Value     ==
									 Header.ProfileVersion)
			   Passed[SPSEARCH_VERSION]      = 1;
			Tested[SPSEARCH_VERSION]         = 1;
			break;

		case SPSEARCH_PROFILECLASS       :
			if (criterion->SearchValue.Signature ==
								 Header.DeviceClass)
			   Passed[SPSEARCH_PROFILECLASS] = 1;
			Tested[SPSEARCH_PROFILECLASS]    = 1;
			break;

		case SPSEARCH_DEVICECOLORSPACE   :
			if (criterion->SearchValue.Signature ==
							  Header.DataColorSpace)
			   Passed[SPSEARCH_DEVICECOLORSPACE] = 1;
			Tested[SPSEARCH_DEVICECOLORSPACE]    = 1;
			break;

		case SPSEARCH_CONNECTIONSPACE    :
			if (criterion->SearchValue.Signature ==
					   Header.InterchangeColorSpace)
			   Passed[SPSEARCH_CONNECTIONSPACE] = 1;
			Tested[SPSEARCH_CONNECTIONSPACE]    = 1;
			break;

		 /* Only use ONDATE value for all date testing since more
		  * than one value can be given for an attribute */
		case SPSEARCH_BEFOREDATE         :
			if (BEFORE == TestHeaderDate(
							&Header.DateTime,
							&criterion->SearchValue.Date))
			   Passed[SPSEARCH_ONDATE]          = 1;
			Tested[SPSEARCH_ONDATE]             = 1;
			break;

		case SPSEARCH_ONDATE             :
			if (SAME   == TestHeaderDate(
							&Header.DateTime,
							&criterion->SearchValue.Date))
			   Passed[SPSEARCH_ONDATE]          = 1;
			Tested[SPSEARCH_ONDATE]             = 1;
			break;

		case SPSEARCH_AFTERDATE          :
			if (AFTER  == TestHeaderDate(
							&Header.DateTime,
							&criterion->SearchValue.Date))
			   Passed[SPSEARCH_ONDATE]          = 1;
			Tested[SPSEARCH_ONDATE]             = 1;
			break;

		case SPSEARCH_PLATFORM           :
			if (criterion->SearchValue.Signature ==
									Header.Platform)
			   Passed[SPSEARCH_PLATFORM] = 1;
			Tested[SPSEARCH_PLATFORM]    = 1;
			break;

		case SPSEARCH_PROFILEFLAGS       :
			if (criterion->SearchValue.Value     ==
									   Header.Flags)
			   Passed[SPSEARCH_PROFILEFLAGS] = 1;
			Tested[SPSEARCH_PROFILEFLAGS]    = 1;
			break;

		case SPSEARCH_DEVICEMFG          :
			if (criterion->SearchValue.Signature ==
						  Header.DeviceManufacturer)
			   Passed[SPSEARCH_DEVICEMFG] = 1;
			Tested[SPSEARCH_DEVICEMFG]    = 1;
			break;

		case SPSEARCH_DEVICEMODEL        :
			if (criterion->SearchValue.Signature ==
								 Header.DeviceModel)
			   Passed[SPSEARCH_DEVICEMODEL] = 1;
			Tested[SPSEARCH_DEVICEMODEL]    = 1;
			break;

		case SPSEARCH_DEVICEATTRIBUTESHI :
			if (criterion->SearchValue.Value     ==
						 Header.DeviceAttributes.hi)
			   Passed[SPSEARCH_DEVICEATTRIBUTESHI] = 1;
			Tested[SPSEARCH_DEVICEATTRIBUTESHI]    = 1;
			break;

		case SPSEARCH_DEVICEATTRIBUTESLO :
			if (criterion->SearchValue.Value     ==
						 Header.DeviceAttributes.lo)
			   Passed[SPSEARCH_DEVICEATTRIBUTESLO] = 1;
			Tested[SPSEARCH_DEVICEATTRIBUTESLO]    = 1;
			break;

		case SPSEARCH_RENDERINGINTENT    :
			if (criterion->SearchValue.Signature ==
							 (KpInt32_t) Header.RenderingIntent)
			   Passed[SPSEARCH_RENDERINGINTENT] = 1;
			Tested[SPSEARCH_RENDERINGINTENT]    = 1;
			break;

		case SPSEARCH_ILLUMINANT         :
			if ((criterion->SearchValue.XYZ.X    ==
								Header.Illuminant.X) &&
				(criterion->SearchValue.XYZ.Y    ==
								Header.Illuminant.Y) &&
				(criterion->SearchValue.XYZ.Z    ==
								Header.Illuminant.Z))
			   Passed[SPSEARCH_ILLUMINANT] = 1;
			Tested[SPSEARCH_ILLUMINANT]    = 1;
			break;

		case SPSEARCH_ORIGINATOR         :
		   if (criterion->SearchValue.Signature ==
								Header.Originator)
			   Passed[SPSEARCH_ORIGINATOR] = 1;
		   Tested[SPSEARCH_ORIGINATOR]    = 1;
		   break;

		case SPSEARCH_PROFILEID         :
		   if ((criterion->SearchValue.ProfileID.a ==
								Header.ProfileID.a) &&
			   (criterion->SearchValue.ProfileID.b ==
								Header.ProfileID.b) &&
			   (criterion->SearchValue.ProfileID.c ==
								Header.ProfileID.c) &&
			   (criterion->SearchValue.ProfileID.d ==
								Header.ProfileID.d))
			   Passed[SPSEARCH_ORIGINATOR] = 1;
		   Tested[SPSEARCH_ORIGINATOR]    = 1;
		   break;

		case SPSEARCH_ENUMTAGVALUE_EQUAL	:
		case SPSEARCH_ENUMTAGVALUE_NOTEQUAL	:		
			/* find the matching tag ID or the first unused one */
			for(j = 0; j < TagCount; j++)
			{
				if ((pTagIdsTested[j] == criterion->SearchValue.Tag.TagId) || 
					(0 == pTagIdsTested[j]))
				{
					/* mark this tag as tested */
					pTagIdsTested[j] = criterion->SearchValue.Tag.TagId;
					break;
				}
			}
			/* load the tag */
			status = SpProfileLoadTag(Filename, Props, criterion->SearchValue.Tag.TagId, &tagValue);
			if (SPSEARCH_ENUMTAGVALUE_EQUAL == criterion->SearchElement) 
			{
				if ((SpStatSuccess == status) &&
					(criterion->SearchValue.Tag.TagEnum == tagValue.Data.TagEnum))
				{
					pTagIdsPassed[j] = pTagIdsTested[j];
				}
			}
			else
			{
				if ((SpStatSuccess != status) ||
					(criterion->SearchValue.Tag.TagEnum != tagValue.Data.TagEnum))
				{
					pTagIdsPassed[j] = pTagIdsTested[j];
				}
			}
			if (SpStatSuccess == status)
			{
				/* free allocated resources */
				SpTagFree(&tagValue);
			}
			break;
		case SPSEARCH_TIMEORDER:
		default:
		   /* No special processing */
		   break;
		}
 		criterion = (SpSearchCriterion_t *)(critSize + (KpUInt8_p)criterion);
	}
	/* assume success */ 
	status = SpStatSuccess;
   /* Loop thru enumeration types, Checking Passed vs Tested
	* for return value
	*/
	for (i = 0; i < SPSEARCH_LIST; i++)
	{
		if (Tested[i] && !Passed[i])
			status = SpStatBadProfile;
	}

	if (0 < TagCount)
	{
		for(j = 0; j < TagCount; j++)
		{
			if (pTagIdsTested[j] != pTagIdsPassed[j])
				status = SpStatBadProfile;
		}

		if (TAGID_LIST < TagCount)
		{
			freeBufferPtr( (KpGenericPtr_t)pTagIdsTested);
			freeBufferPtr( (KpGenericPtr_t)pTagIdsPassed);
		}
	}
	return status;

}
Beispiel #2
0
/*--------------------------------------------------------------------
 * DESCRIPTION
 *	Return the Tag from the profile.
 *
 * AUTHOR
 * 	doro
 *
 * DATE CREATED
 *	March 12, 2002
 *------------------------------------------------------------------*/
SpStatus_t KSPAPI SpProfileLoadTagEx(
    char                   *Filename,
    SpFileProps_t          *Props,
    SpTagId_t               TagId,
    SpTagValue_t            FAR *Value)
{
    SpHeader_t       Header;
    SpHeader_t       *HeaderPtr;
    SpHugeBuffer_t   BufferAddress, TagAddress;
    SpStatus_t       Status = SpStatSuccess;
    KpFileId         FD;
    KpFileProps_t    fileProps;
    char             name[MAX_PATH];
    KpUInt32_t       FilePosition = HEADER_SIZE;
    KpInt32_t       Read_Amount  = sizeof(KpInt32_t);
    KpInt32_t       i, TagArraySize, TagBufferSize;
    SpTagRecord_t   *TagArray;

    if (!SpIsICCProfile(Filename, Props))
        return (SpStatBadProfile);

    strcpy (name, Filename);

    /* Need Header in case we are requesting a Named Color */
    HeaderPtr = (SpHeader_t *)NULL;
    if (TagId == SpTagNamedColor)
    {
        HeaderPtr = &Header;
        Status = SpProfileLoadHeader(name, Props, HeaderPtr);
    }
    if (Status == SpStatSuccess)
    {
        /* Set up for failure - yes I know I'm negative */
        Status = SpStatFileNotFound;

#if defined (KPMAC)
        SpCvrtSpFileProps(Props, &fileProps);
#endif
        if (KpFileOpen(Filename, "r", &fileProps, &FD)) /* 0 = not opened */
        {
            if (KpFilePosition(FD, FROM_START, FilePosition))
            {

                Status = SpStatFileReadError;
                /* Read TagArraySize into Buffer  */
                if (KpFileRead(FD, &TagArraySize, &Read_Amount))
                {
#if defined (KPLSBFIRST)
                    /* If we are on a little endian machine we need to do byte swap	*/
                    Kp_swab32 (&TagArraySize, 1);
#endif
                    TagBufferSize = TagArraySize * 3 * 4;  /* each entry is 3*4 bytes */
                    BufferAddress = allocBufferPtr(TagBufferSize);
                    if (BufferAddress != NULL)
                    {
                        if (KpFileRead(FD, BufferAddress, &TagBufferSize))
                        {
#if defined (KPLSBFIRST)
                            /* If we are on a little endian machine we need to do byte swap	*/
                            Kp_swab32 (BufferAddress, TagBufferSize / sizeof (KpInt32_t));
#endif
                            TagArray = BufferAddress;
                            Status = SpStatTagNotFound;
                            for (i = 0; i < TagArraySize; i++)
                            {
                                if (TagId == (SpTagId_t)TagArray[i].Id)
                                {
                                    Status = SpStatMemory;
                                    TagAddress = allocBufferPtr(TagArray[i].Size);
                                    if (TagAddress != NULL)
                                    {
                                        if (KpFilePosition(FD, FROM_START, TagArray[i].Offset))
                                        {
                                            Read_Amount = TagArray[i].Size;
                                            if (KpFileRead(FD, TagAddress, &Read_Amount))
                                            {
                                                Status = SpTagToPublic(HeaderPtr,   TagId,
                                                                       TagArray[i].Size,
                                                                       TagAddress,  Value);
                                            }
                                        }
                                        freeBufferPtr(TagAddress);
                                    } else
                                    {
                                        Status = SpStatMemory;
                                        break;
                                    }
                                }
                            }
                        }
                        freeBufferPtr(BufferAddress);
                    } else /* Buffer Address != 0 */
                        Status = SpStatMemory;
                }
            }
            /* Close File */
            KpFileClose(FD);
        }
    }
    return Status;

}
Beispiel #3
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;
}