Leaked source code of windows server 2003
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.

832 lines
19 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include "AtkInternet.h"
  4. #include "resource.h"
  5. #include <ithread.h>
  6. #include "icw.h"
  7. #include "util.h"
  8. #include "rw_common.h"
  9. #include "ATK_inet.h"
  10. #define RWZ_POST_MAX_RETRY 3
  11. struct _MK
  12. {
  13. DWORD dwQuery;
  14. char *s;
  15. } ;
  16. #define MK(x) {x,#x}
  17. static _MK Queries[] =
  18. {
  19. MK(HTTP_QUERY_MIME_VERSION),
  20. MK(HTTP_QUERY_CONTENT_TYPE),
  21. MK(HTTP_QUERY_CONTENT_TRANSFER_ENCODING),
  22. MK(HTTP_QUERY_CONTENT_ID),
  23. MK(HTTP_QUERY_CONTENT_DESCRIPTION),
  24. MK(HTTP_QUERY_CONTENT_LENGTH),
  25. MK(HTTP_QUERY_ALLOW),
  26. MK(HTTP_QUERY_PUBLIC),
  27. MK(HTTP_QUERY_DATE),
  28. MK(HTTP_QUERY_EXPIRES),
  29. MK(HTTP_QUERY_LAST_MODIFIED),
  30. MK(HTTP_QUERY_MESSAGE_ID),
  31. MK(HTTP_QUERY_URI),
  32. MK(HTTP_QUERY_DERIVED_FROM),
  33. MK(HTTP_QUERY_COST),
  34. MK(HTTP_QUERY_PRAGMA),
  35. MK(HTTP_QUERY_VERSION),
  36. MK(HTTP_QUERY_STATUS_CODE),
  37. MK(HTTP_QUERY_STATUS_TEXT),
  38. MK(HTTP_QUERY_RAW_HEADERS),
  39. MK(HTTP_QUERY_RAW_HEADERS_CRLF),
  40. MK(HTTP_QUERY_REQUEST_METHOD)
  41. };
  42. void QueryForInfo(HINTERNET );
  43. void GetQueryInfo(HINTERNET ,DWORD ,char *);
  44. typedef BOOL (WINAPI *LPICP)(HWND,BOOL,BOOL);
  45. LPICP lpICP;
  46. void QueryForInfo(HINTERNET hIntHandle)
  47. {
  48. int nSize = sizeof(Queries)/sizeof(_MK);
  49. for(int i=0;i< nSize;i++)
  50. {
  51. GetQueryInfo(hIntHandle,Queries[i].dwQuery,Queries[i].s);
  52. }
  53. }
  54. void GetQueryInfo(HINTERNET hIntHandle,DWORD dwQuery,char *s)
  55. {
  56. char dwbufQuery[512];
  57. DWORD dwLengthBufQuery;
  58. BOOL bQuery = ::ATK_HttpQueryInfo( hIntHandle,
  59. dwQuery,
  60. &dwbufQuery,
  61. &dwLengthBufQuery,
  62. NULL) ;
  63. #ifdef _LOG_IN_FILE
  64. RW_DEBUG << "\n" << s << dwbufQuery << flush;
  65. #endif
  66. }
  67. void _stdcall myCallback( IN HINTERNET hInternet,
  68. IN DWORD dwContext,
  69. IN DWORD dwInternetStatus,
  70. IN LPVOID lpvStatusInformation OPTIONAL,
  71. IN DWORD dwStatusInformationLength)
  72. {
  73. int iX= 100;
  74. iX++;
  75. switch(dwInternetStatus)
  76. {
  77. case INTERNET_STATUS_RESOLVING_NAME :
  78. #ifdef _LOG_IN_FILE
  79. RW_DEBUG << "\nCallback: RESOLVING_NAME\n" << flush;
  80. #endif
  81. break;
  82. case INTERNET_STATUS_NAME_RESOLVED :
  83. #ifdef _LOG_IN_FILE
  84. RW_DEBUG << "\nCallback: INTERNET_STATUS_NAME_RESOLVED\n" << flush;
  85. #endif
  86. break;
  87. case INTERNET_STATUS_CONNECTING_TO_SERVER :
  88. #ifdef _LOG_IN_FILE
  89. RW_DEBUG << "\nCallback: INTERNET_STATUS_CONNECTING_TO_SERVER\n" << flush;
  90. #endif
  91. break;
  92. case INTERNET_STATUS_CONNECTED_TO_SERVER :
  93. #ifdef _LOG_IN_FILE
  94. RW_DEBUG << "\nCallback: INTERNET_STATUS_CONNECTED_TO_SERVER\n" << flush;
  95. #endif
  96. break;
  97. case INTERNET_STATUS_SENDING_REQUEST :
  98. #ifdef _LOG_IN_FILE
  99. RW_DEBUG << "\nCallback: INTERNET_STATUS_SENDING_REQUEST\n" << flush;
  100. #endif
  101. break;
  102. case INTERNET_STATUS_REQUEST_SENT :
  103. #ifdef _LOG_IN_FILE
  104. RW_DEBUG << "\nCallback: INTERNET_STATUS_REQUEST_SENT\n" << flush;
  105. #endif
  106. break;
  107. case INTERNET_STATUS_RECEIVING_RESPONSE :
  108. #ifdef _LOG_IN_FILE
  109. RW_DEBUG << "\nCallback: INTERNET_STATUS_RECEIVING_RESPONSE\n" << flush;
  110. #endif
  111. break;
  112. case INTERNET_STATUS_RESPONSE_RECEIVED :
  113. #ifdef _LOG_IN_FILE
  114. RW_DEBUG << "\nCallback: INTERNET_STATUS_RESPONSE_RECEIVED\n" << flush;
  115. #endif
  116. break;
  117. case INTERNET_STATUS_REDIRECT :
  118. #ifdef _LOG_IN_FILE
  119. RW_DEBUG << "\nCallback: INTERNET_STATUS_REDIRECT\n" << flush;
  120. #endif
  121. break;
  122. case INTERNET_STATUS_CLOSING_CONNECTION :
  123. #ifdef _LOG_IN_FILE
  124. RW_DEBUG << "\nCallback: INTERNET_STATUS_CLOSING_CONNECTION\n" << flush;
  125. #endif
  126. break;
  127. case INTERNET_STATUS_CONNECTION_CLOSED :
  128. #ifdef _LOG_IN_FILE
  129. RW_DEBUG << "\nCallback: INTERNET_STATUS_CONNECTION_CLOSED\n" << flush;
  130. #endif
  131. break;
  132. case INTERNET_STATUS_HANDLE_CREATED :
  133. #ifdef _LOG_IN_FILE
  134. RW_DEBUG << "\nCallback: INTERNET_STATUS_HANDLE_CREATED\n" << flush;
  135. #endif
  136. break;
  137. case INTERNET_STATUS_REQUEST_COMPLETE :
  138. #ifdef _LOG_IN_FILE
  139. RW_DEBUG << "\nCallback: INTERNET_STATUS_REQUEST_COMPLETE\n" << flush;
  140. #endif
  141. break;
  142. default :
  143. #ifdef _LOG_IN_FILE
  144. RW_DEBUG <<"\n Callback : default " << flush;
  145. #endif
  146. }
  147. }
  148. void pickup(const char* in, char* out, int *ipProxy)
  149. {
  150. char czProzy[10]= "80";
  151. char *pProxy;
  152. int iCount ;
  153. pProxy = czProzy;
  154. if( *in == '/' )
  155. in++;
  156. if( *in == '/' )
  157. in++;
  158. while( *in && (*in != ':') && (*in != ';') )
  159. *out++ = *in++;
  160. *out = 0;
  161. if(!*in)
  162. return;
  163. if ( *in == ':' || *in == ';' )
  164. *in++;
  165. iCount = 0;
  166. while(*in && ( isspace(*in) || isdigit(*in)) )
  167. {
  168. if( isdigit(*in) && iCount < ((sizeof(czProzy) / sizeof(czProzy[0])) - 1) ) // leave room for the terminating NULL
  169. {
  170. *pProxy++ = *in;
  171. iCount++;
  172. }
  173. *in++;
  174. }
  175. if(iCount)
  176. *pProxy = 0;
  177. *ipProxy = atoi(czProzy);
  178. }
  179. /* //remove all blabks immediately preceeding ':' and afterwards.
  180. // eg. "HELLO WORLD : 80 " =>
  181. // "HELLO WORLD:80"
  182. Remove all blanks: No blanks are allowed in a machine name?
  183. */
  184. void RemoveBlank(char *pszStr)
  185. {
  186. char *p, *q;
  187. p = pszStr;
  188. q = p;
  189. for(;*p;*p++)
  190. {
  191. if(!isspace(*p))
  192. {
  193. *q++ = *p;
  194. }
  195. }
  196. *q = '\0';
  197. }
  198. int getProxy(const char *in, char *out,int *piPort)
  199. {
  200. char *s;
  201. *piPort = 0;
  202. if( s= strstr(in, "http://") )
  203. {
  204. pickup(s+7,out,piPort);
  205. }
  206. else
  207. if(s= strstr(in, "http=") )
  208. {
  209. pickup(s+5,out,piPort);
  210. }
  211. else
  212. if( s= strstr(in, "http:") )
  213. {
  214. pickup(s+5,out,piPort);
  215. }
  216. else
  217. if(s= strstr(in, "://") )
  218. {
  219. *out = 0;
  220. return 0;
  221. }
  222. else
  223. if(s= strstr(in, "=") )
  224. {
  225. *out = 0;
  226. return 0;
  227. }
  228. else
  229. pickup(in,out,piPort);
  230. return 1;
  231. }
  232. // Constructor
  233. //
  234. CInternetThread::CInternetThread()
  235. : m_hSession(NULL),
  236. m_dwAccessType(PRE_CONFIG_INTERNET_ACCESS)
  237. {
  238. m_strProxyServer = NULL;
  239. m_strBuffer = NULL;
  240. m_strIISServer = NULL;
  241. m_strPath = NULL;
  242. m_hICWDllInstance = NULL ; // ICW DLL not loaded
  243. }
  244. // Closes the Internet session so InternetOpen will be called on next PostData.
  245. //
  246. void CInternetThread::ResetSession()
  247. {
  248. if (m_hSession != NULL)
  249. {
  250. ::InternetCloseHandle(m_hSession);
  251. m_hSession = NULL ;
  252. }
  253. }
  254. //
  255. //
  256. CInternetThread::~CInternetThread()
  257. {
  258. if (m_strBuffer) delete []m_strBuffer;
  259. if (m_strIISServer) delete []m_strIISServer;
  260. if (m_strProxyServer) delete []m_strProxyServer;
  261. if (m_UserName) delete [] m_UserName;
  262. if (m_Password ) delete [] m_Password;
  263. if (m_strPath) delete [] m_strPath;
  264. //ResetSession();
  265. if(m_hICWDllInstance)
  266. {
  267. FreeLibrary(m_hICWDllInstance);
  268. #ifdef _LOG_IN_FILE
  269. RW_DEBUG << "\n Freeing INETCFG.DLL " << flush;
  270. #endif
  271. m_hICWDllInstance = NULL;
  272. }
  273. }
  274. void CInternetThread ::UnLoadInetCfgDll()
  275. {
  276. if( m_hICWDllInstance)
  277. FreeLibrary(m_hICWDllInstance);
  278. m_hICWDllInstance = NULL;
  279. }
  280. void CInternetThread::SetBuffer(LPSTR strBuffer)
  281. {
  282. if (m_strBuffer)
  283. delete []m_strBuffer;
  284. if (strBuffer)
  285. {
  286. m_dwBufferLen = strlen(strBuffer)+1;
  287. m_strBuffer = (LPSTR) new CHAR[strlen(strBuffer)+1];
  288. strcpy(m_strBuffer, strBuffer);
  289. }
  290. }
  291. void CInternetThread::SetBuffer(LPSTR strBuffer, DWORD dwLen)
  292. {
  293. if (m_strBuffer)
  294. delete []m_strBuffer;
  295. if (strBuffer)
  296. {
  297. m_dwBufferLen = dwLen-1;
  298. m_strBuffer = (LPSTR) new CHAR[m_dwBufferLen+1];
  299. memset(m_strBuffer, '\0', m_dwBufferLen+1);
  300. strncpy(m_strBuffer, strBuffer, m_dwBufferLen);
  301. }
  302. }
  303. HINSTANCE CInternetThread:: LoadInetCfgDll()
  304. {
  305. if(m_hICWDllInstance)
  306. {
  307. return m_hICWDllInstance;
  308. }
  309. m_hICWDllInstance = LoadLibrary(_T("INETCFG.DLL"));
  310. if (NULL == m_hICWDllInstance)
  311. {
  312. DisplayMessage("INETCFG.DLL LoadLibrary Failure", "");
  313. }
  314. return m_hICWDllInstance;
  315. }
  316. BOOL CInternetThread :: InstallModem(HWND hwnd)
  317. {
  318. RW_DEBUG << "\n---Inside InstallModem" << flush;
  319. #ifdef _WINNT
  320. /*
  321. STARTUPINFOA startUpInfo;
  322. PROCESS_INFORMATION PrcsInfo;
  323. GetStartupInfoA(&startUpInfo);
  324. DWORD dwPrS;
  325. int iErr;
  326. if( dwPrS= CreateProcessA( NULL ,
  327. "rundll32.exe shell32.dll,Control_RunDLL modem.cpl", 0, 0,
  328. FALSE,CREATE_NEW_CONSOLE, 0, 0,
  329. &startUpInfo, &PrcsInfo) ) {
  330. WaitForSingleObject(PrcsInfo.hProcess, INFINITE);
  331. }
  332. else
  333. {
  334. iErr = GetLastError();
  335. RW_DEBUG << "\n Error In invoking Modem Init " << iErr << flush;
  336. }
  337. return 0;*/
  338. BOOL bRet;
  339. HINSTANCE hInstance = LoadLibrary(_T("modemui.dll"));
  340. if(hInstance != NULL)
  341. {
  342. lpICP = (LPICP) GetProcAddress(hInstance,"InvokeControlPanel");
  343. // Initialise the Control panel application
  344. bRet = lpICP(hwnd,FALSE,FALSE);
  345. FreeLibrary(hInstance);
  346. }
  347. else
  348. {
  349. bRet = FALSE;
  350. RW_DEBUG << "\n Error Loading modemui.dll" << flush;
  351. }
  352. return bRet;
  353. #else
  354. HINSTANCE hInst;
  355. BOOL bRestart=FALSE;
  356. INETCONFIGSYSTEM fpS;
  357. hInst = LoadInetCfgDll();
  358. fpS = (INETCONFIGSYSTEM) GetProcAddress(hInst, "InetConfigSystem");
  359. HRESULT hrs = (*fpS)(NULL,0x02,&bRestart);
  360. DWORD dwR = GetLastError();
  361. return bRestart;
  362. #endif
  363. }
  364. /*
  365. 05/05/97 : Proxy returns as http://XX:port
  366. */
  367. BOOL CInternetThread::GetSystemProxyServer(PCHAR szProxy,
  368. DWORD dwBufferLength,
  369. int *piProxyPort)
  370. {
  371. DWORD size = 0;
  372. ATK_InternetQueryOption(NULL, INTERNET_OPTION_PROXY,NULL, &size);
  373. #ifdef USE_ASTRATEK_WRAPPER
  374. BYTE* buf = new BYTE[size];
  375. #else
  376. BYTE* buf = new BYTE[size* sizeof(_TCHAR)];
  377. #endif
  378. ATK_INTERNET_PROXY_INFO* ipi = (ATK_INTERNET_PROXY_INFO*)buf;
  379. if (!ATK_InternetQueryOption(NULL, INTERNET_OPTION_PROXY, ipi, &size))
  380. {
  381. //MessageBox(NULL,_T("InternetQueryOption"),_T("False"),IDOK);
  382. delete[] buf;
  383. return FALSE;
  384. }
  385. else
  386. {
  387. if(ipi->dwAccessType != 3)
  388. {
  389. //MessageBox(NULL,_T("AccessType"),_T("False"),IDOK);
  390. delete[] buf;
  391. return FALSE;
  392. }
  393. else
  394. {
  395. //MessageBox(NULL,ConvertToUnicode(),ConvertToUnicode((LPSTR)ipi->lpszProxy),IDOK);
  396. #ifdef USE_ASTRATEK_WRAPPER
  397. if( getProxy(ipi->lpszProxy,szProxy,piProxyPort))
  398. #else
  399. if( getProxy(ConvertToANSIString(ipi->lpszProxy),szProxy,piProxyPort))
  400. #endif
  401. {
  402. RemoveBlank(szProxy);
  403. // MessageBox(NULL,_T("after getproxy"),_T("TRUE"),IDOK);
  404. #ifdef _LOG_IN_FILE
  405. RW_DEBUG << "\n Actual HTTP Proxy [" <<szProxy << "] Port:" << *piProxyPort << flush;
  406. #endif
  407. delete[] buf;
  408. return TRUE;
  409. }
  410. else
  411. {
  412. //MessageBox(NULL,_T("GetProxy"),_T("False"),IDOK);
  413. delete[] buf;
  414. return FALSE;
  415. }
  416. }
  417. }
  418. }
  419. //
  420. // This function gets the Actual proxy settings string
  421. void CInternetThread :: GetSystemProxySettings( PCHAR szProxy,
  422. DWORD dwBufferLength)
  423. {
  424. DWORD size = 0;
  425. ATK_InternetQueryOption(NULL, INTERNET_OPTION_PROXY,NULL, &size);
  426. #ifdef USE_ASTRATEK_WRAPPER
  427. BYTE* buf = new BYTE[size];
  428. #else
  429. BYTE* buf = new BYTE[size* sizeof(_TCHAR)];
  430. #endif
  431. ATK_INTERNET_PROXY_INFO* ipi = (ATK_INTERNET_PROXY_INFO*)buf;
  432. ATK_InternetQueryOption(NULL, INTERNET_OPTION_PROXY, ipi, &size);
  433. #ifdef USE_ASTRATEK_WRAPPER
  434. strcpy(szProxy,ipi->lpszProxy);
  435. #else
  436. strcpy(szProxy,ConvertToANSIString(ipi->lpszProxy));
  437. #endif
  438. dwBufferLength = strlen(szProxy) +1;
  439. delete[] buf;
  440. }
  441. //
  442. // IN Parameters:
  443. // LPSTR strProxyServer : Proxy Server name in ANSI char
  444. // int iProxyPort : Proxy Server Port
  445. //
  446. void CInternetThread::SetSystemProxySettings(LPSTR strProxyServer)
  447. {
  448. TCHAR *pProxy;
  449. if (m_strProxyServer)
  450. delete []m_strProxyServer;
  451. if (strProxyServer)
  452. {
  453. pProxy = ConvertToUnicode(strProxyServer);
  454. m_strProxyServer = (LPTSTR) new TCHAR[_tcslen(pProxy)+11];
  455. _tcscpy(m_strProxyServer, pProxy);
  456. }
  457. }
  458. // IN Parameters:
  459. // LPSTR strProxyServer : Proxy Server name in ANSI char
  460. // int iProxyPort : Proxy Server Port
  461. void CInternetThread::SetProxyServer(LPSTR strProxyServer, int iProxyPort)
  462. {
  463. TCHAR czTemp[10];
  464. TCHAR *pProxy;
  465. if (m_strProxyServer)
  466. delete []m_strProxyServer;
  467. if (strProxyServer)
  468. {
  469. pProxy = ConvertToUnicode(strProxyServer);
  470. m_strProxyServer = (LPTSTR) new TCHAR[_tcslen(pProxy)+11];
  471. _tcscpy(m_strProxyServer, pProxy);
  472. _stprintf(czTemp,_T(":%d"),iProxyPort);
  473. _tcscat(m_strProxyServer,czTemp);
  474. }
  475. }
  476. void CInternetThread::SetIISServer(LPTSTR strIISServer)
  477. {
  478. if (m_strIISServer)
  479. delete []m_strIISServer;
  480. if (strIISServer)
  481. {
  482. m_strIISServer = (LPTSTR) new TCHAR[_tcslen(strIISServer)+1];
  483. _tcscpy(m_strIISServer, strIISServer);
  484. }
  485. }
  486. void CInternetThread::SetServerPath(LPTSTR strPath)
  487. {
  488. if (m_strPath)
  489. delete []m_strPath;
  490. if (strPath)
  491. {
  492. m_strPath = (LPTSTR) new TCHAR[_tcslen(strPath)+1];
  493. _tcscpy(m_strPath, strPath);
  494. }
  495. }
  496. // Verify that rAddress is partially valid. Start the worker thread to get a web page.
  497. DWORD CInternetThread::PostData(HWND hWnd)
  498. {
  499. int iRetryCount;
  500. UINT uiRetVal;
  501. int iExit;
  502. iExit =0;
  503. iRetryCount = 0;
  504. uiRetVal = RWZ_POST_FAILURE;
  505. if (!m_strIISServer || !m_strPath)
  506. {
  507. DisplayMessage ("IIS Server path not found ");
  508. }
  509. /*
  510. do {
  511. #ifdef _LOG_IN_FILE
  512. RW_DEBUG << "\nRetry Posting " << iRetryCount+1 << flush;
  513. #endif
  514. uiRetVal = _PostDataWorker();
  515. if(uiRetVal != RWZ_POST_SUCCESS) {
  516. iRetryCount++;
  517. }else {
  518. iExit = 1;
  519. }
  520. if( uiRetVal == RWZ_POST_WITH_SSL_FAILURE) {
  521. // Do not Retry if it is an SSL problem
  522. iExit= 1;
  523. }
  524. if(iRetryCount > RWZ_POST_MAX_RETRY ){
  525. iExit = 1;
  526. }
  527. }while(!iExit);
  528. **/
  529. uiRetVal = _PostDataWorker(hWnd);
  530. return uiRetVal;
  531. }
  532. // This is the thread function.
  533. //
  534. UINT CInternetThread::PostDataThread(LPVOID pvThread)
  535. {
  536. CInternetThread* pInternetThread = (CInternetThread*) pvThread ;
  537. if (pInternetThread == NULL || (!pInternetThread->m_strIISServer))
  538. {
  539. return FALSE;
  540. }
  541. return pInternetThread->_PostDataWorker(NULL) ;
  542. }
  543. // This is where all of the actually Internet work is done.
  544. UINT CInternetThread::_PostDataWorker(HWND hWnd)
  545. {
  546. UINT uiResult = RWZ_POST_FAILURE;
  547. BOOL bRead;
  548. HINTERNET hConnect;
  549. HINTERNET hHttpFile;
  550. _TCHAR szHeader[240];
  551. BOOL bSendRequest;
  552. DWORD dwCL=0;
  553. DWORD dwLengthBufQuery ;
  554. DWORD dwInfoLevel;
  555. BOOL bQuery;
  556. CHAR pBuffer [MAX_PATH] ; // ?? decide with Steve on Bugffer Sz
  557. DWORD dwBytesRead ;
  558. // Variables for the SSL / Normal operation
  559. INTERNET_PORT nServerPort;
  560. DWORD dwFlags;
  561. // Added for Proxy Server
  562. LPTSTR pUserName;
  563. LPTSTR pPassword;
  564. LPTSTR pProxyServerName;
  565. pUserName =_T("");
  566. pPassword =_T("");
  567. pProxyServerName =NULL;
  568. if(m_bPostWithSSL){
  569. nServerPort = INTERNET_DEFAULT_HTTPS_PORT;
  570. dwFlags = INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_SECURE;
  571. }else {
  572. nServerPort = INTERNET_INVALID_PORT_NUMBER;
  573. dwFlags = INTERNET_FLAG_DONT_CACHE;
  574. }
  575. #ifdef _LOG_IN_FILE
  576. RW_DEBUG << "\nPost Data:\n" << flush;
  577. #endif
  578. if (m_hSession == NULL){
  579. // Initialize the Internet Functions.
  580. m_hSession = ATK_InternetOpen(_T("Registration Wizard"),
  581. m_dwAccessType,
  582. pProxyServerName,
  583. NULL,
  584. 0
  585. );
  586. #ifdef _LOG_IN_FILE
  587. RW_DEBUG << "\n\tInternet Open:" << m_hSession << flush;
  588. #endif
  589. if (!Succeeded(m_hSession, "InternetOpen"))
  590. {
  591. goto EndFn;
  592. }
  593. }
  594. hConnect = ATK_InternetConnect(m_hSession,
  595. m_strIISServer,
  596. nServerPort,
  597. pUserName, // m_UserName, Changed on 2/4/98 for IE Proxy Auth
  598. pPassword, // m_Password,
  599. INTERNET_SERVICE_HTTP,
  600. 0,
  601. 0);
  602. #ifdef _LOG_IN_FILE
  603. RW_DEBUG << "\n\tInternet Connection:" << ConvertToANSIString(m_strIISServer) << flush;
  604. // RW_DEBUG << "\n\tUserName :" << ConvertToANSIString(m_UserName) << flush;
  605. // RW_DEBUG << "\n\tPassword :" << ConvertToANSIString(m_Password) << flush;
  606. #endif
  607. if (!Succeeded(hConnect, "InternetConnect"))
  608. {
  609. goto EndFn;
  610. }
  611. hHttpFile = ATK_HttpOpenRequest(hConnect,
  612. _T("POST"),
  613. m_strPath,
  614. HTTP_VERSION,
  615. NULL,
  616. NULL, //szAcceptType,
  617. dwFlags,//INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_SECURE,
  618. 0) ;
  619. #ifdef _LOG_IN_FILE
  620. RW_DEBUG << "\n\t\tInternet Post :" << ConvertToANSIString(m_strPath) << flush;
  621. #endif
  622. if (! Succeeded(hHttpFile, "HttpOpenRequest"))
  623. {
  624. ::InternetCloseHandle(hConnect);
  625. goto EndFn;
  626. }
  627. _tcscpy(szHeader, _T("Accept: */*\nContent-Type: application/x-www-form-urlencoded"));
  628. bSendRequest = ATK_HttpSendRequest(hHttpFile,
  629. szHeader, -1L , m_strBuffer, m_dwBufferLen);
  630. #ifdef _LOG_IN_FILE
  631. RW_DEBUG << "\n\t\tSendData:" << m_strBuffer << flush;
  632. #endif
  633. if (!Succeeded1(bSendRequest, "HttpSendRequest"))
  634. {
  635. ::InternetCloseHandle(hConnect);
  636. goto EndFn;
  637. }
  638. // Get size of file.
  639. dwInfoLevel = HTTP_QUERY_CONTENT_TRANSFER_ENCODING;
  640. dwLengthBufQuery = sizeof( DWORD);
  641. bQuery = ATK_HttpQueryInfo(hHttpFile,
  642. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  643. &dwCL,
  644. &dwLengthBufQuery,
  645. NULL) ;
  646. #ifdef _LOG_IN_FILE
  647. RW_DEBUG << "\n Query ContentLength : " << dwCL << flush;
  648. #endif
  649. if (! Succeeded1(bQuery, "HttpQueryInfo") )
  650. {
  651. ::InternetCloseHandle(hConnect);
  652. goto EndFn;
  653. }
  654. memset(pBuffer,0,MAX_PATH);
  655. bRead = ::InternetReadFile(hHttpFile,
  656. pBuffer,
  657. MAX_PATH,
  658. &dwBytesRead);
  659. #ifdef _LOG_IN_FILE
  660. RW_DEBUG <<"\n ReturnBuffer " << pBuffer << flush;
  661. #endif
  662. if (!Succeeded1(bRead, "InternetReadFile"))
  663. {
  664. DisplayMessage("HTTP POST FAILURE ...");
  665. ::InternetCloseHandle(hConnect);
  666. goto EndFn;
  667. }
  668. if(pBuffer[0] == _T('0' ))
  669. {
  670. #ifdef _LOG_IN_FILE
  671. RW_DEBUG << "\n Post Successful" << flush;
  672. #endif
  673. uiResult = RWZ_POST_SUCCESS;
  674. }
  675. else {
  676. // 438
  677. if ( (pBuffer[0] == _T('4')) && (pBuffer[1] == _T('3')) ) {
  678. uiResult = RWZ_POST_MSN_SITE_BUSY;
  679. #ifdef _LOG_IN_FILE
  680. RW_DEBUG << "\n Post Failure " << flush;
  681. #endif
  682. }
  683. else {
  684. uiResult = RWZ_POST_WITH_SSL_FAILURE;
  685. #ifdef _LOG_IN_FILE
  686. RW_DEBUG << "\n Post with SSL Failure " << flush;
  687. #endif
  688. }
  689. }
  690. pBuffer[dwBytesRead] = 0 ;
  691. ::InternetCloseHandle(hConnect);
  692. EndFn:
  693. return uiResult ;
  694. }
  695. DWORD InvokePost(HWND hWnd, CInternetThread *p)
  696. {
  697. return p->PostData(hWnd);
  698. }