void sg_sync_client__http__get_dagnode_info(
    SG_context* pCtx,
    SG_sync_client* pSyncClient,
    SG_vhash* pvhRequest,
    SG_history_result** ppInfo)
{
    SG_string* pstrRequest = NULL;
    char* pszUrl = NULL;
    SG_string* pstr = NULL;

    SG_NULLARGCHECK_RETURN(pSyncClient);
    SG_NULLARGCHECK_RETURN(pvhRequest);
    SG_NULLARGCHECK_RETURN(ppInfo);

    SG_ERR_CHECK(  _get_sync_url(pCtx, pSyncClient->psz_remote_repo_spec, SYNC_URL_SUFFIX "/incoming" JSON_URL_SUFFIX, NULL, NULL, &pszUrl)  );


    SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstrRequest)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, pvhRequest, pstrRequest)  );

    SG_ERR_CHECK(  do_url(pCtx, pszUrl, "GET", SG_string__sz(pstrRequest), pSyncClient->psz_username, pSyncClient->psz_password, &pstr, NULL, SG_TRUE)  );
    SG_ERR_CHECK(  SG_history_result__from_json(pCtx, SG_string__sz(pstr), ppInfo)  );

    /* fall through */
fail:
    SG_NULLFREE(pCtx, pszUrl);
    SG_STRING_NULLFREE(pCtx, pstrRequest);
    SG_STRING_NULLFREE(pCtx, pstr);
}
/**
 * Queue a request to resolve (or partially resolve) an issue.
 * We assume that the caller has already
 * queued any necessary WD operations
 * (such as moves/renamed) and now just
 * needs to mark the item resolved (or
 * partially resolved).
 *
 * Since an item may have multiple conflict
 * bits set, you can use this to mark the
 * specific choices made in the pvhSavedResolutions
 * and only mark it fully resolved when
 * everything has been chosen.
 *
 * We steal the optional/given pvhSavedResolutions.
 *
 */
void sg_wc_tx__queue__resolve_issue__sr(SG_context * pCtx,
										SG_wc_tx * pWcTx,
										sg_wc_liveview_item * pLVI,
										SG_wc_status_flags statusFlags_x_xr_xu,
										SG_vhash ** ppvhSavedResolutions)
{
	SG_string * pStringResolveData = NULL;

	SG_NULLARGCHECK_RETURN( pWcTx );
	SG_NULLARGCHECK_RETURN( pLVI );
	// ppvhSavedResolutions is optional.

	if (ppvhSavedResolutions && *ppvhSavedResolutions)
	{
		SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pStringResolveData)  );
		SG_ERR_CHECK(  SG_vhash__to_json(pCtx, (*ppvhSavedResolutions), pStringResolveData)  );
	}

	SG_ERR_CHECK(  sg_wc_tx__journal__resolve_issue__sr(pCtx, pWcTx,
														pLVI->uiAliasGid,
														statusFlags_x_xr_xu,
														pStringResolveData)  );

	pLVI->statusFlags_x_xr_xu = statusFlags_x_xr_xu;

	SG_VHASH_NULLFREE(pCtx, pLVI->pvhSavedResolutions);
	if (ppvhSavedResolutions && *ppvhSavedResolutions)
	{
		pLVI->pvhSavedResolutions = *ppvhSavedResolutions;
		*ppvhSavedResolutions = NULL;
	}

fail:
	SG_STRING_NULLFREE(pCtx, pStringResolveData);
}
void u0026_jsonparser__test_jsonparser_vhash_2(SG_context * pCtx)
{
	SG_string* pstr1 = NULL;
	SG_string* pstr2 = NULL;
	SG_vhash* pvh = NULL;

	VERIFY_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstr1)  );
	VERIFY_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstr2)  );

	VERIFY_ERR_CHECK(  u0026_jsonparser__create_2(pCtx, pstr1)  );

	SG_VHASH__ALLOC__FROM_JSON__SZ(pCtx, &pvh, SG_string__sz(pstr1));
	VERIFY_COND("from_json", !SG_context__has_err(pCtx));
	VERIFY_COND("from_json", pvh);

	SG_context__err_reset(pCtx);
	SG_vhash__to_json(pCtx, pvh, pstr2);
	VERIFY_COND("from_json", !SG_context__has_err(pCtx));

	// TODO do some checks

