- Timestamp:
- Nov 27, 2002, 3:28:17 PM (23 years ago)
- Location:
- trunk/src/wininet
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wininet/internet.c
r7291 r9439 1 /* $Id: internet.c,v 1. 6 2001-11-07 11:08:13 phallerExp $1 /* $Id: internet.c,v 1.7 2002-11-27 14:28:17 sandervl Exp $ 2 2 * 3 3 * Wininet … … 23 23 #include <string.h> 24 24 #include <ctype.h> 25 #include <win/windef.h> 25 26 #define strncasecmp strnicmp 26 27 #define TLS_OUT_OF_INDEXES -1 28 #define MAXHOSTNAME 100 27 29 #else 28 30 #include <sys/types.h> … … 82 84 switch (fdwReason) { 83 85 case DLL_PROCESS_ATTACH: 86 { 87 #ifdef __WIN32OS2__ 88 WORD ver = MAKEWORD (2, 2); 89 WSADATA data; 90 #endif 84 91 g_dwTlsErrIndex = TlsAlloc(); 85 92 … … 93 100 dwNumThreads=0; 94 101 dwNumIdleThreads=0; 95 102 #ifdef __WIN32OS2__ 103 WSAStartup ( ver, &data ); 104 #endif 105 } 96 106 case DLL_THREAD_ATTACH: 97 107 { … … 126 136 CloseHandle(hWorkEvent); 127 137 DeleteCriticalSection(&csQueue); 138 #ifdef __WIN32OS2__ 139 WSACleanup(); 140 #endif 128 141 break; 129 142 } … … 456 469 * 457 470 */ 458 BOOL SetUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen, LPCSTR lpszStart, INT len) 471 BOOL SetUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen, 472 LPCSTR lpszStart, INT len) 459 473 { 460 474 TRACE("%s (%d)\n", lpszStart, len); … … 462 476 if (*dwComponentLen != 0) 463 477 { 464 465 466 467 468 469 470 478 if (*lppszComponent == NULL) 479 { 480 *lppszComponent = (LPSTR)lpszStart; 481 *dwComponentLen = len; 482 } 483 else 484 { 471 485 INT ncpylen = min((*dwComponentLen)-1, len); 472 strncpy(*lppszComponent, lpszStart, ncpylen); 486 if (lpszStart) 487 strncpy(*lppszComponent, lpszStart, ncpylen); 473 488 (*lppszComponent)[ncpylen] = '\0'; 474 475 489 *dwComponentLen = ncpylen; 490 } 476 491 } 477 492 … … 479 494 } 480 495 481 482 /***********************************************************************483 * InternetCrackUrlA (WININET.95)484 *485 * Break up URL into its components486 *487 * RETURNS488 * TRUE on success489 * FALSE on failure490 *491 */492 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags,493 LPURL_COMPONENTSA lpUrlComponents)494 {495 /*496 * RFC 1808497 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]498 *499 */500 LPSTR lpszParam = NULL;501 BOOL bIsAbsolute = FALSE;502 LPSTR lpszap = (char*)lpszUrl;503 LPSTR lpszcp = NULL;504 505 TRACE("\n");506 507 /* Determine if the URI is absolute. */508 while (*lpszap != '\0')509 {510 if (isalnum(*lpszap))511 {512 lpszap++;513 continue;514 }515 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2))516 {517 bIsAbsolute = TRUE;518 lpszcp = lpszap;519 }520 else521 {522 lpszcp = (LPSTR)lpszUrl; /* Relative url */523 }524 525 break;526 }527 528 /* Parse <params> */529 lpszParam = strpbrk(lpszap, ";?");530 if (lpszParam != NULL)531 {532 if (!SetUrlComponentValue(&lpUrlComponents->lpszExtraInfo,533 &lpUrlComponents->dwExtraInfoLength, lpszParam+1, strlen(lpszParam+1)))534 {535 return FALSE;536 }537 }538 539 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */540 {541 LPSTR lpszNetLoc;542 543 /* Get scheme first. */544 lpUrlComponents->nScheme = GetInternetScheme(lpszUrl, lpszcp - lpszUrl);545 if (!SetUrlComponentValue(&lpUrlComponents->lpszScheme,546 &lpUrlComponents->dwSchemeLength, lpszUrl, lpszcp - lpszUrl))547 return FALSE;548 549 /* Eat ':' in protocol. */550 lpszcp++;551 552 /* Skip over slashes. */553 if (*lpszcp == '/')554 {555 lpszcp++;556 if (*lpszcp == '/')557 {558 lpszcp++;559 if (*lpszcp == '/')560 lpszcp++;561 }562 }563 564 lpszNetLoc = strpbrk(lpszcp, "/");565 if (lpszParam)566 {567 if (lpszNetLoc)568 lpszNetLoc = min(lpszNetLoc, lpszParam);569 else570 lpszNetLoc = lpszParam;571 }572 else if (!lpszNetLoc)573 lpszNetLoc = lpszcp + strlen(lpszcp);574 575 /* Parse net-loc */576 if (lpszNetLoc)577 {578 LPSTR lpszHost;579 LPSTR lpszPort;580 581 /* [<user>[<:password>]@]<host>[:<port>] */582 /* First find the user and password if they exist */583 584 lpszHost = strchr(lpszcp, '@');585 if (lpszHost == NULL || lpszHost > lpszNetLoc)586 {587 /* username and password not specified. */588 SetUrlComponentValue(&lpUrlComponents->lpszUserName,589 &lpUrlComponents->dwUserNameLength, NULL, 0);590 SetUrlComponentValue(&lpUrlComponents->lpszPassword,591 &lpUrlComponents->dwPasswordLength, NULL, 0);592 }593 else /* Parse out username and password */594 {595 LPSTR lpszUser = lpszcp;596 LPSTR lpszPasswd = lpszHost;597 598 while (lpszcp < lpszHost)599 {600 if (*lpszcp == ':')601 lpszPasswd = lpszcp;602 603 lpszcp++;604 }605 606 SetUrlComponentValue(&lpUrlComponents->lpszUserName,607 &lpUrlComponents->dwUserNameLength, lpszUser, lpszPasswd - lpszUser);608 609 SetUrlComponentValue(&lpUrlComponents->lpszPassword,610 &lpUrlComponents->dwPasswordLength,611 lpszPasswd == lpszHost ? NULL : ++lpszPasswd,612 lpszHost - lpszPasswd);613 614 lpszcp++; /* Advance to beginning of host */615 }616 617 /* Parse <host><:port> */618 619 lpszHost = lpszcp;620 lpszPort = lpszNetLoc;621 622 while (lpszcp < lpszNetLoc)623 {624 if (*lpszcp == ':')625 lpszPort = lpszcp;626 627 lpszcp++;628 }629 630 SetUrlComponentValue(&lpUrlComponents->lpszHostName,631 &lpUrlComponents->dwHostNameLength, lpszHost, lpszPort - lpszHost);632 633 if (lpszPort != lpszNetLoc)634 lpUrlComponents->nPort = atoi(++lpszPort);635 }636 }637 638 /* Here lpszcp points to:639 *640 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>]641 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^642 */643 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam))644 {645 INT len;646 647 /* Only truncate the parameter list if it's already been saved648 * in lpUrlComponents->lpszExtraInfo.649 */650 if (lpszParam && lpUrlComponents->dwExtraInfoLength)651 len = lpszParam - lpszcp;652 else653 {654 /* Leave the parameter list in lpszUrlPath. Strip off any trailing655 * newlines if necessary.656 */657 LPSTR lpsznewline = strchr (lpszcp, '\n');658 if (lpsznewline != NULL)659 len = lpsznewline - lpszcp;660 else661 len = strlen(lpszcp);662 }663 664 if (!SetUrlComponentValue(&lpUrlComponents->lpszUrlPath,665 &lpUrlComponents->dwUrlPathLength, lpszcp, len))666 return FALSE;667 }668 else669 {670 lpUrlComponents->dwUrlPathLength = 0;671 }672 673 TRACE("%s: host(%s) path(%s) extra(%s)\n", lpszUrl, lpUrlComponents->lpszHostName,674 lpUrlComponents->lpszUrlPath, lpUrlComponents->lpszExtraInfo);675 676 return TRUE;677 }678 496 679 497 … … 1489 1307 return TRUE; 1490 1308 } 1309 1310 1311 /********************************************************** 1312 * InternetOpenUrlA (WININET.@) 1313 * 1314 * Opens an URL 1315 * 1316 * RETURNS 1317 * handle of connection or NULL on failure 1318 */ 1319 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl, 1320 LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext) 1321 { 1322 URL_COMPONENTSA urlComponents; 1323 char protocol[32], hostName[MAXHOSTNAME], userName[1024]; 1324 char password[1024], path[2048], extra[1024]; 1325 HINTERNET client = NULL, client1 = NULL; 1326 urlComponents.dwStructSize = sizeof(URL_COMPONENTSA); 1327 urlComponents.lpszScheme = protocol; 1328 urlComponents.dwSchemeLength = 32; 1329 urlComponents.lpszHostName = hostName; 1330 urlComponents.dwHostNameLength = MAXHOSTNAME; 1331 urlComponents.lpszUserName = userName; 1332 urlComponents.dwUserNameLength = 1024; 1333 urlComponents.lpszPassword = password; 1334 urlComponents.dwPasswordLength = 1024; 1335 urlComponents.lpszUrlPath = path; 1336 urlComponents.dwUrlPathLength = 2048; 1337 urlComponents.lpszExtraInfo = extra; 1338 urlComponents.dwExtraInfoLength = 1024; 1339 if(!InternetCrackUrlA(lpszUrl, strlen(lpszUrl), 0, &urlComponents)) 1340 return NULL; 1341 switch(urlComponents.nScheme) { 1342 case INTERNET_SCHEME_FTP: 1343 if(urlComponents.nPort == 0) 1344 urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT; 1345 client = InternetConnectA(hInternet, hostName, urlComponents.nPort, 1346 userName, password, INTERNET_SERVICE_FTP, dwFlags, dwContext); 1347 return FtpOpenFileA(client, path, GENERIC_READ, dwFlags, dwContext); 1348 break; 1349 case INTERNET_SCHEME_HTTP: 1350 case INTERNET_SCHEME_HTTPS: 1351 { 1352 LPCSTR accept[2] = { "*/*", NULL }; 1353 char *hostreq=(char*)malloc(strlen(hostName)+9); 1354 sprintf(hostreq, "Host: %s\r\n", hostName); 1355 if(urlComponents.nPort == 0) { 1356 if(urlComponents.nScheme == INTERNET_SCHEME_HTTP) 1357 urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT; 1358 else 1359 urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT; 1360 } 1361 client = InternetConnectA(hInternet, hostName, urlComponents.nPort, userName, 1362 password, INTERNET_SERVICE_HTTP, dwFlags, dwContext); 1363 if(client == NULL) 1364 return NULL; 1365 client1 = HttpOpenRequestA(client, NULL, path, NULL, NULL, accept, dwFlags, dwContext); 1366 if(client1 == NULL) { 1367 InternetCloseHandle(client); 1368 return NULL; 1369 } 1370 if (lpszHeaders) 1371 HttpAddRequestHeadersA(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD); 1372 HttpAddRequestHeadersA(client1, hostreq, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW); 1373 if(!HttpSendRequestA(client1, NULL, 0, NULL, 0)) { 1374 InternetCloseHandle(client1); 1375 InternetCloseHandle(client); 1376 return NULL; 1377 } 1378 return client1; 1379 break; 1380 } 1381 case INTERNET_SCHEME_GOPHER: 1382 /* gopher doesn't seem to be implemented in wine, but it's supposed 1383 * to be supported by InternetOpenUrlA. */ 1384 default: 1385 return NULL; 1386 } 1387 if(client != NULL) 1388 InternetCloseHandle(client); 1389 } 1390 1391 /********************************************************** 1392 * InternetOpenUrlW (WININET.@) 1393 * 1394 * Opens an URL 1395 * 1396 * RETURNS 1397 * handle of connection or NULL on failure 1398 */ 1399 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl, 1400 LPCWSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext) 1401 { 1402 HINTERNET rc = (HINTERNET)NULL; 1403 1404 INT lenUrl = lstrlenW(lpszUrl)+1; 1405 INT lenHeaders = lstrlenW(lpszHeaders)+1; 1406 CHAR *szUrl = (CHAR *)malloc(lenUrl*sizeof(CHAR)); 1407 CHAR *szHeaders = (CHAR *)malloc(lenHeaders*sizeof(CHAR)); 1408 1409 if (!szUrl || !szHeaders) 1410 { 1411 if (szUrl) 1412 free(szUrl); 1413 if (szHeaders) 1414 free(szHeaders); 1415 return (HINTERNET)NULL; 1416 } 1417 1418 WideCharToMultiByte(CP_ACP, -1, lpszUrl, -1, szUrl, lenUrl, 1419 NULL, NULL); 1420 WideCharToMultiByte(CP_ACP, -1, lpszHeaders, -1, szHeaders, lenHeaders, 1421 NULL, NULL); 1422 1423 rc = InternetOpenUrlA(hInternet, szUrl, szHeaders, 1424 dwHeadersLength, dwFlags, dwContext); 1425 1426 free(szUrl); 1427 free(szHeaders); 1428 1429 return rc; 1430 } 1431 1432 /*********************************************************************** 1433 * InternetCrackUrlA (WININET.@) 1434 * 1435 * Break up URL into its components 1436 * 1437 * TODO: Handle dwFlags 1438 * 1439 * RETURNS 1440 * TRUE on success 1441 * FALSE on failure 1442 * 1443 */ 1444 BOOL WINAPI InternetCrackUrlA(LPCSTR lpszUrl, DWORD dwUrlLength, DWORD dwFlags, 1445 LPURL_COMPONENTSA lpUrlComponents) 1446 { 1447 /* 1448 * RFC 1808 1449 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>] 1450 * 1451 */ 1452 LPSTR lpszParam = NULL; 1453 BOOL bIsAbsolute = FALSE; 1454 LPSTR lpszap = (char*)lpszUrl; 1455 LPSTR lpszcp = NULL; 1456 1457 TRACE("\n"); 1458 1459 /* Determine if the URI is absolute. */ 1460 while (*lpszap != '\0') 1461 { 1462 if (isalnum(*lpszap)) 1463 { 1464 lpszap++; 1465 continue; 1466 } 1467 if ((*lpszap == ':') && (lpszap - lpszUrl >= 2)) 1468 { 1469 bIsAbsolute = TRUE; 1470 lpszcp = lpszap; 1471 } 1472 else 1473 { 1474 lpszcp = (LPSTR)lpszUrl; /* Relative url */ 1475 } 1476 1477 break; 1478 } 1479 1480 /* Parse <params> */ 1481 lpszParam = strpbrk(lpszap, ";?"); 1482 if (lpszParam != NULL) 1483 { 1484 if (!SetUrlComponentValue(&lpUrlComponents->lpszExtraInfo, 1485 &lpUrlComponents->dwExtraInfoLength, lpszParam+1, strlen(lpszParam+1))) 1486 { 1487 return FALSE; 1488 } 1489 } 1490 1491 if (bIsAbsolute) /* Parse <protocol>:[//<net_loc>] */ 1492 { 1493 LPSTR lpszNetLoc; 1494 1495 /* Get scheme first. */ 1496 lpUrlComponents->nScheme = GetInternetScheme(lpszUrl, lpszcp - lpszUrl); 1497 if (!SetUrlComponentValue(&lpUrlComponents->lpszScheme, 1498 &lpUrlComponents->dwSchemeLength, lpszUrl, lpszcp - lpszUrl)) 1499 return FALSE; 1500 1501 /* Eat ':' in protocol. */ 1502 lpszcp++; 1503 1504 /* Skip over slashes. */ 1505 if (*lpszcp == '/') 1506 { 1507 lpszcp++; 1508 if (*lpszcp == '/') 1509 { 1510 lpszcp++; 1511 if (*lpszcp == '/') 1512 lpszcp++; 1513 } 1514 } 1515 1516 lpszNetLoc = strpbrk(lpszcp, "/"); 1517 if (lpszParam) 1518 { 1519 if (lpszNetLoc) 1520 lpszNetLoc = min(lpszNetLoc, lpszParam); 1521 else 1522 lpszNetLoc = lpszParam; 1523 } 1524 else if (!lpszNetLoc) 1525 lpszNetLoc = lpszcp + strlen(lpszcp); 1526 1527 /* Parse net-loc */ 1528 if (lpszNetLoc) 1529 { 1530 LPSTR lpszHost; 1531 LPSTR lpszPort; 1532 1533 /* [<user>[<:password>]@]<host>[:<port>] */ 1534 /* First find the user and password if they exist */ 1535 1536 lpszHost = strchr(lpszcp, '@'); 1537 if (lpszHost == NULL || lpszHost > lpszNetLoc) 1538 { 1539 /* username and password not specified. */ 1540 SetUrlComponentValue(&lpUrlComponents->lpszUserName, 1541 &lpUrlComponents->dwUserNameLength, NULL, 0); 1542 SetUrlComponentValue(&lpUrlComponents->lpszPassword, 1543 &lpUrlComponents->dwPasswordLength, NULL, 0); 1544 } 1545 else /* Parse out username and password */ 1546 { 1547 LPSTR lpszUser = lpszcp; 1548 LPSTR lpszPasswd = lpszHost; 1549 1550 while (lpszcp < lpszHost) 1551 { 1552 if (*lpszcp == ':') 1553 lpszPasswd = lpszcp; 1554 1555 lpszcp++; 1556 } 1557 1558 SetUrlComponentValue(&lpUrlComponents->lpszUserName, 1559 &lpUrlComponents->dwUserNameLength, lpszUser, lpszPasswd - lpszUser); 1560 1561 if (lpszPasswd != lpszHost) 1562 lpszPasswd++; 1563 SetUrlComponentValue(&lpUrlComponents->lpszPassword, 1564 &lpUrlComponents->dwPasswordLength, 1565 lpszPasswd == lpszHost ? NULL : lpszPasswd, 1566 lpszHost - lpszPasswd); 1567 1568 lpszcp++; /* Advance to beginning of host */ 1569 } 1570 1571 /* Parse <host><:port> */ 1572 1573 lpszHost = lpszcp; 1574 lpszPort = lpszNetLoc; 1575 1576 while (lpszcp < lpszNetLoc) 1577 { 1578 if (*lpszcp == ':') 1579 lpszPort = lpszcp; 1580 1581 lpszcp++; 1582 } 1583 1584 SetUrlComponentValue(&lpUrlComponents->lpszHostName, 1585 &lpUrlComponents->dwHostNameLength, lpszHost, lpszPort - lpszHost); 1586 1587 if (lpszPort != lpszNetLoc) 1588 lpUrlComponents->nPort = atoi(++lpszPort); 1589 else 1590 lpUrlComponents->nPort = 0; 1591 } 1592 } 1593 1594 /* Here lpszcp points to: 1595 * 1596 * <protocol>:[//<net_loc>][/path][;<params>][?<query>][#<fragment>] 1597 * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1598 */ 1599 if (lpszcp != 0 && *lpszcp != '\0' && (!lpszParam || lpszcp < lpszParam)) 1600 { 1601 INT len; 1602 1603 /* Only truncate the parameter list if it's already been saved 1604 * in lpUrlComponents->lpszExtraInfo. 1605 */ 1606 if (lpszParam && lpUrlComponents->dwExtraInfoLength) 1607 len = lpszParam - lpszcp; 1608 else 1609 { 1610 /* Leave the parameter list in lpszUrlPath. Strip off any trailing 1611 * newlines if necessary. 1612 */ 1613 LPSTR lpsznewline = strchr (lpszcp, '\n'); 1614 if (lpsznewline != NULL) 1615 len = lpsznewline - lpszcp; 1616 else 1617 len = strlen(lpszcp); 1618 } 1619 1620 if (!SetUrlComponentValue(&lpUrlComponents->lpszUrlPath, 1621 &lpUrlComponents->dwUrlPathLength, lpszcp, len)) 1622 return FALSE; 1623 } 1624 else 1625 { 1626 lpUrlComponents->dwUrlPathLength = 0; 1627 } 1628 1629 TRACE("%s: host(%s) path(%s) extra(%s)\n", lpszUrl, lpUrlComponents->lpszHostName, 1630 lpUrlComponents->lpszUrlPath, lpUrlComponents->lpszExtraInfo); 1631 1632 return TRUE; 1633 } 1634 -
trunk/src/wininet/wininet.cpp
r4842 r9439 1 /* $Id: wininet.cpp,v 1. 3 2000-12-27 23:06:17 sandervl Exp $ */1 /* $Id: wininet.cpp,v 1.4 2002-11-27 14:28:17 sandervl Exp $ */ 2 2 /* 3 3 * WININET stubs … … 90 90 //****************************************************************************** 91 91 //****************************************************************************** 92 HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl, LPCSTR lpszHeaders,93 DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)94 {dprintf(("ERROR:"__FUNCTION__" not implemented"));95 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);96 return 0;97 }98 //******************************************************************************99 //******************************************************************************100 HINTERNET WINAPI InternetOpenUrlW(HINTERNET hInternet, LPCWSTR lpszUrl, LPCWSTR lpszHeaders,101 DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext)102 {dprintf(("ERROR:"__FUNCTION__" not implemented"));103 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);104 return 0;105 }106 //******************************************************************************107 //******************************************************************************108 92 DWORD WINAPI InternetSetFilePointer(HINTERNET hFile, LONG lDistanceToMove, 109 93 PVOID pReserved, DWORD dwMoveMethod,
Note:
See TracChangeset
for help on using the changeset viewer.