public
Created

A test win32 program to reproduce and check behavior of wininet.

  • Download Gist
Makefile
Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
### Generated by Winemaker 0.8.1
###
### Invocation command line was
### /usr/bin/winemaker -iwininet .
 
 
SRCDIR = .
SUBDIRS =
DLLS =
LIBS =
EXES = winetest.exe
 
 
 
### Common settings
 
CEXTRA = -mno-cygwin
CXXEXTRA = -mno-cygwin
RCEXTRA =
DEFINES =
INCLUDE_PATH =
DLL_PATH =
DLL_IMPORTS = wininet
LIBRARY_PATH =
LIBRARIES =
 
 
### winetest.exe sources and settings
 
winetest_exe_MODULE = winetest.exe
winetest_exe_C_SRCS =
winetest_exe_CXX_SRCS = wine_wininet_tls_test.cpp
winetest_exe_RC_SRCS =
winetest_exe_LDFLAGS = -mwindows \
-mno-cygwin
winetest_exe_ARFLAGS =
winetest_exe_DLL_PATH =
winetest_exe_DLLS = odbc32 \
ole32 \
oleaut32 \
winspool \
odbccp32
winetest_exe_LIBRARY_PATH=
winetest_exe_LIBRARIES= uuid
 
winetest_exe_OBJS = $(winetest_exe_C_SRCS:.c=.o) \
$(winetest_exe_CXX_SRCS:.cpp=.o) \
$(winetest_exe_RC_SRCS:.rc=.res)
 
 
 
### Global source lists
 
C_SRCS = $(winetest_exe_C_SRCS)
CXX_SRCS = $(winetest_exe_CXX_SRCS)
RC_SRCS = $(winetest_exe_RC_SRCS)
 
 
### Tools
 
CC = winegcc
CXX = wineg++
RC = wrc
AR = ar
 
 
### Generic targets
 
all: $(SUBDIRS) $(DLLS:%=%.so) $(LIBS) $(EXES)
 
### Build rules
 
.PHONY: all clean dummy
 
$(SUBDIRS): dummy
@cd $@ && $(MAKE)
 
# Implicit rules
 
.SUFFIXES: .cpp .rc .res
DEFINCL = $(INCLUDE_PATH) $(DEFINES) $(OPTIONS)
 
.c.o:
$(CC) -c $(CFLAGS) $(CEXTRA) $(DEFINCL) -o $@ $<
 
.cpp.o:
$(CXX) -c $(CXXFLAGS) $(CXXEXTRA) $(DEFINCL) -o $@ $<
 
.cxx.o:
$(CXX) -c $(CXXFLAGS) $(CXXEXTRA) $(DEFINCL) -o $@ $<
 
.rc.res:
$(RC) $(RCFLAGS) $(RCEXTRA) $(DEFINCL) -fo$@ $<
 
# Rules for cleaning
 
CLEAN_FILES = y.tab.c y.tab.h lex.yy.c core *.orig *.rej \
\\\#*\\\# *~ *% .\\\#*
 
clean:: $(SUBDIRS:%=%/__clean__) $(EXTRASUBDIRS:%=%/__clean__)
$(RM) $(CLEAN_FILES) $(RC_SRCS:.rc=.res) $(C_SRCS:.c=.o) $(CXX_SRCS:.cpp=.o)
$(RM) $(DLLS:%=%.so) $(LIBS) $(EXES) $(EXES:%=%.so)
 
$(SUBDIRS:%=%/__clean__): dummy
cd `dirname $@` && $(MAKE) clean
 
$(EXTRASUBDIRS:%=%/__clean__): dummy
-cd `dirname $@` && $(RM) $(CLEAN_FILES)
 
### Target specific build rules
DEFLIB = $(LIBRARY_PATH) $(LIBRARIES) $(DLL_PATH) $(DLL_IMPORTS:%=-l%)
 
$(winetest_exe_MODULE): $(winetest_exe_OBJS)
$(CXX) $(winetest_exe_LDFLAGS) -o $@ $(winetest_exe_OBJS) $(winetest_exe_LIBRARY_PATH) $(DEFLIB) $(winetest_exe_DLLS:%=-l%) $(winetest_exe_LIBRARIES:%=-l%)
wine_wininet_tls_test.cpp
C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
/* winemaker: Added -lWininet to the libraries */
 
int main() {
 
HINTERNET hInet=NULL,
hConnect=NULL,
hRequest=NULL;
DWORD dwSize=0;
DWORD dwError;
char *lpBufferA,
*lpHeadersA;
LPTSTR AcceptTypes[2] = {TEXT("*/*"), NULL};
 
hInet = InternetOpen(TEXT("SSLTEST"), INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0);
if (!hInet) {
printf("InternetOpen Error\n");
return -1;
}
hConnect = InternetConnect(
hInet,
TEXT("www.evernote.com"),
INTERNET_DEFAULT_HTTPS_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0 );
if (!hConnect) {
printf("InternetConnect Error\n");
return -1;
}
hRequest = HttpOpenRequest (
hConnect,
TEXT("GET"),
TEXT("/"),
HTTP_VERSION,
NULL,
(LPCTSTR*)AcceptTypes,
INTERNET_FLAG_SECURE|INTERNET_FLAG_RELOAD,
0);
if (!hRequest) {
printf("HttpOpenRequest Error\n");
return -1;
}
if (!HttpSendRequest(hRequest, NULL, 0, NULL, 0)) {
dwError = GetLastError();
if (dwError == 12057) {
InternetCloseHandle(hRequest);
hRequest = HttpOpenRequest (
hConnect,
TEXT("GET"),
TEXT("/"),
HTTP_VERSION,
NULL,
(LPCTSTR*)AcceptTypes,
SECURITY_FLAG_IGNORE_REVOCATION|INTERNET_FLAG_SECURE|INTERNET_FLAG_RELOAD,
0);
HttpSendRequest(hRequest, NULL, 0, NULL, 0);
}else {
printf("HttpSendRequest Error:%d\n",dwError);
return -1;
}
}
dwSize = 256;
lpHeadersA = new CHAR [dwSize];
if (!HttpQueryInfoA(hRequest, HTTP_QUERY_STATUS_TEXT, (LPVOID)lpHeadersA, &dwSize, NULL)) {
printf("HttpQueryInfoA Error\n");
return -1;
}
lpHeadersA[dwSize] = '\0';
printf ("Header: %s\n", lpHeadersA);
 
dwSize = 65536;
lpBufferA = new CHAR [dwSize];
{ /* do only one time */
if(!InternetReadFile(hRequest, (LPVOID)lpBufferA, dwSize - 1, &dwSize)) {
printf("InternetReadFile Error\n");
return -1;
}
 
if (dwSize !=0 ){
lpBufferA[dwSize-1] = '\0';
printf("%s\n", lpBufferA);
} else {
printf("No data got\n");
}
}
 
delete[] lpBufferA;
 
InternetCloseHandle(hRequest);
InternetCloseHandle(hConnect);
InternetCloseHandle(hInet);
return 0;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.