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.

1890 lines
54 KiB

  1. //* Microsoft Windows **
  2. //* Copyright(c) Microsoft Corp., 1999 **
  3. //*********************************************************************
  4. //
  5. // MSOBMAIN.CPP - Header for the implementation of CObMain
  6. //
  7. // HISTORY:
  8. //
  9. // 1/27/99 a-jaswed Created.
  10. //
  11. // Class which will provide the an IOleSite to the WebOC
  12. #include "userinfo.h"
  13. #include "appdefs.h"
  14. #include "dispids.h"
  15. #include "windowsx.h"
  16. #include "msobmain.h"
  17. #include "pid.h"
  18. #include "msobmain.h"
  19. #include "resource.h"
  20. #include "shlwapi.h"
  21. #define USER_INFO_INIFILE OEMINFO_INI_FILENAME
  22. #define USER_COMP_MANF_SEC L"General"
  23. #define USER_COMP_MANF_KEY L"Manufacturer"
  24. #define USERINFO_REG_KEY_FIRSTNAME L"FirstName"
  25. #define USERINFO_REG_KEY_MIDDLEINITIAL L"MiddleInitial"
  26. #define USERINFO_REG_KEY_LASTNAME L"LastName"
  27. #define USERINFO_REG_KEY_FURIGANANAME L"FuriganaName"
  28. #define USERINFO_REG_KEY_COMPANYNAME L"CompanyName"
  29. #define USERINFO_REG_KEY_ADDRESS1 L"Address1"
  30. #define USERINFO_REG_KEY_ADDRESS2 L"Address2"
  31. #define USERINFO_REG_KEY_CITY L"City"
  32. #define USERINFO_REG_KEY_STATE L"State"
  33. #define USERINFO_REG_KEY_ZIP L"Zip"
  34. #define USERINFO_REG_KEY_COUNTRY L"Country"
  35. #define USERINFO_REG_KEY_PRIMARYEMAIL L"PrimaryEmail"
  36. #define USERINFO_REG_KEY_SECONDARYEMAIL L"SecondaryEmail"
  37. #define USERINFO_REG_KEY_AREACODE L"AreaCode"
  38. #define USERINFO_REG_KEY_PHONENUMBER L"PhoneNumber"
  39. #define USERINFO_REG_KEY_IDENTITY L"Identity"
  40. #define USERINFO_REG_KEY_OWNERNAME L"OwnerName"
  41. #define USERINFO_REG_KEY_DEFAULTNEWUSER L"DefaultNewUser"
  42. #define DEFAULT_USEIDENTITIES TRUE
  43. DISPATCHLIST UserInfoExternalInterface[] =
  44. {
  45. {L"get_FirstName", DISPID_USERINFO_GET_FIRSTNAME },
  46. {L"set_FirstName", DISPID_USERINFO_SET_FIRSTNAME },
  47. {L"get_MiddleInitial", DISPID_USERINFO_GET_MIDDLEINITIAL },
  48. {L"set_MiddleInitial", DISPID_USERINFO_SET_MIDDLEINITIAL },
  49. {L"get_LastName", DISPID_USERINFO_GET_LASTNAME },
  50. {L"set_LastName", DISPID_USERINFO_SET_LASTNAME },
  51. {L"get_FuriganaName", DISPID_USERINFO_GET_FURIGANANAME },
  52. {L"set_FuriganaName", DISPID_USERINFO_SET_FURIGANANAME },
  53. {L"get_CompanyName", DISPID_USERINFO_GET_COMPANYNAME },
  54. {L"set_CompanyName", DISPID_USERINFO_SET_COMPANYNAME },
  55. {L"get_Address1", DISPID_USERINFO_GET_ADDRESS1 },
  56. {L"set_Address1", DISPID_USERINFO_SET_ADDRESS1 },
  57. {L"get_Address2", DISPID_USERINFO_GET_ADDRESS2 },
  58. {L"set_Address2", DISPID_USERINFO_SET_ADDRESS2 },
  59. {L"get_City", DISPID_USERINFO_GET_CITY },
  60. {L"set_City", DISPID_USERINFO_SET_CITY },
  61. {L"get_State", DISPID_USERINFO_GET_STATE },
  62. {L"set_State", DISPID_USERINFO_SET_STATE },
  63. {L"get_Zip", DISPID_USERINFO_GET_ZIP },
  64. {L"set_Zip", DISPID_USERINFO_SET_ZIP },
  65. {L"get_Country", DISPID_USERINFO_GET_COUNTRY },
  66. {L"set_Country", DISPID_USERINFO_SET_COUNTRY },
  67. {L"get_CountryID", DISPID_USERINFO_GET_COUNTRYID },
  68. {L"set_CountryID", DISPID_USERINFO_SET_COUNTRYID },
  69. {L"get_PrimaryEmail", DISPID_USERINFO_GET_PRIMARYEMAIL },
  70. {L"set_PrimaryEmail", DISPID_USERINFO_SET_PRIMARYEMAIL },
  71. {L"get_SecondaryEmail", DISPID_USERINFO_GET_SECONDARYEMAIL },
  72. {L"set_SecondaryEmail", DISPID_USERINFO_SET_SECONDARYEMAIL },
  73. {L"get_AreaCode", DISPID_USERINFO_GET_AREACODE },
  74. {L"set_AreaCode", DISPID_USERINFO_SET_AREACODE },
  75. {L"get_PhoneNumber", DISPID_USERINFO_GET_PHONENUMBER },
  76. {L"set_PhoneNumber", DISPID_USERINFO_SET_PHONENUMBER },
  77. {L"get_MSUpdate", DISPID_USERINFO_GET_MSUPDATE },
  78. {L"set_MSUpdate", DISPID_USERINFO_SET_MSUPDATE },
  79. {L"get_MSOffer", DISPID_USERINFO_GET_MSOFFER },
  80. {L"set_MSOffer", DISPID_USERINFO_SET_MSOFFER },
  81. {L"get_OtherOffer", DISPID_USERINFO_GET_OTHEROFFER },
  82. {L"set_OtherOffer", DISPID_USERINFO_SET_OTHEROFFER },
  83. {L"get_Identity", DISPID_USERINFO_GET_IDENTITY },
  84. {L"set_Identity", DISPID_USERINFO_SET_IDENTITY },
  85. {L"get_IdentitiesMax", DISPID_USERINFO_GET_IDENTITIESMAX },
  86. {L"check_Identity", DISPID_USERINFO_CHECK_IDENTITY },
  87. {L"SuggestIdentity0", DISPID_USERINFO_SUGGESTIDENTITY0 },
  88. {L"get_UseIdentities", DISPID_USERINFO_GET_USEIDENTITIES },
  89. {L"set_UseIdentities", DISPID_USERINFO_SET_USEIDENTITIES },
  90. {L"get_OEMIdentities", DISPID_USERINFO_GET_OEMIDENTITIES },
  91. {L"get_OwnerName", DISPID_USERINFO_GET_OWNERNAME },
  92. {L"set_OwnerName", DISPID_USERINFO_SET_OWNERNAME },
  93. {L"get_DefaultNewUser", DISPID_USERINFO_GET_DEFAULTNEWUSER },
  94. };
  95. const WCHAR csz_ADDR1[] = L"Addr1";
  96. const WCHAR csz_ADDR2[] = L"Addr2";
  97. const WCHAR csz_ADDRTYPE[] = L"AddrType";
  98. const WCHAR csz_AREACODE[] = L"AreaCode";
  99. const WCHAR csz_CITY[] = L"City";
  100. const WCHAR csz_COMPANYNAME[] = L"CompanyName";
  101. const WCHAR csz_COUNTRYCODE[] = L"CountryCode";
  102. const WCHAR csz_DIVISIONNAME[] = L"DivisionName";
  103. const WCHAR csz_EMAILNAME[] = L"EmailName";
  104. const WCHAR csz_EXTENSION[] = L"Extension";
  105. const WCHAR csz_FNAME[] = L"FName";
  106. const WCHAR csz_INFLUENCELEVEL[] = L"InfluenceLevel";
  107. const WCHAR csz_LANGCODE[] = L"LangCode";
  108. const WCHAR csz_LANGNAME[] = L"LangName";
  109. const WCHAR csz_LNAME[] = L"LName";
  110. const WCHAR csz_MNAME[] = L"MName";
  111. const WCHAR csz_NOOTHER[] = L"NoOther";
  112. const WCHAR csz_PHONE[] = L"Phone";
  113. const WCHAR csz_PID[] = L"PID";
  114. const WCHAR csz_PRODUCT[] = L"Product";
  115. const WCHAR csz_REGWIZVER[] = L"RegWizVer";
  116. const WCHAR csz_SOFTWAREROLE[] = L"SoftwareRole";
  117. const WCHAR csz_STATE[] = L"State";
  118. const WCHAR csz_USERID[] = L"UserID";
  119. const WCHAR csz_ZIP[] = L"Zip";
  120. const WCHAR CSZ_COMPUTERMANF[] = L"ComputerManf";
  121. REGDATAELEMENT aryRegDataElements[] =
  122. {
  123. { csz_ADDR1, NULL, 0},
  124. { csz_ADDR2, NULL, 0},
  125. { csz_ADDRTYPE, NULL, 0},
  126. { csz_AREACODE, NULL, 0},
  127. { csz_CITY, NULL, 0},
  128. { csz_COMPANYNAME, NULL, 0},
  129. { csz_COUNTRYCODE, NULL, 0},
  130. { csz_DIVISIONNAME, NULL, 0},
  131. { csz_EMAILNAME, NULL, 0},
  132. { csz_EXTENSION, NULL, 0},
  133. { csz_FNAME, NULL, 0},
  134. { csz_INFLUENCELEVEL, NULL, 0},
  135. { csz_LANGCODE, NULL, 0},
  136. { csz_LANGNAME, NULL, 0},
  137. { csz_LNAME, NULL, 0},
  138. { csz_MNAME, NULL, 0},
  139. { csz_NOOTHER, NULL, 0},
  140. { csz_PHONE, NULL, 0},
  141. { csz_PID, NULL, 0},
  142. { csz_PRODUCT, NULL, 0},
  143. { csz_REGWIZVER, NULL, 0},
  144. { csz_SOFTWAREROLE, NULL, 0},
  145. { csz_STATE, NULL, 0},
  146. { csz_USERID, NULL, 0},
  147. { csz_ZIP, NULL, 0},
  148. { CSZ_COMPUTERMANF, NULL, 0}
  149. };
  150. enum
  151. {
  152. INDEX_ADDR1 = 0,
  153. INDEX_ADDR2, // = 1,
  154. INDEX_ADDRTYPE, // = 2,
  155. INDEX_AREACODE, // = 3,
  156. INDEX_CITY, // = 4,
  157. INDEX_COMPANYNAME, // = 5,
  158. INDEX_COUNTRYCODE, // = 6,
  159. INDEX_DIVISIONNAME, // = 7,
  160. INDEX_EMAILNAME, // = 8,
  161. INDEX_EXTENSION, // = 9,
  162. INDEX_FNAME, // = 10,
  163. INDEX_INFLUENCELEVEL, // = 11,
  164. INDEX_LANGCODE, // = 12,
  165. INDEX_LANGNAME, // = 13,
  166. INDEX_LNAME, // = 14,
  167. INDEX_MNAME, // = 15,
  168. INDEX_NOOTHER, // = 16,
  169. INDEX_PHONE, // = 17,
  170. INDEX_PID, // = 18,
  171. INDEX_PRODUCT, // = 19,
  172. INDEX_REGWIZVER, // = 20,
  173. INDEX_SOFTWAREROLE, // = 21,
  174. INDEX_STATE, // = 22,
  175. INDEX_USERID, // = 23,
  176. INDEX_ZIP, // = 24,
  177. INDEX_COMPUTERMANF // = 25
  178. };
  179. #define REGDATAELEMENTS_LEN sizeof(aryRegDataElements) / sizeof(REGDATAELEMENT)
  180. const CUserInfo::RESERVED_IDENTITIES_IDS[] =
  181. {
  182. IDS_ACCTNAME_ADMINISTRATOR,
  183. IDS_ACCTNAME_GUEST
  184. };
  185. /////////////////////////////////////////////////////////////
  186. // CUserInfo::CUserInfo
  187. CUserInfo::CUserInfo(HINSTANCE hInstance)
  188. : m_hInstance(hInstance)
  189. {
  190. WCHAR szKeyName[] = REG_KEY_OOBE_TEMP;
  191. HKEY hKey = NULL;
  192. BOOL bName,
  193. bOrg;
  194. // Init member vars
  195. m_cRef = 0;
  196. // What if it failed?
  197. GetCanonicalizedPath(m_szUserInfoINIFile, USER_INFO_INIFILE);
  198. RegOpenKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
  199. // Initialize or restore registration data
  200. ReadUserInfo(hKey, USERINFO_REG_KEY_FIRSTNAME, m_szFirstName, sizeof(m_szFirstName) );
  201. ReadUserInfo(hKey, USERINFO_REG_KEY_MIDDLEINITIAL, m_szMiddleInitial, sizeof(m_szMiddleInitial) );
  202. ReadUserInfo(hKey, USERINFO_REG_KEY_LASTNAME, m_szLastName, sizeof(m_szLastName) );
  203. ReadUserInfo(hKey, USERINFO_REG_KEY_FURIGANANAME, m_szFuriganaName, sizeof(m_szFuriganaName) );
  204. ReadUserInfo(hKey, USERINFO_REG_KEY_COMPANYNAME, m_szCompanyName, sizeof(m_szCompanyName) );
  205. ReadUserInfo(hKey, USERINFO_REG_KEY_ADDRESS1, m_szAddress1, sizeof(m_szAddress1) );
  206. ReadUserInfo(hKey, USERINFO_REG_KEY_ADDRESS2, m_szAddress2, sizeof(m_szAddress2) );
  207. ReadUserInfo(hKey, USERINFO_REG_KEY_CITY, m_szCity, sizeof(m_szCity) );
  208. ReadUserInfo(hKey, USERINFO_REG_KEY_STATE, m_szState, sizeof(m_szState) );
  209. ReadUserInfo(hKey, USERINFO_REG_KEY_ZIP, m_szZip, sizeof(m_szZip) );
  210. ReadUserInfo(hKey, USERINFO_REG_KEY_COUNTRY, m_szCountry, sizeof(m_szCountry) );
  211. ReadUserInfo(hKey, USERINFO_REG_KEY_PRIMARYEMAIL, m_szPrimaryEmail, sizeof(m_szPrimaryEmail) );
  212. ReadUserInfo(hKey, USERINFO_REG_KEY_SECONDARYEMAIL, m_szSecondaryEmail, sizeof(m_szSecondaryEmail) );
  213. ReadUserInfo(hKey, USERINFO_REG_KEY_AREACODE, m_szAreaCode, sizeof(m_szAreaCode) );
  214. ReadUserInfo(hKey, USERINFO_REG_KEY_PHONENUMBER, m_szPhoneNumber, sizeof(m_szPhoneNumber) );
  215. // Initialize or restore new user accounts
  216. ReadUserInfo(hKey, USERINFO_REG_KEY_OWNERNAME, m_szOwnerName, sizeof(m_szOwnerName) );
  217. ReadUserInfo(hKey, USERINFO_REG_KEY_DEFAULTNEWUSER ,m_szDefaultNewUser, sizeof(m_szDefaultNewUser) );
  218. m_fUseIdentities = DEFAULT_USEIDENTITIES;
  219. m_fMSUpdate = VARIANT_TRUE;
  220. m_fMSOffer = VARIANT_TRUE;
  221. m_fOtherOffer = VARIANT_TRUE;
  222. m_dwCountryID = 0;
  223. // Need to distinguish between OEM preset identities and
  224. // Registry value, so ReadUserInfo is not used
  225. m_fOEMIdentities = FALSE;
  226. for (UINT uiIndex = 0; uiIndex < IDENTITIES_MAX; uiIndex++)
  227. {
  228. wsprintf(m_rgIdentities[uiIndex].rgchRegValue,
  229. L"%s%03d",
  230. USERINFO_REG_KEY_IDENTITY, uiIndex
  231. );
  232. GetPrivateProfileString(USER_INFO_KEYNAME,
  233. m_rgIdentities[uiIndex].rgchRegValue,
  234. L"\0",
  235. m_rgIdentities[uiIndex].rgchIdentity,
  236. IDENTITY_CCH_MAX,
  237. m_szUserInfoINIFile);
  238. TRACE4( L"%s/%s/%s=%s",
  239. m_szUserInfoINIFile,
  240. USER_INFO_KEYNAME,
  241. m_rgIdentities[uiIndex].rgchRegValue,
  242. m_rgIdentities[uiIndex].rgchIdentity );
  243. m_fOEMIdentities = m_fOEMIdentities ||
  244. (m_rgIdentities[uiIndex].rgchIdentity[0] != L'\0');
  245. }
  246. if ( (!m_fOEMIdentities) && (hKey != NULL) ) {
  247. for (uiIndex = 0; uiIndex < IDENTITIES_MAX; uiIndex++)
  248. {
  249. DWORD dwType = 0;
  250. DWORD dwSize = IDENTITY_CCH_MAX;
  251. RegQueryValueEx(hKey,
  252. m_rgIdentities[uiIndex].rgchRegValue,
  253. 0,
  254. &dwType,
  255. (LPBYTE)m_rgIdentities[uiIndex].rgchIdentity,
  256. &dwSize);
  257. }
  258. }
  259. if ( hKey )
  260. RegCloseKey(hKey);
  261. // Get the default name or org if there wasn't one already saved.
  262. //
  263. bName = FALSE;
  264. bOrg = ( *m_szCompanyName == L'\0' );
  265. // This is so OEMs can prepopulate the user or org field. We just store the name
  266. // in the first name field. We might want to split it up into First, MI, and Last
  267. // in the future?
  268. //
  269. if ( bName || bOrg ) {
  270. SetupGetSetupInfo(
  271. bName ? m_szFirstName : NULL,
  272. bName ? sizeof(m_szFirstName) : 0,
  273. m_szCompanyName ? m_szCompanyName : NULL,
  274. m_szCompanyName ? sizeof(m_szCompanyName) : 0,
  275. NULL,
  276. 0,
  277. NULL
  278. );
  279. }
  280. m_RegDataElements = aryRegDataElements;
  281. m_RegDataElements[0].lpQueryElementValue = (LPWSTR) m_szAddress1;
  282. m_RegDataElements[1].lpQueryElementValue = (LPWSTR) m_szAddress2;
  283. m_RegDataElements[3].lpQueryElementValue = (LPWSTR) m_szAreaCode;
  284. m_RegDataElements[4].lpQueryElementValue = (LPWSTR) m_szCity;
  285. m_RegDataElements[5].lpQueryElementValue = (LPWSTR) m_szCompanyName;
  286. m_RegDataElements[8].lpQueryElementValue = (LPWSTR) m_szPrimaryEmail;
  287. m_RegDataElements[10].lpQueryElementValue = (LPWSTR) m_szFirstName;
  288. m_RegDataElements[15].lpQueryElementValue = (LPWSTR) m_szMiddleInitial;
  289. m_RegDataElements[14].lpQueryElementValue = (LPWSTR) m_szLastName;
  290. m_RegDataElements[17].lpQueryElementValue = (LPWSTR) m_szPhoneNumber;
  291. m_RegDataElements[22].lpQueryElementValue = (LPWSTR) m_szState;
  292. m_RegDataElements[24].lpQueryElementValue = (LPWSTR) m_szZip;
  293. for (int i = 0; i < RESERVED_IDENTITIES_MAX; i++)
  294. {
  295. if (!LoadString(
  296. m_hInstance,
  297. RESERVED_IDENTITIES_IDS[i],
  298. m_szReservedIdentities[i],
  299. sizeof(m_szReservedIdentities[i]) / sizeof(TCHAR)
  300. ))
  301. {
  302. m_szReservedIdentities[i][0] = L'\0';
  303. }
  304. }
  305. }
  306. /////////////////////////////////////////////////////////////
  307. // CUserInfo::~CUserInfo
  308. CUserInfo::~CUserInfo()
  309. {
  310. assert(m_cRef == 0);
  311. }
  312. void CUserInfo::ReadUserInfo(HKEY hKey, WCHAR* pszKey, WCHAR* pszValue, DWORD dwSize)
  313. {
  314. DWORD dwType = 0;
  315. DWORD cSize = dwSize;
  316. *pszValue = L'\0';
  317. if( ( hKey == NULL) ||
  318. ( ERROR_SUCCESS != RegQueryValueEx(hKey,
  319. pszKey,
  320. 0,
  321. &dwType,
  322. (LPBYTE)pszValue,
  323. &dwSize) || *pszValue == L'\0' ) )
  324. {
  325. GetPrivateProfileString(USER_INFO_KEYNAME,
  326. pszKey,
  327. L"\0",
  328. pszValue,
  329. cSize,
  330. m_szUserInfoINIFile);
  331. }
  332. }
  333. void CUserInfo::WriteUserInfo(WCHAR* pszBuf, WCHAR* pszKey, WCHAR* pszValue)
  334. {
  335. WCHAR szKeyName[] = REG_KEY_OOBE_TEMP;
  336. HKEY hKey;
  337. // A null value must be converted to an empty string.
  338. //
  339. if ( pszValue )
  340. lstrcpy(pszBuf, pszValue);
  341. else
  342. *pszBuf = L'\0';
  343. // Commit the data to the registry.
  344. //
  345. if ( RegCreateKeyEx(HKEY_LOCAL_MACHINE, szKeyName, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL) == ERROR_SUCCESS )
  346. {
  347. if ( *pszBuf )
  348. RegSetValueEx(hKey, pszKey, 0, REG_SZ, (LPBYTE) pszValue, BYTES_REQUIRED_BY_SZ(pszValue));
  349. else
  350. RegDeleteValue(hKey, pszKey);
  351. RegFlushKey(hKey);
  352. RegCloseKey(hKey);
  353. }
  354. }
  355. ////////////////////////////////////////////////
  356. ////////////////////////////////////////////////
  357. //// GET / SET :: Identity
  358. ////
  359. HRESULT CUserInfo::get_Identity(UINT uiIndex, BSTR* pbstrVal)
  360. {
  361. if (uiIndex >= IDENTITIES_MAX)
  362. {
  363. return E_INVALIDARG;
  364. }
  365. *pbstrVal = SysAllocString(m_rgIdentities[uiIndex].rgchIdentity);
  366. if (NULL == *pbstrVal)
  367. {
  368. return E_OUTOFMEMORY;
  369. }
  370. return S_OK;
  371. }
  372. HRESULT CUserInfo::set_Identity(UINT uiIndex, WCHAR* pszVal)
  373. {
  374. if (uiIndex < IDENTITIES_MAX)
  375. {
  376. if (!pszVal) // delete the account if it exists
  377. {
  378. WriteUserInfo(m_rgIdentities[uiIndex].rgchIdentity,
  379. m_rgIdentities[uiIndex].rgchRegValue,
  380. NULL);
  381. }
  382. else
  383. {
  384. if (lstrlen(pszVal) <= IDENTITY_CCH_MAX)
  385. {
  386. WriteUserInfo(m_rgIdentities[uiIndex].rgchIdentity,
  387. m_rgIdentities[uiIndex].rgchRegValue,
  388. pszVal
  389. );
  390. }
  391. }
  392. }
  393. return S_OK;
  394. }
  395. HRESULT CUserInfo::get_Identities(PSTRINGLIST* pUserList)
  396. {
  397. for (UINT uiIndex = 0; uiIndex < IDENTITIES_MAX; uiIndex++)
  398. {
  399. if (lstrlen(m_rgIdentities[uiIndex].rgchIdentity) > 0)
  400. {
  401. PSTRINGLIST Cell;
  402. Cell = CreateStringCell(m_rgIdentities[uiIndex].rgchIdentity);
  403. if (Cell)
  404. {
  405. FixString(Cell->String);
  406. InsertList(pUserList, Cell);
  407. }
  408. }
  409. }
  410. return S_OK;
  411. }
  412. ////////////////////////////////////////////////
  413. ////////////////////////////////////////////////
  414. //// GET / SET :: UseIdentities
  415. ////
  416. HRESULT CUserInfo::get_UseIdentities(VARIANT_BOOL *pfVal)
  417. {
  418. *pfVal = m_fUseIdentities;
  419. return S_OK;
  420. }
  421. HRESULT CUserInfo::set_UseIdentities(VARIANT_BOOL fVal)
  422. {
  423. m_fUseIdentities = fVal;
  424. return S_OK;
  425. }
  426. ////////////////////////////////////////////////
  427. ////////////////////////////////////////////////
  428. //// GET / SET :: MSUpdate
  429. ////
  430. HRESULT CUserInfo::get_MSUpdate(VARIANT_BOOL *pfVal)
  431. {
  432. *pfVal = m_fMSUpdate;
  433. return S_OK;
  434. }
  435. HRESULT CUserInfo::set_MSUpdate(VARIANT_BOOL fVal)
  436. {
  437. m_fMSUpdate = fVal;
  438. return S_OK;
  439. }
  440. ////////////////////////////////////////////////
  441. ////////////////////////////////////////////////
  442. //// GET / SET :: MSOffer
  443. ////
  444. HRESULT CUserInfo::get_MSOffer(VARIANT_BOOL *pfVal)
  445. {
  446. *pfVal = m_fMSOffer;
  447. return S_OK;
  448. }
  449. HRESULT CUserInfo::set_MSOffer(VARIANT_BOOL fVal)
  450. {
  451. m_fMSOffer = fVal;
  452. return S_OK;
  453. }
  454. ////////////////////////////////////////////////
  455. ////////////////////////////////////////////////
  456. //// GET / SET :: OtherOffer
  457. ////
  458. HRESULT CUserInfo::get_OtherOffer(VARIANT_BOOL *pfVal)
  459. {
  460. *pfVal = m_fOtherOffer;
  461. return S_OK;
  462. }
  463. HRESULT CUserInfo::set_OtherOffer(VARIANT_BOOL fVal)
  464. {
  465. m_fOtherOffer = fVal;
  466. return S_OK;
  467. }
  468. ////////////////////////////////////////////////
  469. ////////////////////////////////////////////////
  470. //// GET / SET :: CountryID
  471. ////
  472. HRESULT CUserInfo::get_CountryID(DWORD *pdwVal)
  473. {
  474. *pdwVal = m_dwCountryID;
  475. return S_OK;
  476. }
  477. HRESULT CUserInfo::set_CountryID(DWORD dwVal)
  478. {
  479. m_dwCountryID = dwVal;
  480. return S_OK;
  481. }
  482. ////////////////////////////////////////////////
  483. ////////////////////////////////////////////////
  484. //// CHECK :: Identity
  485. ////
  486. // constant strings used for name validation
  487. #define DOT_CHAR '.'
  488. #define DOT_AND_SPACE_STR TEXT(". ")
  489. #define CTRL_CHARS_0 TEXT( "\001\002\003\004\005\006\007")
  490. #define CTRL_CHARS_1 TEXT("\010\011\012\013\014\015\016\017")
  491. #define CTRL_CHARS_2 TEXT("\020\021\022\023\024\025\026\027")
  492. #define CTRL_CHARS_3 TEXT("\030\031\032\033\034\035\036\037")
  493. #define CTRL_CHARS_STR CTRL_CHARS_0 CTRL_CHARS_1 CTRL_CHARS_2 CTRL_CHARS_3
  494. #define ILLEGAL_FAT_CHARS CTRL_CHARS_STR TEXT("\"*+,/:;<=>?[\\]|@")
  495. HRESULT CUserInfo::check_Identity(UINT uiIndex, VARIANT_BOOL* pfValid)
  496. {
  497. BSTR bstrVal;
  498. *pfValid = TRUE; // initalize outparam, assume ok
  499. if (SUCCEEDED(get_Identity(uiIndex, &bstrVal)))
  500. {
  501. // check length
  502. DWORD cchVal = lstrlen(bstrVal);
  503. if (cchVal > 0) // if cchVal == 0, user trying to delete or didn't define
  504. {
  505. check_Identity(bstrVal, pfValid);
  506. for (UINT i = 0; i < uiIndex; i++) // check not equal to other names
  507. {
  508. BSTR bstrValOther;
  509. if (SUCCEEDED(get_Identity(i, &bstrValOther)))
  510. {
  511. if (0 == StrCmpI(bstrVal, bstrValOther))
  512. {
  513. *pfValid = FALSE;
  514. }
  515. SysFreeString(bstrValOther);
  516. }
  517. }
  518. }
  519. SysFreeString(bstrVal);
  520. }
  521. return S_OK;
  522. }
  523. HRESULT CUserInfo::check_Identity(WCHAR* pszVal, VARIANT_BOOL* pfValid)
  524. {
  525. *pfValid = TRUE; // initalize outparam, assume ok
  526. if (pszVal)
  527. {
  528. WCHAR szComputerName[MAX_COMPUTERNAME_LENGTH + 1];
  529. DWORD cchComputerName = sizeof(szComputerName) / sizeof(WCHAR);
  530. DWORD cchVal = lstrlen(pszVal);
  531. if (cchVal > 0) // if cchVal == 0, user trying to delete or didn't define
  532. {
  533. if (cchVal > 20)
  534. {
  535. *pfValid = FALSE;
  536. }
  537. // check for trailing periods
  538. if (pszVal[cchVal - 1] == DOT_CHAR)
  539. {
  540. *pfValid = FALSE;
  541. }
  542. // check not all spaces and periods
  543. if (StrSpn(pszVal, DOT_AND_SPACE_STR) == (int)cchVal)
  544. {
  545. *pfValid = FALSE;
  546. }
  547. // check nothing from ILLEGAL_FAT_CHARS in name
  548. if (StrCSpn(pszVal, ILLEGAL_FAT_CHARS) < (int)cchVal)
  549. {
  550. *pfValid = FALSE;
  551. }
  552. for (int i = 0; i < RESERVED_IDENTITIES_MAX; i++)
  553. {
  554. if (!lstrcmpi(m_szReservedIdentities[i], pszVal))
  555. {
  556. *pfValid = FALSE;
  557. break;
  558. }
  559. }
  560. if (GetComputerName(szComputerName, &cchComputerName))
  561. {
  562. if (!lstrcmpi(szComputerName, pszVal))
  563. {
  564. *pfValid = FALSE;
  565. }
  566. }
  567. }
  568. else
  569. {
  570. *pfValid = FALSE;
  571. }
  572. }
  573. else
  574. {
  575. *pfValid = FALSE;
  576. }
  577. return S_OK;
  578. }
  579. STDMETHODIMP CUserInfo::SuggestIdentity0()
  580. {
  581. if (lstrlen(m_rgIdentities[0].rgchIdentity) == 0)
  582. {
  583. LPWSTR Candidates[] = {m_szOwnerName, m_szFirstName, m_szLastName, NULL};
  584. for (int i = 0; Candidates[i]; i++)
  585. {
  586. if (lstrlen(Candidates[i]) > 0)
  587. {
  588. VARIANT_BOOL b;
  589. check_Identity(Candidates[i], &b);
  590. if (b)
  591. {
  592. FixString(Candidates[i]);
  593. set_Identity(0, Candidates[i]);
  594. break;
  595. }
  596. }
  597. }
  598. }
  599. return S_OK;
  600. }
  601. ////////////////////////////////////////////////
  602. ////////////////////////////////////////////////
  603. //// GET / SET :: FirstName
  604. ////
  605. HRESULT CUserInfo::set_FirstName(WCHAR* pszVal)
  606. {
  607. WriteUserInfo(m_szFirstName, USERINFO_REG_KEY_FIRSTNAME, pszVal);
  608. return S_OK;
  609. }
  610. HRESULT CUserInfo::get_FirstName(BSTR* pbstrVal)
  611. {
  612. *pbstrVal = SysAllocString(m_szFirstName);
  613. return S_OK;
  614. }
  615. ////////////////////////////////////////////////
  616. ////////////////////////////////////////////////
  617. //// GET / SET :: MiddleInitial
  618. ////
  619. HRESULT CUserInfo::set_MiddleInitial(WCHAR* pszVal)
  620. {
  621. WriteUserInfo(m_szMiddleInitial, USERINFO_REG_KEY_MIDDLEINITIAL, pszVal);
  622. return S_OK;
  623. }
  624. HRESULT CUserInfo::get_MiddleInitial(BSTR* pbstrVal)
  625. {
  626. *pbstrVal = SysAllocString(m_szMiddleInitial);
  627. return S_OK;
  628. }
  629. ////////////////////////////////////////////////
  630. ////////////////////////////////////////////////
  631. //// GET / SET :: LastName
  632. ////
  633. HRESULT CUserInfo::set_LastName(WCHAR* pszVal)
  634. {
  635. WriteUserInfo(m_szLastName, USERINFO_REG_KEY_LASTNAME, pszVal);
  636. return S_OK;
  637. }
  638. HRESULT CUserInfo::get_LastName(BSTR* pbstrVal)
  639. {
  640. *pbstrVal = SysAllocString(m_szLastName);
  641. return S_OK;
  642. }
  643. ////////////////////////////////////////////////
  644. ////////////////////////////////////////////////
  645. //// GET / SET :: FuriganaName
  646. ////
  647. HRESULT CUserInfo::set_FuriganaName(WCHAR* pszVal)
  648. {
  649. WriteUserInfo(m_szFuriganaName, USERINFO_REG_KEY_FURIGANANAME, pszVal);
  650. return S_OK;
  651. }
  652. HRESULT CUserInfo::get_FuriganaName(BSTR* pbstrVal)
  653. {
  654. *pbstrVal = SysAllocString(m_szFuriganaName);
  655. return S_OK;
  656. }
  657. ////////////////////////////////////////////////
  658. ////////////////////////////////////////////////
  659. //// GET / SET :: CompanyName
  660. ////
  661. HRESULT CUserInfo::set_CompanyName(WCHAR* pszVal)
  662. {
  663. WriteUserInfo(m_szCompanyName, USERINFO_REG_KEY_COMPANYNAME, pszVal);
  664. return S_OK;
  665. }
  666. HRESULT CUserInfo::get_CompanyName(BSTR* pbstrVal)
  667. {
  668. *pbstrVal = SysAllocString(m_szCompanyName);
  669. return S_OK;
  670. }
  671. ////////////////////////////////////////////////
  672. ////////////////////////////////////////////////
  673. //// GET / SET :: Address1
  674. ////
  675. HRESULT CUserInfo::set_Address1(WCHAR* pszVal)
  676. {
  677. WriteUserInfo(m_szAddress1, USERINFO_REG_KEY_ADDRESS1, pszVal);
  678. return S_OK;
  679. }
  680. HRESULT CUserInfo::get_Address1(BSTR* pbstrVal)
  681. {
  682. *pbstrVal = SysAllocString(m_szAddress1);
  683. return S_OK;
  684. }
  685. ////////////////////////////////////////////////
  686. ////////////////////////////////////////////////
  687. //// GET / SET :: Address2
  688. ////
  689. HRESULT CUserInfo::set_Address2(WCHAR* pszVal)
  690. {
  691. WriteUserInfo(m_szAddress2, USERINFO_REG_KEY_ADDRESS2, pszVal);
  692. return S_OK;
  693. }
  694. HRESULT CUserInfo::get_Address2(BSTR* pbstrVal)
  695. {
  696. *pbstrVal = SysAllocString(m_szAddress2);
  697. return S_OK;
  698. }
  699. ////////////////////////////////////////////////
  700. ////////////////////////////////////////////////
  701. //// GET / SET :: City
  702. ////
  703. HRESULT CUserInfo::set_City(WCHAR* pszVal)
  704. {
  705. WriteUserInfo(m_szCity, USERINFO_REG_KEY_CITY, pszVal);
  706. return S_OK;
  707. }
  708. HRESULT CUserInfo::get_City(BSTR* pbstrVal)
  709. {
  710. *pbstrVal = SysAllocString(m_szCity);
  711. return S_OK;
  712. }
  713. ////////////////////////////////////////////////
  714. ////////////////////////////////////////////////
  715. //// GET / SET :: State
  716. ////
  717. HRESULT CUserInfo::set_State(WCHAR* pszVal)
  718. {
  719. WriteUserInfo(m_szState, USERINFO_REG_KEY_STATE, pszVal);
  720. return S_OK;
  721. }
  722. HRESULT CUserInfo::get_State(BSTR* pbstrVal)
  723. {
  724. *pbstrVal = SysAllocString(m_szState);
  725. return S_OK;
  726. }
  727. ////////////////////////////////////////////////
  728. ////////////////////////////////////////////////
  729. //// GET / SET :: Zip
  730. ////
  731. HRESULT CUserInfo::set_Zip(WCHAR* pszVal)
  732. {
  733. WriteUserInfo(m_szZip, USERINFO_REG_KEY_ZIP, pszVal);
  734. return S_OK;
  735. }
  736. HRESULT CUserInfo::get_Zip(BSTR* pbstrVal)
  737. {
  738. *pbstrVal = SysAllocString(m_szZip);
  739. return S_OK;
  740. }
  741. ////////////////////////////////////////////////
  742. ////////////////////////////////////////////////
  743. //// GET / SET :: Country
  744. ////
  745. HRESULT CUserInfo::set_Country(WCHAR* pszVal)
  746. {
  747. WriteUserInfo(m_szCountry, USERINFO_REG_KEY_COUNTRY, pszVal);
  748. return S_OK;
  749. }
  750. HRESULT CUserInfo::get_Country(BSTR* pbstrVal)
  751. {
  752. *pbstrVal = SysAllocString(m_szCountry);
  753. return S_OK;
  754. }
  755. ////////////////////////////////////////////////
  756. ////////////////////////////////////////////////
  757. //// GET / SET :: PrimaryEmail
  758. ////
  759. HRESULT CUserInfo::set_PrimaryEmail(WCHAR* pszVal)
  760. {
  761. WriteUserInfo(m_szPrimaryEmail, USERINFO_REG_KEY_PRIMARYEMAIL, pszVal);
  762. return S_OK;
  763. }
  764. HRESULT CUserInfo::get_PrimaryEmail(BSTR* pbstrVal)
  765. {
  766. *pbstrVal = SysAllocString(m_szPrimaryEmail);
  767. return S_OK;
  768. }
  769. ////////////////////////////////////////////////
  770. ////////////////////////////////////////////////
  771. //// GET / SET :: SecondaryEmail
  772. ////
  773. HRESULT CUserInfo::set_SecondaryEmail(WCHAR* pszVal)
  774. {
  775. WriteUserInfo(m_szSecondaryEmail, USERINFO_REG_KEY_SECONDARYEMAIL, pszVal);
  776. return S_OK;
  777. }
  778. HRESULT CUserInfo::get_SecondaryEmail(BSTR* pbstrVal)
  779. {
  780. *pbstrVal = SysAllocString(m_szSecondaryEmail);
  781. return S_OK;
  782. }
  783. ////////////////////////////////////////////////
  784. ////////////////////////////////////////////////
  785. //// GET / SET :: AreaCode
  786. ////
  787. HRESULT CUserInfo::set_AreaCode(WCHAR* pszVal)
  788. {
  789. WriteUserInfo(m_szAreaCode, USERINFO_REG_KEY_AREACODE, pszVal);
  790. return S_OK;
  791. }
  792. HRESULT CUserInfo::get_AreaCode(BSTR* pbstrVal)
  793. {
  794. *pbstrVal = SysAllocString(m_szAreaCode);
  795. return S_OK;
  796. }
  797. ////////////////////////////////////////////////
  798. ////////////////////////////////////////////////
  799. //// GET / SET :: Number
  800. ////
  801. HRESULT CUserInfo::set_PhoneNumber(WCHAR* pszVal)
  802. {
  803. WriteUserInfo(m_szPhoneNumber, USERINFO_REG_KEY_PHONENUMBER, pszVal);
  804. return S_OK;
  805. }
  806. HRESULT CUserInfo::get_PhoneNumber(BSTR* pbstrVal)
  807. {
  808. *pbstrVal = SysAllocString(m_szPhoneNumber);
  809. return S_OK;
  810. }
  811. ////////////////////////////////////////////////
  812. ////////////////////////////////////////////////
  813. //// GET / SET :: OwnerName
  814. ////
  815. HRESULT CUserInfo::set_OwnerName(WCHAR* pszVal)
  816. {
  817. WriteUserInfo(m_szOwnerName, USERINFO_REG_KEY_OWNERNAME, pszVal);
  818. return S_OK;
  819. }
  820. HRESULT CUserInfo::get_OwnerName(BSTR* pbstrVal)
  821. {
  822. *pbstrVal = SysAllocString(m_szOwnerName);
  823. return S_OK;
  824. }
  825. ////////////////////////////////////////////////
  826. ////////////////////////////////////////////////
  827. //// GET / SET :: DefaultNewUser
  828. ////
  829. HRESULT CUserInfo::set_DefaultNewUser(WCHAR* pszVal)
  830. {
  831. WriteUserInfo(m_szDefaultNewUser, USERINFO_REG_KEY_DEFAULTNEWUSER, pszVal);
  832. return S_OK;
  833. }
  834. HRESULT CUserInfo::get_DefaultNewUser(BSTR* pbstrVal)
  835. {
  836. *pbstrVal = SysAllocString(m_szDefaultNewUser);
  837. return S_OK;
  838. }
  839. /////////////////////////////////////////////////////////////
  840. /////////////////////////////////////////////////////////////
  841. /////////////////////////////////////////////////////////////
  842. /////// IUnknown implementation
  843. ///////
  844. ///////
  845. /////////////////////////////////////////////////////////////
  846. // CObMain::QueryInterface
  847. STDMETHODIMP CUserInfo::QueryInterface(REFIID riid, LPVOID* ppvObj)
  848. {
  849. // must set out pointer parameters to NULL
  850. *ppvObj = NULL;
  851. if ( riid == IID_IUnknown)
  852. {
  853. AddRef();
  854. *ppvObj = (IUnknown*)this;
  855. return ResultFromScode(S_OK);
  856. }
  857. if (riid == IID_IDispatch)
  858. {
  859. AddRef();
  860. *ppvObj = (IDispatch*)this;
  861. return ResultFromScode(S_OK);
  862. }
  863. // Not a supported interface
  864. return ResultFromScode(E_NOINTERFACE);
  865. }
  866. /////////////////////////////////////////////////////////////
  867. // CUserInfo::AddRef
  868. STDMETHODIMP_(ULONG) CUserInfo::AddRef()
  869. {
  870. return ++m_cRef;
  871. }
  872. /////////////////////////////////////////////////////////////
  873. // CUserInfo::Release
  874. STDMETHODIMP_(ULONG) CUserInfo::Release()
  875. {
  876. return --m_cRef;
  877. }
  878. /////////////////////////////////////////////////////////////
  879. /////////////////////////////////////////////////////////////
  880. /////////////////////////////////////////////////////////////
  881. /////// IDispatch implementation
  882. ///////
  883. ///////
  884. /////////////////////////////////////////////////////////////
  885. // CUserInfo::GetTypeInfo
  886. STDMETHODIMP CUserInfo::GetTypeInfo(UINT, LCID, ITypeInfo**)
  887. {
  888. return E_NOTIMPL;
  889. }
  890. /////////////////////////////////////////////////////////////
  891. // CUserInfo::GetTypeInfoCount
  892. STDMETHODIMP CUserInfo::GetTypeInfoCount(UINT* pcInfo)
  893. {
  894. return E_NOTIMPL;
  895. }
  896. /////////////////////////////////////////////////////////////
  897. // CUserInfo::GetIDsOfNames
  898. STDMETHODIMP CUserInfo::GetIDsOfNames(REFIID riid,
  899. OLECHAR** rgszNames,
  900. UINT cNames,
  901. LCID lcid,
  902. DISPID* rgDispId)
  903. {
  904. HRESULT hr = DISP_E_UNKNOWNNAME;
  905. rgDispId[0] = DISPID_UNKNOWN;
  906. for (int iX = 0; iX < sizeof(UserInfoExternalInterface)/sizeof(DISPATCHLIST); iX ++)
  907. {
  908. if(lstrcmp(UserInfoExternalInterface[iX].szName, rgszNames[0]) == 0)
  909. {
  910. rgDispId[0] = UserInfoExternalInterface[iX].dwDispID;
  911. hr = NOERROR;
  912. break;
  913. }
  914. }
  915. // Set the disid's for the parameters
  916. if (cNames > 1)
  917. {
  918. // Set a DISPID for function parameters
  919. for (UINT i = 1; i < cNames ; i++)
  920. rgDispId[i] = DISPID_UNKNOWN;
  921. }
  922. return hr;
  923. }
  924. /////////////////////////////////////////////////////////////
  925. // CUserInfo::Invoke
  926. HRESULT CUserInfo::Invoke
  927. (
  928. DISPID dispidMember,
  929. REFIID riid,
  930. LCID lcid,
  931. WORD wFlags,
  932. DISPPARAMS* pdispparams,
  933. VARIANT* pvarResult,
  934. EXCEPINFO* pexcepinfo,
  935. UINT* puArgErr
  936. )
  937. {
  938. HRESULT hr = S_OK;
  939. switch(dispidMember)
  940. {
  941. case DISPID_USERINFO_CHECK_IDENTITY:
  942. {
  943. TRACE(L"DISPID_USERINFO_CHECK_IDENTITY\n");
  944. if(pdispparams && &pdispparams[0].rgvarg[0] && pvarResult)
  945. {
  946. VariantInit(pvarResult);
  947. V_VT(pvarResult) = VT_BOOL;
  948. if (pdispparams[0].rgvarg[0].vt == VT_BSTR)
  949. {
  950. check_Identity(pdispparams[0].rgvarg[0].bstrVal, &pvarResult->boolVal);
  951. }
  952. else
  953. {
  954. check_Identity(pdispparams[0].rgvarg[0].uintVal, &pvarResult->boolVal);
  955. }
  956. }
  957. break;
  958. }
  959. case DISPID_USERINFO_GET_FIRSTNAME:
  960. {
  961. TRACE(L"DISPID_USERINFO_GET_FIRSTNAME\n");
  962. if(pvarResult)
  963. {
  964. VariantInit(pvarResult);
  965. V_VT(pvarResult) = VT_BSTR;
  966. get_FirstName(&pvarResult->bstrVal);
  967. }
  968. break;
  969. }
  970. case DISPID_USERINFO_SET_FIRSTNAME:
  971. {
  972. TRACE(L"DISPID_USERINFO_SET_FIRSTNAME\n");
  973. if(pdispparams && &pdispparams[0].rgvarg[0])
  974. set_FirstName(pdispparams[0].rgvarg[0].bstrVal);
  975. break;
  976. }
  977. case DISPID_USERINFO_GET_MIDDLEINITIAL:
  978. {
  979. TRACE(L"DISPID_USERINFO_GET_MIDDLEINITIAL\n");
  980. if(pvarResult)
  981. {
  982. VariantInit(pvarResult);
  983. V_VT(pvarResult) = VT_BSTR;
  984. get_MiddleInitial(&pvarResult->bstrVal);
  985. }
  986. break;
  987. }
  988. case DISPID_USERINFO_SET_MIDDLEINITIAL:
  989. {
  990. TRACE(L"DISPID_USERINFO_SET_MIDDLEINITIAL\n");
  991. if(pdispparams && &pdispparams[0].rgvarg[0])
  992. set_MiddleInitial(pdispparams[0].rgvarg[0].bstrVal);
  993. break;
  994. }
  995. case DISPID_USERINFO_GET_LASTNAME:
  996. {
  997. TRACE(L"DISPID_USERINFO_GET_LASTNAME\n");
  998. if(pvarResult)
  999. {
  1000. VariantInit(pvarResult);
  1001. V_VT(pvarResult) = VT_BSTR;
  1002. get_LastName(&pvarResult->bstrVal);
  1003. }
  1004. break;
  1005. }
  1006. case DISPID_USERINFO_SET_LASTNAME:
  1007. {
  1008. TRACE(L"DISPID_USERINFO_SET_LASTNAME\n");
  1009. if(pdispparams && &pdispparams[0].rgvarg[0])
  1010. set_LastName(pdispparams[0].rgvarg[0].bstrVal);
  1011. break;
  1012. }
  1013. case DISPID_USERINFO_GET_FURIGANANAME:
  1014. {
  1015. TRACE(L"DISPID_USERINFO_GET_FURIGANANAME\n");
  1016. if(pvarResult)
  1017. {
  1018. VariantInit(pvarResult);
  1019. V_VT(pvarResult) = VT_BSTR;
  1020. get_FuriganaName(&pvarResult->bstrVal);
  1021. }
  1022. break;
  1023. }
  1024. case DISPID_USERINFO_SET_FURIGANANAME:
  1025. {
  1026. TRACE(L"DISPID_USERINFO_SET_FURIGANANAME\n");
  1027. if(pdispparams && &pdispparams[0].rgvarg[0])
  1028. set_FuriganaName(pdispparams[0].rgvarg[0].bstrVal);
  1029. break;
  1030. }
  1031. case DISPID_USERINFO_GET_OWNERNAME:
  1032. {
  1033. TRACE(L"DISPID_USERINFO_GET_OWNERNAME\n");
  1034. if(pvarResult)
  1035. {
  1036. VariantInit(pvarResult);
  1037. V_VT(pvarResult) = VT_BSTR;
  1038. get_OwnerName(&pvarResult->bstrVal);
  1039. }
  1040. break;
  1041. }
  1042. case DISPID_USERINFO_SET_OWNERNAME:
  1043. {
  1044. TRACE(L"DISPID_USERINFO_SET_OWNERNAME\n");
  1045. if(pdispparams && &pdispparams[0].rgvarg[0])
  1046. set_OwnerName(pdispparams[0].rgvarg[0].bstrVal);
  1047. break;
  1048. }
  1049. case DISPID_USERINFO_GET_COMPANYNAME:
  1050. {
  1051. TRACE(L"DISPID_USERINFO_GET_COMPANYNAME\n");
  1052. if(pvarResult)
  1053. {
  1054. VariantInit(pvarResult);
  1055. V_VT(pvarResult) = VT_BSTR;
  1056. get_CompanyName(&pvarResult->bstrVal);
  1057. }
  1058. break;
  1059. }
  1060. case DISPID_USERINFO_SET_COMPANYNAME:
  1061. {
  1062. TRACE(L"DISPID_USERINFO_SET_COMPANYNAME\n");
  1063. if(pdispparams && &pdispparams[0].rgvarg[0])
  1064. set_CompanyName(pdispparams[0].rgvarg[0].bstrVal);
  1065. break;
  1066. }
  1067. case DISPID_USERINFO_GET_ADDRESS1:
  1068. {
  1069. TRACE(L"DISPID_USERINFO_GET_ADDRESS1\n");
  1070. if(pvarResult)
  1071. {
  1072. VariantInit(pvarResult);
  1073. V_VT(pvarResult) = VT_BSTR;
  1074. get_Address1(&pvarResult->bstrVal);
  1075. }
  1076. break;
  1077. }
  1078. case DISPID_USERINFO_SET_ADDRESS1:
  1079. {
  1080. TRACE(L"DISPID_USERINFO_SET_ADDRESS1\n");
  1081. if(pdispparams && &pdispparams[0].rgvarg[0])
  1082. set_Address1(pdispparams[0].rgvarg[0].bstrVal);
  1083. break;
  1084. }
  1085. case DISPID_USERINFO_GET_ADDRESS2:
  1086. {
  1087. TRACE(L"DISPID_USERINFO_GET_ADDRESS2\n");
  1088. if(pvarResult)
  1089. {
  1090. VariantInit(pvarResult);
  1091. V_VT(pvarResult) = VT_BSTR;
  1092. get_Address2(&pvarResult->bstrVal);
  1093. }
  1094. break;
  1095. }
  1096. case DISPID_USERINFO_SET_ADDRESS2:
  1097. {
  1098. TRACE(L"DISPID_USERINFO_SET_ADDRESS2\n");
  1099. if(pdispparams && &pdispparams[0].rgvarg[0])
  1100. set_Address2(pdispparams[0].rgvarg[0].bstrVal);
  1101. break;
  1102. }
  1103. case DISPID_USERINFO_GET_CITY:
  1104. {
  1105. TRACE(L"DISPID_USERINFO_GET_CITY\n");
  1106. if(pvarResult)
  1107. {
  1108. VariantInit(pvarResult);
  1109. V_VT(pvarResult) = VT_BSTR;
  1110. get_City(&pvarResult->bstrVal);
  1111. }
  1112. break;
  1113. }
  1114. case DISPID_USERINFO_SET_CITY:
  1115. {
  1116. TRACE(L"DISPID_USERINFO_SET_CITY\n");
  1117. if(pdispparams && &pdispparams[0].rgvarg[0])
  1118. set_City(pdispparams[0].rgvarg[0].bstrVal);
  1119. break;
  1120. }
  1121. case DISPID_USERINFO_GET_STATE:
  1122. {
  1123. TRACE(L"DISPID_USERINFO_GET_STATE\n");
  1124. if(pvarResult)
  1125. {
  1126. VariantInit(pvarResult);
  1127. V_VT(pvarResult) = VT_BSTR;
  1128. get_State(&pvarResult->bstrVal);
  1129. }
  1130. break;
  1131. }
  1132. case DISPID_USERINFO_SET_STATE:
  1133. {
  1134. TRACE(L"DISPID_USERINFO_SET_STATE\n");
  1135. if(pdispparams && &pdispparams[0].rgvarg[0])
  1136. set_State(pdispparams[0].rgvarg[0].bstrVal);
  1137. break;
  1138. }
  1139. case DISPID_USERINFO_GET_ZIP:
  1140. {
  1141. TRACE(L"DISPID_USERINFO_GET_ZIP\n");
  1142. if(pvarResult)
  1143. {
  1144. VariantInit(pvarResult);
  1145. V_VT(pvarResult) = VT_BSTR;
  1146. get_Zip(&pvarResult->bstrVal);
  1147. }
  1148. break;
  1149. }
  1150. case DISPID_USERINFO_SET_ZIP:
  1151. {
  1152. TRACE(L"DISPID_USERINFO_SET_ZIP\n");
  1153. if(pdispparams && &pdispparams[0].rgvarg[0])
  1154. set_Zip(pdispparams[0].rgvarg[0].bstrVal);
  1155. break;
  1156. }
  1157. case DISPID_USERINFO_GET_COUNTRY:
  1158. {
  1159. TRACE(L"DISPID_USERINFO_GET_COUNTRY\n");
  1160. if(pvarResult)
  1161. {
  1162. VariantInit(pvarResult);
  1163. V_VT(pvarResult) = VT_BSTR;
  1164. get_Country(&pvarResult->bstrVal);
  1165. }
  1166. break;
  1167. }
  1168. case DISPID_USERINFO_SET_COUNTRY:
  1169. {
  1170. TRACE(L"DISPID_USERINFO_SET_COUNTRY\n");
  1171. if(pdispparams && &pdispparams[0].rgvarg[0])
  1172. set_Country(pdispparams[0].rgvarg[0].bstrVal);
  1173. break;
  1174. }
  1175. case DISPID_USERINFO_GET_PRIMARYEMAIL:
  1176. {
  1177. TRACE(L"DISPID_USERINFO_GET_PRIMARYEMAIL\n");
  1178. if(pvarResult)
  1179. {
  1180. VariantInit(pvarResult);
  1181. V_VT(pvarResult) = VT_BSTR;
  1182. get_PrimaryEmail(&pvarResult->bstrVal);
  1183. }
  1184. break;
  1185. }
  1186. case DISPID_USERINFO_SET_PRIMARYEMAIL:
  1187. {
  1188. TRACE(L"DISPID_USERINFO_SET_PRIMARYEMAIL\n");
  1189. if(pdispparams && &pdispparams[0].rgvarg[0])
  1190. set_PrimaryEmail(pdispparams[0].rgvarg[0].bstrVal);
  1191. break;
  1192. }
  1193. case DISPID_USERINFO_GET_SECONDARYEMAIL:
  1194. {
  1195. TRACE(L"DISPID_USERINFO_GET_SECONDARYEMAIL\n");
  1196. if(pvarResult)
  1197. {
  1198. VariantInit(pvarResult);
  1199. V_VT(pvarResult) = VT_BSTR;
  1200. get_SecondaryEmail(&pvarResult->bstrVal);
  1201. }
  1202. break;
  1203. }
  1204. case DISPID_USERINFO_SET_SECONDARYEMAIL:
  1205. {
  1206. TRACE(L"DISPID_USERINFO_SET_SECONDARYEMAIL\n");
  1207. if(pdispparams && &pdispparams[0].rgvarg[0])
  1208. set_SecondaryEmail(pdispparams[0].rgvarg[0].bstrVal);
  1209. break;
  1210. }
  1211. case DISPID_USERINFO_GET_AREACODE:
  1212. {
  1213. TRACE(L"DISPID_USERINFO_GET_AREACODE\n");
  1214. if(pvarResult)
  1215. {
  1216. VariantInit(pvarResult);
  1217. V_VT(pvarResult) = VT_BSTR;
  1218. get_AreaCode(&pvarResult->bstrVal);
  1219. }
  1220. break;
  1221. }
  1222. case DISPID_USERINFO_SET_AREACODE:
  1223. {
  1224. TRACE(L"DISPID_USERINFO_SET_AREACODE\n");
  1225. if(pdispparams && &pdispparams[0].rgvarg[0])
  1226. set_AreaCode(pdispparams[0].rgvarg[0].bstrVal);
  1227. break;
  1228. }
  1229. case DISPID_USERINFO_GET_PHONENUMBER:
  1230. {
  1231. TRACE(L"DISPID_USERINFO_GET_PHONENUMBER\n");
  1232. if(pvarResult)
  1233. {
  1234. VariantInit(pvarResult);
  1235. V_VT(pvarResult) = VT_BSTR;
  1236. get_PhoneNumber(&pvarResult->bstrVal);
  1237. }
  1238. break;
  1239. }
  1240. case DISPID_USERINFO_SET_PHONENUMBER:
  1241. {
  1242. TRACE(L"DISPID_USERINFO_SET_PHONENUMBER\n");
  1243. if(pdispparams && &pdispparams[0].rgvarg[0])
  1244. set_PhoneNumber(pdispparams[0].rgvarg[0].bstrVal);
  1245. break;
  1246. }
  1247. case DISPID_USERINFO_GET_MSUPDATE:
  1248. {
  1249. TRACE(L"DISPID_USERINFO_GET_MSUPDATE");
  1250. if (NULL != pvarResult)
  1251. {
  1252. VariantInit(pvarResult);
  1253. V_VT(pvarResult) = VT_BOOL;
  1254. get_MSUpdate(&(pvarResult->boolVal));
  1255. }
  1256. break;
  1257. }
  1258. case DISPID_USERINFO_SET_MSUPDATE:
  1259. {
  1260. TRACE(L"DISPID_USERINFO_SET_MSUPDATE");
  1261. if (pdispparams && 0 < pdispparams->cArgs)
  1262. set_MSUpdate(pdispparams[0].rgvarg[0].boolVal);
  1263. break;
  1264. }
  1265. case DISPID_USERINFO_GET_MSOFFER:
  1266. {
  1267. TRACE(L"DISPID_USERINFO_GET_MSOFFER");
  1268. if (NULL != pvarResult)
  1269. {
  1270. VariantInit(pvarResult);
  1271. V_VT(pvarResult) = VT_BOOL;
  1272. get_MSOffer(&(pvarResult->boolVal));
  1273. }
  1274. break;
  1275. }
  1276. case DISPID_USERINFO_SET_MSOFFER:
  1277. {
  1278. TRACE(L"DISPID_USERINFO_SET_MSOFFER");
  1279. if (pdispparams && 0 < pdispparams->cArgs)
  1280. set_MSOffer(pdispparams[0].rgvarg[0].boolVal);
  1281. break;
  1282. }
  1283. case DISPID_USERINFO_GET_OTHEROFFER:
  1284. {
  1285. TRACE(L"DISPID_USERINFO_GET_OTHEROFFER");
  1286. if (NULL != pvarResult)
  1287. {
  1288. VariantInit(pvarResult);
  1289. V_VT(pvarResult) = VT_BOOL;
  1290. get_OtherOffer(&(pvarResult->boolVal));
  1291. }
  1292. break;
  1293. }
  1294. case DISPID_USERINFO_SET_OTHEROFFER:
  1295. {
  1296. TRACE(L"DISPID_USERINFO_SET_OTHEROFFER");
  1297. if (pdispparams && 0 < pdispparams->cArgs)
  1298. set_OtherOffer(pdispparams[0].rgvarg[0].boolVal);
  1299. break;
  1300. }
  1301. case DISPID_USERINFO_GET_COUNTRYID:
  1302. {
  1303. TRACE(L"DISPID_USERINFO_GET_COUNTRYID");
  1304. if (NULL != pvarResult)
  1305. {
  1306. VariantInit(pvarResult);
  1307. V_VT(pvarResult) = VT_I4;
  1308. get_CountryID((PDWORD)&(pvarResult->lVal));
  1309. }
  1310. break;
  1311. }
  1312. case DISPID_USERINFO_SET_COUNTRYID:
  1313. {
  1314. TRACE(L"DISPID_USERINFO_SET_COUNTRYID");
  1315. if (pdispparams && 0 < pdispparams->cArgs)
  1316. set_CountryID(pdispparams[0].rgvarg[0].lVal);
  1317. break;
  1318. }
  1319. case DISPID_USERINFO_GET_IDENTITIESMAX:
  1320. {
  1321. TRACE(L"DISPID_USERINFO_GET_IDENTITIESMAX\n");
  1322. if(pvarResult)
  1323. {
  1324. VariantInit(pvarResult);
  1325. V_VT(pvarResult) = VT_I2;
  1326. get_IdentitiesMax(&pvarResult->iVal);
  1327. }
  1328. break;
  1329. }
  1330. case DISPID_USERINFO_GET_IDENTITY:
  1331. {
  1332. TRACE(L"DISPID_USERINFO_GET_IDENTITY\n");
  1333. if ( NULL != pdispparams
  1334. && 0 < pdispparams->cArgs
  1335. && NULL != pvarResult)
  1336. {
  1337. VariantInit(pvarResult);
  1338. V_VT(pvarResult) = VT_BSTR;
  1339. get_Identity(pdispparams[0].rgvarg[0].uintVal,
  1340. &pvarResult->bstrVal
  1341. );
  1342. }
  1343. break;
  1344. }
  1345. case DISPID_USERINFO_SET_IDENTITY:
  1346. {
  1347. TRACE(L"DISPID_USERINFO_SET_IDENTITY\n");
  1348. if(pdispparams && 1 < pdispparams->cArgs)
  1349. set_Identity(pdispparams[0].rgvarg[1].uintVal,
  1350. pdispparams[0].rgvarg[0].bstrVal);
  1351. break;
  1352. }
  1353. case DISPID_USERINFO_GET_USEIDENTITIES:
  1354. {
  1355. TRACE(L"DISPID_USERINFO_GET_USEIDENTITIES");
  1356. if (NULL != pvarResult)
  1357. {
  1358. VariantInit(pvarResult);
  1359. V_VT(pvarResult) = VT_BOOL;
  1360. get_UseIdentities(&(pvarResult->boolVal));
  1361. }
  1362. break;
  1363. }
  1364. case DISPID_USERINFO_SET_USEIDENTITIES:
  1365. {
  1366. TRACE(L"DISPID_USERINFO_SET_USEIDENTITIES");
  1367. if (pdispparams && 0 < pdispparams->cArgs)
  1368. set_UseIdentities(pdispparams[0].rgvarg[0].boolVal);
  1369. break;
  1370. }
  1371. case DISPID_USERINFO_GET_OEMIDENTITIES:
  1372. {
  1373. TRACE(L"DISPID_USERINFO_GET_OEMIDENTITIES");
  1374. if (NULL != pvarResult)
  1375. {
  1376. VariantInit(pvarResult);
  1377. V_VT(pvarResult) = VT_BOOL;
  1378. get_OEMIdentities(&(pvarResult->boolVal));
  1379. }
  1380. break;
  1381. }
  1382. case DISPID_USERINFO_SUGGESTIDENTITY0:
  1383. {
  1384. OutputDebugString(L"DISPID_USERINFO_SUGGESTIDENTITY0\n");
  1385. SuggestIdentity0();
  1386. break;
  1387. }
  1388. case DISPID_USERINFO_GET_DEFAULTNEWUSER:
  1389. {
  1390. TRACE(L"DISPID_USERINFO_GET_DEFAULTNEWUSER");
  1391. if(pvarResult)
  1392. {
  1393. VariantInit(pvarResult);
  1394. V_VT(pvarResult) = VT_BSTR;
  1395. get_DefaultNewUser(&pvarResult->bstrVal);
  1396. }
  1397. break;
  1398. }
  1399. default:
  1400. {
  1401. hr = DISP_E_MEMBERNOTFOUND;
  1402. break;
  1403. }
  1404. }
  1405. return hr;
  1406. }
  1407. //
  1408. HRESULT CUserInfo::set_CountryCode(DWORD dwCountryCd)
  1409. {
  1410. m_dwCountryCode = dwCountryCd;
  1411. return S_OK;
  1412. }
  1413. // This funtion will form the query string to be sent to the ISP signup server
  1414. //
  1415. HRESULT CUserInfo::GetQueryString
  1416. (
  1417. BSTR bstrBaseURL,
  1418. BSTR *lpReturnURL
  1419. )
  1420. {
  1421. LPWSTR lpWorkingURL;
  1422. WORD cchBuffer = 0;
  1423. LPREGDATAELEMENT lpElement;
  1424. LPWSTR lpszBaseURL = bstrBaseURL;
  1425. int i;
  1426. BSTR pbstrVal = NULL;
  1427. CProductID PidObj;
  1428. PidObj.get_PID(&pbstrVal);
  1429. m_RegDataElements[INDEX_PID].lpQueryElementValue = (LPWSTR) pbstrVal;
  1430. WCHAR buffer[8];
  1431. _itow( m_dwCountryCode, buffer, 8 );
  1432. m_RegDataElements[INDEX_COUNTRYCODE].lpQueryElementValue = (LPWSTR)buffer;
  1433. m_RegDataElements[INDEX_PRODUCT].lpQueryElementValue = REG_VAL_OOBE;
  1434. // Now read the INI file.
  1435. WCHAR szOemInfoFile[MAX_PATH] = L"\0";
  1436. WCHAR szComputerManf[MAX_PATH] = L"\0";
  1437. GetSystemDirectory(szOemInfoFile, MAX_CHARS_IN_BUFFER(szOemInfoFile));
  1438. lstrcat(szOemInfoFile, OEMINFO_INI_FILENAME);
  1439. GetPrivateProfileString(USER_COMP_MANF_SEC,
  1440. USER_COMP_MANF_KEY,
  1441. L"\0",
  1442. szComputerManf,
  1443. MAX_CHARS_IN_BUFFER(szComputerManf),
  1444. szOemInfoFile);
  1445. m_RegDataElements[INDEX_COMPUTERMANF].lpQueryElementValue = szComputerManf;
  1446. //ASSERT(lpReturnURL);
  1447. if (!lpReturnURL)
  1448. return E_FAIL;
  1449. // Calculate how big of a buffer we will need
  1450. cchBuffer += (WORD)lstrlen(lpszBaseURL) + 1;
  1451. for (i = 0; i < REGDATAELEMENTS_LEN; i ++)
  1452. {
  1453. lpElement = &m_RegDataElements[i];
  1454. //ASSERT(lpElement);
  1455. if (lpElement->lpQueryElementName)
  1456. {
  1457. cchBuffer += (WORD)( lstrlen(lpElement->lpQueryElementName)
  1458. + (lstrlen(lpElement->lpQueryElementValue) * 3) // *3 for encoding
  1459. + 3 // For the = and & and the terminator
  1460. // (because we copy lpQueryElementValue
  1461. // into a new buffer for encoding)
  1462. );
  1463. }
  1464. else
  1465. {
  1466. // extra character is for the trailing &
  1467. cchBuffer += (WORD)(lstrlen(lpElement->lpQueryElementValue) + 1);
  1468. }
  1469. }
  1470. cchBuffer++; // Terminator
  1471. // Allocate a buffer large enough
  1472. if (NULL == (lpWorkingURL = (LPWSTR)GlobalAllocPtr(GPTR, BYTES_REQUIRED_BY_CCH(cchBuffer))))
  1473. return E_FAIL;
  1474. lstrcpy(lpWorkingURL, lpszBaseURL);
  1475. // See if this ISP provided URL is already a Query String.
  1476. if (*lpWorkingURL)
  1477. {
  1478. if (NULL != wcschr(lpWorkingURL, L'?'))
  1479. lstrcat(lpWorkingURL, cszAmpersand); // Append our params
  1480. else
  1481. lstrcat(lpWorkingURL, cszQuestion); // Start with our params
  1482. }
  1483. for (i = 0; i < REGDATAELEMENTS_LEN; i ++)
  1484. {
  1485. lpElement = &m_RegDataElements[i];
  1486. //ASSERT(lpElement);
  1487. if (lpElement->lpQueryElementName)
  1488. {
  1489. // If there is a query value, then encode it
  1490. if (lpElement->lpQueryElementValue)
  1491. {
  1492. // Allocate a buffer to encode into
  1493. size_t cch = (lstrlen(lpElement->lpQueryElementValue) + 1) * 3;
  1494. LPWSTR lpszVal = (LPWSTR) malloc(BYTES_REQUIRED_BY_CCH(cch));
  1495. lstrcpy(lpszVal, lpElement->lpQueryElementValue);
  1496. URLEncode(lpszVal, cch);
  1497. URLAppendQueryPair(lpWorkingURL,
  1498. (LPWSTR)lpElement->lpQueryElementName,
  1499. lpszVal);
  1500. free(lpszVal);
  1501. }
  1502. else
  1503. {
  1504. URLAppendQueryPair(lpWorkingURL,
  1505. (LPWSTR)lpElement->lpQueryElementName,
  1506. NULL);
  1507. }
  1508. }
  1509. else
  1510. {
  1511. if (lpElement->lpQueryElementValue)
  1512. {
  1513. lstrcat(lpWorkingURL, lpElement->lpQueryElementValue);
  1514. lstrcat(lpWorkingURL, cszAmpersand);
  1515. }
  1516. }
  1517. }
  1518. // Terminate the working URL properly, by removing the trailing ampersand
  1519. lpWorkingURL[lstrlen(lpWorkingURL)-1] = L'\0';
  1520. // Set the return VALUE. We must allocate here, since the caller will free
  1521. // this returned string, and A2W only puts the string in the stack
  1522. *lpReturnURL = SysAllocString(lpWorkingURL);
  1523. // Free the buffer
  1524. GlobalFreePtr(lpWorkingURL);
  1525. return (S_OK);
  1526. }
  1527. void CUserInfo::FixString(BSTR bstrVal)
  1528. {
  1529. if (bstrVal != NULL)
  1530. {
  1531. // StrTrim removes both leading and trailing spaces
  1532. StrTrim(bstrVal, TEXT(" "));
  1533. }
  1534. }