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