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.

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