示例#1
0
stringer_t * check_rand_mthread(void) {

	void *outcome = NULL;
	stringer_t *result = NULL;
	pthread_t *threads = NULL;

	if (!RAND_CHECK_MTHREADS) {
		return NULL;
	}
	else if (!(threads = mm_alloc(sizeof(pthread_t) * RAND_CHECK_MTHREADS))) {
		return st_dupe(NULLER("Thread allocation error."));;
	}

	for (uint64_t counter = 0; counter < RAND_CHECK_MTHREADS; counter++) {
		if (thread_launch(threads + counter, &check_rand_mthread_wrap, NULL)) {
			result = false;
		}
	}

	for (uint64_t counter = 0; counter < RAND_CHECK_MTHREADS; counter++) {
		if (thread_result(*(threads + counter), &outcome)) {
			st_cleanup(result);
			result = st_dupe(NULLER("Thread join error."));
		}
		else if (outcome) {
			st_cleanup(result);
			result = outcome;
		}
	}

	mm_free(threads);
	return result;
}
示例#2
0
bool_t check_string_dupe(uint32_t check) {

	size_t len;
	stringer_t *s, *d;

	if (!(s = st_alloc_opts(check, st_length_int(string_check_constant)))) {
		return false;
	}

	len = snprintf(st_char_get(s), st_length_int(string_check_constant) + 1, "%.*s", st_length_int(string_check_constant), st_char_get(string_check_constant));
	if ((check & MAPPED_T) || (check & MANAGED_T)) {
		st_length_set(s, len);
	}

	if (!(d = st_dupe(s))) {
		st_free(s);
		return false;
	}

	if (memcmp(st_char_get(d), st_char_get(s), st_length_get(s))) {
		st_free(s);
		st_free(d);
		return false;
	}

	st_free(s);
	st_free(d);

	return true;
}
示例#3
0
bool_t check_string_dupe(char *type, uint32_t check) {

	size_t len;
	stringer_t *s, *d;

	if (!(s = st_alloc(check, st_length_int(constant)))) {
		return false;
	}

	len = snprintf(st_char_get(s), st_length_int(constant) + 1, "%.*s", st_length_int(constant), st_char_get(constant));
	if (check & MAPPED_T || check & MANAGED_T) {
		st_length_set(s, len);
	}

	if (!(d = st_dupe(s))) {
		st_free(s);
		return false;
	}

	log_print("%28.28s = %.*s", type, st_length_int(d), st_char_get(d));

	if (memcmp(st_char_get(d), st_char_get(s), st_length_get(s))) {
		st_free(s);
		st_free(d);
		return false;
	}

	st_free(s);
	st_free(d);

	return true;
}
示例#4
0
stringer_t * check_rand_sthread(void) {

	size_t len;
	uint64_t num = 0;
	stringer_t *buffer;

	if (!(buffer = st_alloc(RAND_CHECK_SIZE_MAX))) {
		return st_dupe(NULLER("Buffer allocation error."));
	}

	for (int_t i = 0; status() && i < RAND_CHECK_ITERATIONS; i++) {

		num |= rand_get_int8();
		num |= rand_get_int16();
		num |= rand_get_int32();
		num |= rand_get_int64();

		num |= rand_get_uint8();
		num |= rand_get_uint16();
		num |= rand_get_uint32();
		num |= rand_get_uint64();

		// Pick a random length.
		len = (rand() % (RAND_CHECK_SIZE_MAX - RAND_CHECK_SIZE_MIN)) + RAND_CHECK_SIZE_MIN;

		if (rand_write(PLACER(st_char_get(buffer), len)) != len) {
			st_cleanup(buffer);
			return st_dupe(NULLER("Unable to fill the buffer with random data."));
		}
	}

	st_cleanup(buffer);

	// This time through we use the choices function since it will allocate its own output buffer.
	for (int_t i = 0; status() && i < RAND_CHECK_ITERATIONS; i++) {

		// Pick a random length.
		len = (rand() % (RAND_CHECK_SIZE_MAX - RAND_CHECK_SIZE_MIN)) + RAND_CHECK_SIZE_MIN;

		if (!(buffer = rand_choices("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", len))) {
			return st_dupe(NULLER("Unable to fill the buffer with random data."));
		}
		st_free(buffer);
	}

	return NULL;
}
示例#5
0
文件: cache.c 项目: lavabit/magma
/**
 * @brief	Attempt to retrieve the contents of a message from the thread's cached data.
 * @note	The thread's cache only has the capacity to store a single message.
 * @param	messagenum		the id of the message to be retrieved.
 * @return	NULL on failure or a managed string containing the message data on success.
 */
stringer_t * mail_cache_get(uint64_t messagenum) {

	mail_cache_t *message;

	if (!(message = pthread_getspecific(mail_cache))) {
		return NULL;
	}

	if (message->messagenum == messagenum) {
		return st_dupe(message->text);
	}

	return NULL;
}
示例#6
0
void check_rand_mthread_wrap(void) {

	stringer_t *result = NULL;

	if (!thread_start()) {
		log_error("Unable to setup the thread context.");
		pthread_exit(st_dupe(NULLER("Thread startup error.")));
		return;
	}

	result = check_rand_sthread();

	thread_stop();
	pthread_exit(result);
	return;
}
示例#7
0
/**
 * @brief	Add an entry to an SMTP session's recipients list for outbound/relayed mail.
 * @note	If the recipients list does not exist, it will be created automatically.
 * @param	con		the SMTP client connection specifying the added recipient.
 * @param	address	a managed string containing the recipient's email address.
 * @return	true if the requested recipient was added successfully to the recipients list, or false on failure.
 */
bool_t smtp_add_recipient(connection_t *con, stringer_t *address) {

	smtp_recipients_t *append;
	smtp_recipients_t *holder;

	if (!con->smtp.out_prefs) {
		log_pedantic("A NULL outbound preferences pointer found.");
		return false;
	}
	else if (!(append = mm_alloc(sizeof(smtp_recipients_t)))) {
		log_pedantic("Unable to allocate %zu bytes.", sizeof(smtp_recipients_t));
		return false;
	}
	else if (!(append->address = st_dupe(address))) {
		log_pedantic("Unable to duplicate the address.");
		mm_free(append);
		return false;
	}

	if (!con->smtp.out_prefs->recipients) {
		con->smtp.out_prefs->recipients = append;
	}
	else {
		holder = con->smtp.out_prefs->recipients;

		while (holder->next) {
			holder = (smtp_recipients_t *)holder->next;
		}

		holder->next = (struct smtp_recipients_t *)append;
	}

	con->smtp.num_recipients++;

	return true;
}