short _GetUserAddressBookIndex( userIdentification *theUserID ) { PlayerInfo *thisInfo; short theCount; short iii; theCount = CountAddressBookEntries(); for( iii = 0; iii < theCount; iii++ ) { // // Look for this box and user ID in the address book // thisInfo = GetIndexAddressBookEntry( iii ); /* If the address book entry has not been validated, match on the name */ if (thisInfo->userId.box.box == -1 || theUserID->box.box == -1) { UserName user1, user2; /* If the names match, return it */ if (EqualCStrings(thisInfo->userId.userName, theUserID->userName)) return iii; /* Otherwise, remove spaces and convert to lower-case and try again */ CopyCString(thisInfo->userId.userName, user1); CopyCString(theUserID->userName, user2); MinimizeUserHandle(user1); MinimizeUserHandle(user2); if (EqualCStrings(user1, user2)) return iii; } if( (thisInfo->userId.box.region == theUserID->box.region) && (thisInfo->userId.box.box == theUserID->box.box) && (thisInfo->userId.userID == theUserID->userID) ) return iii; } return kDBIDErrorValue; }
// Get the list of Address Books for the currently logged in user profile STDMETHODIMP CPalmSyncImp::nsGetABList(BOOL aIsUnicode, short * aABListCount, lpnsMozABDesc * aABList, long ** aABCatIndexList, BOOL ** aDirFlagsList) { if (!aABListCount || !aABList || !aABCatIndexList ||!aDirFlagsList) return E_FAIL; *aABListCount = 0; nsresult rv; nsCOMPtr<nsIAbManager> abManager(do_GetService(NS_ABMANAGER_CONTRACTID, &rv)); if (NS_FAILED(rv)) return E_FAIL; nsCOMPtr<nsISimpleEnumerator> subDirectories; if (NS_SUCCEEDED(abManager->GetDirectories(getter_AddRefs(subDirectories))) && subDirectories) { // Get the total number of addrbook. PRInt16 count=0; nsCOMPtr<nsISupports> item; PRBool hasMore; while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore) { if (NS_SUCCEEDED(subDirectories->GetNext(getter_AddRefs(item)))) { nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(item, &rv)); if (NS_SUCCEEDED(rv)) { nsCAutoString fileName; rv = directory->GetFileName(fileName); if(NS_FAILED(rv)) continue; PRInt32 dirType; rv = directory->GetDirType(&dirType); if(NS_FAILED(rv)) continue; PRBool disableThisAB; rv = directory->GetBoolValue("disablePalmSync", PR_FALSE, &disableThisAB); if (NS_FAILED(rv)) continue; // Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) && strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) || (dirType != kPABDirectory && dirType != kMAPIDirectory)) continue; } } count++; } if (!count) return E_FAIL; // should not happen but just in case. lpnsMozABDesc serverDescList = (lpnsMozABDesc) CoTaskMemAlloc(sizeof(nsMozABDesc) * count); BOOL *dirFlagsList = (BOOL *) CoTaskMemAlloc(sizeof(BOOL) * count); long *catIndexList = (long *) CoTaskMemAlloc(sizeof(long) * count); *aABListCount = count; *aABList = serverDescList; *aDirFlagsList = dirFlagsList; *aABCatIndexList = catIndexList; // reset enumerator if (NS_FAILED(abManager->GetDirectories(getter_AddRefs(subDirectories)))) return E_FAIL; // For each valid addrbook collect info. while (NS_SUCCEEDED(rv = subDirectories->HasMoreElements(&hasMore)) && hasMore) { if (NS_SUCCEEDED(subDirectories->GetNext(getter_AddRefs(item)))) { nsCOMPtr<nsIAbDirectory> directory(do_QueryInterface(item, &rv)); if (NS_SUCCEEDED(rv)) { // We don't have to skip mailing list since there's no mailing lists at the top level. nsCAutoString fileName; nsCAutoString uri; nsString description; PRUint32 palmSyncTimeStamp; PRInt32 dirType, palmCategoryIndex; rv = directory->GetDescription(description); if(NS_FAILED(rv)) return E_FAIL; rv = directory->GetFileName(fileName); if(NS_FAILED(rv)) return E_FAIL; rv = directory->GetURI(uri); if(NS_FAILED(rv)) return E_FAIL; rv = directory->GetDirType(&dirType); if(NS_FAILED(rv)) return E_FAIL; rv = directory->GetIntValue("PalmCategoryId", -1, &palmCategoryIndex); if (NS_FAILED(rv)) return E_FAIL; rv = directory->GetIntValue("PalmSyncTimeStamp", 0, (PRInt32*)&palmSyncTimeStamp); if (NS_FAILED(rv)) return E_FAIL; PRBool disableThisAB; rv = directory->GetBoolValue("disablePalmSync", PR_FALSE, &disableThisAB); if (NS_FAILED(rv)) return E_FAIL; // Skip/Ignore 4.X addrbooks (ie, with ".na2" extension), and non personal AB's if (disableThisAB || ((fileName.Length() > kABFileName_PreviousSuffixLen) && strcmp(fileName.get() + fileName.Length() - kABFileName_PreviousSuffixLen, kABFileName_PreviousSuffix) == 0) || (dirType != kPABDirectory && dirType != kMAPIDirectory)) { continue; } if(aIsUnicode) { // convert uri to Unicode nsAutoString abUrl; rv = ConvertToUnicode("UTF-8", uri, abUrl); if (NS_FAILED(rv)) break; // add to the list CopyUnicodeString(&(serverDescList->lpszABName), description); CopyUnicodeString(&(serverDescList->lpszABUrl), abUrl); } else { // we need to convert uri to Unicode and then to ASCII nsAutoString abUUrl; rv = ConvertToUnicode("UTF-8", uri, abUUrl); if (NS_FAILED(rv)) break; CopyCString(&(serverDescList->lpszABName), NS_ConvertUTF16toUTF8(description)); CopyCString(&(serverDescList->lpszABUrl), NS_ConvertUTF16toUTF8(abUUrl)); } serverDescList++; PRUint32 dirFlag = 0; if (palmSyncTimeStamp <= 0) dirFlag |= kFirstTimeSyncDirFlag; // was this the pab? nsCAutoString prefName; rv = directory->GetDirPrefId(prefName); if (NS_FAILED(rv)) break; if (prefName.Equals("ldap_2.servers.pab")) dirFlag |= kIsPabDirFlag; *dirFlagsList = (BOOL) dirFlag; dirFlagsList++; *catIndexList = palmCategoryIndex; catIndexList++; } } } // assign member variables to the beginning of the list serverDescList = *aABList; dirFlagsList = *aDirFlagsList; catIndexList = *aABCatIndexList; if(NS_FAILED(rv)) return E_FAIL; } return S_OK; }