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.

393 lines
16 KiB

  1. #include "pre.h"
  2. #include "tchar.h"
  3. #include "webvwids.h"
  4. #pragma data_seg(".data")
  5. // The following are the names for the name/value pairs that will be passed as a query string to the
  6. // ISP signup server
  7. const TCHAR csz_USER_FIRSTNAME[] = TEXT("USER_FIRSTNAME");
  8. const TCHAR csz_USER_LASTNAME[] = TEXT("USER_LASTNAME");
  9. const TCHAR csz_USER_ADDRESS[] = TEXT("USER_ADDRESS");
  10. const TCHAR csz_USER_MOREADDRESS[] = TEXT("USER_MOREADDRESS");
  11. const TCHAR csz_USER_CITY[] = TEXT("USER_CITY");
  12. const TCHAR csz_USER_STATE[] = TEXT("USER_STATE");
  13. const TCHAR csz_USER_ZIP[] = TEXT("USER_ZIP");
  14. const TCHAR csz_USER_PHONE[] = TEXT("USER_PHONE");
  15. const TCHAR csz_AREACODE[] = TEXT("AREACODE");
  16. const TCHAR csz_COUNTRYCODE[] = TEXT("COUNTRYCODE");
  17. const TCHAR csz_USER_FE_NAME[] = TEXT("USER_FE_NAME");
  18. const TCHAR csz_PAYMENT_TYPE[] = TEXT("PAYMENT_TYPE");
  19. const TCHAR csz_PAYMENT_BILLNAME[] = TEXT("PAYMENT_BILLNAME");
  20. const TCHAR csz_PAYMENT_BILLADDRESS[] = TEXT("PAYMENT_BILLADDRESS");
  21. const TCHAR csz_PAYMENT_BILLEXADDRESS[] = TEXT("PAYMENT_BILLEXADDRESS");
  22. const TCHAR csz_PAYMENT_BILLCITY[] = TEXT("PAYMENT_BILLCITY");
  23. const TCHAR csz_PAYMENT_BILLSTATE[] = TEXT("PAYMENT_BILLSTATE");
  24. const TCHAR csz_PAYMENT_BILLZIP[] = TEXT("PAYMENT_BILLZIP");
  25. const TCHAR csz_PAYMENT_BILLPHONE[] = TEXT("PAYMENT_BILLPHONE");
  26. const TCHAR csz_PAYMENT_DISPLAYNAME[] = TEXT("PAYMENT_DISPLAYNAME");
  27. const TCHAR csz_PAYMENT_CARDNUMBER[] = TEXT("PAYMENT_CARDNUMBER");
  28. const TCHAR csz_PAYMENT_EXMONTH[] = TEXT("PAYMENT_EXMONTH");
  29. const TCHAR csz_PAYMENT_EXYEAR[] = TEXT("PAYMENT_EXYEAR");
  30. const TCHAR csz_PAYMENT_CARDHOLDER[] = TEXT("PAYMENT_CARDHOLDER");
  31. const TCHAR csz_SIGNED_PID[] = TEXT("SIGNED_PID");
  32. const TCHAR csz_GUID[] = TEXT("GUID");
  33. const TCHAR csz_OFFERID[] = TEXT("OFFERID");
  34. const TCHAR csz_USER_COMPANYNAME[] = TEXT("USER_COMPANYNAME");
  35. const TCHAR csz_ICW_VERSION[] = TEXT("ICW_Version");
  36. // NOTE: This order of this table is dependant on the order ot the ENUM in WEBVIEW.H for ISPDATA element.
  37. // DO NOT CHANGE 1 without CHANGING the other!!!!!
  38. ISPDATAELEMENT aryISPDataElements[] =
  39. {
  40. { csz_USER_FIRSTNAME, NULL, 0, IDS_USERINFO_FIRSTNAME, REQUIRE_FIRSTNAME },
  41. { csz_USER_LASTNAME, NULL, 0, IDS_USERINFO_LASTNAME, REQUIRE_LASTNAME },
  42. { csz_USER_ADDRESS, NULL, 0, IDS_USERINFO_ADDRESS1, REQUIRE_ADDRESS },
  43. { csz_USER_MOREADDRESS, NULL, 0, IDS_USERINFO_ADDRESS2, REQUIRE_MOREADDRESS },
  44. { csz_USER_CITY, NULL, 0, IDS_USERINFO_CITY, REQUIRE_CITY },
  45. { csz_USER_STATE, NULL, 0, IDS_USERINFO_STATE, REQUIRE_STATE },
  46. { csz_USER_ZIP, NULL, 0, IDS_USERINFO_ZIP, REQUIRE_ZIP },
  47. { csz_USER_PHONE, NULL, 0, IDS_USERINFO_PHONE, REQUIRE_PHONE },
  48. { csz_AREACODE, NULL, 0, 0, 0 },
  49. { csz_COUNTRYCODE, NULL, 0, 0, 0 },
  50. { csz_USER_FE_NAME, NULL, 0, IDS_USERINFO_FE_NAME, REQUIRE_FE_NAME },
  51. { csz_PAYMENT_TYPE, NULL, 0, 0, 0 },
  52. { csz_PAYMENT_BILLNAME, NULL, 0, IDS_PAYMENT_PBNAME, REQUIRE_PHONEIV_BILLNAME },
  53. { csz_PAYMENT_BILLADDRESS, NULL, 0, IDS_PAYMENT_CCADDRESS, REQUIRE_CCADDRESS },
  54. { csz_PAYMENT_BILLEXADDRESS,NULL, 0, IDS_USERINFO_ADDRESS2, REQUIRE_IVADDRESS2 },
  55. { csz_PAYMENT_BILLCITY, NULL, 0, IDS_USERINFO_CITY, REQUIRE_IVCITY },
  56. { csz_PAYMENT_BILLSTATE, NULL, 0, IDS_USERINFO_STATE, REQUIRE_IVSTATE },
  57. { csz_PAYMENT_BILLZIP, NULL, 0, IDS_USERINFO_ZIP, REQUIRE_IVZIP },
  58. { csz_PAYMENT_BILLPHONE, NULL, 0, IDS_PAYMENT_PBNUMBER, REQUIRE_PHONEIV_ACCNUM },
  59. { csz_PAYMENT_DISPLAYNAME, NULL, 0, 0, 0 },
  60. { csz_PAYMENT_CARDNUMBER, NULL, ValidateCCNumber, IDS_PAYMENT_CCNUMBER, REQUIRE_CCNUMBER },
  61. { csz_PAYMENT_EXMONTH, NULL, 0, 0, 0 },
  62. { csz_PAYMENT_EXYEAR, NULL, ValidateCCExpire, 0, 0 },
  63. { csz_PAYMENT_CARDHOLDER, NULL, 0, IDS_PAYMENT_CCNAME, REQUIRE_CCNAME },
  64. { csz_SIGNED_PID, NULL, 0, 0, 0 },
  65. { csz_GUID, NULL, 0, 0, 0 },
  66. { csz_OFFERID, NULL, 0, 0, 0 },
  67. { NULL, NULL, 0, 0, 0 },
  68. { NULL, NULL, 0, 0, 0 },
  69. { csz_USER_COMPANYNAME, NULL, 0, IDS_USERINFO_COMPANYNAME, REQUIRE_COMPANYNAME },
  70. { csz_ICW_VERSION, NULL, 0, 0, 0 }
  71. };
  72. #define ISPDATAELEMENTS_LEN sizeof(aryISPDataElements) / sizeof(ISPDATAELEMENT)
  73. #pragma data_seg()
  74. //+----------------------------------------------------------------------------
  75. //
  76. // Function CICWISPData:CICWISPData
  77. //
  78. // Synopsis This is the constructor, nothing fancy
  79. //
  80. //-----------------------------------------------------------------------------
  81. CICWISPData::CICWISPData
  82. (
  83. CServer* pServer
  84. )
  85. {
  86. TraceMsg(TF_CWEBVIEW, "CICWISPData constructor called");
  87. m_lRefCount = 0;
  88. // Initialize the data elements array
  89. m_ISPDataElements = aryISPDataElements;
  90. // Assign the pointer to the server control object.
  91. m_pServer = pServer;
  92. }
  93. CICWISPData::~CICWISPData()
  94. {
  95. // Walk through and free any allocated values in m_ISPDataElements
  96. for (int i = 0; i < ISPDATAELEMENTS_LEN; i ++)
  97. {
  98. if (m_ISPDataElements[i].lpQueryElementValue)
  99. free(m_ISPDataElements[i].lpQueryElementValue);
  100. }
  101. }
  102. // BUGBUG need a destructor to walk the array and free the lpQueryElementValue members
  103. //+----------------------------------------------------------------------------
  104. //
  105. // Function CICWISPData::QueryInterface
  106. //
  107. // Synopsis This is the standard QI, with support for
  108. // IID_Unknown, IICW_Extension and IID_ICWApprentice
  109. // (stolen from Inside COM, chapter 7)
  110. //
  111. //
  112. //-----------------------------------------------------------------------------
  113. HRESULT CICWISPData::QueryInterface( REFIID riid, void** ppv )
  114. {
  115. TraceMsg(TF_CWEBVIEW, "CICWISPData::QueryInterface");
  116. if (ppv == NULL)
  117. return(E_INVALIDARG);
  118. *ppv = NULL;
  119. // IID_IICWISPData
  120. if (IID_IICWISPData == riid)
  121. *ppv = (void *)(IICWISPData *)this;
  122. // IID_IUnknown
  123. else if (IID_IUnknown == riid)
  124. *ppv = (void *)this;
  125. else
  126. return(E_NOINTERFACE);
  127. ((LPUNKNOWN)*ppv)->AddRef();
  128. return(S_OK);
  129. }
  130. //+----------------------------------------------------------------------------
  131. //
  132. // Function CICWISPData::AddRef
  133. //
  134. // Synopsis This is the standard AddRef
  135. //
  136. //
  137. //-----------------------------------------------------------------------------
  138. ULONG CICWISPData::AddRef( void )
  139. {
  140. TraceMsg(TF_CWEBVIEW, "CICWISPData::AddRef %d", m_lRefCount + 1);
  141. return InterlockedIncrement(&m_lRefCount) ;
  142. }
  143. //+----------------------------------------------------------------------------
  144. //
  145. // Function CICWISPData::Release
  146. //
  147. // Synopsis This is the standard Release
  148. //
  149. //
  150. //-----------------------------------------------------------------------------
  151. ULONG CICWISPData::Release( void )
  152. {
  153. ASSERT( m_lRefCount > 0 );
  154. InterlockedDecrement(&m_lRefCount);
  155. TraceMsg(TF_CWEBVIEW, "CICWISPData::Release %d", m_lRefCount);
  156. if( 0 == m_lRefCount )
  157. {
  158. if (NULL != m_pServer)
  159. m_pServer->ObjectsDown();
  160. delete this;
  161. return 0;
  162. }
  163. return( m_lRefCount );
  164. }
  165. BOOL CICWISPData::PutDataElement
  166. (
  167. WORD wElement,
  168. LPCTSTR lpValue,
  169. WORD wValidateLevel
  170. )
  171. {
  172. ASSERT(wElement < ISPDATAELEMENTS_LEN);
  173. BOOL bValid = TRUE;
  174. LPISPDATAELEMENT lpElement = &m_ISPDataElements[wElement];
  175. ASSERT(lpElement);
  176. if (wValidateLevel > ISPDATA_Validate_None)
  177. {
  178. // See if we even need to validate. A validateflag of 0 means we always validate
  179. if ((0 == lpElement->dwValidateFlag) || m_dwValidationFlags & lpElement->dwValidateFlag)
  180. {
  181. // process based on validation level
  182. switch (wValidateLevel)
  183. {
  184. case ISPDATA_Validate_DataPresent:
  185. {
  186. bValid = IsValid(lpValue, m_hWndParent, lpElement->wValidateNameID);
  187. break;
  188. }
  189. case ISPDATA_Validate_Content:
  190. {
  191. bValid = bValidateContent(lpElement->idContentValidator, lpValue);
  192. break;
  193. }
  194. }
  195. }
  196. }
  197. // If the element is valid, then store it.
  198. if (bValid)
  199. {
  200. // If this elemement has been previously set the free it
  201. if (lpElement->lpQueryElementValue)
  202. free(lpElement->lpQueryElementValue);
  203. // lpValue can be NULL
  204. if (lpValue)
  205. lpElement->lpQueryElementValue = _tcsdup(lpValue);
  206. else
  207. lpElement->lpQueryElementValue = NULL;
  208. }
  209. return (bValid);
  210. }
  211. // This funtion will form the query string to be sent to the ISP signup server
  212. //
  213. HRESULT CICWISPData::GetQueryString
  214. (
  215. BSTR bstrBaseURL,
  216. BSTR *lpReturnURL
  217. )
  218. {
  219. LPTSTR lpWorkingURL;
  220. WORD cbBuffer = 0;
  221. LPISPDATAELEMENT lpElement;
  222. LPTSTR lpszBaseURL = W2A(bstrBaseURL);
  223. int i;
  224. ASSERT(lpReturnURL);
  225. if (!lpReturnURL)
  226. return E_FAIL;
  227. // Calculate how big of a buffer we will need
  228. cbBuffer += (WORD)lstrlen(lpszBaseURL);
  229. cbBuffer += 1; // For the & or the ?
  230. for (i = 0; i < ISPDATAELEMENTS_LEN; i ++)
  231. {
  232. lpElement = &m_ISPDataElements[i];
  233. ASSERT(lpElement);
  234. if (lpElement->lpQueryElementName)
  235. {
  236. cbBuffer += (WORD)lstrlen(lpElement->lpQueryElementName);
  237. cbBuffer += (WORD)lstrlen(lpElement->lpQueryElementValue) * 3; // *3 for encoding
  238. cbBuffer += 3; // For the = and & and the terminator (because we copy
  239. // lpQueryElementValue into a new buffer for encoding
  240. }
  241. else
  242. {
  243. cbBuffer += (WORD)lstrlen(lpElement->lpQueryElementValue);
  244. cbBuffer += 1; // for the trailing &
  245. }
  246. }
  247. cbBuffer += 1; // Terminator
  248. // Allocate a buffer large enough
  249. if (NULL == (lpWorkingURL = (LPTSTR)GlobalAllocPtr(GPTR, sizeof(TCHAR)*cbBuffer)))
  250. return E_FAIL;
  251. lstrcpy(lpWorkingURL, lpszBaseURL);
  252. // See if this ISP provided URL is already a Query String.
  253. if (NULL != _tcschr(lpWorkingURL, TEXT('?')))
  254. lstrcat(lpWorkingURL, cszAmpersand); // Append our params
  255. else
  256. lstrcat(lpWorkingURL, cszQuestion); // Start with our params
  257. for (i = 0; i < ISPDATAELEMENTS_LEN; i ++)
  258. {
  259. lpElement = &m_ISPDataElements[i];
  260. ASSERT(lpElement);
  261. if (lpElement->lpQueryElementName)
  262. {
  263. // If there is a query value, then encode it
  264. if (lpElement->lpQueryElementValue)
  265. {
  266. // Allocate a buffer to encode into
  267. size_t size = (sizeof(TCHAR)* lstrlen(lpElement->lpQueryElementValue))*3;
  268. LPTSTR lpszVal = (LPTSTR) malloc(size+sizeof(TCHAR));
  269. //
  270. // If allocation fails, the error is ignored. The URL may
  271. // or may not work.
  272. //
  273. if (lpszVal)
  274. {
  275. lstrcpy(lpszVal, lpElement->lpQueryElementValue);
  276. URLEncode(lpszVal, size);
  277. URLAppendQueryPair(lpWorkingURL,
  278. (LPTSTR)lpElement->lpQueryElementName,
  279. lpszVal);
  280. free(lpszVal);
  281. }
  282. }
  283. else
  284. {
  285. URLAppendQueryPair(lpWorkingURL,
  286. (LPTSTR)lpElement->lpQueryElementName,
  287. NULL);
  288. }
  289. }
  290. else
  291. {
  292. if (lpElement->lpQueryElementValue)
  293. {
  294. lstrcat(lpWorkingURL, lpElement->lpQueryElementValue);
  295. lstrcat(lpWorkingURL, cszAmpersand);
  296. }
  297. }
  298. }
  299. // Terminate the working URL properly, by removing the trailing ampersand
  300. lpWorkingURL[lstrlen(lpWorkingURL)-1] = '\0';
  301. // Set the return VALUE. We must allocate here, since the caller will free
  302. // this returned string, and A2W only puts the string in the stack
  303. *lpReturnURL = SysAllocString(A2W(lpWorkingURL));
  304. // Free the buffer
  305. GlobalFreePtr(lpWorkingURL);
  306. return (S_OK);
  307. }
  308. // Dispatch functioin to handle content specific validation
  309. BOOL CICWISPData::bValidateContent
  310. (
  311. WORD wFunctionID,
  312. LPCTSTR lpData
  313. )
  314. {
  315. BOOL bValid = FALSE;
  316. switch (wFunctionID)
  317. {
  318. case ValidateCCNumber:
  319. bValid = validate_cardnum(m_hWndParent, lpData);
  320. break;
  321. case ValidateCCExpire:
  322. {
  323. int iMonth = _ttoi(m_ISPDataElements[ISPDATA_PAYMENT_EXMONTH].lpQueryElementValue);
  324. int iYear = _ttoi(lpData);
  325. bValid = validate_cardexpdate(m_hWndParent, iMonth, iYear);
  326. //Because of Y2K we are going to work with this pointer
  327. //we will assume year is 5 char in len
  328. if (bValid)
  329. {
  330. TCHAR szY2KYear [3] = TEXT("\0");
  331. ASSERT(lstrlen(lpData) == 5);
  332. lstrcpyn(szY2KYear, lpData + 2, 3);
  333. lstrcpy((TCHAR*)lpData, szY2KYear);
  334. }
  335. }
  336. }
  337. return bValid;
  338. }