grn_rc grn_windows_event_logger_set(grn_ctx *ctx, const char *event_source_name) { #ifdef WIN32 grn_rc rc; grn_logger windows_event_logger; grn_windows_event_logger_data *data; if (ctx) { GRN_API_ENTER; } data = malloc(sizeof(grn_windows_event_logger_data)); if (!data) { if (ctx) { ERR(GRN_NO_MEMORY_AVAILABLE, "failed to allocate user data for Windows event logger"); GRN_API_RETURN(ctx->rc); } else { return GRN_NO_MEMORY_AVAILABLE; } } if (event_source_name) { data->event_source_name = grn_strdup_raw(event_source_name); } else { data->event_source_name = grn_strdup_raw("libgroonga"); } data->event_source = INVALID_HANDLE_VALUE; windows_event_logger.max_level = GRN_LOG_DEFAULT_LEVEL; windows_event_logger.flags = GRN_LOG_TIME | GRN_LOG_MESSAGE; windows_event_logger.user_data = data; windows_event_logger.log = windows_event_logger_log; windows_event_logger.reopen = windows_event_logger_reopen; windows_event_logger.fin = windows_event_logger_fin; rc = grn_logger_set(ctx, &windows_event_logger); if (rc != GRN_SUCCESS) { windows_event_logger.fin(ctx, windows_event_logger.user_data); } if (ctx) { GRN_API_RETURN(rc); } else { return rc; } #else /* WIN32 */ return GRN_FUNCTION_NOT_IMPLEMENTED; #endif /* WIN32 */ }
const char * grn_windows_base_dir(void) { if (!windows_base_dir) { HMODULE dll; const wchar_t *dll_filename = GRN_DLL_FILENAME; wchar_t absolute_dll_filename[MAX_PATH]; DWORD absolute_dll_filename_size; dll = GetModuleHandleW(dll_filename); absolute_dll_filename_size = GetModuleFileNameW(dll, absolute_dll_filename, MAX_PATH); if (absolute_dll_filename_size == 0) { windows_base_dir = grn_strdup_raw("."); } else { DWORD ansi_dll_filename_size; ansi_dll_filename_size = WideCharToMultiByte(CP_ACP, 0, absolute_dll_filename, absolute_dll_filename_size, NULL, 0, NULL, NULL); if (ansi_dll_filename_size == 0) { windows_base_dir = grn_strdup_raw("."); } else { char *path; windows_base_dir = malloc(ansi_dll_filename_size + 1); WideCharToMultiByte(CP_ACP, 0, absolute_dll_filename, absolute_dll_filename_size, windows_base_dir, ansi_dll_filename_size, NULL, NULL); windows_base_dir[ansi_dll_filename_size] = '\0'; if ((path = strrchr(windows_base_dir, '\\'))) { *path = '\0'; } path = strrchr(windows_base_dir, '\\'); if (path && (grn_strcasecmp(path + 1, "bin") == 0 || grn_strcasecmp(path + 1, "lib") == 0)) { *path = '\0'; } else { path = windows_base_dir + strlen(windows_base_dir); *path = '\0'; } for (path = windows_base_dir; *path; path++) { if (*path == '\\') { *path = '/'; } } } } } return windows_base_dir; }
void grn_default_query_logger_set_path(const char *path) { if (default_query_logger_path) { free(default_query_logger_path); } if (path) { default_query_logger_path = grn_strdup_raw(path); } else { default_query_logger_path = NULL; } }