ReactOS 0.4.15-dev-8135-g1bc6c90
utility.c File Reference
#include "ws2tcpip.h"
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "windef.h"
#include "winbase.h"
#include "wininet.h"
#include "winnls.h"
#include "wine/debug.h"
#include "internet.h"
Include dependency graph for utility.c:

Go to the source code of this file.

Macros

#define TIME_STRING_LEN   30
 
#define FE(x)   { x, #x }
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wininet)
 
time_t ConvertTimeString (LPCWSTR asctime)
 
BOOL GetAddress (const WCHAR *name, INTERNET_PORT port, struct sockaddr *psa, int *sa_len, char *addr_str)
 
static const charget_callback_name (DWORD dwInternetStatus)
 
static const chardebugstr_status_info (DWORD status, void *info)
 
void INTERNET_SendCallback (object_header_t *hdr, DWORD_PTR context, DWORD status, void *info, DWORD info_len)
 

Macro Definition Documentation

◆ FE

#define FE (   x)    { x, #x }

◆ TIME_STRING_LEN

#define TIME_STRING_LEN   30

Definition at line 47 of file utility.c.

Function Documentation

◆ ConvertTimeString()

time_t ConvertTimeString ( LPCWSTR  asctime)

Definition at line 49 of file utility.c.

50{
51 WCHAR tmpChar[TIME_STRING_LEN];
52 WCHAR *tmpChar2;
53 struct tm t;
54 int timelen = lstrlenW(asctime);
55
56 if(!timelen)
57 return 0;
58
59 /* FIXME: the atoiWs below rely on that tmpChar is \0 padded */
60 memset( tmpChar, 0, sizeof(tmpChar) );
62
63 /* Assert that the string is the expected length */
65
66 /* Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
67 * We assume the time is in this format
68 * and divide it into easy to swallow chunks
69 */
70 tmpChar[3]='\0';
71 tmpChar[7]='\0';
72 tmpChar[11]='\0';
73 tmpChar[16]='\0';
74 tmpChar[19]='\0';
75 tmpChar[22]='\0';
76 tmpChar[25]='\0';
77
78 memset( &t, 0, sizeof(t) );
79 t.tm_year = wcstol(tmpChar+12, NULL, 10) - 1900;
80 t.tm_mday = wcstol(tmpChar+5, NULL, 10);
81 t.tm_hour = wcstol(tmpChar+17, NULL, 10);
82 t.tm_min = wcstol(tmpChar+20, NULL, 10);
83 t.tm_sec = wcstol(tmpChar+23, NULL, 10);
84
85 /* and month */
86 tmpChar2 = tmpChar + 8;
87 switch(tmpChar2[2])
88 {
89 case 'n':
90 if(tmpChar2[1]=='a')
91 t.tm_mon = 0;
92 else
93 t.tm_mon = 5;
94 break;
95 case 'b':
96 t.tm_mon = 1;
97 break;
98 case 'r':
99 if(tmpChar2[1]=='a')
100 t.tm_mon = 2;
101 else
102 t.tm_mon = 3;
103 break;
104 case 'y':
105 t.tm_mon = 4;
106 break;
107 case 'l':
108 t.tm_mon = 6;
109 break;
110 case 'g':
111 t.tm_mon = 7;
112 break;
113 case 'p':
114 t.tm_mon = 8;
115 break;
116 case 't':
117 t.tm_mon = 9;
118 break;
119 case 'v':
120 t.tm_mon = 10;
121 break;
122 case 'c':
123 t.tm_mon = 11;
124 break;
125 default:
126 FIXME("\n");
127 }
128
129 return mktime(&t);
130}
#define FIXME(fmt,...)
Definition: debug.h:114
#define NULL
Definition: types.h:112
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
#define TIME_STRING_LEN
Definition: utility.c:47
GLdouble GLdouble t
Definition: gl.h:2047
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
_Check_return_ _CRTIMP char *__cdecl asctime(_In_ const struct tm *_Tm)
_CRTIMP time_t __cdecl mktime(struct tm *_Tm)
Definition: time.h:418
#define memset(x, y, z)
Definition: compat.h:39
Definition: time.h:68
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by HTTP_HttpQueryInfoW().

