int mget_ocsp_hostname_is_valid(const mget_ocsp_db_t *ocsp_db, const char *hostname) { if (ocsp_db) { mget_ocsp_t ocsp, *ocspp; // look for an exact match ocsp.key = hostname; if ((ocspp = mget_hashmap_get(ocsp_db->hosts, &ocsp)) && ocspp->maxage >= time(NULL)) { return 1; } } return 0; }
int mget_ocsp_fingerprint_in_cache(const mget_ocsp_db_t *ocsp_db, const char *fingerprint, int *revoked) { if (ocsp_db) { mget_ocsp_t ocsp, *ocspp; // look for an exact match ocsp.key = fingerprint; if ((ocspp = mget_hashmap_get(ocsp_db->fingerprints, &ocsp)) && ocspp->maxage >= time(NULL)) { if (revoked) *revoked = !ocspp->valid; return 1; } } return 0; }
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); }
void *mget_stringmap_get(const mget_stringmap_t *h, const char *key) { return mget_hashmap_get(h, key); }