コード例 #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
static void _getUserEmail(SG_context *pCtx,
	SG_repo* pRepo,	
	SG_string *replacement)
{
	SG_vhash* pvh_user = NULL;
	SG_string* pstrUser = NULL;
	const char* psz_email = NULL;

	SG_STRING__ALLOC(pCtx, &pstrUser);
	SG_ERR_CHECK(  _getUserId(pCtx, pRepo, pstrUser)  );
	SG_ERR_CHECK(  SG_user__lookup_by_userid(pCtx, pRepo, SG_string__sz(pstrUser), &pvh_user)  );
    if (pvh_user)
    {
        SG_ERR_CHECK(  SG_vhash__get__sz(pCtx, pvh_user, "email", &psz_email)  );			
    }
	SG_ERR_CHECK(  SG_string__set__sz(pCtx, replacement, psz_email)  );
fail:
	SG_VHASH_NULLFREE(pCtx, pvh_user);
	SG_STRING_NULLFREE(pCtx, pstrUser);

}