Exemple #1
0
static int fast_message_init(xmlNodePtr node, struct fast_message *msg)
{
	struct fast_field *field;
	int nr_fields;
	xmlChar *prop;
	int pmap_bit;
	int ret = 1;

	if (xmlStrcmp(node->name, (const xmlChar *)"template"))
		goto exit;

	prop = xmlGetProp(node, (const xmlChar *)"id");
	if (prop != NULL)
		msg->tid = strtol((char *)prop, NULL, 10);
	else
		msg->tid = 0;
	xmlFree(prop);

	prop = xmlGetProp(node, (const xmlChar *)"reset");
	if (prop != NULL && !xmlStrcmp(prop, (const xmlChar *)"T"))
		fast_msg_add_flags(msg, FAST_MSG_FLAGS_RESET);
	xmlFree(prop);

	nr_fields = xmlChildElementCount(node);
	msg->fields = calloc(nr_fields, sizeof(struct fast_field));
	if (!msg->fields)
		goto exit;

	msg->nr_fields = 0;
	pmap_bit = 1;

	node = node->xmlChildrenNode;
	while (node != NULL) {
		if (node->type != XML_ELEMENT_NODE) {
			node = node->next;
			continue;
		}

		field = msg->fields + msg->nr_fields;

		if (fast_field_init(node, field))
			goto exit;

		if (pmap_required(field))
			field->pmap_bit = pmap_bit++;

		msg->nr_fields++;
		node = node->next;
	}

	ret = 0;

exit:
	return ret;
}
static int fast_decimal_init_individ(xmlNodePtr node, struct fast_field *field)
{
	struct fast_decimal *decimal;
	int ret = -1;

	decimal = &field->decimal_value;

	decimal->fields = calloc(2, sizeof(struct fast_field));
	if (!decimal->fields)
		goto exit;

	node = node->xmlChildrenNode;

	while (node) {
		if (node->type != XML_ELEMENT_NODE) {
			node = node->next;
			continue;
		}

		if (!xmlStrcmp(node->name, (const xmlChar *)"exponent"))
			ret = fast_field_init(node, &decimal->fields[0]);
		else if (!xmlStrcmp(node->name, (const xmlChar *)"mantissa"))
			ret = fast_field_init(node, &decimal->fields[1]);
		else
			ret = -1;

		if (ret)
			goto exit;

		node = node->next;
	}

	field_add_flags(field, FAST_FIELD_FLAGS_DECIMAL_INDIVID);
	decimal->fields[0].presence = field->presence;

exit:
	return ret;
}
Exemple #3
0
static int fast_sequence_init(xmlNodePtr node, struct fast_field *field)
{
	struct fast_sequence *seq;
	struct fast_message *msg;
	struct fast_field *orig;
	xmlNodePtr tmp;
	int i, ret = 1;
	int nr_fields;
	int pmap_bit;

	field->ptr_value = calloc(1, sizeof(struct fast_sequence));
	if (!field->ptr_value)
		goto exit;

	seq = field->ptr_value;

	nr_fields = xmlChildElementCount(node);

	node = node->xmlChildrenNode;
	while (node && node->type != XML_ELEMENT_NODE)
		node = node->next;

	if (xmlStrcmp(node->name, (const xmlChar *)"length"))
		goto exit;

	if (fast_field_init(node, &seq->length))
		goto exit;

	if (!field_is_mandatory(field))
		seq->length.presence = FAST_PRESENCE_OPTIONAL;

	node = node->next;
	orig = field;

	for (i = 0; i < FAST_SEQUENCE_ELEMENTS; i++) {
		msg = seq->elements + i;
		tmp = node;

		msg->fields = calloc(nr_fields, sizeof(struct fast_field));
		if (!msg->fields)
			goto exit;

		msg->nr_fields = 0;
		pmap_bit = 0;

		while (tmp != NULL) {
			if (tmp->type != XML_ELEMENT_NODE) {
				tmp = tmp->next;
				continue;
			}

			field = msg->fields + msg->nr_fields;

			if (fast_field_init(tmp, field))
				goto exit;

			if (pmap_required(field)) {
				field_add_flags(orig, FAST_FIELD_FLAGS_PMAPREQ);
				field->pmap_bit = pmap_bit++;
			}

			msg->nr_fields++;
			tmp = tmp->next;
		}
	}

	ret = 0;

exit:
	return ret;
}
static int fast_message_init(xmlNodePtr node, struct fast_message *msg)
{
	struct fast_field *field;
	int nr_fields;
	xmlChar *prop;
	int ret = 1;

	if (xmlStrcmp(node->name, (const xmlChar *)"template"))
		goto exit;

	prop = xmlGetProp(node, (const xmlChar *)"id");
	if (prop != NULL)
		msg->tid = strtol((char *)prop, NULL, 10);
	else
		msg->tid = 0;
	xmlFree(prop);

	prop = xmlGetProp(node, (const xmlChar *)"name");
	if (prop != NULL)
		strncpy(msg->name, (const char *)prop, sizeof(msg->name));
	else
		strncpy(msg->name, (const char *)"", sizeof(msg->name));
	xmlFree(prop);

	prop = xmlGetProp(node, (const xmlChar *)"reset");
	if (prop != NULL && !xmlStrcmp(prop, (const xmlChar *)"T"))
		fast_msg_add_flags(msg, FAST_MSG_FLAGS_RESET);
	xmlFree(prop);

	nr_fields = xmlChildElementCount(node);
	msg->fields = calloc(nr_fields, sizeof(struct fast_field));
	if (!msg->fields)
		goto exit;

	msg->nr_fields = 0;

	msg->ghtab = g_hash_table_new(g_str_hash, g_str_equal);
	if (!msg->ghtab)
		goto exit;

	node = node->xmlChildrenNode;
	while (node != NULL) {
		if (node->type != XML_ELEMENT_NODE) {
			node = node->next;
			continue;
		}

		field = msg->fields + msg->nr_fields;

		if (fast_field_init(node, field))
			goto exit;

		if (strlen(field->name))
			g_hash_table_insert(msg->ghtab, field->name, field);

		msg->nr_fields++;
		node = node->next;
	}

	ret = 0;

exit:
	return ret;
}