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 VOID SendAsyncCallbackInt(LPWININETAPPINFOA hIC, HINTERNET hHttpSession,
173 DWORD dwContext, DWORD dwInternetStatus, LPVOID
174 lpvStatusInfo, DWORD dwStatusInfoLength)
176 if (! (hIC->lpfnStatusCB))
179 /* the IE5 version of wininet does not
180 send callbacks if dwContext is zero */
184 TRACE("--> Callback %ld\n",dwInternetStatus);
186 hIC->lpfnStatusCB(hHttpSession, dwContext, dwInternetStatus,
187 lpvStatusInfo, dwStatusInfoLength);
189 TRACE("<-- Callback %ld\n",dwInternetStatus);
194 VOID SendAsyncCallback(LPWININETAPPINFOA hIC, HINTERNET hHttpSession,
195 DWORD dwContext, DWORD dwInternetStatus, LPVOID
196 lpvStatusInfo, DWORD dwStatusInfoLength)
198 TRACE("Send Callback %ld\n",dwInternetStatus);
200 if (! (hIC->lpfnStatusCB))
202 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
204 WORKREQUEST workRequest;
206 workRequest.asyncall = SENDCALLBACK;
208 workRequest.param1 = (DWORD)hIC;
209 workRequest.param2 = (DWORD)hHttpSession;
210 workRequest.param3 = dwContext;
211 workRequest.param4 = dwInternetStatus;
212 workRequest.param5 = (DWORD)lpvStatusInfo;
213 workRequest.param6 = dwStatusInfoLength;
215 INTERNET_AsyncCall(&workRequest);
218 SendAsyncCallbackInt(hIC, hHttpSession, dwContext, dwInternetStatus,
219 lpvStatusInfo, dwStatusInfoLength);