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.

928 lines
25 KiB

  1. //
  2. // File : DCONV.CPP
  3. // Date : 04/25/97
  4. // Author : Suresh Krishnan
  5. // This file has modules responsible for making the buffer data to be transmitted to the IIS
  6. //
  7. // MDF 1 : 05/07/97 Modified the Table as per StevBush modifications in the BackEnd
  8. // MFD 2 : 03/03/97 Added Division Name and UserID for FE screens
  9. // Phone number will be prefixed with Area Code
  10. // MFD3 : 04/29/98 Added additional 4 fileds to be sent to the backend as a part of
  11. // Taxanomy Screen changes.
  12. // Fields risen from 60 to 64. Fileds added
  13. // SoftwareRole,InfluenceLevel,EngagementLevel,SkillLevel
  14. // MFD4 : 07/21/98 Additional 2 fields to be sent to the backend SCSIAdapter
  15. // and ComputerManufacturer & Model of SystemInventory
  16. // MFD5 : 08/1/98 The MathCoprocessor and Color Depth are no longer necessary to be sent to the back end
  17. // so the items that are sent to the back end are 66-2 = 64
  18. // MFD6 : 08/21/98 Added AreaCode and MiddleName( Middle Initial) fo posting
  19. // So number of Fields for posting 64+2 = 66
  20. // From now on Area code will be sent as a seperate field to the backend
  21. // the logic involved in prefixing with phone number will be removed
  22. //
  23. // MFD7 : 03/10/99 HWID no longer will be Transmitted to the Backend
  24. // Total Entries to Backend 65
  25. //
  26. //
  27. #include <mbstring.h>
  28. #include "RW_Common.h"
  29. #include "resource.h"
  30. #include <tchar.h>
  31. #include "dconv.h"
  32. #include "cntryinf.h"
  33. #include "RegWizMain.h"
  34. extern BOOL bOemDllLoaded;
  35. extern HINSTANCE hOemDll;
  36. #define NAME_VALUE_SEPERATOR _T("=") // Seperator between name and its value
  37. #define NAME_SEPERATOR _T("&") // Seperator between the names
  38. #define RW_BLANK _T(' ') // The padding character
  39. #define RW_WITH_URL 1
  40. #define PHONE_NUMBER_SEPERATOR _T("-")
  41. #define MAX_NAME_LENGTH 64 // The Max size of the of the name field
  42. #define VARIABLE_LEN -2
  43. #define REG_SEPERATOR TEXT("\\")
  44. #define MAX_TBL_ENTRIES 65 // No of name fields to be sent to the IIS
  45. #define MAX_REG_VAL_BUF_SZ 300 // The Maximum size of a value associated with name field
  46. #define STRCONVERT_MAXLEN 1024
  47. static TCHAR * GetNameString ( TCHAR **pRet,UINT iId,HINSTANCE hIns) ;
  48. int GetRootOfRegWizRegistry(HINSTANCE hInstance , PHKEY phKey);
  49. #ifdef _UNICODE
  50. char* ConvertToMB (TCHAR * szW)
  51. {
  52. static char achA[STRCONVERT_MAXLEN];
  53. WideCharToMultiByte(CP_ACP, 0, szW, -1, achA, STRCONVERT_MAXLEN, NULL, NULL);
  54. return achA;
  55. }
  56. #else
  57. char* ConvertToMB (TCHAR * szW)
  58. {
  59. return szW;
  60. }
  61. #endif
  62. // Information processig functions
  63. void RW_Dummy (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  64. {
  65. };
  66. void RW_LanguageTranslate (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  67. {
  68. LANGID langID = GetSystemDefaultLangID();
  69. VerLanguageName(langID,tcDes,MAX_REG_VAL_BUF_SZ);
  70. }
  71. void RW_CreateDateProcess (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  72. {
  73. };
  74. void RW_RegisterDateProcess (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  75. {
  76. };
  77. void RW_MailingAddressProcess (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  78. {
  79. size_t iSrcLen = _tcslen(tcSrc);
  80. if(iSrcLen)
  81. {
  82. _tcscpy(tcDes,TEXT("1"));
  83. }
  84. else
  85. {
  86. _tcscpy(tcDes,TEXT("2"));
  87. }
  88. }
  89. void RW_ValidateTapiCountryCode (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  90. {
  91. DWORD dwTapiCntryId;
  92. DWORD dwCode = _ttol(tcSrc);
  93. dwTapiCntryId = gTapiCountryTable.GetTapiIDForTheCountryIndex(dwCode);
  94. _stprintf(tcDes,_T("%d"),dwTapiCntryId);
  95. };
  96. void RW_TranslateCountryCode(_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  97. {
  98. DWORD dwCode = _ttol(tcSrc); // Convert the Current code in string to long
  99. _tcscpy(tcDes, gTapiCountryTable.GetCountryName(dwCode));
  100. }
  101. void RW_ParsePhoneNumber(_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  102. {
  103. HKEY hKey;
  104. DWORD infoSize;
  105. TCHAR szR[48];
  106. TCHAR szParam[256];
  107. LONG lRegStatus;
  108. TCHAR szInBuf[256];
  109. //
  110. // As a part of FE screen changes it is necessary to Prefix the Area code
  111. // before the phone number
  112. hKey = NULL;
  113. if(GetRootOfRegWizRegistry(hIns, &hKey) ) {
  114. return;
  115. // Not able to open the Registry Tree for Area Code
  116. // so simply return ...
  117. }
  118. infoSize = 48;
  119. LoadString( hIns, IDS_AREACODE_KEY,
  120. szR,
  121. sizeof(szR)/ sizeof (TCHAR));
  122. lRegStatus = RegQueryValueEx(hKey,&szR[1],NULL,0,(LPBYTE)szParam,&infoSize);
  123. if(tcSrc[0] != _T('\0')){
  124. _tcscpy(szInBuf,tcSrc);
  125. }else {
  126. szInBuf[0] = _T('\0');
  127. }
  128. if (lRegStatus != ERROR_SUCCESS){
  129. return; // RWZ_INVALID_INFORMATION;
  130. }else {
  131. if(szParam[0] != _T('\0')) {
  132. _tcscpy(tcDes,szParam); // Area Code
  133. _tcscat(tcDes,PHONE_NUMBER_SEPERATOR); // Separator
  134. _tcscat(tcDes,szInBuf);
  135. }else {
  136. //No need to do any thing
  137. ;
  138. }
  139. if(hKey)
  140. RegCloseKey(hKey);
  141. }
  142. }
  143. void RW_PrcsProductId (LPTSTR tcSrc, LPTSTR tcDes , HINSTANCE hIns )
  144. {
  145. _TCHAR seps[] = _T("-");
  146. LPTSTR token;
  147. LPTSTR buf;
  148. if (*tcSrc == 0 )
  149. {
  150. *tcDes=0;
  151. return;
  152. }
  153. buf = new _TCHAR[_tcslen(tcSrc) * sizeof(_TCHAR) +sizeof(_TCHAR)];
  154. if (buf)
  155. {
  156. token = _tcstok( tcSrc, seps );
  157. _tcscpy(buf,token);
  158. token = _tcstok( NULL, seps );
  159. while( token != NULL )
  160. {
  161. /* Get next token: */
  162. _tcscat(buf,token);
  163. token = _tcstok( NULL, seps );
  164. }
  165. _tcscpy(tcDes,buf);
  166. delete[] buf;
  167. }
  168. };
  169. //
  170. // void RW_ParseTotalSize (_TCHAR * tcSrc, _TCHAR * tcDes )
  171. // This function retrives the the Size wich is founs as the first token in tcSrc
  172. // After the end of this function the tcDes will be assiged with the Size
  173. //
  174. void RW_ParseTotalSize (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  175. {
  176. int isBlankPassed=0;
  177. TCHAR tcSteps[] = TEXT(" ,\t\n");
  178. if(*tcSrc == 0 )
  179. {
  180. *tcDes=0;
  181. return;
  182. }
  183. // since the value in tcSrc is "RAM UNIT" so it is encouh if is pass only the first word
  184. TCHAR *tcToken;
  185. tcToken =_tcstok(tcSrc, tcSteps);
  186. _tcscpy(tcDes,tcToken);
  187. }
  188. //
  189. // void RW_ParseUnits (_TCHAR * tcSrc, _TCHAR * tcDes )
  190. // This function retrives the the unit name wich is founs as the second token in tcSrc
  191. // After the end of this function the tcDes will be assiged with the Units
  192. //
  193. void RW_ParseUnits (_TCHAR * tcSrc, _TCHAR * tcDes , HINSTANCE hIns )
  194. {
  195. int isBlankPassed=0;
  196. TCHAR tcSteps[] = TEXT(" ,\t\n\0");
  197. if(*tcSrc == 0 )
  198. {
  199. *tcDes=0;
  200. return;
  201. }
  202. // since the value in tcSrc is "RAM UNIT" so it is encouh if is pass only the first word
  203. TCHAR *tcToken;
  204. tcToken =_tcstok(tcSrc, tcSteps); // get the size
  205. tcToken = _tcstok( NULL, tcSteps); // get the units
  206. _tcscpy(tcDes,tcToken);
  207. }
  208. //
  209. // RegWizInfoDetails
  210. // This structure is used to create a table which has the Namefiled,
  211. // the value reference in the Resource which is to be used to retrive from registry
  212. // and Function to process the value
  213. //
  214. typedef struct RegWizInfoDetails
  215. {
  216. int m_iIndex;
  217. TCHAR m_czName[MAX_NAME_LENGTH];
  218. int m_iLen;
  219. int m_ResourceIndex;
  220. int m_iParam;
  221. void (*m_fp)(_TCHAR * tcSrc, _TCHAR * tcDes, HINSTANCE hIns);
  222. } _RegWizInfoDetails ;
  223. static RegWizInfoDetails sRegWizInfoTbl[MAX_TBL_ENTRIES] =
  224. {
  225. { 1, _T("RegWizVer") ,8, IDS_INFOKEY30, 0, RW_Dummy },
  226. { 2, _T("CodePage") ,5, -1 , 0, RW_Dummy },
  227. { 3, _T("LangCode") ,5, IDS_INFOKEY34 , 0, RW_Dummy },
  228. { 4, _T("LangName") ,30, IDS_INFOKEY34 , 0, RW_LanguageTranslate },
  229. { 5, _T("CreatedDate") ,10, -1 , 0, RW_CreateDateProcess },
  230. { 6, _T("RegDate") ,10, IDS_INFOKEY33, 0, RW_RegisterDateProcess },
  231. { 7, _T("FName") ,VARIABLE_LEN, IDS_INFOKEY1 , 0, RW_Dummy },
  232. { 8, _T("LName") ,VARIABLE_LEN, IDS_INFOKEY2 , 0, RW_Dummy },
  233. { 9, _T("CompanyName") ,VARIABLE_LEN, IDS_INFOKEY3, 0, RW_Dummy },
  234. { 10, _T("AddrType") ,1, IDS_INFOKEY3, 0, RW_MailingAddressProcess },
  235. { 11, _T("Addr1") ,VARIABLE_LEN , IDS_INFOKEY4, 0, RW_Dummy },
  236. { 12, _T("Addr2") ,VARIABLE_LEN, IDS_INFOKEY5, 0, RW_Dummy },
  237. { 13, _T("City") ,VARIABLE_LEN, IDS_INFOKEY6, 0, RW_Dummy },
  238. { 14, _T("State") ,VARIABLE_LEN , IDS_INFOKEY7, 0, RW_Dummy },
  239. { 15, _T("Zip") ,VARIABLE_LEN , IDS_INFOKEY8, 0, RW_Dummy },
  240. { 16, _T("CountryCode") ,4 , IDS_INFOKEY9 , 0, RW_ValidateTapiCountryCode },
  241. { 17, _T("Country") ,60, IDS_INFOKEY9 , 0, RW_TranslateCountryCode },
  242. { 18, _T("Phone") ,VARIABLE_LEN , IDS_INFOKEY10, 0, RW_Dummy },
  243. { 19, _T("NoOther") ,1 , IDS_INFOKEY11, 0, RW_Dummy },
  244. { 20, _T("Product") ,255, IDS_INFOKEY28, 0, RW_Dummy },
  245. { 21, _T("PID") ,20, IDS_INFOKEY12, 0, RW_PrcsProductId },
  246. { 22, _T("OEM") ,255 , IDS_INFOKEY29, 0, RW_Dummy },
  247. { 23, _T("SysInv") ,1, IDS_INFOKEY26, 0, RW_Dummy },
  248. { 24, _T("OS") ,40, IDS_INFOKEY25, 0, RW_Dummy },
  249. { 25, _T("CPU") ,20 , IDS_INFOKEY13, 0, RW_Dummy },
  250. //{ 26, _T("MathCo") ,1 , IDS_INFOKEY14, 0, RW_Dummy },
  251. { 27, _T("TotalRAM") ,8 , IDS_INFOKEY15, 0, RW_ParseTotalSize},
  252. { 28, _T("RAMUnits") ,2 , IDS_INFOKEY15, 0, RW_ParseUnits},
  253. { 29, _T("TotalDisk") ,8 , IDS_INFOKEY16, 0, RW_ParseTotalSize},
  254. { 30, _T("DiskUnits") ,2 , IDS_INFOKEY16, 0, RW_ParseUnits},
  255. { 31, _T("RemoveableMedia") ,60 , IDS_INFOKEY17, 0, RW_Dummy },
  256. //{ 32, _T("DisplayRes") ,16 , IDS_INFOKEY18 , 0, RW_Dummy },
  257. { 33, _T("DisplayColorDepth") ,8 , IDS_INFOKEY19 , 0, RW_Dummy },
  258. { 34, _T("PointingDevice") ,75, IDS_INFOKEY20 , 0, RW_Dummy },
  259. { 35, _T("Network") ,75 , IDS_INFOKEY21 , 0, RW_Dummy },
  260. { 36, _T("Modem") ,75 , IDS_INFOKEY22 , 0, RW_Dummy },
  261. { 37, _T("Sound") ,60 , IDS_INFOKEY23 , 0, RW_Dummy },
  262. { 38, _T("CDROM") ,40 , IDS_INFOKEY24 , 0, RW_Dummy },
  263. { 39, _T("ProdInv") ,1 , IDS_INFOKEY27 , 0, RW_Dummy },
  264. { 40, _T("InvProd1") ,75, IDS_PRODUCTBASEKEY, 1, RW_Dummy },
  265. { 41, _T("InvProd2") ,75, IDS_PRODUCTBASEKEY, 2, RW_Dummy },
  266. { 42, _T("InvProd3") ,75, IDS_PRODUCTBASEKEY, 3, RW_Dummy },
  267. { 43, _T("InvProd4") ,75, IDS_PRODUCTBASEKEY, 4, RW_Dummy },
  268. { 44, _T("InvProd5") ,75, IDS_PRODUCTBASEKEY, 5, RW_Dummy },
  269. { 45, _T("InvProd6") ,75, IDS_PRODUCTBASEKEY, 6, RW_Dummy },
  270. { 46, _T("InvProd7") ,75, IDS_PRODUCTBASEKEY, 7, RW_Dummy },
  271. { 47, _T("InvProd8") ,75, IDS_PRODUCTBASEKEY, 8, RW_Dummy },
  272. { 48, _T("InvProd9") ,75, IDS_PRODUCTBASEKEY, 9, RW_Dummy },
  273. { 49, _T("InvProd10") ,75, IDS_PRODUCTBASEKEY, 10,RW_Dummy },
  274. { 50, _T("InvProd11") ,75, IDS_PRODUCTBASEKEY, 11,RW_Dummy },
  275. { 51, _T("InvProd12") ,75, IDS_PRODUCTBASEKEY, 12,RW_Dummy },
  276. { 52, _T("EmailName") ,50, IDS_INFOKEY35, 0, RW_Dummy },
  277. { 53, _T("Reseller") ,30, IDS_INFOKEY36, 0, RW_Dummy },
  278. { 54, _T("ResellerCity") ,20, IDS_INFOKEY37, 0, RW_Dummy },
  279. { 55, _T("ResellerState") ,3, IDS_INFOKEY38, 0, RW_Dummy },
  280. //{ 56, _T("HWID") ,32, IDS_INFOKEY39, 0, RW_Dummy },
  281. { 57, _T("MSID") ,32, IDS_INFOKEY40, 0, RW_Dummy },
  282. { 58, _T("Extension") ,32, IDS_INFOKEY41, 0, RW_Dummy },
  283. { 59, _T("DivisionName") ,50, IDS_DIVISIONNAME_KEY, 0, RW_Dummy },
  284. { 60, _T("UserID") ,50, IDS_USERID_KEY, 0, RW_Dummy },
  285. { 61, _T("SoftwareRole") ,2, IDS_BUSINESSQ1, 0, RW_Dummy },
  286. { 62, _T("InfluenceLevel") ,2, IDS_HOMEQ1, 0, RW_Dummy },
  287. { 63, _T("EngagementLevel") ,2, IDS_HOMEQ2, 0, RW_Dummy },
  288. { 64, _T("SkillLevel") ,2, IDS_HOMEQ3, 0, RW_Dummy },
  289. { 65, _T("SCSIAdapter") ,75, IDS_SCSI_ADAPTER, 0, RW_Dummy },
  290. { 66, _T("ComputerManf") ,256, IDS_COMPUTER_MODEL, 0, RW_Dummy },
  291. { 67, _T("AreaCode") ,30, IDS_AREACODE_KEY, 0, RW_Dummy },
  292. { 68, _T("Mname") ,75, IDS_MIDDLE_NAME, 0, RW_Dummy }
  293. };
  294. //
  295. // PadWithBlanks(TCHAR **pSrc, TCHAR ** pDes,int iLen)
  296. //
  297. // This function adds space to the soiurce string so the resultant string is of the length
  298. // specified by iLen
  299. //
  300. //
  301. //
  302. void PadWithBlanks(TCHAR *pSrc, TCHAR * pDes,int iLen)
  303. {
  304. int iSrcLen;
  305. iSrcLen = _tcslen(pSrc) * sizeof(_TCHAR);
  306. if(iLen < 0)
  307. {
  308. // if it is variable length then copy the string and return
  309. _tcscpy(pDes,pSrc);
  310. return;
  311. }
  312. //
  313. // Try to copy till iLen
  314. // the extra +1 is added to add a null terminator after copy
  315. _tcsnccpy(pDes,pSrc,iLen+ sizeof(_TCHAR));
  316. if(iSrcLen < iLen )
  317. {
  318. // the source string is less than the expected maximum length
  319. for(int iIndex = iSrcLen;iIndex < iLen;iIndex++)
  320. {
  321. pDes[iIndex] = RW_BLANK; // Adds blank
  322. }
  323. pDes[iIndex] = _T('\0');
  324. }
  325. }
  326. // int GetRootOfRegWizRegistry(HINSTANCE hInstance , PHKEY phKey)
  327. //
  328. // Description :
  329. // This function Opens the User Information value in the registry for
  330. // regWizard configured values to be read
  331. //
  332. // Return Information:
  333. // This function return the HANDLE of the registry in phKey and returns 0
  334. // If the Key is not found the function returns 1
  335. //
  336. //
  337. int GetRootOfRegWizRegistry(HINSTANCE hInstance , PHKEY phKey)
  338. {
  339. TCHAR uszPartialKey[128];
  340. TCHAR uszRegKey[128];
  341. uszRegKey[0] = _T('\0');
  342. int resSize = LoadString(hInstance,IDS_KEY2,uszRegKey,128);
  343. _tcscat(uszRegKey,REG_SEPERATOR);
  344. resSize = LoadString(hInstance,IDS_KEY3,uszPartialKey,128);
  345. _tcscat(uszRegKey,uszPartialKey);
  346. _tcscat(uszRegKey,REG_SEPERATOR);
  347. resSize = LoadString(hInstance,IDS_KEY4,uszPartialKey,128);
  348. _tcscat(uszRegKey,uszPartialKey);
  349. #ifdef USE_INFO_SUBKEYS
  350. _tcscat(uszRegKey,REG_SEPERATOR);
  351. #endif
  352. LONG regStatus =RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  353. uszRegKey,
  354. 0,
  355. KEY_ALL_ACCESS,
  356. phKey);
  357. if (regStatus != ERROR_SUCCESS)
  358. {
  359. return 1; // error
  360. }
  361. else
  362. {
  363. return 0; // Success
  364. }
  365. }
  366. //
  367. // TCHAR * GetNameString ( TCHAR **pRet,UINT uId,HINSTANCE hIns)
  368. //
  369. // Description :
  370. //
  371. // This function retrives the Name field for Transmission from the Resource
  372. // Some names in the resouce is prefixed with '_' so this function removes the
  373. // prefix character.
  374. //
  375. // Return Information:
  376. // This function returns NULL if the string is not found in the resource
  377. // It accepts the address of a TCHAR pointer ,the string address is assigned in the
  378. // pointer. It also returns the same address as a return Status
  379. //
  380. // Note :
  381. // It is not required to delete the pointer returned by this function as it is static
  382. //
  383. TCHAR * GetNameString ( TCHAR **pRet,UINT uId,HINSTANCE hIns)
  384. {
  385. static TCHAR tczRetValue[MAX_NAME_LENGTH ];
  386. int iLoad = LoadString( hIns, uId,
  387. tczRetValue,
  388. sizeof(tczRetValue)/ sizeof (TCHAR));
  389. if(!iLoad )
  390. {
  391. pRet = NULL;
  392. return NULL;
  393. }
  394. if( tczRetValue[0] == _T('_') )
  395. {
  396. *pRet = &tczRetValue[1];
  397. return &tczRetValue[1];
  398. }
  399. else
  400. {
  401. *pRet = &tczRetValue[0];
  402. return &tczRetValue[0];
  403. }
  404. }
  405. //
  406. //
  407. // URL Encoding
  408. /*===================================================================
  409. URLEncodeLen
  410. Return the storage requirements for a URL-Encoded string
  411. Parameters:
  412. szSrc - Pointer to the string to URL Encode
  413. Returns:
  414. the number of bytes required to encode the string
  415. ===================================================================*/
  416. int URLEncodeLen(const char *szSrc)
  417. {
  418. int cbURL = 1; // add terminator now
  419. while (*szSrc)
  420. {
  421. if (*szSrc & 0x80) // encode foreign characters
  422. cbURL += 3;
  423. else
  424. if (*szSrc == ' ') // encoded space requires only one character
  425. ++cbURL;
  426. else
  427. if (! isalnum(*szSrc)) // encode non-alphabetic characters
  428. cbURL += 3;
  429. else
  430. ++cbURL;
  431. ++szSrc;
  432. }
  433. return cbURL;
  434. }
  435. /*===================================================================
  436. URLEncode
  437. URL Encode a string by changing space characters to '+' and escaping
  438. non-alphanumeric characters in hex.
  439. Parameters:
  440. szDest - Pointer to the buffer to store the URLEncoded string
  441. szSrc - Pointer to the source buffer
  442. Returns:
  443. A pointer to the NUL terminator is returned.
  444. ===================================================================*/
  445. char *URLEncode(char *szDest, const char *szSrc)
  446. {
  447. char hex[] = "0123456789ABCDEF";
  448. while (*szSrc)
  449. {
  450. if (*szSrc == ' ')
  451. {
  452. *szDest++ = '+';
  453. ++szSrc;
  454. }
  455. else
  456. if (!isalnum(*szSrc) || (*szSrc & 0x80))
  457. {
  458. *szDest++ = '%';
  459. *szDest++ = hex[BYTE(*szSrc) >> 4];
  460. *szDest++ = hex[*szSrc++ & 0x0F];
  461. }
  462. else
  463. *szDest++ = *szSrc++;
  464. }
  465. *szDest = '\0';
  466. return szDest;
  467. }
  468. //
  469. // This class is used to store the RegWiz Info in URL encode format
  470. // This class is construected with the TxBuffer pointer
  471. // The AppendToBuffer converts the string to URL encoded form and adds to the TxBuffer
  472. // if the TxBuffer size is less then it only computesthe size and does not transfer
  473. // the buffer contents
  474. //
  475. class RegWizTxBuffer
  476. {
  477. public :
  478. char *m_pBuf;
  479. int m_iSizeExceeded; // set
  480. DWORD *m_pdInitialSize;
  481. DWORD m_dCurrentIndex;
  482. RegWizTxBuffer(char *tcTxBuf, DWORD * pRetLen)
  483. {
  484. m_pBuf = tcTxBuf; // Initial Pointer of the Destination Buffer
  485. m_pdInitialSize = pRetLen; // The Destination Buffer Size
  486. m_dCurrentIndex = 0; // Current Index of the number of bytes of information transmitted
  487. m_iSizeExceeded = 0;
  488. m_pBuf[0] = '\0';
  489. }
  490. void AppendToBuffer(TCHAR *tcTxBuf, int iIsUrl=0)
  491. {
  492. int iLen=0;
  493. #ifdef _UNICODE
  494. unsigned char *mbpTxBuf;
  495. #endif
  496. // The TxBuffer has to be converted to MultiByte in case
  497. // Convert to MultByte
  498. #ifdef _UNICODE
  499. mbpTxBuf = (unsigned char *)ConvertToMB (tcTxBuf); // Convert to MultiByte
  500. iLen = _mbslen (mbpTxBuf);
  501. #else
  502. iLen = _tcsclen(tcTxBuf);
  503. #endif
  504. if(iIsUrl)
  505. {
  506. #ifdef _UNICODE
  507. iLen= URLEncodeLen((const char *)mbpTxBuf);
  508. #else
  509. iLen = URLEncodeLen(tcTxBuf);
  510. #endif
  511. }
  512. if( m_dCurrentIndex + iLen >= *m_pdInitialSize )
  513. {
  514. // continue counting the lengthn required
  515. m_iSizeExceeded = 1;
  516. }
  517. else
  518. {
  519. if( iIsUrl)
  520. {
  521. #ifdef _UNICODE
  522. URLEncode(m_pBuf+m_dCurrentIndex,(const char *)mbpTxBuf);
  523. #else
  524. // for MBCS and SBCS
  525. URLEncode(m_pBuf+m_dCurrentIndex,tcTxBuf);
  526. #endif
  527. }
  528. else
  529. {
  530. #ifdef _UNICODE
  531. strcat(m_pBuf,(const char *)mbpTxBuf);
  532. #else
  533. _tcscat(m_pBuf,tcTxBuf);
  534. #endif
  535. }
  536. ;
  537. }
  538. if(iIsUrl)
  539. m_dCurrentIndex += iLen-1;
  540. else
  541. m_dCurrentIndex += iLen;
  542. }
  543. int IsValidBuffer()
  544. {
  545. m_pBuf[m_dCurrentIndex] = '\0';
  546. *m_pdInitialSize = m_dCurrentIndex;
  547. return m_iSizeExceeded ;
  548. }
  549. };
  550. int PrepareRegWizTxbuffer(HINSTANCE hIns, char *tcTxBuf, DWORD * pRetLen)
  551. {
  552. int iRetValue;
  553. HKEY hKey;
  554. LONG lRegStatus;
  555. TCHAR *szR;
  556. TCHAR tczTmp[10];
  557. TCHAR szParam[MAX_REG_VAL_BUF_SZ]; // ?? chk in case of Unicode
  558. unsigned long infoSize;
  559. RegWizTxBuffer TxferBuf(tcTxBuf,pRetLen);
  560. iRetValue = RWZ_NOERROR;
  561. infoSize = MAX_REG_VAL_BUF_SZ;
  562. if(GetRootOfRegWizRegistry(hIns, &hKey) )
  563. {
  564. iRetValue = RWZ_NO_INFO_AVAILABLE;
  565. // No User Information is Available So Abort the program
  566. }
  567. else
  568. {
  569. // Process for all the information entries
  570. for(int i =0;i < MAX_TBL_ENTRIES ;i++)
  571. {
  572. infoSize = MAX_REG_VAL_BUF_SZ;
  573. szParam[0] = '\0';
  574. #ifdef _LOG_IN_FILE
  575. RW_DEBUG << "\n" << i+1 << "\t" << ConvertToMB (sRegWizInfoTbl[i].m_czName) << "\t" << flush;
  576. #endif
  577. TxferBuf.AppendToBuffer(sRegWizInfoTbl[i].m_czName,RW_WITH_URL);
  578. TxferBuf.AppendToBuffer(NAME_VALUE_SEPERATOR);
  579. if( sRegWizInfoTbl[i].m_ResourceIndex < 1)
  580. {
  581. // continue processing
  582. }
  583. else
  584. {
  585. if( GetNameString(&szR,sRegWizInfoTbl[i].m_ResourceIndex,hIns ) )
  586. {
  587. if( sRegWizInfoTbl[i].m_iParam )
  588. {
  589. // This block is for appending Product name index
  590. _itot(sRegWizInfoTbl[i].m_iParam,tczTmp,10);
  591. _tcscat(szR,_T(" ")); // add a single blank
  592. _tcscat(szR,tczTmp);
  593. #ifdef _LOG_IN_FILE
  594. RW_DEBUG << ConvertToMB (szR) << "\t";
  595. #endif
  596. }
  597. lRegStatus = RegQueryValueEx(hKey,szR,NULL,0,( LPBYTE ) szParam,&infoSize);
  598. if (lRegStatus != ERROR_SUCCESS)
  599. {
  600. return RWZ_INVALID_INFORMATION;
  601. }
  602. #ifdef _LOG_IN_FILE
  603. RW_DEBUG << "[" <<ConvertToMB (szParam )<< "]\t" << flush;
  604. #endif
  605. }
  606. else
  607. {
  608. //
  609. // This condition can happen if information is not found in the Resource
  610. // If the function entres this block the it is necessary to verify the
  611. // the resource string in the table mapping
  612. //
  613. return RWZ_INTERNAL_ERROR;
  614. }
  615. }
  616. if(szParam)
  617. {
  618. (*sRegWizInfoTbl[i].m_fp)(szParam,szParam,hIns); // Invoke processing Function
  619. //PadWithBlanks(szParam,szRet,sRegWizInfoTbl[i].m_iLen); // Add balnks
  620. }
  621. //TxferBuf.AppendToBuffer(szRet,RW_WITH_URL); with padded
  622. TxferBuf.AppendToBuffer(szParam,RW_WITH_URL);
  623. //
  624. //
  625. // Skip Name key seperator for the last entry
  626. if(i!= MAX_TBL_ENTRIES-1)
  627. TxferBuf.AppendToBuffer(NAME_SEPERATOR);
  628. }// end of for loop
  629. }
  630. if(TxferBuf.IsValidBuffer())
  631. {
  632. iRetValue=RWZ_BUFFER_SIZE_INSUFFICIENT;
  633. }
  634. return iRetValue;
  635. }
  636. DWORD OemTransmitBuffer(HINSTANCE hIns,char *sztxBuffer,DWORD *nInitialSize)
  637. {
  638. BOOL bValueExceeded = FALSE;
  639. if(bOemDllLoaded == TRUE)
  640. {
  641. DWORD nCount,nLen,nCurrentLen = 0;
  642. HKEY hOemKey;
  643. #ifdef _LOG_IN_FILE
  644. RW_DEBUG << "\n OEM: Inside OemTransmitBuffer" << flush;
  645. #endif
  646. GetRootOfRegWizRegistry(hIns, &hOemKey);
  647. OEMDataCount pOEMDataCount;
  648. pOEMDataCount = (OEMDataCount) GetProcAddress(hOemDll, "OEMDataCount");
  649. if (pOEMDataCount == NULL)
  650. {
  651. #ifdef _LOG_IN_FILE
  652. RW_DEBUG << "\n OEM: OEMDataCount Getproc Error" << flush;
  653. #endif
  654. return RWZ_INTERNAL_ERROR;
  655. }
  656. nCount = (DWORD)pOEMDataCount();
  657. if(nCount > 25)
  658. {
  659. nCount = 25;
  660. }
  661. for( DWORD index = 1; index <= nCount; index++ )
  662. {
  663. _TCHAR szOEMValueName[64];
  664. _TCHAR szOEMBase[64];
  665. char szBuffer[1024];
  666. BOOL bIsUnicode;
  667. BYTE lpValue[256] ;
  668. _TCHAR szValue[256];
  669. LoadString(hIns,IDS_OEMBASEKEY,szOEMBase,64);
  670. _stprintf(szOEMValueName,_T("%s_%i"),szOEMBase,index);
  671. #ifdef _UNICODE
  672. strcpy(szBuffer,ConvertToMB(szOEMValueName));
  673. #else
  674. _tcscpy(szBuffer,szOEMValueName);
  675. #endif
  676. OEMGetData pOEMGetData;
  677. pOEMGetData = (OEMGetData) GetProcAddress(hOemDll, "OEMGetData");
  678. if (pOEMGetData == NULL)
  679. {
  680. #ifdef _LOG_IN_FILE
  681. RW_DEBUG << "\n OEM: OEMGetData Getproc Error"<< flush;
  682. #endif
  683. return RWZ_INTERNAL_ERROR;
  684. }
  685. nLen = sizeof(lpValue);
  686. pOEMGetData((WORD)index,&bIsUnicode,lpValue,(WORD)nLen);
  687. #ifdef _UNICODE
  688. if(!bIsUnicode)
  689. {
  690. MultiByteToWideChar(CP_ACP, 0, (LPCSTR)lpValue, -1, (LPTSTR)szValue, 256);
  691. }
  692. else
  693. {
  694. _tcscpy((LPTSTR)szValue,(LPCTSTR)lpValue);
  695. }
  696. #else
  697. if(bIsUnicode)
  698. {
  699. WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)lpValue, -1, (LPTSTR)szValue, 256, NULL, NULL);
  700. }
  701. else
  702. {
  703. _tcscpy((LPTSTR)szValue,(LPCTSTR)lpValue);
  704. }
  705. #endif
  706. if( _tcscmp((LPCTSTR)szValue,_T("")))
  707. {
  708. nLen = strlen("&");
  709. if( nCurrentLen + nLen >= *nInitialSize )
  710. {
  711. bValueExceeded = TRUE;
  712. }
  713. else
  714. {
  715. strcat(sztxBuffer,"&");
  716. }
  717. nCurrentLen += nLen;
  718. nLen = URLEncodeLen(szBuffer);
  719. if( nCurrentLen + nLen >= *nInitialSize )
  720. {
  721. bValueExceeded = TRUE;
  722. }
  723. else
  724. {
  725. URLEncode(sztxBuffer+nCurrentLen,szBuffer);
  726. }
  727. nCurrentLen += nLen-1;
  728. RegSetValueEx(hOemKey,szOEMValueName,NULL,REG_SZ,(CONST BYTE *)szValue,_tcslen((LPCTSTR)szValue));
  729. if(bIsUnicode)
  730. {
  731. strcpy(szBuffer,ConvertToMB((TCHAR *)lpValue));
  732. }
  733. else
  734. {
  735. strcpy(szBuffer,(char *)lpValue);
  736. }
  737. #ifdef _LOG_IN_FILE
  738. RW_DEBUG << "\n OEM " << index << "\t"<< ConvertToMB(szOEMValueName)<< "\t"
  739. << szBuffer <<flush;
  740. #endif
  741. nLen = strlen("=");
  742. if( nCurrentLen + nLen >= *nInitialSize )
  743. {
  744. bValueExceeded = TRUE;
  745. }
  746. else
  747. {
  748. strcat(sztxBuffer,"=");
  749. }
  750. nCurrentLen += nLen;
  751. nLen = URLEncodeLen(szBuffer);
  752. if( nCurrentLen + nLen >= *nInitialSize )
  753. {
  754. #ifdef _LOG_IN_FILE
  755. RW_DEBUG << "\n OEM:Buffer value Exceeded" << flush;
  756. RW_DEBUG << "\n OEM:Current Length:" << nCurrentLen << flush;
  757. RW_DEBUG << "\n OEM:Length of present value:" << nLen << flush;
  758. RW_DEBUG << "\n OEM:Initial Size:" << *nInitialSize << flush;
  759. #endif
  760. bValueExceeded = TRUE;
  761. }
  762. else
  763. {
  764. URLEncode(sztxBuffer+nCurrentLen,szBuffer);
  765. }
  766. nCurrentLen += nLen-1;
  767. }
  768. }
  769. *nInitialSize = nCurrentLen;
  770. if(bValueExceeded )
  771. {
  772. return RWZ_BUFFER_SIZE_INSUFFICIENT;
  773. }
  774. else
  775. {
  776. #ifdef _LOG_IN_FILE
  777. RW_DEBUG << "\n OEM: OemTransmitBuffer Successful" << flush;
  778. #endif
  779. return RWZ_NOERROR;
  780. }
  781. }
  782. else
  783. {
  784. *nInitialSize = 0;
  785. }
  786. #ifdef _LOG_IN_FILE
  787. RW_DEBUG << "\n OEM: OemTransmitBuffer Successful" << flush;
  788. #endif
  789. return RWZ_NOERROR;
  790. }