Exemplo n.º 1
0
/**
 * Return MojObject formated to save to MojDb
 * Used for incoming messages
 */
MojErr IMMessage::createDBObject(MojObject& returnObj) {

	MojLogInfo(IMServiceApp::s_log, _T("createMojObject"));

	// Communications kind
	// From/to address is itself a CommunicationsAddress object
	// "name" and "type" properties are optional
	// Sender
	MojObject addressObj;
	MojErr err = addressObj.putString(MOJDB_ADDRESS, fromAddress);
	MojErrCheck(err);
	err = returnObj.put(MOJDB_FROM, addressObj);
	MojErrCheck(err);

	// Recipient
	MojObject recipientArray, recipient;
	err = recipient.put(MOJDB_ADDRESS, toAddress);
	MojErrCheck(err);
	err = recipientArray.push(recipient);
	MojErrCheck(err);
	err = returnObj.put(MOJDB_TO, recipientArray);
	MojErrCheck(err);

	// Message kind
	err = returnObj.putString(MOJDB_FOLDER, folderStrings[folder]);
	MojErrCheck(err);
	err = returnObj.putString(MOJDB_STATUS, statusStrings[status]);
	MojErrCheck(err);

	err = returnObj.putString(MOJDB_MSG_TEXT, msgText);
	MojErrCheck(err);

	// username - since this is incoming message, the username is always in toAddress
	err = returnObj.putString(MOJDB_USERNAME, toAddress);
	MojErrCheck(err);

	// service name
	err = returnObj.putString(MOJDB_SERVICENAME, msgType);
	MojErrCheck(err);

	// localTimestamp
	err = returnObj.putInt(MOJDB_DEVICE_TIMESTAMP, deviceTimestamp);
	MojErrCheck(err);

	// incoming server
	err = returnObj.putInt(MOJDB_SERVER_TIMESTAMP, serverTimestamp);
	MojErrCheck(err);

	IMServiceHandler::privatelogIMMessage(_T("DB Message object %s:"), returnObj, MOJDB_MSG_TEXT);

	return err;
}
Exemplo n.º 2
0
MojErr MojDbQuotaTest::testEnforce(MojDb& db)
{
	// set quota size to current usage
	MojInt64 quotaUsage1 = 0;
	MojErr err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
	MojTestErrCheck(err);
	MojObject obj;
	err = obj.putString(_T("owner"), _T("com.foo.bar"));
	MojErrCheck(err);
	err = obj.putInt(_T("size"), quotaUsage1);
	MojErrCheck(err);
	err = db.putQuotas(&obj, &obj + 1);
	MojErrCheck(err);
	err = put(db, MojTestKind1Objects[3]);
	MojTestErrExpected(err, MojErrDbQuotaExceeded);
	// Try to delete the kind
	MojString kindStr;
	err = kindStr.assign(_T("Test:1"));
	MojTestErrCheck(err);
	bool found = false;
	err = db.delKind(kindStr, found);

    //The delete should be failure, because it contain sub kind "Test2:1"
    MojTestErrExpected(err,MojErrDbKindHasSubKinds); 
    MojTestAssert(!found); 

	return MojErrNone;
}
Exemplo n.º 3
0
void BusClient::ScheduleShutdown()
{
	MojLogTrace(m_log);
	// Reply to the "run" message now that we're done
	if (m_launchedAsService && m_msg.get()) {
		const Configurator::ConfigCollection& ok = Configurator::ConfigureOk();
		const Configurator::ConfigCollection& failed = Configurator::ConfigureFailure();

		if (m_wrongAplication) {
			MojString response;
			response.appendFormat("Aplication or service doesn't exist");
			m_wrongAplication = false;
			m_msg->replyError(MojErrInternal, response.data());

		} else if (!failed.empty()) {
			MojString response;
			response.appendFormat("Partial configuration - %zu ok, %zu failed", ok.size(), failed.size());
			m_msg->replyError(MojErrInternal, response.data());
		} else {
			MojObject response;
			response.putInt("configured", ok.size());
			m_msg->replySuccess(response);
		}
		m_msg.reset();
	}

	if (!m_pending.empty()) {
		MojLogDebug(m_log, "%d pending service calls to handle remaining", m_pending.size());

		// still more pending work
		m_configuratorsCompleted = 0;
		m_configurators.clear();
		Configurator::ResetConfigStats();

		const PendingWork &pending = m_pending.back();
		(pending.instance->*(pending.callback))(pending.msg.get(), pending.payload);

		m_pending.pop_back();
		return;
	}

	MojLogDebug(m_log, "No more pending service calls to handle - scheduling shutdown");

	// Schedule an event to shutdown once the stack is unwound.
	if (m_timerTimeout == 0) {
		// this is to work around around a race condition where the LSCall is delivered
		// after we shutdown causing us to start back up - give some time for the LSCall
		// to get delivered.  NOV-114626.  This needs a proper fix within ls2 (can't be
		// worked around anywhere else).
		m_timerTimeout = g_timeout_add_full(G_PRIORITY_DEFAULT_IDLE, /* timer priority */
		    500, /* timeout in ms */
		    &BusClient::ShutdownCallback, // callback
		    this, /* callback data */
		    NULL /*destroy notify callback*/
		);
	}
	//g_idle_add(&BusClient::ShutdownCallback, this);

	m_shuttingDown = true;
}
MojErr PowerdPowerActivity::CreateRemotePowerActivity(bool debounce)
{
	LOG_AM_TRACE("Entering function %s", __FUNCTION__);

	MojErr err;
	MojObject params;

	err = params.putString(_T("id"), GetRemotePowerActivityName().c_str());
	MojErrCheck(err);

	int duration;
	if (debounce) {
		duration = PowerActivityDebounceDuration * 1000;
	} else {
		duration = PowerActivityLockDuration * 1000;
	}

	err = params.putInt(_T("duration_ms"), duration);
	MojErrCheck(err);

	m_call = boost::make_shared<MojoWeakPtrCall<PowerdPowerActivity> >(
		boost::dynamic_pointer_cast<PowerdPowerActivity, PowerActivity>(
			shared_from_this()), debounce ?
		&PowerdPowerActivity::PowerUnlockedNotificationDebounce :
		&PowerdPowerActivity::PowerLockedNotification,
		m_service, "palm://com.palm.power/com/palm/power/activityStart",
		params);
	m_call->Call();

	return MojErrNone;
}
Exemplo n.º 5
0
MojErr MojDbQuotaTest::testEnforce(MojDb& db)
{
	// set quota size to current usage
	MojInt64 quotaUsage1 = 0;
	MojErr err = getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1);
	MojTestErrCheck(err);
	MojObject obj;
	err = obj.putString(_T("owner"), _T("com.foo.bar"));
	MojErrCheck(err);
	err = obj.putInt(_T("size"), quotaUsage1);
	MojErrCheck(err);
	err = db.putQuotas(&obj, &obj + 1);
	MojErrCheck(err);
	err = put(db, MojTestKind1Objects[3]);
	MojTestErrExpected(err, MojErrDbQuotaExceeded);
	// make sure we can delete the kind
	MojString kindStr;
	err = kindStr.assign(_T("Test:1"));
	MojTestErrCheck(err);
	bool found = false;
	err = db.delKind(kindStr, found);
	MojTestErrCheck(err);
	MojTestAssert(found);

	return MojErrNone;
}
Exemplo n.º 6
0
void SmtpValidator::Failure(MailError::ErrorCode errorCode, const std::string& errorText)
{
	if (m_timeoutId) {
		g_source_remove(m_timeoutId);
		m_timeoutId = 0;
	}

	MojLogInfo(m_log, "SmtpValidator %p Failure1", this);
	//MojLogInfo(m_log, "SmtpValidator %p Failure1, was trying to connect to %s:%d", this, m_account->GetHostname().c_str(), m_account->GetPort());
	
	MojLogTrace(m_log);

	MojObject reply;
	MojErr err = reply.putBool(MojServiceMessage::ReturnValueKey, false);
	ErrorToException(err);

	std::string accountErrorCode = MailError::GetAccountErrorCode(errorCode);

	err = reply.putString(MojServiceMessage::ErrorCodeKey, accountErrorCode.c_str());
	ErrorToException(err);

	err = reply.putInt("mailErrorCode", errorCode);
	ErrorToException(err);

	err = reply.putString("errorText", errorText.c_str());
	ErrorToException(err);

	if (!m_replied) {
		// if we already replied due to a timeout, don't reply again.
		err = m_msg->reply(reply);
		ErrorToException(err);
		
		m_replied = true;
	}
}
Exemplo n.º 7
0
TEST_F(QuotaTest, enforce)
{
    MojObject obj;

    // put quota
    MojAssertNoErr( obj.fromJson(_T("{\"owner\":\"com.foo.bar\",\"size\":1000}")) );
    MojAssertNoErr( db.putQuotas(&obj, &obj + 1) );

    // make kind2 inherit from kind1
    MojAssertNoErr( obj.fromJson(MojTestKind2Str3) );
    MojExpectNoErr( db.putKind(obj) );

    //// end of prerequisites form prev tests

    // set quota size to current usage
    MojInt64 quotaUsage1 = 0;
    EXPECT_NO_FATAL_FAILURE( getQuotaUsage(db, _T("com.foo.bar"), quotaUsage1) );
    MojAssertNoErr( obj.putString(_T("owner"), _T("com.foo.bar")) );
    MojAssertNoErr( obj.putInt(_T("size"), quotaUsage1) );
    MojExpectNoErr( db.putQuotas(&obj, &obj + 1) );

    MojAssertNoErr( obj.fromJson(MojTestKind1Objects[3]) );
    EXPECT_EQ( MojErrDbQuotaExceeded, db.put(obj) );

    // Try to delete the kind
    MojString kindStr;
    MojAssertNoErr( kindStr.assign(_T("Test:1")) );
    bool found = false;
    EXPECT_EQ( MojErrDbKindHasSubKinds, db.delKind(kindStr, found) )
        << "The delete should be failure, because it contain sub kind \"Test2:1\"";
    EXPECT_FALSE( found );
}
Exemplo n.º 8
0
void Command::Status(MojObject& status) const
{
	MojErr err;

	err = status.putString("class", GetClassName().c_str());
	ErrorToException(err);
	err = status.putInt("priority", m_priority);
	ErrorToException(err);
}
Exemplo n.º 9
0
void SmtpValidator::Status(MojObject& status) const
{
	char buf[64];
	memset(buf, '\0', sizeof(buf));
	snprintf(buf, sizeof(buf)-1, "%p", this);
	MojErr err = status.putString("pointer",buf);;
	ErrorToException(err);

	err = status.putBool("running", m_running);
	ErrorToException(err);
	
	err = status.putString("hostname", m_account->GetHostname().c_str());
	ErrorToException(err);

	err = status.putInt("port", m_account->GetPort());
	ErrorToException(err);

	err = status.putInt("encryption", m_account->GetEncryption());
	ErrorToException(err);
}
MojErr MojoDBPersistToken::ToJson(MojObject& rep) const
{
	MojErr err;

	if (!m_valid) {
		throw std::runtime_error("ID not set");
	}

	err = rep.putString(_T("_id"), m_id);
	MojErrCheck(err);

	err = rep.putInt(_T("_rev"), m_rev);
	MojErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 11
0
	MojErr formatErrResponse(MojErr errExpected, MojObject& objOut)
	{
		MojString errTxt;
		MojErr err = MojErrToString(errExpected, errTxt);
		MojTestErrCheck(err);

		// format expected error return
		err = objOut.putBool(MojServiceMessage::ReturnValueKey, false);
		MojErrCheck(err);
		err = objOut.putInt(MojServiceMessage::ErrorCodeKey, (MojInt64)errExpected);
		MojErrCheck(err);
		err = objOut.putString(MojServiceMessage::ErrorTextKey, errTxt);
		MojErrCheck(err);

		return MojErrNone;
	}
Exemplo n.º 12
0
MojErr MojDbPerfUpdateTest::mergeObj(MojDb& db, MojObject& obj, MojTime& objTime)
{
	MojTime startTime;
	MojTime endTime;

	for (MojUInt64 i = 0; i < numMergeIterations; i++) {
		MojErr err = MojGetCurrentTime(startTime);
		MojTestErrCheck(err);
		err = obj.putInt(_T("newProp"), i);
		MojTestErrCheck(err);
		err = db.merge(obj);
		MojTestErrCheck(err);
		err = MojGetCurrentTime(endTime);
		MojTestErrCheck(err);
		objTime += (endTime - startTime);
		totalTestTime += (endTime - startTime);
	}

	return MojErrNone;
}
Exemplo n.º 13
0
MojErr MojServiceMessage::replyError(MojErr code, const MojChar* text)
{
	MojAssert(code != MojErrNone && text);

	MojObject payload;
	MojErr err = payload.putBool(ReturnValueKey, false);
	MojErrCheck(err);
	err = payload.putInt(ErrorCodeKey, (MojInt64) code);
	MojErrCheck(err);
	err = payload.putString(ErrorTextKey, text);
	MojErrCheck(err);

	// reset the writer first, then reply with this payload
	err = writer().reset();
	MojErrCheck(err);
	err = reply(payload);
	MojErrCheck(err);

	return MojErrNone;
}
Exemplo n.º 14
0
/*
 * Enabling an IM account requires the following
 *     add com.palm.imloginstate.libpurple record
 */
MojErr OnEnabledHandler::accountEnabled(const MojString& accountId, const MojString& serviceName, const MojString& username)
{
	//TODO: first issue a merge in case the account already exists?
	MojLogTrace(IMServiceApp::s_log);
	MojLogInfo(IMServiceApp::s_log, _T("accountEnabled id=%s, serviceName=%s"), accountId.data(), serviceName.data());

	MojObject imLoginState;
	imLoginState.putString(_T("_kind"), IM_LOGINSTATE_KIND);
	imLoginState.put(_T("accountId"), accountId);
	imLoginState.put(_T("serviceName"), serviceName);
	imLoginState.put(_T("username"), username);
	imLoginState.putString(_T("state"), LOGIN_STATE_OFFLINE);
	imLoginState.putInt(_T("availability"), PalmAvailability::ONLINE); //default to online so we automatically login at first
	MojErr err = m_dbClient.put(m_addImLoginStateSlot, imLoginState);
	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogError(IMServiceApp::s_log, _T("OnEnabledHandler db.put() failed: error %d - %s"), err, error.data());
	}

	return err;
}
Exemplo n.º 15
0
// Copy fields from createAccount payload into com.palm.imap.account object
void ImapAccountAdapter::GetImapAccountFromPayload(const MojObject& accountObj, const MojObject& payload, MojObject& imapAccount)
{
	MojErr err = imapAccount.putString(ImapAccountAdapter::KIND, ImapAccountAdapter::SCHEMA);
	ErrorToException(err);

	MojObject accountId;
	err = payload.getRequired(ImapAccountAdapter::ACCOUNT_ID, accountId);
	ErrorToException(err);

	err = imapAccount.put(ImapAccountAdapter::ACCOUNT_ID, accountId);
	ErrorToException(err);

	MojObject config;
	err = payload.getRequired(ImapAccountAdapter::CONFIG, config);
	ErrorToException(err);

	MojString username;
	bool hasUsername = false;
	err = config.get(ImapAccountAdapter::USERNAME, username, hasUsername);
	ErrorToException(err);
	if(!hasUsername)
	{
		err = accountObj.getRequired(ImapAccountAdapter::USERNAME, username);
		ErrorToException(err);
	}
	err = imapAccount.put(ImapAccountAdapter::USERNAME, username);
	ErrorToException(err);

	MojString hostname;
	err = config.getRequired(ImapAccountAdapter::HOSTNAME, hostname);
	ErrorToException(err);

	err = imapAccount.put(ImapAccountAdapter::HOSTNAME, hostname);
	ErrorToException(err);

	int port;
	err = config.getRequired(ImapAccountAdapter::PORT, port);
	ErrorToException(err);

	err = imapAccount.put(ImapAccountAdapter::PORT, port);
	ErrorToException(err);

	MojString encryption;
	err = config.getRequired(ImapAccountAdapter::ENCRYPTION, encryption);
	ErrorToException(err);

	err = imapAccount.put(ImapAccountAdapter::ENCRYPTION, encryption);
	ErrorToException(err);

	/* Optional config parameters; fill in with defaults if not provided */

	bool hasSyncFrequency = false;
	int syncFrequencyMins = 0;
	config.get(EmailAccountAdapter::SYNC_FREQUENCY_MINS, syncFrequencyMins, hasSyncFrequency);
	ErrorToException(err);

	err = imapAccount.putInt(EmailAccountAdapter::SYNC_FREQUENCY_MINS,
			hasSyncFrequency ? syncFrequencyMins : DEFAULT_SYNC_FREQUENCY_MINS);
	ErrorToException(err);

	bool hasSyncWindow = false;
	int syncWindow = 0;
	err = config.get(EmailAccountAdapter::SYNC_WINDOW_DAYS, syncWindow, hasSyncWindow);
	ErrorToException(err);

	err = imapAccount.putInt(EmailAccountAdapter::SYNC_WINDOW_DAYS,
			hasSyncWindow ? syncWindow : DEFAULT_SYNC_WINDOW_DAYS);
	ErrorToException(err);
}
Exemplo n.º 16
0
MojErr MojDbIndexTest::defaultValuesTest()
{
	MojDbIndex index(NULL, NULL);
	MojRefCountedPtr<TestIndex> storageIndex(new TestIndex(false));
	MojAllocCheck(storageIndex.get());
	TestIndex& ti = *storageIndex;

	MojObject prop;
	MojErr err = prop.putString(MojDbIndex::NameKey, _T("foo"));
	MojTestErrCheck(err);
	err = prop.putInt(MojDbIndex::DefaultKey, 100);
	MojTestErrCheck(err);
	err = index.addProp(prop);
	MojTestErrCheck(err);
	MojDbReq req;
	err = index.open(storageIndex.get(), (MojInt64) 0, req);
	MojTestErrCheck(err);

	err = put(index, 1, _T("{\"bar\":1}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti.m_putCount == 1 && ti.m_delCount == 0 && ti.m_set.size() == 1);
	err = put(index, 1, _T("{\"foo\":5}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti.m_putCount == 2 && ti.m_delCount == 0 && ti.m_set.size() == 2);
	err = put(index, 1, _T("{\"foo\":{\"bar\":3}}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti.m_putCount == 3 && ti.m_delCount == 0 && ti.m_set.size() == 3);

	err = index.close();
	MojTestErrCheck(err);

	MojDbIndex index2(NULL, NULL);
	MojRefCountedPtr<TestIndex> storageIndex2(new TestIndex(false));
	MojAllocCheck(storageIndex2.get());
	TestIndex& ti2 = *storageIndex2;

	MojObject prop2;
	err = prop2.putString(MojDbIndex::NameKey, _T("bar"));
	MojTestErrCheck(err);
	err = index2.addProp(prop2);
	MojTestErrCheck(err);
	err = index2.open(storageIndex2.get(), (MojInt64) 0, req);
	MojTestErrCheck(err);

	err = put(index2, 1, _T("{\"bar\":1}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1);
	err = put(index2, 1, _T("{\"foo\":5}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1);
	err = put(index2, 1, _T("{\"foo\":{\"bar\":3}}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti2.m_putCount == 1 && ti2.m_delCount == 0 && ti2.m_set.size() == 1);

	err = index2.close();
	MojTestErrCheck(err);

	MojDbIndex index3(NULL, NULL);
	MojRefCountedPtr<TestIndex> storageIndex3(new TestIndex(false));
	MojAllocCheck(storageIndex3.get());
	TestIndex& ti3 = *storageIndex3;

	MojObject prop3;
	err = prop3.putString(MojDbIndex::NameKey, _T("bar"));
	MojTestErrCheck(err);
	err = index3.addProp(prop3);
	MojTestErrCheck(err);
	err = prop3.putString(MojDbIndex::NameKey, _T("foo"));
	MojTestErrCheck(err);
	err = prop3.putInt(MojDbIndex::DefaultKey, 100);
	MojTestErrCheck(err);
	err = index3.addProp(prop3);
	MojTestErrCheck(err);
	err = index3.open(storageIndex3.get(), (MojInt64) 0, req);
	MojTestErrCheck(err);

	err = put(index3, 1, _T("{\"bar\":1}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1);
	err = put(index3, 1, _T("{\"foo\":5}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1);
	err = put(index3, 1, _T("{\"foo\":{\"bar\":3}}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti3.m_putCount == 1 && ti3.m_delCount == 0 && ti3.m_set.size() == 1);
	err = put(index3, 1, _T("{\"foo\":5, \"bar\":5}"), NULL);
	MojTestErrCheck(err);
	MojTestAssert(ti3.m_putCount == 2 && ti3.m_delCount == 0 && ti3.m_set.size() == 2);

	err = index3.close();
	MojTestErrCheck(err);

	return MojErrNone;
}
MojErr OnEnabledHandler::findImLoginStateResult(MojObject& payload, MojErr err)
{
	MojLogTrace(IMServiceApp::s_log);

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

		// check to see if array is empty - normally it will be if this is a newly created account. There should never be more than 1 item here
		if (!results.empty()){

			IMServiceHandler::logMojObjectJsonString(_T("findImLoginStateResult found existing imLoginState record: %s"), payload);

			// if there is a record already, make sure the account id matches.
			MojObject loginState;
			MojObject::ConstArrayIterator itr = results.arrayBegin();
			bool foundOne = false;
			while (itr != results.arrayEnd()) {
				if (foundOne) {
					MojLogError(IMServiceApp::s_log,
							_T("findImLoginStateResult: found more than one ImLoginState with same username/serviceName - using the first one"));
					break;
				}
				loginState = *itr;
				foundOne = true;
				itr++;
			}

			MojString accountId;
			MojErr err = loginState.getRequired("accountId", accountId);
			if (err) {
				MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: missing accountId in loginState entry"));
			}
			if (0 != accountId.compare(m_accountId)) {
				MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: existing loginState record does not have matching account id. accountId = %s"), accountId.data());

				// delete this record
				MojObject idsToDelete;
				MojString dbId;
				err = loginState.getRequired("_id", dbId);
				if (err) {
					MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: missing dbId in loginState entry"));
				}
				else {
				    idsToDelete.push(dbId);

					// luna://com.palm.db/del '{"ids":[2]}'
					MojLogInfo(IMServiceApp::s_log, _T("findImLoginStateResult: deleting loginState entry id: %s"), dbId.data());
					err = m_dbClient.del(this->m_deleteImLoginStateSlot, idsToDelete.arrayBegin(), idsToDelete.arrayEnd());
					if (err != MojErrNone) {
						MojString error;
						MojErrToString(err, error);
						MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: db.del() failed: error %d - %s"), err, error.data());
					}
				}
			}
			// if the account id matches, leave the old record and we are done
			else return MojErrNone;
		}

		// no existing record found or the old one was deleted - create a new one
		MojLogInfo(IMServiceApp::s_log, _T("findImLoginStateResult: no matching loginState record found for %s, %s. creating a new one"), m_username.data(), m_serviceName.data());
		MojObject imLoginState;
		imLoginState.putString(_T("_kind"), IM_LOGINSTATE_KIND);
		imLoginState.put(_T("accountId"), m_accountId);
		imLoginState.put(_T("serviceName"), m_serviceName);
		imLoginState.put(_T("username"), m_username);
        imLoginState.put(_T("capabilityId"), m_capabilityProviderId);
		imLoginState.putString(_T("state"), LOGIN_STATE_OFFLINE);
		imLoginState.putInt(_T("availability"), PalmAvailability::ONLINE); //default to online so we automatically login at first
        imLoginState.put(_T("config"), m_config);
		MojErr err = m_dbClient.put(m_addImLoginStateSlot, imLoginState);
		if (err != MojErrNone) {
			MojString error;
			MojErrToString(err, error);
			MojLogError(IMServiceApp::s_log, _T("findImLoginStateResult: db.put() failed: error %d - %s"), err, error.data());
		}

	}
	return err;
}
Exemplo n.º 18
0
void PopAccountAdapter::SerializeToDatabasePopObject(const PopAccount& accnt, MojObject& obj)
{
    MojErr err;
    // Set the object kind
    err = obj.putString(KIND, POP_ACCOUNT_KIND);
    ErrorToException(err);

    // Set ID
    err = obj.put(ID, accnt.GetId());
    ErrorToException(err);

    // Set account ID
    err = obj.put(ACCOUNT_ID, accnt.GetAccountId());
    ErrorToException(err);

    // Set host name
    err = obj.putString(HOST_NAME, accnt.GetHostName().c_str());
    ErrorToException(err);

    // Set port
    err = obj.putInt(PORT, accnt.GetPort());
    ErrorToException(err);

    // Set encryption
    err = obj.putString(ENCRYPTION, accnt.GetEncryption().c_str());
    ErrorToException(err);

    // Set user name
    err = obj.putString(USERNAME, accnt.GetUsername().c_str());
    ErrorToException(err);

    // Set 'initialSynced' flag
    err = obj.putBool(INITIAL_SYNC, accnt.IsInitialSync());
    ErrorToException(err);

    // Set 'deleteFromServer' flag
    err = obj.putBool(DELETE_FROM_SERVER, accnt.IsDeleteFromServer());
    ErrorToException(err);

    // Set 'deleteOnDevice' flag
    err = obj.putBool(DELETE_ON_DEVICE, accnt.IsDeleteOnDevice());
    ErrorToException(err);

    // Set sync window
    err = obj.putInt(EmailAccountAdapter::SYNC_WINDOW_DAYS, accnt.GetSyncWindowDays());
    ErrorToException(err);

    // Set sync frequency
    err = obj.putInt(SYNC_FREQUENCY_MINS, accnt.GetSyncFrequencyMins());
    ErrorToException(err);

    if (accnt.IsError()) {
        MojObject mojErr;
        err = mojErr.putInt(EmailAccountAdapter::ERROR_CODE, (int)accnt.GetError().errorCode);
        ErrorToException(err);

        err = mojErr.putString(EmailAccountAdapter::ERROR_TEXT, accnt.GetError().errorText.c_str());
        ErrorToException(err);

        err = obj.put(EmailAccountAdapter::ERROR, mojErr);
        ErrorToException(err);
    } else {
        err = obj.put(EmailAccountAdapter::ERROR, MojObject::Null);
    }

    SerializeSpecialFolders(accnt, obj);
}
Exemplo n.º 19
0
void PopAccountAdapter::GetPopAccountFromPayload(MojLogger& log, const MojObject& payload, MojObject& popAccount)
{
    MojErr err = popAccount.putString(KIND, POP_ACCOUNT_KIND);
    ErrorToException(err);

    MojObject accountId;
    err = payload.getRequired(ACCOUNT_ID, accountId);
    ErrorToException(err);
    err = popAccount.put(ACCOUNT_ID, accountId);
    ErrorToException(err);

    MojObject config;
    err = payload.getRequired(CONFIG, config);
    ErrorToException(err);

    MojObject hostname;
    err = config.getRequired(HOST_NAME, hostname);
    ErrorToException(err);
    err = popAccount.put(HOST_NAME, hostname);
    ErrorToException(err);

    MojObject port;
    err = config.getRequired(PORT, port);
    ErrorToException(err);
    err = popAccount.put(PORT, port);
    ErrorToException(err);

    MojObject encryption;
    err = config.getRequired(ENCRYPTION, encryption);
    ErrorToException(err);
    err = popAccount.put(ENCRYPTION, encryption);
    ErrorToException(err);

    MojObject username;
    err = config.getRequired(USERNAME, username);
    ErrorToException(err);
    err = popAccount.put(USERNAME, username);
    ErrorToException(err);

    // Set 'deleteFromServer' flag
    bool deleteFromServer = true;
    if (!config.get(DELETE_FROM_SERVER, deleteFromServer)) {
        // default value is true if this field doesn't exist
        deleteFromServer = true;
    }
    err = popAccount.putBool(DELETE_FROM_SERVER, deleteFromServer);
    ErrorToException(err);

    // Set 'deleteOnDevice' flag
    bool deleteOnDevice = false;
    if (!config.get(DELETE_ON_DEVICE, deleteOnDevice)) {
        // defaul value is false if this field doesn't exist
        deleteOnDevice = false;
    }
    err = popAccount.putBool(DELETE_ON_DEVICE, deleteOnDevice);
    ErrorToException(err);

    // Set sync window
    MojInt64 syncWindow;
    if (!config.get(EmailAccountAdapter::SYNC_WINDOW_DAYS, syncWindow)) {
        // set default value if this field doesn't exist
        syncWindow = PopAccount::DEFAULT_SYNC_WINDOW;
    }
    err = popAccount.putInt(EmailAccountAdapter::SYNC_WINDOW_DAYS, syncWindow);
    ErrorToException(err);

    // Set sync frequency
    MojInt64 syncFreq;
    if (!config.get(SYNC_FREQUENCY_MINS, syncFreq)) {
        syncFreq = PopAccount::DEFAULT_SYNC_FREQUENCY_MINS;
    }
    err = popAccount.putInt(SYNC_FREQUENCY_MINS, syncFreq);
    ErrorToException(err);
}
Exemplo n.º 20
0
    MojObject getProtocolOptions(MojString prpl)
    {
        MojObject result;

        PurplePluginProtocolInfo* info = getProtocolInfo(prpl.data());

        for(GList* l = info->protocol_options; l != NULL; l = l->next)
        {
            PurpleAccountOption* option = (PurpleAccountOption*)l->data;

            MojObject node;
            MojObject choices;

            node.putString("text", purple_account_option_get_text(option));

            switch(purple_account_option_get_type(option))
            {
            case PURPLE_PREF_BOOLEAN:
                node.putString("type", "bool");
                node.putBool("default_value",
                    purple_account_option_get_default_bool(option)
                    );
                break;

            case PURPLE_PREF_INT:
                node.putString("type", "int");
                node.putInt("default_value",
                    purple_account_option_get_default_int(option)
                    );
                break;

            case PURPLE_PREF_STRING:
                node.putString("type", "string");
                {
                    const char* def
                        = purple_account_option_get_default_string(option);
                    node.putString("default_value", def ? def : "");
                }
                break;

            case PURPLE_PREF_STRING_LIST:
                node.putString("type", "list");
                {
                    MojObject choices;

                    for (GList* list = purple_account_option_get_list(option);
                         list != NULL; list = list->next)
                    {
                        PurpleKeyValuePair* kvp = (PurpleKeyValuePair*)list->data;
                        // XXX: Dangerous!
                        if (kvp->key && kvp->value)
                            choices.putString((const char*)kvp->value,
                                              (const char*)kvp->key);
                    }
                    node.put("choices", choices);

                    const char* def
                        = purple_account_option_get_default_list_value(option);
                    node.putString("default_value", def ? def : "");
                }
                break;

            default:
                continue;
            };

            result.put(purple_account_option_get_setting(option), node);
        }

        return result;
    }