int LoadHZData(const TCHAR *hz_data_name) { int file_length; assert(hz_data_name); if (share_segment->hz_data_loaded) return 1; file_length = GetFileLength(hz_data_name); if (file_length <= 0) return 0; hz_data = AllocateSharedMemory(hz_data_share_name, file_length); if (!hz_data) return 0; if ((file_length = LoadFromFile(hz_data_name, hz_data, file_length)) == -1) { FreeSharedMemory(hz_data_share_name, hz_data); Log(LOG_ID, L"汉字信息表文件打开失败。name=%s", hz_data_name); return 0; } if (!file_length) return 0; share_segment->hz_data_loaded = 1; return 1; }
/** 释放汉字信息表文件 */ int FreeHZData() { share_segment->hz_data_loaded = 0; if (hz_data) { FreeSharedMemory(hz_data_share_name, hz_data); hz_data = 0; } return 1; }
/** 释放FONT MAP文件 */ int FreeFontMapData() { share_segment->fontmap_loaded = 0; if (fontmap) { FreeSharedMemory(fontmap_share_name, fontmap); fontmap = 0; } return 1; }
/** 释放gbk MAP文件 */ int FreeGBKMapData() { share_segment->gbkmap_loaded = 0; if (gbk_map) { FreeSharedMemory(gbkmap_share_name, gbk_map); gbk_map = 0; } return 1; }
void DestroyAPRGlobalStorage (APRGlobalStorage *storage_p) { if (storage_p) { if (storage_p -> ags_entries_p) { unsigned char *key_s = NULL; apr_ssize_t keylen = 0; void *value_p = NULL; apr_hash_index_t *index_p = apr_hash_first (storage_p -> ags_pool_p, storage_p -> ags_entries_p); while (index_p) { apr_hash_this (index_p, (const void **) &key_s, &keylen, (void **) &value_p); storage_p -> ags_free_key_and_value_fn (key_s, value_p); index_p = apr_hash_next (index_p); } apr_hash_clear (storage_p -> ags_entries_p); } storage_p -> ags_pool_p = NULL; if (storage_p -> ags_mutex_p) { apr_global_mutex_destroy (storage_p -> ags_mutex_p); storage_p -> ags_mutex_p = NULL; } if (storage_p -> ags_socache_instance_p) { storage_p -> ags_socache_provider_p -> destroy (storage_p -> ags_socache_instance_p, storage_p -> ags_server_p); } if (storage_p -> ags_largest_entry_memory_id) { FreeSharedMemory (storage_p -> ags_largest_entry_memory_id); } } }
/** 加载fontmap到内存。 * 参数: * fontmap_file_name fontmap文件全路径 * 返回: * 成功:1 * 失败:0 */ int LoadFontMapData(const TCHAR *file_name) { int file_length; assert(file_name); if ( pim_config->scope_gbk == HZ_SCOPE_GBK || !pim_config->hide_black_window ) { share_segment->fontmap_loaded = 0; return 0; } if (share_segment->fontmap_loaded) return 1; file_length = GetFileLength(file_name); if (file_length <= 0) return 0; fontmap = AllocateSharedMemory(fontmap_share_name, file_length); if (!fontmap) return 0; if ((file_length = LoadFromFile(file_name, fontmap, file_length)) == -1) { FreeSharedMemory(fontmap_share_name, fontmap); Log(LOG_ID, L"FONT MAP文件打开失败。name=%s", file_name); return 0; } if (!file_length) return 0; share_segment->fontmap_loaded = 1; return 1; }
bool InitAPRGlobalStorage (APRGlobalStorage *storage_p, apr_pool_t *pool_p, apr_hashfunc_t hash_fn, unsigned char *(*make_key_fn) (const void *data_p, uint32 raw_key_length, uint32 *key_len_p), void (*free_key_and_value_fn) (unsigned char *key_p, void *value_p), server_rec *server_p, const char *mutex_filename_s, const char *cache_id_s, const char *provider_name_s) { ap_socache_provider_t *provider_p = ap_lookup_provider (AP_SOCACHE_PROVIDER_GROUP, provider_name_s, AP_SOCACHE_PROVIDER_VERSION); if (provider_p) { apr_status_t status = apr_global_mutex_create (& (storage_p -> ags_mutex_p), mutex_filename_s, APR_THREAD_MUTEX_UNNESTED, pool_p); if (status == APR_SUCCESS) { char *current_dir_s = GetCurrentWorkingDirectory (); if (current_dir_s) { storage_p -> ags_largest_entry_memory_id = AllocateSharedMemory (current_dir_s, sizeof (unsigned int), 0644); FreeCopiedString (current_dir_s); if (storage_p -> ags_largest_entry_memory_id != -1) { storage_p -> ags_entries_p = apr_hash_make_custom (pool_p, hash_fn); if (storage_p -> ags_entries_p) { storage_p -> ags_pool_p = pool_p; storage_p -> ags_server_p = server_p; storage_p -> ags_make_key_fn = make_key_fn; storage_p -> ags_free_key_and_value_fn = free_key_and_value_fn; storage_p -> ags_cache_id_s = cache_id_s; storage_p -> ags_mutex_lock_filename_s = mutex_filename_s; storage_p -> ags_socache_instance_p = NULL; storage_p -> ags_socache_provider_p = provider_p; apr_pool_cleanup_register (pool_p, storage_p, (const void *) FreeAPRGlobalStorage, apr_pool_cleanup_null); return true; } /* if (storage_p -> ags_entries_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate shared memory hash table"); } FreeSharedMemory (storage_p -> ags_largest_entry_memory_id); } /* if (storage_p -> ags_largest_entry_memory_id != -1) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate shared memory for largest chunk size"); } } /* if (mem_key_s) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create memory key from \"%s\" and \".memory\"", cache_id_s); } apr_global_mutex_destroy (storage_p -> ags_mutex_p); storage_p -> ags_mutex_p = NULL; } /* if (status == APR_SUCCESS) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to create global mutex for shared memory at %s", mutex_filename_s); } } /* if (provider_p) */ else { PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to find provider \"%s\"", provider_name_s ? provider_name_s : "NULL"); } return false; }