2000-04-11 22:07:00 +02:00
|
|
|
/*
|
|
|
|
* Wininet - Utility functions
|
|
|
|
*
|
|
|
|
* Copyright 1999 Corel Corporation
|
|
|
|
*
|
|
|
|
* Ulrich Czekalla
|
|
|
|
*
|
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"
|
|
|
|
|
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"
|
|
|
|
|
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
|
|
|
|
|
|
|
|
time_t ConvertTimeString(LPCSTR asctime)
|
|
|
|
{
|
|
|
|
char tmpChar[TIME_STRING_LEN];
|
|
|
|
char *tmpChar2;
|
2001-09-19 22:30:52 +02:00
|
|
|
struct tm t;
|
2000-04-11 22:07:00 +02:00
|
|
|
int timelen = strlen(asctime);
|
|
|
|
|
|
|
|
if(!asctime || !timelen)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
strncpy(tmpChar, asctime, TIME_STRING_LEN);
|
|
|
|
|
|
|
|
/* Assert that the string is the expected length */
|
|
|
|
if (tmpChar[TIME_STRING_LEN] != '\0')
|
|
|
|
{
|
|
|
|
tmpChar[TIME_STRING_LEN] = '\0';
|
|
|
|
FIXME("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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';
|
|
|
|
|
2001-09-19 22:30:52 +02:00
|
|
|
t.tm_year = atoi(tmpChar+12) - 1900;
|
|
|
|
t.tm_mday = atoi(tmpChar+5);
|
|
|
|
t.tm_hour = atoi(tmpChar+17);
|
|
|
|
t.tm_min = atoi(tmpChar+20);
|
|
|
|
t.tm_sec = atoi(tmpChar+23);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BOOL GetAddress(LPCSTR lpszServerName, INTERNET_PORT nServerPort,
|
|
|
|
struct hostent **phe, struct sockaddr_in *psa)
|
|
|
|
{
|
2001-10-04 20:12:41 +02:00
|
|
|
char *found;
|
|
|
|
|
2000-06-11 22:04:44 +02:00
|
|
|
TRACE("%s\n", lpszServerName);
|
|
|
|
|
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....
|
|
|
|
*/
|
|
|
|
found = strchr(lpszServerName, ':');
|
|
|
|
if (found)
|
|
|
|
{
|
|
|
|
int len = found - lpszServerName;
|
|
|
|
char *new = HeapAlloc(GetProcessHeap(), 0, len + 1);
|
|
|
|
memcpy( new, lpszServerName, len );
|
|
|
|
new[len] = '\0';
|
|
|
|
TRACE("Found a ':' inside the server name, reparsed name: %s\n", new);
|
|
|
|
*phe = gethostbyname(new);
|
|
|
|
HeapFree( GetProcessHeap(), 0, new );
|
|
|
|
}
|
|
|
|
else *phe = gethostbyname(lpszServerName);
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
if (NULL == *phe)
|
|
|
|
{
|
2000-06-11 22:04:44 +02:00
|
|
|
TRACE("Failed to get hostname: (%s)\n", 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;
|
|
|
|
}
|