Example #1
0
wget_metalink_t *wget_metalink_parse(const char *xml)
{
	wget_metalink_t *metalink = xcalloc(1, sizeof(wget_metalink_t));
	_metalink_context_t ctx = { .metalink = metalink, .priority = 999999, .location = "-" };

	wget_xml_parse_buffer(xml, _metalink_parse, &ctx, 0);
	return metalink;
}

void wget_metalink_free(wget_metalink_t **metalink)
{
	if (metalink && *metalink) {
		xfree((*metalink)->name);
		wget_vector_free(&(*metalink)->mirrors);
		wget_vector_free(&(*metalink)->hashes);
		wget_vector_free(&(*metalink)->pieces);
		xfree(*metalink);
	}
}

static int G_GNUC_WGET_PURE _compare_mirror(wget_metalink_mirror_t **m1, wget_metalink_mirror_t **m2)
{
	return (*m1)->priority - (*m2)->priority;
}

void wget_metalink_sort_mirrors(wget_metalink_t *metalink)
{
	if (metalink) {
		wget_vector_setcmpfunc(metalink->mirrors, (int(*)(const void *, const void *))_compare_mirror);
		wget_vector_sort(metalink->mirrors);
	}
}
Example #2
0
void job_free(JOB *job)
{
	wget_http_free_challenges(&job->challenges);
	wget_metalink_free(&job->metalink);
	wget_vector_free(&job->parts);
	xfree(job->local_filename);
}
Example #3
0
static void test_vector(void)
{
	struct ENTRY
		*tmp,
		txt_sorted[5] = { {""}, {"four"}, {"one"}, {"three"}, {"two"} },
		*txt[countof(txt_sorted)];
	wget_vector_t
		*v = wget_vector_create(2, -2, (int(*)(const void *, const void *))compare_txt);
	unsigned
		it;
	int
		n;

	// copy
	for (it = 0; it < countof(txt); it++)
		txt[it] = &txt_sorted[it];

	// shuffle txt
	for (it = 0; it < countof(txt); it++) {
		n = rand() % countof(txt);
		tmp = txt[n];
		txt[n] = txt[it];
		txt[it] = tmp;
	}

	for (it = 0; it < countof(txt); it++) {
		wget_vector_insert_sorted(v, txt[it], sizeof(struct ENTRY));
	}

	for (it = 0; it < countof(txt); it++) {
		struct ENTRY *e = wget_vector_get(v, it);
		if (!strcmp(e->txt,txt_sorted[it].txt))
			ok++;
		else
			failed++;
	}

	wget_vector_free(&v);
}