Пример #1
0
void Codec::setConfig(const Vocabulary& v, const xmlNodePtr config_ptr)
{
	PlatformPlugin::setConfig(v, config_ptr);
	
	// determine the type of event used by the codec
	std::string codec_event_str;
	if (! ConfigManager::getConfigOption(EVENT_ELEMENT_NAME, codec_event_str,
										 config_ptr))
		throw EmptyEventException(getId());

	// find the Term reference number for the event type
	Vocabulary::TermRef event_type = v.findTerm(codec_event_str);
	if (event_type == Vocabulary::UNDEFINED_TERM_REF)
		throw UnknownTermException(codec_event_str);
	m_event_term = v[event_type];

	// make sure that it is an object type Term
	if (m_event_term.term_type != Vocabulary::TYPE_OBJECT)
		throw NotAnObjectException(codec_event_str);
}
Пример #2
0
void FissionReactor::setConfig(const Vocabulary& v, const xmlNodePtr config_ptr)
{
	// first set config options for the Reactor base class
	ConfigWriteLock cfg_lock(*this);
	Reactor::setConfig(v, config_ptr);

	// get the input event type
	std::string config_str;
	if (! ConfigManager::getConfigOption(INPUT_EVENT_TYPE_ELEMENT_NAME, config_str, config_ptr))
		throw EmptyInputEventTypeException(getId());

	// find vocabulary term for input event type
	Vocabulary::TermRef term_ref = v.findTerm(config_str);
	if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
		throw UnknownTermException(config_str);
	m_input_event_type = v[term_ref];

	// make sure that term is object/event type
	if (m_input_event_type.term_type != Vocabulary::TYPE_OBJECT)
		throw NotAnObjectException(config_str);

	// get the input event term
	if (! ConfigManager::getConfigOption(INPUT_EVENT_TERM_ELEMENT_NAME, config_str, config_ptr))
		throw EmptyInputEventTermException(getId());

	// find vocabulary term for input event term
	term_ref = v.findTerm(config_str);
	if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
		throw UnknownTermException(config_str);
	m_input_event_term = v[term_ref];

	// only string types are currently supported for input event term
	switch (m_input_event_term.term_type) {
	case Vocabulary::TYPE_NULL:
	case Vocabulary::TYPE_OBJECT:
	case Vocabulary::TYPE_INT8:
	case Vocabulary::TYPE_INT16:
	case Vocabulary::TYPE_INT32:
	case Vocabulary::TYPE_UINT8:
	case Vocabulary::TYPE_UINT16:
	case Vocabulary::TYPE_UINT32:
	case Vocabulary::TYPE_INT64:
	case Vocabulary::TYPE_UINT64:
	case Vocabulary::TYPE_FLOAT:
	case Vocabulary::TYPE_DOUBLE:
	case Vocabulary::TYPE_LONG_DOUBLE:
	case Vocabulary::TYPE_DATE_TIME:
	case Vocabulary::TYPE_DATE:
	case Vocabulary::TYPE_TIME:
		throw TermNotStringException(config_str);
		break;
	case Vocabulary::TYPE_SHORT_STRING:
	case Vocabulary::TYPE_STRING:
	case Vocabulary::TYPE_LONG_STRING:
	case Vocabulary::TYPE_CHAR:
	case Vocabulary::TYPE_BLOB:
	case Vocabulary::TYPE_ZBLOB:
		break;	// these are all OK
	}

	// get the codec to use
	boost::mutex::scoped_lock codec_lock(m_codec_mutex);
	if (! ConfigManager::getConfigOption(CODEC_ELEMENT_NAME, m_codec_id, config_ptr))
		throw EmptyCodecException(getId());
	m_codec_ptr = getCodecFactory().getCodec(m_codec_id);	
	PION_ASSERT(m_codec_ptr);
	codec_lock.unlock();

	// check if we should copy all terms from original event
	m_copy_all_terms = false;
	std::string copy_all_terms_str;
	if (ConfigManager::getConfigOption(COPY_ALL_TERMS_ELEMENT_NAME,
									   copy_all_terms_str, config_ptr))
	{
		if (copy_all_terms_str == "true")
			m_copy_all_terms = true;
	}

	// get list of terms to copy from original event
	m_copy_terms.clear();
	xmlNodePtr copy_term_node = config_ptr;
	while ((copy_term_node = ConfigManager::findConfigNodeByName(COPY_TERM_ELEMENT_NAME, copy_term_node)) != NULL) {
		xmlChar *xml_char_ptr = xmlNodeGetContent(copy_term_node);
		if (xml_char_ptr != NULL) {
			const std::string copy_term_str(reinterpret_cast<char*>(xml_char_ptr));
			xmlFree(xml_char_ptr);
			if (! copy_term_str.empty()) {
				// find the term in the Vocabulary
				term_ref = v.findTerm(copy_term_str);
				if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
					throw UnknownTermException(copy_term_str);

				// add it to the copy terms collection
				m_copy_terms.push_back(v[term_ref]);
			}
		}

		// step to the next copy term
		copy_term_node = copy_term_node->next;
	}
}
Пример #3
0
void TransformReactor::setConfig(const Vocabulary& v, const xmlNodePtr config_ptr)
{
	// first set config options for the Reactor base class
	ConfigWriteLock cfg_lock(*this);
	Reactor::setConfig(v, config_ptr);

	// clear the current configuration
	m_transforms.clear();

	// Outgoing Event type -- i.e. what will the outgoing event be transformed into
	// Default (UNDEFINED_TERM_REF) -- make it the same as incoming event type
	// 	<OutgoingEvent>obj-term</OutgoingEvent>
	m_event_type = Vocabulary::UNDEFINED_TERM_REF;
	std::string event_type_str;
	if (ConfigManager::getConfigOption(OUTGOING_EVENT_ELEMENT_NAME, event_type_str, config_ptr))
	{
		if (!event_type_str.empty())
			m_event_type = v.findTerm(event_type_str);
	}

	// This really doesn't make much sense anymore -- you can wire the delivery of the original right through
	// it would make sense, if it was possible to deliver "if-not-changed" but TR2 always changes...
	// 	<DeliverOriginal>always|if-not-changed|never</DeliveryOriginal>		-> DEFAULT: never
	m_deliver_original = DO_NEVER;
	std::string deliver_original_str;
	if (ConfigManager::getConfigOption(DELIVER_ORIGINAL_NAME, deliver_original_str, config_ptr))
	{
		if (deliver_original_str == "true" || deliver_original_str == "always")
			m_deliver_original = DO_ALWAYS;
		else if (deliver_original_str == "if-not-changed")
			m_deliver_original = DO_SOMETIMES;
		// Could add code to throw if d_o_s is not "never"
	}

	// What fields/terms of the original event should be COPIED into the new event
	// <CopyOriginal>all-terms|if-not-defined|none</CopyOriginal>			-> DEFAULT: if-not-defined
	m_copy_original = COPY_UNCHANGED;
	std::string copy_original_str;
	if (ConfigManager::getConfigOption(COPY_ORIGINAL_ELEMENT_NAME, copy_original_str, config_ptr))
	{
		if (copy_original_str == "all-terms")
			m_copy_original = COPY_ALL;
		else if (copy_original_str == "none")
			m_copy_original = COPY_NONE;
		// Could add code to throw if c_o_s is not "if-not-defined"
	}

	// now, parse transformation rules
	// [rpt]	<Transformation>
	xmlNodePtr transformation_node = config_ptr;
	while ( (transformation_node = ConfigManager::findConfigNodeByName(TRANSFORMATION_ELEMENT_NAME, transformation_node)) != NULL)
	{
		// parse new Transformation rule

		// get the Term used for the Transformation rule
		//	<Term>src-term</Term>
		std::string term_id;
		if (! ConfigManager::getConfigOption(TERM_ELEMENT_NAME, term_id,
											 transformation_node->children))
			throw EmptyTermException(getId());

		// make sure that the Term is valid
		const Vocabulary::TermRef term_ref = v.findTerm(term_id);
		if (term_ref == Vocabulary::UNDEFINED_TERM_REF)
			throw UnknownTermException(getId());

		// get the Type of transformation
		//	<Type>AssignValue|AssignTerm|Lookup|Rules</Type>
		std::string type_str;
		if (! ConfigManager::getConfigOption(TYPE_ELEMENT_NAME, type_str,
											 transformation_node->children))
			throw EmptyTypeException(getId());	// TODO: Improve the error message

		// Add the transformation
		const bool debug_mode = getReactionEngine().getDebugMode();
		Transform *new_transform;
		if (type_str == "AssignValue")
			new_transform = new TransformAssignValue(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "AssignTerm")
			new_transform = new TransformAssignTerm(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "Lookup")
			new_transform = new TransformLookup(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "Rules")
			new_transform = new TransformRules(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "Regex")
			new_transform = new TransformRegex(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "SplitTerm")
			new_transform = new TransformSplitTerm(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "JoinTerm")
			new_transform = new TransformJoinTerm(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "URLEncode")
			new_transform = new TransformURLEncode(v, v[term_ref], transformation_node->children, debug_mode);
		else if (type_str == "URLDecode")
			new_transform = new TransformURLDecode(v, v[term_ref], transformation_node->children, debug_mode);
		else
			throw InvalidTransformation(type_str);

		m_transforms.push_back(new_transform);

		// step to the next Comparison rule
		transformation_node = transformation_node->next;
	}
}