Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
5.6 KiB

  1. /*
  2. File : ATKInternet.cpp
  3. This is a wrapper function for internet API which accepts UNICODE.
  4. Basically these wrapper converts the UNICODE string to normal SBCS and invokes the
  5. appropriate SBCS internet function
  6. */
  7. #ifdef _UNICODE
  8. #include <tchar.h>
  9. #include "AtkInternet.h"
  10. #include "rw_common.h"
  11. #define MAX_SZ 260
  12. HINTERNET ATK_InternetOpenW(
  13. IN LPCWSTR lpszAgent,
  14. IN DWORD dwAccessType,
  15. IN LPCWSTR lpszProxy OPTIONAL,
  16. IN LPCWSTR lpszProxyBypass OPTIONAL,
  17. IN DWORD dwFlags
  18. )
  19. {
  20. char *pRet;
  21. char szAgent[MAX_SZ] = "" ;
  22. char szProxy[MAX_SZ] ="";
  23. char szProxyByPass[MAX_SZ]="";
  24. pRet = ConvertToANSIString (lpszAgent);
  25. if(pRet) {
  26. strcpy(szAgent, pRet);
  27. }
  28. pRet = ConvertToANSIString (lpszProxy);
  29. if(pRet) {
  30. strcpy(szProxy, pRet);
  31. }
  32. pRet = ConvertToANSIString (lpszProxyBypass);
  33. if(pRet) {
  34. strcpy(szProxyByPass, ConvertToANSIString (lpszProxyBypass));
  35. }
  36. return InternetOpenA(
  37. szAgent,
  38. dwAccessType,
  39. szProxy ,
  40. szProxyByPass,
  41. dwFlags);
  42. }
  43. HINTERNET
  44. ATK_InternetConnectW(
  45. IN HINTERNET hInternet,
  46. IN LPCWSTR lpszServerName,
  47. IN INTERNET_PORT nServerPort,
  48. IN LPCWSTR lpszUserName OPTIONAL,
  49. IN LPCWSTR lpszPassword OPTIONAL,
  50. IN DWORD dwService,
  51. IN DWORD dwFlags,
  52. IN DWORD dwContext
  53. )
  54. {
  55. char szServerName[MAX_SZ]="";
  56. char szUserName[MAX_SZ]="";
  57. char szPassword[MAX_SZ]="";
  58. char *pRet;
  59. pRet = ConvertToANSIString (lpszServerName);
  60. if(pRet) {
  61. strcpy(szServerName,pRet);
  62. }
  63. pRet = ConvertToANSIString (lpszUserName);
  64. if(pRet) {
  65. strcpy(szUserName,pRet);
  66. }
  67. pRet = ConvertToANSIString (lpszPassword);
  68. if(pRet) {
  69. strcpy(szPassword,pRet);
  70. }
  71. return InternetConnectA(
  72. hInternet,
  73. szServerName,
  74. nServerPort,
  75. szUserName ,
  76. szPassword ,
  77. dwService,
  78. dwFlags,
  79. dwContext
  80. );
  81. }
  82. HINTERNET
  83. ATK_HttpOpenRequestW(
  84. IN HINTERNET hConnect,
  85. IN LPCWSTR lpszVerb,
  86. IN LPCWSTR lpszObjectName,
  87. IN LPCWSTR lpszVersion,
  88. IN LPCWSTR lpszReferrer OPTIONAL,
  89. IN LPCWSTR FAR * lpszAcceptTypes OPTIONAL,
  90. IN DWORD dwFlags,
  91. IN DWORD_PTR dwContext
  92. )
  93. {
  94. char szVerb[MAX_SZ]= "";
  95. char szObjectName[MAX_SZ]="";
  96. char szVersion[MAX_SZ]="";
  97. char szReferrer[MAX_SZ]="";
  98. char szAcceptTypes[MAX_SZ]="";
  99. char *pRet;
  100. pRet = ConvertToANSIString (lpszVerb);
  101. if(pRet) {
  102. strcpy(szVerb,pRet);
  103. }
  104. pRet = ConvertToANSIString (lpszObjectName);
  105. if(pRet) {
  106. strcpy(szObjectName,pRet);
  107. }
  108. pRet = ConvertToANSIString (lpszVersion);
  109. if(pRet) {
  110. strcpy(szVersion,pRet);
  111. }
  112. pRet = ConvertToANSIString (lpszReferrer);
  113. if(pRet) {
  114. strcpy(szReferrer,pRet);
  115. }
  116. // strcpy(szAcceptTypes,ConvertToANSIString (lpszAcceptTypes));
  117. return HttpOpenRequestA(
  118. hConnect,
  119. szVerb,
  120. szObjectName,
  121. szVersion,
  122. szReferrer ,
  123. NULL,
  124. dwFlags,
  125. dwContext
  126. );
  127. }
  128. BOOL
  129. ATK_HttpSendRequestW(
  130. IN HINTERNET hRequest,
  131. IN LPCWSTR lpszHeaders OPTIONAL,
  132. IN DWORD dwHeadersLength,
  133. IN LPVOID lpOptional OPTIONAL,
  134. IN DWORD dwOptionalLength
  135. )
  136. {
  137. char szHeaders[MAX_SZ]="";
  138. char *pRet;
  139. pRet = ConvertToANSIString (lpszHeaders);
  140. if(pRet) {
  141. strcpy(szHeaders,pRet);
  142. }
  143. return HttpSendRequestA(
  144. hRequest,
  145. szHeaders ,
  146. dwHeadersLength,
  147. lpOptional,
  148. dwOptionalLength);
  149. }
  150. BOOL
  151. ATK_InternetGetLastResponseInfoW(
  152. OUT LPDWORD lpdwError,
  153. OUT LPWSTR lpszBuffer OPTIONAL,
  154. IN OUT LPDWORD lpdwBufferLength
  155. )
  156. {
  157. DWORD dwError;
  158. DWORD dwErrorLen;
  159. CHAR szErrorInfo[256];
  160. dwErrorLen = 256;
  161. BOOL bRet;
  162. bRet = InternetGetLastResponseInfoA(&dwError,
  163. szErrorInfo,
  164. &dwErrorLen);
  165. #ifdef _DEBUG
  166. RW_DEBUG << "\nInternet GetLastResponse ErrorNo:" << dwError ;
  167. RW_DEBUG << "\n\tErrorInfo:"<<szErrorInfo<<flush;
  168. #endif
  169. return bRet;
  170. }
  171. BOOL ATK_HttpQueryInfoW(
  172. IN HINTERNET hRequest,
  173. IN DWORD dwInfoLevel,
  174. IN OUT LPVOID lpBuffer OPTIONAL,
  175. IN OUT LPDWORD lpdwBufferLength,
  176. IN OUT LPDWORD lpdwIndex OPTIONAL
  177. )
  178. {
  179. BOOL bRet;
  180. bRet = HttpQueryInfoA(hRequest, dwInfoLevel,lpBuffer,
  181. lpdwBufferLength, lpdwIndex);
  182. #ifdef _DEBUG
  183. RW_DEBUG << "\nHttpQueryInfo:" ;
  184. RW_DEBUG << "\n\tBuffer Length "<< *lpdwBufferLength <<flush;
  185. #endif
  186. return bRet;
  187. }
  188. BOOL ATK_InternetGetCookieW(IN TCHAR *lpszUrl,
  189. IN TCHAR *lpszCookieName,
  190. OUT TCHAR *lpCookieData,
  191. OUT LPDWORD lpdwSize)
  192. {
  193. char czUrl[256]="";
  194. char czCookieName[128]="";
  195. char czCookieData[256]="";
  196. char *pRet= NULL;
  197. TCHAR *pTP;
  198. BOOL bRetVal;
  199. #ifdef _UNICODE
  200. // Presently the UNICODE version is not implemented in
  201. // the NT SDK
  202. //and the declaration defined in WININET.H is
  203. // BOOLAPI
  204. // InternetGetCookieW(
  205. // IN LPCSTR lpszUrl,
  206. // IN LPCWSTR lpszCookieName,
  207. // OUT LPWSTR lpCookieData,
  208. // IN OUT LPDWORD lpdwSize
  209. //);
  210. // So Convert the first parameter to ANSI String
  211. pRet = ConvertToANSIString(lpszUrl);
  212. if(pRet) strcpy(czUrl,pRet);
  213. pRet = ConvertToANSIString(lpszCookieName);
  214. if(pRet) strcpy(czCookieName,pRet);
  215. #ifdef USE_ASTRATEK_WRAPPER
  216. bRetVal = InternetGetCookieA(czUrl,
  217. czCookieName,
  218. czCookieData,
  219. lpdwSize);
  220. //
  221. // Convert the Return Values to Unicode
  222. pTP= ConvertToUnicode(czCookieData);
  223. if(pTP) {
  224. _tcscpy(lpCookieData,pTP);
  225. }else {
  226. lpCookieData[0]= _T('\0');
  227. }
  228. #else
  229. bRetVal = InternetGetCookieW(czUrl,
  230. lpszCookieName,
  231. lpCookieData,
  232. lpdwSize);
  233. #endif
  234. return bRetVal;
  235. #endif
  236. }
  237. BOOL ATK_InternetQueryOption(IN HINTERNET hInternet,
  238. IN DWORD dwOption,
  239. OUT LPVOID lpBuffer,
  240. IN OUT LPDWORD lpdwBufferLength
  241. )
  242. {
  243. BOOL bRetVal;
  244. bRetVal = InternetQueryOptionA(hInternet,
  245. dwOption,
  246. lpBuffer,
  247. lpdwBufferLength);
  248. return bRetVal;
  249. }
  250. #endif