void SG_sync_remote__heartbeat(
	SG_context* pCtx,
	SG_repo* pRepo,
	SG_vhash** ppvh)
{
	SG_vhash* pvh = NULL;
	char* pszRepoId = NULL;
	char* pszAdminId = NULL;
	char* pszHashMethod = NULL;

	SG_ERR_CHECK(  SG_VHASH__ALLOC(pCtx, &pvh)  );
	
	SG_ERR_CHECK(  SG_repo__get_repo_id(pCtx, pRepo, &pszRepoId)  );
	SG_ERR_CHECK(  SG_repo__get_admin_id(pCtx, pRepo, &pszAdminId)  );
	SG_ERR_CHECK(  SG_repo__get_hash_method(pCtx, pRepo, &pszHashMethod)  );
	SG_ERR_CHECK(  SG_vhash__add__string__sz(pCtx, pvh, SG_SYNC_REPO_INFO_KEY__REPO_ID, pszRepoId)  );
	SG_ERR_CHECK(  SG_vhash__add__string__sz(pCtx, pvh, SG_SYNC_REPO_INFO_KEY__ADMIN_ID, pszAdminId)  );
	SG_ERR_CHECK(  SG_vhash__add__string__sz(pCtx, pvh, SG_SYNC_REPO_INFO_KEY__HASH_METHOD, pszHashMethod)  );

	*ppvh = pvh;
	pvh = NULL;

	/* fall through */
fail:
	SG_VHASH_NULLFREE(pCtx, pvh);
	SG_NULLFREE(pCtx, pszRepoId);
	SG_NULLFREE(pCtx, pszAdminId);
	SG_NULLFREE(pCtx, pszHashMethod);

}
示例#2
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);

}
void u0052_zip__test_2(SG_context * pCtx)
{
    const char* psz_text = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

    SG_uint32 len_orig = SG_STRLEN(psz_text) + 1;
    SG_byte* p_compressed = NULL;
    SG_byte* p_uncompressed = NULL;
    SG_uint32 len_compressed = 0;

    SG_ERR_CHECK(  SG_zlib__deflate__memory(
                pCtx, 
                (SG_byte*) psz_text,
                len_orig,
                &p_compressed,
                &len_compressed
                )  );

    SG_ERR_CHECK(  SG_allocN(pCtx, len_orig, p_uncompressed)  );
    SG_ERR_CHECK(  SG_zlib__inflate__memory(
                pCtx,
                p_compressed,
                len_compressed,
                p_uncompressed,
                len_orig
                )  );

    VERIFY_COND("name", (0 == strcmp(psz_text, (char*) p_uncompressed)));

fail:
    SG_NULLFREE(pCtx, p_compressed);
    SG_NULLFREE(pCtx, p_uncompressed);
}
void SG_unzip__currentfile__close(SG_context* pCtx, SG_unzip* s)
{

    file_in_zip_read_info_s* pfile_in_zip_read_info;

    SG_NULLARGCHECK_RETURN( s );

    pfile_in_zip_read_info = s->pfile_in_zip_read;

	SG_ARGCHECK_RETURN((pfile_in_zip_read_info!=NULL), s);

    if (pfile_in_zip_read_info->rest_read_uncompressed == 0)
    {
        if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait)
        {
            SG_ERR_THROW(  SG_ERR_ZIP_CRC  );
        }
    }

    SG_NULLFREE(pCtx, pfile_in_zip_read_info->read_buffer);
    pfile_in_zip_read_info->read_buffer = NULL;
    if (pfile_in_zip_read_info->stream_initialised)
    {
        inflateEnd(&pfile_in_zip_read_info->stream);
    }

    pfile_in_zip_read_info->stream_initialised = 0;
    SG_NULLFREE(pCtx, pfile_in_zip_read_info);

    s->pfile_in_zip_read=NULL;

