XPTEXP1 void * XPTAPI XPTEXP2 xppRealloc(void *ptr, size_t size) {
   Err rc;
   UInt32 currentSize;
   void *newMem;

   /* If original pointer is null, act like a normal malloc                */
   if (!ptr) return MemPtrNew(size);

   /* Try resizing original area.  This will always work if the new area   */
   /* is smaller.  It may or may not work if growing the area.             */
   rc = MemPtrResize(ptr, size);
   if (!rc) return ptr;             /* It worked.  Return same pointer.    */

   /* Resizing didn't work.  Allocate a new, larger, area, and copy the    */
   /* previous data from the old area.                                     */
   newMem = MemPtrNew(size);
   if (!newMem) return newMem;      /* Pass error to caller                */

   /* The original size must be smaller than the new size                  */
   currentSize = MemPtrSize(ptr);
   MemMove(newMem, ptr, currentSize);

   /* Release the old area.                                                */
   MemPtrFree(ptr);

   return newMem;
}
Example #2
0
void TestAppendItem( void )
{
    UInt16* item1;
    UInt16* item2;
    UInt16* data1;
    UInt16* data2;

    ASSERT( ListIsEmpty( list ));

    data1 = MemPtrNew( sizeof *data1 );
    *data1 = 6;
    ListAppend( list, data1 );
    ASSERT( ListSize( list ) == 1 );
    ASSERT( ! ListIsEmpty( list ));

    data2 = MemPtrNew( sizeof *data2 );
    *data2 = 10;
    ListAppend( list, data2 );
    ASSERT( ListSize( list ) == 2 );

    item1 = ListGet( list, 1 );
    item2 = ListGet( list, 2 );
    ASSERT_UINT16_EQUAL_MSG( "First item: ", 6, *item1 );
    ASSERT_UINT16_EQUAL_MSG( "Second item: ", 10, *item2 );
}
Example #3
0
static void AddTwoItems( void )
{
    UInt16* item1;
    UInt16* item2;

    item1 = MemPtrNew( sizeof *item1 );
    item2 = MemPtrNew( sizeof *item2 );
    *item1 = 6;
    *item2 = 10;
    ListAppend( list, item1 );
    ListAppend( list, item2 );
}
Example #4
0
}static char*
alloc_zlib_buf(void)
{int i=10;char*p,*zp0,*zp1;unsigned zp0_size=1<<15,zp1_size=(1<<13)+(1<<12);
 zlib_buf_size=1<<i;
 while(1)
 {p=MemPtrNew(zlib_buf_size);zp0=MemPtrNew(zp0_size);
  zp1=MemPtrNew(zp1_size);
  if(!(p&&zp0&&zp1))
  {zlib_buf_size>>=3;
   if(p)MemPtrFree(p);if(zp0)MemPtrFree(zp0);if(zp1)MemPtrFree(zp1);break;
  }
  if(i==15)
  {char*_=MemPtrNew(zlib_buf_size);
   if(_){zlib_buf_size>>=2;MemPtrFree(_);}
   else zlib_buf_size>>=3;MemPtrFree(p);MemPtrFree(zp0);MemPtrFree(zp1);break;
static UInt16 GetHeapId()
{
	MemPtr p=MemPtrNew(8);   
	UInt16 Id=MemPtrHeapID(p);
	MemPtrFree(p);
	return Id;
}
Example #6
0
void *calloc(int s)
{
    void *p;
    p = MemPtrNew(s);
    memset(p,0,s);
    return p;
}
Example #7
0
static void
CourseNameCacheLoad(CacheID id, UInt16 *ids, Char **values, UInt16 numItems)
{
  MemHandle m; 
  UInt16 index=0, i=0;
  
  while ((i < numItems) && ((m = DmQueryNextInCategory(DatabaseGetRef(), &index, DatabaseGetCat())) != NULL)) {
    Char *s=(Char *)MemHandleLock(m);
    if (s[0] == TYPE_COURSE) {
      CourseDBRecord c;
      Char *tempString;

      UnpackCourse(&c, s);
      
      tempString=(Char *)MemPtrNew(StrLen(c.name)+1);
      MemSet(tempString, MemPtrSize(tempString), 0);
      StrCopy(tempString, c.name);

      ids[i] = c.id;
      values[i] = tempString;
      i += 1;
    }
    MemHandleUnlock(m);
    index += 1;
  }
}
Example #8
0
ucl_alloc_internal(ucl_uint nelems, ucl_uint size)
{
    ucl_voidp p = NULL;
    unsigned long s = (unsigned long) nelems * size;

    if (nelems <= 0 || size <= 0 || s < nelems || s < size)
        return NULL;

#if defined(__palmos__)
    p = (ucl_voidp) MemPtrNew(s);
#elif (UCL_UINT_MAX <= SIZE_T_MAX)
    if (s < SIZE_T_MAX)
        p = (ucl_voidp) malloc((size_t)s);
#elif defined(HAVE_HALLOC) && defined(__DMC__)
    if (size < SIZE_T_MAX)
        p = (ucl_voidp) _halloc(nelems,(size_t)size);
#elif defined(HAVE_HALLOC)
    if (size < SIZE_T_MAX)
        p = (ucl_voidp) halloc(nelems,(size_t)size);
#else
    if (s < SIZE_T_MAX)
        p = (ucl_voidp) malloc((size_t)s);
#endif

    return p;
}
/*
 * The following functions provide malloc/free support to Metrowerks
 * Standard Library (MSL). This feature requires the MSL library be
 * built with _MSL_OS_DIRECT_MALLOC enabled.
 */
void*
__sys_alloc(size_t size)
{
    void * ptr = MemPtrNew(size);
    ErrFatalDisplayIf(ptr == NULL, "out of memory");
    return ptr;
}
Example #10
0
// Function add object to nearest autorelease
// pool, it returns a valid object
void* objectAutorelease(void* buffer)
{
    object_p object = NULL;
    void* ptr = NULL;
    autorelease_p autorelease = NULL;

    if (buffer) {
        ASSERT(NULL != runtimeLast,
               "objectAutorelease");

        if (NULL != autoreleaseFree) {
            autorelease = autoreleaseFree;
            autoreleaseFree = autorelease->next;
        } else {
            autorelease = MemPtrNew(
                sizeof(autorelease_t));
        }

        if (NULL == autorelease)
            THROW("MemPtrNew",
                  memErrNotEnoughSpace);

        MemSet(autorelease, sizeof(*autorelease),
               0);

        ptr = ((char*)buffer) - sizeof(object_t);
        object = (object_p)ptr;

        autorelease->object = object;
        autorelease->next = runtimeLast->first;
        runtimeLast->first = autorelease;
    }

    return buffer;
};
Example #11
0
/***********************************************************************
 *
 * FUNCTION:    PrvCreateTimeZoneArray
 *
 * DESCRIPTION: Create the array of time zone entries from our string
 *		list, gtm offset list, and country list resources. Sort based on
 *		time zone name.
 *
 *	DOLATER kwk - we could save the time zone array we're creating here
 *		in memory, to avoid the performance hit of creating the array.
 *		On the other hand, then the list of names would need to stay
 *		locked down, unless we also copy those into the memory buffer,
 *		which means another 700+ bytes.
 *
 * PARAMETERS:
 *		timeZoneNames	<->	Ptr to returned handle to list of names.
 *		numTimeZones	<->	Ptr to count of number of time zones.
 *
 * RETURNED:
 *		Ptr to allocated array of time zone entry records.
 *
 * HISTORY:
 *		07/31/00	kwk	Created by Ken Krugler.
 *		08/23/00	kwk	Fixed bug where release ROMs caused ErrNonFatalDisplayIf
 *							to become a no-op, and thus the country and time zone
 *							offset list ptrs weren't skipping the count word.
 *
 ***********************************************************************/
static TimeZoneEntryType* PrvCreateTimeZoneArray(MemHandle* timeZoneNames, UInt16* numTimeZones)
{
	const Char* tzNamesP;
	TimeZoneEntryType* tzEntries;
	MemHandle offsetsH;
	MemHandle countriesH;
	UInt16* resP;
	Int16* gmtOffsetsP;
	UInt16* countriesP;
	UInt16 i;
	
	// Specify the number of items in the list, based on total # of items
	// in our time zone name list resource.
	*timeZoneNames = DmGetResource(strListRscType, TimeZoneNamesStringList);
	ErrNonFatalDisplayIf(*timeZoneNames == NULL, "No time zone names");
	tzNamesP = (const Char*)MemHandleLock(*timeZoneNames);
	
	// Skip over prefix string, then get the entry count.
	tzNamesP += StrLen(tzNamesP) + 1;
	*numTimeZones = *tzNamesP++;
	*numTimeZones = (*numTimeZones << 8) +  *tzNamesP++;
	
	// Allocate the array of time zone records.
	tzEntries = (TimeZoneEntryType*)MemPtrNew(*numTimeZones * sizeof(TimeZoneEntryType));
	ErrFatalDisplayIf(tzEntries == NULL, "Out of memory");
	
	// Find and lock down the gtm offset and country integer lists.
	offsetsH = DmGetResource(wrdListRscType, TimeZoneGMTOffsetsList);
	ErrNonFatalDisplayIf(offsetsH == NULL, "No time zone offsets");
	resP = (UInt16*)MemHandleLock(offsetsH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "GMT offset count != name count");
	
	// Skip count at start of list.
	gmtOffsetsP = (Int16*)resP + 1;
	
	countriesH = DmGetResource(wrdListRscType, TimeZoneCountriesList);
	ErrNonFatalDisplayIf(countriesH == NULL, "No time zone countries");
	resP = (UInt16*)MemHandleLock(countriesH);
	ErrNonFatalDisplayIf(*resP != *numTimeZones, "Time zone country count != name count");
	
	// Skip count at start of list.
	countriesP = resP + 1;
	
	// Now loop to fill in all of the records.
	for (i = 0; i < *numTimeZones; i++)
	{
		tzEntries[i].tzName = tzNamesP;
		tzNamesP += StrLen(tzNamesP) + 1;
		tzEntries[i].tzOffset = gmtOffsetsP[i];
		tzEntries[i].tzCountry = (CountryType)countriesP[i];
	}
	
	MemHandleUnlock(offsetsH);
	MemHandleUnlock(countriesH);
	
	// Now sort the list, based on the time zone name.
	SysQSort(tzEntries, *numTimeZones, sizeof(TimeZoneEntryType), PrvCompareTimeZoneEntries, 0);
	
	return(tzEntries);
} // PrvCreateTimeZoneArray
Example #12
0
/************************************************************************************
 * Function: PackAccount
 * Description: Utility function that takes an unpacked account, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackAccount (MemPtr retbuff, Account acct, md_hash * pass,
			 Boolean encrypt) {
	UInt16 offset = 0;
	MemPtr pacct;
	if ((pacct = MemPtrNew (MemPtrSize (retbuff)))) {	
		/*	pack the fields of the account buffer together */
		MemMove (pacct + offset, &acct.SystemID, sizeof (acct.SystemID));
		offset += sizeof (acct.SystemID);
		MemMove (pacct + offset, &acct.AccountID, sizeof (acct.AccountID));
		offset += sizeof (acct.AccountID);
		MemMove (pacct + offset, acct.hash, sizeof (md_hash));
		offset += sizeof (md_hash);
		MemMove (pacct + offset, &acct.series, sizeof (acct.series));
		offset += sizeof (acct.series);
		MemMove (pacct + offset, &acct.hash_type, sizeof (acct.hash_type));
		offset += sizeof (acct.hash_type);
		MemMove (pacct + offset, &acct.system_type, sizeof (acct.system_type));
		offset += sizeof (acct.system_type);
		MemMove (pacct + offset, &acct.service_type, sizeof (acct.service_type));
		offset += sizeof (acct.service_type);
		MemMove (pacct + offset, &acct.username_type, sizeof (acct.username_type));
		offset += sizeof (acct.username_type);
		MemMove (pacct + offset, &acct.password_type, sizeof (acct.password_type));
		offset += sizeof (acct.password_type);

		MemMove (pacct + offset, &acct.account_mod_date, sizeof (acct.account_mod_date));
		offset += sizeof (acct.account_mod_date);
		MemMove (pacct + offset, &acct.password_mod_date, sizeof (acct.password_mod_date));
		offset += sizeof (acct.password_mod_date);
		MemMove (pacct + offset, &acct.binary_data_length, sizeof (acct.binary_data_length));
		offset += sizeof (acct.binary_data_length);

		MemMove (pacct + offset, acct.system, StrLen (acct.system) + 1);
		offset += StrLen (acct.system) + 1;
		MemMove (pacct + offset, acct.service, StrLen (acct.service) + 1);
		offset += StrLen (acct.service) + 1;
		MemMove (pacct + offset, acct.username, StrLen (acct.username) + 1);
		offset += StrLen (acct.username) + 1;
		MemMove (pacct + offset, acct.password, StrLen (acct.password) + 1);
		offset += StrLen (acct.password) + 1;
		MemMove (pacct + offset, acct.comment, StrLen (acct.comment) + 1);
		offset += StrLen (acct.comment) + 1;
		MemMove (pacct + offset, acct.key, StrLen (acct.key) + 1);
		offset += StrLen (acct.key) + 1;

		MemMove (pacct + offset, &acct.binary_data, acct.binary_data_length);
		offset += acct.binary_data_length;

		/*	optionally encrypt */
		if (encrypt) {
			MemMove (retbuff, pacct, ACCT_HEADER);
			stripCrypt (*pass, (pacct+ACCT_HEADER), (retbuff+ACCT_HEADER), 
				(getAccountSize (&acct, true) - ACCT_HEADER), 1);  				 
		} else MemMove (retbuff, pacct, getAccountSize (&acct, false));

		MemSet (pacct, MemPtrSize (pacct), 0);
		MemPtrFree (pacct);
	}
}
Example #13
0
/* Finds and opens database,
 * calls plugin specific code to create new item,
 * then fills in GoTo parameters.
 */
static UInt16
PickBooger(KleenexPtr kleenexP)
{
    DmOpenRef dbR;
    DmSearchStateType searchstate;
    UInt32 creatorID, dbtype;
    UInt16 cardNo;
    LocalID dbID;
    Boolean closedb = false;
    UInt16 err, index;

    /* Check for the correct version */
    if (!((kleenexP->version) & IBVERSION_ORIG))
        return (boogerErrorVersionMismatch);

    /* Open the database */
    if (DmGetNextDatabaseByTypeCreator(true, &searchstate, DB_TYPE,
                                       DB_CREATOR, true, &cardNo, &dbID))
        return (1);

    if ((dbR = DmOpenDatabase(cardNo, dbID, dmModeReadWrite))) {
        closedb = true;

    } else if (DmGetLastErr() == dmErrAlreadyOpenForWrites) {
        dbR = NULL;
        while ((dbR = DmNextOpenDatabase(dbR))) {
            DmOpenDatabaseInfo(dbR, &dbID, NULL, NULL, &cardNo, NULL);
            DmDatabaseInfo(cardNo, dbID, NULL, NULL, NULL, NULL, NULL, NULL,
                           NULL, NULL, NULL, &dbtype, &creatorID);
            if ((dbtype == DB_TYPE) && (creatorID == DB_CREATOR))
                break;
        }
        if (!dbR)
            return (1);
    }

    /* Call plugin specific routine to create item in database */
    err = DoTheBoogie(kleenexP, dbR, &index);

    /* Close the database */
    if (closedb)
        DmCloseDatabase(dbR);

    /* Did it work? */
    if (err)
        return (1);

    /* Load the GoTo parameters */
    if (!(kleenexP->booger.cmdPBP = MemPtrNew(sizeof(GoToParamsType))))
        return (1);
    MemSet(kleenexP->booger.cmdPBP, sizeof(GoToParamsType), 0);
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbCardNo = cardNo;
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbID = dbID;
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->recordNum = index;
    MemPtrSetOwner(kleenexP->booger.cmdPBP, 0);

    return (errNone);
}
Example #14
0
/* Finds and opens database,
 * calls plugin specific code to create new item,
 * then fills in GoTo parameters.
 */
static UInt16
PickBooger(KleenexPtr kleenexP)
{
    DmOpenRef dbR;
    UInt32 creatorID;
    UInt16 cardNo;
    LocalID dbID;
    Boolean closedb = false;
    UInt16 err, index;
    Char name[dmDBNameLength];

    /* Check for the correct version */
    if (!((kleenexP->version) & IBVERSION_PICTURE))
        return (boogerErrorVersionMismatch);

    /* Open the database */
    cardNo = 0;
    if (!(dbID = DmFindDatabase(cardNo, "DiddleIDB")))
        return 1;

    if ((dbR = DmOpenDatabase(cardNo, dbID, dmModeReadWrite))) {
        closedb = true;

    } else if (DmGetLastErr() == dmErrAlreadyOpenForWrites) {
        dbR = NULL;
        while ((dbR = DmNextOpenDatabase(dbR))) {
            DmOpenDatabaseInfo(dbR, &dbID, NULL, NULL, &cardNo, NULL);
            DmDatabaseInfo(cardNo, dbID, name, NULL, NULL, NULL, NULL, NULL,
                           NULL, NULL, NULL, NULL, &creatorID);
            if (!StrCompare(name, "DiddleIDB") && (creatorID == DB_CREATOR))
                break;
        }
        if (!dbR)
            return 1;
    }

    /* Call plugin specific routine to create item in database */
    err = DoTheBoogie(kleenexP, dbR, &index);

    /* Close the database */
    if (closedb)
        DmCloseDatabase(dbR);

    /* Did it work? */
    if (err)
        return (1);

    /* Load the GoTo parameters */
    if (!(kleenexP->booger.cmdPBP = MemPtrNew(sizeof(GoToParamsType))))
        return (1);
    MemSet(kleenexP->booger.cmdPBP, sizeof(GoToParamsType), 0);
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbCardNo = cardNo;
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->dbID = dbID;
    ((GoToParamsType *)(kleenexP->booger.cmdPBP))->recordNum = index;
    MemPtrSetOwner(kleenexP->booger.cmdPBP, 0);

    return (errNone);
}
Example #15
0
/***********************************************************************************
 * Function: PackPassword
 * Description: pack a password and encrypt it using spass
 * *********************************************************************************/ 
void PackPassword (MemPtr retbuff,  md_hash * spass) {
	MemPtr ppass;
	if ((ppass = MemPtrNew (getSCSize(sizeof(md_hash))))) {
		MemMove (ppass, spass, sizeof (md_hash));
		stripCrypt (*spass, ppass, retbuff, getSCSize(sizeof(md_hash)), ENCRYPT);
		MemSet (ppass, MemPtrSize (ppass), 0);
		MemPtrFree (ppass);
	}
}
Example #16
0
int
load_preferences(void)
{UInt16 prefs_size=0;int version,n;char*p,*_;
 version=PrefGetAppPreferences(CREATOR,prefs_id,0,&prefs_size,0);
 if(version!=prefs_version)return try_db_name();
 if(prefs_size<db_name_size+1)return try_db_name();
 p=MemPtrNew(prefs_size);if(!p)return try_db_name();_=p;
 version=PrefGetAppPreferences(CREATOR,prefs_id,p,&prefs_size,0);
 if(version!=prefs_version){MemPtrFree(p);return try_db_name();}
 n=db_name_size;MemMove(db_name,_,n);_+=n;prefs_size-=n;db_name[n]=0;
 if(try_db_name())return!0;
 if(prefs_size>1)
 {n=StrLen(_)+1;lookup=MemPtrNew(n);
  if(lookup)MemMove(lookup,_,n);prefs_size-=n;_+=n;
 }if(prefs_size>0)
 {char aux_flags=*_;set_list_mode(2*!!(aux_flags&(1<<list_mode_bit)));
  prefs_size-=1;_+=1;
 }MemPtrFree(p);return 0;
}static int
Example #17
0
Err AppPerformResidentLookup(char* term)
{
    Err             error;
    AppContext*     appContext=(AppContext*)MemPtrNew(sizeof(AppContext));
    AbstractFile *  chosenDb;

    if (!appContext)
    {
        error=memErrNotEnoughSpace;
        goto OnError;
    }
    error=AppCommonInit(appContext);
    RemoveNonexistingDatabases(appContext);
    ScanForDictsNoahPro(appContext, false);
    if (0 == appContext->dictsCount)
    {
        FrmAlert(alertNoDB);
        goto Exit;
    }
    else

    if (1 == appContext->dictsCount )
        chosenDb = appContext->dicts[0];
    else 
    {
        // because we can't start resident mode without previously gracefully exiting at least one time
        Assert(appContext->prefs.lastDbUsedName); 
        chosenDb=FindOpenDatabase(appContext, appContext->prefs.lastDbUsedName);
    }            

    if (!chosenDb || !DictInit(appContext, chosenDb))
    {
        FrmAlert(alertDbFailed);
        goto Exit;
    }

    if (term)
    {
        appContext->currentWord=dictGetFirstMatching(chosenDb, term);
        error=PopupResidentLookupForm(appContext);
    }
    else
    {
        appContext->currentWord=-1;
        error=PopupResidentBrowseForm(appContext);
        if (!error && appContext->currentWord!=-1)
            error=PopupResidentLookupForm(appContext);
    }
Exit:
    AppCommonFree(appContext);
OnError:
    if (appContext)
        MemPtrFree(appContext);
    return error;
}
void OSystem_PalmOS5::sound_handler() {
	if (_sound.active) {
		if (_soundEx.size && !_soundEx.set) {
			if (!_soundEx.dataP)
				_soundEx.dataP = MemPtrNew(_soundEx.size);

			((SoundProc)_sound.proc)(_sound.param, (byte *)_soundEx.dataP, _soundEx.size);
			_soundEx.set = true;
		}
	}// TODO : no Sound API case
}
Example #19
0
/*****************************************************************************
* Function: DrawCourses
*
* Description: local function to fill the course list
*****************************************************************************/
static void
DrawCourses(ListType *lst)
{
  MemHandle mWebsite, mEmail, old;
  Char *buffer;
  FieldType *fldWebsite, *fldEmail;
  
  gNumCourses=CountCourses();
  gCourseList = (Char **) MemPtrNew(gNumCourses * sizeof(Char *));
  gCourseInd = (UInt16 *) MemPtrNew(gNumCourses * sizeof(UInt16));

  CourseListGen(gCourseList, NULL, gCourseInd, gNumCourses, 0, CLIST_SEARCH_INDEX);
  LstSetListChoices(lst, gCourseList, gNumCourses);
  LstSetSelection(lst, -1);

  
  fldWebsite = GetObjectPtr(FIELD_cl_website);
  fldEmail = GetObjectPtr(FIELD_cl_email);
  
  mWebsite = MemHandleNew(4);
  buffer = MemHandleLock(mWebsite);
  MemSet(buffer, 4, 0);
  StrCopy(buffer, "-?-");
  MemHandleUnlock(mWebsite);

  old = FldGetTextHandle(fldWebsite);
  FldSetTextHandle(fldWebsite, mWebsite);
  if (old != NULL)  MemHandleFree(old); 

  mEmail = MemHandleNew(4);
  buffer = MemHandleLock(mEmail);
  MemSet(buffer, 4, 0);
  StrCopy(buffer, "-?-");
  MemHandleUnlock(mEmail);

  old = FldGetTextHandle(fldEmail);
  FldSetTextHandle(fldEmail, mEmail);
  if (old != NULL)  MemHandleFree(old); 

  
}
Example #20
0
/**************************************************************************
 * Function: generateAccountHash
 * Description: returns the unique hash for the account.
 * ************************************************************************/ 
md_hash * generateAccountHash (Account * acct) {
	static md_hash ret;
	unsigned char * hashable;
	int data_length = 0, string_length = 0;
	
	MemSet(ret, sizeof(md_hash), 0);
	
	/* username, password, acct mod date, 
	 * pw mod date, and 256 bits of randomness */
	data_length = 
		StrLen(acct->username)+
		StrLen(acct->system)+
		StrLen(acct->password)+
		StrLen(acct->service)+
		StrLen(acct->comment)+
		sizeof(acct->account_mod_date)+
		sizeof(acct->password_mod_date)+
		(sizeof(Int16)*16)+1;
		
		
	if((hashable=MemPtrNew(data_length))) {
		MemSet(hashable, data_length, 0);
		StrCopy(hashable, acct->username);	
		string_length+=StrLen(acct->username);
		StrCat(hashable, acct->system);	
		string_length+=StrLen(acct->system);
		StrCat(hashable, acct->password);
		string_length+=StrLen(acct->password);	
		StrCat(hashable, acct->service);
		string_length+=StrLen(acct->service);	
		StrCat(hashable, acct->comment);
		string_length+=StrLen(acct->comment);	
		
		MemMove(hashable+string_length, 
			&acct->account_mod_date, 
			sizeof(acct->account_mod_date));
		string_length+=sizeof(acct->account_mod_date);
		
		MemMove(hashable+string_length, 
			&acct->password_mod_date, 				
			sizeof(acct->password_mod_date));
		string_length+=sizeof(acct->password_mod_date);
		
		/* move some randomness onto the end 
		 * to make dictionary attacks impossible.   */
		random_bytes(hashable+string_length, 32);
		string_length+=32;
		
		md_block(hashable, string_length, ret);	
		MemPtrFree(hashable);
	}	
	return &ret;
}
Example #21
0
Int16 GotoAddress(Int16 index)
{
    GoToParamsPtr theGotoPointer;
    DmSearchStateType searchInfo;
    UInt16 cardNo;
    LocalID dbID;
    UInt32 addrID = AddrGotoCreatorId[(int)gPrefsR.addrapp];

    theGotoPointer = MemPtrNew(sizeof(GoToParamsType));
    if (!theGotoPointer) return -1;
    /* Set the owner of the pointer to be the
       system. This is required because all memory
       allocated by our application is freed when
       the application quits. Our application will
       quit the next time through our event
       handler.
    */
    
    if ((MemPtrSetOwner(theGotoPointer, 0) == 0) &&
        (DmGetNextDatabaseByTypeCreator(true, &searchInfo, 0,
                                        addrID, true, &cardNo, &dbID)
         == 0)) {

        // copy all the goto information into the
        // GotoParamsPtr structure
        theGotoPointer->searchStrLen = 0;
        theGotoPointer->dbCardNo = cardNo;
        theGotoPointer->dbID = dbID;
        theGotoPointer->recordNum = index;
        theGotoPointer->matchPos = 0;
        theGotoPointer->matchFieldNum = 0;
        theGotoPointer->matchCustom = 0;

        if ((DmGetNextDatabaseByTypeCreator
             (true, &searchInfo,
            sysFileTApplication, addrID, true, &cardNo, &dbID) == 0)) {
            SysUIAppSwitch(cardNo, dbID,
                           sysAppLaunchCmdGoTo,
                           (MemPtr) theGotoPointer);
			/*
			 * return from address? (fatal?)
            SysAppLaunch(cardNo, dbID, sysAppLaunchFlagNewThread,
                           sysAppLaunchCmdGoTo,
                           (MemPtr) theGotoPointer, &ret);
			*/
            return 0;
        }
    }

	MemPtrFree(theGotoPointer);
    return -1;
}
Example #22
0
static Boolean InitGlobals(void)
{
    GlobalsPtr  gP  = NULL;
    
    gP = (GlobalsPtr)MemPtrNew(sizeof(GlobalsType));
    if (!gP) {
        return false;
    }
    MemSet(gP, sizeof(GlobalsType), 0);
    FtrSet(kAppFileCreator, ftrGlobals, (UInt32)gP);
    
    return true;
}
Example #23
0
/* Initialize the main form */
static void FormInit( void )
{
    UInt16 i;

    form = FrmGetActiveForm();

    for ( i = 0; i < NUM_OF_BUTTONS; i++ ) {
        ButtonType* button;
        UInt32      records;
        UInt32      size;

        button = &buttonList[ i ];

        EnumerateData( button->creator, button->type, &records, &size );

        if ( records == 0 ) {
            HideNShow( button->recordIndex, button->sizeIndex,
                button->notFoundIndex );
            button->status = NOT_FOUND;
        } else {
            button->recordText = MemPtrNew( 255 );
            button->sizeText   = MemPtrNew( 255 );

            StrPrintF( button->recordText, "%ld", records );
            StrPrintF( button->sizeText, "%ld", size );

            FldSetTextPtr( FrmGetObjectPtr( form,
                FrmGetObjectIndex( form, button->recordIndex ) ),
                button->recordText );
            FldSetTextPtr( FrmGetObjectPtr( form,
                FrmGetObjectIndex( form, button->sizeIndex ) ),
                button->sizeText );

            button->status = VALID;
        }
    }

    FrmDrawForm( form );
}
Example #24
0
bool PckTunesCDPlayer::init() {
	PocketTunesStart();
	_isInitialized = PocketTunesIsRunning();
	_isPlaying = false;
	_pAction = NULL;

	if (_isInitialized) {
		_pAction = (PocketTunesAction*)MemPtrNew(sizeof(PocketTunesAction));
		_volumeLimit = getVolumeLimit();
	}

	_isInitialized = (_isInitialized && _pAction);
	return _isInitialized;
}
Example #25
0
}void
save_preferences(void)
{int size=prefs_size(),n;char*p=MemPtrNew(size),*_=p;const char*l;
 const char*dbn;struct database_handle**dbl;char aux_flags;
 if(!p){if(lookup)MemPtrFree(lookup);lookup=0;return;}
 l=get_lookup();dbl=get_database_list(&n);dbn=db_name;
 if(dbl)dbn=dbl[get_current_db_idx()]->name;
 MemMove(_,dbn,db_name_size);_+=db_name_size;
 if(l){StrCopy(_,l);_+=StrLen(l);if(lookup)MemPtrFree(lookup);lookup=0;}
 *_++=0;aux_flags=0;if(get_list_mode())aux_flags|=1<<list_mode_bit;
 *_=aux_flags;
 PrefSetAppPreferences(CREATOR,prefs_id,prefs_version,p,size,0);
 MemPtrFree(p);
}/*Copyright (C) 2008, 2009 Ineiev<*****@*****.**>, super V 93
Example #26
0
/*************************************************************************
 * Function: replaceAccountHash
 * Description: regernate the hash on a single account based on account
 * index
 * ***********************************************************************/ 
