ReactOS  0.4.14-dev-77-gd9e7c48
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 = strlenW(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 */
64  if (strlenW(asctime) >= TIME_STRING_LEN) FIXME("\n");
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 = atoiW(tmpChar+12) - 1900;
80  t.tm_mday = atoiW(tmpChar+5);
81  t.tm_hour = atoiW(tmpChar+17);
82  t.tm_min = atoiW(tmpChar+20);
83  t.tm_sec = atoiW(tmpChar+23);
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 }
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
GLdouble GLdouble t
Definition: gl.h:2047
_Check_return_ _CRTIMP char *__cdecl asctime(_In_ const struct tm *_Tm)
#define lstrcpynW
Definition: compat.h:397
#define FIXME(fmt,...)
Definition: debug.h:110
#define TIME_STRING_LEN
Definition: utility.c:47
__wchar_t WCHAR
Definition: xmlstorage.h:180
Definition: time.h:76
_CRTIMP time_t __cdecl mktime(struct tm *_Tm)
Definition: time.h:426
#define memset(x, y, z)
Definition: compat.h:39
WINE_UNICODE_INLINE int atoiW(const WCHAR *str)
Definition: unicode.h:315

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 }
struct _test_info info[]
Definition: SetCursorPos.c:19
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:271
DWORD_PTR dwResult
Definition: wininet.h:155
#define INTERNET_STATUS_REQUEST_COMPLETE
Definition: wininet.h:898
static __inline const char * wine_dbgstr_longlong(ULONGLONG ll)
Definition: compat.h:41
Definition: ps.c:97

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 < (sizeof(internet_status) / sizeof(internet_status[0])); i++) {
223  if (internet_status[i].val == dwInternetStatus) return internet_status[i].name;
224  }
225  return "Unknown";
226 }
#define INTERNET_STATUS_HANDLE_CLOSING
Definition: wininet.h:896
#define INTERNET_STATUS_REQUEST_SENT
Definition: wininet.h:888
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
#define INTERNET_STATUS_PREFETCH
Definition: wininet.h:892
#define INTERNET_STATUS_CONNECTION_CLOSED
Definition: wininet.h:894
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
#define INTERNET_STATUS_CLOSING_CONNECTION
Definition: wininet.h:893
#define INTERNET_STATUS_RECEIVING_RESPONSE
Definition: wininet.h:889
GLuint GLfloat * val
Definition: glext.h:7180
#define INTERNET_STATUS_NAME_RESOLVED
Definition: wininet.h:884
#define INTERNET_STATUS_CTL_RESPONSE_RECEIVED
Definition: wininet.h:891
#define INTERNET_STATUS_P3P_POLICYREF
Definition: wininet.h:907
#define INTERNET_STATUS_COOKIE_RECEIVED
Definition: wininet.h:904
#define INTERNET_STATUS_P3P_HEADER
Definition: wininet.h:906
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INTERNET_STATUS_REDIRECT
Definition: wininet.h:899
#define INTERNET_STATUS_SENDING_REQUEST
Definition: wininet.h:887
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define INTERNET_STATUS_COOKIE_HISTORY
Definition: wininet.h:908
const char * name
Definition: internet.h:468
#define INTERNET_STATUS_REQUEST_COMPLETE
Definition: wininet.h:898
#define FE(x)
#define INTERNET_STATUS_STATE_CHANGE
Definition: wininet.h:902
#define INTERNET_STATUS_CONNECTED_TO_SERVER
Definition: wininet.h:886
#define INTERNET_STATUS_COOKIE_SENT
Definition: wininet.h:903
#define INTERNET_STATUS_HANDLE_CREATED
Definition: wininet.h:895
#define INTERNET_STATUS_USER_INPUT_REQUIRED
Definition: wininet.h:901
#define INTERNET_STATUS_INTERMEDIATE_RESPONSE
Definition: wininet.h:900
#define INTERNET_STATUS_RESPONSE_RECEIVED
Definition: wininet.h:890
#define INTERNET_STATUS_PRIVACY_IMPACTED
Definition: wininet.h:905

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 {
135  ADDRINFOW *res, hints;
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 
147  ret = GetAddrInfoW(name, NULL, &hints, &res);
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;
152  ret = GetAddrInfoW(name, NULL, &hints, &res);
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 }
namespace GUID const ADDRINFOEXW * hints
Definition: sock.c:80
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:111
#define INET6_ADDRSTRLEN
Definition: request.c:1491
INT WSAAPI GetAddrInfoW(IN PCWSTR pszNodeName, IN PCWSTR pszServiceName, IN const ADDRINFOW *ptHints, OUT PADDRINFOW *pptResult)
Definition: addrinfo.c:509
#define debugstr_w
Definition: kernel32.h:32
smooth NULL
Definition: ftsmooth.c:416
#define AF_INET6
Definition: winsock.h:369
#define TRACE(s)
Definition: solgame.cpp:4
int ret
GLenum const GLvoid * addr
Definition: glext.h:9621
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static SCRIPT_CACHE SCRIPT_ANALYSIS * psa
Definition: usp10.c:64
WINSOCK_API_LINKAGE VOID WSAAPI FreeAddrInfoW(_In_opt_ PADDRINFOW pAddrInfo)
Definition: name.c:36
GLuint res
Definition: glext.h:9613
#define AF_INET
Definition: tcpip.h:117
const char *WSAAPI inet_ntop(int af, const void *src, char *dst, size_t cnt)
Definition: unix_func.c:8
#define htons(x)
Definition: module.h:213
USHORT port
Definition: uri.c:227
#define memset(x, y, z)
Definition: compat.h:39

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 }
char hdr[14]
Definition: iptest.cpp:33
Definition: http.c:6587
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
static void * heap_alloc(size_t len)
Definition: appwiz.h:65
struct _test_info info[]
Definition: SetCursorPos.c:19
#define INET_CALLBACKW
Definition: internet.h:245
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define INTERNET_STATUS_NAME_RESOLVED
Definition: wininet.h:884
#define TRACE(s)
Definition: solgame.cpp:4
static const char * debugstr_status_info(DWORD status, void *info)
Definition: utility.c:228
static char * heap_strdupWtoA(const WCHAR *str)
#define INTERNET_STATUS_REDIRECT
Definition: wininet.h:899
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define INTERNET_STATUS_CONNECTED_TO_SERVER
Definition: wininet.h:886
static const char * get_callback_name(DWORD dwInternetStatus)
Definition: utility.c:190
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
Definition: ps.c:97

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wininet  )