RTR3DECL(char *) RTUriAuthority(const char *pszUri) { AssertPtrReturn(pszUri, NULL); size_t iPos1; size_t cbLen = strlen(pszUri); /* Find the end of the scheme. */ if (!rtUriFindSchemeEnd(pszUri, 0, cbLen, &iPos1)) return NULL; /* no URI */ else ++iPos1; /* Skip ':' */ size_t iPos2; /* Find the start of the authority. */ if (rtUriCheckAuthorityStart(pszUri, iPos1, cbLen - iPos1, &iPos2)) { size_t iPos3 = cbLen; /* Find the end of the authority. If not found, the rest of the string * is used. */ rtUriFindAuthorityEnd(pszUri, iPos2, cbLen - iPos2, &iPos3); if (iPos3 > iPos2) /* Length check */ return rtUriPercentDecodeN(&pszUri[iPos2], iPos3 - iPos2); else return NULL; } return NULL; }
RTR3DECL(char *) RTUriFragment(const char *pszUri) { AssertPtrReturn(pszUri, NULL); size_t iPos1; size_t cbLen = strlen(pszUri); /* Find the end of the scheme. */ if (!rtUriFindSchemeEnd(pszUri, 0, cbLen, &iPos1)) return NULL; /* no URI */ else ++iPos1; /* Skip ':' */ size_t iPos2; size_t iPos3 = iPos1; /* Skip if no authority is found */ /* Find the start of the authority. */ if (rtUriCheckAuthorityStart(pszUri, iPos1, cbLen - iPos1, &iPos2)) { /* Find the end of the authority. If not found, then there is no path * component, cause the authority is the rest of the string. */ if (!rtUriFindAuthorityEnd(pszUri, iPos2, cbLen - iPos2, &iPos3)) return NULL; /* no path! */ } size_t iPos4; size_t iPos5 = iPos3; /* Skip if no path is found */ /* Find the start of the path */ if (rtUriCheckPathStart(pszUri, iPos3, cbLen - iPos3, &iPos4)) { /* Find the end of the path. If not found, then there is no query * component, cause the path is the rest of the string. */ if (!rtUriFindPathEnd(pszUri, iPos4, cbLen - iPos4, &iPos5)) return NULL; /* no query! */ } size_t iPos6; size_t iPos7 = iPos5; /* Skip if no query is found */ /* Find the start of the query */ if (rtUriCheckQueryStart(pszUri, iPos5, cbLen - iPos5, &iPos6)) { /* Find the end of the query If not found, then there is no fragment * component, cause the query is the rest of the string. */ if (!rtUriFindQueryEnd(pszUri, iPos6, cbLen - iPos6, &iPos7)) return NULL; /* no query! */ } size_t iPos8; /* Find the start of the fragment */ if (rtUriCheckFragmentStart(pszUri, iPos7, cbLen - iPos7, &iPos8)) { /* There could be nothing behind a fragment. So use the rest of the * string. */ if (cbLen > iPos8) /* Length check */ return rtUriPercentDecodeN(&pszUri[iPos8], cbLen - iPos8); } return NULL; }
RTDECL(char *) RTUriParsedFragment(const char *pszUri, PCRTURIPARSED pParsed) { AssertPtrReturn(pszUri, NULL); AssertPtrReturn(pParsed, NULL); AssertReturn(pParsed->u32Magic == RTURIPARSED_MAGIC, NULL); if (pParsed->cchFragment) return rtUriPercentDecodeN(&pszUri[pParsed->offFragment], pParsed->cchFragment); return NULL; }
RTDECL(char *) RTUriParsedAuthorityPassword(const char *pszUri, PCRTURIPARSED pParsed) { AssertPtrReturn(pszUri, NULL); AssertPtrReturn(pParsed, NULL); AssertReturn(pParsed->u32Magic == RTURIPARSED_MAGIC, NULL); if (pParsed->cchAuthorityPassword) return rtUriPercentDecodeN(&pszUri[pParsed->offAuthorityPassword], pParsed->cchAuthorityPassword); return NULL; }
RTDECL(char *) RTUriParsedAuthority(const char *pszUri, PCRTURIPARSED pParsed) { AssertPtrReturn(pszUri, NULL); AssertPtrReturn(pParsed, NULL); AssertReturn(pParsed->u32Magic == RTURIPARSED_MAGIC, NULL); if (pParsed->cchAuthority || (pParsed->fFlags & RTURIPARSED_F_HAVE_AUTHORITY)) return rtUriPercentDecodeN(&pszUri[pParsed->offAuthority], pParsed->cchAuthority); return NULL; }
RTR3DECL(char *) RTUriScheme(const char *pszUri) { AssertPtrReturn(pszUri, NULL); size_t iPos1; size_t cbLen = strlen(pszUri); if (rtUriFindSchemeEnd(pszUri, 0, cbLen, &iPos1)) return rtUriPercentDecodeN(pszUri, iPos1); return NULL; }
RTR3DECL(char *) RTUriQuery(const char *pszUri) { AssertPtrReturn(pszUri, NULL); size_t iPos1; size_t cbLen = strlen(pszUri); /* Find the end of the scheme. */ if (!rtUriFindSchemeEnd(pszUri, 0, cbLen, &iPos1)) return NULL; /* no URI */ else ++iPos1; /* Skip ':' */ size_t iPos2; size_t iPos3 = iPos1; /* Skip if no authority is found */ /* Find the start of the authority. */ if (rtUriCheckAuthorityStart(pszUri, iPos1, cbLen - iPos1, &iPos2)) { /* Find the end of the authority. If not found, then there is no path * component, cause the authority is the rest of the string. */ if (!rtUriFindAuthorityEnd(pszUri, iPos2, cbLen - iPos2, &iPos3)) return NULL; /* no path! */ } size_t iPos4; size_t iPos5 = iPos3; /* Skip if no path is found */ /* Find the start of the path */ if (rtUriCheckPathStart(pszUri, iPos3, cbLen - iPos3, &iPos4)) { /* Find the end of the path. If not found, then there is no query * component, cause the path is the rest of the string. */ if (!rtUriFindPathEnd(pszUri, iPos4, cbLen - iPos4, &iPos5)) return NULL; /* no query! */ } size_t iPos6; /* Find the start of the query */ if (rtUriCheckQueryStart(pszUri, iPos5, cbLen - iPos5, &iPos6)) { /* Search for the end of the query. */ size_t iPos7 = cbLen; rtUriFindQueryEnd(pszUri, iPos6, cbLen - iPos6, &iPos7); if (iPos7 > iPos6) /* Length check */ return rtUriPercentDecodeN(&pszUri[iPos6], iPos7 - iPos6); } return NULL; }
RTR3DECL(char *) RTUriFileNPath(const char *pszUri, uint32_t uFormat, size_t cchMax) { AssertPtrReturn(pszUri, NULL); size_t iPos1; size_t cbLen = RT_MIN(strlen(pszUri), cchMax); /* Find the end of the scheme. */ if (!rtUriFindSchemeEnd(pszUri, 0, cbLen, &iPos1)) return NULL; /* no URI */ else ++iPos1; /* Skip ':' */ /* Check that this is a file Uri */ if (RTStrNICmp(pszUri, "file:", iPos1) != 0) return NULL; size_t iPos2; size_t iPos3 = iPos1; /* Skip if no authority is found */ /* Find the start of the authority. */ if (rtUriCheckAuthorityStart(pszUri, iPos1, cbLen - iPos1, &iPos2)) { /* Find the end of the authority. If not found, then there is no path * component, cause the authority is the rest of the string. */ if (!rtUriFindAuthorityEnd(pszUri, iPos2, cbLen - iPos2, &iPos3)) return NULL; /* no path! */ } size_t iPos4; /* Find the start of the path */ if (rtUriCheckPathStart(pszUri, iPos3, cbLen - iPos3, &iPos4)) { uint32_t uFIntern = uFormat; /* Auto is based on the current OS. */ if (uFormat == URI_FILE_FORMAT_AUTO) #ifdef RT_OS_WINDOWS uFIntern = URI_FILE_FORMAT_WIN; #else /* RT_OS_WINDOWS */ uFIntern = URI_FILE_FORMAT_UNIX; #endif /* !RT_OS_WINDOWS */ if ( uFIntern != URI_FILE_FORMAT_UNIX && pszUri[iPos4] == '/') ++iPos4; /* Search for the end of the scheme. */ size_t iPos5 = cbLen; rtUriFindPathEnd(pszUri, iPos4, cbLen - iPos4, &iPos5); if (iPos5 > iPos4) /* Length check */ { char *pszPath = rtUriPercentDecodeN(&pszUri[iPos4], iPos5 - iPos4); if (uFIntern == URI_FILE_FORMAT_UNIX) return RTPathChangeToUnixSlashes(pszPath, true); else if (uFIntern == URI_FILE_FORMAT_WIN) return RTPathChangeToDosSlashes(pszPath, true); else { RTStrFree(pszPath); AssertMsgFailed(("Unknown uri file format %u", uFIntern)); return NULL; } } } return NULL; }