mget_iri_t *blacklist_add(mget_iri_t *iri) { if (!iri) return NULL; if (mget_iri_supported(iri)) { mget_thread_mutex_lock(&mutex); if (!blacklist) { blacklist = mget_hashmap_create(128, -2, (unsigned int(*)(const void *))hash_iri, (int(*)(const void *, const void *))mget_iri_compare); mget_hashmap_set_destructor(blacklist, (void(*)(void *, void *))_free_entry); } if (!mget_hashmap_contains(blacklist, iri)) { // info_printf("Add to blacklist: %s\n",iri->uri); mget_hashmap_put_noalloc(blacklist, iri, NULL); // use hashmap as a hashset (without value) mget_thread_mutex_unlock(&mutex); return iri; } mget_thread_mutex_unlock(&mutex); } mget_iri_free(&iri); return NULL; }
void mget_ocsp_db_add_host(mget_ocsp_db_t *ocsp_db, mget_ocsp_t *ocsp) { if (!ocsp) return; if (!ocsp_db) { mget_ocsp_free(ocsp); return; } mget_thread_mutex_lock(&ocsp_db->mutex); if (ocsp->maxage == 0) { if (mget_hashmap_remove(ocsp_db->hosts, ocsp)) debug_printf("removed OCSP host %s\n", ocsp->key); mget_ocsp_free(ocsp); } else { mget_ocsp_t *old = mget_hashmap_get(ocsp_db->hosts, ocsp); if (old) { if (old->mtime < ocsp->mtime) { old->mtime = ocsp->mtime; old->maxage = ocsp->maxage; old->valid = ocsp->valid; debug_printf("update OCSP host %s (maxage=%ld)\n", old->key, old->maxage); } mget_ocsp_free(ocsp); } else { // key and value are the same to make mget_hashmap_get() return old 'ocsp' mget_hashmap_put_noalloc(ocsp_db->hosts, ocsp, ocsp); debug_printf("add OCSP host %s (maxage=%ld)\n", ocsp->key, ocsp->maxage); // no need to free anything here } } mget_thread_mutex_unlock(&ocsp_db->mutex); }
int mget_stringmap_put_noalloc(mget_stringmap_t *h, const char *key, const void *value) { return mget_hashmap_put_noalloc(h, key, value); }