Exemple #1
0
/*
 * Decode the chunk of XML text encoding REAL.
 */
asn_dec_rval_t
NativeReal_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
	asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
		const void *buf_ptr, size_t size) {
	asn_dec_rval_t rval;
	REAL_t *st = 0;
	REAL_t **stp = &st;
	double *Dbl = (double *)*sptr;

	if(!Dbl) {
		*sptr = CALLOC(1, sizeof(double));
		Dbl = (double *)*sptr;
		if(!Dbl) {
			rval.code = RC_FAIL;
			rval.consumed = 0;
			return rval;
		}
	}

	rval = REAL_decode_xer(opt_codec_ctx, td, (void **)stp, opt_mname,
		buf_ptr, size);
	if(rval.code == RC_OK) {
		if(asn_REAL2double(st, Dbl)) {
			rval.code = RC_FAIL;
			rval.consumed = 0;
		}
	} else {
		rval.consumed = 0;
	}
	ASN_STRUCT_FREE(asn_DEF_REAL, st);
	return rval;
}
Exemple #2
0
static void
_dump_table_json(struct Table *table)
{
	gdouble d = 0;
	gint64 i64 = 0, pos = 0;
	int32_t i, j;

	g_print(" {\n \"table\" : \"%.*s\",\n", table->name.size, table->name.buf);
	if (table->status) {
		asn_INTEGER_to_int64(table->status, &i64);
		g_print(" \"status\" : %"G_GINT64_FORMAT",\n", i64);
	}
	g_print("  \"rows\" : [\n");

	if (table->rows.list.count > 0) {

		for (i=0; i<table->rows.list.count ;i++) {
			struct Row *row = table->rows.list.array[i];
			if (!row->fields || row->fields->list.count < 0)
				continue;

			g_print("   {\n");

			for (j=0; j<row->fields->list.count ;j++) {
				struct RowField *field = row->fields->list.array[j];

				asn_INTEGER_to_int64(&(field->pos), &pos);
				g_print("    \"%"G_GINT64_FORMAT"\" : ", pos);

				switch (field->value.present) {
					case RowFieldValue_PR_NOTHING:
					case RowFieldValue_PR_n:
						g_print("null");
						break;
					case RowFieldValue_PR_i:
						asn_INTEGER_to_int64(&(field->value.choice.i), &i64);
						g_print("%"G_GINT64_FORMAT, i64);
						break;
					case RowFieldValue_PR_f:
						asn_REAL2double(&(field->value.choice.f), &d);
						g_print("%f", d);
						break;
					case RowFieldValue_PR_b:
						json_dump_string(field->value.choice.b.buf, field->value.choice.b.size);
						break;
					case RowFieldValue_PR_s:
						json_dump_string(field->value.choice.s.buf, field->value.choice.s.size);
						break;
				}
				g_print(",\n");
			}
			g_print("   },\n");
		}
	}

	g_print("  ]\n },\n");
}
Exemple #3
0
/*
 * Decode REAL type using APER.
 */
asn_dec_rval_t
NativeReal_decode_aper(asn_codec_ctx_t *opt_codec_ctx,
	asn_TYPE_descriptor_t *td, asn_per_constraints_t *constraints,
		void **dbl_ptr, asn_per_data_t *pd) {
	double *Dbl = (double *)*dbl_ptr;
	asn_dec_rval_t rval;
	REAL_t tmp;
	void *ptmp = &tmp;
	int ret;

	(void)constraints;

	/*
	 * If the structure is not there, allocate it.
	 */
	if(Dbl == NULL) {
		*dbl_ptr = CALLOC(1, sizeof(*Dbl));
		Dbl = (double *)*dbl_ptr;
		if(Dbl == NULL) {
			ASN__DECODE_FAILED;
		}
	}

	memset(&tmp, 0, sizeof(tmp));
	rval = OCTET_STRING_decode_aper(opt_codec_ctx, td, NULL,
			&ptmp, pd);
	if(rval.code != RC_OK) {
		ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);
		return rval;
	}

	ret = asn_REAL2double(&tmp, Dbl);
	ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);
	if(ret) {
		ASN__DECODE_FAILED;
	}

	return rval;
}
Exemple #4
0
/*
 * Decode REAL type.
 */