fail:
    return;
}
void SG_mrg__free(SG_context * pCtx, SG_mrg * pMrg)
{
	if (!pMrg)
		return;

	//////////////////////////////////////////////////////////////////

	pMrg->pMergeArgs = NULL;			// we do not own this
	pMrg->pWcTx = NULL;					// we do not own this

	//////////////////////////////////////////////////////////////////

	SG_VHASH_NULLFREE(pCtx, pMrg->pvhPile);
	SG_NULLFREE(pCtx, pMrg->pszHid_StartingBaseline);
	SG_NULLFREE(pCtx, pMrg->pszBranchName_Starting);
	SG_NULLFREE(pCtx, pMrg->pszHidTarget);

	//////////////////////////////////////////////////////////////////

	SG_DAGLCA_NULLFREE(pCtx,pMrg->pDagLca);
	SG_MRG_CSET_NULLFREE(pCtx, pMrg->pMrgCSet_LCA);
	SG_MRG_CSET_NULLFREE(pCtx, pMrg->pMrgCSet_Baseline);
	SG_MRG_CSET_NULLFREE(pCtx, pMrg->pMrgCSet_Other);
	SG_MRG_CSET_NULLFREE(pCtx,pMrg->pMrgCSet_FinalResult);
	SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx,pMrg->prbCSets_Aux,(SG_free_callback *)SG_mrg_cset__free);

	SG_VECTOR_I64_NULLFREE(pCtx, pMrg->pVecRevertAllKillList);

	SG_NULLFREE(pCtx, pMrg);
}
void SG_mrg_cset_entry_conflict__free(SG_context * pCtx,
									  SG_mrg_cset_entry_conflict * pMrgCSetEntryConflict)
{
	if (!pMrgCSetEntryConflict)
		return;

	SG_VECTOR_I64_NULLFREE(pCtx, pMrgCSetEntryConflict->pVec_MrgCSetEntryNeq_Changes);
	SG_VECTOR_NULLFREE(pCtx, pMrgCSetEntryConflict->pVec_MrgCSetEntry_Changes);	// we do not own the pointers within
	SG_VECTOR_NULLFREE(pCtx, pMrgCSetEntryConflict->pVec_MrgCSet_Deletes);		// we do not own the pointers within

	// for the collapsable rbUnique's we own the vectors in the rbtree-values, but not the pointers within the vector
	SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx, pMrgCSetEntryConflict->prbUnique_AttrBits,          (SG_free_callback *)SG_vector__free);
	SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx, pMrgCSetEntryConflict->prbUnique_Entryname,         (SG_free_callback *)SG_vector__free);
	SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx, pMrgCSetEntryConflict->prbUnique_GidParent,         (SG_free_callback *)SG_vector__free);
	SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx, pMrgCSetEntryConflict->prbUnique_Symlink_HidBlob,   (SG_free_callback *)SG_vector__free);
	SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx, pMrgCSetEntryConflict->prbUnique_Submodule_HidBlob, (SG_free_callback *)SG_vector__free);
	SG_RBTREE_NULLFREE_WITH_ASSOC(pCtx, pMrgCSetEntryConflict->prbUnique_File_HidBlob,      (SG_free_callback *)SG_vector__free);

	SG_VECTOR_NULLFREE(pCtx, pMrgCSetEntryConflict->pVec_MrgCSetEntry_OtherDirsInCycle);	// we do not own the pointers within
	SG_STRING_NULLFREE(pCtx, pMrgCSetEntryConflict->pStringPathCycleHint);

	SG_FILETOOL_NULLFREE(pCtx, pMrgCSetEntryConflict->pMergeTool);

	SG_PATHNAME_NULLFREE(pCtx, pMrgCSetEntryConflict->pPathTempDirForFile);
	SG_PATHNAME_NULLFREE(pCtx, pMrgCSetEntryConflict->pPathTempFile_Ancestor);
	SG_PATHNAME_NULLFREE(pCtx, pMrgCSetEntryConflict->pPathTempFile_Result);
	SG_PATHNAME_NULLFREE(pCtx, pMrgCSetEntryConflict->pPathTempFile_Baseline);
	SG_PATHNAME_NULLFREE(pCtx, pMrgCSetEntryConflict->pPathTempFile_Other);

	SG_NULLFREE(pCtx, pMrgCSetEntryConflict->pszHidDisposable);
	SG_NULLFREE(pCtx, pMrgCSetEntryConflict->pszHidGenerated);

	SG_NULLFREE(pCtx, pMrgCSetEntryConflict);
}
示例#7
0
void MyFn(create_zero_byte_blob)(SG_context* pCtx,
								 SG_repo* pRepo)
{
	struct z
	{
		const char * pszHashMethod;
		const char * pszTrivialHash;
	};
	struct z az[] = { { "SHA1/160", 	"da39a3ee5e6b4b0d3255bfef95601890afd80709" },
					  { "SHA2/256",		"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" },
					  { "SHA2/384",		"38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274edebfe76f65fbd51ad2f14898b95b" },
					  { "SHA2/512",		"cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" },
	};

	char* pszidHidBlob1 = NULL;
	char * pbuf1 = NULL;
	char * pbuf2 = NULL;
	SG_uint64 lenBuf2;
	SG_repo_tx_handle* pTx = NULL;
	SG_uint32 lenBuf1 = 0;
	char * pszHashMethod = NULL;
	SG_uint32 k, kLimit;

	pbuf1 = (char *)SG_calloc(1,lenBuf1+1);

	VERIFY_ERR_CHECK_DISCARD(  SG_repo__begin_tx(pCtx, pRepo, &pTx)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_repo__store_blob_from_memory(pCtx, pRepo,pTx,NULL,SG_FALSE,(SG_byte *)pbuf1,lenBuf1,&pszidHidBlob1)  );
	VERIFY_ERR_CHECK_DISCARD(  SG_repo__commit_tx(pCtx, pRepo, &pTx)  );

	INFOP("create_zero_byte_blob",("Created blob [%s]",(pszidHidBlob1)));

		//////////////////////////////////////////////////////////////////
	// fetch blob into a new buffer and verify that it matches.

	VERIFY_ERR_CHECK_DISCARD(  SG_repo__fetch_blob_into_memory(pCtx, pRepo,pszidHidBlob1,(SG_byte **)&pbuf2,&lenBuf2)  );
	VERIFY_COND("create_zero_byte_blob(fetch blob)",(lenBuf2 == (SG_uint64)lenBuf1));

	VERIFY_COND("create_zero_byte_blob(memcmp)",(memcmp(pbuf1,pbuf2,lenBuf1)==0));

	VERIFY_ERR_CHECK_DISCARD(  SG_repo__get_hash_method(pCtx, pRepo, &pszHashMethod)  );
	kLimit = SG_NrElements(az);
	for (k=0; k<kLimit; k++)
	{
		if (strcmp(pszHashMethod,az[k].pszHashMethod) == 0)
		{
			// The empty blob should always have this hid
			VERIFY_COND("zero byte blob hid mismatch",
						strcmp(pszidHidBlob1, az[k].pszTrivialHash) == 0);
		}
	}

	//////////////////////////////////////////////////////////////////
	// cleanup

	SG_NULLFREE(pCtx, pbuf1);
	SG_NULLFREE(pCtx, pbuf2);
	SG_NULLFREE(pCtx, pszidHidBlob1);
	SG_NULLFREE(pCtx, pszHashMethod);
}
void SG_unzip__fetch_next_file_into_file(SG_context* pCtx, SG_unzip* punzip, SG_pathname* pPath, SG_bool* pb, const char** ppsz_name, SG_uint64* piLength)
{
   SG_byte* pBytes = NULL;
    SG_uint32 sofar = 0;
    SG_uint32 got = 0;
    SG_file* pFile = NULL;
    SG_bool b = SG_FALSE;
    SG_uint64 len = 0;
    const char* psz_name = NULL;

    SG_ERR_CHECK(  SG_unzip__goto_next_file(pCtx, punzip, &b, &psz_name, &len)  );
    if (!b)
    {
        *pb = SG_FALSE;
        goto done;
    }

	SG_ERR_CHECK(  SG_malloc(pCtx, (SG_uint32)SG_STREAMING_BUFFER_SIZE, &pBytes)  );

    SG_ERR_CHECK(  SG_file__open__pathname(pCtx, pPath, SG_FILE_WRONLY | SG_FILE_CREATE_NEW, 0644, &pFile)  );

    SG_ERR_CHECK(  SG_unzip__currentfile__open(pCtx, punzip)  );
    while (sofar < (SG_uint32) len)
    {
        SG_uint32 want = 0;
        if ((len - sofar) > SG_STREAMING_BUFFER_SIZE)
        {
            want = SG_STREAMING_BUFFER_SIZE;
        }
        else
        {
            want = (SG_uint32) (len - sofar);
        }
        SG_ERR_CHECK(  SG_unzip__currentfile__read(pCtx, punzip, pBytes, want, &got)  );
        if (!got)
        {
            SG_ERR_THROW(  SG_ERR_UNSPECIFIED  ); /* TODO better error */
        }
        SG_ERR_CHECK(  SG_file__write(pCtx, pFile, got, pBytes, NULL)  );

        sofar += got;
    }
    SG_NULLFREE(pCtx, pBytes);
    SG_ERR_CHECK(  SG_file__close(pCtx, &pFile)  );
    SG_ERR_CHECK(  SG_unzip__currentfile__close(pCtx, punzip)  );

    *pb = SG_TRUE;
    *ppsz_name = psz_name;
    *piLength = len;

done:
    /* fall through */

fail:
    SG_FILE_NULLCLOSE(pCtx, pFile);
    SG_NULLFREE(pCtx, pBytes);

}
示例#9
0
static void _resolve__external_tool__free(SG_context * pCtx, _resolve__external_tool * pET)
{
	if (!pET)
		return;

	SG_NULLFREE(pCtx, pET->pszName);
	SG_NULLFREE(pCtx, pET->pszExe);
	SG_NULLFREE(pCtx, pET);
}
void _set_curl_options(SG_context* pCtx, CURL* pCurl)
{
	char * szServerFiles = NULL;
	char * szVerifyCerts = NULL;
	SG_pathname *pServerFiles = NULL;
	CURLcode rc = CURLE_OK;
#ifdef WINDOWS
	SG_bool bExists = SG_FALSE;
	SG_bool bVerifyCerts = SG_TRUE;
#endif
	SG_ERR_CHECK(  SG_localsettings__get__sz(pCtx, SG_LOCALSETTING__VERIFY_SSL_CERTS, NULL, &szVerifyCerts, NULL)  );
	if (szVerifyCerts != NULL && (SG_strcmp__null(szVerifyCerts, "false") == 0 || SG_strcmp__null(szVerifyCerts, "FALSE")  == 0))
	{
#ifdef WINDOWS
		bVerifyCerts = SG_FALSE;
#endif
		rc = curl_easy_setopt(pCurl, CURLOPT_SSL_VERIFYPEER, SG_FALSE);		
	}

	if (rc)
		SG_ERR_THROW(SG_ERR_LIBCURL(rc));


#ifdef WINDOWS
	if (bVerifyCerts)
	{
		SG_ERR_CHECK(  SG_localsettings__get__sz(pCtx, SG_LOCALSETTING__SERVER_FILES, NULL, &szServerFiles, NULL)  );
		if (szServerFiles)
		{
			SG_ERR_CHECK(  SG_pathname__alloc__sz(pCtx, &pServerFiles, szServerFiles)  );
			SG_ERR_CHECK(  SG_pathname__append__from_sz(pCtx, pServerFiles, "ssl") );
			SG_ERR_CHECK(  SG_pathname__append__from_sz(pCtx, pServerFiles, "curl-ca-bundle.crt") );
			SG_ERR_CHECK(  SG_fsobj__exists__pathname(pCtx, pServerFiles, &bExists, NULL, NULL)  );
		}

		if (bExists)
		{
			rc = curl_easy_setopt(pCurl, CURLOPT_CAINFO, SG_pathname__sz(pServerFiles));	
			if (rc)
				SG_ERR_THROW(SG_ERR_LIBCURL(rc));
		}
		else
		{
			if (pServerFiles)
				SG_ERR_CHECK(  SG_log__report_warning(pCtx, "Could not find root certificate file. Looked for it at: %s. SSL connections will not work.", SG_pathname__sz(pServerFiles))  );
			else
				SG_ERR_CHECK(  SG_log__report_warning(pCtx, "Could not find root certificate file: no server/files path is configured. SSL connections will not work.")  );
		}
	}
#endif

fail:
	SG_PATHNAME_NULLFREE(pCtx, pServerFiles);
	SG_NULLFREE(pCtx, szServerFiles);
	SG_NULLFREE(pCtx, szVerifyCerts);
}
示例#11
0
static void _add_dagnodes_until_connected(SG_context* pCtx, 
										  SG_vhash** ppvhStagingStatus, 
										  sg_pull_instance_data* pMe, 
										  SG_client* pClient)
{
	SG_bool disconnected = SG_FALSE;
	SG_vhash* pvhFragballRequest = NULL;
	char* pszFragballName = NULL;
	SG_vhash* pvhRequestStatus = NULL;
	const SG_pathname* pStagingPathname;

	SG_ERR_CHECK(  SG_staging__get_pathname(pCtx, pMe->pStaging, &pStagingPathname)  );

	SG_ERR_CHECK(  SG_vhash__has(pCtx, *ppvhStagingStatus, SG_SYNC_STATUS_KEY__DAGS, &disconnected)  );
	while (disconnected)
	{

#if TRACE_PULL
		SG_ERR_CHECK(  SG_vhash_debug__dump_to_console__named(pCtx, *ppvhStagingStatus, "pull staging status")  );
#endif
		// There's at least one dag with connection problems.  
		
		// Convert the staging status vhash into a fragball request vhash.
		pvhFragballRequest = *ppvhStagingStatus;
		*ppvhStagingStatus = NULL;
		SG_ERR_CHECK(  SG_vhash__add__int64(pCtx, pvhFragballRequest, SG_SYNC_STATUS_KEY__GENERATIONS, GENERATIONS_PER_ROUNDTRIP)  );

		SG_ERR_CHECK(  SG_client__pull_request_fragball(pCtx, pClient, pvhFragballRequest, pStagingPathname, &pszFragballName, &pvhRequestStatus)  );

		/* Ian TODO: inspect pvhRequestStatus */

		SG_VHASH_NULLFREE(pCtx, pvhRequestStatus);
		SG_VHASH_NULLFREE(pCtx, pvhFragballRequest);

		SG_ERR_CHECK(  SG_staging__slurp_fragball(pCtx, pMe->pStaging, (const char*)pszFragballName)  );
		SG_NULLFREE(pCtx, pszFragballName);

		SG_ERR_CHECK(  SG_staging__check_status(pCtx, pMe->pStaging, SG_TRUE, SG_FALSE, SG_FALSE, SG_FALSE, SG_FALSE, ppvhStagingStatus)  );

		SG_ERR_CHECK(  SG_vhash__has(pCtx, *ppvhStagingStatus, SG_SYNC_STATUS_KEY__DAGS, &disconnected)  );

#if TRACE_PULL
		SG_ERR_CHECK(  SG_vhash_debug__dump_to_console__named(pCtx, *ppvhStagingStatus, "pull staging status")  );
#endif
	}

	SG_ERR_CHECK_RETURN(  SG_context__msg__emit(pCtx, "done")  );

	/* fall through */
fail:
	SG_VHASH_NULLFREE(pCtx, *ppvhStagingStatus);
	SG_VHASH_NULLFREE(pCtx, pvhFragballRequest);
	SG_NULLFREE(pCtx, pszFragballName);
	SG_VHASH_NULLFREE(pCtx, pvhRequestStatus);
	SG_ERR_IGNORE(  SG_context__msg__emit(pCtx, "\n")  );
}
static void _handle_free(SG_context * pCtx, sg_sync_client_http_push_handle* pPush)
{
    if (pPush)
    {
        if ( (pPush)->pszPushId )
            SG_NULLFREE(pCtx, pPush->pszPushId);

        SG_NULLFREE(pCtx, pPush);
    }
}
示例#13
0
void SG_dbrecord__free(SG_context * pCtx, SG_dbrecord* prec)
{
	if (!prec)
		return;

	SG_VHASH_NULLFREE(pCtx, prec->pvh);
	SG_NULLFREE(pCtx, prec->pid);

	SG_NULLFREE(pCtx, prec);
}
sg_treediff_cache::~sg_treediff_cache()
{
	SG_context * pCtx;
	SG_context__alloc(&pCtx);
	SG_NULLFREE(pCtx, m_pPreviousCommand);
	SG_NULLFREE(pCtx, m_pPreviousResult);
	m_timeLastRequest = 0;
	CloseTransactionIfNecessary(pCtx);
	SG_CONTEXT_NULLFREE(pCtx);
}
示例#15
0
void u0051_hidlookup_test__1(SG_context * pCtx, SG_pathname* pPathTopDir)
{
	char bufName[SG_TID_MAX_BUFFER_LENGTH];
	SG_pathname* pPathWorkingDir = NULL;
	SG_pathname* pPathFile = NULL;
    SG_dagnode* pdn = NULL;
    const char* psz_hid_cs = NULL;
    SG_repo* pRepo = NULL;
    char buf_partial[256];
    char* psz_result = NULL;
    SG_audit q;

	VERIFY_ERR_CHECK(  SG_tid__generate2(pCtx, bufName, sizeof(bufName), 32)  );

	/* create the working dir */
	VERIFY_ERR_CHECK(  SG_PATHNAME__ALLOC__PATHNAME_SZ(pCtx, &pPathWorkingDir, pPathTopDir, bufName)  );
	VERIFY_ERR_CHECK(  SG_fsobj__mkdir__pathname(pCtx, pPathWorkingDir)  );

    /* add stuff */
	VERIFY_ERR_CHECK(  u0051_hidlookup__create_file__numbers(pCtx, pPathWorkingDir, "aaa", 20)  );

    /* create the repo */
	VERIFY_ERR_CHECK(  _ut_pt__new_repo(pCtx, bufName, pPathWorkingDir)  );
	VERIFY_ERR_CHECK(  _ut_pt__addremove(pCtx, pPathWorkingDir)  );
	VERIFY_ERR_CHECK(  u0051_hidlookup__commit_all(pCtx, pPathWorkingDir, &pdn)  );

    VERIFY_ERR_CHECK(  SG_dagnode__get_id_ref(pCtx, pdn, &psz_hid_cs)  );

	VERIFY_ERR_CHECK(  SG_repo__open_repo_instance(pCtx, bufName, &pRepo)  );

    VERIFY_ERR_CHECK(  SG_audit__init(pCtx, &q, pRepo, SG_AUDIT__WHEN__NOW, SG_AUDIT__WHO__FROM_SETTINGS)  );
    VERIFY_ERR_CHECK(  SG_vc_tags__add(pCtx, pRepo, psz_hid_cs, "remember", &q)  );

    VERIFY_ERR_CHECK(  SG_strcpy(pCtx, buf_partial, sizeof(buf_partial), psz_hid_cs)  );
    buf_partial[10] = 0;

	VERIFY_ERR_CHECK(  SG_repo__hidlookup__dagnode(pCtx, pRepo, SG_DAGNUM__VERSION_CONTROL, buf_partial, &psz_result)  );
    VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs)));
    SG_NULLFREE(pCtx, psz_result);

    VERIFY_ERR_CHECK(  SG_repo__hidlookup__blob(pCtx, pRepo, buf_partial, &psz_result)  );
    VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs)));
    SG_NULLFREE(pCtx, psz_result);

	VERIFY_ERR_CHECK(  SG_vc_tags__lookup__tag(pCtx, pRepo, "remember", &psz_result)  );
    VERIFY_COND("found", (0 == strcmp(psz_result, psz_hid_cs)));
    SG_NULLFREE(pCtx, psz_result);

