Example #1
0
File: ocsp.c Project: BIllli/mget
static int _ocsp_db_save(mget_hashmap_t *map, const char *fname, int save_hosts)
{
	FILE *fp;
	int ret = -1, size;

	if ((size = mget_hashmap_size(map)) <= 0)
		return -1;

	if ((fp = fopen(fname, "w"))) {
		fputs("#OCSP 1.0 file\n", fp);
		fputs("#Generated by Mget " PACKAGE_VERSION ". Edit at your own risk.\n", fp);
		if (save_hosts) {
			fputs("<hostname> <time_t maxage> <time_t mtime>\n\n", fp);
			mget_hashmap_browse(map, (int(*)(void *, const void *, void *))_ocsp_save_host, fp);
		} else {
			fputs("<sha256 fingerprint of cert> <time_t maxage> <time_t mtime> <valid>\n\n", fp);
			mget_hashmap_browse(map, (int(*)(void *, const void *, void *))_ocsp_save_entry, fp);
		}

		if (!ferror(fp))
			ret = 0;

		if (fclose(fp))
			ret = -1;

		if (ret)
			error_printf(_("Failed to write to OCSP file '%s' (%d)\n"), fname, errno);
		else
			debug_printf(_("saved %d OCSP entr%s into '%s'\n"), size, size != 1 ? "ies" : "y", fname);
	} else
		error_printf(_("Failed to open OCSP file '%s' (%d)\n"), fname, errno);

	return ret;
}
Example #2
0
int mget_stringmap_browse(const mget_stringmap_t *h, int (*browse)(void *ctx, const char *key, void *value), void *ctx)
{
	return mget_hashmap_browse(h, (int (*)(void *, const void *, void *))browse, ctx);
}
Example #3
0
void blacklist_print(void)
{
	mget_thread_mutex_lock(&mutex);
	mget_hashmap_browse(blacklist, (int(*)(void *, const void *, void *))_blacklist_print, NULL);
	mget_thread_mutex_unlock(&mutex);
}