Ejemplo n.º 1
0
MojErr PopBusDispatcher::ParseEmlMessage(MojServiceMessage* msg, MojObject& payload)
{
	MojLogInfo(s_log, "PopBusDispatcher::ParseEmlMessage");

	// cancel shut down if it is in shut down state
	CancelShutdown();

	try {

		MojString filePath;
		MojErr err = payload.getRequired("filePath", filePath);
		ErrorToException(err);

		MojLogDebug(s_log, "filePath:%s", filePath.data());
		if (filePath.empty()) {
			msg->replyError(MojErrInvalidArg, "Invalid query string");
		} else {
			new ParseEmlHandler(this, m_bClient, m_tasks, msg, filePath.data());
		}

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

}
Ejemplo n.º 2
0
MojErr MojDbQuotaEngine::informQuotaSubscribers(const MojString& kindId)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

    MojErr err;
    MojInt64 sizeOut;
    MojInt64 usageOut;
    MojDbKind* kind = NULL;
    MojString owner;

    err = owner.assign("");
    MojErrCheck(err);

    if(m_db->kindEngine()->isExist(kindId.data(), kind))
        owner = kind->owner();

    if((kind == NULL) || owner.empty())
        return MojErrNone;

    //ignore if quota not exist
    QuotaMap::ConstIterator iter = m_quotas.find(owner.data());
    if (iter == m_quotas.end())
        return MojErrNone;

    err = quotaUsage(owner.data(), sizeOut, usageOut);
    MojErrCheck(err);
    err = m_db->getQuotaAlert().notifySubscriber(owner.data(), usageOut, sizeOut);
    MojErrCheck(err);

    return MojErrNone;
}
Ejemplo n.º 3
0
MojErr  OnEnabledHandler::getAccountInfoResult(MojObject& payload, MojErr resultErr)
{
	MojLogTrace(IMServiceApp::s_log);
	IMServiceHandler::logMojObjectJsonString(_T("OnEnabledHandler::getAccountInfoResult payload: %s"), payload);

	if (resultErr != MojErrNone) {
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler getAccountInfo result error %d"), resultErr);
		return resultErr;
	}

	MojObject result;
	MojErr err = payload.getRequired("result", result);
	if (err != MojErrNone || result.empty()) {
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult result empty or error %d"), err);
		return err;
	}

	MojString accountId;
	err = result.getRequired("_id", accountId);
	if (err != MojErrNone || accountId.empty()) {
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult accountId empty or error %d"), err);
		return err;
	}

	MojString username;
	err = result.getRequired("username", username);
	if (err != MojErrNone || username.empty()) {
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult username empty or error %d"), err);
		return err;
	}

	MojString serviceName;
	getServiceNameFromCapabilityId(serviceName);
	if (serviceName.empty()) {
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler::getAccountInfoResult serviceName empty"));
		return err;
	}

	if (m_enable) {
		err = accountEnabled(accountId, serviceName, username);
	} else {
		err = accountDisabled(accountId, serviceName, username);
	}

	return err;
}
Ejemplo n.º 4
0
MojErr MojDbPutHandler::validateWildcard(const MojString& val, MojErr errToThrow)
{
    LOG_TRACE("Entering function %s", __FUNCTION__);

    if (val.empty())
        MojErrThrow(errToThrow);
    MojSize wildcardPos = val.find(_T('*'));
    if (wildcardPos != MojInvalidSize) {
        if (wildcardPos != val.length() - 1 ||
                (wildcardPos != 0 && val.at(wildcardPos - 1) != _T('.'))) {
            MojErrThrowMsg(errToThrow, _T("db: invalid wildcard in - '%s'"), val.data());
        }
    }
    return MojErrNone;
}
Ejemplo n.º 5
0
/*
 * Unformat the from address - removes blanks and converts to lower case
 *
 *  see IMAddressFormatter.unformat() - palm.com.messaging.data
 */
