1 | /*
|
---|
2 | * Wininet - Utility functions
|
---|
3 | *
|
---|
4 | * Copyright 1999 Corel Corporation
|
---|
5 | *
|
---|
6 | * Ulrich Czekalla
|
---|
7 | *
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include "windows.h"
|
---|
11 | #include "wininet.h"
|
---|
12 | #include "debugtools.h"
|
---|
13 | #include "winerror.h"
|
---|
14 | #include "winsock.h"
|
---|
15 |
|
---|
16 | #include <time.h>
|
---|
17 | #include <string.h>
|
---|
18 | #include <stdlib.h>
|
---|
19 |
|
---|
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 | tmpChar[3]='\0';
|
---|
49 | tmpChar[7]='\0';
|
---|
50 | tmpChar[11]='\0';
|
---|
51 | tmpChar[16]='\0';
|
---|
52 | tmpChar[19]='\0';
|
---|
53 | tmpChar[22]='\0';
|
---|
54 | tmpChar[25]='\0';
|
---|
55 |
|
---|
56 | SystemTime.tm_year = atoi(tmpChar+12) - 1900;
|
---|
57 | SystemTime.tm_mday = atoi(tmpChar+5);
|
---|
58 | SystemTime.tm_hour = atoi(tmpChar+17);
|
---|
59 | SystemTime.tm_min = atoi(tmpChar+20);
|
---|
60 | SystemTime.tm_sec = atoi(tmpChar+23);
|
---|
61 |
|
---|
62 | //and month
|
---|
63 | tmpChar2 = tmpChar + 8;
|
---|
64 | switch(tmpChar2[2])
|
---|
65 | {
|
---|
66 | case 'n':
|
---|
67 | if(tmpChar2[1]=='a')
|
---|
68 | SystemTime.tm_mon = 0;
|
---|
69 | else
|
---|
70 | SystemTime.tm_mon = 5;
|
---|
71 | break;
|
---|
72 | case 'b':
|
---|
73 | SystemTime.tm_mon = 1;
|
---|
74 | break;
|
---|
75 | case 'r':
|
---|
76 | if(tmpChar2[1]=='a')
|
---|
77 | SystemTime.tm_mon = 2;
|
---|
78 | else
|
---|
79 | SystemTime.tm_mon = 3;
|
---|
80 | break;
|
---|
81 | case 'y':
|
---|
82 | SystemTime.tm_mon = 4;
|
---|
83 | break;
|
---|
84 | case 'l':
|
---|
85 | SystemTime.tm_mon = 6;
|
---|
86 | break;
|
---|
87 | case 'g':
|
---|
88 | SystemTime.tm_mon = 7;
|
---|
89 | break;
|
---|
90 | case 'p':
|
---|
91 | SystemTime.tm_mon = 8;
|
---|
92 | break;
|
---|
93 | case 't':
|
---|
94 | SystemTime.tm_mon = 9;
|
---|
95 | break;
|
---|
96 | case 'v':
|
---|
97 | SystemTime.tm_mon = 10;
|
---|
98 | break;
|
---|
99 | case 'c':
|
---|
100 | SystemTime.tm_mon = 11;
|
---|
101 | break;
|
---|
102 | default:
|
---|
103 | FIXME("\n");
|
---|
104 | }//switch
|
---|
105 |
|
---|
106 | return mktime(&SystemTime);
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 | BOOL GetAddress(LPCSTR lpszServerName, INTERNET_PORT nServerPort,
|
---|
111 | struct hostent **phe, struct sockaddr_in *psa)
|
---|
112 | {
|
---|
113 | *phe = gethostbyname(lpszServerName);
|
---|
114 | if (NULL == *phe)
|
---|
115 | {
|
---|
116 | TRACE("Failed to get hostname %s\n", lpszServerName);
|
---|
117 | return FALSE;
|
---|
118 | }
|
---|
119 |
|
---|
120 | memcpy((char *)&psa->sin_addr, (*phe)->h_addr, (*phe)->h_length);
|
---|
121 | psa->sin_family = (*phe)->h_addrtype;
|
---|
122 | psa->sin_port = htons((u_short)nServerPort);
|
---|
123 |
|
---|
124 | return TRUE;
|
---|
125 | }
|
---|