Пример #1
0
void wget_bar_slot_downloaded(wget_bar_t *bar, int slot, size_t nbytes)
{
	wget_thread_mutex_lock(&bar->mutex);
	bar->slots[slot].bytes_downloaded = nbytes;
	bar->slots[slot].redraw = 1;
	wget_thread_mutex_unlock(&bar->mutex);
}
Пример #2
0
void wget_ocsp_db_deinit(wget_ocsp_db_t *ocsp_db)
{
	if (ocsp_db) {
		wget_thread_mutex_lock(&ocsp_db->mutex);
		wget_hashmap_free(&ocsp_db->fingerprints);
		wget_hashmap_free(&ocsp_db->hosts);
		wget_thread_mutex_unlock(&ocsp_db->mutex);
	}
}
Пример #3
0
/**
 * \param[in] seed Value to seed the random generator
 *
 * This functions wraps around srandom_r() to make a thread-safe seeding for wget_random().
 */
void wget_srandom(unsigned int seed)
{
	wget_thread_mutex_lock(&mutex);

	initstate_r(seed, statebuf, sizeof(statebuf), &state);
	seeded = 1;

	wget_thread_mutex_unlock(&mutex);
}
Пример #4
0
void wget_bar_slot_deregister(wget_bar_t *bar, int slot)
{
	wget_thread_mutex_lock(&bar->mutex);
	_bar_slot_t *slotp = &bar->slots[slot];

	slotp->status = COMPLETE;
	_bar_update_slot(bar, slot);
	wget_thread_mutex_unlock(&bar->mutex);
}
Пример #5
0
void wget_bar_print(wget_bar_t *bar, int slot, const char *s)
{
	wget_thread_mutex_lock(&bar->mutex);
	_bar_print_slot(bar, slot);
	// CSI <n> G: Cursor horizontal absolute
	printf("\033[27G[%-*.*s]", bar->max_width, bar->max_width, s);
	_restore_cursor_position();
	fflush(stdout);
	wget_thread_mutex_unlock(&bar->mutex);
}
Пример #6
0
void wget_bar_slot_begin(wget_bar_t *bar, int slot, const char *filename, ssize_t file_size)
{
	wget_thread_mutex_lock(&bar->mutex);
	_bar_slot_t *slotp = &bar->slots[slot];

	xfree(slotp->filename);
	slotp->filename = wget_strdup(filename);
	slotp->tick = 0;
	slotp->file_size = file_size;
	slotp->bytes_downloaded = 0;
	slotp->status = DOWNLOADING;
	slotp->redraw = 1;
	wget_thread_mutex_unlock(&bar->mutex);
}
Пример #7
0
void wget_bar_set_slots(wget_bar_t *bar, int nslots)
{
	wget_thread_mutex_lock(&bar->mutex);
	int more_slots = nslots - bar->nslots;

	if (more_slots > 0) {
		// CSI <n>S: Scroll up whole screen
		printf("\033[%dS", more_slots);

		bar->nslots = nslots;
		_bar_update(bar);
	}
	wget_thread_mutex_unlock(&bar->mutex);
}
Пример #8
0
void wget_bar_write_line(wget_bar_t *bar, const char *buf, size_t len)
{
	wget_thread_mutex_lock(&bar->mutex);
	// CSI s:    Save cursor
	// CSI <n>S: Scroll up whole screen
	// CSI <n>A: Cursor up
	// CSI <n>G: Cursor horizontal absolute
	// CSI 0J:   Clear from cursor to end of screen
	// CSI 31m:  Red text color
	printf("\033[s\033[1S\033[%dA\033[1G\033[0J\033[31m", bar->nslots + 1);
	fwrite(buf, 1, len, stdout);
	printf("\033[m"); // reset text color
	_restore_cursor_position();

	_bar_update(bar);
	wget_thread_mutex_unlock(&bar->mutex);
}
Пример #9
0
/**
 * \return Random value between 0 and RAND_MAX
 *
 * This functions wraps around gnulib's random_r(). It performs a thread-safe seeding on the first use,
 * if not done before by wget_srandom();
 */
int wget_random(void)
{
	int32_t r;

	wget_thread_mutex_lock(&mutex);

	if (!seeded) {
		// seed random generator, used e.g. by Digest Authentication and --random-wait
		initstate_r((unsigned)(time(NULL) ^ getpid()), statebuf, sizeof(statebuf), &state);
		seeded = 1;
	}

	if (random_r(&state, &r))
		r = 0; // return 0 on failure

	wget_thread_mutex_unlock(&mutex);

	return (int)r;
}
Пример #10
0
void wget_ocsp_db_add_host(wget_ocsp_db_t *ocsp_db, wget_ocsp_t *ocsp)
{
	if (!ocsp)
		return;

	if (!ocsp_db) {
		wget_ocsp_free(ocsp);
		return;
	}

	wget_thread_mutex_lock(&ocsp_db->mutex);

	if (ocsp->maxage == 0) {
		if (wget_hashmap_remove(ocsp_db->hosts, ocsp))
			debug_printf("removed OCSP host %s\n", ocsp->key);
		wget_ocsp_free(ocsp);
	} else {
		wget_ocsp_t *old = wget_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);
			}
			wget_ocsp_free(ocsp);
		} else {
			// key and value are the same to make wget_hashmap_get() return old 'ocsp'
			wget_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
		}
	}

	wget_thread_mutex_unlock(&ocsp_db->mutex);
}
Пример #11
0
void wget_bar_update(wget_bar_t *bar)
{
	wget_thread_mutex_lock(&bar->mutex);
	_bar_update(bar);
	wget_thread_mutex_unlock(&bar->mutex);
}