コード例 #1
0
void AuthYahooCommand::RunImpl()
{
	MojLogTrace(m_log);
	// HACK: Hard-code partner ID and fetch of NDUID
	m_partnerId.assign("mblclt11");
	
	char id[256];
	memset(id, '\0', 256);
	
	// Read nduid, if available, otherwise make a fake one and try to record it.
	FILE * nduid = fopen("/proc/nduid", "r");
	if (!nduid) {
		nduid = fopen("yahooCachedFakeDeviceId", "r");
		if (!nduid) {
			snprintf(id, 255, "FEED0BEEF479121481533145%016llX", timeMillis());
			nduid = fopen("yahooCachedFakeDeviceId", "w");
			if (nduid) {
				fputs(id, nduid);
				fclose(nduid);
				nduid = NULL;
			}
		}
	}
	
	if (nduid) {
		if (fgets(id, 255, nduid) == NULL)
			id[0] = '\0';
		
		fclose(nduid);
		nduid = NULL;

		if (strlen(id) > 0 && id[strlen(id)-1] == '\n')
			id[strlen(id)-1] = '\0';
	}
	
	m_deviceId.assign(id);

	MojLogInfo(m_log, "Temp: partnerId=%s deviceId=%s", m_partnerId.data(), m_deviceId.data());

	MojObject accountId = m_session.GetAccount()->GetAccountId();

	MojObject params;
	MojErr err = params.put("accountId", accountId);
	ErrorToException(err);

	MojString token;
	token.assign(m_session.GetAccount()->GetYahooToken().c_str());
	err = params.put("securityToken", token);
	ErrorToException(err);

	MojLogInfo(m_log, "Looking up yahoo cookies for account %s", AsJsonString(accountId).c_str());
	// TODO: Should send the request with SmtpClient instead.
	err = m_session.CreateRequest()->send(m_getYahooCookiesSlot, "com.palm.yahoo","fetchcookies", params);
	ErrorToException(err);
}
コード例 #2
0
bool MojoSimpleMatcher::Match(const MojObject& response)
{
	if (!m_setupComplete) {
		MojLogInfo(s_log, _T("Simple Matcher: Setup successfully"));
		m_setupComplete = true;
		return false;
	} else {
		MojLogInfo(s_log, _T("Simple Matcher: Matched"));
		return true;
	}
}
コード例 #3
0
void ActivityManager::InteractiveYieldTimeout()
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Background interactive yield timeout triggered"));

	if (m_runQueue[RunQueueReadyInteractive].empty()) {
		MojLogInfo(s_log, _T("Ready interactive queue is empty, cancelling "
			"yield timeout"));
		CancelYieldTimeout();
		return;
	}

	/* XXX make 1 more Activity yield, but only if there are fewer Activities
	 * yielding than waiting in the interactive queue. */
	unsigned waiting = (unsigned) m_runQueue[RunQueueReadyInteractive].size();
	unsigned yielding = 0;

	boost::shared_ptr<Activity> victim;

	ActivityRunQueue::iterator iter;

	for (iter = m_runQueue[RunQueueBackgroundInteractive].begin();
		iter != m_runQueue[RunQueueBackgroundInteractive].end(); ++iter) {
		if (iter->IsYielding()) {
			if (++yielding >= waiting) {
				break;
			}
		} else {
			if (!victim) {
				victim = iter->shared_from_this();
			}
		}
	}

	/* If there aren't already too many yielding... */
	if (iter == m_runQueue[RunQueueBackgroundInteractive].end()) {
		if (victim) {
			MojLogInfo(s_log, _T("Requesting that [Activity %llu] yield"),
				victim->GetId());
			victim->YieldActivity();
		} else {
			MojLogInfo(s_log, _T("All running background interactive "
				"Activities are already yielding"));
		}
	} else {
		MojLogInfo(s_log, _T("Number of yielding Activities is already equal "
			"to the number of ready interactive Activities waiting in the "
			"queue"));
	}

	UpdateYieldTimeout();
}
コード例 #4
0
void SyncFolderCommand::SyncFolder()
{
	PopClient::AccountPtr account = m_client.GetAccount();
	MojLogInfo(m_log, "inbox=%s, syncing folder=%s, force=%d",
				AsJsonString(account->GetInboxFolderId()).c_str(),
				AsJsonString(m_folderId).c_str(),
				m_force);
	if (m_folderId != account->GetInboxFolderId()) {
		// POP transport only supports inbox sync.
		MojLogInfo(m_log, "POP transport will skip non-inbox syncing");
		Complete();
		return;
	}

	SyncSessionPtr sSession = m_client.GetOrCreateSyncSession(m_folderId);
	m_activity = ActivityParser::GetActivityFromPayload(m_payload);
	if (!sSession->IsActive() && !sSession->IsEnding()) {
		// since sync session is not running, we can start the folder sync
		MojLogDebug(m_log, "Sync session is not active");
		StartFolderSync(m_activity);

		Complete();
	} else {
		if (m_force) {
			// Manual Sync and session is either active or ending

			// TODO: sync session is in progress, need to terminate the current
			// sync session first.  Then re-start sync session.
			StartFolderSync(m_activity);

			Complete();
		} else {
			// This is either auto sync, schedule sync, retry sync.
			if (sSession->IsActive()) {

				if (m_activity.get()) {
					MojLogInfo(m_log, "Attach sync activity to actively syncing session");

					// Adopt activity and then add it to sync session
					m_activity->Adopt(m_client);
					sSession->AttachActivity(m_activity);
				}

				Complete();
			} else if (sSession->IsEnding()) {
				// wait for sync session to end and then start folder sync
				MojLogInfo(m_log, "Waiting for ending sync session to complete");
				sSession->WaitForSessionComplete(m_syncSessionCompletedSlot);
			}
		}
	}
}
コード例 #5
0
/*
 * Send the messages off to libpurple transport
 */
