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.

440 lines
12 KiB

  1. #include "pch.hxx"
  2. #include <imnact.h>
  3. #include <acctimp.h>
  4. #include <dllmain.h>
  5. #include <resource.h>
  6. #include "netscape.h"
  7. #include "strconst.h"
  8. #include "demand.h"
  9. ASSERTDATA
  10. CNscpAcctImport::CNscpAcctImport()
  11. {
  12. m_cRef = 1;
  13. m_fIni = FALSE;
  14. *m_szIni = 0;
  15. m_cInfo = 0;
  16. m_rgInfo = NULL;
  17. }
  18. CNscpAcctImport::~CNscpAcctImport()
  19. {
  20. if (m_rgInfo != NULL)
  21. MemFree(m_rgInfo);
  22. }
  23. STDMETHODIMP CNscpAcctImport::QueryInterface(REFIID riid, LPVOID *ppv)
  24. {
  25. if (ppv == NULL)
  26. return(E_INVALIDARG);
  27. *ppv = NULL;
  28. if (IID_IUnknown == riid)
  29. *ppv = (IAccountImport *)this;
  30. else if (IID_IAccountImport == riid)
  31. *ppv = (IAccountImport *)this;
  32. else if (IID_IAccountImport2 == riid)
  33. *ppv = (IAccountImport2 *)this;
  34. else
  35. return(E_NOINTERFACE);
  36. ((LPUNKNOWN)*ppv)->AddRef();
  37. return(S_OK);
  38. }
  39. STDMETHODIMP_(ULONG) CNscpAcctImport::AddRef()
  40. {
  41. return(++m_cRef);
  42. }
  43. STDMETHODIMP_(ULONG) CNscpAcctImport::Release()
  44. {
  45. if (--m_cRef == 0)
  46. {
  47. delete this;
  48. return(0);
  49. }
  50. return(m_cRef);
  51. }
  52. HRESULT STDMETHODCALLTYPE CNscpAcctImport::AutoDetect(DWORD *pcAcct, DWORD dwFlags)
  53. {
  54. HRESULT hr;
  55. HKEY hkey, hkeyServices;
  56. char szPop[MAX_PATH];
  57. DWORD type, cb;
  58. if (pcAcct == NULL)
  59. return(E_INVALIDARG);
  60. hr = S_FALSE;
  61. *pcAcct = 0;
  62. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, c_szRegNscp, 0, KEY_READ, &hkey))
  63. {
  64. if (ERROR_SUCCESS == RegOpenKeyEx(hkey, c_szRegServices, 0, KEY_READ, &hkeyServices))
  65. {
  66. cb = sizeof(szPop);
  67. if (ERROR_SUCCESS == RegQueryValueEx(hkeyServices, c_szNscpPopServer, NULL, &type, (LPBYTE)szPop, &cb) &&
  68. cb > 0 &&
  69. type == REG_SZ)
  70. {
  71. hr = S_OK;
  72. }
  73. RegCloseKey(hkeyServices);
  74. }
  75. RegCloseKey(hkey);
  76. }
  77. if (hr == S_FALSE)
  78. {
  79. cb = GetProfileString(c_szNetscape, c_szIni, c_szEmpty, m_szIni, ARRAYSIZE(m_szIni));
  80. if (cb > 0)
  81. {
  82. cb = GetPrivateProfileString(c_szRegServices, c_szNscpPopServer, c_szEmpty,
  83. szPop, ARRAYSIZE(szPop), m_szIni);
  84. if (cb > 0)
  85. {
  86. m_fIni = TRUE;
  87. hr = S_OK;
  88. }
  89. }
  90. }
  91. if (hr == S_OK)
  92. {
  93. if (!MemAlloc((void **)&m_rgInfo, sizeof(NSCPACCTINFO)))
  94. {
  95. hr = E_OUTOFMEMORY;
  96. }
  97. else
  98. {
  99. m_rgInfo->dwCookie = 0;
  100. LoadString(g_hInstRes, idsDefaultAccount, m_rgInfo->szDisplay, ARRAYSIZE(m_rgInfo->szDisplay));
  101. m_cInfo = 1;
  102. *pcAcct = 1;
  103. }
  104. }
  105. return(hr);
  106. }
  107. HRESULT STDMETHODCALLTYPE CNscpAcctImport::EnumerateAccounts(IEnumIMPACCOUNTS **ppEnum)
  108. {
  109. CEnumNSCPACCTS *penum;
  110. HRESULT hr;
  111. if (ppEnum == NULL)
  112. return(E_INVALIDARG);
  113. *ppEnum = NULL;
  114. if (m_cInfo == 0)
  115. return(S_FALSE);
  116. Assert(m_rgInfo != NULL);
  117. penum = new CEnumNSCPACCTS;
  118. if (penum == NULL)
  119. return(E_OUTOFMEMORY);
  120. hr = penum->Init(m_rgInfo, m_cInfo);
  121. if (FAILED(hr))
  122. {
  123. penum->Release();
  124. penum = NULL;
  125. }
  126. *ppEnum = penum;
  127. return(hr);
  128. }
  129. HRESULT STDMETHODCALLTYPE CNscpAcctImport::GetSettings(DWORD_PTR dwCookie, IImnAccount *pAcct)
  130. {
  131. if (pAcct == NULL)
  132. return(E_INVALIDARG);
  133. return(IGetSettings(dwCookie, pAcct, NULL));
  134. }
  135. HRESULT STDMETHODCALLTYPE CNscpAcctImport::GetSettings2(DWORD_PTR dwCookie, IImnAccount *pAcct, IMPCONNINFO *pInfo)
  136. {
  137. if (pAcct == NULL ||
  138. pInfo == NULL)
  139. return(E_INVALIDARG);
  140. return(IGetSettings(dwCookie, pAcct, pInfo));
  141. }
  142. HRESULT CNscpAcctImport::IGetSettings(DWORD_PTR dwCookie, IImnAccount *pAcct, IMPCONNINFO *pInfo)
  143. {
  144. HKEY hkey, hkeyT;
  145. NSCPACCTINFO *pinfo;
  146. char sz[512];
  147. DWORD cb, type;
  148. HRESULT hr;
  149. Assert(pAcct != NULL);
  150. Assert(((int) dwCookie) >= 0 && dwCookie < (DWORD_PTR)m_cInfo);
  151. pinfo = &m_rgInfo[dwCookie];
  152. Assert(pinfo->dwCookie == dwCookie);
  153. hr = pAcct->SetPropSz(AP_ACCOUNT_NAME, pinfo->szDisplay);
  154. if (FAILED(hr))
  155. return(hr);
  156. if (m_fIni)
  157. {
  158. cb = GetPrivateProfileString(c_szRegMail, c_szPopName, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  159. if (cb > 0)
  160. {
  161. hr = pAcct->SetPropSz(AP_POP3_USERNAME, sz);
  162. Assert(!FAILED(hr));
  163. }
  164. cb = GetPrivateProfileString(c_szRegServices, c_szNscpSmtpServer, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  165. if (cb > 0)
  166. {
  167. hr = pAcct->SetPropSz(AP_SMTP_SERVER, sz);
  168. Assert(!FAILED(hr));
  169. }
  170. cb = GetPrivateProfileString(c_szRegServices, c_szNscpPopServer, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  171. if (cb > 0)
  172. {
  173. hr = pAcct->SetPropSz(AP_POP3_SERVER, sz);
  174. Assert(!FAILED(hr));
  175. }
  176. cb = GetPrivateProfileString(c_szRegUser, c_szNscpUserName, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  177. if (cb > 0)
  178. {
  179. hr = pAcct->SetPropSz(AP_SMTP_DISPLAY_NAME, sz);
  180. Assert(!FAILED(hr));
  181. }
  182. cb = GetPrivateProfileString(c_szRegUser, c_szUserAddr, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  183. if (cb > 0)
  184. {
  185. hr = pAcct->SetPropSz(AP_SMTP_EMAIL_ADDRESS, sz);
  186. Assert(!FAILED(hr));
  187. }
  188. cb = GetPrivateProfileString(c_szRegUser, c_szReplyTo, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  189. if (cb > 0)
  190. {
  191. hr = pAcct->SetPropSz(AP_SMTP_REPLY_EMAIL_ADDRESS, sz);
  192. Assert(!FAILED(hr));
  193. }
  194. cb = GetPrivateProfileString(c_szRegMail, c_szLeaveServer, c_szEmpty, sz, ARRAYSIZE(sz), m_szIni);
  195. if (cb > 0)
  196. {
  197. if (lstrcmpi(sz, c_szYes))
  198. {
  199. hr = pAcct->SetPropDw(AP_POP3_LEAVE_ON_SERVER, 1);
  200. Assert(!FAILED(hr));
  201. }
  202. }
  203. }
  204. else
  205. {
  206. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, c_szRegNscp, 0, KEY_READ, &hkey))
  207. {
  208. if (ERROR_SUCCESS == RegOpenKeyEx(hkey, c_szRegMail, 0, KEY_READ, &hkeyT))
  209. {
  210. cb = sizeof(sz);
  211. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szPopName, NULL, &type, (LPBYTE)sz, &cb) &&
  212. !FIsEmpty(sz))
  213. {
  214. hr = pAcct->SetPropSz(AP_POP3_USERNAME, sz);
  215. Assert(!FAILED(hr));
  216. }
  217. cb = sizeof(sz);
  218. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szLeaveServer, NULL, &type, (LPBYTE)sz, &cb) &&
  219. !FIsEmpty(sz))
  220. {
  221. hr = pAcct->SetPropDw(AP_POP3_LEAVE_ON_SERVER, 1);
  222. Assert(!FAILED(hr));
  223. }
  224. RegCloseKey(hkeyT);
  225. }
  226. if (ERROR_SUCCESS == RegOpenKeyEx(hkey, c_szRegServices, 0, KEY_READ, &hkeyT))
  227. {
  228. cb = sizeof(sz);
  229. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szNscpSmtpServer, NULL, &type, (LPBYTE)sz, &cb) &&
  230. !FIsEmpty(sz))
  231. {
  232. hr = pAcct->SetPropSz(AP_SMTP_SERVER, sz);
  233. Assert(!FAILED(hr));
  234. }
  235. cb = sizeof(sz);
  236. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szNscpPopServer, NULL, &type, (LPBYTE)sz, &cb) &&
  237. !FIsEmpty(sz))
  238. {
  239. hr = pAcct->SetPropSz(AP_POP3_SERVER, sz);
  240. Assert(!FAILED(hr));
  241. }
  242. RegCloseKey(hkeyT);
  243. }
  244. if (ERROR_SUCCESS == RegOpenKeyEx(hkey, c_szRegUser, 0, KEY_READ, &hkeyT))
  245. {
  246. cb = sizeof(sz);
  247. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szNscpUserName, NULL, &type, (LPBYTE)sz, &cb) &&
  248. !FIsEmpty(sz))
  249. {
  250. hr = pAcct->SetPropSz(AP_SMTP_DISPLAY_NAME, sz);
  251. Assert(!FAILED(hr));
  252. }
  253. cb = sizeof(sz);
  254. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szUserAddr, NULL, &type, (LPBYTE)sz, &cb) &&
  255. !FIsEmpty(sz))
  256. {
  257. hr = pAcct->SetPropSz(AP_SMTP_EMAIL_ADDRESS, sz);
  258. Assert(!FAILED(hr));
  259. }
  260. cb = sizeof(sz);
  261. if (ERROR_SUCCESS == RegQueryValueEx(hkeyT, c_szReplyTo, NULL, &type, (LPBYTE)sz, &cb) &&
  262. !FIsEmpty(sz))
  263. {
  264. hr = pAcct->SetPropSz(AP_SMTP_REPLY_EMAIL_ADDRESS, sz);
  265. Assert(!FAILED(hr));
  266. }
  267. RegCloseKey(hkeyT);
  268. }
  269. RegCloseKey(hkey);
  270. }
  271. }
  272. if (pInfo != NULL)
  273. {
  274. // TODO: can we do any better than this???
  275. pInfo->dwConnect = CONN_USE_DEFAULT;
  276. }
  277. return(S_OK);
  278. }
  279. HRESULT STDMETHODCALLTYPE CNscpAcctImport::InitializeImport(HWND hwnd, DWORD_PTR dwCookie)
  280. {
  281. return(E_NOTIMPL);
  282. }
  283. HRESULT STDMETHODCALLTYPE CNscpAcctImport::GetNewsGroup(INewsGroupImport *pImp, DWORD dwReserved)
  284. {
  285. return(E_NOTIMPL);
  286. }
  287. CEnumNSCPACCTS::CEnumNSCPACCTS()
  288. {
  289. m_cRef = 1;
  290. // m_iInfo
  291. m_cInfo = 0;
  292. m_rgInfo = NULL;
  293. }
  294. CEnumNSCPACCTS::~CEnumNSCPACCTS()
  295. {
  296. if (m_rgInfo != NULL)
  297. MemFree(m_rgInfo);
  298. }
  299. STDMETHODIMP CEnumNSCPACCTS::QueryInterface(REFIID riid, LPVOID *ppv)
  300. {
  301. if (ppv == NULL)
  302. return(E_INVALIDARG);
  303. *ppv = NULL;
  304. if (IID_IUnknown == riid)
  305. *ppv = (IUnknown *)this;
  306. else if (IID_IEnumIMPACCOUNTS == riid)
  307. *ppv = (IEnumIMPACCOUNTS *)this;
  308. if (*ppv != NULL)
  309. ((LPUNKNOWN)*ppv)->AddRef();
  310. else
  311. return(E_NOINTERFACE);
  312. return(S_OK);
  313. }
  314. STDMETHODIMP_(ULONG) CEnumNSCPACCTS::AddRef()
  315. {
  316. return(++m_cRef);
  317. }
  318. STDMETHODIMP_(ULONG) CEnumNSCPACCTS::Release()
  319. {
  320. if (--m_cRef == 0)
  321. {
  322. delete this;
  323. return(0);
  324. }
  325. return(m_cRef);
  326. }
  327. HRESULT STDMETHODCALLTYPE CEnumNSCPACCTS::Next(IMPACCOUNTINFO *pinfo)
  328. {
  329. if (pinfo == NULL)
  330. return(E_INVALIDARG);
  331. m_iInfo++;
  332. if ((UINT)m_iInfo >= m_cInfo)
  333. return(S_FALSE);
  334. Assert(m_rgInfo != NULL);
  335. pinfo->dwCookie = m_rgInfo[m_iInfo].dwCookie;
  336. pinfo->dwReserved = 0;
  337. StrCpyN(pinfo->szDisplay, m_rgInfo[m_iInfo].szDisplay, ARRAYSIZE(pinfo->szDisplay));
  338. return(S_OK);
  339. }
  340. HRESULT STDMETHODCALLTYPE CEnumNSCPACCTS::Reset()
  341. {
  342. m_iInfo = -1;
  343. return(S_OK);
  344. }
  345. HRESULT CEnumNSCPACCTS::Init(NSCPACCTINFO *pinfo, int cinfo)
  346. {
  347. DWORD cb;
  348. Assert(pinfo != NULL);
  349. Assert(cinfo > 0);
  350. cb = cinfo * sizeof(NSCPACCTINFO);
  351. if (!MemAlloc((void **)&m_rgInfo, cb))
  352. return(E_OUTOFMEMORY);
  353. m_iInfo = -1;
  354. m_cInfo = cinfo;
  355. CopyMemory(m_rgInfo, pinfo, cb);
  356. return(S_OK);
  357. }