From 6c8d315a72786936a831436d4494dac7e52393b7 Mon Sep 17 00:00:00 2001 From: Hans Leidekker Date: Fri, 9 May 2008 15:23:46 +0200 Subject: [PATCH] wininet: Implement INTERNET_OPTION_USER_AGENT for InternetQueryOption. --- dlls/wininet/internet.c | 37 +++++++++++++++++++++++++++++++++-- dlls/wininet/tests/internet.c | 14 ++++++------- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 69b6897a95f..856f302742f 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -1895,9 +1895,42 @@ static BOOL INET_QueryOptionHelper(BOOL bIsUnicode, HINTERNET hInternet, DWORD d } case INTERNET_OPTION_USER_AGENT: - FIXME("INTERNET_OPTION_USER_AGENT\n"); - break; + { + DWORD required; + LPWININETAPPINFOW ai = (LPWININETAPPINFOW)lpwhh; + TRACE("INTERNET_OPTION_USER_AGENT\n"); + + if (lpwhh->htype != INTERNET_HANDLE_TYPE_INTERNET) + { + INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); + return FALSE; + } + if (bIsUnicode) + { + required = (strlenW(ai->lpszAgent) + 1) * sizeof(WCHAR); + if (*lpdwBufferLength < required) + INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); + else if (lpBuffer) + { + strcpyW(lpBuffer, ai->lpszAgent); + bSuccess = TRUE; + } + } + else + { + required = WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, NULL, 0, NULL, NULL); + if (*lpdwBufferLength < required) + INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER); + else if (lpBuffer) + { + WideCharToMultiByte(CP_ACP, 0, ai->lpszAgent, -1, lpBuffer, required, NULL, NULL); + bSuccess = TRUE; + } + } + *lpdwBufferLength = required; + break; + } case INTERNET_OPTION_HTTP_VERSION: { if (*lpdwBufferLength < sizeof(HTTP_VERSION_INFO)) diff --git a/dlls/wininet/tests/internet.c b/dlls/wininet/tests/internet.c index 15495db514d..9f08b777833 100644 --- a/dlls/wininet/tests/internet.c +++ b/dlls/wininet/tests/internet.c @@ -146,10 +146,10 @@ static void test_InternetQueryOptionA(void) buffer=HeapAlloc(GetProcessHeap(),0,len); retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len); err=GetLastError(); - todo_wine ok(retval == 1,"Got wrong return value %d\n",retval); + ok(retval == 1,"Got wrong return value %d\n",retval); if (retval) { - todo_wine ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent); + ok(!strcmp(useragent,buffer),"Got wrong user agent string %s instead of %s\n",buffer,useragent); todo_wine ok(len == strlen(useragent),"Got wrong user agent length %d instead of %d\n",len,lstrlenA(useragent)); } ok(err == 0xdeadbeef, "Got wrong error code %d\n",err); @@ -160,9 +160,9 @@ static void test_InternetQueryOptionA(void) buffer=HeapAlloc(GetProcessHeap(),0,100); retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,buffer,&len); err=GetLastError(); - todo_wine ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1); + ok(len == strlen(useragent) + 1,"Got wrong user agent length %d instead of %d\n", len, lstrlenA(useragent) + 1); ok(!retval, "Got wrong return value %d\n", retval); - todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err); + ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code %d\n", err); HeapFree(GetProcessHeap(),0,buffer); hurl = InternetConnectA(hinet,"www.winehq.com",INTERNET_DEFAULT_HTTP_PORT,NULL,NULL,INTERNET_SERVICE_HTTP,0,0); @@ -173,7 +173,7 @@ static void test_InternetQueryOptionA(void) err=GetLastError(); ok(len == 0,"Got wrong user agent length %d instead of 0\n",len); ok(retval == 0,"Got wrong return value %d\n",retval); - todo_wine ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err); + ok(err == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Got wrong error code %d\n",err); InternetCloseHandle(hurl); InternetCloseHandle(hinet); @@ -185,9 +185,9 @@ static void test_InternetQueryOptionA(void) len=0; retval=InternetQueryOptionA(hinet,INTERNET_OPTION_USER_AGENT,NULL,&len); err=GetLastError(); - todo_wine ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1); + ok(len == 1,"Got wrong user agent length %d instead of %d\n",len,1); ok(retval == 0,"Got wrong return value %d\n",retval); - todo_wine ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err); + ok(err == ERROR_INSUFFICIENT_BUFFER, "Got wrong error code%d\n",err); InternetCloseHandle(hinet);