PRMJ_ToExtendedTime(PRInt32 time) { PRInt64 exttime; PRInt64 g1970GMTMicroSeconds; PRInt64 low; time_t diff; PRInt64 tmp; PRInt64 tmp1; diff = PRMJ_LocalGMTDifference(); LL_UI2L(tmp, PRMJ_USEC_PER_SEC); LL_I2L(tmp1,diff); LL_MUL(tmp,tmp,tmp1); LL_UI2L(g1970GMTMicroSeconds,G1970GMTMICROHI); LL_UI2L(low,G1970GMTMICROLOW); #ifndef HAVE_LONG_LONG LL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,16); LL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,16); #else LL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,32); #endif LL_ADD(g1970GMTMicroSeconds,g1970GMTMicroSeconds,low); LL_I2L(exttime,time); LL_ADD(exttime,exttime,g1970GMTMicroSeconds); LL_SUB(exttime,exttime,tmp); return exttime; }
// Gets shell version as packed 64 bit int PRUint64 nsDragService::GetShellVersion() { PRUint64 lVersion = LL_INIT(0, 0); PRUint64 lMinor = lVersion; // shell32.dll should be loaded already, so we ae not actually loading the library here PRLibrary *libShell = PR_LoadLibrary("shell32.dll"); if (libShell == NULL) return lVersion; do { DLLGETVERSIONPROC versionProc = NULL; versionProc = (DLLGETVERSIONPROC)PR_FindFunctionSymbol(libShell, "DllGetVersion"); if (versionProc == NULL) break; DLLVERSIONINFO versionInfo; ::ZeroMemory(&versionInfo, sizeof(DLLVERSIONINFO)); versionInfo.cbSize = sizeof(DLLVERSIONINFO); if (FAILED(versionProc(&versionInfo))) break; // why is this? LL_UI2L(lVersion, versionInfo.dwMajorVersion); LL_SHL(lVersion, lVersion, 32); LL_UI2L(lMinor, versionInfo.dwMinorVersion); LL_OR2(lVersion, lMinor); } while (false); PR_UnloadLibrary(libShell); libShell = NULL; return lVersion; }
PRInt64 StatsManagerUtil::getSeconds(PRInt64 time) { PRInt64 temp = 0; PRInt64 dividend = 0; PRInt64 divisor = 0; LL_UI2L(temp, PR_USEC_PER_SEC/2); LL_ADD(dividend, time, temp); LL_UI2L(divisor, PR_USEC_PER_SEC); LL_DIV(temp, dividend, divisor); return temp; }
static PRUint64 RubyTo64BitInt(VALUE aRuby) { VALUE bitMask = max_PRUint32; VALUE lo = rb_funcall(aRuby, id_and, 1, bitMask); VALUE hi = rb_funcall(aRuby, id_rshift, 1, INT2FIX(32)); PRUint64 result, hi64, lo64; LL_UI2L(hi64, NUM2UINT(hi)); LL_UI2L(lo64, NUM2UINT(lo)); LL_SHL(result, hi64, 32); LL_ADD(result, result, lo64); return result; }
PRInt32 _PR_MD_GETOPENFILEINFO64(const PRFileDesc *fd, PRFileInfo64 *info) { PRFileInfo info32; PRInt32 rv = _PR_MD_GETOPENFILEINFO(fd, &info32); if (0 == rv) { info->type = info32.type; LL_UI2L(info->size,info32.size); info->modifyTime = info32.modifyTime; info->creationTime = info32.creationTime; } if (isWSEB) { APIRET rc ; FILESTATUS3L fstatus; rc = DosQueryFileInfo(fd->secret->md.osfd, FIL_STANDARDL, &fstatus, sizeof(fstatus)); if (NO_ERROR != rc) { _PR_MD_MAP_OPEN_ERROR(rc); return -1; } if (! (fstatus.attrFile & FILE_DIRECTORY)) { info->size = fstatus.cbFile; } } return rv; }
PRMJ_NowS(void) { PRInt64 us, us2s; us = PRMJ_Now(); LL_UI2L(us2s, PRMJ_USEC_PER_SEC); LL_DIV(us, us, us2s); return us; }
PR_IMPLEMENT(PRUint64) PR_htonll(PRUint64 n) { #ifdef IS_BIG_ENDIAN return n; #else PRUint64 tmp; PRUint32 hi, lo; LL_L2UI(lo, n); LL_SHR(tmp, n, 32); LL_L2UI(hi, tmp); hi = htonl(hi); lo = htonl(lo); LL_UI2L(n, lo); LL_SHL(n, n, 32); LL_UI2L(tmp, hi); LL_ADD(n, n, tmp); return n; #endif } /* htonll */
PRUint32 ticks2xsec(tmreader* aReader, PRUint32 aTicks, PRUint32 aResolution) /* ** Convert platform specific ticks to second units ** Returns 0 on success. */ { PRUint32 retval = 0; PRUint64 bigone; PRUint64 tmp64; LL_UI2L(bigone, aResolution); LL_UI2L(tmp64, aTicks); LL_MUL(bigone, bigone, tmp64); LL_UI2L(tmp64, aReader->ticksPerSec); LL_DIV(bigone, bigone, tmp64); LL_L2UI(retval, bigone); return retval; }
PRMJ_NowMS(void) { PRInt64 us, us2ms; us = PRMJ_Now(); LL_UI2L(us2ms, PRMJ_USEC_PER_MSEC); LL_DIV(us, us, us2ms); return us; }
// this is a utility function void nsAbPalmHotSync::ConvertAssignPalmIDAttrib(PRUint32 id, nsIAbMDBCard * card) { PRInt64 l; LL_UI2L(l, id); PRFloat64 f; LL_L2F(f, l); char buf[128]; PR_cnvtf(buf, 128, 0, f); card->SetAbDatabase(mABDB); card->SetStringAttribute(CARD_ATTRIB_PALMID,NS_ConvertASCIItoUTF16(buf).get()); }
PRTime PRTimeFromSeconds(uint32_t seconds) { int64_t microSecondsPerSecond, intermediateResult; PRTime prTime; LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); LL_UI2L(intermediateResult, seconds); prTime = intermediateResult * microSecondsPerSecond; return prTime; }
PRMJ_DSTOffset(PRInt64 time) { PRInt64 us2s; #ifdef XP_MAC MachineLocation machineLocation; PRInt64 dlsOffset; /* Get the information about the local machine, including * its GMT offset and its daylight savings time info. * Convert each into wides that we can add to * startupTimeMicroSeconds. */ MyReadLocation(&machineLocation); /* Is Daylight Savings On? If so, we need to add an hour to the offset. */ if (machineLocation.u.dlsDelta != 0) { LL_UI2L(us2s, PRMJ_USEC_PER_SEC); /* seconds in a microseconds */ LL_UI2L(dlsOffset, PRMJ_HOUR_SECONDS); /* seconds in one hour */ LL_MUL(dlsOffset, dlsOffset, us2s); } else LL_I2L(dlsOffset, 0); return(dlsOffset); #else time_t local; PRInt32 diff; PRInt64 maxtimet; struct tm tm; #if defined( XP_PC ) || defined( FREEBSD ) struct tm *ptm; #endif PRMJTime prtm; LL_UI2L(us2s, PRMJ_USEC_PER_SEC); LL_DIV(time, time, us2s); /* get the maximum of time_t value */ LL_UI2L(maxtimet,PRMJ_MAX_UNIX_TIMET); if(LL_CMP(time,>,maxtimet)){ LL_UI2L(time,PRMJ_MAX_UNIX_TIMET); } else if(!LL_GE_ZERO(time)){
PRMJ_ToBaseTime(PRInt64 time) { PRInt64 g1970GMTMicroSeconds; PRInt64 g2037GMTMicroSeconds; PRInt64 low; PRInt32 result; LL_UI2L(g1970GMTMicroSeconds,G1970GMTMICROHI); LL_UI2L(low,G1970GMTMICROLOW); #ifndef HAVE_LONG_LONG LL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,16); LL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,16); #else LL_SHL(g1970GMTMicroSeconds,g1970GMTMicroSeconds,32); #endif LL_ADD(g1970GMTMicroSeconds,g1970GMTMicroSeconds,low); LL_UI2L(g2037GMTMicroSeconds,G2037GMTMICROHI); LL_UI2L(low,G2037GMTMICROLOW); #ifndef HAVE_LONG_LONG LL_SHL(g2037GMTMicroSeconds,g2037GMTMicroSeconds,16); LL_SHL(g2037GMTMicroSeconds,g2037GMTMicroSeconds,16); #else LL_SHL(g2037GMTMicroSeconds,g2037GMTMicroSeconds,32); #endif LL_ADD(g2037GMTMicroSeconds,g2037GMTMicroSeconds,low); if(LL_CMP(time, <, g1970GMTMicroSeconds) || LL_CMP(time, >, g2037GMTMicroSeconds)){ return -1; } LL_SUB(time,time,g1970GMTMicroSeconds); LL_L2I(result,time); return result; }
PRStatus FastFetchFile(PRFileDesc *in, PRFileDesc *out, PRUint32 size) { PRInt32 nBytes; PRFileMap *outfMap; void *addr; char *start; PRUint32 rem; PRUint32 bytesToRead; PRStatus rv; PRInt64 sz64; LL_UI2L(sz64, size); outfMap = PR_CreateFileMap(out, sz64, PR_PROT_READWRITE); PR_ASSERT(outfMap); addr = PR_MemMap(outfMap, LL_ZERO, size); if (addr == (void *) -1) { fprintf(stderr, "cannot memory-map file: (%d, %d)\n", PR_GetError(), PR_GetOSError()); PR_CloseFileMap(outfMap); return PR_FAILURE; } PR_ASSERT(addr != (void *) -1); start = (char *) addr; rem = size; while ((nBytes = DrainInputBuffer(start, rem)) > 0) { start += nBytes; rem -= nBytes; } if (nBytes < 0) { /* Input buffer is empty and end of stream */ return PR_SUCCESS; } bytesToRead = (rem < FCOPY_BUFFER_SIZE) ? rem : FCOPY_BUFFER_SIZE; while (rem > 0 && (nBytes = PR_Read(in, start, bytesToRead)) > 0) { start += nBytes; rem -= nBytes; bytesToRead = (rem < FCOPY_BUFFER_SIZE) ? rem : FCOPY_BUFFER_SIZE; } if (nBytes < 0) { fprintf(stderr, "httpget: cannot read from socket\n"); return PR_FAILURE; } rv = PR_MemUnmap(addr, size); PR_ASSERT(rv == PR_SUCCESS); rv = PR_CloseFileMap(outfMap); PR_ASSERT(rv == PR_SUCCESS); return PR_SUCCESS; }
// This should use NSPR but NSPR isn't exporting its PR_strtoll function // Until then... PRInt64 nsCRT::atoll(const char *str) { if (!str) return LL_Zero(); PRInt64 ll = LL_Zero(), digitll = LL_Zero(); while (*str && *str >= '0' && *str <= '9') { LL_MUL(ll, ll, 10); LL_UI2L(digitll, (*str - '0')); LL_ADD(ll, ll, digitll); str++; } return ll; }
void addVariance(VarianceState* inVariance, unsigned inValue) /* ** Add a value to a variance state. */ { PRUint64 squared; PRUint64 bigValue; LL_UI2L(bigValue, inValue); LL_ADD(inVariance->mSum, inVariance->mSum, bigValue); LL_MUL(squared, bigValue, bigValue); LL_ADD(inVariance->mSquaredSum, inVariance->mSquaredSum, squared); inVariance->mCount++; }
extern PRFileMap* _md_OpenAnonFileMap( const char *dirName, PRSize size, PRFileMapProtect prot ) { PRFileMap *fm = NULL; PRFileDesc *fd; int osfd; PRIntn urc; PRIntn mode = 0600; char *genName; pid_t pid = getpid(); /* for generating filename */ PRThread *tid = PR_GetCurrentThread(); /* for generating filename */ int incr; /* for generating filename */ const int maxTries = 20; /* maximum # attempts at a unique filename */ PRInt64 size64; /* 64-bit version of 'size' */ /* ** generate a filename from input and runtime environment ** open the file, unlink the file. ** make maxTries number of attempts at uniqueness in the filename */ for ( incr = 0; incr < maxTries ; incr++ ) { #ifdef SYMBIAN genName = PR_smprintf( "%s\\NSPR-AFM-%d-%p.%d", #else genName = PR_smprintf( "%s/.NSPR-AFM-%d-%p.%d", #endif dirName, (int) pid, tid, incr ); if ( NULL == genName ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): PR_snprintf(): failed, generating filename")); goto Finished; } /* create the file */ osfd = open( genName, (O_CREAT | O_EXCL | O_RDWR), mode ); if ( -1 == osfd ) { if ( EEXIST == errno ) { PR_smprintf_free( genName ); continue; /* name exists, try again */ } else { _PR_MD_MAP_OPEN_ERROR( errno ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): open(): failed, filename: %s, errno: %d", genName, PR_GetOSError())); PR_smprintf_free( genName ); goto Finished; } } break; /* name generation and open successful, break; */ } /* end for() */ if ( incr == maxTries ) { PR_ASSERT( -1 == osfd ); PR_ASSERT( EEXIST == errno ); _PR_MD_MAP_OPEN_ERROR( errno ); goto Finished; } urc = unlink( genName ); #if defined(__WINS__) /* If it is being used by the system or another process, Symbian OS Emulator(WINS) considers this an error. */ if ( -1 == urc && EACCES != errno ) { #else if ( -1 == urc ) { #endif _PR_MD_MAP_UNLINK_ERROR( errno ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): failed on unlink(), errno: %d", errno)); PR_smprintf_free( genName ); close( osfd ); goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): unlink(): %s", genName )); PR_smprintf_free( genName ); fd = PR_ImportFile( osfd ); if ( NULL == fd ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): PR_ImportFile(): failed")); goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): fd: %p", fd )); urc = ftruncate( fd->secret->md.osfd, size ); if ( -1 == urc ) { _PR_MD_MAP_DEFAULT_ERROR( errno ); PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): failed on ftruncate(), errno: %d", errno)); PR_Close( fd ); goto Finished; } PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): ftruncate(): size: %d", size )); LL_UI2L(size64, size); /* PRSize (size_t) is unsigned */ fm = PR_CreateFileMap( fd, size64, prot ); if ( NULL == fm ) { PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("PR_OpenAnonFileMap(): failed")); PR_Close( fd ); goto Finished; } fm->md.isAnonFM = PR_TRUE; /* set fd close */ PR_LOG( _pr_shma_lm, PR_LOG_DEBUG, ("_md_OpenAnonFileMap(): PR_CreateFileMap(): fm: %p", fm )); Finished: return(fm); } /* end md_OpenAnonFileMap() */ /* ** _md_ExportFileMapAsString() ** ** */ extern PRStatus _md_ExportFileMapAsString( PRFileMap *fm, PRSize bufSize, char *buf ) { PRIntn written; PRIntn prot = (PRIntn)fm->prot; written = PR_snprintf( buf, bufSize, "%ld:%d", fm->fd->secret->md.osfd, prot ); return((written == -1)? PR_FAILURE : PR_SUCCESS); } /* end _md_ExportFileMapAsString() */
// Set rcvDate to true to get the Received: date instead of the Date: date. nsresult nsMsgGroupView::GetAgeBucketValue(nsIMsgDBHdr *aMsgHdr, PRUint32 * aAgeBucket, bool rcvDate) { NS_ENSURE_ARG_POINTER(aMsgHdr); NS_ENSURE_ARG_POINTER(aAgeBucket); PRTime dateOfMsg; nsresult rv; if (!rcvDate) rv = aMsgHdr->GetDate(&dateOfMsg); else { PRUint32 rcvDateSecs; rv = aMsgHdr->GetUint32Property("dateReceived", &rcvDateSecs); Seconds2PRTime(rcvDateSecs, &dateOfMsg); } NS_ENSURE_SUCCESS(rv, rv); PRTime currentTime = PR_Now(); PRExplodedTime currentExplodedTime; PR_ExplodeTime(currentTime, PR_LocalTimeParameters, ¤tExplodedTime); PRExplodedTime explodedMsgTime; PR_ExplodeTime(dateOfMsg, PR_LocalTimeParameters, &explodedMsgTime); if (m_lastCurExplodedTime.tm_mday && m_lastCurExplodedTime.tm_mday != currentExplodedTime.tm_mday) m_dayChanged = true; // this will cause us to rebuild the view. m_lastCurExplodedTime = currentExplodedTime; if (currentExplodedTime.tm_year == explodedMsgTime.tm_year && currentExplodedTime.tm_month == explodedMsgTime.tm_month && currentExplodedTime.tm_mday == explodedMsgTime.tm_mday) { // same day... *aAgeBucket = 1; } // figure out how many days ago this msg arrived else if (LL_CMP(currentTime, >, dateOfMsg)) { // some constants for calculation static PRInt64 microSecondsPerSecond; static PRInt64 microSecondsPerDay; static PRInt64 secondsPerDay; static PRInt64 microSecondsPer6Days; static PRInt64 microSecondsPer13Days; static bool bGotConstants = false; if ( !bGotConstants ) { // seeds LL_I2L ( microSecondsPerSecond, PR_USEC_PER_SEC ); LL_UI2L ( secondsPerDay, 60 * 60 * 24 ); // derivees LL_MUL( microSecondsPerDay, secondsPerDay, microSecondsPerSecond ); LL_MUL( microSecondsPer6Days, microSecondsPerDay, 6 ); LL_MUL( microSecondsPer13Days, microSecondsPerDay, 13 ); bGotConstants = true; } // setting the time variables to local time PRInt64 GMTLocalTimeShift; LL_ADD( GMTLocalTimeShift, currentExplodedTime.tm_params.tp_gmt_offset, currentExplodedTime.tm_params.tp_dst_offset ); LL_MUL( GMTLocalTimeShift, GMTLocalTimeShift, microSecondsPerSecond ); LL_ADD( currentTime, currentTime, GMTLocalTimeShift ); LL_ADD( dateOfMsg, dateOfMsg, GMTLocalTimeShift ); // the most recent midnight, counting from current time PRInt64 todaysMicroSeconds, mostRecentMidnight; LL_MOD( todaysMicroSeconds, currentTime, microSecondsPerDay ); LL_SUB( mostRecentMidnight, currentTime, todaysMicroSeconds ); PRInt64 yesterday; LL_SUB( yesterday, mostRecentMidnight, microSecondsPerDay ); // most recent midnight minus 6 days PRInt64 mostRecentWeek; LL_SUB( mostRecentWeek, mostRecentMidnight, microSecondsPer6Days ); // was the message sent yesterday? if ( LL_CMP( dateOfMsg, >=, yesterday ) ) // yes .... *aAgeBucket = 2; else if ( LL_CMP(dateOfMsg, >=, mostRecentWeek) ) *aAgeBucket = 3; else {
nsresult nsMsgSearchAdapter::EncodeImapTerm (nsIMsgSearchTerm *term, bool reallyDredd, const PRUnichar *srcCharset, const PRUnichar *destCharset, char **ppOutTerm) { NS_ENSURE_ARG_POINTER(term); NS_ENSURE_ARG_POINTER(ppOutTerm); nsresult err = NS_OK; bool useNot = false; bool useQuotes = false; bool ignoreValue = false; nsCAutoString arbitraryHeader; const char *whichMnemonic = nsnull; const char *orHeaderMnemonic = nsnull; *ppOutTerm = nsnull; nsCOMPtr <nsIMsgSearchValue> searchValue; nsresult rv = term->GetValue(getter_AddRefs(searchValue)); NS_ENSURE_SUCCESS(rv,rv); nsMsgSearchOpValue op; term->GetOp(&op); if (op == nsMsgSearchOp::DoesntContain || op == nsMsgSearchOp::Isnt) useNot = true; nsMsgSearchAttribValue attrib; term->GetAttrib(&attrib); switch (attrib) { case nsMsgSearchAttrib::ToOrCC: orHeaderMnemonic = m_kImapCC; // fall through to case nsMsgSearchAttrib::To: case nsMsgSearchAttrib::To: whichMnemonic = m_kImapTo; break; case nsMsgSearchAttrib::CC: whichMnemonic = m_kImapCC; break; case nsMsgSearchAttrib::Sender: whichMnemonic = m_kImapFrom; break; case nsMsgSearchAttrib::Subject: whichMnemonic = m_kImapSubject; break; case nsMsgSearchAttrib::Body: whichMnemonic = m_kImapBody; break; case nsMsgSearchAttrib::AgeInDays: // added for searching online for age in days... // for AgeInDays, we are actually going to perform a search by date, so convert the operations for age // to the IMAP mnemonics that we would use for date! { // If we have a future date, the > and < are reversed. // e.g. ageInDays > 2 means more than 2 days old ("date before X") whereas // ageInDays > -2 should be more than 2 days in the future ("date after X") PRInt32 ageInDays; searchValue->GetAge(&ageInDays); bool dateInFuture = (ageInDays < 0); switch (op) { case nsMsgSearchOp::IsGreaterThan: whichMnemonic = (!dateInFuture) ? m_kImapBefore : m_kImapSince; break; case nsMsgSearchOp::IsLessThan: whichMnemonic = (!dateInFuture) ? m_kImapSince : m_kImapBefore; break; case nsMsgSearchOp::Is: whichMnemonic = m_kImapSentOn; break; default: NS_ASSERTION(false, "invalid search operator"); return NS_ERROR_INVALID_ARG; } } break; case nsMsgSearchAttrib::Size: switch (op) { case nsMsgSearchOp::IsGreaterThan: whichMnemonic = m_kImapSizeLarger; break; case nsMsgSearchOp::IsLessThan: whichMnemonic = m_kImapSizeSmaller; break; default: NS_ASSERTION(false, "invalid search operator"); return NS_ERROR_INVALID_ARG; } break; case nsMsgSearchAttrib::Date: switch (op) { case nsMsgSearchOp::IsBefore: whichMnemonic = m_kImapBefore; break; case nsMsgSearchOp::IsAfter: whichMnemonic = m_kImapSince; break; case nsMsgSearchOp::Isnt: /* we've already added the "Not" so just process it like it was a date is search */ case nsMsgSearchOp::Is: whichMnemonic = m_kImapSentOn; break; default: NS_ASSERTION(false, "invalid search operator"); return NS_ERROR_INVALID_ARG; } break; case nsMsgSearchAttrib::AnyText: whichMnemonic = m_kImapAnyText; break; case nsMsgSearchAttrib::Keywords: whichMnemonic = m_kImapKeyword; break; case nsMsgSearchAttrib::MsgStatus: useNot = false; // bizarrely, NOT SEEN is wrong, but UNSEEN is right. ignoreValue = true; // the mnemonic is all we need PRUint32 status; searchValue->GetStatus(&status); switch (status) { case nsMsgMessageFlags::Read: whichMnemonic = op == nsMsgSearchOp::Is ? m_kImapSeen : m_kImapNotSeen; break; case nsMsgMessageFlags::Replied: whichMnemonic = op == nsMsgSearchOp::Is ? m_kImapAnswered : m_kImapNotAnswered; break; case nsMsgMessageFlags::New: whichMnemonic = op == nsMsgSearchOp::Is ? m_kImapNew : m_kImapNotNew; break; case nsMsgMessageFlags::Marked: whichMnemonic = op == nsMsgSearchOp::Is ? m_kImapFlagged : m_kImapNotFlagged; break; default: NS_ASSERTION(false, "invalid search operator"); return NS_ERROR_INVALID_ARG; } break; default: if ( attrib > nsMsgSearchAttrib::OtherHeader && attrib < nsMsgSearchAttrib::kNumMsgSearchAttributes) { nsCString arbitraryHeaderTerm; term->GetArbitraryHeader(arbitraryHeaderTerm); if (!arbitraryHeaderTerm.IsEmpty()) { arbitraryHeader.AssignLiteral(" \""); arbitraryHeader.Append(arbitraryHeaderTerm); arbitraryHeader.AppendLiteral("\" "); whichMnemonic = arbitraryHeader.get(); } else return NS_ERROR_FAILURE; } else { NS_ASSERTION(false, "invalid search operator"); return NS_ERROR_INVALID_ARG; } } char *value = nsnull; char dateBuf[100]; dateBuf[0] = '\0'; bool valueWasAllocated = false; if (attrib == nsMsgSearchAttrib::Date) { // note that there used to be code here that encoded an RFC822 date for imap searches. // The IMAP RFC 2060 is misleading to the point that it looks like it requires an RFC822 // date but really it expects dd-mmm-yyyy, like dredd, and refers to the RFC822 date only in that the // dd-mmm-yyyy date will match the RFC822 date within the message. PRTime adjustedDate; searchValue->GetDate(&adjustedDate); if (whichMnemonic == m_kImapSince) { // it looks like the IMAP server searches on Since includes the date in question... // our UI presents Is, IsGreater and IsLessThan. For the IsGreater case (m_kImapSince) // we need to adjust the date so we get greater than and not greater than or equal to which // is what the IMAP server wants to search on // won't work on Mac. // ack, is this right? is PRTime seconds or microseconds? PRInt64 microSecondsPerSecond, secondsInDay, microSecondsInDay; LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); LL_UI2L(secondsInDay, 60 * 60 * 24); LL_MUL(microSecondsInDay, secondsInDay, microSecondsPerSecond); LL_ADD(adjustedDate, adjustedDate, microSecondsInDay); // bump up to the day after this one... } PRExplodedTime exploded; PR_ExplodeTime(adjustedDate, PR_LocalTimeParameters, &exploded); PR_FormatTimeUSEnglish(dateBuf, sizeof(dateBuf), "%d-%b-%Y", &exploded); // strftime (dateBuf, sizeof(dateBuf), "%d-%b-%Y", localtime (/* &term->m_value.u.date */ &adjustedDate)); value = dateBuf; } else { if (attrib == nsMsgSearchAttrib::AgeInDays) { // okay, take the current date, subtract off the age in days, then do an appropriate Date search on // the resulting day. PRInt32 ageInDays; searchValue->GetAge(&ageInDays); PRTime now = PR_Now(); PRTime matchDay; PRInt64 microSecondsPerSecond, secondsInDays, microSecondsInDay; LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC); LL_I2L(secondsInDays, 60 * 60 * 24 * ageInDays); LL_MUL(microSecondsInDay, secondsInDays, microSecondsPerSecond); LL_SUB(matchDay, now, microSecondsInDay); // = now - term->m_value.u.age * 60 * 60 * 24; PRExplodedTime exploded; PR_ExplodeTime(matchDay, PR_LocalTimeParameters, &exploded); PR_FormatTimeUSEnglish(dateBuf, sizeof(dateBuf), "%d-%b-%Y", &exploded); // strftime (dateBuf, sizeof(dateBuf), "%d-%b-%Y", localtime (&matchDay)); value = dateBuf; } else if (attrib == nsMsgSearchAttrib::Size) { PRUint32 sizeValue; nsCAutoString searchTermValue; searchValue->GetSize(&sizeValue); // Multiply by 1024 to get into kb resolution sizeValue *= 1024; // Ensure that greater than is really greater than // in kb resolution. if (op == nsMsgSearchOp::IsGreaterThan) sizeValue += 1024; searchTermValue.AppendInt(sizeValue); value = ToNewCString(searchTermValue); valueWasAllocated = true; } else if (IS_STRING_ATTRIBUTE(attrib)) { PRUnichar *convertedValue; // = reallyDredd ? MSG_EscapeSearchUrl (term->m_value.u.string) : msg_EscapeImapSearchProtocol(term->m_value.u.string); nsString searchTermValue; searchValue->GetStr(searchTermValue); // Ugly switch for Korean mail/news charsets. // We want to do this here because here is where // we know what charset we want to use. #ifdef DOING_CHARSET if (reallyDredd) dest_csid = INTL_DefaultNewsCharSetID(dest_csid); else dest_csid = INTL_DefaultMailCharSetID(dest_csid); #endif // do all sorts of crazy escaping convertedValue = reallyDredd ? EscapeSearchUrl (searchTermValue.get()) : EscapeImapSearchProtocol(searchTermValue.get()); useQuotes = ((!reallyDredd || (nsDependentString(convertedValue).FindChar(PRUnichar(' ')) != -1)) && (attrib != nsMsgSearchAttrib::Keywords)); // now convert to char* and escape quoted_specials nsCAutoString valueStr; nsresult rv = ConvertFromUnicode(NS_LossyConvertUTF16toASCII(destCharset).get(), nsDependentString(convertedValue), valueStr); if (NS_SUCCEEDED(rv)) { const char *vptr = valueStr.get(); // max escaped length is one extra character for every character in the cmd. nsAutoArrayPtr<char> newValue(new char[2*strlen(vptr) + 1]); if (newValue) { char *p = newValue; while (1) { char ch = *vptr++; if (!ch) break; if ((useQuotes ? ch == '"' : 0) || ch == '\\') *p++ = '\\'; *p++ = ch; } *p = '\0'; value = strdup(newValue); // realloc down to smaller size } } else value = strdup(""); NS_Free(convertedValue); valueWasAllocated = true; } } // this should be rewritten to use nsCString int subLen = (value ? strlen(value) : 0) + (useNot ? strlen(m_kImapNot) : 0) + strlen(m_kImapHeader); int len = strlen(whichMnemonic) + subLen + (useQuotes ? 2 : 0) + (orHeaderMnemonic ? (subLen + strlen(m_kImapOr) + strlen(orHeaderMnemonic) + 2 /*""*/) : 0) + 10; // add slough for imap string literals char *encoding = new char[len]; if (encoding) { encoding[0] = '\0'; // Remember: if ToOrCC and useNot then the expression becomes NOT To AND Not CC as opposed to (NOT TO) || (NOT CC) if (orHeaderMnemonic && !useNot) PL_strcat(encoding, m_kImapOr); if (useNot) PL_strcat (encoding, m_kImapNot); if (!arbitraryHeader.IsEmpty()) PL_strcat (encoding, m_kImapHeader); PL_strcat (encoding, whichMnemonic); if (!ignoreValue) err = EncodeImapValue(encoding, value, useQuotes, reallyDredd); if (orHeaderMnemonic) { if (useNot) PL_strcat(encoding, m_kImapNot); PL_strcat (encoding, m_kImapHeader); PL_strcat (encoding, orHeaderMnemonic); if (!ignoreValue) err = EncodeImapValue(encoding, value, useQuotes, reallyDredd); } // kmcentee, don't let the encoding end with whitespace, // this throws off later url STRCMP if (*encoding && *(encoding + strlen(encoding) - 1) == ' ') *(encoding + strlen(encoding) - 1) = '\0'; } if (value && valueWasAllocated) NS_Free (value); *ppOutTerm = encoding; return err; }
/* * get the difference in seconds between this time zone and UTC (GMT) */ PR_IMPLEMENT(time_t) PRMJ_LocalGMTDifference() { #if defined(XP_UNIX) || defined(XP_PC) struct tm ltime; /* get the difference between this time zone and GMT */ memset((char *)<ime,0,sizeof(ltime)); ltime.tm_mday = 2; ltime.tm_year = 70; #ifdef SUNOS4 ltime.tm_zone = 0; ltime.tm_gmtoff = 0; return timelocal(<ime) - (24 * 3600); #else return mktime(<ime) - (24L * 3600L); #endif #endif #if defined(XP_MAC) static time_t zone = -1L; MachineLocation machineLocation; PRUint64 gmtOffsetSeconds; PRUint64 gmtDelta; PRUint64 dlsOffset; PRInt32 offset; /* difference has been set no need to recalculate */ if(zone != -1) return zone; /* Get the information about the local machine, including * its GMT offset and its daylight savings time info. * Convert each into wides that we can add to * startupTimeMicroSeconds. */ MyReadLocation(&machineLocation); /* Mask off top eight bits of gmtDelta, sign extend lower three. */ if ((machineLocation.u.gmtDelta & 0x00800000) != 0) { gmtOffsetSeconds.lo = (machineLocation.u.gmtDelta & 0x00FFFFFF) | 0xFF000000; gmtOffsetSeconds.hi = 0xFFFFFFFF; LL_UI2L(gmtDelta,0); } else { gmtOffsetSeconds.lo = (machineLocation.u.gmtDelta & 0x00FFFFFF); gmtOffsetSeconds.hi = 0; LL_UI2L(gmtDelta,PRMJ_DAY_SECONDS); } /* normalize time to be positive if you are behind GMT. gmtDelta will always * be positive. */ LL_SUB(gmtDelta,gmtDelta,gmtOffsetSeconds); /* Is Daylight Savings On? If so, we need to add an hour to the offset. */ if (machineLocation.u.dlsDelta != 0) { LL_UI2L(dlsOffset, PRMJ_HOUR_SECONDS); } else LL_I2L(dlsOffset, 0); LL_ADD(gmtDelta,gmtDelta, dlsOffset); LL_L2I(offset,gmtDelta); zone = offset; return (time_t)offset; #endif }
nsresult mozJSComponentLoader::GlobalForLocation(nsILocalFile *aComponent, JSObject **aGlobal, char **aLocation) { nsresult rv; JSPrincipals* jsPrincipals = nsnull; JSCLContextHelper cx(mContext); #ifndef XPCONNECT_STANDALONE rv = mSystemPrincipal->GetJSPrincipals(cx, &jsPrincipals); NS_ENSURE_SUCCESS(rv, rv); JSPrincipalsHolder princHolder(mContext, jsPrincipals); #endif nsCOMPtr<nsIXPCScriptable> backstagePass; rv = mRuntimeService->GetBackstagePass(getter_AddRefs(backstagePass)); NS_ENSURE_SUCCESS(rv, rv); JSCLAutoErrorReporterSetter aers(cx, mozJSLoaderErrorReporter); nsCOMPtr<nsIXPConnect> xpc = do_GetService(kXPConnectServiceContractID, &rv); NS_ENSURE_SUCCESS(rv, rv); // Make sure InitClassesWithNewWrappedGlobal() installs the // backstage pass as the global in our compilation context. JS_SetGlobalObject(cx, nsnull); nsCOMPtr<nsIXPConnectJSObjectHolder> holder; rv = xpc->InitClassesWithNewWrappedGlobal(cx, backstagePass, NS_GET_IID(nsISupports), nsIXPConnect:: FLAG_SYSTEM_GLOBAL_OBJECT, getter_AddRefs(holder)); NS_ENSURE_SUCCESS(rv, rv); JSObject *global; rv = holder->GetJSObject(&global); NS_ENSURE_SUCCESS(rv, rv); if (!JS_DefineFunctions(cx, global, gGlobalFun)) { return NS_ERROR_FAILURE; } nsCOMPtr<nsIXPConnectJSObjectHolder> locationHolder; rv = xpc->WrapNative(cx, global, aComponent, NS_GET_IID(nsILocalFile), getter_AddRefs(locationHolder)); NS_ENSURE_SUCCESS(rv, rv); JSObject *locationObj; rv = locationHolder->GetJSObject(&locationObj); NS_ENSURE_SUCCESS(rv, rv); if (!JS_DefineProperty(cx, global, "__LOCATION__", OBJECT_TO_JSVAL(locationObj), nsnull, nsnull, 0)) { return NS_ERROR_FAILURE; } nsCAutoString nativePath; // Quick hack to unbust XPCONNECT_STANDALONE. // This leaves the jsdebugger with a non-URL pathname in the // XPCONNECT_STANDALONE case - but at least it builds and runs otherwise. // See: http://bugzilla.mozilla.org/show_bug.cgi?id=121438 #ifdef XPCONNECT_STANDALONE localFile->GetNativePath(nativePath); #else NS_GetURLSpecFromFile(aComponent, nativePath); #endif // Before compiling the script, first check to see if we have it in // the fastload file. Note: as a rule, fastload errors are not fatal // to loading the script, since we can always slow-load. nsCOMPtr<nsIFastLoadService> flSvc = do_GetFastLoadService(&rv); // Save the old state and restore it upon return FastLoadStateHolder flState(flSvc); PRBool fastLoading = PR_FALSE; if (NS_SUCCEEDED(rv)) { rv = StartFastLoad(flSvc); if (NS_SUCCEEDED(rv)) { fastLoading = PR_TRUE; } } nsCOMPtr<nsIURI> uri; rv = NS_NewURI(getter_AddRefs(uri), nativePath); NS_ENSURE_SUCCESS(rv, rv); JSScript *script = nsnull; if (fastLoading) { rv = ReadScript(flSvc, nativePath.get(), uri, cx, &script); if (NS_SUCCEEDED(rv)) { LOG(("Successfully loaded %s from fastload\n", nativePath.get())); fastLoading = PR_FALSE; // no need to write out the script } else if (rv == NS_ERROR_NOT_AVAILABLE) { // This is ok, it just means the script is not yet in the // fastload file. rv = NS_OK; } else { LOG(("Failed to deserialize %s\n", nativePath.get())); // Remove the fastload file, it may be corrupted. LOG(("Invalid fastload file detected, removing it\n")); nsCOMPtr<nsIObjectOutputStream> objectOutput; flSvc->GetOutputStream(getter_AddRefs(objectOutput)); if (objectOutput) { flSvc->SetOutputStream(nsnull); objectOutput->Close(); } nsCOMPtr<nsIObjectInputStream> objectInput; flSvc->GetInputStream(getter_AddRefs(objectInput)); if (objectInput) { flSvc->SetInputStream(nsnull); objectInput->Close(); } if (mFastLoadFile) { mFastLoadFile->Remove(PR_FALSE); } fastLoading = PR_FALSE; } } if (!script || NS_FAILED(rv)) { // The script wasn't in the fastload cache, so compile it now. LOG(("Slow loading %s\n", nativePath.get())); #ifdef HAVE_PR_MEMMAP PRInt64 fileSize; rv = aComponent->GetFileSize(&fileSize); if (NS_FAILED(rv)) return rv; PRInt64 maxSize; LL_UI2L(maxSize, PR_UINT32_MAX); if (LL_CMP(fileSize, >, maxSize)) { NS_ERROR("file too large"); return NS_ERROR_FAILURE; } PRFileDesc *fileHandle; rv = aComponent->OpenNSPRFileDesc(PR_RDONLY, 0, &fileHandle); NS_ENSURE_SUCCESS(rv, rv); // Make sure the file is closed, no matter how we return. FileAutoCloser fileCloser(fileHandle); PRFileMap *map = PR_CreateFileMap(fileHandle, fileSize, PR_PROT_READONLY); if (!map) { NS_ERROR("Failed to create file map"); return NS_ERROR_FAILURE; } // Make sure the file map is closed, no matter how we return. FileMapAutoCloser mapCloser(map); PRUint32 fileSize32; LL_L2UI(fileSize32, fileSize); char *buf = static_cast<char*>(PR_MemMap(map, 0, fileSize32)); if (!buf) { NS_WARNING("Failed to map file"); return NS_ERROR_FAILURE; } script = JS_CompileScriptForPrincipals(cx, global, jsPrincipals, buf, fileSize32, nativePath.get(), 1); PR_MemUnmap(buf, fileSize32); #else /* HAVE_PR_MEMMAP */ /** * No memmap implementation, so fall back to using * JS_CompileFileHandleForPrincipals(). */ FILE *fileHandle; rv = aComponent->OpenANSIFileDesc("r", &fileHandle); NS_ENSURE_SUCCESS(rv, rv); script = JS_CompileFileHandleForPrincipals(cx, global, nativePath.get(), fileHandle, jsPrincipals); /* JS will close the filehandle after compilation is complete. */ #endif /* HAVE_PR_MEMMAP */ }
PRMJ_Now(void) { #ifdef XP_PC PRInt64 s, us, ms2us, s2us; struct timeb b; #endif /* XP_PC */ #ifdef XP_UNIX struct timeval tv; PRInt64 s, us, s2us; #endif /* XP_UNIX */ #ifdef XP_MAC UnsignedWide upTime; PRInt64 localTime; PRInt64 gmtOffset; PRInt64 dstOffset; time_t gmtDiff; PRInt64 s2us; #endif /* XP_MAC */ #ifdef XP_PC ftime(&b); LL_UI2L(ms2us, PRMJ_USEC_PER_MSEC); LL_UI2L(s2us, PRMJ_USEC_PER_SEC); LL_UI2L(s, b.time); LL_UI2L(us, b.millitm); LL_MUL(us, us, ms2us); LL_MUL(s, s, s2us); LL_ADD(s, s, us); return s; #endif #ifdef XP_UNIX #if defined(SOLARIS) gettimeofday(&tv); #else gettimeofday(&tv, 0); #endif /* SOLARIS */ LL_UI2L(s2us, PRMJ_USEC_PER_SEC); LL_UI2L(s, tv.tv_sec); LL_UI2L(us, tv.tv_usec); LL_MUL(s, s, s2us); LL_ADD(s, s, us); return s; #endif /* XP_UNIX */ #ifdef XP_MAC LL_UI2L(localTime,0); gmtDiff = PRMJ_LocalGMTDifference(); LL_I2L(gmtOffset,gmtDiff); LL_UI2L(s2us, PRMJ_USEC_PER_SEC); LL_MUL(gmtOffset,gmtOffset,s2us); LL_UI2L(dstOffset,0); dstOffset = PRMJ_DSTOffset(dstOffset); LL_SUB(gmtOffset,gmtOffset,dstOffset); /* don't adjust for DST since it sets ctime and gmtime off on the MAC */ Microseconds(&upTime); LL_ADD(localTime,localTime,gmtOffset); LL_ADD(localTime,localTime, *((PRUint64 *)&dstLocalBaseMicroseconds)); LL_ADD(localTime,localTime, *((PRUint64 *)&upTime)); return *((PRUint64 *)&localTime); #endif /* XP_MAC */ }
// static PRBool xptiManifest::Read(xptiInterfaceInfoManager* aMgr, xptiWorkingSet* aWorkingSet) { int i; char* whole = nsnull; PRBool succeeded = PR_FALSE; PRUint32 flen; nsManifestLineReader reader; xptiHashEntry* hashEntry; int headerCount = 0; int dirCount = 0; int fileCount = 0; int zipItemCount = -1; int interfaceCount = 0; int dir; int flags; char* values[6]; // 6 is currently the max items we need to parse int lengths[6]; PRUint32 size32; PRInt64 size; PRInt64 date; whole = ReadManifestIntoMemory(aMgr, &flen); if(!whole) return PR_FALSE; reader.Init(whole, flen); // All exits from here on should be via 'goto out' // Look for "Header" section // This version accepts only version 1,0. We also freak if the header // has more than one entry. The rationale is that we want to force an // autoreg if the xpti.dat file was written by *any* other version of // the software. Future versions may wish to support updating older // manifests in some interesting way. if(!ReadSectionHeader(reader, g_TOKEN_Header, 2, &headerCount)) goto out; if(headerCount != 2) goto out; // Verify the version number if(!reader.NextLine()) goto out; // index,VersionLiteral,major,minor if(4 != reader.ParseLine(values, lengths, 4)) goto out; // index if(0 != atoi(values[0])) goto out; // VersionLiteral if(0 != PL_strcmp(values[1], g_TOKEN_Version)) goto out; // major if(g_VERSION_MAJOR != atoi(values[2])) goto out; // minor if(g_VERSION_MINOR != atoi(values[3])) goto out; // Verify the application directory if(!reader.NextLine()) goto out; // index,AppDirLiteral,directoryname if(3 != reader.ParseLine(values, lengths, 3)) goto out; // index if(1 != atoi(values[0])) goto out; // AppDirLiteral if(0 != PL_strcmp(values[1], g_TOKEN_AppDir)) goto out; if(!CurrentAppDirMatchesPersistentDescriptor(aMgr, values[2])) goto out; // Look for "Directories" section if(!ReadSectionHeader(reader, g_TOKEN_Directories, 1, &dirCount)) goto out; else { // To validate that the directory list matches the current search path // we first confirm that the list lengths match. nsCOMPtr<nsISupportsArray> searchPath; aMgr->GetSearchPath(getter_AddRefs(searchPath)); PRUint32 searchPathCount; searchPath->Count(&searchPathCount); if(dirCount != (int) searchPathCount) goto out; } // Read the directory records for(i = 0; i < dirCount; ++i) { if(!reader.NextLine()) goto out; // index,directoryname if(2 != reader.ParseLine(values, lengths, 2)) goto out; // index if(i != atoi(values[0])) goto out; // directoryname if(!aWorkingSet->DirectoryAtMatchesPersistentDescriptor(i, values[1])) goto out; } // Look for "Files" section if(!ReadSectionHeader(reader, g_TOKEN_Files, 1, &fileCount)) goto out; // Alloc room in the WorkingSet for the filearray. if(!aWorkingSet->NewFileArray(fileCount)) goto out; // Read the file records for(i = 0; i < fileCount; ++i) { if(!reader.NextLine()) goto out; // index,filename,dirIndex,dilesSize,filesDate if(5 != reader.ParseLine(values, lengths, 5)) goto out; // index if(i != atoi(values[0])) goto out; // filename if(!*values[1]) goto out; // dirIndex dir = atoi(values[2]); if(dir < 0 || dir > dirCount) goto out; // fileSize size32 = atoi(values[3]); if(size32 <= 0) goto out; LL_UI2L(size, size32); // fileDate date = nsCRT::atoll(values[4]); if(LL_IS_ZERO(date)) goto out; // Append a new file record to the array. aWorkingSet->AppendFile( xptiFile(nsInt64(size), nsInt64(date), dir, values[1], aWorkingSet)); } // Look for "ZipItems" section if(!ReadSectionHeader(reader, g_TOKEN_ArchiveItems, 0, &zipItemCount)) goto out; // Alloc room in the WorkingSet for the zipItemarray. if(zipItemCount) if(!aWorkingSet->NewZipItemArray(zipItemCount)) goto out; // Read the zipItem records for(i = 0; i < zipItemCount; ++i) { if(!reader.NextLine()) goto out; // index,filename if(2 != reader.ParseLine(values, lengths, 2)) goto out; // index if(i != atoi(values[0])) goto out; // filename if(!*values[1]) goto out; // Append a new zipItem record to the array. aWorkingSet->AppendZipItem(xptiZipItem(values[1], aWorkingSet)); } // Look for "Interfaces" section if(!ReadSectionHeader(reader, g_TOKEN_Interfaces, 1, &interfaceCount)) goto out; // Read the interface records for(i = 0; i < interfaceCount; ++i) { int fileIndex; int zipItemIndex; nsIID iid; xptiInterfaceEntry* entry; xptiTypelib typelibRecord; if(!reader.NextLine()) goto out; // index,interfaceName,iid,fileIndex,zipIndex,flags if(6 != reader.ParseLine(values, lengths, 6)) goto out; // index if(i != atoi(values[0])) goto out; // interfaceName if(!*values[1]) goto out; // iid if(!iid.Parse(values[2])) goto out; // fileIndex fileIndex = atoi(values[3]); if(fileIndex < 0 || fileIndex >= fileCount) goto out; // zipIndex (NOTE: -1 is a valid value) zipItemIndex = atoi(values[4]); if(zipItemIndex < -1 || zipItemIndex >= zipItemCount) goto out; // flags flags = atoi(values[5]); if(flags != 0 && flags != 1) goto out; // Build an InterfaceInfo and hook it in. if(zipItemIndex == -1) typelibRecord.Init(fileIndex); else typelibRecord.Init(fileIndex, zipItemIndex); entry = xptiInterfaceEntry::NewEntry(values[1], lengths[1], iid, typelibRecord, aWorkingSet); if(!entry) goto out; entry->SetScriptableFlag(flags==1); // Add our entry to the iid hashtable. hashEntry = (xptiHashEntry*) PL_DHashTableOperate(aWorkingSet->mNameTable, entry->GetTheName(), PL_DHASH_ADD); if(hashEntry) hashEntry->value = entry; // Add our entry to the name hashtable. hashEntry = (xptiHashEntry*) PL_DHashTableOperate(aWorkingSet->mIIDTable, entry->GetTheIID(), PL_DHASH_ADD); if(hashEntry) hashEntry->value = entry; } // success! succeeded = PR_TRUE; out: if(whole) delete [] whole; if(!succeeded) { // Cleanup the WorkingSet on failure. aWorkingSet->InvalidateInterfaceInfos(); aWorkingSet->ClearHashTables(); aWorkingSet->ClearFiles(); } return succeeded; }
nsresult nsAbPalmHotSync::UpdateMozABWithPalmRecords() { if(!mInitialized || !mABDB || !mDBOpen) return NS_ERROR_NOT_INITIALIZED; nsresult rv = NS_OK; for(PRInt32 i=mPalmRecords.Count()-1; i >=0; i--) { nsABCOMCardStruct * palmRec = (nsABCOMCardStruct *)mPalmRecords.ElementAt(i); nsAbIPCCard ipcCard(palmRec, PR_FALSE); char recordIDBuf[128]; PRInt64 l; LL_UI2L(l, palmRec->dwRecordId); PRFloat64 f; LL_L2F(f, l); PR_cnvtf(recordIDBuf, 128, 0, f); // if the card already exists nsCOMPtr<nsIAbCard> existingCard; rv = mABDB->GetCardFromAttribute(nsnull, CARD_ATTRIB_PALMID, nsDependentCString(recordIDBuf), PR_FALSE, getter_AddRefs(existingCard)); if (!existingCard) { rv = mABDB->GetCardFromAttribute(nsnull, CARD_ATTRIB_DISPLAY, nsDependentCString((const char *) palmRec->displayName), PR_FALSE, getter_AddRefs(existingCard)); // if card with this display name exists, just continue; But, we should make sure // it's associated with the palm card going forward, so set the palmid. if (NS_SUCCEEDED(rv) && existingCard) { nsCOMPtr<nsIAbMDBCard> dbCard = do_QueryInterface(existingCard); dbCard->SetStringAttribute(CARD_ATTRIB_PALMID, NS_ConvertASCIItoUTF16(recordIDBuf).get()); continue; } } if(NS_SUCCEEDED(rv) && existingCard) { // Archived is the same as deleted in palm. if(palmRec->dwStatus & ATTR_DELETED || palmRec->dwStatus & ATTR_ARCHIVED) { mABDB->DeleteCard(existingCard, PR_FALSE, nsnull); continue; } if(palmRec->dwStatus & ATTR_NEW) continue; if(palmRec->dwStatus & ATTR_MODIFIED) { PRBool isEqual=PR_FALSE; ipcCard.Equals(existingCard, &isEqual); if(isEqual) continue; else { existingCard->Copy(&ipcCard); rv = mABDB->EditCard(existingCard, PR_FALSE, nsnull); continue; } } } nsCOMPtr<nsIAbMDBCard> dbCard; dbCard = do_CreateInstance(NS_ABMDBCARD_CONTRACTID, &rv); if(NS_FAILED(rv)) continue; nsCOMPtr<nsIAbCard> newCard; newCard = do_QueryInterface(dbCard, &rv); if(NS_FAILED(rv)) continue; rv = newCard->Copy(&ipcCard); if(NS_FAILED(rv)) continue; // if the card does not exist if((ipcCard.GetStatus() == ATTR_NEW) ||(ipcCard.GetStatus() == ATTR_MODIFIED) || (ipcCard.GetStatus() == ATTR_NONE)) { PRUint32 modTimeInSec; PRTime2Seconds(PR_Now(), &modTimeInSec); ipcCard.SetLastModifiedDate(modTimeInSec); rv = mABDB->CreateNewCardAndAddToDB(newCard, PR_FALSE, nsnull); if(NS_SUCCEEDED(rv)) { // now set the attribute for the PalmRecID in the card in the DB dbCard->SetAbDatabase(mABDB); dbCard->SetStringAttribute(CARD_ATTRIB_PALMID, NS_ConvertASCIItoUTF16(recordIDBuf).get()); newCard = do_QueryInterface(dbCard, &rv); if(NS_SUCCEEDED(rv)) rv = mABDB->EditCard(newCard, PR_FALSE, nsnull); } } } return rv; }