2 * Wininet - Utility functions
4 * Copyright 1999 Corel Corporation
5 * Copyright 2002 CodeWeavers Inc.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
43 #define TIME_STRING_LEN 30
45 time_t ConvertTimeString(LPCWSTR asctime)
47 WCHAR tmpChar[TIME_STRING_LEN];
50 int timelen = strlenW(asctime);
52 if(!asctime || !timelen)
55 strncpyW(tmpChar, asctime, TIME_STRING_LEN);
57 /* Assert that the string is the expected length */
58 if (tmpChar[TIME_STRING_LEN] != '\0')
60 tmpChar[TIME_STRING_LEN] = '\0';
64 /* Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
65 * We assume the time is in this format
66 * and divide it into easy to swallow chunks
76 t.tm_year = atoiW(tmpChar+12) - 1900;
77 t.tm_mday = atoiW(tmpChar+5);
78 t.tm_hour = atoiW(tmpChar+17);
79 t.tm_min = atoiW(tmpChar+20);
80 t.tm_sec = atoiW(tmpChar+23);
83 tmpChar2 = tmpChar + 8;
130 BOOL GetAddress(LPCWSTR lpszServerName, INTERNET_PORT nServerPort,
131 struct hostent **phe, struct sockaddr_in *psa)
137 TRACE("%s\n", debugstr_w(lpszServerName));
139 /* Validate server name first
140 * Check if there is sth. like
141 * pinger.macromedia.com:80
142 * if yes, eliminate the :80....
144 found = strchrW(lpszServerName, ':');
146 len = found - lpszServerName;
148 len = strlenW(lpszServerName);
150 sz = WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, NULL, 0, NULL, NULL );
151 name = HeapAlloc(GetProcessHeap(), 0, sz+1);
152 WideCharToMultiByte( CP_UNIXCP, 0, lpszServerName, len, name, sz, NULL, NULL );
154 *phe = gethostbyname(name);
155 HeapFree( GetProcessHeap(), 0, name );
159 TRACE("Failed to get hostname: (%s)\n", debugstr_w(lpszServerName) );
163 memset(psa,0,sizeof(struct sockaddr_in));
164 memcpy((char *)&psa->sin_addr, (*phe)->h_addr, (*phe)->h_length);
165 psa->sin_family = (*phe)->h_addrtype;
166 psa->sin_port = htons((u_short)nServerPort);
172 * Helper function for sending async Callbacks
175 static const char *get_callback_name(DWORD dwInternetStatus) {
176 static const wininet_flag_info internet_status[] = {
177 #define FE(x) { x, #x }
178 FE(INTERNET_STATUS_RESOLVING_NAME),
179 FE(INTERNET_STATUS_NAME_RESOLVED),
180 FE(INTERNET_STATUS_CONNECTING_TO_SERVER),
181 FE(INTERNET_STATUS_CONNECTED_TO_SERVER),
182 FE(INTERNET_STATUS_SENDING_REQUEST),
183 FE(INTERNET_STATUS_REQUEST_SENT),
184 FE(INTERNET_STATUS_RECEIVING_RESPONSE),
185 FE(INTERNET_STATUS_RESPONSE_RECEIVED),
186 FE(INTERNET_STATUS_CTL_RESPONSE_RECEIVED),
187 FE(INTERNET_STATUS_PREFETCH),
188 FE(INTERNET_STATUS_CLOSING_CONNECTION),
189 FE(INTERNET_STATUS_CONNECTION_CLOSED),
190 FE(INTERNET_STATUS_HANDLE_CREATED),
191 FE(INTERNET_STATUS_HANDLE_CLOSING),
192 FE(INTERNET_STATUS_REQUEST_COMPLETE),
193 FE(INTERNET_STATUS_REDIRECT),
194 FE(INTERNET_STATUS_INTERMEDIATE_RESPONSE),
195 FE(INTERNET_STATUS_USER_INPUT_REQUIRED),
196 FE(INTERNET_STATUS_STATE_CHANGE),
197 FE(INTERNET_STATUS_COOKIE_SENT),
198 FE(INTERNET_STATUS_COOKIE_RECEIVED),
199 FE(INTERNET_STATUS_PRIVACY_IMPACTED),
200 FE(INTERNET_STATUS_P3P_HEADER),
201 FE(INTERNET_STATUS_P3P_POLICYREF),
202 FE(INTERNET_STATUS_COOKIE_HISTORY),
203 FE(INTERNET_STATE_CONNECTED),
204 FE(INTERNET_STATE_DISCONNECTED),
205 FE(INTERNET_STATE_DISCONNECTED_BY_USER),
206 FE(INTERNET_STATE_IDLE),
207 FE(INTERNET_STATE_BUSY)
212 for (i = 0; i < (sizeof(internet_status) / sizeof(internet_status[0])); i++) {
213 if (internet_status[i].val == dwInternetStatus) return internet_status[i].name;
218 VOID SendAsyncCallbackInt(LPWININETAPPINFOW hIC, HINTERNET hHttpSession,
219 DWORD dwContext, DWORD dwInternetStatus, LPVOID
220 lpvStatusInfo, DWORD dwStatusInfoLength)
222 if (! (hIC->lpfnStatusCB))
225 /* the IE5 version of wininet does not
226 send callbacks if dwContext is zero */
230 TRACE("--> Callback %ld (%s)\n",dwInternetStatus, get_callback_name(dwInternetStatus));
232 hIC->lpfnStatusCB(hHttpSession, dwContext, dwInternetStatus,
233 lpvStatusInfo, dwStatusInfoLength);
235 TRACE("<-- Callback %ld (%s)\n",dwInternetStatus, get_callback_name(dwInternetStatus));
240 VOID SendAsyncCallback(LPWININETAPPINFOW hIC, HINTERNET hHttpSession,
241 DWORD dwContext, DWORD dwInternetStatus, LPVOID
242 lpvStatusInfo, DWORD dwStatusInfoLength)
244 TRACE("Send Callback %ld (%s)\n",dwInternetStatus, get_callback_name(dwInternetStatus));
246 if (! (hIC->lpfnStatusCB))
248 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
250 WORKREQUEST workRequest;
251 struct WORKREQ_SENDCALLBACK *req;
253 workRequest.asyncall = SENDCALLBACK;
254 workRequest.handle = hIC;
255 req = &workRequest.u.SendCallback;
256 req->hHttpSession = hHttpSession;
257 req->dwContext = dwContext;
258 req->dwInternetStatus = dwInternetStatus;
259 req->lpvStatusInfo = lpvStatusInfo;
260 req->dwStatusInfoLength = dwStatusInfoLength;
262 INTERNET_AsyncCall(&workRequest);
265 SendAsyncCallbackInt(hIC, hHttpSession, dwContext, dwInternetStatus,
266 lpvStatusInfo, dwStatusInfoLength);