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.

272 lines
8.9 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. #include "appdefs.h"
  6. #include "obcomglb.h"
  7. #include "wininet.h"
  8. #include "perhist.h"
  9. #include "shlobj.h"
  10. #include "ispcsv.h"
  11. #include "util.h"
  12. const VARIANT c_vaEmpty = {0};
  13. const LARGE_INTEGER c_li0 = { 0, 0 };
  14. WCHAR szTempBuffer[TEMP_BUFFER_LENGTH];
  15. #define MAX_MESSAGE_LEN 256 * 4
  16. #define ReadVerifyDW(x) if (!ReadDW(&(x), pcCSVFile)) \
  17. { \
  18. goto ReadOneLineError; \
  19. }
  20. #define ReadVerifyW(x) if (!ReadW(&(x), pcCSVFile)) \
  21. { \
  22. goto ReadOneLineError; \
  23. }
  24. //Accepts -1 as a valid number. currently this is used for LCID, since all langs has a LDID == -1
  25. #define ReadVerifyWEx(x) if (!ReadWEx(&(x), pcCSVFile)) \
  26. { \
  27. goto ReadOneLineError; \
  28. }
  29. #define ReadVerifyB(x) if (!ReadB(&(x), pcCSVFile)) \
  30. { \
  31. goto ReadOneLineError; \
  32. }
  33. #define ReadVerifyBOOL(x) if (!ReadBOOL(&(x), pcCSVFile)) \
  34. { \
  35. goto ReadOneLineError; \
  36. }
  37. #define ReadVerifySPECIAL(x, y, z) if (!ReadSPECIAL(&(x), &(y), &(z), pcCSVFile)) \
  38. { \
  39. goto ReadOneLineError; \
  40. }
  41. #define ReadVerifySZ(x, y) if (!ReadSZ(&x[0],y+sizeof(L'\0'),pcCSVFile)) \
  42. { \
  43. goto ReadOneLineError; \
  44. }
  45. CISPCSV::~CISPCSV(void)
  46. {
  47. if (hbmTierIcon)
  48. DeleteObject(hbmTierIcon);
  49. }
  50. // Do an strip of Single Quotes from a source string. The source is formatted as:
  51. // 'some text', and the dest string ends up being
  52. // some text
  53. void CISPCSV::StripQuotes
  54. (
  55. LPWSTR lpszDst,
  56. LPWSTR lpszSrc
  57. )
  58. {
  59. lstrcpyn(lpszDst, lpszSrc + 1, lstrlen(lpszSrc) - 1);
  60. }
  61. BOOL CISPCSV::ValidateFile(WCHAR* pszFile)
  62. {
  63. WCHAR szDownloadDir[MAX_PATH];
  64. if (!lstrlen(pszFile))
  65. return FALSE;
  66. if (!GetOOBEPath((LPWSTR)szDownloadDir))
  67. return FALSE;
  68. lstrcat(szDownloadDir, L"\\");
  69. lstrcat(szDownloadDir, pszFile);
  70. if (GetFileAttributes(szDownloadDir) == 0xFFFFFFFF)
  71. return FALSE;
  72. return TRUE;
  73. }
  74. // ############################################################################
  75. BOOL CISPCSV::ReadDW(DWORD far *pdw, CCSVFile far *pcCSVFile)
  76. {
  77. if (!pcCSVFile->ReadToken(szTempBuffer, TEMP_BUFFER_LENGTH))
  78. return FALSE;
  79. return (FSz2Dw(szTempBuffer, pdw));
  80. }
  81. // ############################################################################
  82. BOOL CISPCSV::ReadW(WORD far *pw, CCSVFile far *pcCSVFile)
  83. {
  84. if (!pcCSVFile->ReadToken(szTempBuffer, TEMP_BUFFER_LENGTH))
  85. return FALSE;
  86. return (FSz2W(szTempBuffer, pw));
  87. }
  88. // ############################################################################
  89. //Accepts -1 as a valid number. currently this is used for LCID, since all langs has a LDID == -1
  90. BOOL CISPCSV::ReadWEx(WORD far *pw, CCSVFile far *pcCSVFile)
  91. {
  92. if (!pcCSVFile->ReadToken(szTempBuffer, TEMP_BUFFER_LENGTH))
  93. return FALSE;
  94. return (FSz2WEx(szTempBuffer, pw));
  95. }
  96. // ############################################################################
  97. BOOL CISPCSV::ReadB(BYTE far *pb, CCSVFile far *pcCSVFile)
  98. {
  99. if (!pcCSVFile->ReadToken(szTempBuffer, TEMP_BUFFER_LENGTH))
  100. return FALSE;
  101. return (FSz2B(szTempBuffer, pb));
  102. }
  103. // ############################################################################
  104. BOOL CISPCSV::ReadBOOL(BOOL far *pbool, CCSVFile far *pcCSVFile)
  105. {
  106. if (!pcCSVFile->ReadToken(szTempBuffer, TEMP_BUFFER_LENGTH))
  107. return FALSE;
  108. return (FSz2BOOL(szTempBuffer, pbool));
  109. }
  110. // ############################################################################
  111. // A special int can be either a BOOL (TRUE, FALSE) or a int, 0 or -1
  112. // if the value is 0 or -1, then the pbIsSpecial bool is set to TRUE
  113. BOOL CISPCSV::ReadSPECIAL(BOOL far *pbool, BOOL far *pbIsSpecial, int far *pInt, CCSVFile far *pcCSVFile)
  114. {
  115. if (!pcCSVFile->ReadToken(szTempBuffer, TEMP_BUFFER_LENGTH))
  116. return FALSE;
  117. return (FSz2SPECIAL(szTempBuffer, pbool, pbIsSpecial, pInt));
  118. }
  119. // ############################################################################
  120. BOOL CISPCSV::ReadSZ(LPWSTR psz, DWORD cch, CCSVFile far *pcCSVFile)
  121. {
  122. if (!pcCSVFile->ReadToken(psz, cch))
  123. return FALSE;
  124. return TRUE;
  125. }
  126. // ############################################################################
  127. BOOL CISPCSV::ReadToEOL(CCSVFile far *pcCSVFile)
  128. {
  129. return pcCSVFile->SkipTillEOL();
  130. }
  131. HRESULT CISPCSV::ReadOneLine
  132. (
  133. CCSVFile far *pcCSVFile
  134. )
  135. {
  136. HRESULT hr = ERROR_SUCCESS;
  137. WCHAR szTemp[MAX_ISP_NAME];
  138. if (!ReadSZ(szTemp, MAX_CHARS_IN_BUFFER(szTemp), pcCSVFile))
  139. {
  140. hr = ERROR_NO_MORE_ITEMS; // no more enteries
  141. goto ReadOneLineExit;
  142. }
  143. // Strip the single quotes from the isp Name
  144. StripQuotes(szISPName, szTemp);
  145. ReadVerifyW(wOfferID);
  146. ReadVerifySZ(szISPLogoPath, MAX_CHARS_IN_BUFFER(szISPLogoPath));
  147. ReadVerifySZ(szISPMarketingHTMPath, MAX_CHARS_IN_BUFFER(szISPMarketingHTMPath));
  148. ReadVerifySZ(szISPTierLogoPath, MAX_CHARS_IN_BUFFER(szISPTierLogoPath));
  149. ReadVerifySZ(szISPTeaserPath, MAX_CHARS_IN_BUFFER(szISPTeaserPath));
  150. ReadVerifySZ(szISPFilePath, MAX_CHARS_IN_BUFFER(szISPFilePath));
  151. ReadVerifyDW(dwCfgFlag);
  152. ReadVerifyDW(dwRequiredUserInputFlags);
  153. ReadVerifySZ(szBillingFormPath, MAX_CHARS_IN_BUFFER(szBillingFormPath));
  154. ReadVerifySZ(szPayCSVPath, MAX_CHARS_IN_BUFFER(szPayCSVPath));
  155. ReadVerifySZ(szOfferGUID, MAX_CHARS_IN_BUFFER(szOfferGUID));
  156. ReadVerifySZ(szMir, MAX_CHARS_IN_BUFFER(szMir));
  157. ReadVerifyWEx(wLCID); //Accepts -1 as a valid number. currently this is used for LCID, since all langs has a LDID == -1
  158. ReadToEOL(pcCSVFile);
  159. bCNS = (ICW_CFGFLAG_CNS & dwCfgFlag) ? TRUE : FALSE;
  160. bSecureConnection = (ICW_CFGFLAG_SECURE & dwCfgFlag) ? TRUE : FALSE;
  161. //If this is nooffer we won't try to validate
  162. if (!(dwCfgFlag & ICW_CFGFLAG_OFFERS))
  163. {
  164. if (!ValidateFile(szISPMarketingHTMPath))
  165. hr = ERROR_FILE_NOT_FOUND;
  166. return hr;
  167. }
  168. if (!(dwCfgFlag & ICW_CFGFLAG_AUTOCONFIG))
  169. {
  170. if (!ValidateFile(szISPMarketingHTMPath))
  171. return ERROR_FILE_NOT_FOUND;
  172. }
  173. if (dwCfgFlag & ICW_CFGFLAG_OEM_SPECIAL)
  174. {
  175. if (!ValidateFile(szISPTierLogoPath) || !ValidateFile(szISPTeaserPath))
  176. dwCfgFlag &= ~ICW_CFGFLAG_OEM_SPECIAL ;
  177. }
  178. //Try and validate the integrity of various offers
  179. //based on type.
  180. //OLS, CNS, NO-CNS
  181. if (!ValidateFile(szISPLogoPath))
  182. return ERROR_FILE_NOT_FOUND;
  183. if (!ValidateFile(szISPFilePath))
  184. return ERROR_FILE_NOT_FOUND;
  185. // Validate the billing path only when billing option is set
  186. if (dwCfgFlag & ICW_CFGFLAG_BILL)
  187. {
  188. if(!ValidateFile(szBillingFormPath))
  189. return ERROR_FILE_NOT_FOUND;
  190. }
  191. // Validate the payment path only when payment option is set
  192. if (dwCfgFlag & ICW_CFGFLAG_PAYMENT)
  193. {
  194. if(!ValidateFile(szPayCSVPath))
  195. return ERROR_FILE_NOT_FOUND;
  196. }
  197. ReadOneLineExit:
  198. return hr;
  199. ReadOneLineError:
  200. hr = ERROR_INVALID_DATA;
  201. goto ReadOneLineExit;
  202. }
  203. HRESULT CISPCSV::ReadFirstLine
  204. (
  205. CCSVFile far *pcCSVFile
  206. )
  207. {
  208. WCHAR szTemp[TEMP_BUFFER_LENGTH];
  209. for (int i = 0; i < NUM_ISPCSV_FIELDS; i++)
  210. {
  211. if (!ReadSZ(szTemp, MAX_CHARS_IN_BUFFER(szTemp), pcCSVFile))
  212. {
  213. return(ERROR_INVALID_DATA);
  214. }
  215. }
  216. ReadToEOL(pcCSVFile);
  217. return (ERROR_SUCCESS);
  218. }
  219. void CISPCSV::MakeCompleteURL(LPWSTR lpszURL, LPWSTR lpszSRC)
  220. {
  221. WCHAR szCurrentDir[MAX_PATH];
  222. // Form the URL
  223. if(GetOOBEPath((LPWSTR)szCurrentDir))
  224. {
  225. wsprintf (lpszURL, L"FILE://%s\\%s", szCurrentDir, lpszSRC);
  226. }
  227. }