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.

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