MojErr SendOneMessageHandler::sendToTransport()
{
	MojErr err = MojErrNone;

	// can't log message text in production
	MojLogInfo (IMServiceApp::s_log, "sending message to transport. id: %s, serviceName: %s, username: %s, usernameTo: %s",
			m_currentMsgdbId.data(), m_serviceName.data(), m_username.data(), m_usernameTo.data());

	// Note, libpurple does not return errors on send - adapter only checks that the parameters are valid and that the user is logged in
	// otherwise assume success...
	LibpurpleAdapter::SendResult retVal = LibpurpleAdapter::sendMessage(m_serviceName.data(), m_username.data(), m_usernameTo.data(), m_messageText.data());

	// Now save the status
	MojObject propObject;
	if (LibpurpleAdapter::SENT == retVal) {
		// successful send
		propObject.putString(MOJDB_STATUS, IMMessage::statusStrings[Successful]);
		MojLogInfo(IMServiceApp::s_log, _T("LibpurpleAdapter::sendToTransport succeeded"));
	}
	else if (LibpurpleAdapter::USER_NOT_LOGGED_IN == retVal) {
		// user not logged in - put in queued state
		propObject.putString(MOJDB_STATUS, IMMessage::statusStrings[WaitingForConnection]);
		MojLogError(IMServiceApp::s_log, _T("LibpurpleAdapter::sendToTransport - user not logged in. waiting for connection"));
	}
	else {
		// permanent error - no retry option
		propObject.putString(MOJDB_STATUS, IMMessage::statusStrings[Undeliverable]);

		// set the error category string for the UI
		const MojChar* errorCategory = transportErrorToCategory(retVal);
		propObject.putString(MOJDB_ERROR_CATEGORY, errorCategory);
		MojLogError(IMServiceApp::s_log, _T("LibpurpleAdapter::sendToTransport failed. error %d, category %s"), retVal, errorCategory);
	}

	// id to update
	propObject.putString(MOJDB_ID, m_currentMsgdbId);

	// set server timestamp to current time.
	MojInt64 now = time (NULL);
	propObject.put(MOJDB_SERVER_TIMESTAMP, now);

	// save the new fields - call merge
	// MojErr merge(Signal::SlotRef handler, const MojObject& obj, MojUInt32 flags = MojDb::FlagNone);
	err = m_dbClient.merge(this->m_imSaveMessageSlot, propObject);
	if (err) {
		MojLogError(IMServiceApp::s_log, _T("call to merge message into DB failed. err %d, DB id %s: "), err, m_currentMsgdbId.data() );
		// request to save failed - not much we can do here...
		m_outgoingIMHandler->messageFinished();
	}

	return MojErrNone;
}
コード例 #6
0
MojErr SmtpSyncOutboxCommand::FindOutgoingFolderResponse(MojObject &response, MojErr err)
{
	try {
		ResponseToException(response, err);
		MojLogInfo(m_log, "FindOutgoingFolderResponse, response elided");
	
		try {
			MojObject folder;
			DatabaseAdapter::GetOneResult(response, folder);

			m_retryDelay.clear();
			folder.get("smtpRetryDelay", m_retryDelay);
			ErrorToException(err);
                
			m_retryDelayNew = m_retryDelay;

			MojString json;
			m_retryDelay.toJson(json);
			MojLogInfo(m_log, "got retry delay %s", json.data());
			
			UpdateAccountWatchActivity();
		
		} catch(...) {
			MojLogInfo(m_log, "No outgoing folder, erroring out");
		
			// We must log an error if we cannot find the
			// appropriate outbox folder id, so that in the case
			// of a missing folder, we'll disconnect any
			// potentially left-over watches, and not come back
			// up until the account watches trigger us to update
			// and try again.
			
			m_error.errorCode = MailError::SMTP_OUTBOX_UNAVAILABLE;
			m_error.errorOnAccount = true;
			m_error.errorOnEmail = false;
			m_error.internalError = "Unable to establish outbox folder associated with SMTP account";
			m_error.errorText = "";
			SmtpSyncOutboxCommand::CompleteAndUpdateActivities();
			
			return MojErrNone;
		}

	} catch (std::exception & e) {
		HandleException(e, __func__);
	} catch (...) {
		HandleException(__func__);
	}
        
	return MojErrNone;
}
コード例 #7
0
bool MojoWhereMatcher::Match(const MojObject& response)
{
	MojLogTrace(s_log);

	if (CheckClauses(m_where, response)) {
		MojLogInfo(s_log, _T("Where Matcher: Response %s matches"),
			MojoObjectJson(response).c_str());
		return true;
	} else {
		MojLogInfo(s_log, _T("Where Matcher: Response %s does not match"),
			MojoObjectJson(response).c_str());
		return false;
	}
}
コード例 #8
0
bool MojoNewWhereMatcher::Match(const MojObject& response)
{
	MojLogTrace(s_log);

	MatchResult result = CheckClause(m_where, response, AndMode);
	if (result == Matched) {
		MojLogInfo(s_log, _T("Where Matcher: Response %s matches"),
			MojoObjectJson(response).c_str());
		return true;
	} else {
		MojLogInfo(s_log, _T("Where Matcher: Response %s does not match"),
			MojoObjectJson(response).c_str());
		return false;
	}
}
コード例 #9
0
ファイル: SyncSession.cpp プロジェクト: hatsada1/app-services
void SyncSession::UpdateActivities()
{
	MojLogInfo(m_log, "updating sync session %p activities", this);

	if (m_accountError.errorCode != MailError::NONE) {
		MojLogInfo(m_log, "--- account error: [%d]%s", m_accountError.errorCode, m_accountError.errorText.c_str());
	}

	if(PopErrors::IsRetryError(m_accountError)) {
		m_client.ScheduleRetrySync(m_accountError);
	} else {
		UpdateScheduledSyncActivity();
		UpdateRetryActivity();
	}
}
コード例 #10
0
bool MojoKeyMatcher::Match(const MojObject& response)
{
	MojLogTrace(s_log);

	/* If those were the droids we were looking for, fire! */
	if (response.contains(m_key)) {
		MojLogInfo(s_log, _T("Key Matcher: Key \"%s\" found in response %s"),
			m_key.data(), MojoObjectJson(response).c_str());
		return true;
	} else {
		MojLogInfo(s_log, _T("Key Matcher: Key \"%s\" not found in response"
			"%s"), m_key.data(), MojoObjectJson(response).c_str());
		return false;
	}
}
コード例 #11
0
void SmtpSyncOutboxCommand::UpdateAccountWatchActivity()
{
	MojLogInfo(m_log, "UpdatingAccountWatchActivity");
	
	try {
		// accoundId json object
		MojString accountIdJson;
		MojErr err = m_accountId.toJson(accountIdJson);
		ErrorToException(err);

		SmtpActivityFactory factory;
		ActivityBuilder ab;

		factory.BuildSmtpConfigWatch(ab, m_accountId, m_accountRev);

		bool updating = m_accountWatchActivity.get();

		// and either update and complete the updated activity if we had adopted it, or re-create it.
		
		if ( updating ) {
			
			MojLogInfo(m_log, "updating account watch activity");
	
			m_accountWatchActivity->SetSlots(m_accountActivityUpdatedSlot, m_accountActivityErrorSlot);
	
			m_accountWatchActivity->UpdateAndComplete(m_client, ab.GetActivityObject());
			
		} else {
			// Create payload
			MojObject payload;
			err = payload.put("activity", ab.GetActivityObject());
			ErrorToException(err);
			err = payload.put("start", true);
			ErrorToException(err);
			err = payload.put("replace", true);
			ErrorToException(err);
				
			MojLogInfo(m_log, "creating account watch activity");
							
			m_client.SendRequest(m_createAccountWatchActivityResponseSlot, "com.palm.activitymanager", "create", payload);
		}

	} catch (std::exception & e) {
		HandleException(e, __func__);
	} catch (...) {
		HandleException(__func__);
	}
}
コード例 #12
0
MojErr AccountFinderCommand::GetPasswordResponse(MojObject& response, MojErr err)
{
	CommandTraceFunction();

	try {
		// check the result first
		ErrorToException(err);

		MojObject credentials;
		// Credentials object can be missing if the POP account is restored from
		// backup.  Checking for its existence before using it will prevent exception
		// to be thrown.
		bool exists = response.get("credentials", credentials);
		if (exists) {
			MojString password;
			err = credentials.getRequired("password", password);
			ErrorToException(err);

			m_account->SetPassword(password.data());
		} else {
			MojLogInfo(m_log, "The credentials of POP account '%s' are missing", AsJsonString(m_accountId).c_str());
		}

		// get the transport object
		GetPopAccount();
	} catch (const std::exception& ex) {
		Failure(ex);
	} catch (...) {
		Failure(MailException("unknown exception", __FILE__, __LINE__));
	}

	return MojErrNone;
}
コード例 #13
0
/*
 * inviteBuddy: tell libpurple to add the buddy
 * add buddy to buddyStatus and contact DB kinds
 *
 * imcommand:
 * {
   "params" : {
      "group"            : {"type"        : "string",
                            "optional"    : true,
                            "description" : "The name of the group to put the buddy in."},
      "message"          : {"type"        : "string",
                            "optional"    : true,
                            "description" : "If the IM transport supports custom invite messages."}
     }
 * }
 *
 */
