Beispiel #1
0
//-------------------------------------------------------------------------------------------------
Message *Message::factory(const F8MetaCntx& ctx, const f8String& from)
{
	Message *msg(0);
	f8String len, mtype;
	if (extract_header(from, len, mtype))
	{
		const unsigned mlen(fast_atoi<unsigned>(len.c_str()));
		const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype));
		if (!bme)
			throw InvalidMessage(mtype);
		msg = bme->_create();
#if defined PERMIT_CUSTOM_FIELDS
		if (ctx._ube)
			ctx._ube->post_msg_ctor(msg);
#endif
#if defined CODECTIMING
		ostringstream gerr;
		gerr << "decode(" << mtype << "):";
		IntervalTimer itm;
#endif
		msg->decode(from);
#if defined CODECTIMING
		gerr << itm.Calculate();
		GlobalLogger::log(gerr.str());
#endif

		Fields::const_iterator fitr(msg->_header->_fields.find(Common_BodyLength));
		static_cast<body_length *>(fitr->second)->set(mlen);
		fitr = msg->_header->_fields.find(Common_MsgType);
		static_cast<msg_type *>(fitr->second)->set(mtype);
#if defined POPULATE_METADATA
		msg->check_set_rlm(fitr->second);
#endif

		f8String chksum;
		if (extract_trailer(from, chksum))
		{
			Fields::const_iterator fitr(msg->_trailer->_fields.find(Common_CheckSum));
			static_cast<check_sum *>(fitr->second)->set(chksum);
			const unsigned chkval(fast_atoi<unsigned>(chksum.c_str())), // chksum value
				mchkval(calc_chksum(from, 0)); // chksum pos
			if (chkval != mchkval)
				throw BadCheckSum(mchkval);
		}
	}
	else
	{
		//cerr << "Message::factory throwing" << endl;
		throw InvalidMessage(from);
	}

	return msg;
}
Beispiel #2
0
//-------------------------------------------------------------------------------------------------
Message *Message::factory(const F8MetaCntx& ctx, const f8String& from)
{
	Message *msg(0);
	f8String len, mtype;
	if (extract_header(from, len, mtype))
	{
		const unsigned mlen(fast_atoi<unsigned>(len.c_str()));
		const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype));
		if (!bme)
			throw InvalidMessage(mtype);
		msg = bme->_create();
#if defined PERMIT_CUSTOM_FIELDS
		if (ctx._ube)
			ctx._ube->post_msg_ctor(msg);
#endif
#if defined CODECTIMING
		ostringstream gerr;
		gerr << "decode(" << mtype << "):";
		IntervalTimer itm;
#endif
		msg->decode(from);
#if defined CODECTIMING
		gerr << itm.Calculate();
		GlobalLogger::log(gerr.str());
#endif

		static_cast<body_length *>(msg->_header->_fields.find(Common_BodyLength)->second)->set(mlen);
		Fields::const_iterator fitr(msg->_header->_fields.find(Common_MsgType));
		static_cast<msg_type *>(fitr->second)->set(mtype);
#if defined POPULATE_METADATA
		msg->check_set_rlm(fitr->second);
#endif

		const char *pp(from.data() + from.size() - 7);
		if (*pp != '1' || *(pp + 1) != '0') // 10=XXX^A
			throw InvalidMessage(from);
		if (!ctx.has_flag(F8MetaCntx::noverifychksum)) // permit chksum calculation to be skipped
		{
			const f8String chksum(pp + 3, 3);
			static_cast<check_sum *>(msg->_trailer->_fields.find(Common_CheckSum)->second)->set(chksum);
			const unsigned chkval(fast_atoi<unsigned>(chksum.c_str())), mchkval(calc_chksum(from, 0, from.size() - 7));
			if (chkval != mchkval)
				throw BadCheckSum(mchkval);
		}
	}
	else
	{
		//cerr << "Message::factory throwing" << endl;
		throw InvalidMessage(from);
	}

	return msg;
}
Beispiel #3
0
//-------------------------------------------------------------------------------------------------
Message *Message::factory(const F8MetaCntx& ctx, const f8String& from)
{
	Message *msg(0);
	char mtype[MAX_MSGTYPE_FIELD_LEN] = {}, len[MAX_MSGTYPE_FIELD_LEN] = {};
	if (extract_header(from, len, mtype))
	{
		const unsigned mlen(fast_atoi<unsigned>(len));
		const BaseMsgEntry *bme(ctx._bme.find_ptr(mtype));
		if (!bme)
			throw InvalidMessage(mtype);
		msg = bme->_create();
#if defined CODECTIMING
		IntervalTimer itm;
#endif
		msg->decode(from);
#if defined CODECTIMING
		_decode_timings._cpu_used += itm.Calculate().AsDouble();
		++_decode_timings._msg_count;
#endif

		static_cast<body_length *>(msg->_header->_fields.find(Common_BodyLength)->second)->set(mlen);
		Fields::const_iterator fitr(msg->_header->_fields.find(Common_MsgType));
		static_cast<msg_type *>(fitr->second)->set(mtype);
#if defined POPULATE_METADATA
		msg->check_set_rlm(fitr->second);
#endif

		const char *pp(from.data() + from.size() - 7);
		if (*pp != '1' || *(pp + 1) != '0') // 10=XXX^A
			throw InvalidMessage(from);
		if (!ctx.has_flag(F8MetaCntx::noverifychksum)) // permit chksum calculation to be skipped
		{
			const f8String chksum(pp + 3, 3);
			static_cast<check_sum *>(msg->_trailer->_fields.find(Common_CheckSum)->second)->set(chksum);
			const unsigned chkval(fast_atoi<unsigned>(chksum.c_str())), mchkval(calc_chksum(from, 0, from.size() - 7));
			if (chkval != mchkval)
				throw BadCheckSum(mchkval);
		}
	}
	else
	{
		//cerr << "Message::factory throwing" << endl;
		throw InvalidMessage(from);
	}

	return msg;
}