- Added remaining DirectX 3D3 6&7 3D interfaces.
[wine.git] / dlls / wininet / utility.c
bloba09b66fc3e88687b867a8efdf193513889c4a7ca
1 /*
2 * Wininet - Utility functions
4 * Copyright 1999 Corel Corporation
6 * Ulrich Czekalla
8 */
10 #include <stdlib.h>
11 #include <string.h>
12 #include <time.h>
14 #include "windows.h"
15 #include "wininet.h"
16 #include "winerror.h"
17 #include "winsock.h"
19 #include "debugtools.h"
20 #include "internet.h"
22 DEFAULT_DEBUG_CHANNEL(wininet);
24 #define TIME_STRING_LEN 30
26 time_t ConvertTimeString(LPCSTR asctime)
28 char tmpChar[TIME_STRING_LEN];
29 char *tmpChar2;
30 struct tm SystemTime;
31 int timelen = strlen(asctime);
33 if(!asctime || !timelen)
34 return 0;
36 strncpy(tmpChar, asctime, TIME_STRING_LEN);
38 /* Assert that the string is the expected length */
39 if (tmpChar[TIME_STRING_LEN] != '\0')
41 tmpChar[TIME_STRING_LEN] = '\0';
42 FIXME("\n");
45 /* Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
46 * We assume the time is in this format
47 * and divide it into easy to swallow chunks
49 tmpChar[3]='\0';
50 tmpChar[7]='\0';
51 tmpChar[11]='\0';
52 tmpChar[16]='\0';
53 tmpChar[19]='\0';
54 tmpChar[22]='\0';
55 tmpChar[25]='\0';
57 SystemTime.tm_year = atoi(tmpChar+12) - 1900;
58 SystemTime.tm_mday = atoi(tmpChar+5);
59 SystemTime.tm_hour = atoi(tmpChar+17);
60 SystemTime.tm_min = atoi(tmpChar+20);
61 SystemTime.tm_sec = atoi(tmpChar+23);
63 /* and month */
64 tmpChar2 = tmpChar + 8;
65 switch(tmpChar2[2])
67 case 'n':
68 if(tmpChar2[1]=='a')
69 SystemTime.tm_mon = 0;
70 else
71 SystemTime.tm_mon = 5;
72 break;
73 case 'b':
74 SystemTime.tm_mon = 1;
75 break;
76 case 'r':
77 if(tmpChar2[1]=='a')
78 SystemTime.tm_mon = 2;
79 else
80 SystemTime.tm_mon = 3;
81 break;
82 case 'y':
83 SystemTime.tm_mon = 4;
84 break;
85 case 'l':
86 SystemTime.tm_mon = 6;
87 break;
88 case 'g':
89 SystemTime.tm_mon = 7;
90 break;
91 case 'p':
92 SystemTime.tm_mon = 8;
93 break;
94 case 't':
95 SystemTime.tm_mon = 9;
96 break;
97 case 'v':
98 SystemTime.tm_mon = 10;
99 break;
100 case 'c':
101 SystemTime.tm_mon = 11;
102 break;
103 default:
104 FIXME("\n");
107 return mktime(&SystemTime);
111 BOOL GetAddress(LPCSTR lpszServerName, INTERNET_PORT nServerPort,
112 struct hostent **phe, struct sockaddr_in *psa)
114 *phe = gethostbyname(lpszServerName);
115 if (NULL == *phe)
117 TRACE("Failed to get hostname %s\n", lpszServerName);
118 return FALSE;
121 memset(psa,0,sizeof(struct sockaddr_in));
122 memcpy((char *)&psa->sin_addr, (*phe)->h_addr, (*phe)->h_length);
123 psa->sin_family = (*phe)->h_addrtype;
124 psa->sin_port = htons((u_short)nServerPort);
126 return TRUE;