Changeset 5196
- Timestamp:
- 01/21/08 15:49:10 (6 months ago)
- Files:
-
- wired/trunk/wired/commands.c (modified) (2 diffs)
- wired/trunk/wired/files.c (modified) (8 diffs)
- wired/trunk/wired/server.c (modified) (3 diffs)
- wired/trunk/wired/server.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
wired/trunk/wired/commands.c
r4806 r5196 895 895 static void wd_cmd_hello(wi_array_t *arguments) { 896 896 wd_user_t *user = wd_users_user_for_thread(); 897 wi_string_t *ip , *start_date;897 wi_string_t *ip; 898 898 899 899 if(wd_user_state(user) != WD_USER_CONNECTED) … … 911 911 return; 912 912 } 913 914 start_date = wi_date_iso8601_string(wd_start_date); 915 916 wd_reply(200, WI_STR("%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%llu"), 917 wd_server_version_string, WD_FIELD_SEPARATOR, 918 wd_protocol_version_string, WD_FIELD_SEPARATOR, 919 wd_settings.name, WD_FIELD_SEPARATOR, 920 wd_settings.description, WD_FIELD_SEPARATOR, 921 start_date, WD_FIELD_SEPARATOR, 922 wd_files_unique_count, WD_FIELD_SEPARATOR, 923 wd_files_unique_size); 913 914 wd_server_send_server_info(false); 924 915 925 916 wd_user_set_state(user, WD_USER_SAID_HELLO); wired/trunk/wired/files.c
r5191 r5196 69 69 70 70 static void wd_files_update_index(wi_timer_t *); 71 static void wd_files_update_index_size(void); 71 72 static void wd_files_index_thread(wi_runtime_instance_t *); 72 73 static void wd_files_index_path(wi_string_t *, wi_file_t *, const char *); … … 681 682 682 683 static void wd_files_search_index(wi_string_t *query) { 683 wd_user_t *user = wd_users_user_for_thread(); 684 wi_pool_t *pool; 685 wi_file_t *file; 686 wi_string_t *string; 687 wd_account_t *account; 688 wi_range_t range, pathrange; 689 wi_uinteger_t i = 0, pathlength, index; 684 wd_user_t *user = wd_users_user_for_thread(); 685 wi_pool_t *pool; 686 wi_file_t *file; 687 wi_string_t *string; 688 wd_account_t *account; 689 wi_range_t range, pathrange; 690 wi_uinteger_t i = 0, pathlength, index; 691 wi_file_offset_t length; 692 struct stat sb; 690 693 691 694 wi_rwlock_rdlock(wd_files_index_lock); … … 699 702 goto end; 700 703 } 704 705 if(wi_file_stat(wd_settings.index, &sb)) 706 length = sb.st_size; 707 else 708 length = 0; 701 709 702 710 account = wd_user_account(user); … … 717 725 break; 718 726 719 if( wd_files_name_matches_query(string, query, true)) {727 if(length < wi_file_offset(file) && wd_files_name_matches_query(string, query, true)) { 720 728 index = wi_string_index_of_char(string, WD_FIELD_SEPARATOR, 0); 721 729 … … 778 786 if(!wi_thread_create_thread_with_priority(wd_files_index_thread, NULL, 0.0)) 779 787 wi_log_warn(WI_STR("Could not create a thread for index: %m")); 788 } else { 789 wd_files_update_index_size(); 790 } 791 } 792 793 794 795 static void wd_files_update_index_size(void) { 796 wi_file_t *file; 797 wi_array_t *array; 798 wi_string_t *string; 799 wi_file_offset_t offset; 800 801 file = wi_file_for_reading(wd_settings.index); 802 803 if(!file) 804 return; 805 806 offset = wi_file_seek_to_end_of_file(file); 807 wi_file_seek(file, offset - 1024); 808 809 while((string = wi_file_read_line(file))) { 810 if(wi_string_has_prefix(string, WI_STR("/"))) { 811 array = wi_string_components_separated_by_string(string, WI_STR(WD_FIELD_SEPARATOR_STR)); 812 813 if(wi_array_count(array) == 3) { 814 wd_files_unique_count = wi_string_uint32(WI_ARRAY(array, 1)); 815 wd_files_unique_size = wi_string_uint32(WI_ARRAY(array, 2)); 816 } 817 } 780 818 } 781 819 } … … 810 848 811 849 wd_files_index_level = 0; 812 wd_files_index_set = wi_ set_init_with_capacity(wi_set_alloc(), capacity);850 wd_files_index_set = wi_autorelease(wi_set_init_with_capacity(wi_set_alloc(), capacity)); 813 851 814 852 path = wi_string_with_format(WI_STR("%@~"), wd_settings.index); … … 827 865 828 866 if(wi_file_rename(path, wd_settings.index)) { 867 wi_file_write(file, WI_STR("%s%c%u%c%llu"), 868 "/", WD_FIELD_SEPARATOR, 869 wd_files_unique_count, WD_FIELD_SEPARATOR, 870 wd_files_unique_size); 871 829 872 wi_log_info(WI_STR("Indexed %u %s (%u unique) and %u %s (%u unique) for a total of %llu %s (%llu unique) in %.2f seconds"), 830 873 wd_files_count, … … 851 894 wi_rwlock_unlock(wd_files_index_lock); 852 895 896 wd_server_send_server_info(true); 897 853 898 end: 854 wi_release(wd_files_index_set);855 856 899 wi_lock_unlock(wd_files_indexer_lock); 857 900 } wired/trunk/wired/server.c
r5162 r5196 173 173 174 174 void wd_server_apply_settings(void) { 175 wi_string_t *string;176 175 wi_data_t *data; 177 176 … … 196 195 197 196 /* reload server name/description */ 198 if(wd_settings.name_changed || wd_settings.description_changed) { 199 string = wi_date_iso8601_string(wd_start_date); 200 201 wd_broadcast(wd_public_chat, 200, WI_STR("%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%llu"), 202 wd_server_version_string, WD_FIELD_SEPARATOR, 203 wd_protocol_version_string, WD_FIELD_SEPARATOR, 204 wd_settings.name, WD_FIELD_SEPARATOR, 205 wd_settings.description, WD_FIELD_SEPARATOR, 206 string, WD_FIELD_SEPARATOR, 207 wd_files_unique_count, WD_FIELD_SEPARATOR, 208 wd_files_unique_size); 209 } 197 if(wd_settings.name_changed || wd_settings.description_changed) 198 wd_server_send_server_info(true); 210 199 211 200 /* set SSL cipher list */ … … 233 222 } 234 223 } 224 225 226 227 void wd_server_send_server_info(wi_boolean_t broadcast) { 228 wi_string_t *string, *start_date; 229 230 start_date = wi_date_iso8601_string(wd_start_date); 231 string = wi_string_with_format(WI_STR("%#@%c%#@%c%#@%c%#@%c%#@%c%u%c%llu"), 232 wd_server_version_string, WD_FIELD_SEPARATOR, 233 wd_protocol_version_string, WD_FIELD_SEPARATOR, 234 wd_settings.name, WD_FIELD_SEPARATOR, 235 wd_settings.description, WD_FIELD_SEPARATOR, 236 start_date, WD_FIELD_SEPARATOR, 237 wd_files_unique_count, WD_FIELD_SEPARATOR, 238 wd_files_unique_size); 239 240 if(broadcast) 241 wd_broadcast(wd_public_chat, 200, WI_STR("%#@"), string); 242 else 243 wd_reply(200, WI_STR("%#@"), string); 244 } 245 235 246 236 247 wired/trunk/wired/server.h
r5066 r5196 49 49 void wd_server_create_threads(void); 50 50 void wd_server_apply_settings(void); 51 void wd_server_send_server_info(wi_boolean_t); 51 52 52 53 void wd_ssl_init(void);
