Esempio n. 1
0
File: ocsp.c Progetto: BIllli/mget
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);
}
Esempio n. 2
0
int mget_stringmap_remove(mget_stringmap_t *h, const char *key)
{
	return mget_hashmap_remove(h, key);
}