fail:
	SG_STRING_NULLFREE(pCtx, pstr1);
	SG_STRING_NULLFREE(pCtx, pstr2);
	SG_VHASH_NULLFREE(pCtx, pvh);
}
Example #4
0
void SG_vfile__end(
	SG_context* pCtx,
	SG_vfile** ppvf,
	const SG_vhash* pvh
	)
{
	SG_string* pstr = NULL;
	SG_vfile* pvf = NULL;

	SG_NULLARGCHECK_RETURN(ppvf);

	pvf = *ppvf;

	if (pvh)
	{
		SG_ARGCHECK_RETURN( !(pvf->mode & SG_FILE_RDONLY) , pvh );

		SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstr)  );

		SG_ERR_CHECK(  SG_vhash__to_json(pCtx, pvh,pstr)  );

		SG_ERR_CHECK(  SG_file__seek(pCtx, pvf->pFile, 0)  );

		SG_ERR_CHECK(  SG_file__truncate(pCtx, pvf->pFile)  );

#if TRACE_VFILE
		SG_ERR_IGNORE(  SG_console(pCtx, SG_CS_STDERR, "VFileEnd: Writing %d bytes to file.\n",
								   SG_string__length_in_bytes(pstr))  );
#endif

		SG_ERR_CHECK(  SG_file__write(pCtx, pvf->pFile, SG_string__length_in_bytes(pstr), (const SG_byte *)SG_string__sz(pstr), NULL)  );
		SG_STRING_NULLFREE(pCtx, pstr);
	}
	else
	{
		if (!(pvf->mode & SG_FILE_RDONLY))
		{
			SG_ERR_CHECK(  SG_file__seek(pCtx, pvf->pFile, 0)  );

			SG_ERR_CHECK(  SG_file__truncate(pCtx, pvf->pFile)  );

#if TRACE_VFILE
			SG_ERR_IGNORE(  SG_console(pCtx, SG_CS_STDERR, "VFileEnd: Truncating file.\n")  );
#endif
		}
	}

	SG_FILE_NULLCLOSE(pCtx, pvf->pFile);

	SG_NULLFREE(pCtx, pvf);
	*ppvf = NULL;

	return;
fail:
	SG_STRING_NULLFREE(pCtx, pstr);
}
void sg_sync_client__http__request_fragball(
    SG_context* pCtx,
    SG_sync_client* pSyncClient,
    SG_vhash* pvhRequest,
    SG_bool bProgressIfPossible,
    const SG_pathname* pStagingPathname,
    char** ppszFragballName)
{
    char* pszFragballName = NULL;
    SG_pathname* pPathFragball = NULL;
    SG_string* pstrRequest = NULL;
    char* pszUrl = NULL;

    SG_NULLARGCHECK_RETURN(pSyncClient);

    SG_ERR_CHECK(  SG_allocN(pCtx, SG_TID_MAX_BUFFER_LENGTH, pszFragballName)  );
    SG_ERR_CHECK(  SG_tid__generate(pCtx, pszFragballName, SG_TID_MAX_BUFFER_LENGTH)  );


    SG_ERR_CHECK(  _get_sync_url(pCtx, pSyncClient->psz_remote_repo_spec, SYNC_URL_SUFFIX FRAGBALL_URL_SUFFIX, NULL, NULL, &pszUrl)  );


    if (pvhRequest)
    {
        SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, &pstrRequest)  );
        SG_ERR_CHECK(  SG_vhash__to_json(pCtx, pvhRequest, pstrRequest)  );
    }

    SG_ERR_CHECK(  SG_pathname__alloc__pathname_sz(pCtx, &pPathFragball, pStagingPathname, (const char*)pszFragballName)  );
    SG_ERR_CHECK(  do_url(
                       pCtx,
                       pszUrl,
                       "POST",
                       pstrRequest ? SG_string__sz(pstrRequest) : NULL,
                       pSyncClient->psz_username,
                       pSyncClient->psz_password,
                       NULL,
                       pPathFragball,
                       bProgressIfPossible
                   )  );


    SG_RETURN_AND_NULL(pszFragballName, ppszFragballName);

    /* fall through */
