Fixed issues found by winapi_check.
[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 <stdlib.h>
11 #include <string.h>
12 #include <time.h>
13
14 #include "windows.h"
15 #include "wininet.h"
16 #include "winerror.h"
17 #include "winsock.h"
18
19 #include "debugtools.h"
20 #include "internet.h"
21
22 DEFAULT_DEBUG_CHANNEL(wininet);
23
24 #define TIME_STRING_LEN  30
25
26 time_t ConvertTimeString(LPCSTR asctime)
27 {
28     char tmpChar[TIME_STRING_LEN];
29     char *tmpChar2;
30     struct tm SystemTime;
31     int timelen = strlen(asctime);
32
33     if(!asctime || !timelen)
34         return 0;
35
36     strncpy(tmpChar, asctime, TIME_STRING_LEN);
37
38     /* Assert that the string is the expected length */
39     if (tmpChar[TIME_STRING_LEN] != '\0')
40     { 
41         tmpChar[TIME_STRING_LEN] = '\0';
42         FIXME("\n");
43     }
44     
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
48      */
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';
56
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);
62         
63     /* and month */
64     tmpChar2 = tmpChar + 8;
65     switch(tmpChar2[2])
66     {
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");
105     }
106
107     return mktime(&SystemTime);
108 }
109
110
111 BOOL GetAddress(LPCSTR lpszServerName, INTERNET_PORT nServerPort,
112         struct hostent **phe, struct sockaddr_in *psa)
113 {
114     TRACE("%s\n", lpszServerName);
115
116     *phe = gethostbyname(lpszServerName);
117     if (NULL == *phe)
118     {
119         TRACE("Failed to get hostname: (%s)\n", lpszServerName);
120         return FALSE;
121     }
122
123     memset(psa,0,sizeof(struct sockaddr_in));
124     memcpy((char *)&psa->sin_addr, (*phe)->h_addr, (*phe)->h_length);
125     psa->sin_family = (*phe)->h_addrtype;
126     psa->sin_port = htons((u_short)nServerPort);
127
128     return TRUE;
129 }