◆ debugstr_status_info()

static const char * debugstr_status_info ( DWORD  status,
void info 
)
static

Definition at line 228 of file utility.c.

229{
230 switch(status) {
233 return wine_dbg_sprintf("{%s, %d}", wine_dbgstr_longlong(iar->dwResult), iar->dwError);
234 }
235 default:
236 return wine_dbg_sprintf("%p", info);
237 }
238}
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:296
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:49
DWORD_PTR dwResult
Definition: wininet.h:155
Definition: ps.c:97
#define INTERNET_STATUS_REQUEST_COMPLETE
Definition: wininet.h:898

Referenced by INTERNET_SendCallback().

◆ get_callback_name()

static const char * get_callback_name ( DWORD  dwInternetStatus)
static

Definition at line 190 of file utility.c.

190 {
191 static const wininet_flag_info internet_status[] = {
192#define FE(x) { x, #x }
218#undef FE
219 };
220 DWORD i;
221
222 for (i = 0; i < ARRAY_SIZE(internet_status); i++) {
223 if (internet_status[i].val == dwInternetStatus) return internet_status[i].name;
224 }
225 return "Unknown";
226}
#define ARRAY_SIZE(A)
Definition: main.h:33
#define FE(x)
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLfloat * val
Definition: glext.h:7180
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
const char * name
Definition: internet.h:468
#define INTERNET_STATUS_RECEIVING_RESPONSE
Definition: wininet.h:889
#define INTERNET_STATUS_CONNECTION_CLOSED
Definition: wininet.h:894
#define INTERNET_STATUS_STATE_CHANGE
Definition: wininet.h:902
#define INTERNET_STATUS_REQUEST_SENT
Definition: wininet.h:888
#define INTERNET_STATUS_COOKIE_RECEIVED
Definition: wininet.h:904
#define INTERNET_STATUS_USER_INPUT_REQUIRED
Definition: wininet.h:901
#define INTERNET_STATUS_SENDING_REQUEST
Definition: wininet.h:887
#define INTERNET_STATUS_PREFETCH
Definition: wininet.h:892
#define INTERNET_STATUS_HANDLE_CLOSING
Definition: wininet.h:896
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define INTERNET_STATUS_INTERMEDIATE_RESPONSE
Definition: wininet.h:900
#define INTERNET_STATUS_RESPONSE_RECEIVED
Definition: wininet.h:890
#define INTERNET_STATUS_REDIRECT
Definition: wininet.h:899
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
#define INTERNET_STATUS_HANDLE_CREATED
Definition: wininet.h:895
#define INTERNET_STATUS_COOKIE_HISTORY
Definition: wininet.h:908
#define INTERNET_STATUS_COOKIE_SENT
Definition: wininet.h:903
#define INTERNET_STATUS_CONNECTED_TO_SERVER
Definition: wininet.h:886
#define INTERNET_STATUS_NAME_RESOLVED
Definition: wininet.h:884
#define INTERNET_STATUS_CTL_RESPONSE_RECEIVED
Definition: wininet.h:891
#define INTERNET_STATUS_P3P_HEADER
Definition: wininet.h:906
#define INTERNET_STATUS_CLOSING_CONNECTION
Definition: wininet.h:893
#define INTERNET_STATUS_PRIVACY_IMPACTED
Definition: wininet.h:905
#define INTERNET_STATUS_P3P_POLICYREF
Definition: wininet.h:907

Referenced by INTERNET_SendCallback().

◆ GetAddress()

BOOL GetAddress ( const WCHAR name,
INTERNET_PORT  port,
struct sockaddr psa,
int sa_len,
char addr_str 
)

Definition at line 133 of file utility.c.

