Ejemplo n.º 1
0
bool gtcmtr_initreg(void)
{
	cm_region_head	*region;
	cm_region_list	*list_entry;
	unsigned char	*reply;
	unsigned short temp_short;

	assert(*curr_entry->clb_ptr->mbf == CMMS_S_INITREG);
	region = gtcmd_ini_reg(curr_entry);
	gtcm_add_region(curr_entry,region);

	if (region->reg->max_rec_size + CM_BUFFER_OVERHEAD > curr_entry->clb_ptr->mbl)
	{
		free(curr_entry->clb_ptr->mbf);
		curr_entry->clb_ptr->mbf = (unsigned char *)malloc(region->reg->max_rec_size + CM_BUFFER_OVERHEAD);
		curr_entry->clb_ptr->mbl = region->reg->max_rec_size + CM_BUFFER_OVERHEAD;
	}
	reply = curr_entry->clb_ptr->mbf;
	*reply++ = CMMS_T_REGNUM;
	*reply++ = curr_entry->current_region->regnum;
	*reply++ = region->reg->null_subs;
	temp_short = (unsigned short)region->reg->max_rec_size;
	assert((int4)temp_short == region->reg->max_rec_size); /* ushort <- int4 assignment lossy? */
	PUT_USHORT(reply, temp_short);
	reply += sizeof(unsigned short);
	temp_short = (unsigned short)region->reg->max_key_size;
	assert((int4)temp_short == region->reg->max_key_size); /* ushort <- int4 assignment lossy? */
	PUT_USHORT(reply, temp_short);
	reply += sizeof(unsigned short);
	curr_entry->clb_ptr->cbl = reply - curr_entry->clb_ptr->mbf;
	return TRUE;
}
Ejemplo n.º 2
0
long SDMCode::Marshal(char* buf)
{
    int cur;
    cur = HEADER_SIZE;
    PUT_USHORT(&buf[cur], seq_num);
    cur += sizeof(seq_num);
    PUT_USHORT(&buf[cur], num_segments);
    cur += sizeof(num_segments);
    //
    // Copy the filename
    size_t uiCurLength = strlen(filename);
    strcpy(buf + cur, filename);
    cur += (int)uiCurLength + 1;
    //
    // Copy the code section
    memcpy (&buf[cur], &code, code_length);
    cur += code_length;

    c_sum = checksum(code, code_length);
    PUT_INT (&buf[cur], c_sum);
    cur += sizeof (c_sum);
    msg_length = cur - HEADER_SIZE;
    MarshalHeader(buf);
    return cur;
}
Ejemplo n.º 3
0
bool gtcmtr_data(void)
{
	cm_region_list *reg_ref;
	unsigned char *ptr,regnum;
	unsigned short top,len;
	mval	v;
	int x;

	ptr = curr_entry->clb_ptr->mbf;
	assert(*ptr == CMMS_Q_DATA);
	ptr++;
	GET_USHORT(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);
	x = 0;
 	if (gv_target->root)
		x = gvcst_data();
	v = *fndata_table[x / 10][x & 1];

	ptr = curr_entry->clb_ptr->mbf;
	*ptr++ = CMMS_R_DATA;
	len = sizeof(unsigned char);
	PUT_USHORT(ptr, len);
	ptr += sizeof(unsigned short);
	*ptr++ = MV_FORCE_INTD(&v);
	curr_entry->clb_ptr->cbl = ptr - curr_entry->clb_ptr->mbf;
	return TRUE;
}
Ejemplo n.º 4
0
/*
	Marshal the header without reassigning a new timestamp.
*/
long SDMmessage::MarshalHeaderOldTimeStamp(char* buf)
{
	buf[0] = MsgName;
	PUT_LONG(&buf[1],sec);
	PUT_LONG(&buf[5],subsec);
	PUT_USHORT(&buf[9],msg_length);
	return HEADER_SIZE;
}
Ejemplo n.º 5
0
long SDMmessage::MarshalHeader(char* buf)
{
#ifdef __VXWORKS__
	struct timespec time;
	clock_gettime(CLOCK_REALTIME, &time);
	sec = time.tv_sec;
	subsec = time.tv_nsec/1000;
#else
	struct timeval time;
	gettimeofday(&time,NULL);
	sec = time.tv_sec;
	subsec = time.tv_usec;
#endif
	buf[0] = MsgName;
	PUT_LONG(&buf[1],sec);
	PUT_LONG(&buf[5],subsec);
	PUT_USHORT(&buf[9],msg_length);
	return HEADER_SIZE;
}
Ejemplo n.º 6
0
/*
 * -----------------------------------------------------
 * Convert a string subscript to MUMPS string
 * Save result in a buffer pointed by targ.
 *
 * Entry:
 *	sub	- input string in subscript format
 *	targ	- output string buffer
 *	xlat_flg- translate flag.
 *		  If true convert string to MUMPS format
 * Return:
 *	(pointer to the last char.
 *	converted in the targ string) + 1.
 * -----------------------------------------------------
 */
