1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
bool CMcrHttp::ParseUrl(MCR_CSTR Url,
MCR_STRING & ServiceType,
MCR_STRING & Server,
MCR_STRING & Object,
MCR_U2 & Port)
{
// initialize the returned data
ServiceType = EMPTY_STR;
Server = EMPTY_STR;
Object = EMPTY_STR;
Port = 0;
// Initialize the URL_COMPONENTS structure.
URL_COMPONENTS urlComp;
memset(&urlComp, 0, sizeof(urlComp));
urlComp.dwStructSize = sizeof(urlComp);
// Set required component lengths to non-zero so that they are cracked.
urlComp.dwSchemeLength = (MCR_U4)-1;
urlComp.dwHostNameLength = (MCR_U4)-1;
urlComp.dwUrlPathLength = (MCR_U4)-1;
// parse the URL
if(WinHttpCrackUrl(Url, _tcslen(Url), 0, & urlComp) == FALSE)
{
ERREUR(L"An error in WinHttpCrackUrl()");
ASSERT(FALSE);
return false;
}
// return the values
Port = urlComp.nPort;
// get the scheme
if(urlComp.dwSchemeLength != 0)
{
ServiceType = MCR_STRING(urlComp.lpszScheme, urlComp.dwSchemeLength);
}
// get the server
if(urlComp.dwHostNameLength != 0)
{
Server = MCR_STRING(urlComp.lpszHostName, urlComp.dwHostNameLength);
}
// get the url
if(urlComp.dwUrlPathLength != 0)
{
Object = MCR_STRING(urlComp.lpszUrlPath, urlComp.dwUrlPathLength);
}
return true;
} |
Partager