134{
136 void *addr = NULL;
137 int ret;
138
139 TRACE("%s\n", debugstr_w(name));
140
141 memset( &hints, 0, sizeof(hints) );
142 /* Prefer IPv4 to IPv6 addresses, since some servers do not listen on
143 * their IPv6 addresses even though they have IPv6 addresses in the DNS.
144 */
145 hints.ai_family = AF_INET;
146
148 if (ret != 0)
149 {
150 TRACE("failed to get IPv4 address of %s, retrying with IPv6\n", debugstr_w(name));
151 hints.ai_family = AF_INET6;
153 }
154 if (ret != 0)
155 {
156 TRACE("failed to get address of %s\n", debugstr_w(name));
157 return FALSE;
158 }
159 if (*sa_len < res->ai_addrlen)
160 {
161 WARN("address too small\n");
163 return FALSE;
164 }
165 *sa_len = res->ai_addrlen;
166 memcpy( psa, res->ai_addr, res->ai_addrlen );
167 /* Copy port */
168 switch (res->ai_family)
169 {
170 case AF_INET:
171 addr = &((struct sockaddr_in *)psa)->sin_addr;
172 ((struct sockaddr_in *)psa)->sin_port = htons(port);
173 break;
174 case AF_INET6:
175 addr = &((struct sockaddr_in6 *)psa)->sin6_addr;
176 ((struct sockaddr_in6 *)psa)->sin6_port = htons(port);
177 break;
178 }
179
180 if(addr_str)
181 inet_ntop(res->ai_family, addr, addr_str, INET6_ADDRSTRLEN);
183 return TRUE;
184}
#define FreeAddrInfoW(a)
Definition: addrinfo.c:21
INT WSAAPI GetAddrInfoW(IN PCWSTR pszNodeName, IN PCWSTR pszServiceName, IN const ADDRINFOW *ptHints, OUT PADDRINFOW *pptResult)
Definition: addrinfo.c:509
#define WARN(fmt,...)
Definition: debug.h:115
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
USHORT port
Definition: uri.c:228
#define AF_INET
Definition: tcpip.h:117
GLuint res
Definition: glext.h:9613
GLenum const GLvoid * addr
Definition: glext.h:9621
#define debugstr_w
Definition: kernel32.h:32
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define htons(x)
Definition: module.h:215
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
namespace GUID const ADDRINFOEXW * hints
Definition: sock.c:80
#define TRACE(s)
Definition: solgame.cpp:4
Definition: name.c:39
const char *WSAAPI inet_ntop(int af, const void *src, char *dst, size_t cnt)
Definition: unix_func.c:8
int ret
#define AF_INET6
Definition: winsock.h:369
#define INET6_ADDRSTRLEN
Definition: ws2ipdef.h:132

Referenced by FTP_Connect(), HTTP_ResolveName(), and InternetCheckConnectionW().

◆ INTERNET_SendCallback()

void INTERNET_SendCallback ( object_header_t hdr,
DWORD_PTR  context,
DWORD  status,
void info,
DWORD  info_len 
)

Definition at line 240 of file utility.c.

241{
242 void *new_info = info;
243
244 if( !hdr->lpfnStatusCB )
245 return;
246
247 /* the IE5 version of wininet does not
248 send callbacks if dwContext is zero */
249 if(!context)
250 return;
251
252 switch(status) {
256 new_info = heap_alloc(info_len);
257 if(new_info)
258 memcpy(new_info, info, info_len);
259 break;
262 if(hdr->dwInternalFlags & INET_CALLBACKW) {
263 new_info = heap_strdupW(info);
264 break;
265 }else {
266 new_info = heap_strdupWtoA(info);
267 info_len = strlen(new_info)+1;
268 break;
269 }
270 }
271
272 TRACE(" callback(%p) (%p (%p), %08lx, %d (%s), %s, %d)\n",
273 hdr->lpfnStatusCB, hdr->hInternet, hdr, context, status, get_callback_name(status),
274 debugstr_status_info(status, new_info), info_len);
275
276 hdr->lpfnStatusCB(hdr->hInternet, context, status, new_info, info_len);
277
278 TRACE(" end callback().\n");
279
280 if(new_info != info)
281 heap_free(new_info);
282}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static char * heap_strdupWtoA(const WCHAR *str)
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
static const char * debugstr_status_info(DWORD status, void *info)
Definition: utility.c:228
static const char * get_callback_name(DWORD dwInternetStatus)
Definition: utility.c:190
#define INET_CALLBACKW
Definition: internet.h:244
char hdr[14]
Definition: iptest.cpp:33
Definition: http.c:7252

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wininet  )