static struct custom_data *decode_custom_data(unsigned char *buf, int len, struct custom_data *d) { gint ix = 0; gboolean err = FALSE; LOG("%s: len=%d", __FUNCTION__, len); while (ix < len && !err) { LOG("buf[%d]=0x%02x=%d", ix, buf[ix], buf[ix]); switch (buf[ix++]) { case CD_VERSION: { gint ver; ix += get_byte(&(buf[ix]), &ver); if (ver != 0) ERROR("Wrong version %d", ver); } break; case CD_NAME_LONG: LOG("CD_NAME_LONG"); ix += get_string(&(buf[ix]), d->name_long); break; case CD_NAME_SHORT: LOG("CD_NAME_SHORT"); ix += get_string(&(buf[ix]), d->name_short); break; case CD_COMPETITORS_MIN: GET_SHORT(d->competitors_min); LOG("CD_COMPETITORS_MIN = %d", d->competitors_min); break; case CD_COMPETITORS_MAX: GET_SHORT(d->competitors_max); LOG("CD_COMPETITORS_MAX = %d", d->competitors_max); break; case CD_NUM_RR_POOLS: LOG("CD_NUM_RR_POOLS"); ix += get_rr_pools(&(buf[ix]), d, &err); break; case CD_NUM_MATCHES: LOG("CD_NUM_MATCHES"); ix += get_matches(&(buf[ix]), d, &err); break; case CD_NUM_POSITIONS: LOG("CD_NUM_POSITIONS"); ix += get_positions(&(buf[ix]), d, &err); break; case CD_NUM_B3_POOLS: ix += get_best_of_three_pairs(&(buf[ix]), d, &err); break; case CD_NUM_GROUPS: ix += get_groups(&(buf[ix]), d, &err); break; default: g_print("Unknown CD type %d\n", buf[ix-1]); return NULL; } } if (err) return NULL; return d; }
long SDMSerreqst::Unmarshal(const char* buf) { int cur; cur = UnmarshalHeader(buf); if(cur==SDM_INVALID_MESSAGE) { return SDM_INVALID_MESSAGE; } if(total_length>msg_length) { return SDM_INVALID_MESSAGE; } cur += source.Unmarshal(buf,cur); cur += destination.Unmarshal(buf,cur); cur += command_id.Unmarshal(buf, cur); cur += reply_id.Unmarshal(buf, cur); cur += fault_id.Unmarshal(buf, cur); seq_num = GET_SHORT(&buf[cur]); cur += sizeof(seq_num); length = msg_length - cur + HEADER_SIZE; memcpy(&data,buf+cur,length); cur += length; #ifdef BUILD_WITH_MESSAGE_LOGGING Logger.MessageReceived(*this); #endif return cur; }
// process incoming squadmate messaging info void multi_msg_process_squadmsg_packet(unsigned char *data, header *hinfo) { int command; ushort net_sig; short source_id; int source_index; char s_val; int offset = HEADER_LENGTH; // get all packet data GET_INT(command); GET_SHORT(source_id); GET_USHORT(net_sig); GET_DATA(s_val); PACKET_SET_SIZE(); // determine who the order is from source_index = find_player_id(source_id); if(source_index == -1){ nprintf(("Network","Received squadmsg order packet from unknown player!!\n")); return; } // display the squadmessage somehow multi_msg_show_squadmsg(&Net_players[source_index],command,net_sig,(int)s_val); }
// process a player kick packet void process_player_kick_packet(ubyte *data, header *hinfo) { int player_num,from_player,ban,reason; short player_id; int offset = HEADER_LENGTH; // get the address of the guy who is to be kicked GET_SHORT(player_id); GET_INT(ban); GET_INT(reason); player_num = find_player_id(player_id); PACKET_SET_SIZE(); // only the server should ever receive a request to kick a guy Assert(Net_player->flags & NETINFO_FLAG_AM_MASTER); // determine who sent the packet from_player = find_player_id(hinfo->id); // check to see if this guy is allowed to make such a request if((from_player == -1) || !multi_kick_can_kick(&Net_players[from_player]) ){ nprintf(("Network","Received a kick request from an invalid player!!\n")); } // otherwise, process the request fully else { // make sure we have a valid player to kick if(player_num == -1){ nprintf(("Network","Received request to kick an unknown player!\n")); } else { // will handle all the rest of the details multi_kick_player(player_num,ban,reason); } } }
long SDMmessage::SendTCP(long ip_addr,long port) { int sock; long i; long result; char buf[3*BUFSIZE]; char ack[16]; short error = 0; //fill buffer i = Marshal(buf); if(i < 0) return SDM_MESSAGE_SEND_ERROR; //send message sock = TCPconnect(ip_addr,port); if (sock != IP_SOCK_INVALID) { result = TCPsend(sock,buf,i); if(buf[0] == SDM_xTEDS || buf[0] == SDM_CancelxTEDS) { TCPrecv(sock,ack,13); error = GET_SHORT(&ack[HEADER_SIZE]); if(error < 0) { result = error; } } TCPclose (sock); #ifdef BUILD_WITH_MESSAGE_LOGGING Logger.MessageSent(*this); #endif } return result; }
/* attaches mob's name and vnum to msg and sends it to script_log */ void mob_log(char_data *mob, char *msg) { char buf[MAX_INPUT_LENGTH + 100]; void script_log(char *msg); sprintf(buf, "Mob (%s, VNum %d): %s", GET_SHORT(mob), GET_MOB_VNUM(mob), msg); script_log(buf); }
/* attaches mob's name and vnum to msg and sends it to script_log */ void mob_log(char_data *mob, const char *format, ...) { va_list args; char output[MAX_STRING_LENGTH]; snprintf(output, sizeof(output), "Mob (%s, VNum %d):: %s", GET_SHORT(mob), GET_MOB_VNUM(mob), format); va_start(args, format); script_vlog(output, args); va_end(args); }
long SDMRegister::Unmarshal(const char*buf) { int cur = UnmarshalHeader(buf); if(cur == SDM_INVALID_MESSAGE || total_length != msg_length) { return SDM_INVALID_MESSAGE; } sensorIndex = GET_SHORT(&buf[cur]); cur += sizeof(short); #ifdef BUILD_WITH_MESSAGE_LOGGING Logger.MessageReceived(*this); #endif return cur; }
bool gtcmtr_kill(void) { cm_region_list *reg_ref; unsigned char *ptr, regnum; unsigned short len; static readonly gds_file_id file; error_def(ERR_DBPRIVERR); ptr = curr_entry->clb_ptr->mbf; assert(*ptr == CMMS_Q_KILL); ptr++; GET_SHORT(len, ptr); ptr += sizeof(unsigned short); regnum = *ptr++; reg_ref = gtcm_find_region(curr_entry,regnum); len--; /* subtract size of regnum */ CM_GET_GVCURRKEY(ptr, len); gtcm_bind_name(reg_ref->reghead, TRUE); if (gv_cur_region->read_only) rts_error(VARLSTCNT(4) ERR_DBPRIVERR, 2, DB_LEN_STR(gv_cur_region)); if (JNL_ALLOWED(cs_addrs)) { /* we need to copy client's specific prc_vec into the global variable in order that the gvcst* routines * do the right job. actually we need to do this only if JNL_ENABLED(cs_addrs), but since it is not * easy to re-execute the following two assignments in case gvcst_kill()'s call to t_end() encounters a * cdb_sc_jnlstatemod retry code, we choose the easier approach of executing the following segment * if JNL_ALLOWED(cs_addrs) is TRUE instead of checking for JNL_ENABLED(cs_addrs) to be TRUE. * this approach has the overhead that we will be doing the following assignments even though JNL_ENABLED * might not be TRUE but since the following two are just pointer copies, it is not considered a big overhead. * this approach ensures that the jnl_put_jrt_pini() gets the appropriate prc_vec for writing into the * journal record in case JNL_ENABLED turns out to be TRUE in t_end() time. * note that the value of JNL_ALLOWED(cs_addrs) cannot be changed on the fly without obtaining standalone access * and hence the correctness of prc_vec whenever it turns out necessary is guaranteed. */ originator_prc_vec = curr_entry->pvec; cs_addrs->jnl->pini_addr = reg_ref->pini_addr; } if (gv_target->root) gvcst_kill(TRUE); if (JNL_ALLOWED(cs_addrs)) reg_ref->pini_addr = cs_addrs->jnl->pini_addr; /* In case journal switch occurred */ ptr = curr_entry->clb_ptr->mbf; *ptr++ = CMMS_R_KILL; curr_entry->clb_ptr->cbl = S_HDRSIZE; return TRUE; }
void dse_m_rest ( block_id blk, /* block number */ unsigned char *bml_list, /* start of local list of local bit maps */ int4 bml_size, /* size of each entry in *bml_list */ sm_vuint_ptr_t blks_ptr, /* total free blocks */ bool in_dir_tree) { sm_uc_ptr_t bp, b_top, rp, r_top, bml_ptr, np, ptr; unsigned char util_buff[MAX_UTIL_LEN]; block_id next; int util_len; int4 dummy_int; cache_rec_ptr_t dummy_cr; int4 bml_index; short level, rsize; int4 bplmap; error_def(ERR_DSEBLKRDFAIL); if(!(bp = t_qread (blk, &dummy_int, &dummy_cr))) rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); if (((blk_hdr_ptr_t) bp)->bsiz > cs_addrs->hdr->blk_size) b_top = bp + cs_addrs->hdr->blk_size; else if (((blk_hdr_ptr_t) bp)->bsiz < sizeof(blk_hdr)) b_top = bp + sizeof(blk_hdr); else b_top = bp + ((blk_hdr_ptr_t) bp)->bsiz; level = ((blk_hdr_ptr_t)bp)->levl; bplmap = cs_addrs->hdr->bplmap; for (rp = bp + sizeof (blk_hdr); rp < b_top ;rp = r_top) { if (in_dir_tree || level > 1) /* reread block because it may have been flushed from read */ { if (!(np = t_qread(blk,&dummy_int,&dummy_cr))) /* cache due to LRU buffer scheme and reads in recursive */ rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); /* calls to dse_m_rest. */ if (np != bp) { b_top = np + (b_top - bp); rp = np + (rp - bp); r_top = np + (r_top - bp); bp = np; } } GET_SHORT(rsize,&((rec_hdr_ptr_t)rp)->rsiz); r_top = rp + rsize; if (r_top > b_top) r_top = b_top; if (r_top - rp < (sizeof (rec_hdr) + sizeof (block_id))) break; if (in_dir_tree && level == 0) { for (ptr = rp + sizeof(rec_hdr); ; ) { if (*ptr++ == 0 && *ptr++ == 0) break; } GET_LONG(next,ptr); } else GET_LONG(next,r_top - sizeof (block_id)); if (next < 0 || next >= cs_addrs->ti->total_blks || (next / bplmap * bplmap == next)) { memcpy(util_buff,"Invalid pointer in block ",25); util_len = 25; util_len += i2hex_nofill(blk, &util_buff[util_len], 8); memcpy(&util_buff[util_len], " record offset ",15); util_len += 15; util_len += i2hex_nofill((int)(rp - bp), &util_buff[util_len], 4); util_buff[util_len] = 0; util_out_print((char*)util_buff,TRUE); continue; } bml_index = next / bplmap; bml_ptr = bml_list + bml_index * bml_size; if (bml_busy(next - next / bplmap * bplmap, bml_ptr + sizeof(blk_hdr))) { *blks_ptr = *blks_ptr - 1; if (((blk_hdr_ptr_t) bp)->levl > 1) { dse_m_rest (next, bml_list, bml_size, blks_ptr, in_dir_tree); } else if (in_dir_tree) { assert(((blk_hdr_ptr_t) bp)->levl == 0 || ((blk_hdr_ptr_t) bp)->levl == 1); dse_m_rest (next, bml_list, bml_size, blks_ptr, ((blk_hdr_ptr_t)bp)->levl); } } } return; }
void dse_range(void) { char lower[256], targ_key[256], upper[256], util_buff[MAX_UTIL_LEN]; block_id from, to, blk, blk_child; sm_uc_ptr_t bp, b_top, key_bot, key_top, key_top1, rp, r_top; char level; int4 dummy_int, nocrit_present; cache_rec_ptr_t dummy_cr; short int rsize, size, size1; int cnt, dummy, lower_len, util_len, upper_len; boolean_t busy_matters, free, got_lonely_star, index, low, lost, star, up, was_crit, was_hold_onto_crit; if (cli_present("FROM") == CLI_PRESENT) { if (!cli_get_hex("FROM", (uint4 *)&from)) return; if (from < 0 || from > cs_addrs->ti->total_blks || !(from % cs_addrs->hdr->bplmap)) { util_out_print("Error: invalid block number.", TRUE); return; } } else from = 1; if (cli_present("TO") == CLI_PRESENT) { if(!cli_get_hex("TO", (uint4 *)&to)) return; if (to < 0 || to > cs_addrs->ti->total_blks || !(to % cs_addrs->hdr->bplmap)) { util_out_print("Error: invalid block number.", TRUE); return; } } else to = cs_addrs->ti->total_blks - 1; if (low = (cli_present("LOWER") == CLI_PRESENT)) { if (!dse_getki(&lower[0], &lower_len, LIT_AND_LEN("LOWER"))) return; } if (up = (cli_present("UPPER") == CLI_PRESENT)) { if (!dse_getki(&upper[0], &upper_len, LIT_AND_LEN("UPPER"))) return; } star = (cli_present("STAR") == CLI_PRESENT); if (!low && !up && !star) { util_out_print("Must specify star, or a lower or upper key limit.", TRUE); return; } index = (cli_present("INDEX") == CLI_PRESENT); lost = (cli_present("LOST") == CLI_PRESENT); dummy = cli_present("BUSY"); if (dummy == CLI_PRESENT) { busy_matters = TRUE; free = FALSE; } else if (dummy == CLI_NEGATED) busy_matters = free = TRUE; else busy_matters = free = FALSE; patch_path[0] = get_dir_root(); cnt = 0; was_crit = cs_addrs->now_crit; nocrit_present = (CLI_NEGATED == cli_present("CRIT")); DSE_GRAB_CRIT_AS_APPROPRIATE(was_crit, was_hold_onto_crit, nocrit_present, cs_addrs, gv_cur_region); for (blk = from; blk <= to ;blk++) { if (util_interrupt) { DSE_REL_CRIT_AS_APPROPRIATE(was_crit, was_hold_onto_crit, nocrit_present, cs_addrs, gv_cur_region); rts_error(VARLSTCNT(1) ERR_CTRLC); break; } if (!(blk % cs_addrs->hdr->bplmap)) continue; if (!(bp = t_qread(blk, &dummy_int, &dummy_cr))) rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); level = ((blk_hdr_ptr_t)bp)->levl; if (index && (level == 0)) continue; if (busy_matters && (free != dse_is_blk_free(blk, &dummy_int, &dummy_cr))) continue; if (((blk_hdr_ptr_t) bp)->bsiz > cs_addrs->hdr->blk_size) b_top = bp + cs_addrs->hdr->blk_size; else if (((blk_hdr_ptr_t) bp)->bsiz < SIZEOF(blk_hdr)) b_top = bp + SIZEOF(blk_hdr); else b_top = bp + ((blk_hdr_ptr_t) bp)->bsiz; rp = bp + SIZEOF(blk_hdr); GET_SHORT(rsize, &((rec_hdr_ptr_t) rp)->rsiz); if (rsize < SIZEOF(rec_hdr)) r_top = rp + SIZEOF(rec_hdr); else r_top = rp + rsize; if (r_top >= b_top) r_top = b_top; got_lonely_star = FALSE; if (((blk_hdr_ptr_t) bp)->levl) { key_top = r_top - SIZEOF(block_id); if (star && (r_top == b_top)) got_lonely_star = TRUE; } else { if (!up && !low) continue; for (key_top = rp + SIZEOF(rec_hdr); key_top < r_top ; ) if (!*key_top++ && !*key_top++) break; } if (!got_lonely_star) { key_bot = rp + SIZEOF(rec_hdr); size = key_top - key_bot; if (size <= 0) continue; if (size > SIZEOF(targ_key)) size = SIZEOF(targ_key); if (lost) { for (key_top1 = rp + SIZEOF(rec_hdr); key_top1 < r_top ; ) if (!*key_top1++) break; size1 = key_top1 - rp - SIZEOF(rec_hdr); if (size1 > SIZEOF(targ_key)) size1 = SIZEOF(targ_key); patch_find_root_search = TRUE; patch_path_count = 1; patch_find_blk = blk; if (dse_is_blk_in(rp, r_top, size1)) continue; } if (low && memcmp(lower, key_bot, MIN(lower_len, size)) > 0) continue; if (up && memcmp(upper, key_bot, MIN(upper_len, size)) < 0) continue; } else { got_lonely_star = FALSE; if (lost) { blk_child = *(block_id_ptr_t)key_top; if (!(bp = t_qread(blk_child, &dummy_int, &dummy_cr))) rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); if (((blk_hdr_ptr_t) bp)->bsiz > cs_addrs->hdr->blk_size) b_top = bp + cs_addrs->hdr->blk_size; else if (((blk_hdr_ptr_t) bp)->bsiz < SIZEOF(blk_hdr)) b_top = bp + SIZEOF(blk_hdr); else b_top = bp + ((blk_hdr_ptr_t) bp)->bsiz; rp = bp + SIZEOF(blk_hdr); GET_SHORT(rsize, &((rec_hdr_ptr_t) rp)->rsiz); if (rsize < SIZEOF(rec_hdr)) r_top = rp + SIZEOF(rec_hdr); else r_top = rp + rsize; if (r_top >= b_top) r_top = b_top; if (((blk_hdr_ptr_t) bp)->levl) key_top = r_top - SIZEOF(block_id); for (key_top1 = rp + SIZEOF(rec_hdr); key_top1 < r_top ; ) if (!*key_top1++) break; size1 = key_top1 - rp - SIZEOF(rec_hdr); if (size1 > 0) { if (size1 > SIZEOF(targ_key)) size1 = SIZEOF(targ_key); patch_find_root_search = TRUE; patch_path_count = 1; patch_find_blk = blk; if (dse_is_blk_in(rp, r_top, size1)) continue; } } } if (!cnt++) util_out_print("!/Blocks in the specified key range:", TRUE); util_out_print("Block: !8XL Level: !2UL", TRUE, blk, level); } DSE_REL_CRIT_AS_APPROPRIATE(was_crit, was_hold_onto_crit, nocrit_present, cs_addrs, gv_cur_region); if (cnt) util_out_print("Found !UL blocks", TRUE, cnt); else util_out_print("None found.", TRUE); return; }
long SDMmessage::SendTo(const SDMComponent_ID& destination) { int sock; long i; long result; char buf[LARGE_MSG_BUFSIZE]; char ack[16]; long address = destination.getAddress(); int timeout = 2000; // 2 sec int count = 0; short error = 0; //fill buffer i = Marshal(buf); if(i < 0) return SDM_MESSAGE_SEND_ERROR; #ifdef TCP_TRANSMIT_OF_LARGE_XTEDS if(i>BUFSIZE) return SendTCP(destination.getAddress(),destination.getPort()); #endif //send message sock = UDPconnect(address,destination.getPort()); if (sock != IP_SOCK_INVALID) // cleanup issue 26 { result = UDPsend(sock,buf,i); //Look for SDM_ACK from DM for certain messages if(buf[0] == SDM_xTEDS || buf[0] == SDM_CancelxTEDS) { if(buf[0] == SDM_xTEDS) { timeout = 5000; // 5 sec } UDPset_recv_timeout(sock, timeout); UDPrecv(sock,&ack,13); while(ack[0]!=SDM_ACK && count < NUMRETRIES) { count++; result = UDPsend(sock,buf,i); UDPrecv(sock,&ack,13); } //remove timeout on sdm_dm_sock UDPset_recv_timeout(sock, 0); if(count == NUMRETRIES && ack[0]!=SDM_ACK) { result = SDM_UNABLE_TO_REGISTER; } else { error = GET_SHORT(&ack[11]); if(error < 0) { result = error; } } } UDPclose (sock); #ifdef BUILD_WITH_MESSAGE_LOGGING Logger.MessageSent(*this); #endif } return result; }
static int run_vm(ClipMachine * mp, ClipBlock * bp) { char *func = bp->func; char *modbeg = func - GETLONG(func); char *pp = modbeg + GETLONG(F_OFFS(func, 1, 0, 0)); char code; long len = GETLONG(F_OFFS(func, 2, 0, 0)); char *beg = pp, *end = pp + len; long staticsOffs = GETLONG(modbeg); ClipFile *file = bp->file; ClipVar *statics = file->statics + staticsOffs; int nlocals = GETSHORT(F_OFFS(func, 3, 0, 1)); int nreflocals = GETSHORT(F_OFFS(func, 3, 1, 1)); int ret = 0; int i; #if 0 ClipVar *locals /* = alloca(sizeof(ClipVar) * nlocals) */ ; #endif int maxdeep = GETSHORT(F_OFFS(func, 3, 2, 1)); ClipVar *stack = alloca(sizeof(ClipVar) * maxdeep); char *filename = F_OFFS(modbeg, 6, 6, 0); int nprivates = GETSHORT(F_OFFS(func, 3, 3, 1)); /*int nparams = GETSHORT( F_OFFS(func, 3, 4, 1)); */ /*long *privates = (long *) F_OFFS(func, 3, 5, 1); */ /*long *localDefHashs = (long *) F_OFFS(func, 3 + nprivates, 5, 1); */ int numlocals = nlocals + nreflocals; /*ClipVarDef *ldp, *localDefs = alloca(sizeof(ClipVarDef) * (numlocals+1)); */ /*short *localDefNums = (short *) F_OFFS(func, 3 + nprivates + numlocals, 5, 1); */ char *procname = F_OFFS(func, 3 + nprivates + numlocals, 5 + numlocals, 1 + 1); char *localnames = procname + *(unsigned char *) F_OFFS(func, 3 + nprivates + numlocals, 5 + numlocals, 1) + 1; /*ClipVar *params = alloca( nparams*sizeof(ClipVar)); */ ClipFrame frame = {stack, stack, filename, 0, 0, 0, 0 /*localDefs */ , file->staticDefs, 0, file->hash_names, procname, maxdeep, 0}; unsigned char c, c1; short s, s1; long l, l1; ClipVar *vp; ClipBlock bl; char *trap_pp = 0; int debuglevel = _clip_debuglevel; ClipVarFrame *localvars = 0, *reflocals = 0; int local_locals = 0; if (!nlocals && !nreflocals) { reflocals = frame.localvars = mp->fp->localvars; if (reflocals && reflocals->refcount) reflocals->refcount++; } else if (nreflocals) { localvars = calloc(1, sizeof(ClipVarFrame) + numlocals * sizeof(ClipVar)); localvars->vars = (ClipVar *) (localvars + 1); localvars->refcount = 1; reflocals = frame.localvars = localvars; localvars->size = numlocals; localvars->names = localnames; } else { #if 1 localvars = calloc(1, sizeof(ClipVarFrame) + numlocals * sizeof(ClipVar)); localvars->vars = (ClipVar *) (localvars + 1); localvars->size = numlocals; localvars->refcount = 1; localvars->names = localnames; reflocals = frame.localvars = localvars; #else locals = alloca(sizeof(ClipVar) * numlocals); memset(locals, 0, numlocals * sizeof(ClipVar)); localvars = alloca(sizeof(ClipVarFrame)); localvars->vars = locals; localvars->size = numlocals; localvars->refcount = 0; localvars->names = localnames; reflocals = frame.localvars = localvars; local_locals = 1; #endif } frame.up = mp->fp; mp->fp = &frame; #if 0 localDefs[0].name = numlocals; for (i = 0, ldp = localDefs + 1; i < numlocals; i++, ldp++, localDefHashs++, localDefNums++) { /*int no = *localDefNums; */ long hash = *localDefHashs; ldp->name = hash; /* if (no < 0) ldp->vp = reflocals - no; else */ /*ldp->vp = locals + no; */ ldp->vp = 0; } #endif if (_clip_profiler) _clip_start_profiler(mp); _clip_logg(4, "PCODE call: proc '%s' file '%s' line %d", frame.procname ? frame.procname : "unknown", frame.filename, frame.line); cont: while (pp >= beg && pp < end) { if (debuglevel) _clip_debug(mp); switch ((code = *pp++)) { case CLIP_NOP: break; case CLIP_POP: _clip_pop(mp); break; case CLIP_LINE: frame.line = GET_SHORT(pp); if (debuglevel) _clip_line(mp); break; case CLIP_PUSH_NUM: { int len, dec; double d; s = GET_SHORT(pp); frame.sp->t.memo = 0; frame.sp->t.type = NUMERIC_t; frame.sp->t.flags = F_NONE; get_num(modbeg, s, &d, &len, &dec); frame.sp->t.len = len; frame.sp->t.dec = dec; frame.sp->n.d = d; frame.sp->t.memo = 0; ++frame.sp; } break; case CLIP_PUSH_STR: #if 0 s = GET_SHORT(pp); frame.sp->t.type = CHARACTER_t; frame.sp->t.flags = F_MSTAT; frame.sp->t.memo = 0; get_str(modbeg, s, &(frame.sp->s.str.buf), &(frame.sp->s.str.len)); /* if ( !(mp->flags1 & NOEXPAND_MACRO_FLAG) ) { */ if (strchr(frame.sp->s.str.buf, '&')) _clip_expand_var(mp, frame.sp); /*}*/ ++frame.sp; break; #endif case CLIP_PUSH_STRDUP: s = GET_SHORT(pp); frame.sp->t.type = CHARACTER_t; frame.sp->t.flags = F_NONE; frame.sp->t.memo = 0; { char *str = ""; int len = 0; get_str(modbeg, s, &str, &len); frame.sp->s.str.buf = _clip_memdup(str, len); frame.sp->s.str.len = len; } /* if ( !(mp->flags1 & NOEXPAND_MACRO_FLAG) ) { */ if (strchr(frame.sp->s.str.buf, '&')) _clip_expand_var(mp, frame.sp); /*}*/ ++frame.sp; break; case CLIP_PUSH_NIL: frame.sp->t.type = UNDEF_t; frame.sp->t.flags = F_NONE; ++frame.sp; break; case CLIP_PUSH_TRUE: frame.sp->t.type = LOGICAL_t; frame.sp->t.flags = F_NONE; frame.sp->l.val = 1; ++frame.sp; break; case CLIP_PUSH_FALSE: frame.sp->t.type = LOGICAL_t; frame.sp->t.flags = F_NONE; frame.sp->l.val = 0; ++frame.sp; break; case CLIP_MEMVAR_PUBLIC: l = GET_LONG(pp); _clip_memvar_public(mp, l); break; case CLIP_MEMVAR_SPACE: l = GET_LONG(pp); l1 = GET_LONG(pp); _clip_memvar_space(mp, _clip_space(mp, l), l1, 1); break; case CLIP_MEMVAR_PRIVATE: l = GET_LONG(pp); _clip_memvar_private(mp, l); break; case CLIP_MEMVAR_PUBLIC_POP: l = _clip_pop_hash(mp); _clip_memvar_public(mp, l); break; case CLIP_MEMVAR_SPACE_POP: l = GET_LONG(pp); l1 = _clip_pop_hash(mp); _clip_memvar_space(mp, _clip_space(mp, l), l1, 1); break; case CLIP_MEMVAR_PRIVATE_POP: l = _clip_pop_hash(mp); /*_clip_memvar_private(mp, l);*/ _clip_add_private(mp, l); break; case CLIP_MEMVAR_PARAM: l = GET_LONG(pp); c = GET_BYTE(pp); _clip_memvar_param(mp, l, c); break; case CLIP_PUSH_PARAM: c = GET_BYTE(pp); s = GET_SHORT(pp); _clip_param(mp, c, s); break; case CLIP_PUSH_LOCAL: s = GET_SHORT(pp); if ((ret = _clip_push_local(mp, s))) goto _trap; break; case CLIP_PUSH_REF_LOCAL: s = GET_SHORT(pp); #if 0 frame.sp->p.vp = _clip_ref_local(mp, s); #else { ClipVar *vp1 = _clip_ref_local(mp, s); frame.sp->p.vp = vp1; } #endif break; case CLIP_PUSH_STATIC: s = GET_SHORT(pp); get_static(mp, file, statics, modbeg, s, &vp); if ((ret = _clip_push_static(mp, vp))) goto _trap; break; case CLIP_PUSH_REF_STATIC: s = GET_SHORT(pp); get_static(mp, file, statics, modbeg, s, &vp); frame.sp->p.vp = vp; break; case CLIP_PUSH_MEMVAR: l = GET_LONG(pp); if ((ret = _clip_memvar(mp, l))) goto _trap; break; case CLIP_PUSH_FMEMVAR: l = GET_LONG(pp); if ((ret = _clip_fmemvar(mp, l))) goto _trap; break; case CLIP_PUSH_MEMVARF: l = GET_LONG(pp); if ((ret = _clip_memvarf(mp, l))) goto _trap; break; case CLIP_REF_FMEMVAR: l = GET_LONG(pp); if ((ret = _clip_ref_fmemvar(mp, l))) goto _trap; break; case CLIP_PUSH_REF_MEMVAR: l = GET_LONG(pp); #if 0 frame.sp->p.vp = _clip_ref_memvar(mp, l); #else { ClipVar *vp1 = _clip_ref_memvar(mp, l); frame.sp->p.vp = vp1; } #endif break; case CLIP_PUSH_REF_MEMVAR_NOADD: l = GET_LONG(pp); { ClipVar *vp1 = _clip_ref_memvar_noadd(mp, l); frame.sp->p.vp = vp1; } break; case CLIP_PUSH_PUBLIC: l = GET_LONG(pp); if ((ret = _clip_public(mp, l))) goto _trap; break; case CLIP_PUSH_REF_PUBLIC: l = GET_LONG(pp); #if 0 frame.sp->p.vp = _clip_ref_public(mp, l); #else { ClipVar *vp1 = _clip_ref_public(mp, l); frame.sp->p.vp = vp1; } #endif break; case CLIP_REFMACRO: if ((ret = _clip_refmacro(mp))) goto _trap; break; case CLIP_MAKE_REF: c = GET_BYTE(pp); vp = frame.sp->p.vp; if ((ret = _clip_ref(mp, vp, c))) goto _trap; break; case CLIP_UNREF_ARR: _clip_unref_arr(mp); break; case CLIP_FIELD: l = GET_LONG(pp); l1 = GET_LONG(pp); if ((ret = _clip_field(mp, l, l1))) goto _trap; break; case CLIP_FIELD_POP: l = GET_LONG(pp); l1 = _clip_pop_hash(mp); if ((ret = _clip_field(mp, l, l1))) goto _trap; break; case CLIP_FIELD_POP_NAME: _clip_pop_fieldhash(mp, &l1, &l); if ((ret = _clip_field(mp, l, l1))) goto _trap; break; case CLIP_PUSH_AREA: l = GET_LONG(pp); if ((ret = _clip_push_area(mp, l))) goto _trap; break; case CLIP_PUSH_AREA_POP: l = _clip_pop_hash(mp); if ((ret = _clip_push_area(mp, l))) goto _trap; break; case CLIP_POP_AREA: if ((ret = _clip_pop_area(mp))) goto _trap; break; case CLIP_FUNC: c = GET_BYTE(pp); l = GET_LONG(pp); if ((ret = _clip_func_hash(mp, l, c, 0, reflocals))) goto _trap; break; case CLIP_FUNCR: c = GET_BYTE(pp); l = GET_LONG(pp); if ((ret = _clip_func_hash(mp, l, c, 1, reflocals))) goto _trap; break; case CLIP_PROC: c = GET_BYTE(pp); l = GET_LONG(pp); if ((ret = _clip_proc_hash(mp, l, c, 0, reflocals))) goto _trap; break; case CLIP_PROCR: c = GET_BYTE(pp); l = GET_LONG(pp); if ((ret = _clip_proc_hash(mp, l, c, 1, reflocals))) goto _trap; break; case CLIP_SFUNC: c = GET_BYTE(pp); s = GET_SHORT(pp); bl.file = file; get_func(modbeg, s, &bl.func); if ((ret = _clip_code_func(mp, &bl, c, 0, reflocals))) goto _trap; break; case CLIP_SFUNCR: c = GET_BYTE(pp); s = GET_SHORT(pp); bl.file = file; get_func(modbeg, s, &bl.func); if ((ret = _clip_code_func(mp, &bl, c, 1, reflocals))) goto _trap; break; case CLIP_SPROC: c = GET_BYTE(pp); s = GET_SHORT(pp); bl.file = file; get_func(modbeg, s, &bl.func); if ((ret = _clip_code_proc(mp, &bl, c, 0, reflocals))) goto _trap; break; case CLIP_SPROCR: c = GET_BYTE(pp); s = GET_SHORT(pp); bl.file = file; get_func(modbeg, s, &bl.func); if ((ret = _clip_code_proc(mp, &bl, c, 1, reflocals))) goto _trap; break; case CLIP_ASSIGN: vp = frame.sp->p.vp; if ((ret = _clip_assign(mp, vp))) goto _trap; break; case CLIP_REF_DESTROY: vp = frame.sp->p.vp; /*if (vp->t.flags != F_MREF)*/ _clip_destroy(mp, vp); /*_clip_destroy(mp, vp);*/ break; case CLIP_MACROASSIGN: c = GET_BYTE(pp); c1 = GET_BYTE(pp); if ((ret = _clip_macroassign(mp, c, c1 & 1, c1 & 2))) goto _trap; break; case CLIP_REFASSIGN: c = GET_BYTE(pp); vp = frame.sp->p.vp; if ((ret = _clip_refassign(mp, vp, c))) goto _trap; break; case CLIP_UNREF: vp = frame.sp->p.vp; _clip_destroy(mp, vp); break; case CLIP_IASSIGN: vp = frame.sp->p.vp; if ((ret = _clip_iassign(mp, vp))) goto _trap; break; case CLIP_OPASSIGN: c = GET_BYTE(pp); vp = frame.sp->p.vp; if ((ret = _clip_opassign(mp, vp, c))) goto _trap; break; case CLIP_OPIASSIGN: c = GET_BYTE(pp); vp = frame.sp->p.vp; if ((ret = _clip_opiassign(mp, vp, c))) goto _trap; break; case CLIP_ASSIGN_FIELD: l = GET_LONG(pp); l1 = GET_LONG(pp); if ((ret = _clip_assign_field(mp, l, l1))) goto _trap; break; case CLIP_IASSIGN_FIELD: l = GET_LONG(pp); l1 = GET_LONG(pp); if ((ret = _clip_iassign_field(mp, l, l1))) goto _trap; break; case CLIP_ASSIGN_FIELD_POP: l = GET_LONG(pp); l1 = _clip_pop_hash(mp); if ((ret = _clip_assign_field(mp, l, l1))) goto _trap; break; case CLIP_IASSIGN_FIELD_POP: l = GET_LONG(pp); l1 = _clip_pop_hash(mp); if ((ret = _clip_iassign_field(mp, l, l1))) goto _trap; break; case CLIP_ASSIGN_PFIELD: l = _clip_pop_hash(mp); l1 = GET_LONG(pp); if ((ret = _clip_assign_field(mp, l, l1))) goto _trap; break; case CLIP_IASSIGN_PFIELD: l = _clip_pop_hash(mp); l1 = GET_LONG(pp); if ((ret = _clip_iassign_field(mp, l, l1))) goto _trap; break; case CLIP_ASSIGN_PFIELD_POP: l = _clip_pop_hash(mp); l1 = _clip_pop_hash(mp); if ((ret = _clip_assign_field(mp, l, l1))) goto _trap; break; case CLIP_IASSIGN_PFIELD_POP: l = _clip_pop_hash(mp); l1 = _clip_pop_hash(mp); if ((ret = _clip_iassign_field(mp, l, l1))) goto _trap; break; case CLIP_FM_ASSIGN: l = GET_LONG(pp); if ((ret = _clip_fm_assign(mp, l))) goto _trap; break; case CLIP_FM_IASSIGN: l = GET_LONG(pp); if ((ret = _clip_fm_iassign(mp, l))) goto _trap; break; case CLIP_ARRAY: l = GET_LONG(pp); _clip_sarray(mp, l); break; case CLIP_DIMARRAY: l = GET_LONG(pp); _clip_dimarray(mp, l); break; case CLIP_NEWARRAY: l = GET_LONG(pp); _clip_vnewarray(mp, l, (long *) pp); pp += l * sizeof(long); break; case CLIP_GET: l = GET_LONG(pp); if ((ret = _clip_get(mp, l))) goto _trap; break; case CLIP_SET: l = GET_LONG(pp); if ((ret = _clip_set(mp, l))) goto _trap; break; case CLIP_RETURN_POP: _clip_return(mp); case CLIP_RETURN: goto _return; case CLIP_STORE: c1 = GET_BYTE(pp); c = GET_BYTE(pp); if ((ret = _clip_store(mp, c, c1))) goto _trap; break; case CLIP_ISTORE: c1 = GET_BYTE(pp); c = GET_BYTE(pp); if ((ret = _clip_istore(mp, c, c1))) goto _trap; break; case CLIP_OPSTORE: c = GET_BYTE(pp); c1 = GET_BYTE(pp); if ((ret = _clip_opstore(mp, c1, c))) goto _trap; break; case CLIP_OPISTORE: c = GET_BYTE(pp); c1 = GET_BYTE(pp); if ((ret = _clip_opistore(mp, c1, c))) goto _trap; break; case CLIP_FETCH: c = GET_BYTE(pp); if ((ret = _clip_fetch(mp, c))) goto _trap; break; case CLIP_FETCHREF: c = GET_BYTE(pp); #if 0 frame.sp->p.vp = _clip_fetchref(mp, c); #else { ClipVar *vp1 = _clip_fetchref(mp, c); /*printf("%p\n", vp1);*/ frame.sp->p.vp = vp1; } #endif if (!frame.sp->p.vp) goto _trap; break; case CLIP_IFETCH: c = GET_BYTE(pp); if ((ret = _clip_ifetch(mp, c))) goto _trap; break; case CLIP_CALL: c = GET_BYTE(pp); l = GET_LONG(pp); if ((ret = _clip_call(mp, c, l))) goto _trap; break; case CLIP_PUSH_CODE: s = GET_SHORT(pp); c = GET_BYTE(pp); c1 = GET_BYTE(pp); vp = NEW(ClipVar); vp->t.type = PCODE_t; vp->t.flags = F_NONE; vp->t.count = 1; vp->c.u.block = NEW(ClipBlock); get_func(modbeg, s, &(vp->c.u.block->func)); vp->c.u.block->file = file; if (c) { int nlocals = c; ClipVarFrame *localvars = calloc(1, sizeof(ClipVarFrame) + nlocals * sizeof(ClipVar)); localvars->vars = (ClipVar *) (localvars + 1); memcpy(localvars->vars, mp->fp->sp - nlocals, nlocals * sizeof(ClipVar)); localvars->refcount = 1; localvars->size = nlocals; vp->c.uplocals = localvars; mp->fp->sp -= nlocals; } else if (!c1 && reflocals && reflocals->refcount) { reflocals->refcount++; vp->c.uplocals = reflocals; } else vp->c.uplocals = 0; file->refCount++; CLEAR_CLIPVAR(frame.sp); frame.sp->t.type = PCODE_t; frame.sp->t.flags = F_MPTR; frame.sp->p.vp = vp; frame.sp++; CLIP_CHECK_STACK; break; case CLIP_MACRO: if ((ret = _clip_macro(mp))) goto _trap; break; case CLIP_PCOUNT: _clip_pcount(mp); break; case CLIP_PSHIFT: _clip_pshift(mp); break; case CLIP_PARN: if ((ret = _clip_parn(mp))) goto _trap; break; case CLIP_FUNC_NAME: c = GET_BYTE(pp); if ((ret = _clip_func_name(mp, c))) goto _trap; break; case CLIP_INCR: vp = frame.sp->p.vp; if ((ret = _clip_incr(mp, vp, 1, 0))) goto _trap; break; case CLIP_INCR_POST: vp = frame.sp->p.vp; if ((ret = _clip_incr(mp, vp, 1, 1))) goto _trap; break; case CLIP_DECR: vp = frame.sp->p.vp; if ((ret = _clip_incr(mp, vp, 0, 0))) goto _trap; break; case CLIP_DECR_POST: vp = frame.sp->p.vp; if ((ret = _clip_incr(mp, vp, 0, 1))) goto _trap; break; case CLIP_OP: c = GET_BYTE(pp); if ((ret = _clip_op(mp, c))) goto _trap; break; case CLIP_NOT: if ((ret = _clip_not(mp))) goto _trap; break; case CLIP_COND: s = GET_SHORT(pp); if ((ret = _clip_cond(mp, &i))) goto _trap; if (!i) pp += s; break; case CLIP_TCOND: s = GET_SHORT(pp); if ((ret = _clip_tcond(mp, &i))) goto _trap; if (!i) pp += s; break; case CLIP_ITCOND: s = GET_SHORT(pp); if ((ret = _clip_tcond(mp, &i))) goto _trap; if (i) pp += s; break; case CLIP_GOTO: s = GET_SHORT(pp); pp += s; break; case CLIP_FORSTEP: s = GET_SHORT(pp); if ((ret = _clip_forstep(mp, &i))) goto _trap; if (!i) pp += s; break; case CLIP_MAP_FIRST: c = GET_BYTE(pp); s = GET_SHORT(pp); if ((ret = _clip_map_first(mp, c, &i))) goto _trap; if (!i) pp += s; break; case CLIP_MAP_NEXT: c = GET_BYTE(pp); s = GET_SHORT(pp); if ((ret = _clip_map_next(mp, c, &i))) goto _trap; if (!i) pp += s; break; case CLIP_MINUS: if ((ret = _clip_minus(mp))) goto _trap; break; case CLIP_RESETTRAP: trap_pp = 0; break; case CLIP_SETTRAP: s = GET_SHORT(pp); trap_pp = pp + s; break; case CLIP_RECOVER: while (frame.sp > frame.stack) _clip_destroy(mp, --frame.sp); ret = 0; break; case CLIP_USING: if (mp->trapVar) { vp = frame.sp->p.vp; *frame.sp = *mp->trapVar; ++frame.sp; free(mp->trapVar); mp->trapVar = 0; if ((ret = _clip_assign(mp, vp))) goto _trap; } break; case CLIP_BREAK: #if 0 /*_clip_trap_str(mp, filename, frame.line, "BREAK");*/ #else vp = NEW(ClipVar); _clip_trap_var(mp, filename, frame.line, vp); #endif ret = -1; goto _trap; case CLIP_BREAK_EXPR: vp = NEW(ClipVar); --frame.sp; *vp = *frame.sp; _clip_trap_var(mp, filename, frame.line, vp); ret = -1; goto _trap; case CLIP_SWAP: c = GET_BYTE(pp); _clip_swap(mp, c); break; case CLIP_PUSH_HASH: l = GET_LONG(pp); frame.sp->t.memo = 0; frame.sp->t.type = NUMERIC_t; frame.sp->t.flags = F_NONE; frame.sp->t.len = 10; frame.sp->t.dec = 0; frame.sp->n.d = l; frame.sp++; CLIP_CHECK_STACK; break; case CLIP_CALC_HASH: _clip_calc_hash(mp); break; case CLIP_CALC_HASH2: _clip_calc_hash2(mp, 1); break; case CLIP_PUSH_LOCALE: _clip_push_locale(mp); break; case CLIP_RDDFIELD: s = GET_SHORT(pp); s1 = GET_SHORT(pp); _clip_rddfield(mp, s, s1); break; case CLIP_CATSTR: s = GET_SHORT(pp); _clip_catstr(mp, s); break; case CLIP_QUOT: _clip_quot(mp); break; case CLIP_SWITCH: s = GET_SHORT(pp); /* label num */ l = _clip_pop_shash(mp); /* hash */ { short other = GET_SHORT(pp); long *lp = (long *) pp; short *jmps = (short *) (pp + s * sizeof(long)); int n = search_long(lp, s, l); if (n < 0) pp += other; else pp += GETSHORT(jmps+n); } break; default: _clip_trap_printf(mp, filename, frame.line, "invalid bytecode %d", code); _clip_call_errblock(mp, 1); ret = 1; goto _trap; } } goto _return; _trap: if (trap_pp /*&& ret > 0 */ ) { pp = trap_pp; goto cont; } _clip_trap(mp, filename, frame.line); /*ret = 1; */ _return: if (_clip_profiler) _clip_stop_profiler(mp); if (local_locals) _clip_destroy_locals(mp); _clip_resume(mp, nlocals, nreflocals); #if 0 _clip_vresume(mp, nlocals, locals); #endif #if 0 _clip_vresume(mp, nparams, params); #endif #if 0 if (nreflocals) _clip_vresume(mp, nreflocals, reflocals); #endif /*_clip_vremove_privates(mp, nprivates, privates);*/ dealloca(stack); return ret; }
short rc_fnd_file(rc_xdsid *xdsid) { gv_namehead *g; short dsid, node; gd_binding *map; char buff[1024], *cp, *cp1; mstr fpath1, fpath2; mval v; int i, keysize; int len, node2; GET_SHORT(dsid, &xdsid->dsid.value); GET_SHORT(node, &xdsid->node.value); if (!dsid_list) { /* open special database, set up entry */ dsid_list = (rc_dsid_list *)malloc(SIZEOF(rc_dsid_list)); dsid_list->dsid = RC_NSPACE_DSID; dsid_list->next = NULL; fpath1.addr = RC_NSPACE_PATH; fpath1.len = SIZEOF(RC_NSPACE_PATH); if (SS_NORMAL != TRANS_LOG_NAME(&fpath1, &fpath2, buff, SIZEOF(buff), do_sendmsg_on_log2long)) { char msg[256]; SPRINTF(msg, "Invalid DB filename, \"%s\"", fpath1.addr); gtcm_rep_err(msg, errno); return RC_BADFILESPEC; } if (fpath2.len > MAX_FN_LEN) return RC_BADFILESPEC; dsid_list->fname = (char *)malloc(fpath2.len + 1); memcpy(dsid_list->fname, fpath2.addr, fpath2.len); *((char*)(dsid_list->fname + fpath2.len)) = 0; gv_cur_region = (gd_region *)malloc(SIZEOF(gd_region)); memset(gv_cur_region, 0, SIZEOF(gd_region)); gv_cur_region->dyn.addr = (gd_segment *)malloc(SIZEOF(gd_segment)); memset(gv_cur_region->dyn.addr, 0, SIZEOF(gd_segment)); memcpy(gv_cur_region->dyn.addr->fname, fpath2.addr, fpath2.len); gv_cur_region->dyn.addr->fname_len = fpath2.len; gv_cur_region->dyn.addr->acc_meth = dba_bg; ESTABLISH_RET(rc_fnd_file_ch1, RC_SUCCESS); gvcst_init(gv_cur_region); REVERT; change_reg(); /* check to see if this DB has the reserved bytes field set * correctly. Global pages must always have some extra unused * space left in them (RC_RESERVED bytes) so that the page * will fit into the client buffer when unpacked by the * client. */ if (cs_data->reserved_bytes < RC_RESERVED) { OMI_DBG((omi_debug, "Unable to access database file: \"%s\"\nReserved_bytes field in the file header is too small for GT.CM\n", fpath2.addr)); free(dsid_list->fname); dsid_list->fname = NULL; free(dsid_list); dsid_list = NULL; free(gv_cur_region->dyn.addr); gv_cur_region->dyn.addr = NULL; free(gv_cur_region); gv_cur_region = NULL; return RC_FILEACCESS; } gv_keysize = DBKEYSIZE(gv_cur_region->max_key_size); GVKEY_INIT(gv_currkey, gv_keysize); GVKEY_INIT(gv_altkey, gv_keysize); cs_addrs->dir_tree = (gv_namehead *)malloc(SIZEOF(gv_namehead) + 2 * SIZEOF(gv_key) + 3 * (gv_keysize - 1)); g = cs_addrs->dir_tree; g->first_rec = (gv_key*)(g->clue.base + gv_keysize); g->last_rec = (gv_key*)(g->first_rec->base + gv_keysize); g->clue.top = g->last_rec->top = g->first_rec->top = gv_keysize; g->clue.prev = g->clue.end = 0; g->root = DIR_ROOT; dsid_list->gda = (gd_addr*)malloc(SIZEOF(gd_addr) + 3 * SIZEOF(gd_binding)); dsid_list->gda->n_maps = 3; dsid_list->gda->n_regions = 1; dsid_list->gda->n_segments = 1; dsid_list->gda->maps = (gd_binding*)((char*)dsid_list->gda + SIZEOF(gd_addr)); dsid_list->gda->max_rec_size = gv_cur_region->max_rec_size; map = dsid_list->gda->maps; map ++; memset(map->name, 0, SIZEOF(map->name)); map->name[0] = '%'; map->reg.addr = gv_cur_region; map++; map->reg.addr = gv_cur_region; memset(map->name, -1, SIZEOF(map->name)); dsid_list->gda->tab_ptr = (hash_table_mname *)malloc(SIZEOF(hash_table_mname)); init_hashtab_mname(dsid_list->gda->tab_ptr, 0, HASHTAB_NO_COMPACT, HASHTAB_NO_SPARE_TABLE); change_reg(); if (rc_overflow->top < cs_addrs->hdr->blk_size) { if (rc_overflow->buff) free(rc_overflow->buff); rc_overflow->top = cs_addrs->hdr->blk_size; rc_overflow->buff = (char*)malloc(rc_overflow->top); if (rc_overflow_size < rc_overflow->top) rc_overflow_size = rc_overflow->top; } } for (fdi_ptr = dsid_list; fdi_ptr && (fdi_ptr->dsid != dsid); fdi_ptr = fdi_ptr->next) ; if (!fdi_ptr) { /* need to open new database, add to list, set fdi_ptr */ gd_header = dsid_list->gda; gv_currkey->end = 0; v.mvtype = MV_STR; v.str.len = RC_NSPACE_GLOB_LEN-1; v.str.addr = RC_NSPACE_GLOB; GV_BIND_NAME_AND_ROOT_SEARCH(gd_header, &v.str); if (!gv_target->root) /* No namespace global */ return RC_UNDEFNAMSPC; v.mvtype = MV_STR; v.str.len = SIZEOF(RC_NSPACE_DSI_SUB)-1; v.str.addr = RC_NSPACE_DSI_SUB; mval2subsc(&v,gv_currkey); node2 = node; MV_FORCE_MVAL(&v,node2); mval2subsc(&v,gv_currkey); i = dsid / 256; MV_FORCE_MVAL(&v,i); mval2subsc(&v,gv_currkey); if (gvcst_get(&v)) return RC_UNDEFNAMSPC; for (cp = v.str.addr, i = 1; i < RC_FILESPEC_PIECE; i++) for (; *cp++ != RC_FILESPEC_DELIM; ) ; for (cp1 = cp; *cp1++ != RC_FILESPEC_DELIM; ) ; cp1--; len = (int)(cp1 - cp); if (len > MAX_FN_LEN) return RC_BADFILESPEC; fdi_ptr = (rc_dsid_list *)malloc(SIZEOF(rc_dsid_list)); fdi_ptr->fname = (char *)malloc(len+1); fdi_ptr->dsid = dsid; memcpy(fdi_ptr->fname, cp, len); *(fdi_ptr->fname + (len)) = 0; gv_cur_region = (gd_region *)malloc(SIZEOF(gd_region)); memset(gv_cur_region, 0, SIZEOF(gd_region)); gv_cur_region->dyn.addr = (gd_segment *)malloc(SIZEOF(gd_segment)); memset(gv_cur_region->dyn.addr, 0, SIZEOF(gd_segment)); memcpy(gv_cur_region->dyn.addr->fname, cp, len); gv_cur_region->dyn.addr->fname_len = len; gv_cur_region->dyn.addr->acc_meth = dba_bg; ESTABLISH_RET(rc_fnd_file_ch2, RC_SUCCESS); gvcst_init(gv_cur_region); REVERT; change_reg(); /* check to see if this DB has the reserved bytes field set * correctly. Global pages must always have some extra unused * space left in them (RC_RESERVED bytes) so that the page * will fit into the client buffer when unpacked by the * client. */ if (cs_data->reserved_bytes < RC_RESERVED) { OMI_DBG((omi_debug, "Unable to access database file: \"%s\"\nReserved_bytes field in the file header is too small for GT.CM\n", fdi_ptr->fname)); free(dsid_list->fname); dsid_list->fname = NULL; free(dsid_list); dsid_list = NULL; free(gv_cur_region->dyn.addr); gv_cur_region->dyn.addr = NULL; free(gv_cur_region); gv_cur_region = NULL; return RC_FILEACCESS; } assert(!cs_addrs->hold_onto_crit); /* this ensures we can safely do unconditional grab_crit and rel_crit */ grab_crit(gv_cur_region); cs_data->rc_srv_cnt++; if (!cs_data->dsid) { cs_data->dsid = dsid; cs_data->rc_node = node; } else if (cs_data->dsid != dsid || cs_data->rc_node != node) { cs_data->rc_srv_cnt--; rel_crit(gv_cur_region); OMI_DBG((omi_debug, "Dataset ID/RC node mismatch")); OMI_DBG((omi_debug, "DB file: \"%s\"\n", dsid_list->fname)); OMI_DBG((omi_debug, "Stored DSID: %d\tRC Node: %d\n", cs_data->dsid, cs_data->rc_node)); OMI_DBG((omi_debug, "RC Rq DSID: %d\tRC Node: %d\n", dsid,node)); free(fdi_ptr->fname); fdi_ptr->fname = NULL; free(fdi_ptr); fdi_ptr = NULL; free(gv_cur_region->dyn.addr); gv_cur_region->dyn.addr = NULL; free(gv_cur_region); gv_cur_region = NULL; return RC_FILEACCESS; } rel_crit(gv_cur_region); keysize = DBKEYSIZE(gv_cur_region->max_key_size); GVKEYSIZE_INCREASE_IF_NEEDED(keysize); cs_addrs->dir_tree = (gv_namehead *)malloc(SIZEOF(gv_namehead) + 2 * SIZEOF(gv_key) + 3 * (keysize - 1)); g = cs_addrs->dir_tree; g->first_rec = (gv_key*)(g->clue.base + keysize); g->last_rec = (gv_key*)(g->first_rec->base + keysize); g->clue.top = g->last_rec->top = g->first_rec->top = keysize; g->clue.prev = g->clue.end = 0; g->root = DIR_ROOT; fdi_ptr->gda = (gd_addr*)malloc(SIZEOF(gd_addr) + 3 * SIZEOF(gd_binding)); fdi_ptr->gda->n_maps = 3; fdi_ptr->gda->n_regions = 1; fdi_ptr->gda->n_segments = 1; fdi_ptr->gda->maps = (gd_binding*)((char*)fdi_ptr->gda + SIZEOF(gd_addr)); fdi_ptr->gda->max_rec_size = gv_cur_region->max_rec_size; map = fdi_ptr->gda->maps; map ++; memset(map->name, 0, SIZEOF(map->name)); map->name[0] = '%'; map->reg.addr = gv_cur_region; map++; map->reg.addr = gv_cur_region; memset(map->name, -1, SIZEOF(map->name)); fdi_ptr->gda->tab_ptr = (hash_table_mname *)malloc(SIZEOF(hash_table_mname)); init_hashtab_mname(fdi_ptr->gda->tab_ptr, 0, HASHTAB_NO_COMPACT, HASHTAB_NO_SPARE_TABLE); fdi_ptr->next = dsid_list->next; dsid_list->next = fdi_ptr; } gv_cur_region = fdi_ptr->gda->maps[1].reg.addr; change_reg(); if (rc_overflow->top < cs_addrs->hdr->blk_size) { if (rc_overflow->buff) free(rc_overflow->buff); rc_overflow->top = cs_addrs->hdr->blk_size; rc_overflow->buff = (char*)malloc(rc_overflow->top); if (rc_overflow_size < rc_overflow->top) rc_overflow_size = rc_overflow->top; } if (!rc_overflow -> top) { rc_overflow -> top = rc_overflow_size; rc_overflow->buff = (char *)malloc(rc_overflow->top); } gd_header = fdi_ptr->gda; return RC_SUCCESS; }
int rc_prc_setf(rc_q_hdr *qhdr) { rc_set *req, *rsp; short data_off, str_remain, *ptr; char *cp1; int i; mval v; ESTABLISH_RET(rc_dbms_ch, RC_SUCCESS); if ((qhdr->a.erc.value = rc_fnd_file(&qhdr->r.xdsid)) != RC_SUCCESS) { REVERT; #ifdef DEBUG gtcm_cpktdmp(qhdr,qhdr->a.len.value,"rc_fnd_file failed."); #endif return -1; } rsp = req = (rc_set *)qhdr; v.mvtype = MV_STR; for (cp1 = req->key.key; *cp1; cp1++) ; v.str.len = cp1 - req->key.key; v.str.addr = req->key.key; if (v.str.len > 8) /* GT.M does not support global variables > 8 chars */ { qhdr->a.erc.value = RC_KEYTOOLONG; REVERT; #ifdef DEBUG gtcm_cpktdmp(qhdr,qhdr->a.len.value,"RC_KEYTOOLONG."); #endif return -1; } gv_bind_name(gd_header, &v.str); memcpy(gv_currkey->base, req->key.key, req->key.len.value); gv_currkey->end = req->key.len.value; gv_currkey->base[gv_currkey->end] = 0; for (i = gv_currkey->end - 2; i > 0; i--) if (!gv_currkey->base[i - 1]) break; gv_currkey->prev = i; ptr = (short*)(req->key.key + req->key.len.value); GET_SHORT(v.str.len, ptr); ptr++; GET_SHORT(data_off ,ptr); ptr++; GET_SHORT(str_remain ,ptr); ptr++; if (gv_currkey->end + 1 + v.str.len + sizeof(rec_hdr) > gv_cur_region->max_rec_size) { qhdr->a.erc.value = RC_KEYTOOLONG; #ifdef DEBUG gtcm_cpktdmp(qhdr,qhdr->a.len.value,"RC_KEYTOOLONG."); #endif } else /* the total record will fit into a block */ { if (rc_set_fragment = data_off) /* just send fragment */ { v.str.len = v.str.len - data_off - str_remain; v.str.addr = (char*)ptr; } else /* first fragment, put whole record, with zero filler */ { v.str.addr = (char*)malloc(v.str.len); memset(v.str.addr, 0, v.str.len); memcpy(v.str.addr + data_off, ptr, v.str.len - data_off - str_remain); } v.mvtype = MV_STR; gvcst_put(&v); if (rc_set_fragment) rc_set_fragment = 0; else free(v.str.addr); } REVERT; return ((qhdr->a.erc.value == RC_SUCCESS) ? 0 : -1); }
static HLOCAL GRPFILE_ScanProgram(LPCSTR buffer, INT size, LPCSTR program_ptr, INT seqnum, LPCSTR extension, HLOCAL hGroup, LPCSTR lpszGrpFile) { INT icontype; HICON hIcon; LPCSTR lpszName, lpszCmdLine, lpszIconFile, lpszWorkDir; LPCSTR iconinfo_ptr, iconANDbits_ptr, iconXORbits_ptr; INT x, y, nIconIndex, iconANDsize, iconXORsize; INT nHotKey, nCmdShow; UINT width, height, planes, bpp; x = GET_SHORT(program_ptr, 0); y = GET_SHORT(program_ptr, 2); nIconIndex = GET_USHORT(program_ptr, 4); /* FIXME is this correct ?? */ icontype = GET_USHORT(program_ptr, 6); switch (icontype) { default: MAIN_MessageBoxIDS_s(IDS_UNKNOWN_FEATURE_s, lpszGrpFile, IDS_WARNING, MB_OK); case 0x048c: iconXORsize = GET_USHORT(program_ptr, 8); iconANDsize = GET_USHORT(program_ptr, 10) / 8; iconinfo_ptr = buffer + GET_USHORT(program_ptr, 12); iconXORbits_ptr = buffer + GET_USHORT(program_ptr, 14); iconANDbits_ptr = buffer + GET_USHORT(program_ptr, 16); width = GET_USHORT(iconinfo_ptr, 4); height = GET_USHORT(iconinfo_ptr, 6); planes = GET_USHORT(iconinfo_ptr, 10); bpp = GET_USHORT(iconinfo_ptr, 11); break; case 0x000c: iconANDsize = GET_USHORT(program_ptr, 8); iconXORsize = GET_USHORT(program_ptr, 10); iconinfo_ptr = buffer + GET_USHORT(program_ptr, 12); iconANDbits_ptr = buffer + GET_USHORT(program_ptr, 14); iconXORbits_ptr = buffer + GET_USHORT(program_ptr, 16); width = GET_USHORT(iconinfo_ptr, 4); height = GET_USHORT(iconinfo_ptr, 6); planes = GET_USHORT(iconinfo_ptr, 10); bpp = GET_USHORT(iconinfo_ptr, 11); } if (iconANDbits_ptr + iconANDsize > buffer + size || iconXORbits_ptr + iconXORsize > buffer + size) return(0); hIcon = CreateIcon( Globals.hInstance, width, height, planes, bpp, iconANDbits_ptr, iconXORbits_ptr ); lpszName = buffer + GET_USHORT(program_ptr, 18); lpszCmdLine = buffer + GET_USHORT(program_ptr, 20); lpszIconFile = buffer + GET_USHORT(program_ptr, 22); if (iconinfo_ptr + 6 > buffer + size || lpszName > buffer + size || lpszCmdLine > buffer + size || lpszIconFile > buffer + size) return(0); /* Scan Extensions */ lpszWorkDir = ""; nHotKey = 0; nCmdShow = SW_SHOWNORMAL; if (extension) { LPCSTR ptr = extension; while (ptr + 6 <= buffer + size) { UINT type = GET_USHORT(ptr, 0); UINT number = GET_USHORT(ptr, 2); UINT skip = GET_USHORT(ptr, 4); if (number == seqnum) { switch (type) { case 0x8000: if (ptr + 10 > buffer + size) return(0); if (ptr[6] != 'P' || ptr[7] != 'M' || ptr[8] != 'C' || ptr[9] != 'C') return(0); break; case 0x8101: lpszWorkDir = ptr + 6; break; case 0x8102: if (ptr + 8 > buffer + size) return(0); nHotKey = GET_USHORT(ptr, 6); break; case 0x8103: if (ptr + 8 > buffer + size) return(0); nCmdShow = GET_USHORT(ptr, 6); break; default: MAIN_MessageBoxIDS_s(IDS_UNKNOWN_FEATURE_s, lpszGrpFile, IDS_WARNING, MB_OK); } } if (!skip) break; ptr += skip; } } return (PROGRAM_AddProgram(hGroup, hIcon, lpszName, x, y, lpszCmdLine, lpszIconFile, nIconIndex, lpszWorkDir, nHotKey, nCmdShow)); }
void dse_chng_rhead(void) { block_id blk; sm_uc_ptr_t bp, b_top, cp, rp; boolean_t chng_rec; rec_hdr new_rec; uint4 x; blk_segment *bs1, *bs_ptr; int4 blk_seg_cnt, blk_size; srch_blk_status blkhist; error_def(ERR_DBRDONLY); error_def(ERR_DSEBLKRDFAIL); error_def(ERR_DSEFAIL); if (gv_cur_region->read_only) rts_error(VARLSTCNT(4) ERR_DBRDONLY, 2, DB_LEN_STR(gv_cur_region)); CHECK_AND_RESET_UPDATE_ARRAY; /* reset update_array_ptr to update_array */ if (cli_present("BLOCK") == CLI_PRESENT) { if(!cli_get_hex("BLOCK", (uint4 *)&blk)) return; patch_curr_blk = blk; } if (patch_curr_blk < 0 || patch_curr_blk >= cs_addrs->ti->total_blks || !(patch_curr_blk % cs_addrs->hdr->bplmap)) { util_out_print("Error: invalid block number.", TRUE); return; } t_begin_crit(ERR_DSEFAIL); blkhist.blk_num = patch_curr_blk; if (!(blkhist.buffaddr = t_qread(blkhist.blk_num, &blkhist.cycle, &blkhist.cr))) rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); bp = blkhist.buffaddr; blk_size = cs_addrs->hdr->blk_size; chng_rec = FALSE; b_top = bp + ((blk_hdr_ptr_t)bp)->bsiz; if (((blk_hdr_ptr_t)bp)->bsiz > blk_size || ((blk_hdr_ptr_t)bp)->bsiz < SIZEOF(blk_hdr)) chng_rec = TRUE; /* force rewrite to correct size */ if (cli_present("RECORD") == CLI_PRESENT) { if (!(rp = skan_rnum(bp, FALSE))) { t_abort(gv_cur_region, cs_addrs); return; } } else if (!(rp = skan_offset(bp, FALSE))) { t_abort(gv_cur_region, cs_addrs); return; } GET_SHORT(new_rec.rsiz, &((rec_hdr_ptr_t)rp)->rsiz); new_rec.cmpc = ((rec_hdr_ptr_t)rp)->cmpc; if (cli_present("CMPC") == CLI_PRESENT) { if (!cli_get_hex("CMPC", &x)) { t_abort(gv_cur_region, cs_addrs); return; } if (x > 0x7f) { util_out_print("Error: invalid cmpc.",TRUE); t_abort(gv_cur_region, cs_addrs); return; } if (x > patch_comp_count) util_out_print("Warning: specified compression count is larger than the current expanded key size.", TRUE); new_rec.cmpc = x; chng_rec = TRUE; } if (cli_present("RSIZ") == CLI_PRESENT) { if (!cli_get_hex("RSIZ", &x)) { t_abort(gv_cur_region, cs_addrs); return; } if (x < SIZEOF(rec_hdr) || x > blk_size) { util_out_print("Error: invalid rsiz.", TRUE); t_abort(gv_cur_region, cs_addrs); return; } new_rec.rsiz = x; chng_rec = TRUE; } if (chng_rec) { BLK_INIT(bs_ptr, bs1); cp = bp; cp += SIZEOF(blk_hdr); if (chng_rec) { BLK_SEG(bs_ptr, cp, rp - cp); BLK_SEG(bs_ptr, (uchar_ptr_t)&new_rec, SIZEOF(rec_hdr)); cp = rp + SIZEOF(rec_hdr); } if (b_top - cp) BLK_SEG(bs_ptr, cp, b_top - cp); if (!BLK_FINI(bs_ptr, bs1)) { util_out_print("Error: bad blk build.", TRUE); t_abort(gv_cur_region, cs_addrs); return; } t_write(&blkhist, (unsigned char *)bs1, 0, 0, ((blk_hdr_ptr_t)bp)->levl, TRUE, FALSE, GDS_WRITE_KILLTN); BUILD_AIMG_IF_JNL_ENABLED(cs_data, non_tp_jfb_buff_ptr, cs_addrs->ti->curr_tn); t_end(&dummy_hist, NULL, TN_NOT_SPECIFIED); } return; }
void dse_exhaus(int4 pp, int4 op) { sm_uc_ptr_t bp, np, b_top, rp, r_top, nrp, nr_top, ptr; char util_buff[MAX_UTIL_LEN]; block_id last; short temp_short; int count, util_len; int4 dummy_int; cache_rec_ptr_t dummy_cr; global_dir_path *d_ptr, *temp; error_def(ERR_DSEBLKRDFAIL); error_def(ERR_CTRLC); last = 0; patch_path_count++; if(!(bp = t_qread(patch_path[pp - 1],&dummy_int,&dummy_cr))) rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); if (((blk_hdr_ptr_t) bp)->bsiz > cs_addrs->hdr->blk_size) b_top = bp + cs_addrs->hdr->blk_size; else if (((blk_hdr_ptr_t) bp)->bsiz < sizeof(blk_hdr)) b_top = bp + sizeof(blk_hdr); else b_top = bp + ((blk_hdr_ptr_t) bp)->bsiz; for (rp = bp + sizeof(blk_hdr); rp < b_top ;rp = r_top) { if (util_interrupt) { rts_error(VARLSTCNT(1) ERR_CTRLC); break; } if (!(np = t_qread(patch_path[pp - 1],&dummy_int,&dummy_cr))) rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); if (np != bp) { b_top = np + (b_top - bp); rp = np + (rp - bp); r_top = np + (r_top - bp); bp = np; } GET_SHORT(temp_short,&((rec_hdr_ptr_t) rp)->rsiz); r_top = rp + temp_short; if (r_top > b_top) r_top = b_top; if (r_top - rp < sizeof(block_id)) break; if (((blk_hdr_ptr_t)bp)->levl) GET_LONG(patch_path[pp],(r_top - sizeof(block_id))); else { for (ptr = rp + sizeof(rec_hdr); ; ) { if (*ptr++ == 0 && *ptr++ ==0) break; } GET_LONG(patch_path[pp],ptr); } patch_offset[op] = rp - bp; if (patch_path[pp] == patch_find_blk) { if (!patch_exh_found) { if (patch_find_sibs) util_out_print("!/ Left siblings Right siblings",TRUE); patch_exh_found = TRUE; } if (patch_find_sibs) { patch_left_sib = last; if (r_top < b_top) { nrp = r_top; GET_SHORT(temp_short,&((rec_hdr_ptr_t) rp)->rsiz); nr_top = nrp + temp_short; if (nr_top > b_top) nr_top = b_top; if (nr_top - nrp >= sizeof(block_id)) { if (((blk_hdr_ptr_t)bp)->levl) GET_LONG(patch_right_sib,(nr_top - sizeof(block_id))); else { for (ptr = rp + sizeof(rec_hdr); ;) { if (*ptr++ == 0 && *ptr++ == 0) break; } GET_LONG(patch_right_sib,ptr); } } } else patch_right_sib = 0; if (patch_left_sib) { memcpy(util_buff," ",1); util_len = 1; util_len += i2hex_nofill(patch_left_sib,(uchar_ptr_t)&util_buff[util_len],8); memcpy(&util_buff[util_len]," ",1); util_len += 1; util_buff[util_len] = 0; util_out_print(util_buff,FALSE); }else util_out_print(" none ",FALSE); if (patch_right_sib) { memcpy(util_buff," ",1); util_len = 1; util_len += i2hex_nofill(patch_right_sib,(uchar_ptr_t)&util_buff[util_len],8); util_buff[util_len] = 0; util_out_print(util_buff,FALSE); } else util_out_print(" none",TRUE); } else /* !patch_find_sibs */ { patch_path_count--; util_out_print(" Directory path!/ Path--blk:off",TRUE); if (!patch_find_root_search) { d_ptr = global_roots_head->link->dir_path; while(d_ptr) { memcpy(util_buff," ",1); util_len = 1; util_len += i2hex_nofill(d_ptr->block,(uchar_ptr_t)&util_buff[util_len],8); memcpy(&util_buff[util_len],":",1); util_len += 1; util_len += i2hex_nofill(d_ptr->offset,(uchar_ptr_t)&util_buff[util_len],4); util_buff[util_len] = 0; util_out_print(util_buff,FALSE); temp = d_ptr; d_ptr = d_ptr->next; free(temp); } global_roots_head->link->dir_path = 0; util_out_print("!/!/ Global paths!/ Path--blk:off",TRUE); } for (count = 0; count < patch_path_count ;count++) { memcpy(util_buff," ",1); util_len = 1; util_len += i2hex_nofill(patch_path[count],(uchar_ptr_t)&util_buff[util_len],8); memcpy(&util_buff[util_len],":",1); util_len += 1; util_len += i2hex_nofill(patch_offset[count],(uchar_ptr_t)&util_buff[util_len],4); util_buff[util_len] = 0; util_out_print(util_buff,FALSE); } memcpy(util_buff," ",1); util_len = 1; util_len += i2hex_nofill(patch_path[count],(uchar_ptr_t)&util_buff[util_len],8); util_buff[util_len] = 0; util_out_print(util_buff,TRUE); patch_path_count++; } } if (patch_path[pp] > 0 && patch_path[pp] < cs_addrs->ti->total_blks && (patch_path[pp] % cs_addrs->hdr->bplmap)) if (((blk_hdr_ptr_t) bp)->levl > 1) dse_exhaus(pp + 1,op + 1); else if (((blk_hdr_ptr_t)bp)->levl == 1 && patch_find_root_search) dse_find_roots(patch_path[pp]); last = patch_path[pp]; } patch_path_count--; return; }
static HLOCAL GRPFILE_ScanGroup(LPCSTR buffer, INT size, LPCSTR lpszGrpFile, BOOL bModifiedFileName) { HLOCAL hGroup; INT i, seqnum; LPCSTR extension; LPCSTR lpszName; INT x, y, width, height, iconx, icony, nCmdShow; INT number_of_programs; BOOL bOverwriteFileOk; if (buffer[0] != 'P' || buffer[1] != 'M') return(0); if (buffer[2] == 'C' && buffer[3] == 'C') /* original with checksum */ bOverwriteFileOk = FALSE; else if (buffer[2] == 'X' && buffer[3] == 'X') /* modified without checksum */ bOverwriteFileOk = TRUE; else return(0); /* checksum = GET_USHORT(buffer, 4) (ignored) */ extension = buffer + GET_USHORT(buffer, 6); if (extension == buffer + size) extension = 0; else if (extension + 6 > buffer + size) return(0); nCmdShow = GET_USHORT(buffer, 8); x = GET_SHORT(buffer, 10); y = GET_SHORT(buffer, 12); width = GET_USHORT(buffer, 14); height = GET_USHORT(buffer, 16); iconx = GET_SHORT(buffer, 18); icony = GET_SHORT(buffer, 20); lpszName = buffer + GET_USHORT(buffer, 22); if (lpszName >= buffer + size) return(0); /* unknown bytes 24 - 31 ignored */ /* Unknown bytes should be: wLogPixelsX = GET_SHORT(buffer, 24); wLogPixelsY = GET_SHORT(buffer, 26); byBitsPerPixel = byte at 28; byPlanes = byte at 29; wReserved = GET_SHORT(buffer, 30); */ hGroup = GROUP_AddGroup(lpszName, lpszGrpFile, nCmdShow, x, y, width, height, iconx, icony, bModifiedFileName, bOverwriteFileOk, TRUE); if (!hGroup) return(0); number_of_programs = GET_USHORT(buffer, 32); if (2 * number_of_programs + 34 > size) return(0); for (i=0, seqnum=0; i < number_of_programs; i++, seqnum++) { LPCSTR program_ptr = buffer + GET_USHORT(buffer, 34 + 2*i); if (program_ptr + 24 > buffer + size) return(0); if (!GET_USHORT(buffer, 34 + 2*i)) continue; if (!GRPFILE_ScanProgram(buffer, size, program_ptr, seqnum, extension, hGroup, lpszGrpFile)) { GROUP_DeleteGroup(hGroup); return(0); } } /* FIXME shouldn't be necessary */ GROUP_ShowGroupWindow(hGroup); return hGroup; }
int dse_ksrch(block_id srch, block_id_ptr_t pp, int4 *off, char *targ_key, int targ_len) { cache_rec_ptr_t dummy_cr; int rsize, tmp_cmpc; int4 cmp, dummy_int; ssize_t size; sm_uc_ptr_t blk_id, bp, b_top, key_top, rp, r_top; unsigned short cc, dummy_short; if(!(bp = t_qread(srch, &dummy_int, &dummy_cr))) rts_error_csa(CSA_ARG(cs_addrs) VARLSTCNT(1) ERR_DSEBLKRDFAIL); if (((blk_hdr_ptr_t) bp)->bsiz > cs_addrs->hdr->blk_size) b_top = bp + cs_addrs->hdr->blk_size; else if (((blk_hdr_ptr_t) bp)->bsiz < SIZEOF(blk_hdr)) b_top = bp + SIZEOF(blk_hdr); else b_top = bp + ((blk_hdr_ptr_t) bp)->bsiz; CLEAR_DSE_COMPRESS_KEY; *off = 0; for (rp = bp + SIZEOF(blk_hdr); rp < b_top; rp = r_top) { *off = (int4)(rp - bp); GET_SHORT(dummy_short, &((rec_hdr_ptr_t)rp)->rsiz); rsize = dummy_short; if (rsize < SIZEOF(rec_hdr)) r_top = rp + SIZEOF(rec_hdr); else r_top = rp + rsize; if (r_top > b_top) r_top = b_top; if (r_top - rp < (((blk_hdr_ptr_t)bp)->levl ? SIZEOF(block_id) : MIN_DATA_SIZE) + SIZEOF(rec_hdr)) { *pp = 0; break; } for (key_top = rp + SIZEOF(rec_hdr); key_top < r_top ; ) if (!*key_top++ && !*key_top++) break; if (((blk_hdr_ptr_t)bp)->levl && key_top > (blk_id = r_top - SIZEOF(block_id))) key_top = blk_id; if (EVAL_CMPC((rec_hdr_ptr_t)rp) > patch_comp_count) cc = patch_comp_count; else cc = EVAL_CMPC((rec_hdr_ptr_t)rp); size = (ssize_t)(key_top - rp - SIZEOF(rec_hdr)); if (size > MAX_KEY_SZ - cc) size = MAX_KEY_SZ - cc; if (size < 0) size = 0; memcpy(&patch_comp_key[cc], rp + SIZEOF(rec_hdr), size); patch_comp_count = (int)(cc + size); GET_LONGP(pp, key_top); cmp = memvcmp(targ_key, targ_len, &patch_comp_key[0], patch_comp_count); if (0 > cmp) break; if (!cmp) { if (0 != ((blk_hdr_ptr_t)bp)->levl) break; if (patch_find_root_search) { for (key_top = rp + SIZEOF(rec_hdr); key_top < r_top; ) if (!*key_top++ && !*key_top++) break; GET_LONG(ksrch_root, key_top); } return TRUE; } } patch_path_count++; if (((blk_hdr_ptr_t) bp)->levl && *pp > 0 && *pp < cs_addrs->ti->total_blks && (*pp % cs_addrs->hdr->bplmap) && dse_ksrch(*pp, pp + 1, off + 1, targ_key, targ_len)) return TRUE; return FALSE; }
void op_gvrectarg (mval *v) { int len, n; mstr temp; unsigned char *c; /* You might be somewhat apprehensive at the seemingly cavalier use of GTMASSERT in this routine. First, let me explain myself. The mvals passed to RECTARG are supposed to come only from SAVTARG, and are to represent the state of gv_currkey when SAVTARG was done. Consequently, there are certain preconditions that one can expect. Namely, 1) SAVTARG makes all mvals MV_STR's. If this one isn't, it should be. 2) If gv_currkey existed for SAVTARG (len is > 0), it had better exist for RECTARG. 3) All gv_keys end with 00. When reading this mval, if you run out of characters before you see a 0, something is amiss. */ if (!MV_IS_STRING(v)) GTMASSERT; n = len = v->str.len - sizeof(short) - sizeof(gd_targ_addr); if (len <= 0) { if (gv_currkey) { gv_currkey->end = gv_currkey->prev = 0; } return; } if (!gv_currkey) GTMASSERT; c = (unsigned char *) (v->str.addr + sizeof(short) + sizeof(gd_targ_addr)); temp.addr = (char *)c; while (*c++) { n--; if (n <= 0) GTMASSERT; } temp.len = (char *)c - temp.addr - 1; if ( (gd_header != 0 && gd_header->maps == gd_map) && (gv_currkey->base[temp.len] == 0 && memcmp(gv_currkey->base, temp.addr, temp.len) == 0) ) { gv_currkey->end = temp.len + 1; gv_currkey->prev = 0; gv_currkey->base[temp.len + 1] = 0; if (gv_cur_region->dyn.addr->acc_meth == dba_bg || gv_cur_region->dyn.addr->acc_meth == dba_mm) { if (dollar_tlevel != 0 && first_sgm_info == NULL) tp_set_sgm(); if (gv_target->root == 0 || gv_target->root == DIR_ROOT) gvcst_root_search(); } } else { memcpy(&gd_targ_addr, v->str.addr + sizeof(short), sizeof(gd_targ_addr)); gv_bind_name(gd_targ_addr, &(temp)); } c = (unsigned char *)v->str.addr; GET_SHORT(gv_currkey->prev,c); c += sizeof(short) + sizeof(gd_targ_addr); gv_currkey->end = len; memcpy(gv_currkey->base, c, len); gv_currkey->base[len] = 0; c = &gv_currkey->base [ gv_currkey->prev ]; gv_curr_subsc_null = ( *c++ == 255 && *c == 0); return; }
sm_uc_ptr_t dump_record(sm_uc_ptr_t rp, block_id blk, sm_uc_ptr_t bp, sm_uc_ptr_t b_top) { sm_uc_ptr_t r_top, key_top, cptr0, cptr1, cptr_top, cptr_base = NULL, cptr_next = NULL; char key_buf[MAX_KEY_SZ + 1], *temp_ptr, *temp_key, util_buff[MAX_UTIL_LEN]; char *prefix_str, *space_str, *dot_str, *format_str; unsigned char cc; short int size; int4 util_len, head; uint4 ch; int buf_len, field_width,fastate, chwidth = 0; ssize_t chlen; block_id blk_id; boolean_t rechdr_displayed = FALSE; sgmnt_addrs *csa; if (rp >= b_top) return NULL; head = cli_present("HEADER"); GET_SHORT(size, &((rec_hdr_ptr_t)rp)->rsiz); cc = ((rec_hdr_ptr_t)rp)->cmpc; if ((CLI_NEGATED != head) && !patch_is_fdmp) { MEMCPY_LIT(util_buff, "Rec:"); util_len = SIZEOF("Rec:") - 1; util_len += i2hex_nofill(patch_rec_counter, (uchar_ptr_t)&util_buff[util_len], 4); MEMCPY_LIT(&util_buff[util_len], " Blk "); util_len += SIZEOF(" Blk ") - 1; util_len += i2hex_nofill(blk, (uchar_ptr_t)&util_buff[util_len], 8); MEMCPY_LIT(&util_buff[util_len], " Off "); util_len += SIZEOF(" Off ") - 1; util_len += i2hex_nofill((int)(rp - bp), (uchar_ptr_t)&util_buff[util_len], 4); MEMCPY_LIT(&util_buff[util_len], " Size "); util_len += SIZEOF(" Size ") - 1; util_len += i2hex_nofill(size, (uchar_ptr_t)&util_buff[util_len], 4); MEMCPY_LIT(&util_buff[util_len], " Cmpc "); util_len += SIZEOF(" Cmpc ") - 1; util_len += i2hex_nofill(cc, (uchar_ptr_t)&util_buff[util_len], 2); MEMCPY_LIT(&util_buff[util_len], " "); util_len += SIZEOF(" ") - 1; util_buff[util_len] = 0; util_out_print(util_buff, FALSE); } r_top = rp + size; if (r_top > b_top) r_top = b_top; else if (r_top < rp + SIZEOF(rec_hdr)) r_top = rp + SIZEOF(rec_hdr); if (cc > patch_comp_count) cc = patch_comp_count; if (((blk_hdr_ptr_t)bp)->levl) key_top = r_top - SIZEOF(block_id); else { for (key_top = rp + SIZEOF(rec_hdr); key_top < r_top;) if (!*key_top++ && !*key_top++) break; } size = key_top - rp - SIZEOF(rec_hdr); if (size > SIZEOF(patch_comp_key) - 2 - cc) size = SIZEOF(patch_comp_key) - 2 - cc; if (size < 0) size = 0; memcpy(&patch_comp_key[cc], rp + SIZEOF(rec_hdr), size); patch_comp_count = cc + size; patch_comp_key[patch_comp_count] = patch_comp_key[patch_comp_count + 1] = 0; if (patch_is_fdmp) { if (dse_fdmp(key_top, (int)(r_top - key_top))) patch_fdmp_recs++; } else { if (r_top - SIZEOF(block_id) >= key_top) { GET_LONG(blk_id, key_top); if ((((blk_hdr_ptr_t)bp)->levl) || (blk_id <= cs_addrs->ti->total_blks)) { MEMCPY_LIT(util_buff, "Ptr "); util_len = SIZEOF("Ptr ") - 1; util_len += i2hex_nofill(blk_id, (uchar_ptr_t)&util_buff[util_len], SIZEOF(blk_id) * 2); MEMCPY_LIT(&util_buff[util_len], " "); util_len += SIZEOF(" ") - 1; util_buff[util_len] = 0; util_out_print(util_buff, FALSE); } } util_out_print("Key ", FALSE); if (r_top == b_top && ((blk_hdr_ptr_t)bp)->levl && !((rec_hdr_ptr_t)rp)->cmpc && r_top - rp == SIZEOF(rec_hdr) + SIZEOF(block_id)) util_out_print("*", FALSE); else if (patch_comp_key[0]) { util_out_print("^", FALSE); csa = cs_addrs; RETRIEVE_ROOT_VAL(patch_comp_key, key_buf, temp_ptr, temp_key, buf_len); INIT_ROOT_GVT(key_buf, buf_len, curr_gbl_root); } print_target((uchar_ptr_t)patch_comp_key); util_out_print(0, TRUE); if (CLI_PRESENT != head) { prefix_str = " |"; if (wide_out) { format_str = " !AD"; dot_str = " ."; space_str = " "; field_width = 4; } else { format_str = " !AD"; dot_str = " ."; space_str = " "; field_width = 3; } fastate = 0; for (cptr0 = rp; cptr0 < r_top; cptr0 += NUM_BYTES_PER_LINE) { if (util_interrupt) { /* return, rather than signal ERR_CTRLC so that the calling routine can deal with that signal and do the appropriate cleanup */ return NULL; } util_len = 8; i2hex_blkfill((int)(cptr0 - bp), (uchar_ptr_t)util_buff, 8); MEMCPY_LIT(&util_buff[util_len], " : |"); util_len += SIZEOF(" : |") - 1; util_buff[util_len] = 0; util_out_print(util_buff, FALSE); /* Dump hexadecimal byte values */ for (cptr1 = cptr0; cptr1 < (cptr0 + NUM_BYTES_PER_LINE); cptr1++) { if (cptr1 < r_top) { i2hex_blkfill(*(sm_uc_ptr_t)cptr1, (uchar_ptr_t)util_buff, field_width); util_buff[field_width] = 0; util_out_print(util_buff, FALSE); } else util_out_print(space_str, FALSE); } util_out_print("|", TRUE); util_out_print(prefix_str, FALSE); /* Display character/wide-character glyphs */ for (cptr1 = cptr0, cptr_top = cptr0 + NUM_BYTES_PER_LINE; cptr1 < cptr_top; cptr1++) { if (!rechdr_displayed && (cptr1 == (rp + SIZEOF(rec_hdr)))) rechdr_displayed = TRUE; assert(rechdr_displayed || (cptr1 < (rp + SIZEOF(rec_hdr)))); assert(!rechdr_displayed || (cptr1 >= (rp + SIZEOF(rec_hdr)))); switch (fastate) { case 0: /* prints single-byte characters or intepret multi-byte characters */ if (cptr1 >= r_top) util_out_print(space_str, FALSE); else if (!gtm_utf8_mode || IS_ASCII(*cptr1) || !rechdr_displayed) { /* single-byte characters */ if (PRINTABLE(*(sm_uc_ptr_t)cptr1)) util_out_print(format_str, FALSE, 1, cptr1); else util_out_print(dot_str, FALSE); } #ifdef UNICODE_SUPPORTED else { /* multi-byte characters */ cptr_next = UTF8_MBTOWC(cptr1, r_top, ch); chlen = cptr_next - cptr1; if (WEOF == ch || !U_ISPRINT(ch)) { /* illegal or non-printable characters */ cptr1--; fastate = 1; } else { /* multi-byte printable characters */ cptr_base = cptr1; chwidth = UTF8_WCWIDTH(ch); assert(chwidth >= 0 && chwidth <= 2); cptr1--; fastate = 2; } } #endif break; case 1: /* illegal or non-printable characters */ util_out_print(dot_str, FALSE); if (--chlen <= 0) fastate = 0; break; case 2: /* printable multi-byte characters */ if (chlen-- > 1) /* fill leading bytes with spaces */ util_out_print(space_str, FALSE); else { util_out_print("!AD", FALSE, field_width - chwidth, space_str); if (0 < chwidth) util_out_print("!AD", FALSE, cptr_next - cptr_base, cptr_base); fastate = 0; } break; } } util_out_print("|", TRUE); } } if (CLI_NEGATED != head) util_out_print(0, TRUE); } return (r_top == b_top) ? NULL : r_top; }
sm_uc_ptr_t dump_record(sm_uc_ptr_t rp, block_id blk, sm_uc_ptr_t bp, sm_uc_ptr_t b_top) { sm_uc_ptr_t r_top, key_top, cptr0, cptr1; char key_buf[MAX_KEY_SZ + 1], *temp_ptr, *temp_key, util_buff[MAX_UTIL_LEN]; unsigned char cc; short int size; int4 util_len, head; int buf_len; block_id blk_id; if (rp >= b_top) return NULL; head = cli_present("HEADER"); GET_SHORT(size, &((rec_hdr_ptr_t)rp)->rsiz); cc = ((rec_hdr_ptr_t)rp)->cmpc; if ((CLI_NEGATED != head) && !patch_is_fdmp) { memcpy(util_buff, "Rec:", sizeof("Rec:") - 1); util_len = sizeof("Rec:") - 1; util_len += i2hex_nofill(patch_rec_counter, (uchar_ptr_t)&util_buff[util_len], 4); memcpy(&util_buff[util_len], " Blk ", sizeof(" Blk ") - 1); util_len += sizeof(" Blk ") - 1; util_len += i2hex_nofill(blk, (uchar_ptr_t)&util_buff[util_len], 8); memcpy(&util_buff[util_len], " Off ", sizeof(" Off ") - 1); util_len += sizeof(" Off ") - 1; util_len += i2hex_nofill(rp - bp, (uchar_ptr_t)&util_buff[util_len], 4); memcpy(&util_buff[util_len], " Size ", sizeof(" Size ") - 1); util_len += sizeof(" Size ") - 1; util_len += i2hex_nofill(size, (uchar_ptr_t)&util_buff[util_len], 4); memcpy(&util_buff[util_len], " Cmpc ", sizeof(" Cmpc ") - 1); util_len += sizeof(" Cmpc ") - 1; util_len += i2hex_nofill(cc, (uchar_ptr_t)&util_buff[util_len], 2); memcpy(&util_buff[util_len], " ", sizeof(" ") - 1); util_len += sizeof(" ") - 1; util_buff[util_len] = 0; util_out_print(util_buff, FALSE); } r_top = rp + size; if (r_top > b_top) r_top = b_top; else if (r_top < rp + sizeof(rec_hdr)) r_top = rp + sizeof(rec_hdr); if (cc > patch_comp_count) cc = patch_comp_count; if (((blk_hdr_ptr_t)bp)->levl) key_top = r_top - sizeof(block_id); else { for (key_top = rp + sizeof(rec_hdr); key_top < r_top;) if (!*key_top++ && !*key_top++) break; } size = key_top - rp - sizeof(rec_hdr); if (size < 0) size = 0; else if (size > sizeof(patch_comp_key) - 2) size = sizeof(patch_comp_key) - 2; memcpy(&patch_comp_key[cc], rp + sizeof(rec_hdr), size); patch_comp_count = cc + size; patch_comp_key[patch_comp_count] = patch_comp_key[patch_comp_count + 1] = 0; if (patch_is_fdmp) { if (dse_fdmp(key_top, r_top - key_top)) patch_fdmp_recs++; } else { if (r_top - sizeof(block_id) >= key_top) { GET_LONG(blk_id, key_top); if ((((blk_hdr_ptr_t)bp)->levl) || (blk_id <= cs_addrs->ti->total_blks)) { memcpy(util_buff, "Ptr ", sizeof("Ptr ") - 1); util_len = sizeof("Ptr ") - 1; util_len += i2hex_nofill(blk_id, (uchar_ptr_t)&util_buff[util_len], sizeof(blk_id) * 2); memcpy(&util_buff[util_len], " ", sizeof(" ") - 1); util_len += sizeof(" ") - 1; util_buff[util_len] = 0; util_out_print(util_buff, FALSE); } } util_out_print("Key ", FALSE); if (r_top == b_top && ((blk_hdr_ptr_t)bp)->levl && !((rec_hdr_ptr_t)rp)->cmpc && r_top - rp == sizeof(rec_hdr) + sizeof(block_id)) util_out_print("*", FALSE); else if (patch_comp_key[0]) { util_out_print("^", FALSE); RETRIEVE_ROOT_VAL(patch_comp_key, key_buf, temp_ptr, temp_key, buf_len); INIT_ROOT_GVT(key_buf, buf_len, curr_gbl_root); } print_target((uchar_ptr_t)patch_comp_key); util_out_print(0, TRUE); if (CLI_PRESENT != head) { for (cptr0 = rp; cptr0 < r_top; cptr0 += 20) { if (util_interrupt) { /* return, rather than signal ERR_CTRLC so * that the calling routine can deal with * that signal and do the appropriate * cleanup. */ return NULL; } util_len = 8; i2hex_blkfill(cptr0 - bp, (uchar_ptr_t)util_buff, 8); memcpy(&util_buff[util_len], " : |", sizeof(" : |") - 1 ); util_len += sizeof(" : |") - 1; util_buff[util_len] = 0; util_out_print(util_buff, FALSE); for (cptr1 = cptr0; cptr1 < (cptr0 + 20); cptr1++) { if (wide_out) { if (cptr1 < r_top) { i2hex_blkfill(*(sm_uc_ptr_t)cptr1, (uchar_ptr_t)util_buff, 4); util_buff[4] = 0; util_out_print(util_buff, FALSE); } else util_out_print(" ", FALSE); } else { if (cptr1 < r_top) { i2hex_blkfill(*(sm_uc_ptr_t)cptr1, (uchar_ptr_t)util_buff, 3); util_buff[3] = 0; util_out_print(util_buff, FALSE); } else util_out_print(" ", FALSE); } } if (wide_out) { util_out_print("| |", FALSE); for (cptr1 = cptr0; cptr1 < (cptr0 + 20); cptr1++) { if (cptr1 < r_top) { if (PRINTABLE(*(sm_uc_ptr_t)cptr1)) util_out_print("!AD", FALSE, 1, cptr1); else util_out_print(".", FALSE); } else util_out_print(" ", FALSE); } } else { util_out_print("|", TRUE); util_out_print(" |", FALSE); for (cptr1 = cptr0; cptr1 < (cptr0 + 20); cptr1++) { if (cptr1 < r_top) { if (PRINTABLE(*(sm_uc_ptr_t)cptr1)) util_out_print(" !AD", FALSE, 1, cptr1); else util_out_print(" .", FALSE); } else util_out_print(" ", FALSE); } } util_out_print("|", TRUE); } } if (CLI_NEGATED != head) util_out_print(0, TRUE); } return (r_top == b_top) ? NULL : r_top; }
void dse_rmrec(void) { block_id blk; blk_segment *bs1, *bs_ptr; int4 blk_seg_cnt, blk_size, count; sm_uc_ptr_t bp; uchar_ptr_t lbp, b_top, rp, r_top, key_top, rp_base; char cc, comp_key[256], cc_base; short int size, i, rsize; cw_set_element *cse; error_def(ERR_DSEFAIL); error_def(ERR_DSEBLKRDFAIL); error_def(ERR_DBRDONLY); if (gv_cur_region->read_only) rts_error(VARLSTCNT(4) ERR_DBRDONLY, 2, DB_LEN_STR(gv_cur_region)); assert(update_array); /* reset new block mechanism */ update_array_ptr = update_array; if (cli_present("BLOCK") == CLI_PRESENT) { if(!cli_get_hex("BLOCK", &blk)) return; if (blk < 0 || blk >= cs_addrs->ti->total_blks || !(blk % cs_addrs->hdr->bplmap)) { util_out_print("Error: invalid block number.", TRUE); return; } patch_curr_blk = blk; } if (cli_present("COUNT") == CLI_PRESENT) { if (!cli_get_hex("COUNT", &count) || count < 1) return; } else count = 1; t_begin_crit(ERR_DSEFAIL); blk_size = cs_addrs->hdr->blk_size; if(!(bp = t_qread(patch_curr_blk, &dummy_hist.h[0].cycle, &dummy_hist.h[0].cr))) rts_error(VARLSTCNT(1) ERR_DSEBLKRDFAIL); lbp = (uchar_ptr_t)malloc(blk_size); memcpy(lbp, bp, blk_size); if (((blk_hdr_ptr_t)lbp)->bsiz > cs_addrs->hdr->blk_size) b_top = lbp + cs_addrs->hdr->blk_size; else if (((blk_hdr_ptr_t)lbp)->bsiz < sizeof(blk_hdr)) b_top = lbp + sizeof(blk_hdr); else b_top = lbp + ((blk_hdr_ptr_t)lbp)->bsiz; if (cli_present("RECORD") == CLI_PRESENT) { if (!(rp = rp_base = skan_rnum(lbp, FALSE))) { free(lbp); t_abort(gv_cur_region, cs_addrs); return; } } else if (!(rp = rp_base = skan_offset(lbp, FALSE))) { free(lbp); t_abort(gv_cur_region, cs_addrs); return; } memcpy(&comp_key[0], &patch_comp_key[0], sizeof(patch_comp_key)); cc_base = patch_comp_count; for ( ; ; ) { GET_SHORT(rsize, &((rec_hdr_ptr_t)rp)->rsiz); if (rsize < sizeof(rec_hdr)) r_top = rp + sizeof(rec_hdr); else r_top = rp + rsize; if (r_top >= b_top) { if (count) { if (((blk_hdr_ptr_t) lbp)->levl) util_out_print("Warning: removed a star record from the end of this block.", TRUE); ((blk_hdr_ptr_t)lbp)->bsiz = rp_base - lbp; BLK_INIT(bs_ptr, bs1); BLK_SEG(bs_ptr, (uchar_ptr_t)lbp + sizeof(blk_hdr), (int)((blk_hdr_ptr_t)lbp)->bsiz - sizeof(blk_hdr)); if (!BLK_FINI(bs_ptr, bs1)) { util_out_print("Error: bad blk build.",TRUE); free(lbp); t_abort(gv_cur_region, cs_addrs); return; } t_write(patch_curr_blk, (unsigned char *)bs1, 0, 0, bp, ((blk_hdr_ptr_t)lbp)->levl, TRUE, FALSE); BUILD_AIMG_IF_JNL_ENABLED(cs_addrs, cs_data, non_tp_jfb_buff_ptr, cse); t_end(&dummy_hist, 0); free(lbp); return; } r_top = b_top; } if (((blk_hdr_ptr_t)lbp)->levl) key_top = r_top - sizeof(block_id); else { for (key_top = rp + sizeof(rec_hdr); key_top < r_top; ) if (!*key_top++ && !*key_top++) break; } if (((rec_hdr_ptr_t)rp)->cmpc > patch_comp_count) cc = patch_comp_count; else cc = ((rec_hdr_ptr_t)rp)->cmpc; size = key_top - rp - sizeof(rec_hdr); if (size < 0) size = 0; else if (size > sizeof(patch_comp_key) - 2) size = sizeof(patch_comp_key) - 2; memcpy(&patch_comp_key[cc], rp + sizeof(rec_hdr), size); patch_comp_count = cc + size; if (--count >= 0) { rp = r_top; continue; } size = (patch_comp_count < cc_base) ? patch_comp_count : cc_base; for (i = 0; i < size && patch_comp_key[i] == comp_key[i]; i++) ; ((rec_hdr_ptr_t)rp_base)->cmpc = i; rsize = r_top - key_top + sizeof(rec_hdr) + patch_comp_count - i; PUT_SHORT(&((rec_hdr_ptr_t)rp_base)->rsiz, rsize); memcpy(rp_base + sizeof(rec_hdr), &patch_comp_key[i], patch_comp_count - i); memcpy(rp_base + sizeof(rec_hdr) + patch_comp_count - i, key_top, b_top - key_top); ((blk_hdr_ptr_t)lbp)->bsiz = rp_base + rsize - lbp + b_top - r_top; BLK_INIT(bs_ptr, bs1); BLK_SEG(bs_ptr, (uchar_ptr_t)lbp + sizeof(blk_hdr), ((blk_hdr_ptr_t)lbp)->bsiz - sizeof(blk_hdr)); if (!BLK_FINI(bs_ptr, bs1)) { util_out_print("Error: bad blk build.", TRUE); free(lbp); t_abort(gv_cur_region, cs_addrs); return; } t_write(patch_curr_blk, (unsigned char *)bs1, 0, 0, bp, ((blk_hdr_ptr_t)lbp)->levl, TRUE, FALSE); BUILD_AIMG_IF_JNL_ENABLED(cs_addrs, cs_data, non_tp_jfb_buff_ptr, cse); t_end(&dummy_hist, 0); free(lbp); return; } }
void bin_load(uint4 begin, uint4 end) { unsigned char *ptr, *cp1, *cp2, *btop, *gvkey_char_ptr, *tmp_ptr, *tmp_key_ptr; unsigned char hdr_lvl, src_buff[MAX_KEY_SZ + 1], dest_buff[MAX_ZWR_KEY_SZ], cmpc_str[MAX_KEY_SZ + 1], dup_key_str[MAX_KEY_SZ + 1]; unsigned char *end_buff; unsigned short len, rec_len, next_cmpc; int current, last, length, max_blk_siz, max_key, status; uint4 iter, max_data_len, max_subsc_len, key_count; ssize_t rec_count, global_key_count, subsc_len,extr_std_null_coll; boolean_t need_xlation, new_gvn, utf8_extract; rec_hdr *rp, *next_rp; mval v, tmp_mval; mstr mstr_src, mstr_dest; collseq *extr_collseq, *db_collseq, *save_gv_target_collseq; coll_hdr extr_collhdr, db_collhdr; gv_key *tmp_gvkey; char std_null_coll[BIN_HEADER_NUMSZ + 1]; error_def(ERR_GVIS); error_def(ERR_TEXT); error_def(ERR_LDBINFMT); error_def(ERR_LOADCTRLY); error_def(ERR_LOADEOF); error_def(ERR_MUNOFINISH); error_def(ERR_COLLTYPVERSION); error_def(ERR_COLLATIONUNDEF); error_def(ERR_OLDBINEXTRACT); error_def(ERR_LOADINVCHSET); tmp_gvkey = (gv_key *)malloc(sizeof(gv_key) + MAX_KEY_SZ - 1); assert(4 == sizeof(coll_hdr)); gvinit(); v.mvtype = MV_STR; len = mu_bin_get((char **)&ptr); hdr_lvl = EXTR_HEADER_LEVEL(ptr); if (!((hdr_lvl == '4' && len == BIN_HEADER_SZ) || (hdr_lvl < '4' && len == V3_BIN_HEADER_SZ))) { rts_error(VARLSTCNT(1) ERR_LDBINFMT); mupip_exit(ERR_LDBINFMT); } /* assert the assumption that the level can be represented in a single character */ assert(' ' == *(ptr + sizeof(BIN_HEADER_LABEL) - 3)); if (0 != memcmp(ptr, BIN_HEADER_LABEL, sizeof(BIN_HEADER_LABEL) - 2) || hdr_lvl < '2' || *(BIN_HEADER_VERSION) < hdr_lvl) { /* ignore the level check */ rts_error(VARLSTCNT(1) ERR_LDBINFMT); mupip_exit(ERR_LDBINFMT); } /* check if extract was generated in UTF-8 mode */ utf8_extract = (0 == MEMCMP_LIT(&ptr[len - BIN_HEADER_LABELSZ], UTF8_NAME)) ? TRUE : FALSE; if ((utf8_extract && !gtm_utf8_mode) || (!utf8_extract && gtm_utf8_mode)) { /* extract CHSET doesn't match $ZCHSET */ if (utf8_extract) rts_error(VARLSTCNT(4) ERR_LOADINVCHSET, 2, LEN_AND_LIT("UTF-8")); else rts_error(VARLSTCNT(4) ERR_LOADINVCHSET, 2, LEN_AND_LIT("M")); mupip_exit(ERR_LDBINFMT); } util_out_print("Label = !AD\n", TRUE, len, ptr); new_gvn = FALSE; if (hdr_lvl > '3') { memcpy(std_null_coll, ptr + BIN_HEADER_NULLCOLLOFFSET, BIN_HEADER_NUMSZ); std_null_coll[BIN_HEADER_NUMSZ] = '\0'; extr_std_null_coll = STRTOUL(std_null_coll, NULL, 10); if (0 != extr_std_null_coll && 1!= extr_std_null_coll) { rts_error(VARLSTCNT(5) ERR_TEXT, 2, RTS_ERROR_TEXT("Corrupted null collation field in header"), ERR_LDBINFMT); mupip_exit(ERR_LDBINFMT); } } else extr_std_null_coll = 0; if (hdr_lvl > '2') { len = mu_bin_get((char **)&ptr); if (sizeof(coll_hdr) != len) { rts_error(VARLSTCNT(5) ERR_TEXT, 2, RTS_ERROR_TEXT("Corrupt collation header"), ERR_LDBINFMT); mupip_exit(ERR_LDBINFMT); } extr_collhdr = *((coll_hdr *)(ptr)); new_gvn = TRUE; } else gtm_putmsg(VARLSTCNT(3) ERR_OLDBINEXTRACT, 1, hdr_lvl - '0'); if (begin < 2) begin = 2; for (iter = 2; iter < begin; iter++) { if (!(len = mu_bin_get((char **)&ptr))) { gtm_putmsg(VARLSTCNT(3) ERR_LOADEOF, 1, begin); util_out_print("Error reading record number: !UL\n", TRUE, iter); mupip_error_occurred = TRUE; return; } else if (len == sizeof(coll_hdr)) { extr_collhdr = *((coll_hdr *)(ptr)); assert(hdr_lvl > '2'); iter--; } } assert(iter == begin); util_out_print("Beginning LOAD at record number: !UL\n", TRUE, begin); max_data_len = 0; max_subsc_len = 0; key_count = 0; rec_count = begin - 1; extr_collseq = db_collseq = NULL; need_xlation = FALSE; for (; !mupip_DB_full ;) { if (++rec_count > end) break; next_cmpc = 0; mupip_error_occurred = FALSE; if (mu_ctrly_occurred) break; if (mu_ctrlc_occurred) { util_out_print("!AD:!_ Key cnt: !UL max subsc len: !UL max data len: !UL", TRUE, LEN_AND_LIT(gt_lit), key_count, max_subsc_len, max_data_len); util_out_print("Last LOAD record number: !UL", TRUE, key_count ? (rec_count - 1) : 0); mu_gvis(); util_out_print(0, TRUE); mu_ctrlc_occurred = FALSE; } /* reset the stringpool for every record in order to avoid garbage collection */ stringpool.free = stringpool.base; if (!(len = mu_bin_get((char **)&ptr)) || mupip_error_occurred) break; else if (len == sizeof(coll_hdr)) { extr_collhdr = *((coll_hdr *)(ptr)); assert(hdr_lvl > '2'); new_gvn = TRUE; /* next record will contain a new gvn */ rec_count--; /* Decrement as this record does not count as a record for loading purposes */ continue; } global_key_count = 1; rp = (rec_hdr*)ptr; btop = ptr + len; cp1 = (unsigned char*)(rp + 1); v.str.addr = (char*)cp1; while (*cp1++) ; v.str.len =INTCAST((char*)cp1 - v.str.addr - 1); if (hdr_lvl <= '2' || new_gvn) { bin_call_db(BIN_BIND, (INTPTR_T)gd_header, (INTPTR_T)&v.str); max_key = gv_cur_region->max_key_size; db_collhdr.act = gv_target->act; db_collhdr.ver = gv_target->ver; db_collhdr.nct = gv_target->nct; } GET_SHORT(rec_len, &rp->rsiz); if (rp->cmpc != 0 || v.str.len > rec_len || mupip_error_occurred) { bin_call_db(ERR_COR, rec_count, global_key_count); mu_gvis(); util_out_print(0, TRUE); continue; } if (new_gvn) { if ((db_collhdr.act != extr_collhdr.act || db_collhdr.ver != extr_collhdr.ver || db_collhdr.nct != extr_collhdr.nct || gv_cur_region->std_null_coll != extr_std_null_coll)) { if (extr_collhdr.act) { if (extr_collseq = ready_collseq((int)extr_collhdr.act)) { if (!do_verify(extr_collseq, extr_collhdr.act, extr_collhdr.ver)) { gtm_putmsg(VARLSTCNT(8) ERR_COLLTYPVERSION, 2, extr_collhdr.act, extr_collhdr.ver, ERR_GVIS, 2, gv_altkey->end - 1, gv_altkey->base); mupip_exit(ERR_COLLTYPVERSION); } } else { gtm_putmsg(VARLSTCNT(7) ERR_COLLATIONUNDEF, 1, extr_collhdr.act, ERR_GVIS, 2, gv_altkey->end - 1, gv_altkey->base); mupip_exit(ERR_COLLATIONUNDEF); } } if (db_collhdr.act) { if (db_collseq = ready_collseq((int)db_collhdr.act)) { if (!do_verify(db_collseq, db_collhdr.act, db_collhdr.ver)) { gtm_putmsg(VARLSTCNT(8) ERR_COLLTYPVERSION, 2, db_collhdr.act, db_collhdr.ver, ERR_GVIS, 2, gv_altkey->end - 1, gv_altkey->base); mupip_exit(ERR_COLLTYPVERSION); } } else { gtm_putmsg(VARLSTCNT(7) ERR_COLLATIONUNDEF, 1, db_collhdr.act, ERR_GVIS, 2, gv_altkey->end - 1, gv_altkey->base); mupip_exit(ERR_COLLATIONUNDEF); } } need_xlation = TRUE; } else need_xlation = FALSE; } new_gvn = FALSE; for (; rp < (rec_hdr*)btop; rp = (rec_hdr*)((unsigned char *)rp + rec_len)) { GET_SHORT(rec_len, &rp->rsiz); if (rec_len + (unsigned char *)rp > btop) { bin_call_db(ERR_COR, rec_count, global_key_count); mu_gvis(); util_out_print(0, TRUE); break; } cp1 = (unsigned char*)(rp + 1); cp2 = gv_currkey->base + rp->cmpc; current = 1; for (;;) { last = current; current = *cp2++ = *cp1++; if (0 == last && 0 == current) break; if (cp1 > (unsigned char *) rp + rec_len || cp2 > (unsigned char *) gv_currkey + gv_currkey->top) { bin_call_db(ERR_COR, rec_count, global_key_count); mu_gvis(); util_out_print(0, TRUE); break; } } if (mupip_error_occurred) break; gv_currkey->end = cp2 - gv_currkey->base - 1; if (need_xlation) { assert(hdr_lvl >= '3'); assert(extr_collhdr.act || db_collhdr.act || extr_collhdr.nct || db_collhdr.nct || extr_std_null_coll != gv_cur_region->std_null_coll); /* gv_currkey would have been modified/translated in the earlier put */ memcpy(gv_currkey->base, cmpc_str, next_cmpc); next_rp = (rec_hdr *)((unsigned char*)rp + rec_len); if ((unsigned char*)next_rp < btop) { next_cmpc = next_rp->cmpc; assert(next_cmpc <= gv_currkey->end); memcpy(cmpc_str, gv_currkey->base, next_cmpc); } else next_cmpc = 0; /* length of the key might change (due to nct variation), * so get a copy of the original key from the extract */ memcpy(dup_key_str, gv_currkey->base, gv_currkey->end + 1); gvkey_char_ptr = dup_key_str; while (*gvkey_char_ptr++) ; gv_currkey->prev = 0; gv_currkey->end = gvkey_char_ptr - dup_key_str; tmp_gvkey->top = gv_keysize; while (*gvkey_char_ptr) { /* get next subscript (in GT.M internal subsc format) */ subsc_len = 0; tmp_ptr = src_buff; while (*gvkey_char_ptr) *tmp_ptr++ = *gvkey_char_ptr++; subsc_len = tmp_ptr - src_buff; src_buff[subsc_len] = '\0'; if (extr_collseq) { /* undo the extract time collation */ transform = TRUE; save_gv_target_collseq = gv_target->collseq; gv_target->collseq = extr_collseq; } else transform = FALSE; /* convert the subscript to string format */ end_buff = gvsub2str(src_buff, dest_buff, FALSE); /* transform the string to the current subsc format */ transform = TRUE; tmp_mval.mvtype = MV_STR; tmp_mval.str.addr = (char *)dest_buff; tmp_mval.str.len = INTCAST(end_buff - dest_buff); tmp_gvkey->prev = 0; tmp_gvkey->end = 0; if (extr_collseq) gv_target->collseq = save_gv_target_collseq; mval2subsc(&tmp_mval, tmp_gvkey); /* we now have the correctly transformed subscript */ tmp_key_ptr = gv_currkey->base + gv_currkey->end; memcpy(tmp_key_ptr, tmp_gvkey->base, tmp_gvkey->end + 1); gv_currkey->prev = gv_currkey->end; gv_currkey->end += tmp_gvkey->end; gvkey_char_ptr++; } if ( gv_cur_region->std_null_coll != extr_std_null_coll && gv_currkey->prev) { if (extr_std_null_coll == 0) { GTM2STDNULLCOLL(gv_currkey->base, gv_currkey->end); } else { STD2GTMNULLCOLL(gv_currkey->base, gv_currkey->end); } } } if (gv_currkey->end >= max_key) { bin_call_db(ERR_COR, rec_count, global_key_count); mu_gvis(); util_out_print(0, TRUE); continue; } if (max_subsc_len < (gv_currkey->end + 1)) max_subsc_len = gv_currkey->end + 1; v.str.addr = (char*)cp1; v.str.len =INTCAST(rec_len - (cp1 - (unsigned char *)rp) ); if (max_data_len < v.str.len) max_data_len = v.str.len; bin_call_db(BIN_PUT, (INTPTR_T)&v, 0); if (mupip_error_occurred) { if (!mupip_DB_full) { bin_call_db(ERR_COR, rec_count, global_key_count); util_out_print(0, TRUE); } break; } key_count++; global_key_count++; } } free(tmp_gvkey); mu_load_close(); util_out_print("LOAD TOTAL!_!_Key Cnt: !UL Max Subsc Len: !UL Max Data Len: !UL", TRUE, key_count, max_subsc_len, max_data_len); util_out_print("Last LOAD record number: !UL\n", TRUE, key_count ? (rec_count - 1) : 0); if (mu_ctrly_occurred) { gtm_putmsg(VARLSTCNT(1) ERR_LOADCTRLY); mupip_exit(ERR_MUNOFINISH); } }
// process an incoming respawn info packet void multi_respawn_process_packet(ubyte *data, header *hinfo) { ubyte code,cur_link_status; char cur_primary_bank,cur_secondary_bank; ushort net_sig,ship_ets; short player_id; int player_index; vector v; char parse_name[1024] = ""; int offset = HEADER_LENGTH; // determine who send the packet player_index = find_player_id(hinfo->id); if(player_index == -1){ nprintf(("Network","Couldn't find player for processing respawn packet!\n")); } // get the opcode GET_DATA(code); // do something based upon the opcode switch((int)code){ case AI_RESPAWN_NOTICE: p_object *pobjp; GET_USHORT( net_sig ); pobjp = mission_parse_get_arrival_ship( net_sig ); Assert( pobjp != NULL ); multi_respawn_ai( pobjp ); break; case RESPAWN_BROADCAST: // get the respawn data GET_USHORT(net_sig); get_vector_data( data, &offset, v ); GET_SHORT(player_id); GET_DATA(cur_primary_bank); GET_DATA(cur_secondary_bank); GET_DATA(cur_link_status); GET_USHORT(ship_ets); GET_STRING(parse_name); player_index = find_player_id(player_id); if(player_index == -1){ nprintf(("Network","Couldn't find player to respawn!\n")); break; } // create the ship and assign its position, net_signature, and class // respawn the player multi_respawn_player(&Net_players[player_index], cur_primary_bank, cur_secondary_bank, cur_link_status, ship_ets, net_sig, parse_name, &v); // if this is for me, I should jump back into gameplay if(&Net_players[player_index] == Net_player){ extern int Player_multi_died_check; Player_multi_died_check = -1; gameseq_post_event(GS_EVENT_ENTER_GAME); } break; case RESPAWN_REQUEST: // determine whether he wants to respawn as an observer or not GET_DATA(code); nprintf(("Network","Received respawn request\n")); if(player_index == -1){ nprintf(("Network","Received respawn request from unknown player!\n")); break; } // make sure he's not making an invalid request if((code == 0) && !(Net_players[player_index].flags & NETINFO_FLAG_RESPAWNING)){ nprintf(("Network","Received respawn request from player who shouldn't be respawning!\n")); Int3(); break; } else if((code == 1) && !(Net_players[player_index].flags & NETINFO_FLAG_LIMBO)){ nprintf(("Network","Received respawn observer request from a player who shouldn't be respawning as an observer!\n")); Int3(); break; } // otherwise perform the operation // respawn the guy as an observer if(code){ multi_respawn_make_observer(&Net_players[player_index]); } // respawn him as normal else { // create his new ship, and change him from respawning to respawned Assert(Net_players[player_index].p_info.p_objp != NULL); if(Net_players[player_index].p_info.p_objp != NULL){ multi_respawn_player(&Net_players[player_index], Net_players[player_index].s_info.cur_primary_bank, Net_players[player_index].s_info.cur_secondary_bank,Net_players[player_index].s_info.cur_link_status, Net_players[player_index].s_info.ship_ets, 0, Net_players[player_index].p_info.p_objp->name); } } break; } PACKET_SET_SIZE(); }