예제 #1
0
void DoParseUri(const TPtrCType& aUri, TPtrCType aComponent[])
	{
	// Parse the components
	TPtrCType uri = aUri;
	TInt consumed = 0;
	TPtrCType& scheme = aComponent[EUriScheme];
	if( (consumed = ParseScheme(uri, scheme)) > 0 )
		{
		uri.Set(uri.Mid(consumed));
		}
	if( (consumed = ParseAuthority(uri, aComponent[EUriUserinfo], 
		 aComponent[EUriHost], aComponent[EUriPort], IsNetworkScheme(scheme))) > 0 )
		{
		uri.Set(uri.Mid(consumed));
		}
	if( (consumed = ParsePath(uri, aComponent[EUriPath])) > 0 )
		{
		uri.Set(uri.Mid(consumed));
		}
	if( (consumed = ParseQuery(uri, aComponent[EUriQuery])) > 0 )
		{
		uri.Set(uri.Mid(consumed));
		}
	if( (consumed = ParseFragment(uri, aComponent[EUriFragment])) > 0 )
		{
		uri.Set(uri.Mid(consumed));
		}
	}
예제 #2
0
/*----------------------------------------------------------------------
|   NPT_Uri::SetScheme
+---------------------------------------------------------------------*/
void
NPT_Uri::SetScheme(const char* scheme)
{
    m_Scheme = scheme;
    m_Scheme.MakeLowercase();
    m_SchemeId = ParseScheme(m_Scheme);
}
예제 #3
0
파일: uri.cpp 프로젝트: 252525fb/rpcs3
const wxChar* wxURI::Parse(const wxChar* uri)
{
    uri = ParseScheme(uri);
    uri = ParseAuthority(uri);
    uri = ParsePath(uri);
    uri = ParseQuery(uri);
    return ParseFragment(uri);
}
예제 #4
0
bool wxURI::Parse(const char *uri)
{
    uri = ParseScheme(uri);
    if ( uri )
        uri = ParseAuthority(uri);
    if ( uri )
        uri = ParsePath(uri);
    if ( uri )
        uri = ParseQuery(uri);
    if ( uri )
        uri = ParseFragment(uri);

    // we only succeed if we parsed the entire string
    return uri && *uri == '\0';
}
ECode CHttpAuthHeader::ParseHeader(
    /* [in] */ const String& header)
{
    if (HttpLog::LOGV) {
        HttpLog::V(String("HttpAuthHeader.parseHeader(): header: ") + header);
    }

    if (header != NULL) {
        String parameters;
        ParseScheme(header, &parameters);
        if (parameters != NULL) {
            // if we have a supported scheme
            if (mScheme != UNKNOWN) {
                ParseParameters(parameters);
            }
        }
    }
    return NOERROR;
}
예제 #6
0
gfcontext_t *BuildContextFromRequestString(char *request)
{
	char *delimiter = " ";
	char *saveptr;

	printf("Parsing request string [%s]\n", request);

	gfcontext_t *context = malloc(sizeof(gfcontext_t));
	context->Scheme = ParseScheme(strtok_r(request, delimiter, &saveptr));
	context->Method = ParseMethod(strtok_r(NULL, delimiter, &saveptr));
	context->FilePath = strtok_r(NULL, delimiter, &saveptr);
	context->Status = GF_OK;

	if(context->Scheme == NO_SCHEME)
	{
		printf("Parsed scheme [%d] is not a known scheme.", context->Scheme);
		context->Status = GF_ERROR;
		return context;
	}

	if(context->Method == NO_METHOD)
	{
		printf("Parsed method [%d] is not a known method.", context->Method);
		context->Status = GF_ERROR;
		return context;
	}

	if(!IsValidFilePath(context->FilePath))
	{
		printf("Parsed file path [%s] is not a known path.", context->FilePath);
		context->Status = GF_ERROR;
		return context;
	}

    printf("Context.Scheme: %d\n", context->Scheme);
    printf("Context.Method: %d\n", context->Method);
    printf("Context.FilePath: %s\n", context->FilePath);
	return context;
}
예제 #7
0
/*----------------------------------------------------------------------
|   NPT_Uri::SetSchemeFromUri
+---------------------------------------------------------------------*/
NPT_Result
NPT_Uri::SetSchemeFromUri(const char* uri)
{
    const char* start = uri;
    char c;
    while ((c =*uri++)) {
        if (c == ':') {
            m_Scheme.Assign(start, (NPT_Size)(uri-start-1));
            m_Scheme.MakeLowercase();
            m_SchemeId = ParseScheme(m_Scheme);
            return NPT_SUCCESS;
        } else if ((c >= 'a' && c <= 'z') ||
                   (c >= 'A' && c <= 'Z') ||
                   (c >= '0' && c <= '9') ||
                   (c == '+')             ||
                   (c == '.')             ||
                   (c == '-')) {
            continue;
        } else {
            break;
        }
    }
    return NPT_ERROR_INVALID_SYNTAX;
}
예제 #8
0
파일: url.cpp 프로젝트: whrool/Net
Url Url::Parse(const std::string& strRawUrl)
{
    // <scheme>://<user>:<password>@<host>:<port>/<path>?<query>#<frag>
    // <scheme>:opaque?query#fragment
    Url url;
    if (strRawUrl.empty())
        return url;
    do 
    {
        // Firstly, we will split fragment and query string.
        std::string strPrefix;
        auto spList = base::strings::Split(strRawUrl, "#");
        if (spList.size() > 2)
            break;
        strPrefix = spList[0];
        if (spList.size() == 2)
            url.m_strFragment = base::Unescape(spList[1]);
        spList = base::strings::Split(strPrefix, "?");
        if (spList.size() > 2)
            break;
        strPrefix = spList[0];
        if (spList.size() == 2)
            url.m_strRawQuery = spList[1];
        
        // Parse scheme.
        std::string strRest;
        if (!ParseScheme(strPrefix, url.m_strScheme, strRest))
            break;
        if (url.GetScheme() == "http")
            url.SetPort(80);
        else if (url.GetScheme() == "https")
            url.SetPort(443);

        if (strRest.empty())
            break;
        
        // <scheme>:opaque
        if (!url.m_strScheme.empty() && strRest[0] != '/')
        {
            url.m_strOpaque = strRest;
            break;
        } // !if <scheme>:opaque

        // Invalid URL.
        if (!url.m_strScheme.empty()
            && !base::strings::StartsWith(strRest, "//"))
            break;

        // Relative path.
        if (url.m_strScheme.empty()
            && !base::strings::StartsWith(strRest, "//"))
        {
            url.m_strPath = base::Unescape(strRest);
            break;
        }

        // Secondly, we will parse the particular case.
        // <scheme>:///<path>
        if (strRest[2] == '/')
        {
            auto pos1 = strRest.find_first_not_of('/');
            if (std::string::npos == pos1)
                break;
            url.m_strPath = base::Unescape(strRest.substr(pos1 - 1));
            break;
        } // !if <scheme>:///<path>

        // <scheme>://<user>:<password>@<host>:<port>/<path>
        auto pos1 = strRest.find_first_not_of('/');
        if (std::string::npos == pos1)
            break;
        auto pos2 = strRest.find_first_of("/", pos1);
        std::string strAuthority;
        if (std::string::npos == pos2)
            strAuthority = strRest.substr(pos1);
        else
            strAuthority = strRest.substr(pos1, pos2 - pos1);
        if (!ParseAuthority(strAuthority, url.m_strUserName, url.m_strPassword,
                            url.m_strHost, url.m_iPort))
        {
            url.m_strUserName = "";
            url.m_strPassword = "";
            url.m_strHost = "";
            url.m_iPort = 0;
            break;
        }
        if (pos2 == std::string::npos)
        {
            url.m_strPath = "/";
            break;
        }
        url.m_strPath = base::Unescape(strRest.substr(pos2));
        
    } while (0);
    
    return url;
}