Beispiel #1
0
wr_window_t * wr_window_init_with_chat(wr_window_t *window, wr_chat_t *chat) {
	window = wr_window_init(window);

	window->type		= WR_WINDOW_TYPE_CHAT;
	window->chat		= wi_retain(chat);
	
	return window;
}
Beispiel #2
0
wr_window_t * wr_window_init_with_user(wr_window_t *window, wr_user_t *user) {
	window = wr_window_init(window);
	
	window->type		= WR_WINDOW_TYPE_USER;
	window->uid			= user->uid;
	window->topic.topic	= wi_retain(user->nick);
	
	return window;
}
Beispiel #3
0
wt_server_t * wt_servers_server_with_key(wi_string_t *key) {
	wt_server_t		*server;
	
	wi_dictionary_rdlock(wt_servers);
	server = wi_autorelease(wi_retain(wi_dictionary_data_for_key(wt_servers, key)));
	wi_dictionary_unlock(wt_servers);
	
	return server;
}
Beispiel #4
0
wr_window_t * wr_window_init_with_user(wr_window_t *window, wr_user_t *user) {
	window = wr_window_init(window);
	
	window->type		= WR_WINDOW_TYPE_USER;
	window->user		= wi_retain(user);
	window->topic		= wr_topic_init_with_user(wr_topic_alloc(), user);
	
	return window;
}
Beispiel #5
0
void wr_transfers_set_download_path(wi_string_t *download_path) {
	if(wi_is_equal(download_path, wr_download_path))
		return;
	
	wi_release(wr_download_path);
	wr_download_path = wi_retain(download_path);
	
	wr_printf_prefix(WI_STR("Using download path %@"), download_path);
}
Beispiel #6
0
wi_regexp_t * wi_config_regexp_for_name(wi_config_t *config, wi_string_t *name) {
	wi_regexp_t		*value;
	
	wi_lock_lock(config->lock);
	value = wi_autorelease(wi_retain(wi_dictionary_data_for_key(config->values, name)));
	wi_lock_unlock(config->lock);
	
	return value;
}
Beispiel #7
0
wd_user_t * wd_users_user_with_uid(wd_uid_t uid) {
	wd_user_t     *user;

	wi_dictionary_rdlock(wd_users);
	user = wi_autorelease(wi_retain(wi_dictionary_data_for_key(wd_users, wi_number_with_int32(uid))));
	wi_dictionary_unlock(wd_users);
	
	return user;
}
Beispiel #8
0
wi_uinteger_t wi_config_port_for_name(wi_config_t *config, wi_string_t *name) {
	wi_number_t		*value;
	
	wi_lock_lock(config->lock);
	value = wi_autorelease(wi_retain(wi_dictionary_data_for_key(config->values, name)));
	wi_lock_unlock(config->lock);
	
	return value ? wi_number_integer(value) : 0;
}
Beispiel #9
0
static void wd_transfer_accept_thread(wi_runtime_instance_t *argument) {
	wi_pool_t			*pool;
	wi_socket_t			*socket = argument;
	wi_array_t			*arguments;
	wi_string_t			*ip, *string, *command;
	wd_transfer_t		*transfer;
	
	pool = wi_pool_init(wi_pool_alloc());
	
	ip = wi_address_string(wi_socket_address(socket));
	
	if(!wi_socket_accept_tls(socket, wd_transfer_socket_tls, 30.0)) {
		wi_log_err(WI_STR("Could not accept a connection for %@: %m"), ip);
		
		goto end;
	}
	
	if(!wi_socket_set_timeout(socket, 30.0))
		wi_log_warn(WI_STR("Could not set timeout for %@: %m"), ip);
	
	string = wi_socket_read_to_string(socket, 5.0, WI_STR(WD_MESSAGE_SEPARATOR_STR));
	
	if(!string || wi_string_length(string) == 0) {
		if(!string)
			wi_log_warn(WI_STR("Could not read from %@: %m"), ip);
		
		goto end;
	}
	
	wi_parse_wired_command(string, &command, &arguments);
	
	if(wi_is_equal(command, WI_STR("TRANSFER")) && wi_array_count(arguments) >= 1) {
		transfer = wd_transfers_transfer_with_hash(WI_ARRAY(arguments, 0));
		
		if(!transfer)
			goto end;
		
		if(!wi_is_equal(ip, wd_user_ip(transfer->user)))
			goto end;
		
		wi_lock_lock(transfer->socket_lock);
		
		if(!transfer->socket) {
			transfer->socket = wi_retain(socket);
			wi_lock_unlock(transfer->socket_lock);
		
			wd_transfer_loop(transfer);
		} else {
			wi_lock_unlock(transfer->socket_lock);
		}
	}

end:
	wi_socket_close(socket);

	wi_release(pool);
}
Beispiel #10
0
static wi_timer_t * _wi_timer_first_timer(void) {
	wi_timer_t		*timer;
	
	wi_array_rdlock(_wi_timers);
	timer = wi_autorelease(wi_retain(wi_array_first_data(_wi_timers)));
	wi_array_unlock(_wi_timers);
	
	return timer;
}
Beispiel #11
0
wd_topic_t * wd_chat_topic(wd_chat_t *chat) {
	wd_topic_t		*topic;
	
	wi_recursive_lock_lock(chat->lock);
	topic = wi_autorelease(wi_retain(chat->topic));
	wi_recursive_lock_unlock(chat->lock);
	
	return topic;
}
Beispiel #12
0
void wr_windows_set_timestamp_format(wi_string_t *timestamp_format) {
	if(wi_is_equal(timestamp_format, wr_timestamp_format))
		return;
	
	wi_release(wr_timestamp_format);
	wr_timestamp_format = wi_retain(timestamp_format);

	wr_printf_prefix(WI_STR("Using timestamp format %@"), wr_timestamp_format);
}
Beispiel #13
0
wd_chat_t * wd_chats_chat_with_cid(wd_cid_t cid) {
	wd_chat_t		*chat;
	
	wi_dictionary_rdlock(wd_chats);
	chat = wi_autorelease(wi_retain(wi_dictionary_data_for_key(wd_chats, wi_number_with_int32(cid))));
	wi_dictionary_unlock(wd_chats);
	
	return chat;
}
Beispiel #14
0
wi_time_interval_t wi_config_time_interval_for_name(wi_config_t *config, wi_string_t *name) {
	wi_number_t		*value;
	
	wi_lock_lock(config->lock);
	value = wi_autorelease(wi_retain(wi_dictionary_data_for_key(config->values, name)));
	wi_lock_unlock(config->lock);
	
	return value ? wi_number_double(value) : 0.0;
}
Beispiel #15
0
void wi_mutable_url_set_host(wi_mutable_url_t *url, wi_string_t *host) {
	WI_RUNTIME_ASSERT_MUTABLE(url);
	
	wi_retain(host);
	wi_release(url->host);
	
	url->host = host;
	
	_wi_url_regenerate_string(url);
}
Beispiel #16
0
void wi_error_set_error_with_string(wi_error_domain_t domain, int code, wi_string_t *string) {
	wi_error_t		*error;

	error			= _wi_error_get_error();
	error->domain	= domain;
	error->code		= code;

	wi_release(error->string);
	error->string = wi_retain(string);
}
Beispiel #17
0
void wi_mutable_url_set_password(wi_mutable_url_t *url, wi_string_t *password) {
	WI_RUNTIME_ASSERT_MUTABLE(url);
	
	wi_retain(password);
	wi_release(url->password);
	
	url->password = password;
	
	_wi_url_regenerate_string(url);
}
Beispiel #18
0
void wi_mutable_url_set_user(wi_mutable_url_t *url, wi_string_t *user) {
	WI_RUNTIME_ASSERT_MUTABLE(url);
	
	wi_retain(user);
	wi_release(url->user);
	
	url->user = user;
	
	_wi_url_regenerate_string(url);
}
Beispiel #19
0
wr_user_t * wr_user_init_with_message(wr_user_t *user, wi_p7_message_t *message) {
	wi_p7_uint32_t		uid;
	wi_p7_boolean_t		idle, admin;
	wi_p7_enum_t		color;
	
	wi_p7_message_get_uint32_for_name(message, &uid, WI_STR("wired.user.id"));
	wi_p7_message_get_bool_for_name(message, &idle, WI_STR("wired.user.idle"));
	wi_p7_message_get_bool_for_name(message, &admin, WI_STR("wired.user.admin"));
	wi_p7_message_get_enum_for_name(message, &color, WI_STR("wired.account.color"));
	
	user->nick		= wi_retain(wi_p7_message_string_for_name(message, WI_STR("wired.user.nick")));
	user->status	= wi_retain(wi_p7_message_string_for_name(message, WI_STR("wired.user.status")));
	user->uid		= uid;
	user->idle		= idle;
	user->admin		= admin;
	user->color		= color;

	return user;
}
Beispiel #20
0
void wi_mutable_url_set_scheme(wi_mutable_url_t *url, wi_string_t *scheme) {
	WI_RUNTIME_ASSERT_MUTABLE(url);
	
	wi_retain(scheme);
	wi_release(url->scheme);
	
	url->scheme = scheme;
	
	_wi_url_regenerate_string(url);
}
Beispiel #21
0
void wi_error_set_openssl_ssl_error_with_result(void *ssl, int result) {
	wi_error_t		*error;
	int				code;
	
	code = SSL_get_error(ssl, result);
	
	if(code == SSL_ERROR_SYSCALL) {
		if(ERR_peek_error() == 0) {
			if(result == 0)
				wi_error_set_libwired_error(WI_ERROR_SOCKET_EOF);
			else
				wi_error_set_errno(errno);
		} else {
			wi_error_set_openssl_error();
		}
	}
	else if(code == SSL_ERROR_SSL) {
		wi_error_set_openssl_error();
	} else {
		error = _wi_error_get_error();
		error->domain = WI_ERROR_DOMAIN_OPENSSL_SSL;
		error->code = code;

		wi_release(error->string);

		switch(error->code) {
			case SSL_ERROR_NONE:
				error->string = wi_retain(WI_STR("SSL: No error"));
				break;

			case SSL_ERROR_ZERO_RETURN:
				error->string = wi_retain(WI_STR("SSL: Zero return"));
				break;
				
			case SSL_ERROR_WANT_READ:
				error->string = wi_retain(WI_STR("SSL: Want read"));
				break;
				
			case SSL_ERROR_WANT_WRITE:
				error->string = wi_retain(WI_STR("SSL: Want write"));
				break;
				
			case SSL_ERROR_WANT_CONNECT:
				error->string = wi_retain(WI_STR("SSL: Want connect"));
				break;
				
			case SSL_ERROR_WANT_ACCEPT:
				error->string = wi_retain(WI_STR("SSL: Want accept"));
				break;
				
			case SSL_ERROR_WANT_X509_LOOKUP:
				error->string = wi_retain(WI_STR("SSL: Want X509 lookup"));
				break;
		}
	}
	
	ERR_clear_error();
}
Beispiel #22
0
static void wd_transfer_create_timer(wd_transfer_t *transfer) {
	transfer->timer = wi_timer_init_with_function(wi_timer_alloc(),
												  wd_transfer_expire_timer,
												  WD_TRANSFERS_WAITING_INTERVAL,
												  false);
	wi_timer_set_data(transfer->timer, transfer);
	wi_timer_schedule(transfer->timer);
	
	wi_retain(transfer);
}
Beispiel #23
0
wi_boolean_t _wi_settings_set_path(wi_settings_t *settings, wi_uinteger_t index, wi_string_t *name, wi_string_t *value) {
	wi_string_t		**string = (wi_string_t **) settings->spec[index].setting;
	
	if(*string)
		wi_release(*string);

	*string = wi_retain(value);
	
	return true;
}
Beispiel #24
0
static wi_process_t * _wi_process_init_with_argv(wi_process_t *process, int argc, const char **argv) {
	wi_array_t			*array;
	wi_string_t			*string;
	struct utsname		name;
#ifdef HAVE_MACH_O_ARCH_H
	const NXArchInfo	*arch_info;
#endif
	
	array = wi_array_init_with_argv(wi_array_alloc(), argc, argv);
	
	string = wi_array_first_data(array);
	
	if(string) {
		process->path = wi_retain(string);
		process->name = wi_retain(wi_string_last_path_component(process->path));
	} else {
		process->path = wi_retain(WI_STR("unknown"));
		process->name = wi_retain(process->path);
	}
	
	if(wi_array_count(array) <= 1)
		process->arguments = wi_array_init(wi_array_alloc());
	else
		process->arguments = wi_retain(wi_array_subarray_with_range(array, wi_make_range(1, wi_array_count(array) - 1)));
	
	wi_release(array);
	
	uname(&name);
	
	process->os_name = wi_string_init_with_cstring(wi_string_alloc(), name.sysname);
	process->os_release = wi_string_init_with_cstring(wi_string_alloc(), name.release);

#ifdef HAVE_MACH_O_ARCH_H
	arch_info = NXGetArchInfoFromCpuType(NXGetLocalArchInfo()->cputype, CPU_SUBTYPE_MULTIPLE);
	
	process->arch = wi_string_init_with_cstring(wi_string_alloc(), arch_info->name);
#else
	process->arch = wi_string_init_with_cstring(wi_string_alloc(), name.machine);
#endif

	return process;
}
Beispiel #25
0
void wr_client_init(void) {
	wr_server_string_encoding = wi_string_encoding_init_with_charset(
		wi_string_encoding_alloc(),
		WI_STR("UTF-8"),
		WI_STRING_ENCODING_IGNORE | WI_STRING_ENCODING_TRANSLITERATE);
	
	wr_client_set_charset(WI_STR("UTF-8"));
	
	wr_nick = wi_retain(wi_user_name());
	wr_icon = wi_data_init_with_base64(wi_data_alloc(), wi_string_with_cstring(wr_default_icon));
}
Beispiel #26
0
static wd_topic_t * wd_topic_init_with_string(wd_topic_t *topic, wi_string_t *string) {
	wd_user_t	*user = wd_users_user_for_thread();
	
	topic->topic	= wi_retain(string);
	topic->date		= wi_date_init(wi_date_alloc());
	topic->nick		= wi_copy(wd_user_nick(user));
	topic->login	= wi_copy(wd_user_login(user));
	topic->ip		= wi_copy(wd_user_ip(user));
	
	return topic;
}
Beispiel #27
0
wi_array_t * wi_array_init_with_string(wi_array_t *array, wi_string_t *string, wi_string_t *separator) {
	if(wi_string_length(string) == 0) {
		array = wi_array_init_with_data(array, WI_STR(""), (void *) NULL);
	} else {
		wi_release(array);
		
		array = wi_retain(wi_string_components_separated_by_string(string, separator));
	}
	
	return array;
}
Beispiel #28
0
static wd_user_t * wd_user_init_with_socket(wd_user_t *user, wi_socket_t *socket) {
	wi_address_t	*address;

	user->uid				= wd_user_next_uid();
	user->socket			= wi_retain(socket);
	user->state				= WD_USER_CONNECTED;
	user->login_time		= wi_time_interval();
	user->idle_time			= user->login_time;
	
	address					= wi_socket_address(socket);
	user->ip				= wi_retain(wi_address_string(address));
	user->host				= wi_retain(wi_address_hostname(address));
	
	user->user_lock			= wi_recursive_lock_init(wi_recursive_lock_alloc());
	user->socket_lock		= wi_lock_init(wi_lock_alloc());
	
	user->transfers_queue	= wi_array_init(wi_array_alloc());

	return user;
}
Beispiel #29
0
static void wr_msg_200(wi_array_t *arguments) {
	wi_string_t		*password;
	double			protocol;
	
	protocol = wi_string_double(wr_protocol_version_string);
	
	wr_server = wr_server_init(wr_server_alloc());
	wr_server->version = wi_retain(WI_ARRAY(arguments, 0));
	wr_server->protocol = wi_string_double(WI_ARRAY(arguments, 1));
	wr_server->name = wi_retain(WI_ARRAY(arguments, 2));
	wr_server->description = wi_retain(WI_ARRAY(arguments, 3));
	wr_server->startdate = wi_date_init_with_rfc3339_string(wi_date_alloc(), WI_ARRAY(arguments, 4));
	wr_server->files = wi_string_uint32(WI_ARRAY(arguments, 5));
	wr_server->size = wi_string_uint64(WI_ARRAY(arguments, 6));

	wr_draw_divider();
	
	if(!wr_logged_in) {
		if(wr_server->protocol > protocol) {
			wr_wprintf_prefix(wr_console_window, WI_STR("Server protocol version %.1f may not be fully compatible with client protocol version %.1f"),
				wr_server->protocol, protocol);
		}

		wr_send_command(WI_STR("CLIENT %#@"), wr_client_version_string);
		wr_send_command(WI_STR("NICK %#@"), wr_nick);
		wr_send_command(WI_STR("STATUS %#@"), wr_status);
		wr_send_command(WI_STR("ICON %u%c%#@"), 0, WR_FIELD_SEPARATOR, wr_icon);
		wr_send_command(WI_STR("USER %#@"), wr_login ? wr_login : WI_STR("guest"));
		
		if(wr_password && wi_string_length(wr_password) > 0)
			password = wi_string_sha1(wr_password);
		else
			password = NULL;

		wr_send_command(WI_STR("PASS %#@"), password);
		
		wr_send_command(WI_STR("WHO %u"), 1);

		wr_logged_in = true;
	}
}
Beispiel #30
0
void wd_trackers_register(wi_boolean_t update) {
	if(wi_array_count(wd_trackers) > 0) {
		wi_release(wd_trackers_guest_account);
		
		wd_trackers_guest_account = wi_retain(wd_accounts_read_user_and_group(WI_STR("guest")));
		
		wi_log_info(WI_STR("Registering with trackers..."));

		if(!wi_thread_create_thread(wd_trackers_register_thread, wi_number_with_bool(update)))
			wi_log_err(WI_STR("Could not create a register thread: %m"));
	}
}