fail:
    SG_NULLFREE(pCtx, psz_result);
    SG_REPO_NULLFREE(pCtx, pRepo);
    SG_DAGNODE_NULLFREE(pCtx, pdn);
	SG_PATHNAME_NULLFREE(pCtx, pPathWorkingDir);
	SG_PATHNAME_NULLFREE(pCtx, pPathFile);
}
示例#16
0
static void _free_instance_data(SG_context* pCtx,
								sg_pull_instance_data* pMe)
{
	if (pMe)
	{
		SG_NULLFREE(pCtx, pMe->pszPullId);
		SG_STAGING_NULLFREE(pCtx, pMe->pStaging);
		SG_REPO_NULLFREE(pCtx, pMe->pPullIntoRepo);
		SG_NULLFREE(pCtx, pMe);
	}
}
示例#17
0
void SG_stringarray__free(SG_context * pCtx, SG_stringarray* pThis)
{
	if (!pThis)
	{
		return;
	}

	SG_NULLFREE(pCtx, pThis->aStrings);
	SG_STRPOOL_NULLFREE(pCtx, pThis->pStrPool);
	SG_NULLFREE(pCtx, pThis);
}
示例#18
0
void SG_vector_i64__free(SG_context * pCtx, SG_vector_i64 * pVector)
{
	if (!pVector)
		return;

	SG_NULLFREE(pCtx, pVector->m_array);

	pVector->m_uiSizeInUse = 0;
	pVector->m_uiAllocated = 0;
	SG_NULLFREE(pCtx, pVector);
}
示例#19
0
static void _add_blobs_until_done(SG_context* pCtx, 
								  SG_staging* pStaging, 
								  SG_client* pClient) 
{
	SG_bool need_blobs = SG_FALSE;
	SG_vhash* pvhFragballRequest = NULL;
	char* pszFragballName = NULL;
	SG_vhash* pvhRequestStatus = NULL;
	const SG_pathname* pStagingPathname = NULL;
	SG_vhash* pvhStagingStatus = NULL;

	SG_ERR_CHECK_RETURN(  SG_context__msg__emit(pCtx, "Retrieving blobs...")  );

	SG_ERR_CHECK(  SG_staging__check_status(pCtx, pStaging, SG_FALSE, SG_FALSE, SG_FALSE, SG_TRUE, SG_TRUE, &pvhStagingStatus)  );

	SG_ERR_CHECK(  SG_vhash__has(pCtx, pvhStagingStatus, SG_SYNC_STATUS_KEY__BLOBS, &need_blobs)  );
	
	if (need_blobs)
		SG_ERR_CHECK(  SG_staging__get_pathname(pCtx, pStaging, &pStagingPathname)  );

	while (need_blobs)
	{
		pvhFragballRequest = pvhStagingStatus;
		pvhStagingStatus = NULL;

		SG_ERR_CHECK(  SG_client__pull_request_fragball(pCtx, pClient, pvhFragballRequest, pStagingPathname, &pszFragballName, &pvhRequestStatus)  );

		/* Ian TODO: inspect pvhRequestStatus */

		SG_VHASH_NULLFREE(pCtx, pvhRequestStatus);
		SG_VHASH_NULLFREE(pCtx, pvhFragballRequest);

		SG_ERR_CHECK(  SG_staging__slurp_fragball(pCtx, pStaging, (const char*)pszFragballName)  );
		SG_NULLFREE(pCtx, pszFragballName);

		SG_ERR_CHECK(  SG_staging__check_status(pCtx, pStaging, SG_FALSE, SG_FALSE, SG_FALSE, SG_TRUE, SG_TRUE, &pvhStagingStatus)  );

#if TRACE_PULL
		SG_ERR_CHECK(  SG_vhash_debug__dump_to_console__named(pCtx, pvhStagingStatus, "pull staging status")  );
#endif

		SG_ERR_CHECK(  SG_vhash__has(pCtx, pvhStagingStatus, SG_SYNC_STATUS_KEY__BLOBS, &need_blobs)  );
	}

	SG_ERR_CHECK_RETURN(  SG_context__msg__emit(pCtx, "done")  );

	/* fall through */
fail:
	SG_VHASH_NULLFREE(pCtx, pvhStagingStatus);
	SG_VHASH_NULLFREE(pCtx, pvhFragballRequest);
	SG_NULLFREE(pCtx, pszFragballName);
	SG_VHASH_NULLFREE(pCtx, pvhRequestStatus);
	SG_ERR_IGNORE(  SG_context__msg__emit(pCtx, "\n")  );
}
void sg_treediff_cache::RememberLastQuery(SG_context * pCtx, const char * pszLastQuery, const char * pszLastResult)
{
	//Free the previous results.
	SG_NULLFREE(pCtx, m_pPreviousResult);
	SG_NULLFREE(  pCtx, m_pPreviousCommand);

	//Save the current  command and result to reuse if necessary
	SG_ERR_CHECK(  SG_STRDUP(pCtx, pszLastResult, &m_pPreviousResult )  );
	SG_ERR_CHECK(  SG_STRDUP(pCtx, pszLastQuery, &m_pPreviousCommand)  );
fail:
	return;
}
示例#21
0
void SG_group__add_users(
	SG_context* pCtx,
    SG_repo* pRepo,
    const char* psz_group_name,
    const char** paszMemberNames,
    SG_uint32 count_names
    )
{
    char* psz_hid_cs_leaf = NULL;
    SG_zingtx* pztx = NULL;
    SG_dagnode* pdn = NULL;
    SG_changeset* pcs = NULL;
    SG_audit q;
    SG_uint32 i = 0;
    char* psz_recid_group = NULL;
    char* psz_recid_user = NULL;

    SG_ERR_CHECK(  SG_zing__get_leaf__fail_if_needs_merge(pCtx, pRepo, SG_DAGNUM__USERS, &psz_hid_cs_leaf)  );

    SG_ERR_CHECK(  SG_audit__init(pCtx, &q, pRepo, SG_AUDIT__WHEN__NOW,  SG_AUDIT__WHO__FROM_SETTINGS)  );

    // lookup the recid of the group
    SG_ERR_CHECK(  SG_zing__lookup_recid(pCtx, pRepo, SG_DAGNUM__USERS, psz_hid_cs_leaf, "group", "name", psz_group_name, &psz_recid_group)  );

    /* start a changeset */
    SG_ERR_CHECK(  SG_zing__begin_tx(pCtx, pRepo, SG_DAGNUM__USERS, q.who_szUserId, psz_hid_cs_leaf, &pztx)  );
    SG_ERR_CHECK(  SG_zingtx__add_parent(pCtx, pztx, psz_hid_cs_leaf)  );

    for (i=0; i<count_names; i++)
    {
        // lookup the recid of the user
        SG_ERR_CHECK(  SG_zing__lookup_recid(pCtx, pRepo, SG_DAGNUM__USERS, psz_hid_cs_leaf, "user", "email", paszMemberNames[i], &psz_recid_user)  );
        SG_ERR_CHECK(  SG_zingtx__add_link__unpacked(pCtx, pztx, psz_recid_user, psz_recid_group, "member")  );
        SG_NULLFREE(pCtx, psz_recid_user);
    }

    /* commit the changes */
	SG_ERR_CHECK(  SG_zing__commit_tx(pCtx, q.when_int64, &pztx, &pcs, &pdn, NULL)  );

    // fall thru

fail:
    if (pztx)
    {
        SG_ERR_IGNORE(  SG_zing__abort_tx(pCtx, &pztx)  );
    }
    SG_NULLFREE(pCtx, psz_hid_cs_leaf);
    SG_NULLFREE(pCtx, psz_recid_group);
    SG_NULLFREE(pCtx, psz_recid_user);
    SG_DAGNODE_NULLFREE(pCtx, pdn);
    SG_CHANGESET_NULLFREE(pCtx, pcs);
}
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);
}
示例#23
0
/**
 * Creates a staging area and returns an initialized instance data structure.
 */