asn_dec_rval_t
NativeReal_decode_ber(asn_codec_ctx_t *opt_codec_ctx,
	asn_TYPE_descriptor_t *td,
	void **dbl_ptr, const void *buf_ptr, size_t size, int tag_mode) {
	double *Dbl = (double *)*dbl_ptr;
	asn_dec_rval_t rval;
	ber_tlv_len_t length;

	/*
	 * If the structure is not there, allocate it.
	 */
	if(Dbl == NULL) {
		*dbl_ptr = CALLOC(1, sizeof(*Dbl));
		Dbl = (double *)*dbl_ptr;
		if(Dbl == NULL) {
			rval.code = RC_FAIL;
			rval.consumed = 0;
			return rval;
		}
	}

	ASN_DEBUG("Decoding %s as REAL (tm=%d)",
		td->name, tag_mode);

	/*
	 * Check tags.
	 */
	rval = ber_check_tags(opt_codec_ctx, td, 0, buf_ptr, size,
			tag_mode, 0, &length, 0);
	if(rval.code != RC_OK)
		return rval;

	ASN_DEBUG("%s length is %d bytes", td->name, (int)length);

	/*
	 * Make sure we have this length.
	 */
	buf_ptr = ((const char *)buf_ptr) + rval.consumed;
	size -= rval.consumed;
	if(length > (ber_tlv_len_t)size) {
		rval.code = RC_WMORE;
		rval.consumed = 0;
		return rval;
	}

	/*
	 * ASN.1 encoded REAL: buf_ptr, length
	 * Fill the Dbl, at the same time checking for overflow.
	 * If overflow occured, return with RC_FAIL.
	 */
	{
		REAL_t tmp;
		union {
			const void *constbuf;
			void *nonconstbuf;
		} unconst_buf;
		double d;

		unconst_buf.constbuf = buf_ptr;
		tmp.buf = (uint8_t *)unconst_buf.nonconstbuf;
		tmp.size = length;

		if(asn_REAL2double(&tmp, &d)) {
			rval.code = RC_FAIL;
			rval.consumed = 0;
			return rval;
		}

		*Dbl = d;
	}

	rval.code = RC_OK;
	rval.consumed += length;

	ASN_DEBUG("Took %ld/%ld bytes to encode %s (%f)",
		(long)rval.consumed, (long)length, td->name, *Dbl);

	return rval;
}
/*
 * Decode REAL type.
 */