fail:
    SG_NULLFREE(pCtx, pszFragballName);
    SG_PATHNAME_NULLFREE(pCtx, pPathFragball);
    SG_NULLFREE(pCtx, pszUrl);
    SG_STRING_NULLFREE(pCtx, pstrRequest);
}
void sg_sync_client__http__pull_clone(
    SG_context* pCtx,
    SG_sync_client* pSyncClient,
    SG_vhash* pvh_clone_request,
    const SG_pathname* pStagingPathname,
    char** ppszFragballName)
{
    SG_vhash* pvhRequest = NULL;
    char* pszFragballName = NULL;
    SG_pathname* pPathFragball = NULL;
    SG_string* pstrRequest = NULL;
    char* pszUrl = NULL;

    SG_ERR_CHECK(  SG_log__push_operation(pCtx, "Requesting repository from server", SG_LOG__FLAG__NONE)  );

    SG_NULLARGCHECK_RETURN(pSyncClient);

    SG_ERR_CHECK(  SG_allocN(pCtx, SG_TID_MAX_BUFFER_LENGTH, pszFragballName)  );
    SG_ERR_CHECK(  SG_tid__generate(pCtx, pszFragballName, SG_TID_MAX_BUFFER_LENGTH)  );

    SG_ERR_CHECK(  _get_sync_url(pCtx, pSyncClient->psz_remote_repo_spec, SYNC_URL_SUFFIX FRAGBALL_URL_SUFFIX, NULL, NULL, &pszUrl)  );


    SG_ERR_CHECK(  SG_VHASH__ALLOC(pCtx, &pvhRequest)  );
    SG_ERR_CHECK(  SG_vhash__add__null(pCtx, pvhRequest, SG_SYNC_STATUS_KEY__CLONE)  );
    if (pvh_clone_request)
    {
        SG_ERR_CHECK(  SG_vhash__addcopy__vhash(pCtx, pvhRequest, SG_SYNC_STATUS_KEY__CLONE_REQUEST, pvh_clone_request)  );
    }
    SG_ERR_CHECK(  SG_STRING__ALLOC__RESERVE(pCtx, &pstrRequest, 50)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, pvhRequest, pstrRequest)  );

    SG_ERR_CHECK(  SG_pathname__alloc__pathname_sz(pCtx, &pPathFragball, pStagingPathname, (const char*)pszFragballName)  );
    SG_ERR_CHECK(  do_url(pCtx, pszUrl, "POST", SG_string__sz(pstrRequest), pSyncClient->psz_username, pSyncClient->psz_password, NULL, pPathFragball, SG_TRUE)  );

    SG_RETURN_AND_NULL(pszFragballName, ppszFragballName);

    /* fall through */
fail:
    SG_log__pop_operation(pCtx);
    SG_NULLFREE(pCtx, pszFragballName);
    SG_VHASH_NULLFREE(pCtx, pvhRequest);
    SG_PATHNAME_NULLFREE(pCtx, pPathFragball);
    SG_NULLFREE(pCtx, pszUrl);
    SG_STRING_NULLFREE(pCtx, pstrRequest);
}
Example #7
0
/**
 * Write a vhash table in JSON format.  This function handles all the details of
 * setting up the SG_jsonwriter and places the output stream in the given string.
 */