MojErr IMMessage::unformatFromAddress(const MojString formattedScreenName, MojString& unformattedName) {

	if(!formattedScreenName.empty()) {
		MojVector<MojString> stringTokens;
		MojErr err = formattedScreenName.split(' ', stringTokens);
		MojErrCheck(err);

		MojVector<MojString>::ConstIterator itr = stringTokens.begin();
		while (itr != stringTokens.end()) {
			err = unformattedName.append(*itr);
			MojErrCheck(err);
			itr++;
		}
		err = unformattedName.toLower();
		MojErrCheck(err);
	}
	return MojErrNone;
}
Ejemplo n.º 6
0
MojErr MojDb::dump(const MojChar* path, MojUInt32& countOut, bool incDel, MojDbReqRef req, bool backup,
		MojUInt32 maxBytes, const MojObject* incrementalKey, MojObject* backupResponse)
{
	MojAssert(path);
	MojLogTrace(s_log);

	MojErr err = beginReq(req);
	MojErrCheck(err);

	if (!req->admin()) {
		MojLogError(s_log, _T("access denied: '%s' cannot dump db to path: '%s'"), req->domain().data(), path);
		MojErrThrow(MojErrDbAccessDenied);
	}

	MojFile file;
	err = file.open(path, MOJ_O_WRONLY | MOJ_O_CREAT | MOJ_O_TRUNC, MOJ_S_IRUSR | MOJ_S_IWUSR);
	MojErrCheck(err);

	// write out kinds first, then existing objects, then deleted objects
	MojSize bytesWritten = 0;
	MojSize totalwarns = 0;
	MojSize newwarns = 0;
	MojDbQuery objQuery;
	MojVector<MojObject> kindVec;
	MojObject revParam = -1;
	MojObject delRevParam = -1;

	// if we were given an incremental key, pull out the revs now
	if (incrementalKey) {
		incrementalKey->get(MojDbServiceDefs::RevKey, revParam);
		incrementalKey->get(MojDbServiceDefs::DeletedRevKey, delRevParam);
	}

	err = m_kindEngine.getKinds(kindVec);
	MojErrCheck(err);

	// write kinds - if incremental, only write the kinds that have changed since the respective revs
	MojString countStr;
	for (MojVector<MojObject>::ConstIterator i = kindVec.begin(); i != kindVec.end(); ++i) {
		if (backup) {
			bool backupKind = false;
			i->get(MojDbKind::SyncKey, backupKind);
			if (!backupKind)
				continue;
			MojString id;
			err = i->getRequired(MojDbServiceDefs::IdKey, id);
			MojErrCheck(err);
			MojDbQuery countQuery;
			err = countQuery.from(id);
			MojErrCheck(err);
			MojDbCursor cursor;
			err = find(countQuery, cursor, req);
			MojErrCheck(err);
			MojUInt32 count = 0;
			err = cursor.count(count);
			MojErrCheck(err);
			if (count > 0) {
				if (i != kindVec.begin()) {
					err = countStr.appendFormat(_T(", "));
					MojErrCheck(err);
				}
				err = countStr.appendFormat("%s=%u", id.data(), count);
				MojErrCheck(err);
			}
		}
		bool deleted = false;
		i->get(DelKey, deleted);
		MojObject kindRev;
		err = i->getRequired(RevKey, kindRev);
		MojErrCheck(err);
		if ((deleted && kindRev > delRevParam) || (!deleted && kindRev > revParam)) {
			err = dumpObj(file, (*i), bytesWritten, maxBytes);
			MojErrCheck(err);
			countOut++;
		}
	}

	// dump all the non-deleted objects
	err = dumpImpl(file, backup, false, revParam, delRevParam, true, countOut, req, backupResponse, MojDbServiceDefs::RevKey, bytesWritten, newwarns, maxBytes);
	MojErrCheck(err);
	totalwarns += newwarns;
	// If we're supposed to include deleted objects, dump the deleted objects now.
	// There's a chance that we may have run out of space in our backup.  If that's the case,
	// we don't want to try to dump deleted objects - we can detect this by looking for the HasMoreKey
	if (incDel && backupResponse && !backupResponse->contains(MojDbServiceDefs::HasMoreKey)) {
		err = dumpImpl(file, backup, true, revParam, delRevParam, false, countOut, req, backupResponse, MojDbServiceDefs::DeletedRevKey, bytesWritten, newwarns, maxBytes);
		MojErrCheck(err);
	}
	totalwarns += newwarns;

	// Add the Full and Version keys
	if (backup && backupResponse) {
		bool incremental = (incrementalKey != NULL);
		err = backupResponse->putBool(MojDbServiceDefs::FullKey, !incremental);
		MojErrCheck(err);
		err = backupResponse->put(MojDbServiceDefs::VersionKey, DatabaseVersion);
		MojErrCheck(err);
		err = backupResponse->put(MojDbServiceDefs::WarningsKey, (MojInt32)totalwarns);
		MojErrCheck(err);
		MojString description;
		err = description.format(_T("incremental=%u"), countOut);
		MojErrCheck(err);
		if (!countStr.empty()) {
			err = description.appendFormat(_T(", %s"), countStr.data());
			MojErrCheck(err);
		}
		err = backupResponse->put(_T("description"), description);
		MojErrCheck(err);
	}

	err = req->end();
	MojErrCheck(err);

	return MojErrNone;
}