static void _pull_init(SG_context* pCtx, 
					   SG_client* pClient,
					   const char* pszPullIntoRepoDescriptorName,
					   sg_pull_instance_data** ppMe)
{
	char* pszThisRepoId = NULL;
	char* pszThisHashMethod = NULL;
	char* pszOtherRepoId = NULL;
	char* pszOtherHashMethod = NULL;

	sg_pull_instance_data* pMe = NULL;
	
	SG_repo* pPullIntoRepo = NULL;

	SG_NULLARGCHECK_RETURN(pszPullIntoRepoDescriptorName);
	SG_NULLARGCHECK_RETURN(ppMe);

	SG_ERR_CHECK(  SG_client__get_repo_info(pCtx, pClient, &pszOtherRepoId, NULL, &pszOtherHashMethod)  );

	SG_ERR_CHECK(  SG_repo__open_repo_instance(pCtx, pszPullIntoRepoDescriptorName, &pPullIntoRepo)  );

	/* TODO This will care about dagnums once we're using the user dag. */
	SG_ERR_CHECK(  SG_repo__get_repo_id(pCtx, pPullIntoRepo, &pszThisRepoId)  );
	if (strcmp(pszThisRepoId, pszOtherRepoId) != 0)
		SG_ERR_THROW(SG_ERR_REPO_ID_MISMATCH);

	/* TODO check admin id when appropriate */

	SG_ERR_CHECK(  SG_repo__get_hash_method(pCtx, pPullIntoRepo, &pszThisHashMethod)  );
	if (strcmp(pszThisHashMethod, pszOtherHashMethod) != 0)
		SG_ERR_THROW(SG_ERR_REPO_HASH_METHOD_MISMATCH);

	// alloc instance data, store pull id in it (which identifies the staging area)
	SG_ERR_CHECK(  SG_alloc1(pCtx, pMe)  );
	SG_ERR_CHECK(  SG_staging__create(pCtx, pszPullIntoRepoDescriptorName, &pMe->pszPullId, &pMe->pStaging)  );
	pMe->pPullIntoRepo = pPullIntoRepo;
	pPullIntoRepo = NULL;

	SG_RETURN_AND_NULL(pMe, ppMe);

	/* fall through */
fail:
	SG_NULLFREE(pCtx, pszThisRepoId);
	SG_NULLFREE(pCtx, pszThisHashMethod);
	SG_NULLFREE(pCtx, pszOtherRepoId);
	SG_NULLFREE(pCtx, pszOtherHashMethod);
	SG_NULLFREE(pCtx, pPullIntoRepo);
	_NULLFREE_INSTANCE_DATA(pCtx, pMe);
}
示例#24
0
void SG_treendx__get_path_in_dagnode(SG_context* pCtx, SG_treendx* pTreeNdx, const char* psz_search_item_gid, const char* psz_changeset, SG_treenode_entry ** ppTreeNodeEntry)
{
	SG_rbtree_iterator * rb_it = NULL;
	const char * pPath = NULL;
	SG_changeset * pChangeset = NULL;
	SG_stringarray * pPaths = NULL;
	const char* pszHidTreeNode = NULL;
	SG_treenode * pTreenodeRoot = NULL;
	char* pszReturnedGID = NULL;
	SG_uint32 i = 0;
	SG_uint32 count = 0;

	SG_ERR_CHECK_RETURN(  SG_gid__argcheck(pCtx, psz_search_item_gid)  );

	SG_ERR_CHECK(  SG_treendx__get_all_paths(pCtx, pTreeNdx, psz_search_item_gid, &pPaths)   );
	*ppTreeNodeEntry = NULL;
	SG_ERR_CHECK(  SG_changeset__load_from_repo(pCtx, pTreeNdx->pRepo, psz_changeset, &pChangeset)  );
	SG_ERR_CHECK(  SG_changeset__get_root(pCtx, pChangeset, &pszHidTreeNode) );
	SG_ERR_CHECK(  SG_treenode__load_from_repo(pCtx, pTreeNdx->pRepo, pszHidTreeNode, &pTreenodeRoot)  );
	SG_ERR_CHECK(  SG_stringarray__count(pCtx, pPaths, &count )  );
	for (i = 0; i < count; i++)
	{
		SG_ERR_CHECK(  SG_stringarray__get_nth(pCtx, pPaths, i, &pPath)  );
		SG_ERR_CHECK(  SG_treenode__find_treenodeentry_by_path(pCtx, pTreeNdx->pRepo, pTreenodeRoot, pPath, &pszReturnedGID, ppTreeNodeEntry)  );
		if (*ppTreeNodeEntry != NULL && strcmp(pszReturnedGID, psz_search_item_gid) == 0)
		{
			break;
		}
		else if (*ppTreeNodeEntry != NULL)
		{
			SG_TREENODE_ENTRY_NULLFREE(pCtx, *ppTreeNodeEntry);
			*ppTreeNodeEntry = NULL; //It's not the right GID, even though it's in the right spot.
		}
	}

	SG_NULLFREE(pCtx, pszReturnedGID);
	SG_CHANGESET_NULLFREE(pCtx, pChangeset);
	SG_TREENODE_NULLFREE(pCtx, pTreenodeRoot);
	SG_STRINGARRAY_NULLFREE(pCtx, pPaths);
	SG_RBTREE_ITERATOR_NULLFREE(pCtx, rb_it);
	return;
fail:
	SG_NULLFREE(pCtx, pszReturnedGID);
	SG_CHANGESET_NULLFREE(pCtx, pChangeset);
	SG_STRINGARRAY_NULLFREE(pCtx, pPaths);
	SG_RBTREE_ITERATOR_NULLFREE(pCtx, rb_it);
	return;

}
void sg_variantsubpool__free(SG_context * pCtx, sg_variantsubpool *psp)
{
    sg_variantsubpool* p = psp;

    while (p)
    {
        sg_variantsubpool* pnext = p->pNext;

        SG_NULLFREE(pCtx, p->pVariants);

        SG_NULLFREE(pCtx, p);

        p = pnext;
    }
}
void SG_jscontextpool__teardown(SG_context * pCtx)
{
	if(gpJSContextPoolGlobalState!=NULL)
	{
		SG_ERR_CHECK_RETURN(  SG_mutex__lock(pCtx, &gpJSContextPoolGlobalState->lock)  );

		// Wait until all outstanding SG_jscontexts have been released. Don't try to terminate
		// early, otherwise we have a race condition on our hands: If the outstanding SG_jscontext
		// tries to perform any JavaScript operations before the app terminates, but after we have
		// called JS_Shutdown(), we'll end up crashing on exit. This of course is worse than
		//  making the user hit Ctrl-C again to do a hard shutdown if it's taking too long.
		if(gpJSContextPoolGlobalState->numContextsCheckedOut > 0)
		{
			SG_ERR_IGNORE(  SG_log__report_warning(pCtx, "Waiting on %d SG_jscontexts that are still in use.", gpJSContextPoolGlobalState->numContextsCheckedOut)  );
			while(gpJSContextPoolGlobalState->numContextsCheckedOut > 0)
			{
				SG_ERR_CHECK_RETURN(  SG_mutex__unlock(pCtx, &gpJSContextPoolGlobalState->lock)  );
				SG_sleep_ms(10);
				SG_ERR_CHECK_RETURN(  SG_mutex__lock(pCtx, &gpJSContextPoolGlobalState->lock)  );
			}
		}

		SG_ERR_CHECK_RETURN(  SG_mutex__unlock(pCtx, &gpJSContextPoolGlobalState->lock)  );
		SG_mutex__destroy(&gpJSContextPoolGlobalState->lock);

		while(gpJSContextPoolGlobalState->pFirstAvailableContext!=NULL)
		{
			SG_jscontext * pJs = gpJSContextPoolGlobalState->pFirstAvailableContext;
			gpJSContextPoolGlobalState->pFirstAvailableContext = pJs->pNextAvailableContext;

			(void)JS_SetContextThread(pJs->cx);
			JS_BeginRequest(pJs->cx);
			JS_SetContextPrivate(pJs->cx, pCtx);
			JS_DestroyContextNoGC(pJs->cx);

			if(SG_context__has_err(pCtx)) // An error was produced during GC...
			{
				SG_log__report_error__current_error(pCtx);
				SG_context__err_reset(pCtx);
			}

			SG_NULLFREE(pCtx, pJs);
		}

		SG_VHASH_NULLFREE(pCtx, gpJSContextPoolGlobalState->pServerConfig);
		SG_NULLFREE(pCtx, gpJSContextPoolGlobalState);
	}
}
示例#27
0
void SG_server__free(SG_context * pCtx, SG_server* pServer)
{
	if (!pServer)
		return;

	SG_NULLFREE(pCtx, pServer);
}
void u0025_jsonwriter__verify(SG_context * pCtx, SG_string* pstr)
{
	const char *psz = SG_string__sz(pstr);
	SG_int32* putf32 = NULL;
	SG_uint32 len = 0;
	JSON_checker jc = new_JSON_checker(20);
	SG_uint32 i;
	int ok = 0;

	SG_utf8__to_utf32__sz(pCtx, psz, &putf32, &len);
	for (i=0; i<len; i++)
	{
		ok = JSON_checker_char(jc, putf32[i]);
		VERIFY_COND("JSON_checker_char", ok);
		if (!ok)
		{
			break;
		}
    }

	if (ok)
	{
		ok = JSON_checker_done(jc);
		VERIFY_COND("JSON_checker_done", ok);
	}


	SG_NULLFREE(pCtx, putf32);
}
示例#29
0
void SG_vfile__reread(
	SG_context* pCtx,
	SG_vfile * pvf,
	SG_vhash** ppvh)
{
	SG_vhash* pvh = NULL;
	SG_uint64 len64;
	SG_uint32 len32;
	SG_byte* p = NULL;

	SG_ERR_CHECK(  SG_file__seek_end(pCtx, pvf->pFile, &len64)  );
	SG_ERR_CHECK(  SG_file__seek(pCtx, pvf->pFile, 0)  );
	
	// TODO "len64" is uint64 because we can have huge files, but
	// TODO our buffer is limited to uint32 (on 32bit systems).
	// TODO verify that len will fit in uint32.
	len32 = (SG_uint32)len64;
	if (len32 > 0)
	{
		SG_ERR_CHECK(  SG_alloc(pCtx, 1,len32+1,&p)  );
		SG_ERR_CHECK(  SG_file__read(pCtx, pvf->pFile, len32, p, NULL)  );

		p[len32] = 0;

		SG_ERR_CHECK(  SG_VHASH__ALLOC__FROM_JSON(pCtx, &pvh, (const char*) p)  );
		*ppvh = pvh;
	}

fail:
	SG_NULLFREE(pCtx, p);
}
示例#30
0
void SG_pull__clone(
	SG_context* pCtx, 
	const char* pszPullIntoRepoDescriptorName, 
	SG_client* pClient)
{
	sg_pull_instance_data* pMe = NULL;
	char* pszFragballName = NULL;
	const SG_pathname* pStagingPathname;

	SG_NULLARGCHECK_RETURN(pszPullIntoRepoDescriptorName);
	SG_NULLARGCHECK_RETURN(pClient);

	SG_ERR_CHECK(  _pull_init(pCtx, pClient, pszPullIntoRepoDescriptorName, &pMe)  );
	SG_ERR_CHECK(  SG_staging__get_pathname(pCtx, pMe->pStaging, &pStagingPathname)  );

	/* Request a fragball containing the entire repo */
	SG_ERR_CHECK(  SG_client__pull_clone(pCtx, pClient, pStagingPathname, &pszFragballName)  );

	/* commit and cleanup */
	SG_ERR_CHECK_RETURN(  SG_staging__commit_fragball(pCtx, pMe->pStaging, pszFragballName)  );

	SG_ERR_CHECK(  SG_context__msg__emit(pCtx, "Cleaning up...")  );
	SG_ERR_CHECK_RETURN(  SG_staging__cleanup(pCtx, &pMe->pStaging)  );
	SG_ERR_CHECK(  SG_context__msg__emit(pCtx, "done")  );

	/* fall through */
fail:
	_NULLFREE_INSTANCE_DATA(pCtx, pMe);
	SG_NULLFREE(pCtx, pszFragballName);
	SG_ERR_IGNORE(  SG_context__msg__emit(pCtx, "\n")  );
}