UCHAR DbImplementation::backwardCompatibleImplementation() const { if (di_cpu >= FB_NELEM(hardware) || di_os >= FB_NELEM(operatingSystem)) { return 0; } return backwardTable[USHORT(di_os) * FB_NELEM(hardware) + USHORT(di_cpu)]; }
Firebird::string pagtype(UCHAR type) { // Print pretty name for database page type const char* nameArray[pag_max + 1] = { "purposely undefined", "database header", "page inventory", "transaction inventory", "pointer", "data", "index root", "index B-tree", "blob", "generators", "SCN inventory" }; Firebird::string rc; if (type < FB_NELEM(nameArray)) rc = nameArray[type]; else rc.printf("unknown (%d)", type); return rc; }
void HSH_init() { /************************************** * * H S H _ i n i t * ************************************** * * Functional description * Initialize the hash table. This mostly involves * inserting all known keywords. * **************************************/ const qli_kword* qword = keywords; for (int i = 0; i < FB_NELEM(keywords); i++, qword++) { qli_symbol* symbol = (qli_symbol*) ALLOCPV(type_sym, 0); symbol->sym_type = SYM_keyword; symbol->sym_length = strlen(qword->keyword); symbol->sym_string = qword->keyword; symbol->sym_keyword = qword->id; HSH_insert(symbol, true); symbol->sym_object = (BLK) key_symbols; key_symbols = symbol; } }
DbImplementation DbImplementation::fromBackwardCompatibleByte(UCHAR bcImpl) { for (UCHAR os = 0; os < FB_NELEM(operatingSystem); ++os) { for (UCHAR hw = 0; hw < FB_NELEM(hardware); ++hw) { USHORT ind = USHORT(os) * FB_NELEM(hardware) + USHORT(hw); if (backwardTable[ind] == bcImpl) { return DbImplementation(hw, os, 0xFF, backEndianess[hw] ? EndianBig : EndianLittle); } } } return DbImplementation(0xFF, 0xFF, 0xFF, 0x80); }
void HSH_init() { /************************************** * * H S H _ i n i t * ************************************** * * Functional description * Initialize the hash table. This mostly involves * inserting all known keywords. * **************************************/ SYM symbol; int i; SSHORT length; for (i = 0; i < FB_NELEM(keywords); i++) { const char* string = keywords[i].keyword; for (length = 0; string[length] != '\0'; length++); symbol = (SYM) DDL_alloc(SYM_LEN); symbol->sym_type = SYM_keyword; symbol->sym_length = length; symbol->sym_string = keywords[i].keyword; symbol->sym_keyword = (int) keywords[i].id; HSH_insert(symbol); symbol->sym_object = (DUDLEY_CTX) key_symbols; key_symbols = symbol; } }
void StatusVector::ImplStatusVector::shiftLeft(const Base& arg) throw() { if (m_length < FB_NELEM(m_status_vector) - 2) { m_status_vector[m_length++] = arg.getKind(); m_status_vector[m_length++] = arg.getCode(); m_status_vector[m_length] = isc_arg_end; } }
int PRETTY_print_cdb( UCHAR* blr, FPTR_PRINT_CALLBACK routine, void* user_arg, SSHORT language) { ctl ctl_buffer; ctl* control = &ctl_buffer; if (!routine) { routine = gds__default_printer; user_arg = NULL; } control->ctl_routine = routine; control->ctl_user_arg = user_arg; control->ctl_blr = control->ctl_blr_start = blr; control->ctl_ptr = control->ctl_buffer; control->ctl_language = language; SSHORT level = 0; indent(control, level); const SSHORT i = BLR_BYTE; SCHAR temp[32]; if (*control->ctl_blr) sprintf(temp, "gds__dpb_version%d, ", i); else sprintf(temp, "gds__dpb_version%d", i); blr_format(control, temp); SSHORT offset = 0; print_line(control, offset); SSHORT parameter; while (parameter = BLR_BYTE) { const char* p; if (parameter > FB_NELEM(cdb_table) || !(p = cdb_table[parameter])) { return error(control, 0, "*** cdb parameter %d is undefined ***\n", parameter); } indent(control, level); blr_format(control, p); PUT_BYTE(','); int length = print_byte(control); if (length) { do { print_char(control, offset); } while (--length); } print_line(control, offset); } return 0; }
ConfigImpl::ConfigImpl(MemoryPool& p) : ConfigRoot(p), confMessage(p) { // Prepare some stuff ConfigFile file(p); root_dir = getRootDirectory(); const int size = FB_NELEM(entries); values = FB_NEW(p) ConfigValue[size]; //string val_sep = ","; file.setConfigFilePath(getConfigFilePath()); // Iterate through the known configuration entries for (int i = 0; i < size; i++) { const ConfigEntry entry = entries[i]; const string value = getValue(file, entries[i].key); if (!value.length()) { // Assign the default value values[i] = entries[i].default_value; continue; } // Assign the actual value switch (entry.data_type) { case TYPE_BOOLEAN: values[i] = (ConfigValue) asBoolean(value); break; case TYPE_INTEGER: values[i] = (ConfigValue) asInteger(value); break; case TYPE_STRING: { const char* src = asString(value); char* dst = FB_NEW(p) char[strlen(src) + 1]; strcpy(dst, src); values[i] = (ConfigValue) dst; } break; //case TYPE_STRING_VECTOR: // break; } } if (file.getMessage()) { confMessage = file.getMessage(); } }
StatusVector::ImplStatusVector::ImplStatusVector(const ISC_STATUS* s) throw() : Base::ImplBase(0, 0) { fb_assert(s); clear(); // special case - empty initialized status vector, no warnings if (s[0] != isc_arg_gds || s[1] != 0 || s[2] != 0) { append(s, FB_NELEM(m_status_vector) - 1); } }
bool StatusVector::ImplStatusVector::append(const ISC_STATUS* const from, const unsigned int count) throw() { // CVC: I didn't expect count to be zero but it's, in some calls fb_assert(count >= 0 && count <= ISC_STATUS_LENGTH); if (!count) return true; // not sure it's the best option here unsigned int copied = fb_utils::copyStatus(&m_status_vector[m_length], FB_NELEM(m_status_vector) - m_length, from, count); m_length += copied; return copied == count; }
HWND DisplayPropSheet(HWND hParentWnd, HINSTANCE hInst) { /****************************************************************************** * * D i s p l a y P r o p S h e e t * ****************************************************************************** * * Input: hParentWnd - Handle to the main window of this application * * Return: Handle to the Property sheet dialog if successful * NULL if error in displaying property sheet * * Description: This function initializes the page(s) of the property sheet, * and then calls the PropertySheet() function to display it. *****************************************************************************/ PROPSHEETPAGE PSPages[1]; HINSTANCE hInstance = hInst; PSPages[0].dwSize = sizeof(PROPSHEETPAGE); PSPages[0].dwFlags = PSP_USETITLE; PSPages[0].hInstance = hInstance; PSPages[0].pszTemplate = MAKEINTRESOURCE(IDD_PROPSHEET); PSPages[0].pszTitle = MAKEINTRESOURCE(IDS_PROP_TITLE); PSPages[0].pfnDlgProc = (DLGPROC) GeneralPage; PSPages[0].pfnCallback = NULL; PROPSHEETHEADER PSHdr; PSHdr.dwSize = sizeof(PROPSHEETHEADER); PSHdr.dwFlags = PSH_PROPTITLE | PSH_PROPSHEETPAGE | PSH_USEICONID | PSH_MODELESS | PSH_NOAPPLYNOW | PSH_NOCONTEXTHELP; PSHdr.hwndParent = hParentWnd; PSHdr.hInstance = hInstance; PSHdr.pszIcon = MAKEINTRESOURCE(IDI_IBGUARD); PSHdr.pszCaption = (LPSTR) GUARDIAN_APP_LABEL; PSHdr.nPages = FB_NELEM(PSPages); PSHdr.nStartPage = 0; PSHdr.ppsp = (LPCPROPSHEETPAGE) & PSPages; PSHdr.pfnCallback = NULL; hPSDlg = (HWND) PropertySheet(&PSHdr); if (hPSDlg == 0 || hPSDlg == (HWND) -1) { gds__log("Create property sheet window failed. Error code %d", GetLastError()); hPSDlg = NULL; } return hPSDlg; }
ISC_STATUS API_ROUTINE_VARARG gds__start_transaction(ISC_STATUS* status_vector, FB_API_HANDLE* tra_handle, SSHORT count, ...) { // This infamous structure is defined several times in different places struct teb_t { FB_API_HANDLE* teb_database; int teb_tpb_length; UCHAR* teb_tpb; }; teb_t tebs[16]; teb_t* teb = tebs; if (count > FB_NELEM(tebs)) teb = (teb_t*) gds__alloc(((SLONG) sizeof(teb_t) * count)); // FREE: later in this module if (!teb) { // NOMEM: status_vector[0] = isc_arg_gds; status_vector[1] = isc_virmemexh; status_vector[2] = isc_arg_end; return status_vector[1]; } const teb_t* const end = teb + count; va_list ptr; va_start(ptr, count); for (teb_t* teb_iter = teb; teb_iter < end; ++teb_iter) { teb_iter->teb_database = va_arg(ptr, FB_API_HANDLE*); teb_iter->teb_tpb_length = va_arg(ptr, int); teb_iter->teb_tpb = va_arg(ptr, UCHAR *); } va_end(ptr); const ISC_STATUS status = isc_start_multiple(status_vector, tra_handle, count, teb); if (teb != tebs) gds__free(teb); return status; }
void TimeStamp::round_time(ISC_TIME &ntime, const int precision) { const int scale = -ISC_TIME_SECONDS_PRECISION_SCALE - precision; // for the moment, if greater precision was requested than we can // provide return what we have. if (scale <= 0) return; static const ISC_TIME pow10table[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; fb_assert(scale < FB_NELEM(pow10table)); const ISC_TIME period = pow10table[scale]; ntime -= (ntime % period); }
ConfigImpl::~ConfigImpl() { const int size = FB_NELEM(entries); // Free allocated memory for (int i = 0; i < size; i++) { if (values[i] == entries[i].default_value) continue; switch (entries[i].data_type) { case TYPE_STRING: delete[] (char*) values[i]; break; //case TYPE_STRING_VECTOR: // break; } } delete[] values; }
int main( int argc, char* argv[]) { const SCHAR* const prog_name = argv[0]; if (argc < 2) { fprintf(stderr, "%s: No Command Line Option Specified\n", argv[0]); print_clo(prog_name); return FB_FAILURE; } // Fields initialization b_fil* file_ptr = NULL; b_fil* file_list = NULL; b_fil* prev_file = NULL; SINT64 file_size = -1; gsplit_option sw_replace = IN_SW_SPIT_0; // Initialize in_sw_table table. const Switches switches(spit_in_sw_table, FB_NELEM(spit_in_sw_table), false, false); // validating command line options SLONG ret_cd, file_num = 0; bool file_nm_sw = false; const SCHAR* string = NULL; const SCHAR* const* const end = argv + argc; ++argv; while (argv < end) { string = *argv; if (*string == '-') { argv++; ret_cd = get_function_option(prog_name, &sw_replace, string, switches); if (ret_cd == FB_FAILURE) { free_file_list(file_list); return FB_FAILURE; } } // end of processing (*string == '-') else { // processing function specific command line options switch (sw_replace) { case IN_SW_SPIT_SP: if (!file_nm_sw) { // process file name file_size = 0; file_num = file_num + 1; if (file_num > MAX_NUM_OF_FILES) { fprintf(stderr, "%s: maximum of files is %d\n", prog_name, MAX_NUM_OF_FILES); print_clo(prog_name); free_file_list(file_list); return FB_FAILURE; } if (strlen(string) > MAX_FILE_NM_LEN) { fprintf(stderr, "%s: file name %s is too long\n", prog_name, string); fprintf(stderr, "%s: maximum length of file name is %"SIZEFORMAT" bytes\n", prog_name, MAX_FILE_NM_LEN); print_clo(prog_name); free_file_list(file_list); return FB_FAILURE; } ret_cd = get_file_name(string, file_size, &file_ptr); if (ret_cd == FB_FAILURE) { free_file_list(file_list); return FB_FAILURE; } file_nm_sw = true; file_ptr->b_fil_number = file_num; if (!file_list) file_list = prev_file = file_ptr; else { prev_file->b_fil_next = file_ptr; prev_file = file_ptr; } } // processing file name else { // processing file size file_nm_sw = false; ret_cd = get_file_size(prog_name, string, &file_size); if (ret_cd == FB_FAILURE) { free_file_list(file_list); return FB_FAILURE; } } // end of processing file size specification file_ptr->b_fil_size = file_size; break; case IN_SW_SPIT_JT: ret_cd = get_file_name(string, file_size, &file_ptr); if (ret_cd == FB_FAILURE) { free_file_list(file_list); return FB_FAILURE; } file_num = file_num + 1; file_ptr->b_fil_number = file_num; if (!file_list) file_list = prev_file = file_ptr; else { prev_file->b_fil_next = file_ptr; prev_file = file_ptr; } // end of processing file size specification break; default: fprintf(stderr, "%s: invalid option '%s'\n", prog_name, string); print_clo(prog_name); free_file_list(file_list); return FB_FAILURE; } // end of switch (sw_replace) argv++; } // processing function specific command line options } // while (argv < end) if (!file_list && sw_replace != IN_SW_SPIT_0) { fprintf(stderr, "%s: invalid option '%s', rest of parameters is missing\n", prog_name, string); print_clo(prog_name); free_file_list(file_list); return FB_FAILURE; } FILE_DESC input_file_desc; switch (sw_replace) { case IN_SW_SPIT_SP: input_file_desc = GBAK_STDIN_DESC(); ret_cd = gen_multy_bakup_files(file_list, input_file_desc, file_num); if (ret_cd == FB_FAILURE) { fprintf(stderr, "%s: progam fails to generate multi-volumn back-up files\n", prog_name); free_file_list(file_list); return FB_FAILURE; } break; case IN_SW_SPIT_JT: ret_cd = join_multy_bakup_files(file_list); if (ret_cd == FB_FAILURE) { fprintf(stderr, "%s: progam fails to join multi-volumn back-up files\n", prog_name); free_file_list(file_list); return FB_FAILURE; } break; default: break; } // free all the storage allocated for backup files free_file_list(file_list); return FB_SUCCESS; } // end of main()
// Build full file name in specified directory Firebird::PathName getPrefix(unsigned int prefType, const char* name) { Firebird::PathName s; char tmp[MAXPATHLEN]; const char* configDir[] = { FB_BINDIR, FB_SBINDIR, FB_CONFDIR, FB_LIBDIR, FB_INCDIR, FB_DOCDIR, FB_UDFDIR, FB_SAMPLEDIR, FB_SAMPLEDBDIR, FB_HELPDIR, FB_INTLDIR, FB_MISCDIR, FB_SECDBDIR, FB_MSGDIR, FB_LOGDIR, FB_GUARDDIR, FB_PLUGDIR }; fb_assert(FB_NELEM(configDir) == Firebird::IConfigManager::DIR_COUNT); fb_assert(prefType < Firebird::IConfigManager::DIR_COUNT); if (! bootBuild()) { if (prefType != Firebird::IConfigManager::DIR_CONF && prefType != Firebird::IConfigManager::DIR_MSG && configDir[prefType][0]) { // Value is set explicitly and is not environment overridable PathUtils::concatPath(s, configDir[prefType], name); return s; } } switch(prefType) { case Firebird::IConfigManager::DIR_BIN: case Firebird::IConfigManager::DIR_SBIN: #ifdef WIN_NT s = ""; #else s = "bin"; #endif break; case Firebird::IConfigManager::DIR_CONF: case Firebird::IConfigManager::DIR_LOG: case Firebird::IConfigManager::DIR_GUARD: case Firebird::IConfigManager::DIR_SECDB: s = ""; break; case Firebird::IConfigManager::DIR_LIB: #ifdef WIN_NT s = ""; #else s = "lib"; #endif break; case Firebird::IConfigManager::DIR_PLUGINS: s = "plugins"; break; case Firebird::IConfigManager::DIR_INC: s = "include"; break; case Firebird::IConfigManager::DIR_DOC: s = "doc"; break; case Firebird::IConfigManager::DIR_UDF: s = "UDF"; break; case Firebird::IConfigManager::DIR_SAMPLE: s = "examples"; break; case Firebird::IConfigManager::DIR_SAMPLEDB: s = "examples/empbuild"; break; case Firebird::IConfigManager::DIR_HELP: s = "help"; break; case Firebird::IConfigManager::DIR_INTL: s = "intl"; break; case Firebird::IConfigManager::DIR_MISC: s = "misc"; break; case Firebird::IConfigManager::DIR_MSG: gds__prefix_msg(tmp, name); return tmp; default: fb_assert(false); break; } if (s.hasData() && name[0]) { s += '/'; } s += name; gds__prefix(tmp, s.c_str()); return tmp; }
static int print_dyn_verb( ctl* control, SSHORT level) { const SSHORT offset = control->ctl_blr - control->ctl_blr_start; const UCHAR dyn_operator = BLR_BYTE; const char* p; const int size = FB_NELEM(dyn_table); if (dyn_operator > size || dyn_operator <= 0 || !(p = dyn_table[dyn_operator])) { return error(control, offset, "*** dyn operator %d is undefined ***\n", (int) dyn_operator); } indent(control, level); blr_format(control, p); PUT_BYTE(','); PUT_BYTE(' '); ++level; int length; switch (dyn_operator) { case isc_dyn_drop_difference: case isc_dyn_begin_backup: case isc_dyn_end_backup: return 0; case isc_dyn_begin: case isc_dyn_mod_database: print_line(control, offset); while (NEXT_BYTE != isc_dyn_end) PRINT_DYN_VERB; PRINT_DYN_VERB; return 0; case isc_dyn_view_blr: case isc_dyn_fld_validation_blr: case isc_dyn_fld_computed_blr: case isc_dyn_trg_blr: case isc_dyn_fld_missing_value: case isc_dyn_prc_blr: case isc_dyn_fld_default_value: length = print_word(control); print_line(control, offset); if (length) { control->ctl_level = level; fb_print_blr(control->ctl_blr, length, print_blr_line, control, control->ctl_language); control->ctl_blr += length; } return 0; case isc_dyn_scl_acl: // case isc_dyn_log_check_point_length: // case isc_dyn_log_num_of_buffers: // case isc_dyn_log_buffer_size: // case isc_dyn_log_group_commit_wait: case isc_dyn_idx_inactive: length = print_word(control); while (length--) print_byte(control); print_line(control, offset); return 0; case isc_dyn_view_source: case isc_dyn_fld_validation_source: case isc_dyn_fld_computed_source: case isc_dyn_description: case isc_dyn_prc_source: case isc_dyn_fld_default_source: length = print_word(control); while (length--) print_char(control, offset); print_line(control, offset); return 0; case isc_dyn_del_exception: if (length = print_word(control)) do { print_char(control, offset); } while (--length); return 0; case isc_dyn_fld_not_null: case isc_dyn_sql_object: // case isc_dyn_drop_log: // case isc_dyn_drop_cache: // case isc_dyn_def_default_log: // case isc_dyn_log_file_serial: // case isc_dyn_log_file_raw: // case isc_dyn_log_file_overflow: case isc_dyn_single_validation: case isc_dyn_del_computed: case isc_dyn_del_default: case isc_dyn_del_validation: case isc_dyn_idx_statistic: case isc_dyn_foreign_key_delete: case isc_dyn_foreign_key_update: case isc_dyn_foreign_key_cascade: case isc_dyn_foreign_key_default: case isc_dyn_foreign_key_null: case isc_dyn_foreign_key_none: print_line(control, offset); return 0; case isc_dyn_end: print_line(control, offset); return 0; } if (length = print_word(control)) do { print_char(control, offset); } while (--length); print_line(control, offset); switch (dyn_operator) { case isc_dyn_def_database: case isc_dyn_def_dimension: case isc_dyn_def_exception: case isc_dyn_def_file: // case isc_dyn_def_log_file: // case isc_dyn_def_cache_file: case isc_dyn_def_filter: case isc_dyn_def_function: case isc_dyn_def_function_arg: case isc_dyn_def_generator: case isc_dyn_def_global_fld: case isc_dyn_def_idx: case isc_dyn_def_local_fld: case isc_dyn_def_rel: case isc_dyn_def_procedure: case isc_dyn_def_parameter: case isc_dyn_def_security_class: case isc_dyn_def_shadow: case isc_dyn_def_sql_fld: case isc_dyn_def_trigger: case isc_dyn_def_trigger_msg: case isc_dyn_def_view: case isc_dyn_delete_database: case isc_dyn_delete_dimensions: case isc_dyn_delete_filter: case isc_dyn_delete_function: case isc_dyn_delete_global_fld: case isc_dyn_delete_idx: case isc_dyn_delete_local_fld: case isc_dyn_delete_rel: case isc_dyn_delete_procedure: case isc_dyn_delete_parameter: case isc_dyn_delete_security_class: case isc_dyn_delete_trigger: case isc_dyn_delete_trigger_msg: case isc_dyn_delete_shadow: case isc_dyn_mod_exception: case isc_dyn_mod_global_fld: case isc_dyn_mod_idx: case isc_dyn_mod_local_fld: case isc_dyn_mod_procedure: case isc_dyn_mod_rel: case isc_dyn_mod_security_class: case isc_dyn_mod_trigger: case isc_dyn_mod_trigger_msg: case isc_dyn_rel_constraint: case isc_dyn_mod_view: case isc_dyn_grant: case isc_dyn_revoke: case isc_dyn_view_relation: case isc_dyn_def_sql_role: while (NEXT_BYTE != isc_dyn_end) PRINT_DYN_VERB; PRINT_DYN_VERB; return 0; } return 0; }
static int print_sdl_verb( ctl* control, SSHORT level) { const char* p; SSHORT offset = control->ctl_blr - control->ctl_blr_start; const UCHAR sdl_operator = BLR_BYTE; if (sdl_operator > FB_NELEM(sdl_table) || sdl_operator <= 0 || !(p = sdl_table[sdl_operator])) { return error(control, offset, "*** SDL operator %d is undefined ***\n", (int) sdl_operator); } indent(control, level); blr_format(control, p); PUT_BYTE(','); PUT_BYTE(' '); ++level; int n = 0; switch (sdl_operator) { case isc_sdl_begin: print_line(control, offset); while (NEXT_BYTE != isc_sdl_end) PRINT_SDL_VERB; PRINT_SDL_VERB; return 0; case isc_sdl_struct: n = print_byte(control); while (n--) { print_line(control, offset); indent(control, level + 1); offset = control->ctl_blr - control->ctl_blr_start; print_blr_dtype(control, true); } break; case isc_sdl_scalar: print_byte(control); case isc_sdl_element: n = print_byte(control); print_line(control, offset); while (n--) PRINT_SDL_VERB; return 0; case isc_sdl_field: case isc_sdl_relation: print_string(control, offset); break; case isc_sdl_fid: case isc_sdl_rid: case isc_sdl_short_integer: print_word(control); break; case isc_sdl_variable: case isc_sdl_tiny_integer: print_byte(control); break; case isc_sdl_long_integer: print_long(control); break; case isc_sdl_add: case isc_sdl_subtract: case isc_sdl_multiply: case isc_sdl_divide: print_line(control, offset); PRINT_SDL_VERB; PRINT_SDL_VERB; return 0; case isc_sdl_negate: print_line(control, offset); PRINT_SDL_VERB; return 0; case isc_sdl_do3: n++; case isc_sdl_do2: n++; case isc_sdl_do1: n += 2; print_byte(control); print_line(control, offset); while (n--) PRINT_SDL_VERB; return 0; } print_line(control, offset); return 0; }
void fbtrace(UtilSvc* uSvc, TraceSvcIntf* traceSvc) { const char* const* end = uSvc->argv.end(); bool version = false, help = false; // search for "action" switch, set NULL into recognized argv const Switches actSwitches(trace_action_in_sw_table, FB_NELEM(trace_action_in_sw_table), false, true); const Switches::in_sw_tab_t* action_sw = NULL; const char** argv = uSvc->argv.begin(); for (++argv; argv < end; argv++) { if (!uSvc->isService() && strcmp(argv[0], "-?") == 0) { help = true; *argv = NULL; break; } const Switches::in_sw_tab_t* sw = actSwitches.findSwitch(*argv); if (sw) { if (sw->in_sw == IN_SW_TRACE_VERSION) { version = true; *argv = NULL; continue; } if (action_sw) usage(uSvc, isc_trace_conflict_acts, action_sw->in_sw_name, sw->in_sw_name); else action_sw = sw; *argv = NULL; } } if (version) { printMsg(1, SafeArg() << FB_VERSION); if (!action_sw) exit(FINI_OK); } if (!action_sw) { if (help) usage(uSvc, 0); else usage(uSvc, isc_trace_act_notfound); } // search for action's parameters, set NULL into recognized argv const Switches optSwitches(trace_option_in_sw_table, FB_NELEM(trace_option_in_sw_table), false, true); TraceSession session(*getDefaultMemoryPool()); argv = uSvc->argv.begin(); for (++argv; argv < end; argv++) { if (!*argv) continue; const Switches::in_sw_tab_t* sw = optSwitches.findSwitch(*argv); if (!sw) continue; *argv = NULL; switch (sw->in_sw) { case IN_SW_TRACE_CONFIG: switch (action_sw->in_sw) { case IN_SW_TRACE_STOP: case IN_SW_TRACE_SUSPEND: case IN_SW_TRACE_RESUME: case IN_SW_TRACE_LIST: usage(uSvc, isc_trace_param_act_notcompat, sw->in_sw_name, action_sw->in_sw_name); break; } if (!session.ses_config.empty()) usage(uSvc, isc_trace_switch_once, sw->in_sw_name); argv++; if (argv < end && *argv) session.ses_config = *argv; else usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name); break; case IN_SW_TRACE_NAME: switch (action_sw->in_sw) { case IN_SW_TRACE_STOP: case IN_SW_TRACE_SUSPEND: case IN_SW_TRACE_RESUME: case IN_SW_TRACE_LIST: usage(uSvc, isc_trace_param_act_notcompat, sw->in_sw_name, action_sw->in_sw_name); break; } if (!session.ses_name.empty()) usage(uSvc, isc_trace_switch_once, sw->in_sw_name); argv++; if (argv < end && *argv) session.ses_name = *argv; else usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name); break; case IN_SW_TRACE_ID: switch (action_sw->in_sw) { case IN_SW_TRACE_START: case IN_SW_TRACE_LIST: usage(uSvc, isc_trace_param_act_notcompat, sw->in_sw_name, action_sw->in_sw_name); break; } if (session.ses_id) usage(uSvc, isc_trace_switch_once, sw->in_sw_name); argv++; if (argv < end && *argv) { session.ses_id = atol(*argv); if (!session.ses_id) usage(uSvc, isc_trace_param_invalid, *argv, sw->in_sw_name); } else usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name); break; default: fb_assert(false); } *argv = NULL; } // search for authentication parameters const Switches authSwitches(trace_auth_in_sw_table, FB_NELEM(trace_auth_in_sw_table), false, true); string svc_name, user, pwd; bool adminRole = false; argv = uSvc->argv.begin(); for (++argv; argv < end; argv++) { if (!*argv) continue; const Switches::in_sw_tab_t* sw = authSwitches.findSwitch(*argv); if (!sw) { usage(uSvc, isc_trace_switch_unknown, *argv); } switch (sw->in_sw) { case IN_SW_TRACE_USERNAME: if (!user.empty()) usage(uSvc, isc_trace_switch_once, sw->in_sw_name); argv++; if (argv < end && *argv) user = *argv; else usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name); break; case IN_SW_TRACE_PASSWORD: if (!pwd.empty()) usage(uSvc, isc_trace_switch_once, sw->in_sw_name); argv++; if (argv < end && *argv) pwd = *argv; else usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name); break; case IN_SW_TRACE_FETCH_PWD: if (uSvc->isService()) usage(uSvc, isc_trace_switch_user_only, sw->in_sw_name); if (!pwd.empty()) usage(uSvc, isc_trace_switch_once, sw->in_sw_name); argv++; if (argv < end && *argv) { const PathName fileName(*argv); const char *s = NULL; switch (fb_utils::fetchPassword(fileName, s)) { case fb_utils::FETCH_PASS_OK: pwd = s; break; case fb_utils::FETCH_PASS_FILE_OPEN_ERROR: (Arg::Gds(isc_io_error) << Arg::Str("open") << Arg::Str(fileName) << Arg::Gds(isc_io_open_err) << Arg::OsError()).raise(); break; case fb_utils::FETCH_PASS_FILE_READ_ERROR: case fb_utils::FETCH_PASS_FILE_EMPTY: (Arg::Gds(isc_io_error) << Arg::Str("read") << Arg::Str(fileName) << Arg::Gds(isc_io_read_err) << Arg::OsError()).raise(); break; } } else usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name); break; case IN_SW_TRACE_TRUSTED_AUTH: if (uSvc->isService()) usage(uSvc, isc_trace_switch_user_only, sw->in_sw_name); adminRole = true; break; case IN_SW_TRACE_SERVICE_NAME: if (uSvc->isService()) continue; if (!svc_name.empty()) usage(uSvc, isc_trace_switch_once, sw->in_sw_name); argv++; if (argv < end && *argv) svc_name = *argv; else usage(uSvc, isc_trace_param_val_miss, sw->in_sw_name); break; default: fb_assert(false); } } // validate missed action's parameters and perform action if (!uSvc->isService() && svc_name.isEmpty()) { usage(uSvc, isc_trace_mandatory_switch_miss, "SERVICE"); } if (!session.ses_id) { switch (action_sw->in_sw) { case IN_SW_TRACE_STOP: case IN_SW_TRACE_SUSPEND: case IN_SW_TRACE_RESUME: usage(uSvc, isc_trace_switch_param_miss, "ID", action_sw->in_sw_name); break; } } if (session.ses_config.empty()) { if (action_sw->in_sw == IN_SW_TRACE_START) { usage(uSvc, isc_trace_switch_param_miss, "CONFIG", action_sw->in_sw_name); } } AuthReader::AuthBlock authBlock; const unsigned char* bytes; unsigned int authBlockSize = uSvc->getAuthBlock(&bytes); if (authBlockSize) { authBlock.add(bytes, authBlockSize); pwd = ""; user = ""; adminRole = false; } traceSvc->setAttachInfo(svc_name, user, pwd, authBlock, adminRole); switch (action_sw->in_sw) { case IN_SW_TRACE_START: traceSvc->startSession(session, true); break; case IN_SW_TRACE_STOP: traceSvc->stopSession(session.ses_id); break; case IN_SW_TRACE_SUSPEND: traceSvc->setActive(session.ses_id, false); break; case IN_SW_TRACE_RESUME: traceSvc->setActive(session.ses_id, true); break; case IN_SW_TRACE_LIST: traceSvc->listSessions(); break; default: fb_assert(false); } }
TextType::TextType(TTYPE_ID _type, texttype *_tt, CharSet* _cs) : tt(_tt), cs(_cs), type(_type) { canonical(cs->getSqlMatchAnyLength(), cs->getSqlMatchAny(), sizeof(ULONG), reinterpret_cast<UCHAR*>(&canonicalChars[CHAR_SQL_MATCH_ANY])); canonical(cs->getSqlMatchOneLength(), cs->getSqlMatchOne(), sizeof(ULONG), reinterpret_cast<UCHAR*>(&canonicalChars[CHAR_SQL_MATCH_ONE])); struct Conversion { USHORT code; int ch; }; const Conversion conversions[] = { {'*', CHAR_ASTERISK}, {'@', CHAR_AT}, {'^', CHAR_CIRCUMFLEX}, {':', CHAR_COLON}, {',', CHAR_COMMA}, {'=', CHAR_EQUAL}, {'-', CHAR_MINUS}, {'%', CHAR_PERCENT}, {'+', CHAR_PLUS}, {'?', CHAR_QUESTION_MARK}, {' ', CHAR_SPACE}, {'~', CHAR_TILDE}, {'_', CHAR_UNDERLINE}, {'|', CHAR_VERTICAL_BAR}, {'{', CHAR_OPEN_BRACE}, {'}', CHAR_CLOSE_BRACE}, {'[', CHAR_OPEN_BRACKET}, {']', CHAR_CLOSE_BRACKET}, {'(', CHAR_OPEN_PAREN}, {')', CHAR_CLOSE_PAREN}, {'s', CHAR_LOWER_S}, {'S', CHAR_UPPER_S} }; for (int i = 0; i < FB_NELEM(conversions); i++) { UCHAR temp[sizeof(ULONG)]; ULONG length = getCharSet()->getConvFromUnicode().convert( sizeof(USHORT), &conversions[i].code, sizeof(temp), temp); canonical(length, temp, sizeof(ULONG), reinterpret_cast<UCHAR*>(&canonicalChars[conversions[i].ch])); } struct Conversion2 { const char* str; UCHAR* buffer; }; const Conversion2 conversions2[] = { {"0123456789", reinterpret_cast<UCHAR*>(canonicalNumbers)}, {"abcdefghijklmnopqrstuvwxyz", reinterpret_cast<UCHAR*>(canonicalLowerLetters)}, {"ABCDEFGHIJKLMNOPQRSTUVWXYZ", reinterpret_cast<UCHAR*>(canonicalUpperLetters)}, {" \t\v\r\n\f", reinterpret_cast<UCHAR*>(canonicalWhiteSpaces)} }; for (int i = 0; i < FB_NELEM(conversions2); i++) { UCHAR temp[sizeof(ULONG)]; for (const char* p = conversions2[i].str; *p; ++p) { USHORT code = static_cast<USHORT>(*p); ULONG length = getCharSet()->getConvFromUnicode().convert(sizeof(code), &code, sizeof(temp), temp); const size_t pos = (p - conversions2[i].str) * getCanonicalWidth(); canonical(length, temp, sizeof(ULONG), &conversions2[i].buffer[pos]); } } }