Ejemplo n.º 1
0
void PrivacyQueryFactory::handleStartElement(const QStringRef &name, const QStringRef &uri,
											 const QXmlStreamAttributes &attributes)
{
	Q_UNUSED(uri);
	m_depth++;
	if (m_depth == 1) {
		m_query.reset(new PrivacyQuery);
	} if (m_depth == 2) {
		QStringRef listName = attributes.value(QLatin1String("name"));
		if (name == QLatin1String("list")) {
			m_state = AtList;
			m_name = listName.toString();
			
		} else if (name == QLatin1String("active")) {
			m_query->activeList = listName.toString();
		} else if (name == QLatin1String("default")) {
			m_query->defaultList = listName.toString();
		}
	} else if (m_depth == 3 && m_state == AtList && name == QLatin1String("item")) {
		// We should provide fallback as said in rfc-3920
		m_items.append(m_items.isEmpty() ? PrivacyItem() : m_items.last());
		PrivacyItem &item = m_items.last();
		m_state = AtItem;
		QStringRef data = attributes.value(QLatin1String("value"));
		int type = strToEnum(attributes.value(QLatin1String("type")), privacy_types);
		if (type == -1 && !data.isEmpty())
			type = item.type();
		switch (type) {
		case PrivacyItem::ByJID:
			item.setJID(data.toString());
			break;
		case PrivacyItem::ByGroup:
			item.setGroup(data.toString());
			break;
		case PrivacyItem::BySubscription:
			item.setSubscription(strToEnum<PrivacyItem::SubscriptionType>(data, subscription_types));
			break;
		default:
			item = PrivacyItem();
			break;
		}
		data = attributes.value(QLatin1String("action"));
		item.setAction(strToEnum<PrivacyItem::Action>(data, privacy_actions));
		item.setOrder(attributes.value(QLatin1String("order")).toString().toInt());
		item.setStanzaTypes(0);
	} else if (m_depth == 4 && m_state == AtItem) {
		int data = strToEnum(name, privacy_stanzas);
		if (data == -1)
			return;
		PrivacyItem &item = m_items.last();
		item.setStanzaTypes(item.stanzaTypes() | static_cast<PrivacyItem::StanzaType>(1 << data));
	}
}
Ejemplo n.º 2
0
void fromBytes(Str& topic,Bytes& message) {
	Str& str = (Str&) message;
	Gpio::Mode mode;
	if (strToEnum((uint32_t&) mode, gpioModeEnum,
			sizeof(gpioModeEnum) / sizeof(EnumEntry), str)) {
		_gpio.setMode(mode);
	}
}