void SG_dbrecord__to_json(SG_context* pCtx, SG_dbrecord* prec, SG_string* pStr)
{
	SG_NULLARGCHECK_RETURN(prec);
	SG_ERR_CHECK_RETURN(  SG_vhash__sort(pCtx, prec->pvh, SG_FALSE, SG_vhash_sort_callback__increasing)  );
	SG_ERR_CHECK_RETURN(  SG_vhash__to_json(pCtx, prec->pvh, pStr)  );
}
static void SG_db__make_delta_from_path(
    SG_context* pCtx,
    SG_repo* pRepo,
    SG_uint64 dagnum,
    SG_varray* pva_path,
    SG_uint32 flags,
    SG_vhash* pvh_add,
    SG_vhash* pvh_remove
    )
{
#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_int64 t1 = -1;
    SG_int64 t2 = -1;
    SG_vhash* new_pvh_add = NULL;
    SG_vhash* new_pvh_remove = NULL;
    SG_vhash* old_pvh_add = NULL;
    SG_vhash* old_pvh_remove = NULL;
    SG_string* old_pstr = NULL;
    SG_string* new_pstr = NULL;

    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &new_pvh_add, pvh_add)  );
    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &new_pvh_remove, pvh_remove)  );
    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &old_pvh_add, pvh_add)  );
    SG_ERR_CHECK(  SG_vhash__alloc__copy(pCtx, &old_pvh_remove, pvh_remove)  );

    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t1)  );
    SG_ERR_CHECK(  old_SG_db__make_delta_from_path(
                pCtx,
                pRepo,
                dagnum,
                pva_path,
                old_pvh_add,
                old_pvh_remove
                )  );
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t2)  );
    {
        SG_uint32 path_length = 0;
        SG_ERR_CHECK(  SG_varray__count(pCtx, pva_path, &path_length)  );
        fprintf(stderr, "make_delta_from_path (%d)\n", path_length);
    }
    fprintf(stderr, "  time old %d ms\n", (int) (t2 - t1));

    SG_ERR_CHECK(  SG_vhash__sort(pCtx, old_pvh_add, SG_FALSE, SG_vhash_sort_callback__increasing)  );
    SG_ERR_CHECK(  SG_vhash__sort(pCtx, old_pvh_remove, SG_FALSE, SG_vhash_sort_callback__increasing)  );

    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t1)  );
    SG_ERR_CHECK(  SG_repo__dbndx__make_delta_from_path(
                pCtx,
                pRepo,
                dagnum,
                pva_path,
                0,
                new_pvh_add,
                new_pvh_remove
                )  );
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t2)  );
    fprintf(stderr, "  time new %d ms\n", (int) (t2 - t1));
    SG_ERR_CHECK(  SG_vhash__sort(pCtx, new_pvh_add, SG_FALSE, SG_vhash_sort_callback__increasing)  );
    SG_ERR_CHECK(  SG_vhash__sort(pCtx, new_pvh_remove, SG_FALSE, SG_vhash_sort_callback__increasing)  );

    SG_ERR_CHECK(  SG_string__alloc(pCtx, &old_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, old_pvh_add, old_pstr)  );
    SG_ERR_CHECK(  SG_string__alloc(pCtx, &new_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, new_pvh_add, new_pstr)  );

    if (0 != strcmp(SG_string__sz(old_pstr), SG_string__sz(new_pstr)))
    {
        fprintf(stderr, "oldway:\n");
        SG_VHASH_STDERR(old_pvh_add);
        fprintf(stderr, "new:\n");
        SG_VHASH_STDERR(new_pvh_add);

        SG_ERR_THROW(  SG_ERR_UNSPECIFIED  );
    }

    SG_STRING_NULLFREE(pCtx, old_pstr);
    SG_STRING_NULLFREE(pCtx, new_pstr);

    SG_ERR_CHECK(  SG_string__alloc(pCtx, &old_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, old_pvh_remove, old_pstr)  );
    SG_ERR_CHECK(  SG_string__alloc(pCtx, &new_pstr)  );
    SG_ERR_CHECK(  SG_vhash__to_json(pCtx, new_pvh_remove, new_pstr)  );

    if (0 != strcmp(SG_string__sz(old_pstr), SG_string__sz(new_pstr)))
    {
        fprintf(stderr, "oldway:\n");
        SG_VHASH_STDERR(old_pvh_remove);
        fprintf(stderr, "new:\n");
        SG_VHASH_STDERR(new_pvh_remove);

        SG_ERR_THROW(  SG_ERR_UNSPECIFIED  );
    }
#endif

#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t1)  );
#endif
    SG_ERR_CHECK(  SG_repo__dbndx__make_delta_from_path(
                pCtx,
                pRepo,
                dagnum,
                pva_path,
                flags,
                pvh_add,
                pvh_remove
                )  );
#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_ERR_CHECK(  SG_time__get_milliseconds_since_1970_utc(pCtx, &t2)  );
    fprintf(stderr, "  time NEW %d ms\n", (int) (t2 - t1));
#endif

fail:
#if SG_DOUBLE_CHECK__CALC_DELTA
    SG_STRING_NULLFREE(pCtx, old_pstr);
    SG_STRING_NULLFREE(pCtx, new_pstr);

    SG_VHASH_NULLFREE(pCtx, old_pvh_add);
    SG_VHASH_NULLFREE(pCtx, old_pvh_remove);
    SG_VHASH_NULLFREE(pCtx, new_pvh_add);
    SG_VHASH_NULLFREE(pCtx, new_pvh_remove);
#endif
    ;
}