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;
}
Exemple #2
0
// This defines a new cache type and will cause a new CFileCache
// object to be instantiated.  The typeName must be unique.  The sum
// of the cache loWatermarks must be less than the total cache space
// available or the cache type creation will fail.
bool
CFileCacheSet::DefineType(std::string& msgText, const std::string& typeName,
                          CCacheParamValues* params, bool dirType) {

  MojLogTrace(s_log);

  msgText = "DefineType: ";
  bool retVal = false;
  CFileCache* fileCache = GetFileCacheForType(typeName);
  if (fileCache == NULL) {
    CFileCache* newType = new CFileCache(this, typeName);
    if (newType != NULL) {
      if (newType->Configure(params, dirType)) {
        m_cacheSet.insert(std::map<const std::string,
			  CFileCache*>::value_type(typeName, newType));
        retVal = true;
        msgText += "Created type '" + typeName + "'.";
        MojLogInfo(s_log, _T("%s"), msgText.c_str());
      } else {
        delete newType;
        msgText += "Failed to configure '" + typeName + "'.";
        MojLogError(s_log, _T("%s"), msgText.c_str());
      }
    } else {
      msgText += "Failed to allocate '" + typeName + "'.";
      MojLogCritical(s_log, _T("%s"),msgText.c_str());
    }
  } else {
    msgText += "Type '" + typeName + "'" + " already exists.";
    MojLogWarning(s_log, _T("%s"), msgText.c_str());
  }

  return retVal;
}
MojErr OnEnabledHandler::deleteImBuddyStatusResult(MojObject& payload, MojErr err)
{
	MojLogTrace(IMServiceApp::s_log);
	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogCritical(IMServiceApp::s_log, _T("deleteImBuddyStatusResult failed: error %d - %s"), err, error.data());
	}
	return err;
}
MojErr
TestCategoryHandler::Leak(MojServiceMessage *msg, MojObject &payload)
{
	ACTIVITY_SERVICEMETHOD_BEGIN();

	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Leak: %s"), MojoObjectJson(payload).c_str());

	MojErr err = MojErrNone;

	bool freeAll = false;

	payload.get(_T("freeAll"), freeAll);

	if (freeAll) {
		MojLogCritical(s_log, _T("RELEASING REFERENCES TO ALL INTENTIONALLY "
			"LEAKED ACTIVITIES"));
		while (!m_leakedActivities.empty()) {
			boost::shared_ptr<Activity> act = m_leakedActivities.front();
			m_leakedActivities.pop_front();

			MojLogCritical(s_log, _T("RELEASING REFERENCE TO [Activity %llu]"),
				act->GetId());
		}
	} else {
		boost::shared_ptr<Activity> act;

		err = LookupActivity(msg, payload, act);
		MojErrCheck(err);

		MojLogCritical(s_log, _T("INTENTIONALLY LEAKING [Activity %llu]!!"),
			act->GetId());

		m_leakedActivities.push_back(act);
	}

	err = msg->replySuccess();
	MojErrCheck(err);

	ACTIVITY_SERVICEMETHOD_END(msg);

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

	if (err != MojErrNone) {
		MojString error;
		MojErrToString(err, error);
		MojLogCritical(IMServiceApp::s_log, _T("addLoginStateResult failed: error %d - %s"), err, error.data());
		//TODO retry adding the record. Not worrying about this for now because the add would only fail in
		// extreme conditions.
	}
	return err;
}
MojErr
DevelCategoryHandler::Run(MojServiceMessage *msg, MojObject &payload)
{
	ACTIVITY_SERVICEMETHOD_BEGIN();

	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Run: %s"), MojoObjectJson(payload).c_str());

	MojErr err = MojErrNone;

	bool runAll = false;

	payload.get(_T("runAll"), runAll);

	if (runAll) {
		MojLogCritical(s_log, _T("EVICTING ALL ACTIVITIES FROM BACKGROUND "
			"QUEUE"));
		m_am->RunAllReadyActivities();
	} else {
		boost::shared_ptr<Activity> act;

		err = LookupActivity(msg, payload, act);
		MojErrCheck(err);

		MojLogCritical(s_log, _T("EVICTING [Activity %llu] FROM BACKGROUND "
			"QUEUE"), act->GetId());

		m_am->RunReadyBackgroundActivity(act);
	}

	err = msg->replySuccess();
	MojErrCheck(err);

	ACTIVITY_SERVICEMETHOD_END(msg);

	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;
}
Exemple #8
0
void PopSession::CheckQueue()
{
	MojLogDebug(m_log, "PopSession: Checking the queue. Current state: %d", m_state);

	switch(m_state)
	{
		case State_None:
		{
			MojLogCritical(m_log, "unable to run commands, no account available");
			break;
		}
		case State_NeedsConnection:
		{
			MojLogInfo(m_log, "State: NeedsConnection");
			MojRefCountedPtr<ConnectCommand> command(new ConnectCommand(*this));
			m_commandManager->RunCommand(command);
			m_state = State_Connecting;
			m_canShutdown = false;

			break;
		}
		case State_Connecting:
		{
			MojLogInfo(m_log, "State: Connecting");
			break;
		}
		case State_CheckTlsSupport:
		{
			MojLogInfo(m_log, "State: CheckTlsSupport");
			MojRefCountedPtr<CheckTlsCommand> command(new CheckTlsCommand(*this));
			m_commandManager->RunCommand(command);
			m_state = State_PendingTlsSupport;

			break;
		}
		case State_NegotiateTlsConnection:
		{
			MojLogInfo(m_log, "State: NegotiateTlsConnect");
			MojRefCountedPtr<NegotiateTlsCommand> command(new NegotiateTlsCommand(*this));
			m_commandManager->RunCommand(command);
			m_state = State_PendingTlsNegotiation;

			break;
		}
		case State_UsernameRequired:
		{
			MojLogInfo(m_log, "State: UsernameRequired");
			MojRefCountedPtr<UserCommand> command(new UserCommand(*this, m_account->GetUsername()));
			m_commandManager->RunCommand(command);
			m_state = State_PendingLogin;

			break;
		}
		case State_PasswordRequired:
		{
			MojLogInfo(m_log, "State: PasswordRequired");
			MojRefCountedPtr<PasswordCommand> command(new PasswordCommand(*this, m_account->GetPassword()));
			m_commandManager->RunCommand(command);
			m_state = State_PendingLogin;

			break;
		}
		case State_PendingLogin:
		{
			break;
		}
		case State_NeedUidMap:
		{
			MojLogInfo(m_log, "State: NeedUidMap");
			MojRefCountedPtr<CreateUidMapCommand> command(new CreateUidMapCommand(*this, m_uidMap));
			m_commandManager->RunCommand(command);
			m_state = State_GettingUidMap;

			break;
		}
		case State_GettingUidMap:
		{
			MojLogInfo(m_log, "State: GettingUidMap");
			break;
		}
		case State_OkToSync:
		{
			MojLogInfo(m_log, "State: OkToSync");
			MojLogInfo(m_log, "%i command(s) to run in queue", m_commandManager->GetPendingCommandCount());
			m_commandManager->Resume();
			RunCommandsInQueue();

			break;
		}
		case State_CancelPendingCommands:
		{
			MojLogInfo(m_log, "State: CancelPendingCommands");
			CancelCommands();

			break;
		}
		case State_InvalidCredentials:
		{
			break;
		}
		case State_AccountDisabled:
		{
			MojLogInfo(m_log, "State: AccountDisabled");
			CancelCommands();

			break;
		}
		case State_AccountDeleted:
		{
			break;
		}
		case State_LogOut:
		{
			MojLogInfo(m_log, "State: LogOut");
			LogOut();

			break;
		}
		case State_LoggingOut:
		{
			break;
		}
		default:
		{

		}
	}
}