[4842] | 1 | /* $Id: utility.c,v 1.3 2000-12-27 23:06:17 sandervl Exp $
|
---|
[3898] | 2 | *
|
---|
[2624] | 3 | * Wininet - Utility functions
|
---|
| 4 | *
|
---|
| 5 | * Copyright 1999 Corel Corporation
|
---|
| 6 | *
|
---|
| 7 | * Ulrich Czekalla
|
---|
| 8 | *
|
---|
| 9 | */
|
---|
| 10 |
|
---|
| 11 | #include "windows.h"
|
---|
| 12 | #include "wininet.h"
|
---|
| 13 | #include "debugtools.h"
|
---|
| 14 | #include "winerror.h"
|
---|
| 15 | #include "winsock.h"
|
---|
| 16 |
|
---|
| 17 | #include <time.h>
|
---|
| 18 | #include <string.h>
|
---|
| 19 | #include <stdlib.h>
|
---|
| 20 |
|
---|
| 21 | #include "internet.h"
|
---|
| 22 |
|
---|
| 23 | DEFAULT_DEBUG_CHANNEL(wininet)
|
---|
| 24 |
|
---|
| 25 | #define TIME_STRING_LEN 30
|
---|
| 26 |
|
---|
| 27 | time_t ConvertTimeString(LPCSTR asctime)
|
---|
| 28 | {
|
---|
[4842] | 29 | char tmpChar[TIME_STRING_LEN];
|
---|
| 30 | char *tmpChar2;
|
---|
| 31 | struct tm SystemTime;
|
---|
| 32 | int timelen = strlen(asctime);
|
---|
[2624] | 33 |
|
---|
[4842] | 34 | if(!asctime || !timelen)
|
---|
| 35 | return 0;
|
---|
[2624] | 36 |
|
---|
[4842] | 37 | strncpy(tmpChar, asctime, TIME_STRING_LEN);
|
---|
[2624] | 38 |
|
---|
[4842] | 39 | //Assert that the string is the expected length
|
---|
| 40 | if (tmpChar[TIME_STRING_LEN] != '\0')
|
---|
| 41 | {
|
---|
| 42 | tmpChar[TIME_STRING_LEN] = '\0';
|
---|
| 43 | FIXME("\n");
|
---|
| 44 | }
|
---|
[2624] | 45 |
|
---|
[4842] | 46 | //Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
|
---|
| 47 | //We assume the time is in this format
|
---|
| 48 | //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';
|
---|
[2624] | 56 |
|
---|
[4842] | 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);
|
---|
[3898] | 62 |
|
---|
[4842] | 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 | }//switch
|
---|
[2624] | 106 |
|
---|
[4842] | 107 | return mktime(&SystemTime);
|
---|
[2624] | 108 | }
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | BOOL GetAddress(LPCSTR lpszServerName, INTERNET_PORT nServerPort,
|
---|
[4842] | 112 | struct hostent **phe, struct sockaddr_in *psa)
|
---|
[2624] | 113 | {
|
---|
[4842] | 114 | *phe = gethostbyname(lpszServerName);
|
---|
| 115 | if (NULL == *phe)
|
---|
| 116 | {
|
---|
| 117 | TRACE("Failed to get hostname %s\n", lpszServerName);
|
---|
| 118 | return FALSE;
|
---|
| 119 | }
|
---|
[2624] | 120 |
|
---|
[4842] | 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);
|
---|
[2624] | 125 |
|
---|
[4842] | 126 | return TRUE;
|
---|
[2624] | 127 | }
|
---|