Пример #1
0
void SG_localsettings__get__varray(SG_context * pCtx, const char * psz_path, SG_repo* pRepo, SG_varray** ppva, SG_string** ppstr_where_found)
{
    SG_varray* pva = NULL;
    SG_string* pstr_path = NULL;
    SG_variant* pv = NULL;

    SG_ERR_CHECK(  SG_localsettings__get__variant(pCtx, psz_path, pRepo, &pv, &pstr_path)  );
    if (pv)
    {
        if (SG_VARIANT_TYPE_VARRAY == pv->type)
        {
            pva = pv->v.val_varray;
            pv->v.val_varray = NULL;
        }
    }

    *ppva = pva;
    pva = NULL;

    if (ppstr_where_found)
    {
        *ppstr_where_found = pstr_path;
        pstr_path = NULL;
    }

fail:
    SG_VARIANT_NULLFREE(pCtx, pv);
    SG_STRING_NULLFREE(pCtx, pstr_path);
    SG_VARRAY_NULLFREE(pCtx, pva);
}
Пример #2
0
void SG_localsettings__get__sz(SG_context * pCtx, const char * psz_path, SG_repo* pRepo, char** ppsz, SG_string** ppstr_where_found)
{
    char* psz_val = NULL;
    SG_string* pstr_path = NULL;
    SG_variant* pv = NULL;

    SG_ERR_CHECK(  SG_localsettings__get__variant(pCtx, psz_path, pRepo, &pv, &pstr_path)  );
    if (pv)
    {
        if (SG_VARIANT_TYPE_SZ == pv->type)
        {
            psz_val = (char*) pv->v.val_sz;
            pv->v.val_sz = NULL;
        }
    }

    *ppsz = psz_val;
    psz_val = NULL;

    if (ppstr_where_found)
    {
        *ppstr_where_found = pstr_path;
        pstr_path = NULL;
    }

fail:
    SG_VARIANT_NULLFREE(pCtx, pv);
    SG_STRING_NULLFREE(pCtx, pstr_path);
    SG_NULLFREE(pCtx, psz_val);
}
Пример #3
0
static void SG_localsettings__factory__get_nth__variant(
    SG_context* pCtx,
    SG_uint32 i,
    SG_variant** ppv
    )
{
	SG_variant* pv = NULL;

    if (SG_VARIANT_TYPE_SZ == g_factory_defaults[i].type)
    {
        SG_ERR_CHECK(  SG_alloc1(pCtx, pv)  );
        pv->type = g_factory_defaults[i].type;
        SG_ERR_CHECK(  SG_strdup(pCtx, g_factory_defaults[i].psz_val, (char**) &pv->v.val_sz)  );
    }
    else if (SG_VARIANT_TYPE_VARRAY == g_factory_defaults[i].type)
    {
        const char** pp_el = NULL;

        SG_ERR_CHECK(  SG_alloc1(pCtx, pv)  );
        pv->type = g_factory_defaults[i].type;
        SG_ERR_CHECK(  SG_varray__alloc(pCtx, &pv->v.val_varray)  );

        pp_el = g_factory_defaults[i].pasz_array;
        while (*pp_el)
        {
            SG_ERR_CHECK(  SG_varray__append__string__sz(pCtx, pv->v.val_varray, *pp_el)  );
            pp_el++;
        }
    }
    else
    {
        SG_ERR_THROW(  SG_ERR_NOTIMPLEMENTED  );
    }

    *ppv = pv;
    pv = NULL;

fail:
    SG_VARIANT_NULLFREE(pCtx, pv);
}
Пример #4
0
static void SG_localsettings__factory__get__variant(
    SG_context* pCtx,
    const char* psz_path,
    SG_variant** ppv
    )
{
    SG_uint32 i = 0;
	SG_variant* pv = NULL;

    for (i=0; i<(sizeof(g_factory_defaults) / sizeof(struct localsetting_factory_default)); i++)
    {
        if (0 == strcmp(psz_path, g_factory_defaults[i].psz_path_partial))
        {
            SG_ERR_CHECK(  SG_localsettings__factory__get_nth__variant(pCtx, i, &pv)  );
            break;
        }
    }

    *ppv = pv;
    pv = NULL;

fail:
    SG_VARIANT_NULLFREE(pCtx, pv);
}
Пример #5
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);
}
Пример #6
0
void SG_localsettings__get__variant(SG_context * pCtx, const char * psz_path, SG_repo* pRepo, SG_variant** ppv, SG_string** ppstr_where_found)
{
    SG_jsondb* p = NULL;
    SG_string* pstr_path = NULL;
    SG_variant* pv = NULL;
    char* psz_repo_id = NULL;
    char* psz_admin_id = NULL;
    const char* psz_ref_descriptor_name = NULL;

    SG_ASSERT(pCtx);
    SG_NONEMPTYCHECK_RETURN(psz_path);

    SG_ERR_CHECK(  SG_closet__get_localsettings(pCtx, &p)  );

    SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstr_path)  );
    if ('/' == psz_path[0])
    {
        SG_bool b = SG_FALSE;

        SG_ERR_CHECK(  SG_string__sprintf(pCtx, pstr_path, "%s", psz_path)  );
        SG_ERR_CHECK(  SG_jsondb__has(pCtx, p, SG_string__sz(pstr_path), &b)  );
        if (b)
        {
            SG_ERR_CHECK(  SG_jsondb__get__variant(pCtx, p, SG_string__sz(pstr_path), &pv)  );
        }
    }
    else
    {
        SG_bool b_has_val = SG_FALSE;

        // try the instance of the repo
        if (!b_has_val && pRepo)
        {
            SG_ERR_CHECK(  SG_repo__get_descriptor_name(pCtx, pRepo, &psz_ref_descriptor_name)  );

            SG_ERR_CHECK(  SG_string__sprintf(pCtx, pstr_path, "%s/%s/%s",
                        SG_LOCALSETTING__SCOPE__INSTANCE,
                        psz_ref_descriptor_name,
                        psz_path
                        )  );
            SG_ERR_CHECK(  SG_jsondb__has(pCtx, p, SG_string__sz(pstr_path), &b_has_val)  );
            if (b_has_val)
            {
                SG_ERR_CHECK(  SG_jsondb__get__variant(pCtx, p, SG_string__sz(pstr_path), &pv)  );
            }
        }

        // then the repo
        if (!b_has_val && pRepo)
        {
            SG_ERR_CHECK(  SG_repo__get_repo_id(pCtx, pRepo, &psz_repo_id)  );

            SG_ERR_CHECK(  SG_string__sprintf(pCtx, pstr_path, "%s/%s/%s",
                        SG_LOCALSETTING__SCOPE__REPO,
                        psz_repo_id,
                        psz_path
                        )  );
            SG_ERR_CHECK(  SG_jsondb__has(pCtx, p, SG_string__sz(pstr_path), &b_has_val)  );
            if (b_has_val)
            {
                SG_ERR_CHECK(  SG_jsondb__get__variant(pCtx, p, SG_string__sz(pstr_path), &pv)  );
            }
        }

        // then the admin group of repos
        if (!b_has_val && pRepo)
        {
            SG_ERR_CHECK(  SG_repo__get_admin_id(pCtx, pRepo, &psz_admin_id)  );

            SG_ERR_CHECK(  SG_string__sprintf(pCtx, pstr_path, "%s/%s/%s",
                        SG_LOCALSETTING__SCOPE__ADMIN,
                        psz_admin_id,
                        psz_path
                        )  );
            SG_ERR_CHECK(  SG_jsondb__has(pCtx, p, SG_string__sz(pstr_path), &b_has_val)  );
            if (b_has_val)
            {
                SG_ERR_CHECK(  SG_jsondb__get__variant(pCtx, p, SG_string__sz(pstr_path), &pv)  );
            }
        }

        // then the machine
        if (!b_has_val)
        {
            SG_ERR_CHECK(  SG_string__sprintf(pCtx, pstr_path, "%s/%s", SG_LOCALSETTING__SCOPE__MACHINE, psz_path)  );
            SG_ERR_CHECK(  SG_jsondb__has(pCtx, p, SG_string__sz(pstr_path), &b_has_val)  );
            if (b_has_val)
            {
                SG_ERR_CHECK(  SG_jsondb__get__variant(pCtx, p, SG_string__sz(pstr_path), &pv)  );
            }
        }

        // then the factory default
        if (!b_has_val)
        {
            SG_STRING_NULLFREE(pCtx, pstr_path);
            SG_ERR_CHECK(  SG_localsettings__factory__get__variant(pCtx, psz_path, &pv)  );
        }
    }

    *ppv = pv;
    pv = NULL;

    if (ppstr_where_found)
    {
        *ppstr_where_found = pstr_path;
        pstr_path = NULL;
    }

fail:
    SG_NULLFREE(pCtx, psz_repo_id);
    SG_NULLFREE(pCtx, psz_admin_id);
    SG_VARIANT_NULLFREE(pCtx, pv);
    SG_STRING_NULLFREE(pCtx, pstr_path);
    SG_JSONDB_NULLFREE(pCtx, p);
}