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
36 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wininet);
41 #define TIME_STRING_LEN 30
43 time_t ConvertTimeString(LPCSTR asctime)
45 char tmpChar[TIME_STRING_LEN];
48 int timelen = strlen(asctime);
50 if(!asctime || !timelen)
53 strncpy(tmpChar, asctime, TIME_STRING_LEN);
55 /* Assert that the string is the expected length */
56 if (tmpChar[TIME_STRING_LEN] != '\0')
58 tmpChar[TIME_STRING_LEN] = '\0';
62 /* Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
63 * We assume the time is in this format
64 * and divide it into easy to swallow chunks
74 t.tm_year = atoi(tmpChar+12) - 1900;
75 t.tm_mday = atoi(tmpChar+5);
76 t.tm_hour = atoi(tmpChar+17);
77 t.tm_min = atoi(tmpChar+20);
78 t.tm_sec = atoi(tmpChar+23);
81 tmpChar2 = tmpChar + 8;
128 BOOL GetAddress(LPCSTR lpszServerName, INTERNET_PORT nServerPort,
129 struct hostent **phe, struct sockaddr_in *psa)
133 TRACE("%s\n", lpszServerName);
135 /* Validate server name first
136 * Check if there is sth. like
137 * pinger.macromedia.com:80
138 * if yes, eliminate the :80....
140 found = strchr(lpszServerName, ':');
143 int len = found - lpszServerName;
144 char *new = HeapAlloc(GetProcessHeap(), 0, len + 1);
145 memcpy( new, lpszServerName, len );
147 TRACE("Found a ':' inside the server name, reparsed name: %s\n", new);
148 *phe = gethostbyname(new);
149 HeapFree( GetProcessHeap(), 0, new );
151 else *phe = gethostbyname(lpszServerName);
155 TRACE("Failed to get hostname: (%s)\n", lpszServerName);
159 memset(psa,0,sizeof(struct sockaddr_in));
160 memcpy((char *)&psa->sin_addr, (*phe)->h_addr, (*phe)->h_length);
161 psa->sin_family = (*phe)->h_addrtype;
162 psa->sin_port = htons((u_short)nServerPort);
168 * Helper function for sending async Callbacks
171 VOID SendAsyncCallbackInt(LPWININETAPPINFOA hIC, HINTERNET hHttpSession,
172 DWORD dwContext, DWORD dwInternetStatus, LPVOID
173 lpvStatusInfo, DWORD dwStatusInfoLength)
175 if (! (hIC->lpfnStatusCB))
178 TRACE("--> Callback %ld\n",dwInternetStatus);
180 hIC->lpfnStatusCB(hHttpSession, dwContext, dwInternetStatus,
181 lpvStatusInfo, dwStatusInfoLength);
183 TRACE("<-- Callback %ld\n",dwInternetStatus);
188 VOID SendAsyncCallback(LPWININETAPPINFOA hIC, HINTERNET hHttpSession,
189 DWORD dwContext, DWORD dwInternetStatus, LPVOID
190 lpvStatusInfo, DWORD dwStatusInfoLength)
192 TRACE("Send Callback %ld\n",dwInternetStatus);
194 if (! (hIC->lpfnStatusCB))
196 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
198 WORKREQUEST workRequest;
200 workRequest.asyncall = SENDCALLBACK;
202 workRequest.param1 = (DWORD)hIC;
203 workRequest.param2 = (DWORD)hHttpSession;
204 workRequest.param3 = dwContext;
205 workRequest.param4 = dwInternetStatus;
206 workRequest.param5 = (DWORD)lpvStatusInfo;
207 workRequest.param6 = dwStatusInfoLength;
209 INTERNET_AsyncCall(&workRequest);
212 SendAsyncCallbackInt(hIC, hHttpSession, dwContext, dwInternetStatus,
213 lpvStatusInfo, dwStatusInfoLength);