From e00aca0298accd7fccb6dfdefadd08d5c6ab6e26 Mon Sep 17 00:00:00 2001 From: Bernhard Rosenkraenzer <bero@redhat.de> Date: Wed, 20 Mar 2002 00:56:49 +0000 Subject: [PATCH] Added InternetOpenURLA implementation. --- dlls/wininet/internet.c | 81 +++++++++++++++++++++++++++++++++++++-- dlls/wininet/wininet.spec | 2 +- 2 files changed, 79 insertions(+), 4 deletions(-) diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index e67c4ca10f2..3e5e30ce776 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -22,7 +22,10 @@ #include "config.h" +#define MAXHOSTNAME 100 /* from http.c */ + #include <string.h> +#include <stdio.h> #include <sys/types.h> #ifdef HAVE_SYS_SOCKET_H # include <sys/socket.h> @@ -517,7 +520,7 @@ BOOL SetUrlComponentValue(LPSTR* lppszComponent, LPDWORD dwComponentLen, LPCSTR * * Break up URL into its components * - * TODO: Hadnle dwFlags + * TODO: Handle dwFlags * * RETURNS * TRUE on success @@ -1165,7 +1168,80 @@ End: return rc; } - +/********************************************************** + * InternetOpenUrlA (WININET.@) + * + * Opens an URL + * + * RETURNS + * handle of connection or NULL on failure + */ +HINTERNET WINAPI InternetOpenUrlA(HINTERNET hInternet, LPCSTR lpszUrl, LPCSTR lpszHeaders, DWORD dwHeadersLength, DWORD dwFlags, DWORD dwContext) +{ + URL_COMPONENTSA urlComponents; + char protocol[32], hostName[MAXHOSTNAME], userName[1024], password[1024], path[2048], extra[1024]; + HINTERNET client = NULL, client1 = NULL; + urlComponents.dwStructSize = sizeof(URL_COMPONENTSA); + urlComponents.lpszScheme = protocol; + urlComponents.dwSchemeLength = 32; + urlComponents.lpszHostName = hostName; + urlComponents.dwHostNameLength = MAXHOSTNAME; + urlComponents.lpszUserName = userName; + urlComponents.dwUserNameLength = 1024; + urlComponents.lpszPassword = password; + urlComponents.dwPasswordLength = 1024; + urlComponents.lpszUrlPath = path; + urlComponents.dwUrlPathLength = 2048; + urlComponents.lpszExtraInfo = extra; + urlComponents.dwExtraInfoLength = 1024; + if(!InternetCrackUrlA(lpszUrl, strlen(lpszUrl), 0, &urlComponents)) + return NULL; + switch(urlComponents.nScheme) { + case INTERNET_SCHEME_FTP: + if(urlComponents.nPort == 0) + urlComponents.nPort = INTERNET_DEFAULT_FTP_PORT; + client = InternetConnectA(hInternet, hostName, urlComponents.nPort, userName, password, INTERNET_SERVICE_FTP, dwFlags, dwContext); + return FtpOpenFileA(client, path, GENERIC_READ, dwFlags, dwContext); + break; + case INTERNET_SCHEME_HTTP: + case INTERNET_SCHEME_HTTPS: + { + LPCSTR accept[2] = { "*/*", NULL }; + char *hostreq=(char*)malloc(strlen(hostName)+9); + sprintf(hostreq, "Host: %s\r\n", hostName); + if(urlComponents.nPort == 0) { + if(urlComponents.nScheme == INTERNET_SCHEME_HTTP) + urlComponents.nPort = INTERNET_DEFAULT_HTTP_PORT; + else + urlComponents.nPort = INTERNET_DEFAULT_HTTPS_PORT; + } + client = InternetConnectA(hInternet, hostName, urlComponents.nPort, userName, password, INTERNET_SERVICE_HTTP, dwFlags, dwContext); + if(client == NULL) + return NULL; + client1 = HttpOpenRequestA(hInternet, NULL, path, NULL, NULL, accept, dwFlags, dwContext); + if(client1 == NULL) { + InternetCloseHandle(client); + return NULL; + } + HttpAddRequestHeadersA(client1, lpszHeaders, dwHeadersLength, HTTP_ADDREQ_FLAG_ADD); + HttpAddRequestHeadersA(client1, hostreq, -1L, HTTP_ADDREQ_FLAG_ADD_IF_NEW); + if(!HttpSendRequestA(client1, NULL, 0, NULL, 0)) { + InternetCloseHandle(client1); + InternetCloseHandle(client); + return NULL; + } + return client1; + break; + } + case INTERNET_SCHEME_GOPHER: + /* gopher doesn't seem to be implemented in wine, but it's supposed + * to be supported by InternetOpenUrlA. */ + default: + return NULL; + } + if(client != NULL) + InternetCloseHandle(client); +} /*********************************************************************** * INTERNET_WriteDataToStream (internal) @@ -1586,4 +1662,3 @@ lend: return NULL; } } - diff --git a/dlls/wininet/wininet.spec b/dlls/wininet/wininet.spec index 3902cfa9e40..1189d7af6c2 100644 --- a/dlls/wininet/wininet.spec +++ b/dlls/wininet/wininet.spec @@ -123,7 +123,7 @@ debug_channels (wininet) @ stub InternetLockRequestFile @ stdcall InternetOpenA(str long str str long) InternetOpenA @ stub InternetOpenServerPushParse -@ stub InternetOpenUrlA +@ stdcall InternetOpenUrlA(ptr str str long long long) InternetOpenUrlA @ stub InternetOpenUrlW @ stub InternetOpenW @ stub InternetQueryDataAvailable -- GitLab