Source code of Windows XP (NT5)
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.

720 lines
22 KiB

  1. // service.cpp : Implementation of INntpVirtualServer
  2. #include "stdafx.h"
  3. #include "nntpcmn.h"
  4. #include "oleutil.h"
  5. #include "metautil.h"
  6. #include "service.h"
  7. // Must define THIS_FILE_* macros to use NntpCreateException()
  8. #define THIS_FILE_HELP_CONTEXT 0
  9. #define THIS_FILE_PROG_ID _T("Nntpadm.Service.1")
  10. #define THIS_FILE_IID IID_INntpService
  11. // Bitmasks for changed fields:
  12. #define CHNG_ARTICLETIMELIMIT 0x00000001
  13. #define CHNG_HISTORYEXPIRATION 0x00000002
  14. #define CHNG_HONORCLIENTMSGIDS 0x00000004
  15. #define CHNG_SMTPSERVER 0x00000008
  16. #define CHNG_ALLOWCLIENTPOSTS 0x00000010
  17. #define CHNG_ALLOWFEEDPOSTS 0x00000020
  18. #define CHNG_ALLOWCONTROLMSGS 0x00000040
  19. #define CHNG_DEFAULTMODERATORDOMAIN 0x00000080
  20. #define CHNG_COMMANDLOGMASK 0x00000100
  21. #define CHNG_DISABLENEWNEWS 0x00000200
  22. #define CHNG_EXPIRERUNFREQUENCY 0x00000400
  23. #define CHNG_SHUTDOWNLATENCY 0x00000800
  24. // Default Values:
  25. #define DEFAULT_ARTICLETIMELIMIT ( 1138 )
  26. #define DEFAULT_HISTORYEXPIRATION ( 1138 )
  27. #define DEFAULT_HONORCLIENTMSGIDS ( TRUE )
  28. #define DEFAULT_SMTPSERVER _T( "" )
  29. #define DEFAULT_ALLOWCLIENTPOSTS ( TRUE )
  30. #define DEFAULT_ALLOWFEEDPOSTS ( TRUE )
  31. #define DEFAULT_ALLOWCONTROLMSGS ( TRUE )
  32. #define DEFAULT_DEFAULTMODERATORDOMAIN _T( "" )
  33. #define DEFAULT_COMMANDLOGMASK ( (DWORD) -1 )
  34. #define DEFAULT_DISABLENEWNEWS ( FALSE )
  35. #define DEFAULT_EXPIRERUNFREQUENCY ( 1138 )
  36. #define DEFAULT_SHUTDOWNLATENCY ( 1138 )
  37. // Parameter ranges:
  38. #define MAXLEN_SERVER ( 256 )
  39. #define MIN_ARTICLETIMELIMIT ( (DWORD) 0 )
  40. #define MAX_ARTICLETIMELIMIT ( (DWORD) -1 )
  41. #define MIN_HISTORYEXPIRATION ( (DWORD) 0 )
  42. #define MAX_HISTORYEXPIRATION ( (DWORD) -1 )
  43. #define MAXLEN_SMTPSERVER ( 256 )
  44. #define MAXLEN_DEFAULTMODERATORDOMAIN ( 256 )
  45. #define MIN_COMMANDLOGMASK ( (DWORD) 0 )
  46. #define MAX_COMMANDLOGMASK ( (DWORD) -1 )
  47. #define MIN_EXPIRERUNFREQUENCY ( (DWORD) 1 )
  48. #define MAX_EXPIRERUNFREQUENCY ( (DWORD) -1 )
  49. #define MIN_SHUTDOWNLATENCY ( (DWORD) 1 )
  50. #define MAX_SHUTDOWNLATENCY ( (DWORD) -1 )
  51. /////////////////////////////////////////////////////////////////////////////
  52. //
  53. STDMETHODIMP CNntpAdminService::InterfaceSupportsErrorInfo(REFIID riid)
  54. {
  55. static const IID* arr[] =
  56. {
  57. &IID_INntpService,
  58. };
  59. for (int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
  60. {
  61. if (InlineIsEqualGUID(*arr[i],riid))
  62. return S_OK;
  63. }
  64. return S_FALSE;
  65. }
  66. CNntpAdminService::CNntpAdminService () :
  67. m_dwArticleTimeLimit ( 0 ),
  68. m_dwHistoryExpiration ( 0 ),
  69. m_fHonorClientMsgIDs ( FALSE ),
  70. m_fAllowClientPosts ( FALSE ),
  71. m_fAllowFeedPosts ( FALSE ),
  72. m_fAllowControlMsgs ( FALSE ),
  73. m_dwCommandLogMask ( 0 ),
  74. m_fDisableNewnews ( FALSE ),
  75. m_dwExpireRunFrequency ( 0 ),
  76. m_dwShutdownLatency ( 0 ),
  77. m_fGotProperties ( FALSE ),
  78. m_bvChangedFields ( 0 )
  79. // CComBSTR's are initialized to NULL by default.
  80. {
  81. m_ftLastChanged.dwHighDateTime = 0;
  82. m_ftLastChanged.dwLowDateTime = 0;
  83. InitAsyncTrace ( );
  84. }
  85. CNntpAdminService::~CNntpAdminService ()
  86. {
  87. // All CComBSTR's are freed automatically.
  88. TermAsyncTrace ( );
  89. }
  90. // Which Server to configure:
  91. STDMETHODIMP CNntpAdminService::get_Server ( BSTR * pstrServer )
  92. {
  93. return StdPropertyGet ( m_strServer, pstrServer );
  94. }
  95. STDMETHODIMP CNntpAdminService::put_Server ( BSTR strServer )
  96. {
  97. // If the server name changes, that means the client will have to
  98. // call Get again:
  99. // I assume this here:
  100. _ASSERT ( sizeof (DWORD) == sizeof (int) );
  101. return StdPropertyPutServerName ( &m_strServer, strServer, (DWORD *) &m_fGotProperties, 1 );
  102. }
  103. // Server Properties:
  104. STDMETHODIMP CNntpAdminService::get_ArticleTimeLimit ( long * plArticleTimeLimit )
  105. {
  106. return StdPropertyGet ( m_dwArticleTimeLimit, plArticleTimeLimit );
  107. }
  108. STDMETHODIMP CNntpAdminService::put_ArticleTimeLimit ( long lArticleTimeLimit )
  109. {
  110. return StdPropertyPut ( &m_dwArticleTimeLimit, lArticleTimeLimit, &m_bvChangedFields, CHNG_ARTICLETIMELIMIT );
  111. }
  112. STDMETHODIMP CNntpAdminService::get_HistoryExpiration ( long * plHistoryExpiration )
  113. {
  114. return StdPropertyGet ( m_dwHistoryExpiration, plHistoryExpiration );
  115. }
  116. STDMETHODIMP CNntpAdminService::put_HistoryExpiration ( long lHistoryExpiration )
  117. {
  118. return StdPropertyPut ( &m_dwHistoryExpiration, lHistoryExpiration, &m_bvChangedFields, CHNG_HISTORYEXPIRATION );
  119. }
  120. STDMETHODIMP CNntpAdminService::get_HonorClientMsgIDs ( BOOL * pfHonorClientMsgIDs )
  121. {
  122. return StdPropertyGet ( m_fHonorClientMsgIDs, pfHonorClientMsgIDs );
  123. }
  124. STDMETHODIMP CNntpAdminService::put_HonorClientMsgIDs ( BOOL fHonorClientMsgIDs )
  125. {
  126. return StdPropertyPut ( &m_fHonorClientMsgIDs, fHonorClientMsgIDs, &m_bvChangedFields, CHNG_HONORCLIENTMSGIDS );
  127. }
  128. STDMETHODIMP CNntpAdminService::get_SmtpServer ( BSTR * pstrSmtpServer )
  129. {
  130. return StdPropertyGet ( m_strSmtpServer, pstrSmtpServer );
  131. }
  132. STDMETHODIMP CNntpAdminService::put_SmtpServer ( BSTR strSmtpServer )
  133. {
  134. return StdPropertyPut ( &m_strSmtpServer, strSmtpServer, &m_bvChangedFields, CHNG_SMTPSERVER );
  135. }
  136. STDMETHODIMP CNntpAdminService::get_AllowClientPosts ( BOOL * pfAllowClientPosts )
  137. {
  138. return StdPropertyGet ( m_fAllowClientPosts, pfAllowClientPosts );
  139. }
  140. STDMETHODIMP CNntpAdminService::put_AllowClientPosts ( BOOL fAllowClientPosts )
  141. {
  142. return StdPropertyPut ( &m_fAllowClientPosts, fAllowClientPosts, &m_bvChangedFields, CHNG_ALLOWCLIENTPOSTS );
  143. }
  144. STDMETHODIMP CNntpAdminService::get_AllowFeedPosts ( BOOL * pfAllowFeedPosts )
  145. {
  146. return StdPropertyGet ( m_fAllowFeedPosts, pfAllowFeedPosts );
  147. }
  148. STDMETHODIMP CNntpAdminService::put_AllowFeedPosts ( BOOL fAllowFeedPosts )
  149. {
  150. return StdPropertyPut ( &m_fAllowFeedPosts, fAllowFeedPosts, &m_bvChangedFields, CHNG_ALLOWFEEDPOSTS );
  151. }
  152. STDMETHODIMP CNntpAdminService::get_AllowControlMsgs ( BOOL * pfAllowControlMsgs )
  153. {
  154. return StdPropertyGet ( m_fAllowControlMsgs, pfAllowControlMsgs );
  155. }
  156. STDMETHODIMP CNntpAdminService::put_AllowControlMsgs ( BOOL fAllowControlMsgs )
  157. {
  158. return StdPropertyPut ( &m_fAllowControlMsgs, fAllowControlMsgs, &m_bvChangedFields, CHNG_ALLOWCONTROLMSGS );
  159. }
  160. STDMETHODIMP CNntpAdminService::get_DefaultModeratorDomain ( BSTR * pstrDefaultModeratorDomain )
  161. {
  162. return StdPropertyGet ( m_strDefaultModeratorDomain, pstrDefaultModeratorDomain );
  163. }
  164. STDMETHODIMP CNntpAdminService::put_DefaultModeratorDomain ( BSTR strDefaultModeratorDomain )
  165. {
  166. return StdPropertyPut ( &m_strDefaultModeratorDomain, strDefaultModeratorDomain, &m_bvChangedFields, CHNG_DEFAULTMODERATORDOMAIN );
  167. }
  168. STDMETHODIMP CNntpAdminService::get_CommandLogMask ( long * plCommandLogMask )
  169. {
  170. return StdPropertyGet ( m_dwCommandLogMask, plCommandLogMask );
  171. }
  172. STDMETHODIMP CNntpAdminService::put_CommandLogMask ( long lCommandLogMask )
  173. {
  174. return StdPropertyPut ( &m_dwCommandLogMask, lCommandLogMask, &m_bvChangedFields, CHNG_COMMANDLOGMASK );
  175. }
  176. STDMETHODIMP CNntpAdminService::get_DisableNewnews ( BOOL * pfDisableNewnews )
  177. {
  178. return StdPropertyGet ( m_fDisableNewnews, pfDisableNewnews );
  179. }
  180. STDMETHODIMP CNntpAdminService::put_DisableNewnews ( BOOL fDisableNewnews )
  181. {
  182. return StdPropertyPut ( &m_fDisableNewnews, fDisableNewnews, &m_bvChangedFields, CHNG_DISABLENEWNEWS );
  183. }
  184. STDMETHODIMP CNntpAdminService::get_ExpireRunFrequency ( long * plExpireRunFrequency )
  185. {
  186. return StdPropertyGet ( m_dwExpireRunFrequency, plExpireRunFrequency );
  187. }
  188. STDMETHODIMP CNntpAdminService::put_ExpireRunFrequency ( long lExpireRunFrequency )
  189. {
  190. return StdPropertyPut ( &m_dwExpireRunFrequency, lExpireRunFrequency, &m_bvChangedFields, CHNG_EXPIRERUNFREQUENCY );
  191. }
  192. STDMETHODIMP CNntpAdminService::get_ShutdownLatency ( long * plShutdownLatency )
  193. {
  194. return StdPropertyGet ( m_dwShutdownLatency, plShutdownLatency );
  195. }
  196. STDMETHODIMP CNntpAdminService::put_ShutdownLatency ( long lShutdownLatency )
  197. {
  198. return StdPropertyPut ( &m_dwShutdownLatency, lShutdownLatency, &m_bvChangedFields, CHNG_SHUTDOWNLATENCY );
  199. }
  200. //////////////////////////////////////////////////////////////////////
  201. // Methods:
  202. //////////////////////////////////////////////////////////////////////
  203. //$-------------------------------------------------------------------
  204. //
  205. // CNntpAdminService::Get
  206. //
  207. // Description:
  208. //
  209. // Gets server properties from the metabase.
  210. //
  211. // Parameters:
  212. //
  213. // (property) m_strServer
  214. // pErr - Resulting error code. This can be translated to a
  215. // string through the INntpAdmin interface.
  216. //
  217. // Returns:
  218. //
  219. // E_POINTER, DISP_E_EXCEPTION, E_OUTOFMEMORY or NOERROR.
  220. // Additional error conditions are returned through the pErr value.
  221. //
  222. //--------------------------------------------------------------------
  223. STDMETHODIMP CNntpAdminService::Get ( )
  224. {
  225. TraceFunctEnter ( "CNntpAdminService::Get" );
  226. HRESULT hr = NOERROR;
  227. CComPtr<IMSAdminBase> pmetabase;
  228. // Validate Server & Service Instance:
  229. // Talk to the metabase:
  230. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  231. if ( FAILED(hr) ) {
  232. goto Exit;
  233. }
  234. hr = GetPropertiesFromMetabase ( pmetabase );
  235. if ( FAILED(hr) ) {
  236. goto Exit;
  237. }
  238. StateTrace ( 0, "Successfully got server properties" );
  239. m_fGotProperties = TRUE;
  240. m_bvChangedFields = 0;
  241. Exit:
  242. TRACE_HRESULT(hr);
  243. TraceFunctLeave ();
  244. return hr;
  245. // CComPtr automatically releases the metabase handle.
  246. }
  247. //$-------------------------------------------------------------------
  248. //
  249. // CNntpAdminService::Set
  250. //
  251. // Description:
  252. //
  253. // Sends server properties to the metabase.
  254. //
  255. // Parameters:
  256. //
  257. // (property) m_strServer
  258. // fFailIfChanged - return an error if the metabase has changed?
  259. // pErr - Resulting error code. This can be translated to a
  260. // string through the INntpAdmin interface.
  261. //
  262. // Returns:
  263. //
  264. // E_POINTER, DISP_E_EXCEPTION, E_OUTOFMEMORY or NOERROR.
  265. // Additional error conditions are returned through the pErr value.
  266. //
  267. //--------------------------------------------------------------------
  268. STDMETHODIMP CNntpAdminService::Set ( BOOL fFailIfChanged)
  269. {
  270. TraceFunctEnter ( "CNntpAdminService::Set" );
  271. HRESULT hr = NOERROR;
  272. CComPtr<IMSAdminBase> pmetabase;
  273. // Make sure the client call Get first:
  274. if ( !m_fGotProperties ) {
  275. ErrorTrace ( 0, "Didn't call get first" );
  276. hr = NntpCreateException ( IDS_NNTPEXCEPTION_DIDNT_CALL_GET );
  277. goto Exit;
  278. }
  279. // Validate data members:
  280. if ( !ValidateStrings () ) {
  281. // !!!magnush - what about the case when any strings are NULL?
  282. hr = E_FAIL;
  283. goto Exit;
  284. }
  285. if ( !ValidateProperties ( ) ) {
  286. hr = RETURNCODETOHRESULT ( ERROR_INVALID_PARAMETER );
  287. goto Exit;
  288. }
  289. hr = m_mbFactory.GetMetabaseObject ( m_strServer, &pmetabase );
  290. if ( FAILED(hr) ) {
  291. goto Exit;
  292. }
  293. hr = SendPropertiesToMetabase ( fFailIfChanged, pmetabase );
  294. if ( FAILED(hr) ) {
  295. goto Exit;
  296. }
  297. StateTrace ( 0, "Successfully set server properties" );
  298. Exit:
  299. TRACE_HRESULT(hr);
  300. TraceFunctLeave ();
  301. return hr;
  302. }
  303. //$-------------------------------------------------------------------
  304. //
  305. // CNntpAdminService::GetPropertiesFromMetabase
  306. //
  307. // Description:
  308. //
  309. // Asks the metabase for each property in this class.
  310. // This class's properties come from /LM/NntpSvc/
  311. //
  312. // Parameters:
  313. //
  314. // pMetabase - The metabase object
  315. // pErr - Resulting error code.
  316. //
  317. // Returns:
  318. //
  319. // E_OUTOFMEMORY or an error code in pErr.
  320. //
  321. //--------------------------------------------------------------------
  322. HRESULT CNntpAdminService::GetPropertiesFromMetabase ( IMSAdminBase * pMetabase)
  323. {
  324. TraceFunctEnter ( "CNntpAdminService::GetPropertiesFromMetabase" );
  325. HRESULT hr = NOERROR;
  326. CMetabaseKey metabase ( pMetabase );
  327. BOOL fRet;
  328. hr = metabase.Open ( NNTP_MD_ROOT_PATH );
  329. if ( FAILED(hr) ) {
  330. ErrorTraceX ( (LPARAM) this, "Failed to open NntpSvc key, %x", hr );
  331. // Return some kind of error code here:
  332. // hr = RETURNCODETOHRESULT ( GetLastError () );
  333. goto Exit;
  334. }
  335. fRet = TRUE;
  336. fRet = StdGetMetabaseProp ( &metabase, MD_ARTICLE_TIME_LIMIT, DEFAULT_ARTICLETIMELIMIT, &m_dwArticleTimeLimit ) && fRet;
  337. fRet = StdGetMetabaseProp ( &metabase, MD_HISTORY_EXPIRATION, DEFAULT_HISTORYEXPIRATION, &m_dwHistoryExpiration ) && fRet;
  338. fRet = StdGetMetabaseProp ( &metabase, MD_HONOR_CLIENT_MSGIDS, DEFAULT_HONORCLIENTMSGIDS, &m_fHonorClientMsgIDs ) && fRet;
  339. fRet = StdGetMetabaseProp ( &metabase, MD_SMTP_SERVER, DEFAULT_SMTPSERVER, &m_strSmtpServer ) && fRet;
  340. fRet = StdGetMetabaseProp ( &metabase, MD_ALLOW_CLIENT_POSTS, DEFAULT_ALLOWCLIENTPOSTS, &m_fAllowClientPosts ) && fRet;
  341. fRet = StdGetMetabaseProp ( &metabase, MD_ALLOW_FEED_POSTS, DEFAULT_ALLOWFEEDPOSTS, &m_fAllowFeedPosts ) && fRet;
  342. fRet = StdGetMetabaseProp ( &metabase, MD_ALLOW_CONTROL_MSGS, DEFAULT_ALLOWCONTROLMSGS, &m_fAllowControlMsgs ) && fRet;
  343. fRet = StdGetMetabaseProp ( &metabase, MD_DEFAULT_MODERATOR, DEFAULT_DEFAULTMODERATORDOMAIN, &m_strDefaultModeratorDomain ) && fRet;
  344. fRet = StdGetMetabaseProp ( &metabase, MD_NNTP_COMMAND_LOG_MASK,DEFAULT_COMMANDLOGMASK, &m_dwCommandLogMask ) && fRet;
  345. fRet = StdGetMetabaseProp ( &metabase, MD_DISABLE_NEWNEWS, DEFAULT_DISABLENEWNEWS, &m_fDisableNewnews ) && fRet;
  346. fRet = StdGetMetabaseProp ( &metabase, MD_NEWS_CRAWLER_TIME, DEFAULT_EXPIRERUNFREQUENCY, &m_dwExpireRunFrequency ) && fRet;
  347. fRet = StdGetMetabaseProp ( &metabase, MD_SHUTDOWN_LATENCY, DEFAULT_SHUTDOWNLATENCY, &m_dwShutdownLatency ) && fRet;
  348. // Check all property strings:
  349. // If any string is NULL, it is because we failed to allocate memory:
  350. if ( !ValidateStrings () ) {
  351. hr = E_OUTOFMEMORY;
  352. goto Exit;
  353. }
  354. // We can only fail from memory allocations:
  355. _ASSERT ( fRet );
  356. // Save the last changed time for this key:
  357. m_ftLastChanged.dwHighDateTime = 0;
  358. m_ftLastChanged.dwLowDateTime = 0;
  359. hr = pMetabase->GetLastChangeTime ( metabase.QueryHandle(), (BYTE *) "", &m_ftLastChanged, FALSE );
  360. if ( FAILED (hr) ) {
  361. ErrorTraceX ( (LPARAM) this, "Failed to get last change time: %x", hr );
  362. // Ignore this error.
  363. hr = NOERROR;
  364. }
  365. // Validate the data received from the metabase:
  366. _ASSERT ( ValidateStrings () );
  367. _ASSERT ( ValidateProperties( ) );
  368. if ( !ValidateProperties( ) ) {
  369. CorrectProperties ();
  370. }
  371. Exit:
  372. TraceFunctLeave ();
  373. return hr;
  374. // MB automatically closes its handle
  375. }
  376. //$-------------------------------------------------------------------
  377. //
  378. // CNntpAdminService::SendPropertiesToMetabase
  379. //
  380. // Description:
  381. //
  382. // Saves each property to the metabase.
  383. // This class's properties go into /LM/NntpSvc/
  384. //
  385. // Parameters:
  386. //
  387. // fFailIfChanged - Return a failure code if the metabase
  388. // has changed since last get.
  389. // pMetabase - the metabase object.
  390. // pErr - resulting error code.
  391. //
  392. // Returns:
  393. //
  394. // E_OUTOFMEMORY or resulting error code in pErr.
  395. //
  396. //--------------------------------------------------------------------
  397. HRESULT CNntpAdminService::SendPropertiesToMetabase (
  398. BOOL fFailIfChanged,
  399. IMSAdminBase * pMetabase
  400. )
  401. {
  402. TraceFunctEnter ( "CNntpAdminService::SendPropertiesToMetabase" );
  403. HRESULT hr = NOERROR;
  404. CMetabaseKey metabase ( pMetabase );
  405. hr = metabase.Open ( (CHAR *) NNTP_MD_ROOT_PATH, METADATA_PERMISSION_WRITE );
  406. if ( FAILED(hr) ) {
  407. ErrorTraceX ( (LPARAM) this, "Failed to open NntpSvc key, %x", hr );
  408. // hr = RETURNCODETOHRESULT ( GetLastError () );
  409. goto Exit;
  410. }
  411. // Does the client care if the key has changed?
  412. if ( fFailIfChanged ) {
  413. // Did the key change?
  414. if ( HasKeyChanged ( pMetabase, metabase.QueryHandle(), &m_ftLastChanged ) ) {
  415. StateTrace ( (LPARAM) this, "Metabase has changed, not setting properties" );
  416. // !!!magnush - Return the appropriate error code:
  417. hr = E_FAIL;
  418. goto Exit;
  419. }
  420. }
  421. //
  422. // The general procedure here is to keep setting metabase properties
  423. // as long as nothing has gone wrong. This is done by short-circuiting
  424. // the statement by ANDing it with the status code. This makes the code
  425. // much more concise.
  426. //
  427. fRet = TRUE;
  428. if ( m_bvChangedFields & CHNG_ARTICLETIMELIMIT ) {
  429. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_ARTICLE_TIME_LIMIT, m_dwArticleTimeLimit );
  430. }
  431. if ( m_bvChangedFields & CHNG_HISTORYEXPIRATION ) {
  432. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_HISTORY_EXPIRATION, m_dwHistoryExpiration );
  433. }
  434. if ( m_bvChangedFields & CHNG_HONORCLIENTMSGIDS ) {
  435. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_HONOR_CLIENT_MSGIDS, m_fHonorClientMsgIDs );
  436. }
  437. if ( m_bvChangedFields & CHNG_SMTPSERVER ) {
  438. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_SMTP_SERVER, m_strSmtpServer );
  439. }
  440. if ( m_bvChangedFields & CHNG_ALLOWCLIENTPOSTS ) {
  441. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_ALLOW_CLIENT_POSTS, m_fAllowClientPosts );
  442. }
  443. if ( m_bvChangedFields & CHNG_ALLOWFEEDPOSTS ) {
  444. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_ALLOW_FEED_POSTS, m_fAllowFeedPosts );
  445. }
  446. if ( m_bvChangedFields & CHNG_ALLOWCONTROLMSGS ) {
  447. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_ALLOW_CONTROL_MSGS, m_fAllowControlMsgs );
  448. }
  449. if ( m_bvChangedFields & CHNG_DEFAULTMODERATORDOMAIN ) {
  450. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_DEFAULT_MODERATOR, m_strDefaultModeratorDomain );
  451. }
  452. if ( m_bvChangedFields & CHNG_COMMANDLOGMASK ) {
  453. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_NNTP_COMMAND_LOG_MASK,m_dwCommandLogMask );
  454. }
  455. if ( m_bvChangedFields & CHNG_DISABLENEWNEWS ) {
  456. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_DISABLE_NEWNEWS, m_fDisableNewnews );
  457. }
  458. if ( m_bvChangedFields & CHNG_EXPIRERUNFREQUENCY ) {
  459. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_NEWS_CRAWLER_TIME, m_dwExpireRunFrequency );
  460. }
  461. if ( m_bvChangedFields & CHNG_SHUTDOWNLATENCY ) {
  462. fRet = fRet && StdPutMetabaseProp ( &metabase, MD_SHUTDOWN_LATENCY, m_dwShutdownLatency );
  463. }
  464. if ( !fRet ) {
  465. hr = RETURNCODETOHRESULT ( GetLastError () );
  466. }
  467. // Save the data to the metabase:
  468. hr = metabase.Save ();
  469. BAIL_ON_FAILURE(hr);
  470. // Save the last changed time for this key:
  471. m_ftLastChanged.dwHighDateTime = 0;
  472. m_ftLastChanged.dwLowDateTime = 0;
  473. hr = pMetabase->GetLastChangeTime ( metabase.QueryHandle(), (BYTE *) "", &m_ftLastChanged, FALSE );
  474. if ( FAILED (hr) ) {
  475. ErrorTraceX ( (LPARAM) this, "Failed to get last change time: %x", hr );
  476. // Ignore this error.
  477. hr = NOERROR;
  478. }
  479. Exit:
  480. TraceFunctLeave ();
  481. return hr;
  482. // MB automatically closes its handle
  483. }
  484. //$-------------------------------------------------------------------
  485. //
  486. // CNntpAdminService::ValidateStrings
  487. //
  488. // Description:
  489. //
  490. // Checks to make sure each string property is non-null.
  491. //
  492. // Returns:
  493. //
  494. // FALSE if any string property is NULL.
  495. //
  496. //--------------------------------------------------------------------
  497. BOOL CNntpAdminService::ValidateStrings ( ) const
  498. {
  499. TraceFunctEnter ( "CNntpAdminService::ValidateStrings" );
  500. // Check all property strings:
  501. // If any string is NULL, return FALSE:
  502. if (
  503. !m_strSmtpServer ||
  504. !m_strDefaultModeratorDomain
  505. ) {
  506. ErrorTrace ( (LPARAM) this, "String validation failed" );
  507. TraceFunctLeave ();
  508. return FALSE;
  509. }
  510. _ASSERT ( IS_VALID_STRING ( m_strSmtpServer ) );
  511. _ASSERT ( IS_VALID_STRING ( m_strDefaultModeratorDomain ) );
  512. TraceFunctLeave ();
  513. return TRUE;
  514. }
  515. //$-------------------------------------------------------------------
  516. //
  517. // CNntpAdminService::ValidateProperties
  518. //
  519. // Description:
  520. //
  521. // Checks to make sure all parameters are valid.
  522. //
  523. // Parameters:
  524. //
  525. // pErr - resulting error code.
  526. //
  527. // Returns:
  528. //
  529. // FALSE if any property was not valid. In this case pErr
  530. // will contain an error that describes the invalid condition.
  531. //
  532. //--------------------------------------------------------------------
  533. BOOL CNntpAdminService::ValidateProperties ( ) const
  534. {
  535. BOOL fRet = TRUE;
  536. _ASSERT ( ValidateStrings () );
  537. fRet = fRet && PV_MinMax ( m_dwArticleTimeLimit, MIN_ARTICLETIMELIMIT, MAX_ARTICLETIMELIMIT );
  538. fRet = fRet && PV_MinMax ( m_dwHistoryExpiration, MIN_HISTORYEXPIRATION, MAX_HISTORYEXPIRATION );
  539. fRet = fRet && PV_Boolean ( m_fHonorClientMsgIDs );
  540. fRet = fRet && PV_MaxChars ( m_strSmtpServer, MAXLEN_SMTPSERVER );
  541. fRet = fRet && PV_Boolean ( m_fAllowClientPosts );
  542. fRet = fRet && PV_Boolean ( m_fAllowFeedPosts );
  543. fRet = fRet && PV_Boolean ( m_fAllowControlMsgs );
  544. fRet = fRet && PV_MaxChars ( m_strDefaultModeratorDomain, MAXLEN_DEFAULTMODERATORDOMAIN );
  545. fRet = fRet && PV_MinMax ( m_dwCommandLogMask, MIN_COMMANDLOGMASK, MAX_COMMANDLOGMASK );
  546. fRet = fRet && PV_Boolean ( m_fDisableNewnews );
  547. fRet = fRet && PV_MinMax ( m_dwExpireRunFrequency, MIN_EXPIRERUNFREQUENCY, MAX_EXPIRERUNFREQUENCY );
  548. fRet = fRet && PV_MinMax ( m_dwShutdownLatency, MIN_SHUTDOWNLATENCY, MAX_SHUTDOWNLATENCY );
  549. return fRet;
  550. }
  551. void CNntpAdminService::CorrectProperties ( )
  552. {
  553. if ( m_strServer && !PV_MaxChars ( m_strServer, MAXLEN_SERVER ) ) {
  554. m_strServer[ MAXLEN_SERVER - 1 ] = NULL;
  555. }
  556. if ( !PV_MinMax ( m_dwArticleTimeLimit, MIN_ARTICLETIMELIMIT, MAX_ARTICLETIMELIMIT ) ) {
  557. m_dwArticleTimeLimit = DEFAULT_ARTICLETIMELIMIT;
  558. }
  559. if ( !PV_MinMax ( m_dwHistoryExpiration, MIN_HISTORYEXPIRATION, MAX_HISTORYEXPIRATION ) ) {
  560. m_dwHistoryExpiration = DEFAULT_HISTORYEXPIRATION;
  561. }
  562. if ( !PV_Boolean ( m_fHonorClientMsgIDs ) ) {
  563. m_fHonorClientMsgIDs = !!m_fHonorClientMsgIDs;
  564. }
  565. if ( !PV_MaxChars ( m_strSmtpServer, MAXLEN_SMTPSERVER ) ) {
  566. m_strSmtpServer[ MAXLEN_SMTPSERVER - 1 ] = NULL;
  567. }
  568. if ( !PV_Boolean ( m_fAllowClientPosts ) ) {
  569. m_fAllowClientPosts = !!m_fAllowClientPosts;
  570. }
  571. if ( !PV_Boolean ( m_fAllowFeedPosts ) ) {
  572. m_fAllowFeedPosts = !!m_fAllowFeedPosts;
  573. }
  574. if ( !PV_Boolean ( m_fAllowControlMsgs ) ) {
  575. m_fAllowControlMsgs = !!m_fAllowControlMsgs;
  576. }
  577. if ( !PV_MaxChars ( m_strDefaultModeratorDomain, MAXLEN_DEFAULTMODERATORDOMAIN ) ) {
  578. m_strDefaultModeratorDomain[ MAXLEN_DEFAULTMODERATORDOMAIN - 1] = NULL;
  579. }
  580. if ( !PV_MinMax ( m_dwCommandLogMask, MIN_COMMANDLOGMASK, MAX_COMMANDLOGMASK ) ) {
  581. m_dwCommandLogMask = DEFAULT_COMMANDLOGMASK;
  582. }
  583. if ( !PV_Boolean ( m_fDisableNewnews ) ) {
  584. m_fDisableNewnews = !!m_fDisableNewnews;
  585. }
  586. if ( !PV_MinMax ( m_dwExpireRunFrequency, MIN_EXPIRERUNFREQUENCY, MAX_EXPIRERUNFREQUENCY ) ) {
  587. m_dwExpireRunFrequency = DEFAULT_EXPIRERUNFREQUENCY;
  588. }
  589. if ( !PV_MinMax ( m_dwShutdownLatency, MIN_SHUTDOWNLATENCY, MAX_SHUTDOWNLATENCY ) ) {
  590. m_dwShutdownLatency = DEFAULT_SHUTDOWNLATENCY;
  591. }
  592. _ASSERT ( ValidateProperties ( ) );
  593. }