asn_dec_rval_t
NativeReal_decode_ber(Allocator * allocator, asn_codec_ctx_t *opt_codec_ctx,
	asn_TYPE_descriptor_t *td,
	void **dbl_ptr, const void *buf_ptr, size_t size, int tag_mode) {
	double *Dbl = (double *)*dbl_ptr;
	asn_dec_rval_t rval;
	ber_tlv_len_t length;

	/*
	 * If the structure is not there, allocate it.
	 */
	if(Dbl == NULL) {
		*dbl_ptr = CXX_ALLOC_WRAP CALLOC(1, sizeof(*Dbl));
		Dbl = (double *)*dbl_ptr;
		if(Dbl == NULL) {
			rval.code = RC_FAIL;
			rval.consumed = 0;
			return rval;
		}
	}

	ASN_DEBUG("Decoding %s as REAL (tm=%d)",
		td->name, tag_mode);

	/*
	 * Check tags.
	 */
	rval = ber_check_tags(opt_codec_ctx, td, 0, buf_ptr, size,
			tag_mode, 0, &length, 0);
	if(rval.code != RC_OK)
		return rval;

	ASN_DEBUG("%s length is %d bytes", td->name, (int)length);

	/*
	 * Make sure we have this length.
	 */
	buf_ptr = ((const char *)buf_ptr) + rval.consumed;
	size -= rval.consumed;
	if(length > (ber_tlv_len_t)size) {
		rval.code = RC_WMORE;
		rval.consumed = 0;
		return rval;
	}

	/*
	 * ASN.1 encoded REAL: buf_ptr, length
	 * Fill the Dbl, at the same time checking for overflow.
	 * If overflow occured, return with RC_FAIL.
	 */
	{
		REAL_t tmp;
		union {
			const void *constbuf;
			void *nonconstbuf;
		} unconst_buf;
		double d;

		unconst_buf.constbuf = buf_ptr;
		tmp.buf = (uint8_t *)unconst_buf.nonconstbuf;
		tmp.size = length;

		if(length < (ber_tlv_len_t)size) {
			int ret;
			uint8_t saved_byte = tmp.buf[tmp.size];
			tmp.buf[tmp.size] = '\0';
			ret = asn_REAL2double(allocator, &tmp, &d);
			tmp.buf[tmp.size] = saved_byte;
			if(ret) {
				rval.code = RC_FAIL;
				rval.consumed = 0;
				return rval;
			}
		} else if(length < 48 /* Enough for longish %f value. */) {
			tmp.buf = (uint8_t *)alloca(length + 1);
			tmp.size = length;
			memcpy(tmp.buf, buf_ptr, length);
			tmp.buf[tmp.size] = '\0';
			if(asn_REAL2double(allocator, &tmp, &d)) {
				rval.code = RC_FAIL;
				rval.consumed = 0;
				return rval;
			}
		} else {
			/* This should probably never happen: impractically long value */
			tmp.buf = (uint8_t *)CXX_ALLOC_WRAP CALLOC(1, length + 1);
			tmp.size = length;
			if(tmp.buf) memcpy(tmp.buf, buf_ptr, length);
			if(!tmp.buf || asn_REAL2double(allocator, &tmp, &d)) {
				CXX_ALLOC_WRAP FREEMEM(tmp.buf);
				rval.code = RC_FAIL;
				rval.consumed = 0;
				return rval;
			}
			CXX_ALLOC_WRAP FREEMEM(tmp.buf);
		}

		*Dbl = d;
	}

	rval.code = RC_OK;
	rval.consumed += length;

	ASN_DEBUG("Took %ld/%ld bytes to encode %s (%f)",
		(long)rval.consumed, (long)length, td->name, *Dbl);

	return rval;
}
Exemple #6
0
static void
_dump_table_text(struct Table *table)
{
	gdouble d = 0;
	gint64 i64 = 0, pos = 0;
	int32_t i, imax, j, jmax;

	g_print("# query = \"%.*s\"\n", table->name.size, table->name.buf);
	g_print("# rows = %u\n", table->rows.list.count);

	if (!table->status)
		g_print("# status = ?");
	else {
		asn_INTEGER_to_int64(table->status, &i64);
		g_print("# status = %"G_GINT64_FORMAT, i64);
	}

	if (!table->statusString)
		g_print("\n");
	else
		g_print(" (%.*s)\n", table->statusString->size, table->statusString->buf);

	if (table->rows.list.count > 0) {

		for (i=0,imax=table->rows.list.count; i<imax ;i++) {
			struct Row *row = table->rows.list.array[i];
			if (!row->fields || row->fields->list.count < 0)
				continue;

			for (j=0,jmax=row->fields->list.count; j<jmax ;j++) {
				struct RowField *field = row->fields->list.array[j];

				asn_INTEGER_to_int64(&(field->pos), &pos);
				if (j)
					g_print("|");
				
				switch (field->value.present) {
					case RowFieldValue_PR_NOTHING:
					case RowFieldValue_PR_n:
						g_print("(nil)");
						break;
					case RowFieldValue_PR_i:
						asn_INTEGER_to_int64(&(field->value.choice.i), &i64);
						g_print("%"G_GINT64_FORMAT, i64);
						break;
					case RowFieldValue_PR_f:
						asn_REAL2double(&(field->value.choice.f), &d);
						g_print("%f", d);
						break;
					case RowFieldValue_PR_b:
						g_print("%.*s", field->value.choice.b.size,
							field->value.choice.b.buf);
						break;
					case RowFieldValue_PR_s:
						g_print("%.*s", field->value.choice.s.size,
									field->value.choice.s.buf);
						break;
				}
			}

			g_print("\n");
		}
	}
}
Exemple #7
0
static void
_dump_table_xml(struct Table *table)
{
	gdouble d = 0;
	gint64 i64 = 0, pos = 0;
	int32_t i, j;

	g_print("<table>\n <name>%.*s</name>\n", table->name.size, table->name.buf);

	i64 = 0;
	if (table->status)
		asn_INTEGER_to_int64(table->status, &i64);

	if (table->statusString)
		g_print(" <status code=\"%"G_GINT64_FORMAT"\"/>\n", i64);
	else
		g_print(" <status code=\"%"G_GINT64_FORMAT"\">%.*s</status>\n", i64,
				table->statusString->size, table->statusString->buf);

	if (table->rows.list.count > 0) {

		g_print(" <rows>\n");

		for (i=0; i<table->rows.list.count ;i++) {
			struct Row *row = table->rows.list.array[i];
			if (!row->fields || row->fields->list.count < 0)
				continue;

			g_print("  <row>\n");

			for (j=0; j<row->fields->list.count ;j++) {
				struct RowField *field = row->fields->list.array[j];

				asn_INTEGER_to_int64(&(field->pos), &pos);
				g_print("   <f pos=%"G_GINT64_FORMAT">", pos);

				switch (field->value.present) {
					case RowFieldValue_PR_NOTHING:
					case RowFieldValue_PR_n:
						g_print("(nil)");
						break;
					case RowFieldValue_PR_i:
						asn_INTEGER_to_int64(&(field->value.choice.i), &i64);
						g_print("%"G_GINT64_FORMAT, i64);
						break;
					case RowFieldValue_PR_f:
						asn_REAL2double(&(field->value.choice.f), &d);
						g_print("%f", d);
						break;
					case RowFieldValue_PR_b:
						g_print("%.*s", field->value.choice.b.size,
								field->value.choice.b.buf);
						break;
					case RowFieldValue_PR_s:
						g_print("%.*s", field->value.choice.s.size,
								field->value.choice.s.buf);
						break;
				}

				g_print("</f>\n");
			}

			g_print("  </row>\n");
		}

		g_print(" </rows>\n");
	}

	g_print("<table>\n");
}