LibpurpleAdapter::SendResult SendOneCommandHandler::inviteBuddy(const MojObject imCmd) {

	bool found = false;

	// params
	MojObject params;
	MojString group;
	found = imCmd.get(MOJDB_PARAMS, params);
	IMServiceHandler::logMojObjectJsonString(_T("command params: %s"),params);
	if (found) {
		params.get(XPORT_GROUP, group, found);
	}

	MojLogInfo (IMServiceApp::s_log, "sending addBuddy command to transport. id: %s, serviceName: %s, username: %s, buddyUsername: %s, groupName: %s",
			m_currentCmdDbId.data(), m_serviceName.data(), m_username.data(), m_buddyName.data(), group.data());

	// Note, libpurple does not return errors on send - adapter only checks that the parameters are valid and that the user is logged in
	// otherwise assume success...
	LibpurpleAdapter::SendResult retVal = LibpurpleAdapter::addBuddy(m_serviceName.data(), m_username.data(), m_buddyName.data(), group.data());

	// Note: if the remote user rejects our invite, buddy gets deleted on the server but we do not get notified, so the contact will remain, but the buddy list gets re-synced on the next login

	if (LibpurpleAdapter::SENT == retVal) {
		// add to buddyStatus and contacts list. They will get removed later if the invite is rejected
		addBuddyToDb();
	}
	return retVal;
}
コード例 #14
0
void MojoWhereMatcher::ValidateClause(const MojObject& clause) const
{
	MojLogTrace(s_log);
	MojLogInfo(s_log, _T("Validating where clause \"%s\""),
		MojoObjectJson(clause).c_str());

	if (!clause.contains(_T("prop"))) {
		throw std::runtime_error("Each where clause must contain a property "
			"to operate on");
	}

	MojObject prop;
	clause.get(_T("prop"), prop);
	ValidateKey(prop);

	if (!clause.contains(_T("op"))) {
		throw std::runtime_error("Each where clause must contain a test "
			"operation to perform");
	}

	MojObject op;
	clause.get(_T("op"), op);
	ValidateOp(op);

	if (!clause.contains(_T("val"))) {
		throw std::runtime_error("Each where clause must contain a value to "
			"test against");
	}
}
コード例 #15
0
void SmtpSendMailCommand::GetEmail()
{
	try {
		// Get the email from the database
		MojLogInfo(m_log, "trying GetOutboxEmail query");

		m_session.GetDatabaseInterface().GetOutboxEmail(m_getEmailSlot, m_emailId);

		MojLogInfo(m_log, "started GetOutboxEmail query");

	} catch (const std::exception& e) {
		HandleException(e, __func__, __FILE__, __LINE__);
	} catch (...) {
		HandleUnknownException();
	}
}
コード例 #16
0
ファイル: MojDbIsamQuery.cpp プロジェクト: KyleMaas/db8
MojErr MojDbIsamQuery::count(MojUInt32& countOut)
{
	MojAssert(m_isOpen);

	countOut = 0;
	MojInt32 warns = 0;
	m_plan->limit(MojUInt32Max);
	bool found = false;
	do {
		// Iterate over all the db results but only count
		// the ones that would not be excluded.  If we're not
		// excluding any kinds, getImpl does not need to get the
		// storage item.
		MojDbStorageItem* item = NULL;
		//MojErr err = getImpl(item, found, !m_excludeKinds.empty());  // orig
		//to ensure that we do not count ghost keys, me need to always try to get the item as well
		MojErr err = getImpl(item, found, true);
		if (err == MojErrInternalIndexOnFind) {
			found = true;			// to continue with counting
			warns++;
			continue;			// we ignore such keys; it is not counted in getImpl either
		}
		MojErrCheck(err);
	} while (found);
	countOut = m_count;
	if (warns > 0) {
		const MojChar * from = m_plan->query().from().data();
		MojLogInfo(MojDb::s_log, _T("isamquery_count: from: %s; indexid: %zu; warnings: %d \n"),
								 from, m_plan->idIndex(), warns);
	}
	return MojErrNone;
}
コード例 #17
0
ファイル: FileCacheSet.cpp プロジェクト: uncle22/filecache
// Returns the filename of a cachedObject
const std::string
CFileCacheSet::CachedObjectFilename(const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  std::string retVal;
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      retVal = fileCache->GetObjectFilename(objId);
      MojLogInfo(s_log,
		 _T("CachedObjectFilename: Object '%llu' has name '%s'."),
		 objId, retVal.c_str());
    } else {
      MojLogWarning(s_log,
		    _T("CachedObjectFilename: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    }
  } else {
    MojLogWarning(s_log,
		  _T("CachedObjectFilename: Cache type not found for id '%llu'."),
		  objId);
  }

  return retVal;

}
コード例 #18
0
ファイル: FileCacheSet.cpp プロジェクト: uncle22/filecache
// Pin an object in the cache by allowing a client to subscribe to
// the object.  This will guarantee the object will not be removed
// from the cache while the subscription is active.  Returns the
// file path associated with the objectId.
const std::string
CFileCacheSet::SubscribeCacheObject(std::string& msgText, const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  std::string retVal("");
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      retVal = fileCache->Subscribe(msgText, objId);
      if (msgText.empty()) {
	MojLogInfo(s_log,
		   _T("SubscribeCacheObject: Object '%llu' subscribed."), objId);
      }
    } else {
      MojLogWarning(s_log,
		   _T("SubscribeCacheObject: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    }
  } else {
    MojLogWarning(s_log,
		  _T("SubscribeCacheObject: Cache type not found for id '%llu'."),
		  objId);
  }

  return retVal;
}
コード例 #19
0
ファイル: FileCacheSet.cpp プロジェクト: uncle22/filecache
// 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;
}
コード例 #20
0
ファイル: FileCacheSet.cpp プロジェクト: uncle22/filecache
// Expire an object from the cache.  This will cause the object to
// be deleted from the cache.  This will return false if the
// requested item is currently pinned in the cache by a subscription
// and the object will be deleted once the subscription expires.
bool
CFileCacheSet::ExpireCacheObject(const cachedObjectId_t objId) {

  MojLogTrace(s_log);

  bool retVal = true;
  const std::string typeName(GetTypeForObjectId(objId));
  if (!typeName.empty()) {
    CFileCache* fileCache = GetFileCacheForType(typeName);
    if (fileCache != NULL) {
      RemoveObjectFromIdMap(objId);
      retVal = fileCache->Expire(objId);
      if (!retVal) {
	MojLogInfo(s_log,
		   _T("ExpireCacheObject: expire deferred, object '%llu' in use"),
		   objId);
      }
    } else {
      MojLogWarning(s_log,
		    _T("ExpireCacheObject: No cache of type '%s' found for id '%llu'."),
		    typeName.c_str(), objId);
    } 
  } else {
    MojLogWarning(s_log,
		  _T("ExpireCacheObject: Cache type not found for id '%llu'."),
		  objId);
  }

  return retVal;
}
コード例 #21
0
/*
 * Save the new incoming IM message to the DB
 *
 * @return MojErr if error - caller will log it
 */
MojErr IncomingIMHandler::saveNewIMMessage(MojRefCountedPtr<IMMessage> IMMessage) {

	MojErr err;

	// The message we are handling
	m_IMMessage = IMMessage;

	// save it
	MojObject dbObject;
	err = m_IMMessage->createDBObject(dbObject);
	MojErrCheck(err);

	//add our kind to the object
	//luna://com.palm.db/put '{"objects":[{"_kind":"com.palm.test:1","foo":1,"bar":1000}]}'
	err = dbObject.putString(_T("_kind"), PALM_DB_IMMESSAGE_KIND);
	MojErrCheck(err);

	// log it - OK to show body in debug log
	MojString json;
	err = dbObject.toJson(json);
	MojErrCheck(err);
	MojLogDebug(IMServiceApp::s_log, _T("saving message to db: %s"), json.data());
	MojLogInfo(IMServiceApp::s_log, _T("saving message to db"));

	// save it
	// the save generates a call to the save result handler
	err = m_dbClient.put(this->m_IMSaveMessageSlot, dbObject);
	MojErrCheck(err);

	return MojErrNone;
}
コード例 #22
0
MojErr SmtpSyncOutboxCommand::GetOutboxEmailsResponse(MojObject &response, MojErr err)
{
	try {
		ResponseToException(response, err);
	
		try {
			ErrorToException(err);

			BOOST_FOREACH(const MojObject& email, DatabaseAdapter::GetResultsIterators(response)) {
				m_emailsToSend.push_back(email);
			}

			if(DatabaseAdapter::GetNextPage(response, m_outboxPage)) {
				// Get more emails
				GetSomeOutboxEmails();
			} else {
				MojLogInfo(m_log, "Found %d emails in outbox", m_emailsToSend.size());

				m_emailIt = m_emailsToSend.begin();

				m_didSomething = false;

				SendNextEmail();
			}
		} catch(std::exception& e) {
			HandleException(e, __func__);
		} catch(...) {
			HandleException(__func__);
		}

	} catch (std::exception & e) {
コード例 #23
0
MojErr AccountFinderCommand::GetPopAccountResponse(MojObject& response, MojErr err)
{
	CommandTraceFunction();

	try {
		// check database result first
		ErrorToException(err);

		MojObject results;
		err = response.getRequired(_T("results"), results);
		ErrorToException(err);

		if (results.size() > 0) {
			MojObject transportObj;
			if (results.at(0, transportObj)) {
				PopAccountAdapter::GetPopAccount(m_accountObj, transportObj, *(m_account.get()));
			}
		}

		MojLogInfo(m_log, "Setting account to pop client");
		m_client.SetAccount(m_account);

		Complete();
	} catch (const std::exception& ex) {
		Failure(ex);
	} catch (...) {
		Failure(MailException("unknown exception", __FILE__, __LINE__));
	}

	return MojErrNone;
}
コード例 #24
0
MojErr UpSyncSentEmailsCommand::GetSentEmailsResponse(MojObject& response, MojErr err)
{
	CommandTraceFunction();

	try {
		ErrorToException(err);

		// Store all sent emails in a vector.
		BOOST_FOREACH(const MojObject& emailObj, DatabaseAdapter::GetResultsIterators(response))
		{
			EmailPtr email = boost::make_shared<Email>();
			EmailAdapter::ParseDatabaseObject(emailObj, *email);
			MojObject id;
			err = emailObj.getRequired(DatabaseAdapter::ID, id);
			ErrorToException(err);
			email->SetId(id);
			m_sentEmails.push_back(email);
		}

		// Check for more results
		bool hasMoreResults = DatabaseAdapter::GetNextPage(response, m_sentEmailsPage);

		if(hasMoreResults) {
			GetSentEmails();
		} else {
			if(!m_sentEmails.empty()) {
				MojLogInfo(m_log, "up sync %d sent emails to the server", m_sentEmails.size());
				m_emailP = m_sentEmails.back();
				CreateAndRunAppendCommand();
			} else {
				UpSyncSentItemsComplete();
			}
		}

	} CATCH_AS_FAILURE
コード例 #25
0
MojErr
DevelCategoryHandler::PriorityControl(MojServiceMessage *msg, MojObject& payload)
{
	ACTIVITY_SERVICEMETHOD_BEGIN();

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

	MojErr err;

	bool enabled = false;
	bool found = payload.get(_T("enabled"), enabled);
	if (!found) {
		err = msg->replyError(MojErrInvalidArg, _T("Must specify "
			"\"enabled\":true or \"enabled\":false"));
		MojErrCheck(err);
		return MojErrNone;
	}

	if (enabled) {
		m_resourceManager->Enable();
	} else {
		m_resourceManager->Disable();
	}

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

	ACTIVITY_SERVICEMETHOD_END(msg);

	return MojErrNone;
}
コード例 #26
0
void ConnectCommand::RunImpl()
{
    CommandTraceFunction();

    try {
        const ImapLoginSettings& loginSettings = m_session.GetLoginSettings();

        std::string hostname = loginSettings.GetHostname();
        int port = loginSettings.GetPort();
        ImapLoginSettings::EncryptionType encryption = loginSettings.GetEncryption();

        if(hostname.empty() || port <= 0) {
            throw MailException("empty hostname or port", __FILE__, __LINE__);
        }

        MojLogInfo(m_log, "connecting to %s:%d%s on interface %s",
                   hostname.c_str(), port, (encryption == ImapLoginSettings::Encrypt_SSL) ? " with SSL" : "",
                   !m_bindAddress.empty() ? m_bindAddress.c_str() : "0.0.0.0");

        m_connection = SocketConnection::CreateSocket(hostname.c_str(), port,
                       (encryption == ImapLoginSettings::Encrypt_SSL), m_bindAddress);

        int connectTimeout = ImapConfig::GetConfig().GetConnectTimeout();

        if(connectTimeout) {
            m_connection->SetConnectTimeout(connectTimeout);
        }

        m_connection->Connect(m_connectedSlot);
    } catch(const exception& e) {
        ConnectFailure(e);
    }
}
コード例 #27
0
void SmtpSendMailCommand::CalculateEmailSize()
{
	try {
		MojLogInfo(m_log, "calculating email size");
		m_counter.reset( new CounterOutputStream() );

		// Wrap the mail writer in a CRLF fixer stream, which ensures that the stream ends with 
		// CRLF, so we can safely write out a DOT to end the body, without the risk that it'll end
		// up on the end of a body line. We're doing that here, so the counter will include those
		// octets.
		m_crlfTerminator.reset( new CRLFTerminatedOutputStream(m_counter));
	
		m_emailWriter.reset( new AsyncEmailWriter(m_email) );
		m_emailWriter->SetOutputStream(m_crlfTerminator );
		m_emailWriter->SetBccIncluded(false); // bcc should only appear in the RCPT list
	
		m_emailWriter->SetPartList(m_email.GetPartList());
	
		m_emailWriter->WriteEmail(m_calculateDoneSlot);

	} catch (const std::exception& e) {
		HandleException(e, __func__, __FILE__, __LINE__);
	} catch (...) {
		HandleUnknownException();
	}
}
コード例 #28
0
ファイル: PopSession.cpp プロジェクト: Garfonso/app-services
void PopSession::FetchEmail(Request::RequestPtr request)
{
	MojLogInfo(m_log, "Fetching email '%s' with '%s' priority", AsJsonString(request->GetEmailId()).c_str(), ((request->GetPriority() == Request::Priority_High) ? "high" : "low"));
	MojRefCountedPtr<FetchEmailCommand> command(new FetchEmailCommand(*this, request));
	m_commandManager->QueueCommand(command, (request->GetPriority() == Request::Priority_High));
	CheckQueue();
}
コード例 #29
0
ファイル: FileCacheSet.cpp プロジェクト: uncle22/filecache
// Gets the current status of a specied cache type.  Returns the
// amount of space and the number of cached objects used by the
// items in that cache type.
bool
CFileCacheSet::GetCacheTypeStatus(const std::string& typeName,
				  cacheSize_t* size,
				  paramValue_t* numCacheObjects) {

  MojLogTrace(s_log);

  bool retVal = false;
  cacheSize_t cacheSize = 0;
  paramValue_t numObjects = 0;

  CFileCache* fileCache = GetFileCacheForType(typeName);
  if (fileCache != NULL) {
    fileCache->GetCacheStatus(&cacheSize, &numObjects);
    if (size != NULL) {
      *size = cacheSize;
    }
    if (numCacheObjects != NULL) {
      *numCacheObjects = numObjects;
    }
    
    MojLogInfo(s_log, _T("GetCacheTypeStatus: size = '%d', numobjs = '%d'"),
	       cacheSize, numObjects);
    retVal = true;
  } else {
    MojLogWarning(s_log,
		  _T("GetCacheTypeStatus: No cache of type '%s' found."),
		  typeName.c_str());
  }

  return retVal;
}
コード例 #30
0
ファイル: PopSession.cpp プロジェクト: Garfonso/app-services
void PopSession::CommandComplete(Command* command)
{
	m_requestManager->UnregisterCommand(command);
	m_commandManager->CommandComplete(command);

	if ((m_state == State_OkToSync || m_state == State_CancelPendingCommands)
			&& m_commandManager->GetPendingCommandCount() == 0
			&& m_commandManager->GetActiveCommandCount() == 0) {
		// no commands to run

		// complete sync session
		if (m_syncSession.get() && (m_syncSession->IsActive() || m_syncSession->IsStarting())) {
			MojLogInfo(m_log, "Requesting to stop sync session");

			if (m_accountError.errorCode != MailError::NONE) {
				MojLogError(m_log, "in session, account error: [%d]%s", m_accountError.errorCode, m_accountError.errorText.c_str());
			}
			m_syncSession->SetAccountError(m_accountError);
			m_syncSession->RequestStop();
		}

		// apply pending account changes
		ApplyAccountUpdates();

		// set the state so that we can log out the current session
		m_state = State_LogOut;
		LogOut();
	}
}