Ejemplo n.º 1
0
static void _getDescriptorName(
	SG_context *pCtx,
	const _request_headers *pRequestHeaders,
	SG_string **ppRepoName)
{
	SG_pathname *pPathCwd = NULL;

	if (_startsWith("repos/", pRequestHeaders->pUri) && (strlen(pRequestHeaders->pUri) > 6))
	{
		const char *nameStart = pRequestHeaders->pUri + 6;
		const char *nameEnd = strchr(nameStart, '/');

		SG_ERR_CHECK(  SG_STRING__ALLOC(pCtx, ppRepoName)  );

		if (nameEnd == NULL)
			SG_ERR_CHECK(  SG_string__set__sz(pCtx, *ppRepoName, nameStart)  );
		else
			SG_ERR_CHECK(  SG_string__set__buf_len(pCtx, *ppRepoName, (const SG_byte *)nameStart,
												   (nameEnd - nameStart) * sizeof(char))  );
	}
	else
	{
		SG_ERR_CHECK(  SG_PATHNAME__ALLOC(pCtx, &pPathCwd)  );
		SG_ERR_CHECK(  SG_pathname__set__from_cwd(pCtx, pPathCwd)  );
		SG_ERR_CHECK(  SG_workingdir__find_mapping(pCtx, pPathCwd, NULL, ppRepoName, NULL)  );
	}

fail:
	SG_PATHNAME_NULLFREE(pCtx, pPathCwd);
}
Ejemplo n.º 2
0
void SG_localsettings__split_full_name(
	SG_context* pCtx,
	const char* szFullName,
	SG_uint32* uSplitIndex,
	SG_string* pScopeName,
	SG_string* pSettingName
	)
{
	SG_uint32 uSlashCount = 0;
	SG_uint32 uCurrent = 0;

	SG_ARGCHECK(szFullName[0] == '/', szFullName);

	// this is basically implemented by locating the Nth '/' character
	// where N depends on which scope the name is in
	if (0 == strncmp(szFullName, SG_LOCALSETTING__SCOPE__INSTANCE, strlen(SG_LOCALSETTING__SCOPE__INSTANCE)))
	{
		uSlashCount = 2;
	}
	else if (0 == strncmp(szFullName, SG_LOCALSETTING__SCOPE__REPO, strlen(SG_LOCALSETTING__SCOPE__REPO)))
	{
		uSlashCount = 2;
	}
	else if (0 == strncmp(szFullName, SG_LOCALSETTING__SCOPE__ADMIN, strlen(SG_LOCALSETTING__SCOPE__ADMIN)))
	{
		uSlashCount = 2;
	}
	else if (0 == strncmp(szFullName, SG_LOCALSETTING__SCOPE__MACHINE, strlen(SG_LOCALSETTING__SCOPE__MACHINE)))
	{
		uSlashCount = 1;
	}
	else
	{
		uSlashCount = 1;
	}

	// iterate through the string until we find the slash that we're looking for
	while (szFullName[uCurrent] != '\0' && uSlashCount > 0u)
	{
		// the first time through, this will always skip the leading slash character
		// this is why uSlashCount is one less than it seems like it should be
		uCurrent = uCurrent + 1u;

		// if this is a slash, update our count
		if (szFullName[uCurrent] == '/')
		{
			uSlashCount = uSlashCount - 1;
		}
	}

	// if the caller wants the index, fill it in
	if (uSplitIndex != NULL)
	{
		*uSplitIndex = uCurrent;
	}

	// if the caller wants the scope name, fill it in
	if (pScopeName != NULL)
	{
		SG_ERR_CHECK(  SG_string__set__buf_len(pCtx, pScopeName, (const SG_byte*)szFullName, uCurrent)  );
	}

	// if the caller wants the setting name, fill it in
	if (pSettingName != NULL)
	{
		SG_ERR_CHECK(  SG_string__set__sz(pCtx, pSettingName, szFullName + uCurrent + 1)  );
	}

fail:
	return;
}