void createRestoreBuffer(VALUE file, VALUE database, VALUE options, char **buffer, short *length) { char *offset = NULL; int number = 0; long mask = 0; VALUE cache = rb_hash_aref(options, CACHE_BUFFERS), page = rb_hash_aref(options, PAGE_SIZE), mode = rb_hash_aref(options, ACCESS_MODE), policy = rb_hash_aref(options, RESTORE_MODE); /* Determine the length of the buffer. */ *length = 7; *length += strlen(STR2CSTR(file)) + 3; *length += strlen(STR2CSTR(database)) + 3; if(cache != Qnil) { *length += 5; } if(page != Qnil) { *length += 5; } if(mode != Qnil) { *length += 2; } /* Create and populate the buffer. */ offset = *buffer = ALLOC_N(char, *length); if(buffer == NULL) { rb_raise(rb_eNoMemError, "Memory allocation error preparing database restore."); } memset(*buffer, 8, *length); *offset++ = isc_action_svc_restore; number = strlen(STR2CSTR(file)); *offset++ = isc_spb_bkp_file; ADD_SPB_LENGTH(offset, number); memcpy(offset, STR2CSTR(file), number); offset += number; number = strlen(STR2CSTR(database)); *offset++ = isc_spb_dbname; ADD_SPB_LENGTH(offset, number); memcpy(offset, STR2CSTR(database), number); offset += number; if(cache != Qnil) { long value; value = TYPE(cache) == T_FIXNUM ? FIX2INT(cache) : NUM2INT(cache); *offset++ = isc_spb_res_buffers; ADD_SPB_NUMERIC(offset, value); } if(page != Qnil) { long value; value = TYPE(page) == T_FIXNUM ? FIX2INT(page) : NUM2INT(page); *offset++ = isc_spb_res_page_size; ADD_SPB_NUMERIC(offset, value); } if(mode != Qnil) { *offset++ = isc_spb_res_access_mode; *offset++ = (char)FIX2INT(mode); } mask = FIX2INT(policy); if(rb_hash_aref(options, BUILD_INDICES) == Qfalse) { mask |= isc_spb_res_deactivate_idx; } if(rb_hash_aref(options, NO_SHADOWS) == Qtrue) { mask |= isc_spb_res_no_shadow; } if(rb_hash_aref(options, VALIDITY_CHECKS) == Qfalse) { mask |= isc_spb_res_no_validity; } if(rb_hash_aref(options, COMMIT_TABLES) == Qtrue) { mask |= isc_spb_res_one_at_a_time; } if(rb_hash_aref(options, USE_ALL_SPACE) == Qtrue) { mask |= isc_spb_res_use_all_space; } *offset++ = isc_spb_options; ADD_SPB_NUMERIC(offset, mask); *offset++ = isc_spb_verbose; }
void createAddUserBuffer(VALUE self, char **buffer, short *length) { VALUE value = Qnil, first = Qnil, middle = Qnil, last = Qnil; char *offset = NULL; int number = 0; /* Calculate the required buffer length. */ *length = 1; *length += strlen(STR2CSTR(rb_iv_get(self, "@user_name"))) + 3; *length += strlen(STR2CSTR(rb_iv_get(self, "@password"))) + 3; value = rb_iv_get(self, "@first_name"); if(value != Qnil) { first = rb_funcall(value, rb_intern("to_s"), 0); *length += strlen(STR2CSTR(first)) + 3; } value = rb_iv_get(self, "@middle_name"); if(value != Qnil) { middle = rb_funcall(value, rb_intern("to_s"), 0); *length += strlen(STR2CSTR(middle)) + 3; } value = rb_iv_get(self, "@last_name"); if(value != Qnil) { last = rb_funcall(value, rb_intern("to_s"), 0); *length += strlen(STR2CSTR(last)) + 3; } /* Create and populate the buffer. */ offset = *buffer = ALLOC_N(char, *length); if(*buffer == NULL) { rb_raise(rb_eNoMemError, "Memory allocation error preparing to add user."); } memset(*buffer, 0, *length); *offset++ = isc_action_svc_add_user; *offset++ = isc_spb_sec_username; value = rb_iv_get(self, "@user_name"); number = strlen(STR2CSTR(value)); ADD_SPB_LENGTH(offset, number); memcpy(offset, STR2CSTR(value), number); offset += number; *offset++ = isc_spb_sec_password; value = rb_iv_get(self, "@password"); number = strlen(STR2CSTR(value)); ADD_SPB_LENGTH(offset, number); memcpy(offset, STR2CSTR(value), number); offset += number; if(first != Qnil) { *offset++ = isc_spb_sec_firstname; number = strlen(STR2CSTR(first)); ADD_SPB_LENGTH(offset, number); memcpy(offset, STR2CSTR(first), number); offset += number; } if(middle != Qnil) { *offset++ = isc_spb_sec_middlename; number = strlen(STR2CSTR(middle)); ADD_SPB_LENGTH(offset, number); memcpy(offset, STR2CSTR(middle), number); offset += number; } if(last != Qnil) { *offset++ = isc_spb_sec_lastname; number = strlen(STR2CSTR(last)); ADD_SPB_LENGTH(offset, number); memcpy(offset, STR2CSTR(last), number); offset += number; } }
void TraceSvcUtil::runService(size_t spbSize, const UCHAR* spb) { os_utils::CtrlCHandler ctrlCHandler; ISC_STATUS_ARRAY status; if (isc_service_start(status, &m_svcHandle, 0, static_cast<USHORT>(spbSize), reinterpret_cast<const char*>(spb))) { status_exception::raise(status); } const char query[] = {isc_info_svc_to_eof, isc_info_end}; // use one second timeout to poll service char send[16]; char* p = send; *p++ = isc_info_svc_timeout; ADD_SPB_LENGTH(p, 4); ADD_SPB_NUMERIC(p, 1); *p++ = isc_info_end; const USHORT sendSize = (p - send); char results[MAXBUF]; bool noData; do { if (isc_service_query(status, &m_svcHandle, 0, sendSize, send, sizeof(query), query, sizeof(results) - 1, results)) { status_exception::raise(status); } p = results; bool ignoreTruncation = false; bool dirty = false; noData = true; while (*p != isc_info_end) { const UCHAR item = *p++; switch (item) { case isc_info_svc_to_eof: ignoreTruncation = true; case isc_info_svc_line: { const unsigned short l = isc_vax_integer(p, sizeof(l)); p += sizeof(l); if (l) { const char ch = p[l]; p[l] = 0; fprintf(stdout, "%s", p); p[l] = ch; p += l; dirty = true; } noData = (l == 0); } break; case isc_info_truncated: if (!ignoreTruncation) return; break; case isc_info_svc_timeout: case isc_info_data_not_ready: noData = false; if (dirty) { fflush(stdout); dirty = false; } break; default: status_exception::raise(Arg::Gds(isc_fbsvcmgr_query_err) << Arg::Num(static_cast<unsigned char>(p[-1]))); } } } while (!(ctrlCHandler.getTerminated() || noData)); }
/** * This function creates a service parameter buffer for backup service * requests. * * @param from A reference to a String containing the path and name of the * database file to be backed up. * @param to Either a reference to a String containing the path and name * of the backup file or a hash matching file path/names to * their permitted sizes. * @param options A reference to a Hash containing the parameter options to * be used. * @param buffer A pointer that will be set to the generated parameter * buffer. * @param length A pointer to a short integer that will be assigned the * length of buffer. * */ void createBackupBuffer(VALUE from, VALUE to, VALUE options, char **buffer, short *length) { ID id = rb_intern("key?"); VALUE names = rb_funcall(to, rb_intern("keys"), 0), sizes = rb_funcall(to, rb_intern("values"), 0), count = rb_funcall(names, rb_intern("size"), 0), tmp_str = Qnil; char *position = NULL; short number, flags = 0, extras = 0, blocking = 0, size = TYPE(count) == T_FIXNUM ? FIX2INT(count) : NUM2INT(count), i; /* Check if extra options have been provided. */ if(TYPE(options) != T_NIL) { VALUE temp = rb_funcall(options, rb_intern("size"), 0); extras = TYPE(temp) == T_FIXNUM ? FIX2INT(temp) : NUM2INT(temp); } /* Calculate the length needed for the buffer. */ *length = 2; *length += strlen(StringValuePtr(from)) + 3; /* Count file name and length sizes. */ for(i = 0; i < size; i++) { tmp_str = rb_ary_entry(names, i); *length += strlen(StringValuePtr(tmp_str)) + 3; if(i != size - 1) { VALUE num = rb_funcall(rb_ary_entry(sizes, i), rb_intern("to_s"), 0); *length += strlen(StringValuePtr(num)) + 3; } } if(extras) { if(rb_funcall(options, id, 1, INT2FIX(isc_spb_bkp_factor)) == Qtrue) { *length += 5; blocking = 1; } if(rb_funcall(options, id, 1, IGNORE_CHECKSUMS) == Qtrue || rb_funcall(options, id, 1, IGNORE_LIMBO) == Qtrue || rb_funcall(options, id, 1, METADATA_ONLY) == Qtrue || rb_funcall(options, id, 1, NO_GARBAGE_COLLECT) == Qtrue || rb_funcall(options, id, 1, NON_TRANSPORTABLE) == Qtrue || rb_funcall(options, id, 1, CONVERT_TABLES) == Qtrue) { *length += 5; flags = 1; } } /* Allocate the buffer. */ *buffer = position = ALLOC_N(char, *length); if(*buffer == NULL) { rb_raise(rb_eNoMemError, "Memory allocation error preparing database back up."); } memset(*buffer, 0, *length); /* Populate the buffer. */ *position++ = isc_action_svc_backup; *position++ = isc_spb_dbname; number = strlen(StringValuePtr(from)); ADD_SPB_LENGTH(position, number); memcpy(position, StringValuePtr(from), number); position += number; for(i = 0; i < size; i++) { VALUE name = rb_ary_entry(names, i); *position++ = isc_spb_bkp_file; number = strlen(StringValuePtr(name)); ADD_SPB_LENGTH(position, number); memcpy(position, StringValuePtr(name), number); position += number; if(i != size - 1) { VALUE max = rb_ary_entry(sizes, i); max = rb_funcall(max, rb_intern("to_s"), 0); *position++ = isc_spb_bkp_length; number = strlen(StringValuePtr(max)); ADD_SPB_LENGTH(position, number); memcpy(position, StringValuePtr(max), number); position += number; } } if(extras && blocking) { VALUE key = INT2FIX(isc_spb_bkp_factor), temp = rb_funcall(options, rb_intern("fetch"), 1, key); unsigned long size = TYPE(temp) == T_FIXNUM ? FIX2INT(temp) : NUM2INT(temp); *position++ = isc_spb_bkp_factor; memcpy(position, &size, 4); position += 4; } if(extras && flags) { unsigned long mask = 0; if(rb_funcall(options, id, 1, IGNORE_CHECKSUMS) == Qtrue) { mask |= isc_spb_bkp_ignore_checksums; } if(rb_funcall(options, id, 1, IGNORE_LIMBO) == Qtrue) { mask |= isc_spb_bkp_ignore_limbo; } if(rb_funcall(options, id, 1, METADATA_ONLY) == Qtrue) { mask |= isc_spb_bkp_metadata_only; } if(rb_funcall(options, id, 1, NO_GARBAGE_COLLECT) == Qtrue) { mask |= isc_spb_bkp_no_garbage_collect; } if(rb_funcall(options, id, 1, NON_TRANSPORTABLE) == Qtrue) { mask |= isc_spb_bkp_non_transportable; } if(rb_funcall(options, id, 1, CONVERT_TABLES) == Qtrue) { mask |= isc_spb_bkp_convert; } *position++ = isc_spb_options; memcpy(position, &mask, 4); position += 4; } *position++ = isc_spb_verbose; }