Exemplo n.º 1
0
void wr_client_disconnect(void) {
	if(wr_connected) {
		wr_wprintf_prefix(wr_console_window, WI_STR("Connection to %@ closed"),
			wi_address_string(wi_socket_address(wr_socket)));

		wr_connected = false;
	}
	
	wr_runloop_remove_socket(wr_socket);
	wi_socket_close(wr_socket);
	wi_release(wr_p7_socket);
	wi_release(wr_socket);

	wi_release(wr_server);
	
	wi_release(wr_password);

	wr_windows_clear();
	wr_chats_clear();
	wr_users_clear();

	wr_draw_header();
	wr_draw_divider();
}
Exemplo n.º 2
0
void wd_reply(uint32_t n, wi_string_t *fmt, ...) {
	wd_user_t		*user = wd_users_user_for_thread();
	wi_string_t		*string;
	va_list			ap;
	
	va_start(ap, fmt);
	string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap);
	va_end(ap);
	
	wd_user_lock_socket(user);
	wi_socket_write(wd_user_socket(user), 0.0, WI_STR("%u %@%c"), n, string, WD_MESSAGE_SEPARATOR);
	wd_user_unlock_socket(user);
	
	wi_release(string);
}
Exemplo n.º 3
0
wi_dictionary_t * wi_dictionary_init_with_plist_file(wi_dictionary_t *dictionary, wi_string_t *path) {
	wi_runtime_instance_t	*instance;
	
	wi_release(dictionary);
	
	instance = wi_plist_read_instance_from_file(path);
	
	if(!instance)
		return NULL;
	
	if(wi_runtime_id(instance) != wi_dictionary_runtime_id())
		return NULL;
	
	return wi_retain(instance);
}
Exemplo n.º 4
0
int32_t wi_socket_sendto(wi_socket_t *socket, wi_socket_context_t *context, wi_string_t *fmt, ...) {
	wi_string_t		*string;
	int				bytes;
	va_list			ap;

	va_start(ap, fmt);
	string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap);
	va_end(ap);

	bytes = wi_socket_sendto_buffer(socket, context, wi_string_cstring(string), wi_string_length(string));
	
	wi_release(string);

	return bytes;
}
Exemplo n.º 5
0
wi_terminal_t * wi_terminal_init(wi_terminal_t *terminal) {
	wi_string_t		*type;
	const char		*term;
	
	term = getenv("TERM");
		
	if(!term)
		term = "vt100";
	
	type = wi_string_init_with_cstring(wi_string_alloc(), term);
	terminal = wi_terminal_init_with_type(terminal, type);
	wi_release(type);
	
	return terminal;
}
Exemplo n.º 6
0
void wr_client_reload_icon(void) {
    wi_data_t 		*data;
    wi_string_t 	*icon_path;

    if(wr_icon)
        wi_release(wr_icon), wr_icon = NULL;

    if(wr_icon_path)
        wi_release(wr_icon_path), wr_icon_path = NULL;

    icon_path = wi_config_path_for_name(wd_config, WI_STR("icon path"));

    if(!wi_string_has_prefix(icon_path, WI_STR("/")))
        wr_icon_path = wi_retain(wi_string_by_appending_path_component(wi_string_by_appending_path_component(wi_user_home(), WI_STR(".wirebot")), icon_path));
    else {
        wr_icon_path = wi_retain(icon_path);
    }

    if(wi_fs_path_exists(wr_icon_path, false))	{
        wr_icon = wi_data_init_with_contents_of_file(wi_data_alloc(), wr_icon_path);
    } else {
        wr_icon = wi_data_init_with_base64(wi_data_alloc(), wi_string_with_cstring(wr_default_icon));
    }
}
Exemplo n.º 7
0
static void _wi_list_dealloc(wi_runtime_instance_t *instance) {
	wi_list_t		*list = instance;
	uint32_t		i;

	wi_list_remove_all_data(list);

	if(list->node_chunks) {
		for(i = 0; i < list->node_chunks_count; i++)
			wi_free(list->node_chunks[i]);

		wi_free(list->node_chunks);
	}

	wi_release(list->lock);
}
Exemplo n.º 8
0
wi_socket_t * wi_socket_init_with_address(wi_socket_t *_socket, wi_address_t *address, wi_socket_type_t type) {
	_socket->address	= wi_copy(address);
	_socket->close		= true;
	_socket->buffer		= wi_string_init_with_capacity(wi_string_alloc(), WI_SOCKET_BUFFER_SIZE);
	_socket->type		= type;

	_socket->sd			= socket(wi_address_family(_socket->address), _socket->type, 0);
	
	if(_socket->sd < 0) {
		wi_error_set_errno(errno);
		
		wi_release(_socket);
		
		return NULL;
	}
	
	if(!_wi_socket_set_option(_socket, SOL_SOCKET, SO_REUSEADDR, 1)) {
		wi_release(_socket);
		
		return NULL;
	}

	return _socket;
}
Exemplo n.º 9
0
wi_file_t * wi_file_init_temporary_file(wi_file_t *file) {
	FILE		*fp;
	
	fp = wi_tmpfile();
	
	if(!fp) {
		wi_error_set_errno(errno);

		wi_release(file);
		
		return NULL;
	}

	return wi_file_init_with_file_descriptor(file, fileno(fp));
}
Exemplo n.º 10
0
int32_t wi_socket_write(wi_socket_t *socket, wi_time_interval_t timeout, wi_string_t *fmt, ...) {
	wi_string_t		*string;
	int				bytes;
	va_list			ap;

	va_start(ap, fmt);
	string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap);
	va_end(ap);
	
	bytes = wi_socket_write_buffer(socket, timeout, wi_string_cstring(string), wi_string_length(string));
	
	wi_release(string);

	return bytes;
}
Exemplo n.º 11
0
void wi_error_set_libxml2_error(void) {
	wi_error_t		*error;
	xmlErrorPtr		xml_error;

	xml_error = xmlGetLastError();

	error = _wi_get_error();
	error->domain = WI_ERROR_DOMAIN_REGEX;
	error->code = xml_error->code;
	
	wi_release(error->string);

	error->string = wi_string_init_with_cstring(wi_string_alloc(), xml_error->message);
	wi_string_delete_surrounding_whitespace(error->string);
}
Exemplo n.º 12
0
static void wt_server_dealloc(wi_runtime_instance_t *instance) {
	wt_server_t		*server = instance;
	
	wi_release(server->key);
	wi_release(server->ip);
	wi_release(server->category);
	wi_release(server->url);
	wi_release(server->name);
	wi_release(server->description);
}
Exemplo n.º 13
0
static void wr_msg_400(wi_array_t *arguments) {
	wi_address_t		*address;
	wr_transfer_t		*transfer;

	transfer = wr_transfers_transfer_with_path(WI_ARRAY(arguments, 0));

	if(!transfer)
		return;
	
	address = wi_copy(wr_address);
	wi_address_set_port(address, wi_address_port(address) + 1);
	
	transfer->state			= WR_TRANSFER_RUNNING;
	transfer->offset		= wi_string_uint64(WI_ARRAY(arguments, 1));
	transfer->transferred	= transfer->offset;
	transfer->key			= wi_retain(WI_ARRAY(arguments, 2));
	transfer->start_time	= wi_time_interval();
	transfer->socket		= wi_socket_init_with_address(wi_socket_alloc(), address, WI_SOCKET_TCP);

	wi_socket_set_interactive(transfer->socket, false);
	
	if(!wi_socket_connect(transfer->socket, wr_socket_context, 15.0)) {
		wr_printf_prefix(WI_STR("Could not connect to %@: %m"), wi_address_string(address));
		
		wr_transfer_stop(transfer);

		goto end;
	}
	
	wi_file_seek(transfer->file, transfer->offset);

	if(transfer->type == WR_TRANSFER_DOWNLOAD) {
		wi_socket_set_direction(transfer->socket, WI_SOCKET_READ);
		wr_runloop_add_socket(transfer->socket, wr_runloop_download_callback);
	} else {
		wi_socket_set_direction(transfer->socket, WI_SOCKET_WRITE);
		wr_runloop_add_socket(transfer->socket, wr_runloop_upload_callback);
	}

	wr_send_command_on_socket(transfer->socket, WI_STR("TRANSFER %#@"), transfer->key);

	wr_printf_prefix(WI_STR("Starting transfer of \"%@\""), transfer->name);
	
	wr_draw_transfers(true);

end:
	wi_release(address);
}
Exemplo n.º 14
0
static void wd_client_info_dealloc(wi_runtime_instance_t *instance) {
	wd_client_info_t		*client_info = instance;

	wi_release(client_info->application_name);
	wi_release(client_info->application_version);
    wi_release(client_info->application_build);
	wi_release(client_info->os_name);
	wi_release(client_info->os_version);
	wi_release(client_info->arch);
}
Exemplo n.º 15
0
void wi_error_set_libxml2_error(void) {
	wi_error_t		*error;
	wi_string_t		*string;
	xmlErrorPtr		xml_error;

	xml_error = xmlGetLastError();

	error = _wi_error_get_error();
	error->domain = WI_ERROR_DOMAIN_REGEX;
	error->code = xml_error->code;
	
	string = wi_string_by_deleting_surrounding_whitespace(wi_string_with_cstring(xml_error->message));
	
	wi_release(error->string);
	error->string = wi_retain(string);
}
Exemplo n.º 16
0
void wr_wprintf_block(wr_window_t *window, wi_string_t *fmt, ...) {
	wi_enumerator_t	*enumerator;
	wi_string_t		*string, *line;
	va_list			ap;

	va_start(ap, fmt);
	string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap);
	va_end(ap);

	enumerator = wi_array_data_enumerator(wi_string_components_separated_by_string(string, WI_STR("\n")));
	
	while((line = wi_enumerator_next_data(enumerator)))
		wr_wprintf(window, WI_STR("   %@"), line);

	wi_release(string);
}
Exemplo n.º 17
0
wi_string_t * _wi_string_constant_string(const char *cstring) {
	wi_string_t			*string;
	
	wi_lock_lock(_wi_string_constant_string_lock);
	string = wi_dictionary_data_for_key(_wi_string_constant_string_table, (void *) cstring);
	
	if(!string) {
		string = wi_string_init_with_cstring(wi_string_alloc(), cstring);
		wi_mutable_dictionary_set_data_for_key(_wi_string_constant_string_table, string, (void *) cstring);
		wi_release(string);
	}
	
	wi_lock_unlock(_wi_string_constant_string_lock);

	return string;
}
Exemplo n.º 18
0
wi_string_t * wi_string_init_with_contents_of_file(wi_string_t *string, wi_string_t *path) {
	wi_file_t       *file;
	
	wi_release(string);
		
	file = wi_file_for_reading(path);
	
	if(!file)
		return NULL;
	
	string = wi_file_read_to_end_of_file(file);
	
	wi_file_close(file);
	
	return wi_retain(string);
}
Exemplo n.º 19
0
wi_cipher_t * wi_cipher_init_with_random_key(wi_cipher_t *cipher, wi_cipher_type_t type) {
	wi_data_t			*key, *iv;

	if(!_wi_cipher_set_type(cipher, type)) {
		wi_error_set_libwired_error(WI_ERROR_CIPHER_CIPHERNOTSUPP);
		
		wi_release(cipher);
		
		return NULL;
	}
	
	key = wi_data_with_random_bytes(wi_cipher_bits(cipher) / 8);
	iv = wi_data_with_random_bytes(wi_cipher_block_size(cipher));
	
	return _wi_cipher_init_with_key(cipher, key, iv);
}
Exemplo n.º 20
0
static void _wi_tests_assert_handler(const char *file, unsigned int line, wi_string_t *fmt, ...) {
	wi_string_t		*string;
	va_list			ap;
	
	va_start(ap, fmt);
	string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap);
	va_end(ap);
	
	wi_log_warn(WI_STR("%@:%u: %@"), wi_string_last_path_component(wi_string_with_cstring(file)), line, string);
	
	wi_release(string);
	
	_wi_tests_current_test->passed = false;
	
	longjmp(_wi_tests_jmp_buf, 1);
}
Exemplo n.º 21
0
void wi_test_runtime_info(void) {
    _wi_runtimetest_t   *runtimetest;
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_name(WI_STR("_wi_runtimetest_t")), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_class_with_id(_wi_runtimetest_runtime_id), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id_for_class(&_wi_runtimetest_runtime_class), _wi_runtimetest_runtime_id, "");
    
    runtimetest = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42);
    
    WI_TEST_ASSERT_EQUALS(wi_runtime_class(runtimetest), &_wi_runtimetest_runtime_class, "");
    WI_TEST_ASSERT_EQUAL_INSTANCES(wi_runtime_class_name(runtimetest), wi_string_with_utf8_string(_wi_runtimetest_runtime_class.name), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id(runtimetest), _wi_runtimetest_runtime_id, "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_options(runtimetest), WI_RUNTIME_OPTION_IMMUTABLE, "");
    
    wi_release(runtimetest);
}
Exemplo n.º 22
0
static void wr_msg_302(wi_array_t *arguments) {
	wr_chat_t	*chat;
	wr_user_t	*user;
	wr_cid_t	cid;
	
	cid = wi_string_uint32(WI_ARRAY(arguments, 0));
	chat = wr_chats_chat_with_cid(cid);

	user = wr_user_init_with_arguments(wr_user_alloc(), arguments);
	wr_chat_add_user(chat, user);
	wi_release(user);

	wr_draw_divider();
	wr_wprintf_prefix(wr_windows_window_with_chat(chat), WI_STR("%@ has joined"),
		wr_user_nick(user));
}
Exemplo n.º 23
0
void wr_wprintf_prefix(wr_window_t *window, wi_string_t *fmt, ...) {
	wi_string_t		*string;
	va_list			ap;

	va_start(ap, fmt);
	string = wi_string_init_with_format_and_arguments(wi_string_alloc(), fmt, ap);
	va_end(ap);

	wr_wprintf(window, WI_STR("%s%s%s%@"),
		WR_PREFIX_COLOR,
		WR_PREFIX,
		WR_TERMINATE_COLOR,
		string);

	wi_release(string);
}
Exemplo n.º 24
0
void wi_error_set_libwired_error_with_string(int code, wi_string_t *string) {
	wi_string_t		*errorstring;
	
	errorstring = wi_string_init_with_cstring(wi_mutable_string_alloc(), _wi_error_strings[code]);

	if(wi_string_length(string) > 0) {
		if(wi_string_length(errorstring) > 0)
			wi_mutable_string_append_string(errorstring, WI_STR(": "));
		
		wi_mutable_string_append_string(errorstring, string);
	}
	
	wi_error_set_error_with_string(WI_ERROR_DOMAIN_LIBWIRED, code, errorstring);
	
	wi_release(errorstring);
}
Exemplo n.º 25
0
static void _wi_process_dealloc(wi_runtime_instance_t *instance) {
	wi_process_t		*process = instance;
	
	wi_release(process->name);
	wi_release(process->path);
	wi_release(process->arguments);

	wi_release(process->os_name);
	wi_release(process->os_release);
	wi_release(process->arch);
}
Exemplo n.º 26
0
static void _wi_url_dealloc(wi_runtime_instance_t *instance) {
	wi_url_t		*url = instance;
	
	wi_release(url->scheme);
	wi_release(url->host);
	wi_release(url->path);
	wi_release(url->user);
	wi_release(url->password);

	wi_release(url->string);
}
Exemplo n.º 27
0
static void wd_transfer_expire_timer(wi_timer_t *timer) {
	wd_transfer_t		*transfer;
	
	transfer = wi_timer_data(timer);
	
	wi_lock_lock(wd_transfers_update_queue_lock);
	
	wi_array_wrlock(wd_transfers);
	wi_mutable_array_remove_data(wd_transfers, transfer);
	wi_array_unlock(wd_transfers);
	
	wd_transfers_update_queue();
	
	wi_lock_unlock(wd_transfers_update_queue_lock);

	wi_release(transfer);
}
Exemplo n.º 28
0
wi_boolean_t _wi_settings_set_path(wi_settings_t *settings, uint32_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);

	if(wi_string_has_prefix(value, WI_STR("/")))
		*string = wi_retain(value);
	else if(settings->chroot)
		*string = wi_string_init_with_format(wi_string_alloc(), WI_STR("/%@"), value);
	else
		*string = wi_string_init_with_format(wi_string_alloc(), WI_STR("%@/%@"), wi_root_path, value);

	wi_string_normalize_path(*string);
	
	return true;
}
Exemplo n.º 29
0
wi_date_t * wi_date_init_with_iso8601_string(wi_date_t *date, wi_string_t *string) {
	if(wi_string_length(string) < _WI_DATE_ISO8601_STRING_SIZE) {
		wi_release(date);
		
		return NULL;
	}

#ifdef HAVE_GLIBC
	string = wi_string_by_deleting_characters_in_range(string, wi_make_range(19, 6));

	return wi_date_init_with_string(date, string, WI_STR("%Y-%m-%dT%H:%M:%S"));
#else
	string = wi_string_by_deleting_characters_in_range(string, wi_make_range(22, 1));

	return wi_date_init_with_string(date, string, WI_STR("%Y-%m-%dT%H:%M:%S%z"));
#endif
}
Exemplo n.º 30
0
static void _wi_set_dealloc(wi_runtime_instance_t *instance) {
	wi_set_t		*set = instance;
	wi_uinteger_t	i;

	_wi_set_remove_all_data(set);

	if(set->bucket_chunks) {
		for(i = 0; i < set->bucket_chunks_count; i++)
			wi_free(set->bucket_chunks[i]);

		wi_free(set->bucket_chunks);
	}
	
	wi_free(set->buckets);

	wi_release(set->lock);
}