wi_array_t * wd_user_subscribed_virtual_paths_for_path(wd_user_t *user, wi_string_t *path) { wi_mutable_array_t *array; wi_string_t *virtualpath; array = wi_mutable_array(); wi_recursive_lock_lock(user->user_lock); if(wi_is_equal(wi_string_last_path_component(path), WI_STR(WD_FILES_META_PATH))) { path = wi_string_by_deleting_last_path_component(path); virtualpath = wi_dictionary_data_for_key(user->subscribed_virtualpaths, path); if(virtualpath) wi_mutable_array_add_data(array, virtualpath); if(!wi_is_equal(path, WI_STR("/"))) { path = wi_string_by_deleting_last_path_component(path); virtualpath = wi_dictionary_data_for_key(user->subscribed_virtualpaths, path); if(virtualpath) wi_mutable_array_add_data(array, virtualpath); } } else { virtualpath = wi_dictionary_data_for_key(user->subscribed_virtualpaths, path); if(virtualpath) wi_mutable_array_add_data(array, virtualpath); } wi_recursive_lock_unlock(user->user_lock); return array; }
void wi_test_runtime_functions(void) { _wi_runtimetest_t *runtimetest1, *runtimetest2; _wi_mutable_runtimetest_t *runtimetest3; _wi_runtimetest_deallocs = 0; runtimetest1 = _wi_runtimetest_init_with_value(_wi_runtimetest_alloc(), 42); runtimetest2 = wi_copy(runtimetest1); WI_TEST_ASSERT_TRUE(runtimetest1 == runtimetest2, ""); wi_release(runtimetest2); runtimetest3 = wi_mutable_copy(runtimetest1); WI_TEST_ASSERT_TRUE(runtimetest1 != runtimetest3, ""); WI_TEST_ASSERT_EQUALS(runtimetest1->value, runtimetest3->value, ""); WI_TEST_ASSERT_TRUE(wi_is_equal(runtimetest1, runtimetest3), ""); runtimetest3->value++; WI_TEST_ASSERT_FALSE(wi_is_equal(runtimetest1, runtimetest3), ""); wi_release(runtimetest3); WI_TEST_ASSERT_EQUALS(_wi_runtimetest_deallocs, 1U, ""); WI_TEST_ASSERT_EQUAL_INSTANCES(wi_description(runtimetest1), WI_STR("value=42"), ""); WI_TEST_ASSERT_EQUALS(wi_hash(runtimetest1), 42U, ""); wi_release(runtimetest1); }
void wi_test_string_compare(void) { WI_TEST_ASSERT_TRUE(wi_is_equal(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello world")), ""); WI_TEST_ASSERT_FALSE(wi_is_equal(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello another world")), ""); WI_TEST_ASSERT_TRUE(wi_string_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello world")) == 0, ""); WI_TEST_ASSERT_FALSE(wi_string_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("Hello world")) == 0, ""); WI_TEST_ASSERT_FALSE(wi_string_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("hello another world")) == 0, ""); WI_TEST_ASSERT_TRUE(wi_string_case_insensitive_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("Hello world")) == 0, ""); WI_TEST_ASSERT_FALSE(wi_string_case_insensitive_compare(wi_string_with_cstring("hello world"), wi_string_with_cstring("Hello another world")) == 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); }
static wi_runtime_instance_t * _wi_plist_instance_for_document(xmlDocPtr doc) { wi_runtime_instance_t *instance; wi_string_t *version; xmlNodePtr root_node, content_node = NULL, node; root_node = xmlDocGetRootElement(doc); if(!wi_is_equal(wi_xml_node_name(root_node), WI_STR("plist"))) { wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED, WI_STR("Root node \"%@\" is not equal to \"plist\""), wi_xml_node_name(root_node)); return NULL; } version = wi_xml_node_attribute_with_name(root_node, WI_STR("version")); if(!version) { wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED, WI_STR("No version attribute on \"plist\"")); return NULL; } if(!wi_is_equal(version, WI_STR("1.0"))) { wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED, WI_STR("Unhandled version \"%@\""), version); return NULL; } for(node = root_node->children; node != NULL; node = node->next) { if(node->type == XML_ELEMENT_NODE) { content_node = node; break; } } if(!content_node) { wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED, WI_STR("No content")); return NULL; } instance = _wi_plist_instance_for_node(content_node); if(!_wi_plist_read_node_to_instance(content_node, instance)) return NULL; return instance; }
static wi_runtime_instance_t * _wi_plist_instance_for_node(xmlNodePtr node) { wi_string_t *name; name = wi_xml_node_name(node); if(wi_is_equal(name, WI_STR("dict"))) return wi_dictionary(); else if(wi_is_equal(name, WI_STR("array"))) return wi_array(); wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED, WI_STR("Content \"%@\" is not \"dict\" or \"array\""), name); return NULL; }
wi_boolean_t wt_category_is_valid(wi_string_t *category) { wi_file_t *file; wi_string_t *string; wi_boolean_t result = false; if(wi_string_length(category) == 0) return true; file = wi_file_for_reading(wt_settings.categories); if(!file) { wi_log_err(WI_STR("Could not open %@: %m"), wt_settings.categories); return true; } while((string = wi_file_read_config_line(file))) { if(wi_is_equal(category, string)) { result = true; break; } } return result; }
void wr_transfer_upload_remove_files(wr_transfer_t *transfer, wi_array_t *files) { wi_enumerator_t *enumerator; wr_file_t *file; wi_uinteger_t i, count; count = wi_array_count(transfer->remote_paths); enumerator = wi_array_data_enumerator(files); while((file = wi_enumerator_next_data(enumerator))) { for(i = 0; i < count; i++) { if(wi_is_equal(wr_file_path(file), WI_ARRAY(transfer->remote_paths, i))) { transfer->total_size -= wr_file_size(WI_ARRAY(transfer->files, i)); wi_mutable_array_remove_data_at_index(transfer->remote_paths, i); wi_mutable_array_remove_data_at_index(transfer->local_paths, i); wi_mutable_array_remove_data_at_index(transfer->files, i); count--; break; } } } wr_transfers_recursive_upload = false; }
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); }
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); }
void wi_test_runtime_invalid(void) { WI_TEST_ASSERT_NULL(wi_runtime_class_with_name(WI_STR("foo")), ""); WI_TEST_ASSERT_NULL(wi_runtime_class_with_id(1337), ""); WI_TEST_ASSERT_EQUALS(wi_runtime_id_for_class(NULL), WI_RUNTIME_ID_NULL, ""); WI_TEST_ASSERT_NULL(wi_runtime_class("foo"), ""); WI_TEST_ASSERT_NULL(wi_runtime_class_name("foo"), ""); WI_TEST_ASSERT_EQUALS(wi_runtime_id("foo"), WI_RUNTIME_ID_NULL, ""); WI_TEST_ASSERT_NULL(wi_retain(NULL), ""); WI_TEST_ASSERT_EQUALS(wi_retain_count(NULL), 0U, ""); WI_TEST_ASSERT_NULL(wi_copy(NULL), ""); WI_TEST_ASSERT_NULL(wi_mutable_copy(NULL), ""); WI_TEST_ASSERT_TRUE(wi_is_equal(NULL, NULL), ""); WI_TEST_ASSERT_FALSE(wi_is_equal(NULL, "foo"), ""); WI_TEST_ASSERT_FALSE(wi_is_equal(wi_array(), wi_dictionary()), ""); WI_TEST_ASSERT_NULL(wi_description(NULL), ""); WI_TEST_ASSERT_EQUALS(wi_hash(NULL), 0U, ""); }
wr_transfer_t * wr_transfers_transfer_with_remote_path(wi_string_t *remote_path) { wi_enumerator_t *enumerator, *path_enumerator; wi_string_t *path; wr_transfer_t *transfer; enumerator = wi_array_data_enumerator(wr_transfers); while((transfer = wi_enumerator_next_data(enumerator))) { if(wi_is_equal(transfer->master_path, remote_path)) return transfer; path_enumerator = wi_array_data_enumerator(transfer->remote_paths); while((path = wi_enumerator_next_data(path_enumerator))) { if(wi_is_equal(path, remote_path)) return transfer; } } return NULL; }
wr_window_t * wr_windows_window_with_user(wr_user_t *user) { wi_enumerator_t *enumerator; wr_window_t *window; enumerator = wi_array_data_enumerator(wr_windows); while((window = wi_enumerator_next_data(enumerator))) { if(wr_window_is_user(window) && wi_is_equal(window->user, user)) return window; } return NULL; }
wr_window_t * wr_windows_window_with_chat(wr_chat_t *chat) { wi_enumerator_t *enumerator; wr_window_t *window; enumerator = wi_array_data_enumerator(wr_windows); while((window = wi_enumerator_next_data(enumerator))) { if(wr_window_is_chat(window) && wi_is_equal(window->chat, chat)) return window; } return NULL; }
void DRFilesTreeModel::receivedMessage(wi_p7_message_t *message, DRServerConnection *connection) { if(QThread::currentThread() != QApplication::instance()->thread()) qDebug() << "is background thread"; else qDebug() << "DRFilesTreeModel::receivedMessage is main thread"; if(wi_is_equal(wi_p7_message_name(message), WI_STR("wired.file.file_list"))) { if(this->loadingItem == NULL) return; DRFileItem *parent = this->loadingItem; QModelIndex parentIndex = parent->getIndex(); int row = parent->childNumber()+1; QModelIndex childIndex = createIndex(row, 0, parent); DRFileItem *newChild = new DRFileItem(message, this->connection, this->loadingItem, childIndex); bool success = false; qDebug() << newChild; beginInsertRows(parentIndex, parent->childCount()+1, parent->childCount()+2); success = this->loadingItem->appendChild(newChild); endInsertRows(); } else if(wi_is_equal(wi_p7_message_name(message), WI_STR("wired.file.file_list.done"))) { //qDebug() << this->loadingItem->childCount(); //emit dataChanged(this->loadingItem->getIndex(), this->loadingItem->getIndex()); //emit rowsInserted(this->loadingItem->getIndex(), 0, 0); //emit layoutChanged(); this->loadingItem = NULL; this->connection->removeDelegateForMessage(this, "wired.file.file_list"); this->connection->removeDelegateForMessage(this, "wired.file.file_list.done"); // QObject::disconnect(this->connection, SIGNAL(receivedMessage(wi_p7_message_t*,DRServerConnection*)), // this, SLOT(receivedMessage(wi_p7_message_t*,DRServerConnection*))); } }
void wd_transfers_queue_upload(wi_string_t *path, wi_file_offset_t size, wi_string_t *checksum) { wd_user_t *user = wd_users_user_for_thread(); wi_string_t *realpath, *filechecksum; wd_transfer_t *transfer; wi_file_offset_t offset; wi_fs_stat_t sb; realpath = wi_string_by_resolving_aliases_in_path(wd_files_real_path(path)); if(wi_fs_stat_path(realpath, &sb)) { wd_reply(521, WI_STR("File or Directory Exists")); return; } if(!wi_string_has_suffix(realpath, WI_STR(WD_TRANSFERS_PARTIAL_EXTENSION))) realpath = wi_string_by_appending_path_extension(realpath, WI_STR(WD_TRANSFERS_PARTIAL_EXTENSION)); if(!wi_fs_stat_path(realpath, &sb)) { offset = 0; } else { offset = sb.size; if(sb.size >= WD_FILES_CHECKSUM_SIZE) { filechecksum = wi_fs_sha1_for_path(realpath, WD_FILES_CHECKSUM_SIZE); if(!wi_is_equal(filechecksum, checksum)) { wd_reply(522, WI_STR("Checksum Mismatch")); return; } } } transfer = wi_autorelease(wd_transfer_init_upload_with_user(wd_transfer_alloc(), user)); transfer->path = wi_retain(path); transfer->realpath = wi_retain(realpath); transfer->size = size; transfer->offset = offset; transfer->transferred = offset; wi_lock_lock(wd_transfers_update_queue_lock); wi_array_wrlock(wd_transfers); wi_mutable_array_add_data(wd_transfers, transfer); wi_array_unlock(wd_transfers); wd_transfers_update_queue(); wi_lock_unlock(wd_transfers_update_queue_lock); }
void DRUser::setObjectWithMessage(wi_p7_message_t *message) { if(wi_is_equal(wi_p7_message_name(message), WI_STR("wired.chat.user_list")) || wi_is_equal(wi_p7_message_name(message), WI_STR("wired.chat.user_join"))) { wi_p7_message_get_int32_for_name(message, &userID, WI_STR("wired.user.id")); wi_p7_message_get_bool_for_name(message, &this->isIdle, WI_STR("wired.user.idle")); wi_p7_message_get_uint32_for_name(message, &this->color, WI_STR("wired.account.color")); this->nick = QString(wi_string_cstring(wi_p7_message_string_for_name(message, WI_STR("wired.user.nick")))); this->status = QString(wi_string_cstring(wi_p7_message_string_for_name(message, WI_STR("wired.user.status")))); QString base64icon = QString(wi_string_cstring(wi_data_base64(wi_p7_message_data_for_name(message, WI_STR("wired.user.icon"))))); this->icon = DR::iconForBase64String(base64icon); } else if(wi_is_equal(wi_p7_message_name(message), WI_STR("wired.chat.user_status"))) { wi_p7_message_get_bool_for_name(message, &this->isIdle, WI_STR("wired.user.idle")); wi_p7_message_get_uint32_for_name(message, &this->color, WI_STR("wired.account.color")); this->nick = QString(wi_string_cstring(wi_p7_message_string_for_name(message, WI_STR("wired.user.nick")))); this->status = QString(wi_string_cstring(wi_p7_message_string_for_name(message, WI_STR("wired.user.status")))); } }
void wi_config_set_instance_for_name(wi_config_t *config, wi_runtime_instance_t *instance, wi_string_t *name) { wi_runtime_instance_t *copy; wi_lock_lock(config->lock); if(!wi_is_equal(instance, wi_dictionary_data_for_key(config->values, name))) wi_mutable_set_add_data(config->changes, name); copy = wi_copy(instance); wi_mutable_dictionary_set_data_for_key(config->values, copy, name); wi_release(copy); wi_lock_unlock(config->lock); }
static wi_boolean_t _wi_p7_socket_receive_compatibility_check(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) { wi_string_t *string; wi_p7_message_t *p7_message; wi_p7_spec_t *p7_spec; wi_boolean_t compatible; p7_message = wi_p7_socket_read_message(p7_socket, timeout); if(!p7_message) return false; if(!wi_is_equal(p7_message->name, WI_STR("p7.compatibility_check.specification"))) { wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, WI_STR("Message should be \"p7.compatibility_check.specification\", not \"%@\""), p7_message->name); return false; } string = wi_p7_message_string_for_name(p7_message, WI_STR("p7.compatibility_check.specification")); if(!string) { wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, WI_STR("Message has no \"p7.compatibility_check.specification\" field")); return false; } p7_spec = wi_p7_spec_init_with_string(wi_p7_spec_alloc(), string); if(!p7_spec) return false; compatible = wi_p7_spec_is_compatible_with_spec(p7_socket->spec, p7_spec); wi_release(p7_spec); p7_message = wi_p7_message_with_name(WI_STR("p7.compatibility_check.status"), p7_socket); if(!p7_message) return false; if(!wi_p7_message_set_bool_for_name(p7_message, compatible, WI_STR("p7.compatibility_check.status"))) return false; if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message)) return false; return true; }
static void wd_cmd_pass(wi_array_t *arguments) { wd_client_t *client = wd_client(); wi_string_t *password; wd_chat_t *chat; if(client->state != WD_CLIENT_STATE_GAVE_USER) return; client->account = wi_retain(wd_accounts_read_user_and_group(client->login)); if(!client->account) { wd_reply(510, WI_STR("Login Failed")); wi_log_info(WI_STR("Login from %@/%@/%@ failed: %@"), client->nick, client->login, client->ip, WI_STR("No such account")); return; } password = WI_ARRAY(arguments, 0); if(!wi_is_equal(client->account->password, password)) { wd_reply(510, WI_STR("Login Failed")); wi_log_info(WI_STR("Login from %@/%@/%@ failed: %@"), client->nick, client->login, client->ip, WI_STR("Wrong password")); return; } wi_log_info(WI_STR("Login from %@/%@/%@ succeeded"), client->nick, client->login, client->ip); wi_lock_lock(client->flag_lock); client->admin = (client->account->kick_users || client->account->ban_users); client->state = WD_CLIENT_STATE_LOGGED_IN; wi_lock_unlock(client->flag_lock); wi_lock_lock(wd_status_lock); wd_current_users++; wd_total_users++; wd_write_status(true); wi_lock_unlock(wd_status_lock); wd_reply(201, WI_STR("%u"), client->uid); chat = wd_chat_with_cid(WD_PUBLIC_CID); wd_chat_add_client(chat, client); }
void wd_transfers_queue_upload(wi_string_t *path, wi_file_offset_t size, wi_string_t *checksum) { wd_client_t *client = wd_client(); wi_string_t *realpath, *filechecksum; wd_transfer_t *transfer; wi_file_offset_t offset; struct stat sb; realpath = wd_files_real_path(path); wi_string_resolve_aliases_in_path(realpath); if(wi_file_stat(realpath, &sb)) { wd_reply(521, WI_STR("File or Directory Exists")); return; } if(!wi_string_has_suffix(realpath, WI_STR(WD_TRANSFERS_PARTIAL_EXTENSION))) wi_string_append_string(realpath, WI_STR(WD_TRANSFERS_PARTIAL_EXTENSION)); if(!wi_file_stat(realpath, &sb)) { offset = 0; } else { offset = sb.st_size; if(sb.st_size >= WD_FILES_CHECKSUM_SIZE) { filechecksum = wi_file_sha1(realpath, WD_FILES_CHECKSUM_SIZE); if(!wi_is_equal(filechecksum, checksum)) { wd_reply(522, WI_STR("Checksum Mismatch")); return; } } } transfer = wd_transfer_init_upload_with_client(wd_transfer_alloc(), client); transfer->path = wi_retain(path); transfer->realpath = wi_retain(realpath); transfer->size = size; transfer->offset = offset; transfer->transferred = offset; wi_list_wrlock(wd_transfers); wi_list_append_data(wd_transfers, transfer); wi_list_unlock(wd_transfers); wi_release(transfer); wd_transfers_update_queue(); }
wt_server_t * wt_server_with_key(wi_string_t *key) { wi_list_node_t *node; wt_server_t *server, *value = NULL; wi_list_rdlock(wt_servers); WI_LIST_FOREACH(wt_servers, node, server) { if(wi_is_equal(server->key, key)) { value = server; break; } } wi_list_unlock(wt_servers); return value; }
static void wr_command_nick(wi_array_t *arguments) { wi_p7_message_t *message; wi_string_t *nick; nick = WI_ARRAY(arguments, 0); if(!wi_is_equal(nick, wr_nick)) { wi_release(wr_nick); wr_nick = wi_retain(nick); if(wr_connected) { message = wi_p7_message_with_name(WI_STR("wired.user.set_nick"), wr_p7_spec); wi_p7_message_set_string_for_name(message, nick, WI_STR("wired.user.nick")); wr_commands_send_message(message, WI_STR("nick")); } } }
static wi_boolean_t _wi_p7_socket_send_compatibility_check(wi_p7_socket_t *p7_socket, wi_time_interval_t timeout) { wi_p7_message_t *p7_message; wi_p7_boolean_t status; p7_message = wi_p7_message_with_name(WI_STR("p7.compatibility_check.specification"), p7_socket); if(!p7_message) return false; if(!wi_p7_message_set_string_for_name(p7_message, wi_p7_spec_xml(p7_socket->spec), WI_STR("p7.compatibility_check.specification"))) return false; if(!wi_p7_socket_write_message(p7_socket, timeout, p7_message)) return false; p7_message = wi_p7_socket_read_message(p7_socket, timeout); if(!p7_message) return false; if(!wi_is_equal(p7_message->name, WI_STR("p7.compatibility_check.status"))) { wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, WI_STR("Message should be \"p7.compatibility_check.status\", not \"%@\""), p7_message->name); return false; } if(!wi_p7_message_get_bool_for_name(p7_message, &status, WI_STR("p7.compatibility_check.status"))) { wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, WI_STR("Message has no \"p7.compatibility_check.status\" field")); return false; } if(!status) { wi_error_set_libwired_p7_error(WI_ERROR_P7_HANDSHAKEFAILED, WI_STR("Remote protocol %@ %.1f is not compatible"), p7_socket->name, p7_socket->version); return false; } return true; }
static void wd_cmd_status(wi_array_t *arguments) { wd_client_t *client = wd_client(); wi_string_t *status; if(client->state < WD_CLIENT_STATE_SAID_HELLO) return; status = WI_ARRAY(arguments, 0); if(!wi_is_equal(status, client->status)) { wi_release(client->status); client->status = wi_retain(status); if(client->state == WD_CLIENT_STATE_LOGGED_IN) { wd_broadcast_lock(); wd_client_broadcast_status(client); wd_broadcast_unlock(); } } }
wi_array_t * wd_users_users_with_login(wi_string_t *name) { wi_enumerator_t *enumerator; wi_mutable_array_t *users; wd_user_t *user; users = wi_mutable_array(); wi_dictionary_rdlock(wd_users); enumerator = wi_dictionary_data_enumerator(wd_users); while((user = wi_enumerator_next_data(enumerator))) { if(wi_is_equal(wd_user_login(user), name)) wi_mutable_array_add_data(users, user); } wi_dictionary_unlock(wd_users); return users; }
wt_server_t * wt_servers_server_with_ip(wi_string_t *ip) { wi_enumerator_t *enumerator; wt_server_t *server, *value = NULL; wi_dictionary_rdlock(wt_servers); enumerator = wi_dictionary_data_enumerator(wt_servers); while((server = wi_enumerator_next_data(enumerator))) { if(wi_is_equal(server->ip, ip)) { value = wi_autorelease(wi_retain(server)); break; } } wi_dictionary_unlock(wt_servers); return value; }
static void wr_command_status(wi_array_t *arguments) { wi_p7_message_t *message; wi_string_t *status; if(wi_array_count(arguments) > 0) status = WI_ARRAY(arguments, 0); else status = WI_STR(""); if(!wi_is_equal(status, wr_status)) { wi_release(wr_status); wr_status = wi_retain(status); if(wr_connected) { message = wi_p7_message_with_name(WI_STR("wired.user.set_status"), wr_p7_spec); wi_p7_message_set_string_for_name(message, status, WI_STR("wired.user.status")); wr_commands_send_message(message, WI_STR("status")); } } }
wi_boolean_t wr_client_set_charset(wi_string_t *charset) { wi_string_encoding_t *encoding; wi_integer_t options; if(wr_client_string_encoding && wi_is_equal(charset, wi_string_encoding_charset(wr_client_string_encoding))) return true; options = WI_STRING_ENCODING_IGNORE | WI_STRING_ENCODING_TRANSLITERATE; encoding = wi_string_encoding_init_with_charset(wi_string_encoding_alloc(), charset, options); if(!encoding) return false; wi_release(wr_client_string_encoding); wr_client_string_encoding = encoding; wr_printf_prefix(WI_STR("Using character set %@"), charset); return true; }
wd_transfer_t * wd_transfers_transfer_with_path(wd_transfer_type_t type, wi_string_t *path) { wd_transfer_t *transfer, *value = NULL; wi_uinteger_t i, count; wi_array_rdlock(wd_transfers); count = wi_array_count(wd_transfers); for(i = 0; i < count; i++) { transfer = WI_ARRAY(wd_transfers, i); if(transfer->type == type && wi_is_equal(transfer->path, path)) { value = wi_autorelease(wi_retain(transfer)); break; } } wi_array_unlock(wd_transfers); return value; }