Пример #1
0
void SG_user__get_email_for_repo(SG_context * pCtx, SG_repo* pRepo, const char ** ppsz_email)
{
	char * psz_admin_id = NULL;
	char * psz_userid = NULL;
	const char * psz_email_temp = NULL;
	SG_string * pstr_path = NULL;
	SG_vhash * pvh_userhash = NULL;
	if (pRepo)
	{
		SG_ERR_CHECK(  SG_repo__get_admin_id(pCtx, pRepo, &psz_admin_id)  );

		// we store this userid under the admin scope of the repo we were given
		SG_ERR_CHECK(  SG_string__alloc__format(pCtx, &pstr_path, "%s/%s/%s",
					SG_LOCALSETTING__SCOPE__ADMIN,
					psz_admin_id,
					SG_LOCALSETTING__USERID
					)  );
		SG_ERR_CHECK(  SG_localsettings__get__sz(pCtx, SG_string__sz(pstr_path), pRepo, &psz_userid, NULL)  );
		if (psz_userid == NULL || *psz_userid == 0)
			SG_ERR_THROW(SG_ERR_USER_NOT_FOUND);
		SG_ERR_CHECK(  SG_user__lookup_by_userid(pCtx, pRepo, psz_userid, &pvh_userhash)  );
		SG_ERR_CHECK(  SG_vhash__get__sz(pCtx, pvh_userhash, "email", &psz_email_temp)  );
		SG_ERR_CHECK(  SG_STRDUP(pCtx, psz_email_temp, (char**)ppsz_email)  );
	}

fail:
	SG_VHASH_NULLFREE(pCtx, pvh_userhash);
	SG_NULLFREE(pCtx, psz_admin_id);
	SG_NULLFREE(pCtx, psz_userid);
	SG_STRING_NULLFREE(pCtx, pstr_path);

}
Пример #2
0
void SetProfileSettings(
	SG_context* pCtx, 
	const char* szProfile,
	const char* pszDest, 
	const char* pszSrc, 
	SG_int64 lSyncIntervalMinutes)
{
	SG_string* pstrConfigPath = NULL;

	SG_ERR_CHECK(  SG_string__alloc__format(pCtx, &pstrConfigPath, "%s/%s/%s", CONFIG_ROOT, szProfile, CONFIG_DEST)  );
	SG_ERR_CHECK(  SG_localsettings__update__sz(pCtx, SG_string__sz(pstrConfigPath), pszDest)  );
	SG_ERR_CHECK(  SG_string__clear(pCtx, pstrConfigPath)  );

	SG_ERR_CHECK(  SG_string__append__format(pCtx, pstrConfigPath, "%s/%s/%s", CONFIG_ROOT, szProfile, CONFIG_SRC)  );
	SG_ERR_CHECK(  SG_localsettings__update__sz(pCtx, SG_string__sz(pstrConfigPath), pszSrc)  );
	SG_ERR_CHECK(  SG_string__clear(pCtx, pstrConfigPath)  );

	SG_ERR_CHECK(  SG_string__append__format(pCtx, pstrConfigPath, "%s/%s/%s", CONFIG_ROOT, szProfile, CONFIG_INTERVAL)  );
	SG_ERR_CHECK(  SG_localsettings__update__int64(pCtx, SG_string__sz(pstrConfigPath), lSyncIntervalMinutes)  );

	/* common cleanup */
fail:
	SG_STRING_NULLFREE(pCtx, pstrConfigPath);
}
Пример #3
0
void GetProfileSettings(
	SG_context* pCtx, 
	const char* szProfile,
	char** ppszDest, 
	char** ppszSrc, 
	SG_int64* plSyncIntervalMinutes,
	LPWSTR* ppwszErr)
{
	static const LPWSTR ERR_NO_DEST = L"No destination repository is configured.";
	static const LPWSTR ERR_NO_SRC = L"No source repository is configured.";

	char* pszDest = NULL;
	char* pszSrc = NULL;
	SG_variant* pvMinutes = NULL;
	SG_string* pstrConfigPath = NULL;
	SG_uint64 lMinutes;
	LPWSTR pwszErr = NULL;

	/* It's kind of icky, but we copy these error strings so the balloon code that displays them doesn't have to
	   be very smart and can always free the message string.  (Generic unhandled errors aren't constant, so it has
	   to free those.) I'm not sure making the balloon code more complexso this can be simpler is a net win, so I'm 
	   leaving this be. But it is icky. */

	SG_ERR_CHECK(  SG_string__alloc__format(pCtx, &pstrConfigPath, "%s/%s/%s", CONFIG_ROOT, szProfile, CONFIG_DEST)  );
	SG_ERR_CHECK(  SG_localsettings__get__sz(pCtx, SG_string__sz(pstrConfigPath), NULL, &pszDest, NULL)  );
	SG_ERR_CHECK(  SG_string__clear(pCtx, pstrConfigPath)  );
	if (!pszDest || !pszDest[0])
	{
		size_t len_in_chars = 0;
		if (FAILED(  StringCchLength(ERR_NO_DEST, STRSAFE_MAX_CCH, &len_in_chars)  ))
			SG_ERR_THROW(SG_ERR_GETLASTERROR(GetLastError()));
		pwszErr = (LPWSTR)malloc(sizeof(wchar_t) * (len_in_chars + 1));
		if (FAILED(  StringCchCopy(pwszErr, len_in_chars + 1, ERR_NO_DEST)  ))
			SG_ERR_THROW(SG_ERR_GETLASTERROR(GetLastError()));
	}

	SG_ERR_CHECK(  SG_string__append__format(pCtx, pstrConfigPath, "%s/%s/%s", CONFIG_ROOT, szProfile, CONFIG_SRC)  );
	SG_ERR_CHECK(  SG_localsettings__get__sz(pCtx, SG_string__sz(pstrConfigPath), NULL, &pszSrc, NULL)  );
	SG_ERR_CHECK(  SG_string__clear(pCtx, pstrConfigPath)  );
	if (!pwszErr)
	{
		if (!pszSrc || !pszSrc[0])
		{
			size_t len_in_chars = 0;
			if (FAILED(  StringCchLength(ERR_NO_SRC, STRSAFE_MAX_CCH, &len_in_chars)  ))
				SG_ERR_THROW(SG_ERR_GETLASTERROR(GetLastError()));
			pwszErr = (LPWSTR)malloc(sizeof(wchar_t) * (len_in_chars + 1));
			if (FAILED(  StringCchCopy(pwszErr, len_in_chars + 1, ERR_NO_SRC)  ))
				SG_ERR_THROW(SG_ERR_GETLASTERROR(GetLastError()));
		}
	}

	SG_ERR_CHECK(  SG_string__append__format(pCtx, pstrConfigPath, "%s/%s/%s", CONFIG_ROOT, szProfile, CONFIG_INTERVAL)  );
	SG_ERR_CHECK(  SG_localsettings__get__variant(pCtx, SG_string__sz(pstrConfigPath), NULL, &pvMinutes, NULL)  );

	if (!pvMinutes)
		lMinutes = DEFAULT_SYNC_EVERY_N_MINUTES;
	else
		SG_ERR_CHECK(  SG_variant__get__uint64(pCtx, pvMinutes, &lMinutes)  );

	if (plSyncIntervalMinutes)
		*plSyncIntervalMinutes = lMinutes;
	SG_RETURN_AND_NULL(pszDest, ppszDest);
	SG_RETURN_AND_NULL(pszSrc, ppszSrc);

	SG_RETURN_AND_NULL(pwszErr, ppwszErr);

	/* common cleanup */
fail:
	SG_NULLFREE(pCtx, pszDest);
	SG_NULLFREE(pCtx, pszSrc);
	SG_VARIANT_NULLFREE(pCtx, pvMinutes);
	SG_STRING_NULLFREE(pCtx, pstrConfigPath);

	if (pwszErr)
		free(pwszErr);
}