NS_IMETHODIMP nsAppShell::ListenToEventQueue(nsIEventQueue *aQueue, PRBool aListen) { #ifdef DEBUG_APPSHELL printf("ListenToEventQueue(%p, %d) this=%p\n", aQueue, aListen, this); #endif if (!sQueueHashTable) { sQueueHashTable = PL_NewHashTable(3, (PLHashFunction)IntHashKey, PL_CompareValues, PL_CompareValues, 0, 0); } if (!sCountHashTable) { sCountHashTable = PL_NewHashTable(3, (PLHashFunction)IntHashKey, PL_CompareValues, PL_CompareValues, 0, 0); } if (aListen) { /* add listener */ PRInt32 key = aQueue->GetEventQueueSelectFD(); /* only add if we arn't already in the table */ if (!PL_HashTableLookup(sQueueHashTable, GINT_TO_POINTER(key))) { gint tag; tag = our_gdk_input_add(aQueue->GetEventQueueSelectFD(), event_processor_callback, aQueue, G_PRIORITY_HIGH_IDLE); if (tag >= 0) { PL_HashTableAdd(sQueueHashTable, GINT_TO_POINTER(key), GINT_TO_POINTER(tag)); } PLEventQueue *plqueue; aQueue->GetPLEventQueue(&plqueue); PL_RegisterEventIDFunc(plqueue, getNextRequest, 0); sEventQueueList->AppendElement(plqueue); } /* bump up the count */ gint count = GPOINTER_TO_INT(PL_HashTableLookup(sCountHashTable, GINT_TO_POINTER(key))); PL_HashTableAdd(sCountHashTable, GINT_TO_POINTER(key), GINT_TO_POINTER(count+1)); } else { /* remove listener */ PRInt32 key = aQueue->GetEventQueueSelectFD(); PLEventQueue *plqueue; aQueue->GetPLEventQueue(&plqueue); PL_UnregisterEventIDFunc(plqueue); sEventQueueList->RemoveElement(plqueue); gint count = GPOINTER_TO_INT(PL_HashTableLookup(sCountHashTable, GINT_TO_POINTER(key))); if (count - 1 == 0) { gint tag = GPOINTER_TO_INT(PL_HashTableLookup(sQueueHashTable, GINT_TO_POINTER(key))); if (tag > 0) { g_source_remove(tag); PL_HashTableRemove(sQueueHashTable, GINT_TO_POINTER(key)); } } PL_HashTableAdd(sCountHashTable, GINT_TO_POINTER(key), GINT_TO_POINTER(count-1)); } return NS_OK; }
nsresult nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, nsINodeInfo** aNodeInfo) { NS_ASSERTION(!aName.IsEmpty(), "Don't pass an empty string to GetNodeInfo, fix caller."); nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID); void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey); if (node) { nsINodeInfo* nodeInfo = static_cast<nsINodeInfo *>(node); NS_ADDREF(*aNodeInfo = nodeInfo); return NS_OK; } nsRefPtr<nsNodeInfo> newNodeInfo = nsNodeInfo::Create(); NS_ENSURE_TRUE(newNodeInfo, nsnull); nsCOMPtr<nsIAtom> nameAtom = do_GetAtom(aName); nsresult rv = newNodeInfo->Init(nameAtom, aPrefix, aNamespaceID, this); NS_ENSURE_SUCCESS(rv, rv); PLHashEntry *he; he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo); NS_ENSURE_TRUE(he, NS_ERROR_FAILURE); newNodeInfo.forget(aNodeInfo); return NS_OK; }
static BloatEntry* GetBloatEntry(const char* aTypeName, uint32_t aInstanceSize) { if (!gBloatView) { RecreateBloatView(); } BloatEntry* entry = NULL; if (gBloatView) { entry = (BloatEntry*)PL_HashTableLookup(gBloatView, aTypeName); if (entry == NULL && aInstanceSize > 0) { entry = new BloatEntry(aTypeName, aInstanceSize); PLHashEntry* e = PL_HashTableAdd(gBloatView, aTypeName, entry); if (e == NULL) { delete entry; entry = NULL; } } else { NS_ASSERTION(aInstanceSize == 0 || entry->GetClassSize() == aInstanceSize, "bad size recorded"); } } return entry; }
/* * m a n i f e s t o _ x p i _ f n * * Called by pointer from SignArchive(), once for * each file within the directory. This function * is only used for adding to XPI compatible archive * */ static int manifesto_xpi_fn(char *relpath, char *basedir, char *reldir, char *filename, void *arg) { char fullname[FNSIZE]; int count; if (verbosity >= 0) { PR_fprintf(outputFD, "--> %s\n", relpath); } /* extension matching */ if (extensionsGiven) { char *ext = PL_strrchr(relpath, '.'); if (!ext) return 0; if (!PL_HashTableLookup(extensions, ext)) return 0; } count = snprintf(fullname, sizeof(fullname), "%s/%s", basedir, relpath); if (count >= sizeof(fullname)) { return 1; } JzipAdd(fullname, relpath, zipfile, compression_level); return 0; }
PR_IMPLEMENT(nsresult) NS_TimelineMarkTimer(const char *timerName, const char *str) { PR_CallOnce(&initonce, TimelineInit); if (gTimelineDisabled) return NS_ERROR_NOT_AVAILABLE; TimelineThreadData *thread = GetThisThreadData(); if (thread->timers == NULL) return NS_ERROR_FAILURE; if (thread->disabled) return NS_ERROR_NOT_AVAILABLE; nsTimelineServiceTimer *timer = (nsTimelineServiceTimer *)PL_HashTableLookup(thread->timers, timerName); if (timer == NULL) { return NS_ERROR_FAILURE; } PRTime accum = timer->getAccum(); char buf[500]; PRInt32 sec, msec; ParseTime(accum, sec, msec); if (!str) PR_snprintf(buf, sizeof buf, "%s total: %d.%03d", timerName, sec, msec); else PR_snprintf(buf, sizeof buf, "%s total: %d.%03d (%s)", timerName, sec, msec, str); NS_TimelineMark(buf); return NS_OK; }
PR_IMPLEMENT(nsresult) NS_TimelineStopTimer(const char *timerName) { if (gTimelineDisabled) return NS_ERROR_NOT_AVAILABLE; /* * Strange-looking now/timer->stop() interaction is to avoid * including time spent in TLS and PL_HashTableLookup in the * timer. */ PRTime now = Now(); TimelineThreadData *thread = GetThisThreadData(); if (thread->timers == NULL) return NS_ERROR_FAILURE; if (thread->disabled) return NS_ERROR_NOT_AVAILABLE; nsTimelineServiceTimer *timer = (nsTimelineServiceTimer *)PL_HashTableLookup(thread->timers, timerName); if (timer == NULL) { return NS_ERROR_FAILURE; } timer->stop(now); return NS_OK; }
already_AddRefed<nsINodeInfo> nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID) { NS_ENSURE_TRUE(aName, nsnull); NS_ASSERTION(!aName->Equals(EmptyString()), "Don't pass an empty string to GetNodeInfo, fix caller."); nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID); void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey); if (node) { nsINodeInfo* nodeInfo = static_cast<nsINodeInfo *>(node); NS_ADDREF(nodeInfo); return nodeInfo; } nsRefPtr<nsNodeInfo> newNodeInfo = nsNodeInfo::Create(); NS_ENSURE_TRUE(newNodeInfo, nsnull); nsresult rv = newNodeInfo->Init(aName, aPrefix, aNamespaceID, this); NS_ENSURE_SUCCESS(rv, nsnull); PLHashEntry *he; he = PL_HashTableAdd(mNodeInfoHash, &newNodeInfo->mInner, newNodeInfo); NS_ENSURE_TRUE(he, nsnull); nsNodeInfo *nodeInfo = nsnull; newNodeInfo.swap(nodeInfo); return nodeInfo; }
static BloatEntry* GetBloatEntry(const char* aTypeName, uint32_t aInstanceSize) { if (!gBloatView) { RecreateBloatView(); } BloatEntry* entry = nullptr; if (gBloatView) { entry = (BloatEntry*)PL_HashTableLookup(gBloatView, aTypeName); if (!entry && aInstanceSize > 0) { entry = new BloatEntry(aTypeName, aInstanceSize); PLHashEntry* e = PL_HashTableAdd(gBloatView, aTypeName, entry); if (!e) { delete entry; entry = nullptr; } } else { #ifdef DEBUG static const char kMismatchedSizesMessage[] = "Mismatched sizes were recorded in the memory leak logging table. " "The usual cause of this is having a templated class that uses " "MOZ_COUNT_{C,D}TOR in the constructor or destructor, respectively. " "As a workaround, the MOZ_COUNT_{C,D}TOR calls can be moved to a " "non-templated base class."; NS_ASSERTION(aInstanceSize == 0 || entry->GetClassSize() == aInstanceSize, kMismatchedSizesMessage); #endif } } return entry; }
NS_IMETHODIMP nsTopProgressManager::OnStopBinding(const URL_Struct* url, PRInt32 status, const char* message) { PR_ASSERT(url); if (! url) return NS_ERROR_NULL_POINTER; TRACE_PROGRESS(("OnStatus(%s, %d, %s)\n", url->address, status, message)); PR_ASSERT(fURLs); if (! fURLs) return NS_ERROR_NULL_POINTER; nsTransfer* transfer = (nsTransfer*) PL_HashTableLookup(fURLs, url); PR_ASSERT(transfer); if (!transfer) return NS_ERROR_NULL_POINTER; transfer->MarkComplete(status); transfer->SetStatus(message); return NS_OK; }
void tmTransactionService::OnDetachReply(tmTransaction *aTrans) { tm_queue_mapping *qmap = GetQueueMap(aTrans->GetQueueID()); // get the observer before we release the hashtable entry ipcITransactionObserver *observer = (ipcITransactionObserver *)PL_HashTableLookup(mObservers, qmap->joinedQueueName); // if it was removed, clean up if (aTrans->GetStatus() >= 0) { // remove the link between observer and queue PL_HashTableRemove(mObservers, qmap->joinedQueueName); // remove the mapping of queue names and id mQueueMaps.Remove(qmap); delete qmap; } // notify the observer -- could be didn't detach if (observer) observer->OnDetachReply(aTrans->GetQueueID(), aTrans->GetStatus()); }
NS_IMETHODIMP nsTopProgressManager::OnProgress(const URL_Struct* url, PRUint32 bytesReceived, PRUint32 contentLength) { // Some sanity checks... PR_ASSERT(url); if (! url) return NS_ERROR_NULL_POINTER; TRACE_PROGRESS(("OnProgress(%s, %ld, %ld)\n", url->address, bytesReceived, contentLength)); PR_ASSERT(fURLs); if (! fURLs) return NS_ERROR_NULL_POINTER; nsTransfer* transfer = (nsTransfer*) PL_HashTableLookup(fURLs, url); PR_ASSERT(transfer); if (!transfer) return NS_ERROR_NULL_POINTER; transfer->SetProgress(bytesReceived, contentLength); return NS_OK; }
void *thread_main(void *arg ) { /* BUG! If the following line is uncommented, a race is NOT detected */ PL_HashTableLookup(g_hash, ""); g_cache_misses ++; return 0; }
/* if vs is given, delete only those values - otherwise, delete all values */ void replica_updatedn_list_delete(ReplicaUpdateDNList list, const Slapi_ValueSet *vs) { PLHashTable *hash = list; if (!vs || slapi_valueset_count(vs) == 0) { /* just delete everything */ PL_HashTableEnumerateEntries(hash, replica_destroy_hash_entry, NULL); } else { Slapi_ValueSet *vs_nc = (Slapi_ValueSet *)vs; /* cast away const */ Slapi_Value *val = NULL; int index = 0; for (index = slapi_valueset_first_value(vs_nc, &val); val; index = slapi_valueset_next_value(vs_nc, index, &val)) { Slapi_DN *dn = slapi_sdn_new_dn_byval(slapi_value_get_string(val)); /* locate object */ Slapi_DN *deldn = (Slapi_DN *)PL_HashTableLookup(hash, slapi_sdn_get_ndn(dn)); if (deldn == NULL) { slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "replica_updatedn_list_delete -" "Update DN with value (%s) is not in the update DN list.\n", slapi_sdn_get_ndn(dn)); } else { /* remove from hash */ PL_HashTableRemove(hash, slapi_sdn_get_ndn(dn)); /* free the pointer */ slapi_sdn_free(&deldn); } /* free the temp dn */ slapi_sdn_free(&dn); } } return; }
void tmTransactionService::OnAttachReply(tmTransaction *aTrans) { // if we attached, store the queue's ID if (aTrans->GetStatus() >= 0) { PRUint32 size = mQueueMaps.Size(); tm_queue_mapping *qmap = nsnull; for (PRUint32 index = 0; index < size; index++) { qmap = (tm_queue_mapping*) mQueueMaps[index]; if (qmap && PL_strcmp(qmap->joinedQueueName, (char*) aTrans->GetMessage()) == 0) { // set the ID in the mapping qmap->queueID = aTrans->GetQueueID(); // send any stored messges to the queue DispatchStoredMessages(qmap); } } } // notify the observer we have attached (or didn't) ipcITransactionObserver *observer = (ipcITransactionObserver *)PL_HashTableLookup(mObservers, (char*)aTrans->GetMessage()); if (observer) observer->OnAttachReply(aTrans->GetQueueID(), aTrans->GetStatus()); }
PR_IMPLEMENT(nsresult) NS_TimelineStartTimer(const char *timerName) { PR_CallOnce(&initonce, TimelineInit); if (gTimelineDisabled) return NS_ERROR_NOT_AVAILABLE; TimelineThreadData *thread = GetThisThreadData(); if (thread->timers == NULL) return NS_ERROR_FAILURE; if (thread->disabled) return NS_ERROR_NOT_AVAILABLE; nsTimelineServiceTimer *timer = (nsTimelineServiceTimer *)PL_HashTableLookup(thread->timers, timerName); if (timer == NULL) { timer = new nsTimelineServiceTimer; if (!timer) return NS_ERROR_OUT_OF_MEMORY; PL_HashTableAdd(thread->timers, timerName, timer); } timer->start(); return NS_OK; }
void tmTransactionService::OnFlushReply(tmTransaction *aTrans) { ipcITransactionObserver *observer = (ipcITransactionObserver *)PL_HashTableLookup(mObservers, GetJoinedQueueName(aTrans->GetQueueID())); if (observer) observer->OnFlushReply(aTrans->GetQueueID(), aTrans->GetStatus()); }
void tmTransactionService::OnPost(tmTransaction *aTrans) { ipcITransactionObserver *observer = (ipcITransactionObserver*) PL_HashTableLookup(mObservers, GetJoinedQueueName(aTrans->GetQueueID())); if (observer) observer->OnTransactionAvailable(aTrans->GetQueueID(), aTrans->GetMessage(), aTrans->GetMessageLength()); }
SKERR SetValue(const char* pKey, const char* pValue) { char * pOldValue; if((pOldValue = (char*) PL_HashTableLookup(m_pHash, pKey))) { PL_HashTableRemove(m_pHash, pKey); } char* pHashKey = PL_strdup(pKey); char* pHashValue = PL_strdup(pValue); PL_HashTableAdd(m_pHash, pHashKey, pHashValue); return noErr; }
SKERR ImportValue(const char *pszKey, const char *pszSystemKey, PRBool bForce) { char *pszValue; if(!bForce) { pszValue = (char *)PL_HashTableLookup(m_pHash, pszKey); if(pszValue) return noErr; } return LoadEnvirFromIni(pszSystemKey); }
nsHttpAuthNode * nsHttpAuthCache::LookupAuthNode(const char *scheme, const char *host, PRInt32 port, nsCString &key) { if (!mDB) return nsnull; GetAuthKey(scheme, host, port, key); return (nsHttpAuthNode *) PL_HashTableLookup(mDB, key.get()); }
SKERR GetValue(const char* pKey, char **pValue) { *pValue = (char *)PL_HashTableLookup(m_pHash, pKey); if(*pValue) { *pValue = PL_strdup(*pValue); } else *pValue = PL_strdup(""); return noErr; }
NS_IMETHODIMP nsLocale::GetCategory(const nsAString& category, nsAString& result) { const PRUnichar *value = (const PRUnichar*) PL_HashTableLookup(fHashtable, PromiseFlatString(category).get()); if (value) { result.Assign(value); return NS_OK; } return NS_ERROR_FAILURE; }
nsHttpAuthNode * nsHttpAuthCache::LookupAuthNode(const char *scheme, const char *host, int32_t port, nsACString const &originSuffix, nsCString &key) { if (!mDB) return nullptr; GetAuthKey(scheme, host, port, originSuffix, key); return (nsHttpAuthNode *) PL_HashTableLookup(mDB, key.get()); }
nsHttpAuthNode * nsHttpAuthCache::LookupAuthNode(const char *scheme, const char *host, int32_t port, uint32_t appId, bool inBrowserElement, nsCString &key) { if (!mDB) return nullptr; GetAuthKey(scheme, host, port, appId, inBrowserElement, key); return (nsHttpAuthNode *) PL_HashTableLookup(mDB, key.get()); }
/* * nssHash_Lookup * */ NSS_IMPLEMENT void * nssHash_Lookup ( nssHash *hash, const void *it ) { void *rv; PZ_Lock(hash->mutex); rv = PL_HashTableLookup(hash->plHashTable, it); (void)PZ_Unlock(hash->mutex); return rv; }
HRESULT CNode::FindFromDOMNode(nsIDOMNode *pIDOMNode, CNode **pNode) { if (pIDOMNode == nsnull) { return E_FAIL; } if (g_NodeLookupTable == NULL) { return E_FAIL; } nsCOMPtr<nsISupports> nodeAsSupports = do_QueryInterface(pIDOMNode); *pNode = (CNode *) PL_HashTableLookup(g_NodeLookupTable, nodeAsSupports); return S_OK; }
RDF_Resource hostUnitOfURL (RDF r, RDF_Resource top, RDF_Resource nu, char* title) { char host[100]; char* url = resourceID(nu); int16 s1, s2, s3; RDF_Resource hostResource, existing; if (strlen(url) > 100) return NULL; if (startsWith("file", url)) { return RDF_GetResource(NULL, "Local Files", 1); } else { memset(host, '\0', 100); s1 = charSearch(':', url)+3; s2 = charSearch('/', &url[s1]); s3 = charSearch(':', &url[s1]); if (s2 == -1) s2 = strlen(url)-s1; if ((s3 != -1) && (s2 > s3)) s2 = s3; if (startsWith("www", &url[s1])) {s1 = s1+4; s2 = s2-4;} if (s2<1) return(NULL); memcpy((char*)host, &url[s1], s2); host[0] = toupper(host[0]); hostResource = RDF_GetResource(NULL, host, 1); setContainerp(hostResource, 1); setResourceType(hostResource, HISTORY_RT); existing = PL_HashTableLookup(hostHash, hostResource); if (existing != NULL) { if (existing == nu) { return existing; } else if (existing == top) { return hostResource; } else { remoteStoreRemove(gRemoteStore, existing, gCoreVocab->RDF_parent, top, RDF_RESOURCE_TYPE); histAddParent(existing, hostResource); histAddParent(hostResource, top); PL_HashTableAdd(hostHash, hostResource, top); return hostResource; } } else { PL_HashTableAdd(hostHash, hostResource, nu); histAddParent(nu, top); return nu; } } }
PR_IMPLEMENT(nsresult) NS_TimelineResetTimer(const char *timerName) { if (gTimelineDisabled) return NS_ERROR_NOT_AVAILABLE; TimelineThreadData *thread = GetThisThreadData(); if (thread->timers == NULL) return NS_ERROR_FAILURE; if (thread->disabled) return NS_ERROR_NOT_AVAILABLE; nsTimelineServiceTimer *timer = (nsTimelineServiceTimer *)PL_HashTableLookup(thread->timers, timerName); if (timer == NULL) { return NS_ERROR_FAILURE; } timer->reset(); return NS_OK; }
/* * nssCKFWHash_Lookup * */ NSS_IMPLEMENT void * nssCKFWHash_Lookup ( nssCKFWHash *hash, const void *it ) { void *rv; if( CKR_OK != nssCKFWMutex_Lock(hash->mutex) ) { return (void *)NULL; } rv = PL_HashTableLookup(hash->plHashTable, it); (void)nssCKFWMutex_Unlock(hash->mutex); return rv; }
/* * add a list of dns to the ReplicaUpdateDNList. * The dn could be the dn of a group, so get the entry * and check the objectclass. If it is a static or dynamic group * generate the list of member dns and recursively call * replica_updatedn_list_add(). * The dn of the group is added to the list, so it will detect * potential circular group definitions */ void replica_updatedn_list_add_ext(ReplicaUpdateDNList list, const Slapi_ValueSet *vs, int group_update) { PLHashTable *hash = list; Slapi_ValueSet *vs_nc = (Slapi_ValueSet *)vs; /* cast away const */ Slapi_Value *val = NULL; int index = 0; PR_ASSERT(list && vs); for (index = slapi_valueset_first_value(vs_nc, &val); val; index = slapi_valueset_next_value(vs_nc, index, &val)) { Slapi_DN *dn = slapi_sdn_new_dn_byval(slapi_value_get_string(val)); const char *ndn = slapi_sdn_get_ndn(dn); /* make sure that the name is unique */ if (PL_HashTableLookup(hash, ndn) != NULL) { slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "replica_updatedn_list_add - " "Update DN with value (%s) already in the update DN list\n", ndn); slapi_sdn_free(&dn); } else { Slapi_ValueSet *members = NULL; PL_HashTableAdd(hash, ndn, dn); /* add it, even if it is a group dn, this will * prevent problems with circular group definitions * then check if it has mor members to add */ if (group_update) { members = replica_updatedn_list_get_members(dn); if (members) { replica_updatedn_list_add_ext(list, members, 1); /* free members */ slapi_valueset_free(members); } } } } return; }