unsigned char *gvsub2str(unsigned char *sub, unsigned char *targ, bool xlat_flg)
{
	unsigned char	buf1[MAX_KEY_SZ + 1], ch, *ptr, trail_ch;
	unsigned short	*tbl_ptr;
	int		expon, in_length, length, tmp;
	mstr		mstr_ch, mstr_targ;

	ch = *sub++;

	if (STR_SUB_PREFIX == ch || (SUBSCRIPT_STDCOL_NULL == ch && KEY_DELIMITER == *sub))
	{	/* If this is a string */
		if (xlat_flg)
			return gvstrsub(sub, targ);
		else
		{
			in_length = 0;
			ptr = targ;
			while ((ch = *sub++))
			{	/* Copy string to targ, xlating each char */
				in_length++;
				if (STR_SUB_ESCAPE == ch)
				/* if this is an escape, demote next char */
					ch = (*sub++ - 1);
				*targ++ = ch;
			}

			if (transform && gv_target && gv_target->collseq)
			{
				mstr_ch.len = in_length;
				mstr_ch.addr = (char *)ptr;
				mstr_targ.len = sizeof(buf1);
				mstr_targ.addr = (char *)buf1;
				do_xform(gv_target->collseq, XBACK, &mstr_ch, &mstr_targ, &length);
				memcpy(ptr, mstr_targ.addr, length); /* mstr_targ.addr is used just in case it is
								        reallocated by the XBACK routine */
				targ = ptr + length;
			}
		}
	} else
	{	/* Number */
		if (SUBSCRIPT_ZERO == ch)
			*targ++ = '0';
		else
		{
			tbl_ptr = (unsigned short *)&dpos[0] - 1;
			trail_ch = KEY_DELIMITER;
			if ((signed char)ch >= 0)
			{	/* Bit 7 of the exponent is set for positive numbers; must be negative */
				trail_ch = NEG_MNTSSA_END;
				tbl_ptr = (unsigned short *)dneg;
				ch = ~ch;
				*targ++ = '-';
			}
			ch -= (SUBSCRIPT_BIAS - 1);	/* Unbias the exponent */
			expon = ch;
			if ((signed char)ch <= 0)
			{	/* number is a fraction */
				ch = -(signed char)ch;
					/* Save decimal point */
				*targ++ = '.';
					/* generate leading 0's */
				do *targ++ = '0';
				while ((signed char)ch-- > 0)
					;
					/* make expon. really large to avoid
					 * generating extra dots */
				expon = LARGE_EXP;
			}
			while ((ch = *sub++) && ch != trail_ch)
			{	/* Convert digits loop */
					/* adjust dcm. point */
				if ((expon -= 2) <= 0)
				{
					if (0 != expon)
					{
						*targ++ = '.';
						expon = LARGE_EXP;
						PUT_USHORT(targ, tbl_ptr[ch]);
						targ += sizeof(short);
					} else
					{	/* Insert dot between digits */
						PUT_USHORT(targ, tbl_ptr[ch]);
						targ += sizeof(short);
						*targ = *(targ - 1);
						*(targ - 1) = '.';
						targ++;
						expon = LARGE_EXP;
					}
				} else
				{
					PUT_USHORT(targ, tbl_ptr[ch]);
					targ += sizeof(short);
				}
			}
			if (expon > (LARGE_EXP - 100))
			{
				if ('0' == *(targ - 1))
					targ--;
				if ('.' == *(targ - 1))
					targ--;
			} else
				while (--expon > 0)
					*targ++ = '0';
		}
	}
	return (targ);
}
Ejemplo n.º 7
0
bool	gtcmtr_increment(void)
{
	cm_region_list	*reg_ref;
	mval		incr_delta, post_incr;
	unsigned char	buff[MAX_ZWR_KEY_SZ], *end;
	unsigned char	*ptr, regnum;
	short		n;
	unsigned short	top, len, temp_short;
	static readonly	gds_file_id file;

	error_def(ERR_KEY2BIG);
	error_def(ERR_GVIS);
	error_def(ERR_DBPRIVERR);

	ptr = curr_entry->clb_ptr->mbf;
	assert(*ptr == CMMS_Q_INCREMENT);
	ptr++;
	GET_USHORT(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_incr'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;
	}
	GET_USHORT(len, ptr);
	ptr += SIZEOF(unsigned short);
	incr_delta.mvtype = MV_STR;
	incr_delta.str.len = len;
	incr_delta.str.addr = (char *)ptr;
	if ((n = gv_currkey->end + 1) > gv_cur_region->max_key_size)
	{
		if ((end = format_targ_key(&buff[0], MAX_ZWR_KEY_SZ, gv_currkey, TRUE)) == 0)
			end = &buff[MAX_ZWR_KEY_SZ - 1];
		rts_error(VARLSTCNT(11) ERR_KEY2BIG, 4, n, (int4)gv_cur_region->max_key_size,
			REG_LEN_STR(gv_cur_region), 0, ERR_GVIS, 2, end - buff, buff);
	}
	MV_FORCE_NUMD(&incr_delta);
	gvcst_incr(&incr_delta, &post_incr);
	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;
	if (MV_DEFINED(&post_incr))
	{
		temp_short = (unsigned short)post_incr.str.len;
		assert((int4)temp_short == post_incr.str.len); /* ushort <- int4 assignment lossy? */
		if (curr_entry->clb_ptr->mbl < 1 +			/* msg header */
					       SIZEOF(temp_short) +	/* size of length of $INCR return value */
					       temp_short) 		/* length of $INCR return value */
		{	/* resize buffer */
			cmi_realloc_mbf(curr_entry->clb_ptr, 1 + SIZEOF(temp_short) + temp_short);
			ptr = curr_entry->clb_ptr->mbf;
		}
		*ptr++ = CMMS_R_INCREMENT;
		PUT_USHORT(ptr, temp_short);
		ptr += SIZEOF(unsigned short);
		memcpy(ptr, post_incr.str.addr, temp_short);
		ptr += temp_short;
	} else