void replaceAccountHash(UInt16 index, DmOpenRef db, md_hash * SysPass) {
	Account ac;
	MemHandle rH;
	MemPtr pac = NULL, scratch = NULL, scratch2=NULL;
	if ((rH = DmGetRecord (db, index))) {
		pac = MemHandleLock (rH);
		if ((scratch = MemPtrNew (MemPtrSize (pac)))) {
			UnpackAccount (&ac, pac, scratch, SysPass, 
				MemHandleSize (rH), true, true);
			if ((scratch2 = MemPtrNew (MemPtrSize (pac)))) {
				MemMove(ac.hash, 
					generateAccountHash(&ac), 
					sizeof(md_hash)); 
				PackAccount (scratch2, ac, SysPass, true);
				writeRecord(scratch2, rH);
			}
		}
		MemPtrFree(scratch);
		MemPtrFree(scratch2);
		MemHandleUnlock (rH);
		DmReleaseRecord (db, index, true);
	}
}
Example #27
0
void *MemPtrNewLarge(Int32 size)
{
	// Allocate a chunk of memory where the size of the memory might exceed
	// 64k.  There are a few potential problems here:
	//  (a) the memory cannot be saved to a database
	//  (b) if you forget to free the large chunk before
	//      you application quits, you will cause a MEMORY LEAK on
	//      Palm OS 5 and 5.1 .
	if (size > 65500) {
        SysAppInfoType      *unusedAppInfoP;
		UInt16 currentOwnerID = SysGetAppInfo(&unusedAppInfoP, &unusedAppInfoP)->memOwnerID;
		return MemChunkNew(0, size, currentOwnerID | memNewChunkFlagNonMovable | memNewChunkFlagAllowLarge);
	}
    
    return MemPtrNew(size);
}
Example #28
0
/************************************************************************************
 * Function: PackRegistration
 * Description: Utility function that takes an unpacked Registration, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackRegistration (MemPtr retbuff, Registration reg) {
	UInt16 offset = 0;
	MemPtr preg;
	if ((preg = MemPtrNew (MemPtrSize (retbuff)))) {
		/*	move the data into the buffer. */
		MemMove (preg + offset, &reg.first_use, sizeof (reg.first_use));
		offset += sizeof (reg.first_use);
		MemMove (preg + offset, reg.email, StrLen (reg.email) + 1);
		offset += StrLen (reg.email) + 1;
		MemMove (preg + offset, reg.code, StrLen (reg.code) + 1);
		offset += StrLen (reg.code) + 1;

		MemMove (retbuff, preg, MemPtrSize(preg));
		MemSet (preg, MemPtrSize (preg), 0);
		MemPtrFree (preg);
	}
}
Example #29
0
MemPtr __malloc(UInt32 size) {
    MemPtr newP = NULL;

    if (size <= 65000) {
        newP = MemPtrNew(size);
    } else {
        SysAppInfoPtr appInfoP;
        UInt16 ownerID;
        UInt16 attr;

        ownerID = ((SysAppInfoPtr)SysGetAppInfo(&appInfoP, &appInfoP))->memOwnerID;
        attr	= ownerID|memNewChunkFlagAllowLarge|memNewChunkFlagNonMovable;

        newP = MemChunkNew(0, size, attr);
    }

    return newP;
}
Example #30
0
/************************************************************************************
 * Function: PackSystem
 * Description: Utility function that takes an unpacked system, optionally encrypts
 * it and packs it into a buffer, strings are seperated by null characters. puts the 
 * content in retbuffer
 * *********************************************************************************/ 
void PackSystem (MemPtr retbuff, System sys, md_hash * pass, Boolean encrypt) {
	UInt16 offset = 0;
	MemPtr psys;
	if ((psys = MemPtrNew (MemPtrSize (retbuff)))) {
		/*	move the data into the buffer. */
		MemMove (psys + offset, &sys.SystemID, sizeof (sys.SystemID));
		offset += sizeof (sys.SystemID);
		MemMove (psys + offset, sys.name, StrLen (sys.name) + 1);
		offset += StrLen (sys.name) + 1;
		
		if (encrypt) {
			MemMove(retbuff, psys, SYST_HEADER);
			stripCrypt (*pass, psys+SYST_HEADER, retbuff+SYST_HEADER, getSystemSize(&sys, true)-SYST_HEADER, ENCRYPT);
		} else MemMove (retbuff, psys, getSystemSize (&sys, true));

		MemSet (psys, MemPtrSize (psys), 0);
		MemPtrFree (psys);
	}
}