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
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(wininet
);
42 #define TIME_STRING_LEN 30
44 time_t ConvertTimeString(LPCSTR asctime
)
46 char tmpChar
[TIME_STRING_LEN
];
49 int timelen
= strlen(asctime
);
51 if(!asctime
|| !timelen
)
54 strncpy(tmpChar
, asctime
, TIME_STRING_LEN
);
56 /* Assert that the string is the expected length */
57 if (tmpChar
[TIME_STRING_LEN
] != '\0')
59 tmpChar
[TIME_STRING_LEN
] = '\0';
63 /* Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
64 * We assume the time is in this format
65 * and divide it into easy to swallow chunks
75 t
.tm_year
= atoi(tmpChar
+12) - 1900;
76 t
.tm_mday
= atoi(tmpChar
+5);
77 t
.tm_hour
= atoi(tmpChar
+17);
78 t
.tm_min
= atoi(tmpChar
+20);
79 t
.tm_sec
= atoi(tmpChar
+23);
82 tmpChar2
= tmpChar
+ 8;
129 BOOL
GetAddress(LPCSTR lpszServerName
, INTERNET_PORT nServerPort
,
130 struct hostent
**phe
, struct sockaddr_in
*psa
)
134 TRACE("%s\n", lpszServerName
);
136 /* Validate server name first
137 * Check if there is sth. like
138 * pinger.macromedia.com:80
139 * if yes, eliminate the :80....
141 found
= strchr(lpszServerName
, ':');
144 int len
= found
- lpszServerName
;
145 char *new = HeapAlloc(GetProcessHeap(), 0, len
+ 1);
146 memcpy( new, lpszServerName
, len
);
148 TRACE("Found a ':' inside the server name, reparsed name: %s\n", new);
149 *phe
= gethostbyname(new);
150 HeapFree( GetProcessHeap(), 0, new );
152 else *phe
= gethostbyname(lpszServerName
);
156 TRACE("Failed to get hostname: (%s)\n", lpszServerName
);
160 memset(psa
,0,sizeof(struct sockaddr_in
));
161 memcpy((char *)&psa
->sin_addr
, (*phe
)->h_addr
, (*phe
)->h_length
);
162 psa
->sin_family
= (*phe
)->h_addrtype
;
163 psa
->sin_port
= htons((u_short
)nServerPort
);
169 * Helper function for sending async Callbacks
172 static const char *get_callback_name(DWORD dwInternetStatus
) {
173 static const wininet_flag_info internet_status
[] = {
174 #define FE(x) { x, #x }
175 FE(INTERNET_STATUS_RESOLVING_NAME
),
176 FE(INTERNET_STATUS_NAME_RESOLVED
),
177 FE(INTERNET_STATUS_CONNECTING_TO_SERVER
),
178 FE(INTERNET_STATUS_CONNECTED_TO_SERVER
),
179 FE(INTERNET_STATUS_SENDING_REQUEST
),
180 FE(INTERNET_STATUS_REQUEST_SENT
),
181 FE(INTERNET_STATUS_RECEIVING_RESPONSE
),
182 FE(INTERNET_STATUS_RESPONSE_RECEIVED
),
183 FE(INTERNET_STATUS_CTL_RESPONSE_RECEIVED
),
184 FE(INTERNET_STATUS_PREFETCH
),
185 FE(INTERNET_STATUS_CLOSING_CONNECTION
),
186 FE(INTERNET_STATUS_CONNECTION_CLOSED
),
187 FE(INTERNET_STATUS_HANDLE_CREATED
),
188 FE(INTERNET_STATUS_HANDLE_CLOSING
),
189 FE(INTERNET_STATUS_REQUEST_COMPLETE
),
190 FE(INTERNET_STATUS_REDIRECT
),
191 FE(INTERNET_STATUS_INTERMEDIATE_RESPONSE
),
192 FE(INTERNET_STATUS_USER_INPUT_REQUIRED
),
193 FE(INTERNET_STATUS_STATE_CHANGE
),
194 FE(INTERNET_STATUS_COOKIE_SENT
),
195 FE(INTERNET_STATUS_COOKIE_RECEIVED
),
196 FE(INTERNET_STATUS_PRIVACY_IMPACTED
),
197 FE(INTERNET_STATUS_P3P_HEADER
),
198 FE(INTERNET_STATUS_P3P_POLICYREF
),
199 FE(INTERNET_STATUS_COOKIE_HISTORY
),
200 FE(INTERNET_STATE_CONNECTED
),
201 FE(INTERNET_STATE_DISCONNECTED
),
202 FE(INTERNET_STATE_DISCONNECTED_BY_USER
),
203 FE(INTERNET_STATE_IDLE
),
204 FE(INTERNET_STATE_BUSY
)
209 for (i
= 0; i
< (sizeof(internet_status
) / sizeof(internet_status
[0])); i
++) {
210 if (internet_status
[i
].val
== dwInternetStatus
) return internet_status
[i
].name
;
215 VOID
SendAsyncCallbackInt(LPWININETAPPINFOA hIC
, HINTERNET hHttpSession
,
216 DWORD dwContext
, DWORD dwInternetStatus
, LPVOID
217 lpvStatusInfo
, DWORD dwStatusInfoLength
)
219 if (! (hIC
->lpfnStatusCB
))
222 /* the IE5 version of wininet does not
223 send callbacks if dwContext is zero */
227 TRACE("--> Callback %ld (%s)\n",dwInternetStatus
, get_callback_name(dwInternetStatus
));
229 hIC
->lpfnStatusCB(hHttpSession
, dwContext
, dwInternetStatus
,
230 lpvStatusInfo
, dwStatusInfoLength
);
232 TRACE("<-- Callback %ld (%s)\n",dwInternetStatus
, get_callback_name(dwInternetStatus
));
237 VOID
SendAsyncCallback(LPWININETAPPINFOA hIC
, HINTERNET hHttpSession
,
238 DWORD dwContext
, DWORD dwInternetStatus
, LPVOID
239 lpvStatusInfo
, DWORD dwStatusInfoLength
)
241 TRACE("Send Callback %ld (%s)\n",dwInternetStatus
, get_callback_name(dwInternetStatus
));
243 if (! (hIC
->lpfnStatusCB
))
245 if (hIC
->hdr
.dwFlags
& INTERNET_FLAG_ASYNC
)
247 WORKREQUEST workRequest
;
248 struct WORKREQ_SENDCALLBACK
*req
;
250 workRequest
.asyncall
= SENDCALLBACK
;
251 workRequest
.handle
= hIC
;
252 req
= &workRequest
.u
.SendCallback
;
253 req
->hHttpSession
= hHttpSession
;
254 req
->dwContext
= dwContext
;
255 req
->dwInternetStatus
= dwInternetStatus
;
256 req
->lpvStatusInfo
= lpvStatusInfo
;
257 req
->dwStatusInfoLength
= dwStatusInfoLength
;
259 INTERNET_AsyncCall(&workRequest
);
262 SendAsyncCallbackInt(hIC
, hHttpSession
, dwContext
, dwInternetStatus
,
263 lpvStatusInfo
, dwStatusInfoLength
);