Beispiel #1
0
MojErr MojDbPropExtractor::fromObjectImpl(const MojObject& obj, const MojDbPropExtractor& defaultConfig, const MojChar* locale)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	// super
	MojErr err = MojDbExtractor::fromObject(obj, locale);
	MojErrCheck(err);

	// default value
	m_default = defaultConfig.m_default;
	MojObject defaultVal;
	if (obj.get(DefaultKey, defaultVal)) {
		MojObject::Type type = defaultVal.type();
		MojDbKey key;
		if (type == MojObject::TypeArray) {
			// if the value is an array, act on its elements rather than the array object itself
			MojObject::ConstArrayIterator end = defaultVal.arrayEnd();
			for (MojObject::ConstArrayIterator j = defaultVal.arrayBegin(); j != end; ++j) {
				err = key.assign(*j);
				MojErrCheck(err);
				err = m_default.put(key);
				MojErrCheck(err);
			}
		} else {
			err = key.assign(defaultVal);
			MojErrCheck(err);
			err = m_default.put(key);
			MojErrCheck(err);
		}
	}

	// tokenizer
	m_tokenizer = defaultConfig.m_tokenizer;
	MojString tokenize;
	bool found = false;
	err = obj.get(TokenizeKey, tokenize, found);
	MojErrCheck(err);
	if (found) {
		if (tokenize == AllKey || tokenize == DefaultKey) {
			m_tokenizer.reset(new MojDbTextTokenizer);
			MojAllocCheck(m_tokenizer.get());
			err = m_tokenizer->init(locale);
			MojErrCheck(err);
		} else {
			MojErrThrow(MojErrDbInvalidTokenization);
		}
	}

	// collator
	if (m_collation == MojDbCollationInvalid)
		m_collation = defaultConfig.m_collation;
	err = updateLocale(locale);
	MojErrCheck(err);

	// set prop
	err = prop(m_name);
	MojErrCheck(err);

	return MojErrNone;
}
Beispiel #2
0
MojErr MojDbMultiExtractor::fromObject(const MojObject& obj, const MojChar* locale)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

	MojErr err = MojDbExtractor::fromObject(obj, locale);
	MojErrCheck(err);

	// load the default config
	MojDbPropExtractor defaultExtractor;
	err = defaultExtractor.fromObject(obj, locale);
	MojErrCheck(err);

	MojObject include;
	err = obj.getRequired(IncludeKey, include);
	MojErrCheck(err);

	for (MojObject::ConstArrayIterator i = include.arrayBegin();
		 i != include.arrayEnd(); ++i) {
		MojString includeName;
		err = i->stringValue(includeName);
		MojErrCheck(err);
		MojRefCountedPtr<MojDbPropExtractor> propExtractor(new MojDbPropExtractor);
		MojAllocCheck(propExtractor.get());
		err = propExtractor->fromObjectImpl(*i, defaultExtractor, locale);
		MojErrCheck(err);
		err = m_extractors.push(propExtractor);
		MojErrCheck(err);
	}
	return MojErrNone;
}
Beispiel #3
0
MojErr MojDbKind::configureRevSets(const MojObject& obj)
{
	MojLogTrace(s_log);

	m_revSets.clear();
	MojSet<MojString> setNames;
	MojObject array;
	if (obj.get(RevisionSetsKey, array)) {
		MojObject::ConstArrayIterator end = array.arrayEnd();
		for (MojObject::ConstArrayIterator i = array.arrayBegin(); i != end; ++i) {
			MojRefCountedPtr<MojDbRevisionSet> set(new MojDbRevisionSet());
			MojAllocCheck(set.get());

			MojErr err = set->fromObject(*i);
			MojErrCheck(err);
			if (setNames.contains(set->name())) {
				MojErrThrowMsg(MojErrDbInvalidRevisionSet, _T("db: cannot repeat revSet name: '%s'"), set->name().data());
			}
			err = setNames.put(set->name());
			MojErrCheck(err);
			err = m_revSets.push(set);
			MojErrCheck(err);
		}
	}
	return MojErrNone;
}
Beispiel #4
0
static MojErr getTypes(MojObject typesArray, BusClient::ScanTypes &bitmask)
{
	MojObject::ConstArrayIterator it = typesArray.arrayBegin();
	if (it == NULL)
		MojErrThrowMsg(MojErrInvalidMsg, "'types' not an array");

	for (MojObject::ConstArrayIterator ni = typesArray.arrayEnd(); it != ni; it++) {
		const MojObject& element = *it;
		MojString type;
		MojErr err;

		err = element.stringValue(type);
		MojErrCheck(err);

		if (type == "dbkinds")
			bitmask |= BusClient::DBKINDS;
		else if (type == "dbpermissions")
			bitmask |= BusClient::DBPERMISSIONS;
		else if (type == "filecache")
			bitmask |= BusClient::FILECACHE;
		else if (type == "activities")
			bitmask |= BusClient::ACTIVITIES;
		else
			MojErrThrowMsg(MojErrInvalidMsg, "unrecognized type '%s'", type.data());
	}

	return MojErrNone;
}
Beispiel #5
0
MojErr MojDbPerfCreateTest::batchPutLargeArrayObj(MojDb& db, const MojChar* kindId, MojTime& lgArrayObjTime)
{
	MojTime startTime;
	MojTime endTime;

	MojObject objArray;

	for (MojUInt64 i = 0; i < numInsert; i++) {
		MojObject obj;
		MojErr err = obj.putString(MojDb::KindKey, kindId);
		MojTestErrCheck(err);
		err = createLargeArrayObj(obj, i);
		MojTestErrCheck(err);
		err = objArray.push(obj);
		MojTestErrCheck(err);
	}

	MojObject::ArrayIterator begin;
	MojErr err = objArray.arrayBegin(begin);
	MojTestErrCheck(err);
	MojObject::ConstArrayIterator end = objArray.arrayEnd();
	err = MojGetCurrentTime(startTime);
	MojTestErrCheck(err);
	err = db.put(begin, end);
	MojTestErrCheck(err);
	err = MojGetCurrentTime(endTime);
	MojTestErrCheck(err);
	lgArrayObjTime += (endTime - startTime);
	totalTestTime += (endTime - startTime);

	return MojErrNone;
}
MojErr MojDbServiceHandler::handleGet(MojServiceMessage* msg, MojObject& payload, MojDbReq& req)
{
	MojAssert(msg);
	MojLogTrace(s_log);

	MojObject ids;
	MojErr err = payload.getRequired(MojDbServiceDefs::IdsKey, ids);
	MojErrCheck(err);

	MojObjectVisitor& writer = msg->writer();
	err = writer.beginObject();
	MojErrCheck(err);
	err = writer.boolProp(MojServiceMessage::ReturnValueKey, true);
	MojErrCheck(err);
	err = writer.propName(MojDbServiceDefs::ResultsKey);
	MojErrCheck(err);
	err = writer.beginArray();
	MojErrCheck(err);
	err = m_db.get(ids.arrayBegin(), ids.arrayEnd(), writer, req);
	MojErrCheck(err);
	err = writer.endArray();
	MojErrCheck(err);
	err = writer.endObject();
	MojErrCheck(err);

	return MojErrNone;
}
MojErr MojDbTextTokenizerTest::check(const MojChar* text, const MojChar* tokens)
{
	// tokenize string
	MojString textStr;
	MojErr err = textStr.assign(text);
	MojTestErrCheck(err);
	MojSet<MojDbKey> set;
	MojRefCountedPtr<MojDbTextTokenizer> tokenizer(new MojDbTextTokenizer);
	MojAllocCheck(tokenizer.get());
	err = tokenizer->init(_T("en_US"));
	MojTestErrCheck(err);
	err = tokenizer->tokenize(textStr, NULL, set);
	MojTestErrCheck(err);
	// check that tokens match
	MojObject obj;
	err = obj.fromJson(tokens);
	MojTestErrCheck(err);
	MojSize objSize = obj.size();
	MojSize setSize = set.size();
	MojTestAssert(objSize == setSize);
	for (MojObject::ConstArrayIterator i = obj.arrayBegin(); i != obj.arrayEnd(); ++i) {
		MojDbKey key;
		err = key.assign(*i);
		MojTestErrCheck(err);
		MojTestAssert(set.contains(key));
	}
	return MojErrNone;
}
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckMatches(
	const MojObject& rhsArray, const MojObject& op, const MojObject& val,
	MatchMode mode) const
{
	/* Matching a value against an array */
	for (MojObject::ConstArrayIterator iter = rhsArray.arrayBegin();
		iter != rhsArray.arrayEnd(); ++iter) {
		MatchResult result = CheckMatch(*iter, op, val);
		if (mode == AndMode) {
			if (result != Matched) {
				return NotMatched;
			}
		} else {
			if (result == Matched) {
				return Matched;
			}
		}
	}

	/* If we got here in And mode it means all the values matched.  If we
	 * got here in Or mode, it means none of them did. */
	if (mode == AndMode) {
		return Matched;
	} else {
		return NotMatched;
	}
}
MojErr MojDbPerfCreateTest::batchPutLargeArrayObj(MojDb& db, const MojChar* kindId, MojUInt64& lgArrayObjTime)
{
	timespec startTime;
	startTime.tv_nsec = 0;
	startTime.tv_sec = 0;
	timespec endTime;
	endTime.tv_nsec = 0;
	endTime.tv_sec = 0;

	MojObject objArray;

	for (MojUInt64 i = 0; i < numInsert; i++) {
		MojObject obj;
		MojErr err = obj.putString(MojDb::KindKey, kindId);
		MojTestErrCheck(err);
		err = createLargeArrayObj(obj, i);
		MojTestErrCheck(err);
		err = objArray.push(obj);
		MojTestErrCheck(err);
	}

	MojObject::ArrayIterator begin;
	MojErr err = objArray.arrayBegin(begin);
	MojTestErrCheck(err);
	MojObject::ConstArrayIterator end = objArray.arrayEnd();
	clock_gettime(CLOCK_REALTIME, &startTime);
	err = db.put(begin, end);
	MojTestErrCheck(err);
	clock_gettime(CLOCK_REALTIME, &endTime);
	lgArrayObjTime += timeDiff(startTime, endTime);
	totalTestTime += timeDiff(startTime, endTime);

	return MojErrNone;
}
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty(
	const MojObject& key, const MojObject& response, const MojObject& op,
	const MojObject& val, MatchMode mode) const
{
	if (key.type() == MojObject::TypeString) {
		MojString keyStr;
		MojErr err = key.stringValue(keyStr);
		if (err) {
			throw std::runtime_error("Failed to convert property lookup key "
				"to string");
		}

		MojObject propVal;
		bool found = response.get(keyStr.data(), propVal);
		if (!found) {
			return NoProperty;
		}

		return CheckMatch(propVal, op, val);

	} else if (key.type() == MojObject::TypeArray) {
		return CheckProperty(key, key.arrayBegin(), response, op, val, mode);
	} else {
		throw std::runtime_error("Key specified was neither a string or "
			"array of strings");
	}
}
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty(
	const MojObject& keyArray, MojObject::ConstArrayIterator keyIter,
	const MojObject& response, const MojObject& op, const MojObject& val,
	MatchMode mode) const
{
	MojObject onion = response;
	for (; keyIter != keyArray.arrayEnd(); ++keyIter) {
		if (onion.type() == MojObject::TypeArray) {
			return CheckProperty(keyArray, keyIter, onion, onion.arrayBegin(),
				op, val, mode);
		} else if (onion.type() == MojObject::TypeObject) {
			MojString keyStr;
			MojErr err = (*keyIter).stringValue(keyStr);
			if (err) {
				throw std::runtime_error("Failed to convert property lookup "
					"key to string");
			}

			MojObject next;
			if (!onion.get(keyStr.data(), next)) {
				return NoProperty;
			}

			onion = next;
		} else {
			return NoProperty;
		}
	}

	return CheckMatch(onion, op, val);

}
Beispiel #12
0
void EmailAdapter::ParseRecipients(const MojObject& recipients, Email& email)
{
	MojErr err;
	
	EmailAddressListPtr to_list(new EmailAddressList);
	EmailAddressListPtr cc_list(new EmailAddressList);
	EmailAddressListPtr bcc_list(new EmailAddressList);
	
	MojObject::ConstArrayIterator it = recipients.arrayBegin();

	for (; it != recipients.arrayEnd(); ++it) {
		const MojObject& recipient = *it;

		MojString type;
		err = recipient.getRequired(Part::TYPE, type);
		ErrorToException(err);
		
		EmailAddressPtr addr = ParseAddress(recipient);

		if(type.compareCaseless("to") == 0)
			to_list->push_back(addr);
		else if(type.compareCaseless("cc") == 0)
			cc_list->push_back(addr);
		else if(type.compareCaseless("bcc") == 0)
			bcc_list->push_back(addr);
		else // not a valid recipient type
			throw MailException("invalid recipient type", __FILE__, __LINE__);
	}
	
	email.SetTo(to_list);
	email.SetCc(cc_list);
	email.SetBcc(bcc_list);
}
MojErr OnEnabledHandler::getAccountConfigResult(MojObject& payload, MojErr err)
{
    MojLogTrace(IMServiceApp::s_log);

    if (err != MojErrNone) {
        MojString error;
        MojErrToString(err, error);
        MojLogCritical(IMServiceApp::s_log, "getAccountConfig failed: error %d - %s", err, error.data());
    }
    else
    {
        MojObject results;
        payload.get("results", results);

        if (!results.empty())
        {
            m_config = *results.arrayBegin();
        }
    }

	if (m_enable) {
		err = accountEnabled();
	} else {
		err = accountDisabled();
	}

	return err;
}
Beispiel #14
0
MojErr MojDbPerfUpdateTest::updateObjsViaPut(MojDb& db, const MojChar* kindId, MojErr (MojDbPerfTest::*createFn) (MojObject&, MojUInt64))
{
	// register all the kinds
	MojTime time;
	MojErr err = putKinds(db, time);
	MojTestErrCheck(err);

	// put objects using createFn
	MojObject objs;
	err = putObjs(db, kindId, numInsertForPut, createFn, objs);
	MojTestErrCheck(err);

	MojObject midObj;
	bool found = objs.at(numInsertForPut/2, midObj);
	MojTestAssert(found);

	MojTime objTime;
	err = putObj(db, midObj, objTime);
	MojTestErrCheck(err);
	MojUInt64 putTime = objTime.microsecs();
	err = MojPrintF("\n -------------------- \n");
	MojTestErrCheck(err);
	err = MojPrintF("   putting single object - index %llu - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/2, kindId, numPutIterations, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per put: %llu microsecs", (putTime) / (numPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	MojString buf;
	err = buf.format("Put single object - index %llu - %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/2, numPutIterations, kindId, putTime, putTime/numPutIterations, putTime/(1*numPutIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	MojTime batchTime;
	MojObject::ArrayIterator beginArr;
	err = objs.arrayBegin(beginArr);
	MojErrCheck(err);
	err = batchPutObj(db, beginArr, beginArr + (numInsertForPut / 10), batchTime);
	putTime = batchTime.microsecs();
	MojTestErrCheck(err);
	err = MojPrintF("   putting batch - %llu objects - of kind %s %llu times took: %llu microsecs\n", numInsertForPut/10, kindId, numBatchPutIterations, putTime);
	MojTestErrCheck(err);
	err = MojPrintF("   time per batch put: %llu microsecs\n", (putTime) / (numBatchPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("   time per object: %llu microsecs", (putTime) / (numInsertForPut/10 * numBatchPutIterations));
	MojTestErrCheck(err);
	err = MojPrintF("\n\n");
	MojTestErrCheck(err);

	err = buf.format("Batch put %llu objects %llu times,%s,%llu,%llu,%llu,\n", numInsertForPut/10, numBatchPutIterations, kindId, putTime, putTime/numBatchPutIterations, putTime/(numInsertForPut/10*numBatchPutIterations));
	MojTestErrCheck(err);
	err = fileWrite(file, buf);
	MojTestErrCheck(err);

	return MojErrNone;
}
Beispiel #15
0
MojErr BusClient::BusMethods::ScanRequest(MojServiceMessage* msg, MojObject& payload, ConfigurationMode confmode)
{
	try {
		MojErr err;
		if (payload.type() != MojObject::TypeArray) {
			MojErrThrowMsg(MojErrInternal, "invalid message format");
		}

		m_client.m_msg.reset(msg);

		for (MojObject::ConstArrayIterator it = payload.arrayBegin(); it != payload.arrayEnd(); it++) {
			const MojObject& request = *it;
			MojString locationStr;
			MojString typeStr;
			MojString app;
			BusClient::PackageType type;
			BusClient::PackageLocation location;

			err = request.getRequired("id", app);
			MojErrCheck(err);

			err = request.getRequired("type", typeStr);
			MojErrCheck(err);

			err = request.getRequired("location", locationStr);
			MojErrCheck(err);

			if (typeStr == "app") {
				type = BusClient::Application;
			} else if (typeStr == "service") {
				type = BusClient::Service;
			} else {
				MojErrThrow(MojErrInvalidMsg);
			}

			if (locationStr == "system") {
				location = BusClient::System;
			} else if (locationStr == "third party") {
				location = BusClient::ThirdParty;
			} else {
				MojErrThrow(MojErrInvalidMsg);
			}

			m_client.Scan(confmode, app, type, location);
		}

		m_client.RunNextConfigurator();
	} catch (const std::exception& e) {
		MojErrThrowMsg(MojErrInternal, "%s", e.what());
	} catch (...) {
		MojErrThrowMsg(MojErrInternal, "uncaught exception");
	}

	return MojErrNone;
}
bool MojoWhereMatcher::GetObjectValue(const MojObject& key,
	const MojObject& response, MojObject& value) const
{
	if (key.type() == MojObject::TypeString) {
		MojString keyStr;
		MojErr err = key.stringValue(keyStr);
		if (err) {
			throw std::runtime_error("Error attempting to retrieve key name "
				"getting object value");
		}

		if (response.contains(keyStr)) {
			return response.get(keyStr, value);
		} else {
			return false;
		}
	} else if (key.type() == MojObject::TypeArray) {
		MojObject cur = response;
		for (MojObject::ConstArrayIterator iter = key.arrayBegin();
			iter != key.arrayEnd(); ++iter) {
			const MojObject& keyObj = *iter; 

			if (keyObj.type() != MojObject::TypeString) {
				throw std::runtime_error("Non-string found in property "
					"specifiction array");
			}

			MojString keyStr;
			MojErr err = keyObj.stringValue(keyStr);
			if (err) {
				throw std::runtime_error("Failed to access lookup key");
			}

			if (cur.contains(keyStr)) {
				MojObject tmp;
				if (!cur.get(keyStr, tmp)) {
					return false;
				} else {
					cur = tmp;
				}
			} else {
				return false;
			}
		}

		value = cur;
		return true;
	} else {
		throw std::runtime_error("Property specification must be the "
			"property name or array of property names");
	}
}
Beispiel #17
0
void EmailAdapter::ParseParts(const MojObject& partsArray, EmailPartList& partList)
{
	MojObject::ConstArrayIterator it = partsArray.arrayBegin();

	for (; it != partsArray.arrayEnd(); ++it) {
		const MojObject& partObj = *it;

		EmailPartPtr emailPart = ParseEmailPart(partObj);

		// Add to the part list
		partList.push_back(emailPart);
	}
}
MojErr MojDbServiceHandler::handleMerge(MojServiceMessage* msg, MojObject& payload, MojDbReq& req)
{
	MojAssert(msg);
	MojLogTrace(s_log);

	MojErr err = MojErrNone;
	MojUInt32 count = 0;
	MojObject obj;
	

	if (payload.get(MojDbServiceDefs::ObjectsKey, obj)) {
		if (payload.contains(MojDbServiceDefs::QueryKey))
			MojErrThrowMsg(MojErrInvalidArg, _T("db: cannot have both an objects param and a query param"));
		MojObject::ArrayIterator begin;
		bool ignoreM = false;
		payload.get(MojDbServiceDefs::IgnoreMissingKey, ignoreM);
		MojUInt32 mflags = MojDb::FlagNone;
		if (ignoreM)
			mflags = mflags | MojDb::FlagIgnoreMissing;
		err = obj.arrayBegin(begin);
		MojErrCheck(err);
		MojObject::ConstArrayIterator end = obj.arrayEnd();
		err = m_db.merge(begin, end, mflags, req);
		MojErrCheck(err);
		err = formatPut(msg, begin, end); // TO DO: we need to drop non-existing objects
		MojErrCheck(err);
	}
	else if (payload.get(MojDbServiceDefs::QueryKey, obj)) {
		MojObject props;
		err = payload.getRequired(MojDbServiceDefs::PropsKey, props);
		MojErrCheck(err);
		bool ignoreM = false;
		if (payload.get(MojDbServiceDefs::IgnoreMissingKey, ignoreM))
			MojErrThrowMsg(MojErrInvalidArg, _T("db: ignoreMissing - invalid option for merge query"));

		MojDbQuery query;
		err = query.fromObject(obj);
		MojErrCheck(err);
		MojUInt32 queryCount = 0;
		err = m_db.merge(query, props, queryCount, MojDb::FlagNone, req);
		MojErrCheck(err);
		count += queryCount;
		err = formatCount(msg, count);
		MojErrCheck(err);
	}
	else {
		MojErrThrowMsg(MojErrInvalidArg, _T("db: either objects or query param required for merge"));
	}

	return MojErrNone;
}
Beispiel #19
0
MojErr MojDbDistinctTest::check(MojDb& db, const MojDbQuery& query, MojDbCursor& cursor, const MojChar* queryString, const MojChar* expectedIdsJson)
{
	MojErr err = db.find(query, cursor);
	MojTestErrCheck(err);

	MojObjectBuilder builder;
	err = builder.beginArray();
	MojTestErrCheck(err);
	err = cursor.visit(builder);
	MojTestErrCheck(err);
	err = cursor.close();
	MojTestErrCheck(err);
	err = builder.endArray();
	MojTestErrCheck(err);
	MojObject results = builder.object();

	MojString json;
	err = results.toJson(json);
	MojTestErrCheck(err);

	MojObject expected;
	err = expected.fromJson(expectedIdsJson);
	MojTestErrCheck(err);

	// size check
	MojTestAssert(expected.size() == results.size());

	// value check
	MojObject::ConstArrayIterator j = results.arrayBegin();
	for (MojObject::ConstArrayIterator i = expected.arrayBegin();
			i != expected.arrayEnd(); ++i, ++j) {
		MojObject value;
		err = j->getRequired(queryString, value);
		MojTestErrCheck(err);
		MojTestAssert(*i == value);
	}
	return MojErrNone;
}
MojErr MojDbServiceHandler::handleBatch(MojServiceMessage* msg, MojObject& payload, MojDbReq& req)
{
	MojAssert(msg);
	MojLogTrace(s_log);

	MojObject operations;
	MojErr err = payload.getRequired(MojDbServiceDefs::OperationsKey, operations);
	MojErrCheck(err);
	MojObject::ArrayIterator begin;
	err = operations.arrayBegin(begin);
	MojErrCheck(err);

	//start the response array
	MojObjectVisitor& writer = msg->writer();
	err = writer.beginObject();
	MojErrCheck(err);
	err = writer.boolProp(MojServiceMessage::ReturnValueKey, true);
	MojErrCheck(err);
	err = writer.propName(MojDbServiceDefs::ResponsesKey);
	MojErrCheck(err);
	err = writer.beginArray();
	MojErrCheck(err);

	for (MojObject* i = begin; i != operations.arrayEnd(); ++i) {
		MojString method;
		err = i->getRequired(MojDbServiceDefs::MethodKey, method);
		MojErrCheck(err);
		MojObject params;
		err = i->getRequired(MojDbServiceDefs::ParamsKey, params);
		MojErrCheck(err);
		// not allowed to specify watch key in a batch
		bool watchValue = false;
		if (payload.get(MojDbServiceDefs::WatchKey, watchValue) && watchValue) {
			MojErrThrow(MojErrDbInvalidBatch);
		}
		DbCallback cb;
		if (!m_batchCallbacks.get(method, cb)) {
			MojErrThrow(MojErrDbInvalidBatch);
		}
		err = (this->*cb)(msg, params, req);
		MojErrCheck(err);
	}

	err = writer.endArray();
	MojErrCheck(err);
	err = writer.endObject();
	MojErrCheck(err);

	return MojErrNone;
}
Beispiel #21
0
MojErr MojDbSearchTest::check(MojDb& db, const MojDbQuery& query, const MojChar* expectedIdsJson)
{
   MojString str;
   MojDbSearchCursor cursor(str);
	MojErr err = db.find(query, cursor);
	MojTestErrCheck(err);

	MojObjectBuilder builder;
	err = builder.beginArray();
	MojTestErrCheck(err);
	err = cursor.visit(builder);
	MojTestErrCheck(err);
	err = cursor.close();
	MojTestErrCheck(err);
	err = builder.endArray();
	MojTestErrCheck(err);
	MojObject results = builder.object();

	MojString json;
	err = results.toJson(json);
	MojTestErrCheck(err);

	MojObject expected;
	err = expected.fromJson(expectedIdsJson);
	MojTestErrCheck(err);

	MojTestAssert(expected.size() == results.size());
	MojObject::ConstArrayIterator j = results.arrayBegin();
	for (MojObject::ConstArrayIterator i = expected.arrayBegin();
			i != expected.arrayEnd(); ++i, ++j) {
		MojObject id;
		err = j->getRequired(MojDb::IdKey, id);
		MojTestErrCheck(err);
		MojTestAssert(*i == id);
	}
	return MojErrNone;
}
MojErr MojDbServiceHandler::handleDel(MojServiceMessage* msg, MojObject& payload, MojDbReq& req)
{
	MojAssert(msg);
	MojLogTrace(s_log);

	MojErr err = MojErrNone;
	MojUInt32 count = 0;
	MojUInt32 flags = MojDb::FlagNone;

	bool purge = false;
	if (payload.get(MojDbServiceDefs::PurgeKey, purge) && purge) {
		flags |= MojDb::FlagPurge;
	}

	MojObject obj;
	if (payload.get(MojDbServiceDefs::IdsKey, obj)) {
		if (payload.contains(MojDbServiceDefs::QueryKey))
			MojErrThrowMsg(MojErrInvalidArg, _T("db: cannot have both an objects argument and a query argument"));
		MojObject deletedObjects;
		err = m_db.del(obj.arrayBegin(), obj.arrayEnd(), count, deletedObjects, flags, req);
		MojErrCheck(err);
		err = formatPut(msg, deletedObjects.arrayBegin(), deletedObjects.arrayEnd());
		MojErrCheck(err);
	}
	else if (payload.get(MojDbServiceDefs::QueryKey, obj)) {
		MojDbQuery query;
		err = query.fromObject(obj);
		MojErrCheck(err);
		MojUInt32 queryCount = 0;
		err = m_db.del(query, queryCount, flags, req);
		MojErrCheck(err);
		count += queryCount;
		err = formatCount(msg, count);
		MojErrCheck(err);
	}
	return MojErrNone;
}
void MojoWhereMatcher::ValidateKey(const MojObject& key) const
{
	if (key.type() == MojObject::TypeArray) {
		for (MojObject::ConstArrayIterator iter = key.arrayBegin();
			iter != key.arrayEnd(); ++iter) {
			const MojObject& keyObj = *iter;
			if (keyObj.type() != MojObject::TypeString) {
				throw std::runtime_error("Something other than a string "
					"found in array of property names");
			}
		}
	} else if (key.type() != MojObject::TypeString) {
		throw std::runtime_error("Property keys must be specified as "
			"a property name, or array of property names");
	}
}
Beispiel #24
0
MojErr MojDbPutHandler::configure(const MojObject& conf, MojDbReq& req)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);
    MojAssertWriteLocked(m_db->schemaLock());

    // built-in permissions
    MojObject objects;
    if (conf.get(m_confProp, objects)) {
        MojObject::ConstArrayIterator end = objects.arrayEnd();
        for (MojObject::ConstArrayIterator i = objects.arrayBegin();
                i != end; ++i) {
            MojObject perm(*i);
            MojErr err = put(perm, req, false);
            MojErrCheck(err);
        }
    }
    return MojErrNone;
}
/*
 * Example messaging capability provider
 *  "capabilityProviders": [{
            "_id": "2+MR",
            "capability": "MESSAGING",
            "id": "com.palm.google.talk",
            "capabilitySubtype": "IM",
            "loc_name": "Google Talk",
            "icon": {
                "loc_32x32": "/usr/palm/public/accounts/com.palm.google/images/gtalk32x32.png",
                "loc_48x48": "/usr/palm/public/accounts/com.palm.google/images/gtalk48x48.png",
                "splitter": "/usr/palm/public/accounts/com.palm.google/images/gtalk_transport_splitter.png"
            },
            "implementation": "palm://com.palm.imlibpurple/",
            "onEnabled": "palm://com.palm.imlibpurple/onEnabled"
            "serviceName":"type_aim",
            "dbkinds": {
                "immessage":"com.palm.immessage.libpurple:1",
                "imcommand":"com.palm.imcommand.libpurple:1"
            }
    }],
 */
MojErr OnEnabledHandler::getMessagingCapabilityObject(const MojObject& capabilityProviders, MojObject& messagingObj)
{
	// iterate thru the capabilities array
	MojErr err = MojErrRequiredPropNotFound;
	MojString capability;
	MojObject::ConstArrayIterator itr = capabilityProviders.arrayBegin();
	// This shouldn't happen, but check if there's nothing to do.
	while (itr != capabilityProviders.arrayEnd()) {
		messagingObj = *itr;
		err = messagingObj.getRequired("capability", capability);
		if (capability == "MESSAGING") {
			err = MojErrNone;
			break;
		}
		++itr;
	}

	return err;
}
/*
 * Parse the account id from the results object for the accountId query
 * saved in m_accountId member variable
 *
 */
MojErr SendOneMessageHandler::readAccountIdFromResults(MojObject& result)
{
	// log the results
	MojString mojStringJson;
	result.toJson(mojStringJson);
	MojLogDebug(IMServiceApp::s_log, _T("readAccountIdFromResults result: %s"), mojStringJson.data());

	// "results" in result
	MojObject results;
	result.get(_T("results"), results);

	// check to see if array is empty - there should really always be 1 item here
	if (!results.empty()){

		// get the db id of the buddy
		MojObject loginState;
		MojObject::ConstArrayIterator itr = results.arrayBegin();
		bool foundOne = false;
		while (itr != results.arrayEnd()) {
			if (foundOne) {
				MojLogError(IMServiceApp::s_log,
						_T("readAccountIdFromResults: found more than one ImLoginState with same username/serviceName - using the first one"));
				break;
			}
			loginState = *itr;
			foundOne = true;
			itr++;
		}

		// create the DB object
		MojErr err = loginState.getRequired("accountId", m_accountId);
		if (err) {
			MojLogError(IMServiceApp::s_log, _T("readAccountIdFromResults: missing accountId in loginState entry"));
		}
		MojLogInfo(IMServiceApp::s_log, _T("readAccountIdFromResults - accountId: %s. "), m_accountId.data());
	}
	else {
		MojLogError(IMServiceApp::s_log, _T("readAccountIdFromResults: no matching loginState record found for %s"), m_serviceName.data());
	}

	return MojErrNone;
}
bool MojoWhereMatcher::CheckClauses(const MojObject& clauses,
	const MojObject& response) const
{
	MojLogTrace(s_log);

	if (clauses.type() == MojObject::TypeObject) {
		return CheckClause(clauses, response);
	} else if (clauses.type() == MojObject::TypeArray) {
		for (MojObject::ConstArrayIterator iter = clauses.arrayBegin();
			iter != clauses.arrayEnd(); ++iter) {
			if (!CheckClause(*iter, response)) {
				return false;
			}
		}
	} else {
		throw std::runtime_error("Clauses must consist of either a single "
			"where clause or array of where clauses");
	}

	return true;
}
MojErr SyncFolderListCommand::GetLocalFoldersResponse(MojObject& response, MojErr err)
{
	CommandTraceFunction();
	
	try {
		ErrorToException(err);
		
		MojObject accountId = m_session.GetAccount()->GetId();
		
		MojObject results;
		err = response.getRequired("results", results);
		ErrorToException(err);
		
		MojObject::ArrayIterator it;
		err = results.arrayBegin(it);
		ErrorToException(err);

		// Read list of local folders
		for (; it != results.arrayEnd(); ++it) {
			MojObject& folderObj = *it;
			ImapFolderPtr folder = boost::make_shared<ImapFolder>();
			
			ImapFolderAdapter::ParseDatabaseObject(folderObj, *folder);
			folder->SetAccountId(accountId);
			
			m_localFolders.push_back(folder);
		}
		
		if(DatabaseAdapter::GetNextPage(response, m_folderPage)) {
			// Get more folders
			GetLocalFolders();
		} else {
			// Next step: get list of emails from server
			SendListCommand();
		}
	} CATCH_AS_FAILURE
	
	return MojErrNone;
}
void MojoNewWhereMatcher::ValidateClauses(const MojObject& where) const
{
	LOG_AM_TRACE("Entering function %s", __FUNCTION__);
	LOG_AM_DEBUG("Validating trigger clauses");

	if (where.type() == MojObject::TypeObject) {
		ValidateClause(where);
	} else if (where.type() == MojObject::TypeArray) {
		for (MojObject::ConstArrayIterator iter = where.arrayBegin();
			iter != where.arrayEnd(); ++iter) {
			const MojObject& clause = *iter;
			if (clause.type() != MojObject::TypeObject) {
				throw std::runtime_error("where statement array must "
					"consist of valid clauses");
			} else {
				ValidateClause(clause);
			}
		}
	} else {
		throw std::runtime_error("where statement should consist of a single "
			"clause or array of valid clauses");
	}
}
void MojoWhereMatcher::ValidateClauses(const MojObject& where) const
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Validating trigger clauses"));

	if (where.type() == MojObject::TypeObject) {
		ValidateClause(where);
	} else if (where.type() == MojObject::TypeArray) {
		for (MojObject::ConstArrayIterator iter = where.arrayBegin();
			iter != where.arrayEnd(); ++iter) {
			const MojObject& clause = *iter;
			if (clause.type() != MojObject::TypeObject) {
				throw std::runtime_error("where statement array must "
					"consist of valid clauses");
			} else {
				ValidateClause(clause);
			}
		}
	} else {
		throw std::runtime_error("where statement should consist of a single "
			"clause or array of valid clauses");
	}
}