2002-06-01 01:06:46 +02:00
|
|
|
/*
|
2000-04-11 22:07:00 +02:00
|
|
|
* Wininet - Utility functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Corel Corporation
|
2002-06-22 01:59:49 +02:00
|
|
|
* Copyright 2002 CodeWeavers Inc.
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Ulrich Czekalla
|
2002-06-22 01:59:49 +02:00
|
|
|
* Aric Stewart
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
2002-03-10 00:29:33 +01:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2000-04-11 22:07:00 +02:00
|
|
|
*/
|
|
|
|
|
2000-11-30 02:31:28 +01:00
|
|
|
#include "config.h"
|
2004-09-03 20:30:28 +02:00
|
|
|
#include "wine/port.h"
|
2000-11-30 02:31:28 +01:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-04-11 22:07:00 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2000-11-30 02:31:28 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
2000-04-11 22:07:00 +02:00
|
|
|
#include "wininet.h"
|
|
|
|
#include "winerror.h"
|
2004-03-30 06:36:09 +02:00
|
|
|
#include "winnls.h"
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-04-11 22:07:00 +02:00
|
|
|
#include "internet.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
#define TIME_STRING_LEN 30
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
time_t ConvertTimeString(LPCWSTR asctime)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR tmpChar[TIME_STRING_LEN];
|
|
|
|
WCHAR *tmpChar2;
|
2001-09-19 22:30:52 +02:00
|
|
|
struct tm t;
|
2004-03-30 06:36:09 +02:00
|
|
|
int timelen = strlenW(asctime);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if(!asctime || !timelen)
|
|
|
|
return 0;
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
strncpyW(tmpChar, asctime, TIME_STRING_LEN);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/* Assert that the string is the expected length */
|
|
|
|
if (tmpChar[TIME_STRING_LEN] != '\0')
|
2002-06-01 01:06:46 +02:00
|
|
|
{
|
2000-04-11 22:07:00 +02:00
|
|
|
tmpChar[TIME_STRING_LEN] = '\0';
|
|
|
|
FIXME("\n");
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
|
|
|
|
* We assume the time is in this format
|
|
|
|
* and divide it into easy to swallow chunks
|
|
|
|
*/
|
|
|
|
tmpChar[3]='\0';
|
|
|
|
tmpChar[7]='\0';
|
|
|
|
tmpChar[11]='\0';
|
|
|
|
tmpChar[16]='\0';
|
|
|
|
tmpChar[19]='\0';
|
|
|
|
tmpChar[22]='\0';
|
|
|
|
tmpChar[25]='\0';
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
t.tm_year = atoiW(tmpChar+12) - 1900;
|
|
|
|
t.tm_mday = atoiW(tmpChar+5);
|
|
|
|
t.tm_hour = atoiW(tmpChar+17);
|
|
|
|
t.tm_min = atoiW(tmpChar+20);
|
|
|
|
t.tm_sec = atoiW(tmpChar+23);
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* and month */
|
|
|
|
tmpChar2 = tmpChar + 8;
|
|
|
|
switch(tmpChar2[2])
|
|
|
|
{
|
|
|
|
case 'n':
|
|
|
|
if(tmpChar2[1]=='a')
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 0;
|
2000-04-11 22:07:00 +02:00
|
|
|
else
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 5;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'b':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 1;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
if(tmpChar2[1]=='a')
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 2;
|
2000-04-11 22:07:00 +02:00
|
|
|
else
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 3;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'y':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 4;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'l':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 6;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'g':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 7;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'p':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 8;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 't':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 9;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'v':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 10;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
case 'c':
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_mon = 11;
|
2000-04-11 22:07:00 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
FIXME("\n");
|
|
|
|
}
|
|
|
|
|
2001-09-19 22:30:52 +02:00
|
|
|
return mktime(&t);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
|
2000-04-11 22:07:00 +02:00
|
|
|
struct hostent **phe, struct sockaddr_in *psa)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
WCHAR *found;
|
|
|
|
char *name;
|
|
|
|
int len, sz;
|
2001-10-04 20:12:41 +02:00
|
|
|
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("%s\n", debugstr_w(lpszServerName));
|
2000-06-11 22:04:44 +02:00
|
|
|
|
2001-10-04 20:12:41 +02:00
|
|
|
/* Validate server name first
|
|
|
|
* Check if there is sth. like
|
|
|
|
* pinger.macromedia.com:80
|
|
|
|
* if yes, eliminate the :80....
|
|
|
|
*/
|
2004-03-30 06:36:09 +02:00
|
|
|
found = strchrW(lpszServerName, ':');
|
2001-10-04 20:12:41 +02:00
|
|
|
if (found)
|
2004-03-30 06:36:09 +02:00
|
|
|
len = found - lpszServerName;
|
|
|
|
else
|
|
|
|
len = strlenW(lpszServerName);
|
|
|
|
|
|
|
|
sz = WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, NULL, 0, NULL, NULL );
|
|
|
|
name = HeapAlloc(GetProcessHeap(), 0, sz+1);
|
|
|
|
WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, name, sz, NULL, NULL );
|
|
|
|
name[sz] = 0;
|
|
|
|
*phe = gethostbyname(name);
|
|
|
|
HeapFree( GetProcessHeap(), 0, name );
|
2001-10-04 20:12:41 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
if (NULL == *phe)
|
|
|
|
{
|
2004-03-30 06:36:09 +02:00
|
|
|
TRACE("Failed to get hostname: (%s)\n", debugstr_w(lpszServerName) );
|
2000-04-11 22:07:00 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(psa,0,sizeof(struct sockaddr_in));
|
|
|
|
memcpy((char *)&psa->sin_addr, (*phe)->h_addr, (*phe)->h_length);
|
|
|
|
psa->sin_family = (*phe)->h_addrtype;
|
|
|
|
psa->sin_port = htons((u_short)nServerPort);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function for sending async Callbacks
|
|
|
|
*/
|
|
|
|
|
2004-02-09 23:01:49 +01:00
|
|
|
static const char *get_callback_name(DWORD dwInternetStatus) {
|
|
|
|
static const wininet_flag_info internet_status[] = {
|
|
|
|
#define FE(x) { x, #x }
|
|
|
|
FE(INTERNET_STATUS_RESOLVING_NAME),
|
|
|
|
FE(INTERNET_STATUS_NAME_RESOLVED),
|
|
|
|
FE(INTERNET_STATUS_CONNECTING_TO_SERVER),
|
|
|
|
FE(INTERNET_STATUS_CONNECTED_TO_SERVER),
|
|
|
|
FE(INTERNET_STATUS_SENDING_REQUEST),
|
|
|
|
FE(INTERNET_STATUS_REQUEST_SENT),
|
|
|
|
FE(INTERNET_STATUS_RECEIVING_RESPONSE),
|
|
|
|
FE(INTERNET_STATUS_RESPONSE_RECEIVED),
|
|
|
|
FE(INTERNET_STATUS_CTL_RESPONSE_RECEIVED),
|
|
|
|
FE(INTERNET_STATUS_PREFETCH),
|
|
|
|
FE(INTERNET_STATUS_CLOSING_CONNECTION),
|
|
|
|
FE(INTERNET_STATUS_CONNECTION_CLOSED),
|
|
|
|
FE(INTERNET_STATUS_HANDLE_CREATED),
|
|
|
|
FE(INTERNET_STATUS_HANDLE_CLOSING),
|
|
|
|
FE(INTERNET_STATUS_REQUEST_COMPLETE),
|
|
|
|
FE(INTERNET_STATUS_REDIRECT),
|
|
|
|
FE(INTERNET_STATUS_INTERMEDIATE_RESPONSE),
|
|
|
|
FE(INTERNET_STATUS_USER_INPUT_REQUIRED),
|
|
|
|
FE(INTERNET_STATUS_STATE_CHANGE),
|
|
|
|
FE(INTERNET_STATUS_COOKIE_SENT),
|
|
|
|
FE(INTERNET_STATUS_COOKIE_RECEIVED),
|
|
|
|
FE(INTERNET_STATUS_PRIVACY_IMPACTED),
|
|
|
|
FE(INTERNET_STATUS_P3P_HEADER),
|
|
|
|
FE(INTERNET_STATUS_P3P_POLICYREF),
|
|
|
|
FE(INTERNET_STATUS_COOKIE_HISTORY),
|
|
|
|
FE(INTERNET_STATE_CONNECTED),
|
|
|
|
FE(INTERNET_STATE_DISCONNECTED),
|
|
|
|
FE(INTERNET_STATE_DISCONNECTED_BY_USER),
|
|
|
|
FE(INTERNET_STATE_IDLE),
|
|
|
|
FE(INTERNET_STATE_BUSY)
|
|
|
|
#undef FE
|
|
|
|
};
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD i;
|
2004-02-09 23:01:49 +01:00
|
|
|
|
|
|
|
for (i = 0; i < (sizeof(internet_status) / sizeof(internet_status[0])); i++) {
|
|
|
|
if (internet_status[i].val == dwInternetStatus) return internet_status[i].name;
|
|
|
|
}
|
|
|
|
return "Unknown";
|
|
|
|
}
|
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
VOID SendSyncCallback(LPWININETHANDLEHEADER hdr, DWORD dwContext,
|
|
|
|
DWORD dwInternetStatus, LPVOID lpvStatusInfo,
|
|
|
|
DWORD dwStatusInfoLength)
|
2002-06-22 01:59:49 +02:00
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
HINTERNET hHttpSession;
|
2004-05-25 06:02:05 +02:00
|
|
|
LPVOID lpvNewInfo = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
if( !hdr->lpfnStatusCB )
|
2004-05-25 06:02:05 +02:00
|
|
|
return;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
/* the IE5 version of wininet does not
|
|
|
|
send callbacks if dwContext is zero */
|
|
|
|
if( !dwContext )
|
|
|
|
return;
|
2003-07-19 00:59:25 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("--> Callback %ld (%s)\n",dwInternetStatus, get_callback_name(dwInternetStatus));
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
hHttpSession = WININET_FindHandle( hdr );
|
|
|
|
if( !hHttpSession )
|
|
|
|
return;
|
|
|
|
|
2004-06-14 18:56:10 +02:00
|
|
|
lpvNewInfo = lpvStatusInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if(!(hdr->dwInternalFlags & INET_CALLBACKW)) {
|
2004-06-14 18:56:10 +02:00
|
|
|
switch(dwInternetStatus)
|
|
|
|
{
|
|
|
|
case INTERNET_STATUS_RESOLVING_NAME:
|
|
|
|
case INTERNET_STATUS_REDIRECT:
|
2004-05-25 06:02:05 +02:00
|
|
|
lpvNewInfo = WININET_strdup_WtoA(lpvStatusInfo);
|
2004-06-14 18:56:10 +02:00
|
|
|
}
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
2004-09-20 21:10:31 +02:00
|
|
|
hdr->lpfnStatusCB(hHttpSession, dwContext, dwInternetStatus,
|
2004-06-14 18:56:10 +02:00
|
|
|
lpvNewInfo, dwStatusInfoLength);
|
|
|
|
if(lpvNewInfo != lpvStatusInfo)
|
2004-05-25 06:02:05 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpvNewInfo);
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("<-- Callback %ld (%s)\n",dwInternetStatus, get_callback_name(dwInternetStatus));
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
WININET_Release( hdr );
|
2002-06-22 01:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
VOID SendAsyncCallback(LPWININETHANDLEHEADER hdr, DWORD dwContext,
|
|
|
|
DWORD dwInternetStatus, LPVOID lpvStatusInfo,
|
|
|
|
DWORD dwStatusInfoLength)
|
2002-06-22 01:59:49 +02:00
|
|
|
{
|
2004-02-09 23:01:49 +01:00
|
|
|
TRACE("Send Callback %ld (%s)\n",dwInternetStatus, get_callback_name(dwInternetStatus));
|
2002-06-22 01:59:49 +02:00
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
if (!(hdr->lpfnStatusCB))
|
2002-06-22 01:59:49 +02:00
|
|
|
return;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hdr->dwFlags & INTERNET_FLAG_ASYNC)
|
2002-06-22 01:59:49 +02:00
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2003-09-25 22:25:22 +02:00
|
|
|
struct WORKREQ_SENDCALLBACK *req;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
workRequest.asyncall = SENDCALLBACK;
|
2004-09-20 21:10:31 +02:00
|
|
|
workRequest.hdr = WININET_AddRef( hdr );
|
2003-09-25 22:25:22 +02:00
|
|
|
req = &workRequest.u.SendCallback;
|
|
|
|
req->dwContext = dwContext;
|
|
|
|
req->dwInternetStatus = dwInternetStatus;
|
|
|
|
req->lpvStatusInfo = lpvStatusInfo;
|
|
|
|
req->dwStatusInfoLength = dwStatusInfoLength;
|
2002-06-22 01:59:49 +02:00
|
|
|
|
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
}
|
|
|
|
else
|
2004-09-20 21:10:31 +02:00
|
|
|
SendSyncCallback(hdr, dwContext, dwInternetStatus,
|
|
|
|
lpvStatusInfo, dwStatusInfoLength);
|
2002-06-22 01:59:49 +02:00
|
|
|
}
|