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.

188 lines
6.0 KiB

  1. //*********************************************************************
  2. //* Microsoft Windows **
  3. //* Copyright(c) Microsoft Corp., 1994 **
  4. //*********************************************************************
  5. #include "pre.h"
  6. extern CHAR szTempBuffer[];
  7. const CHAR cszLUHN[] = "LUHN";
  8. const CHAR cszCustURL[] = "CustURL";
  9. #define ReadVerifyW(x) if (!ReadW(&(x),pcCSVFile)) \
  10. { \
  11. AssertMsg(0,"Invalid WORD in CSV file"); \
  12. goto PAYCSVReadOneLineError; \
  13. }
  14. #define ReadVerifyBOOL(x) if (!ReadBOOL(&(x),pcCSVFile)) \
  15. { \
  16. AssertMsg(0,"Invalid BOOL in CSV file"); \
  17. goto PAYCSVReadOneLineError; \
  18. }
  19. #define ReadVerifySZ(x,y) if (!ReadSZ(&x[0],y+sizeof('\0'),pcCSVFile)) \
  20. { \
  21. AssertMsg(0,"Invalid STRING in CSV file"); \
  22. goto PAYCSVReadOneLineError; \
  23. }
  24. // Do an strip of Single Quotes from a source string. The source is formatted as:
  25. // 'some text', and the dest string ends up being
  26. // some text
  27. void CPAYCSV::StripQuotes
  28. (
  29. LPSTR lpszDst,
  30. LPSTR lpszSrc
  31. )
  32. {
  33. //lstrcpyn(lpszDst, lpszSrc + 1, lstrlen(lpszSrc) - 1);
  34. strcpy(lpszDst, lpszSrc + 1);
  35. lpszDst[strlen(lpszDst) - 1] = '\0';
  36. }
  37. // ############################################################################
  38. BOOL CPAYCSV::ReadW(WORD far *pw, CCSVFile far *pcCSVFile)
  39. {
  40. if (!pcCSVFile->ReadToken(szTempBuffer,TEMP_BUFFER_LENGTH))
  41. return FALSE;
  42. return (FSz2W(szTempBuffer,pw));
  43. }
  44. // ############################################################################
  45. BOOL CPAYCSV::ReadBOOL(BOOL far *pbool, CCSVFile far *pcCSVFile)
  46. {
  47. if (!pcCSVFile->ReadToken(szTempBuffer,TEMP_BUFFER_LENGTH))
  48. return FALSE;
  49. return (FSz2BOOL(szTempBuffer,pbool));
  50. }
  51. // ############################################################################
  52. BOOL CPAYCSV::ReadSZ(LPSTR psz, DWORD dwSize, CCSVFile far *pcCSVFile)
  53. {
  54. if (!pcCSVFile->ReadToken(psz,dwSize))
  55. return FALSE;
  56. return TRUE;
  57. }
  58. // ############################################################################
  59. BOOL CPAYCSV::ReadToEOL(CCSVFile far *pcCSVFile)
  60. {
  61. return pcCSVFile->SkipTillEOL();
  62. }
  63. HRESULT CPAYCSV::ReadOneLine
  64. (
  65. CCSVFile far *pcCSVFile,
  66. BOOL bLUHNFormat
  67. )
  68. {
  69. HRESULT hr = ERROR_SUCCESS;
  70. CHAR szTemp[MAX_ISP_NAME] = "\0";
  71. WORD wLUHN;
  72. CHAR szDisplayName[MAX_DISPLAY_NAME] = "\0";
  73. CHAR szCustomPayURLPath[MAX_PATH] = "\0";
  74. if (!ReadSZ(szTemp, MAX_ISP_NAME, pcCSVFile))
  75. {
  76. hr = ERROR_NO_MORE_ITEMS; // no more enteries
  77. goto PAYCSVReadOneLineExit;
  78. }
  79. if ('\0' == *szTemp)
  80. {
  81. hr = ERROR_FILE_NOT_FOUND; // no more enteries
  82. goto PAYCSVReadOneLineExit;
  83. }
  84. // Strip the single quotes from the isp Name
  85. StripQuotes(szDisplayName, szTemp);
  86. #ifdef UNICODE
  87. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szDisplayName, MAX_DISPLAY_NAME, m_szDisplayName, MAX_DISPLAY_NAME);
  88. #else
  89. lstrcpy(m_szDisplayName, szDisplayName);
  90. #endif
  91. ReadVerifyW(m_wPaymentType);
  92. // If this NOT a LUHN format file, then the next field is the payment custom URL
  93. if (!bLUHNFormat)
  94. {
  95. if (ReadSZ(szTemp, MAX_ISP_NAME, pcCSVFile))
  96. {
  97. StripQuotes(szCustomPayURLPath, szTemp);
  98. #ifdef UNICODE
  99. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szCustomPayURLPath, MAX_PATH, m_szCustomPayURLPath, MAX_PATH);
  100. #else
  101. lstrcpy(m_szCustomPayURLPath, szCustomPayURLPath);
  102. #endif
  103. }
  104. else
  105. {
  106. goto PAYCSVReadOneLineError;
  107. }
  108. }
  109. else
  110. {
  111. // BUGBUG: The format of the PAYMENT CSV file is not clear, so I am coding this for
  112. // now to just consume the entry, and move on. Once the format is clarified, and FORBIN
  113. // updated, then the real code can be turned on, which should just be a ReadBOOL, followed
  114. // by the readSZ.
  115. ReadVerifyW(wLUHN);
  116. m_bLUHNCheck = FALSE;
  117. if (wLUHN == (WORD)1)
  118. {
  119. m_bLUHNCheck = TRUE;
  120. }
  121. // There may now also be a URL
  122. if (ReadSZ(szTemp, MAX_ISP_NAME, pcCSVFile))
  123. {
  124. StripQuotes(szCustomPayURLPath, szTemp);
  125. #ifdef UNICODE
  126. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, szCustomPayURLPath, MAX_PATH, m_szCustomPayURLPath, MAX_PATH);
  127. #else
  128. lstrcpy(m_szCustomPayURLPath, szCustomPayURLPath);
  129. #endif
  130. }
  131. }
  132. ReadToEOL(pcCSVFile);
  133. PAYCSVReadOneLineExit:
  134. return hr;
  135. PAYCSVReadOneLineError:
  136. hr = ERROR_INVALID_DATA;
  137. goto PAYCSVReadOneLineExit;
  138. }
  139. HRESULT CPAYCSV::ReadFirstLine
  140. (
  141. CCSVFile far *pcCSVFile,
  142. BOOL far *pbLUHNFormat
  143. )
  144. {
  145. CHAR szTemp[TEMP_BUFFER_LENGTH];
  146. int i = 0;
  147. while (TRUE)
  148. {
  149. if (!ReadSZ(szTemp, TEMP_BUFFER_LENGTH, pcCSVFile))
  150. return(ERROR_INVALID_DATA);
  151. if (_strcmpi(szTemp, cszLUHN) == 0)
  152. *pbLUHNFormat = TRUE;
  153. if (_strcmpi(szTemp, cszCustURL) == 0)
  154. break;
  155. // Safety check
  156. if (i++ > NUM_PAYCSV_FIELDS)
  157. return (ERROR_INVALID_DATA);
  158. }
  159. ReadToEOL(pcCSVFile);
  160. return (ERROR_SUCCESS);
  161. }