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.

761 lines
19 KiB

  1. /********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990,1991 **/
  4. /********************************************************************/
  5. /*
  6. newprof.hxx
  7. INI-file handling primitives
  8. These classes deal with simple INI files. Most clients will prefer
  9. to use the wrapper APIs in newprof.h, including all C clients.
  10. The wrapper APIs provide almost all the functionality of the C++
  11. APIs. The C++ APIs are more subject to change with changing
  12. implementation (NT configuration manager, DS) than are the C-language
  13. wrappers.
  14. Clients needing to support more complex manipulation on more complex
  15. text files may prefer the CFGFILE class hierarchy defined in
  16. cfgfile.hxx. These classes require more code overhead, but will
  17. provide more sophisticated support to overcome the following
  18. restrictions of the classes defined here:
  19. -- All lines must be either component headers ("[component]") or
  20. parameter-value lines ("param=value"). Other lines will be
  21. ignored and will not be written back out.
  22. -- If two components share the same name, or if two parameters in a
  23. component share the same name, the second will be inaccessible
  24. until the first is deleted.
  25. -- These classes ignore whitespace except as part of a parameter
  26. name or value. They make no attempt to preserve it, even on
  27. lines which are not manipulated.
  28. These classes are defined in terms of CPSZ because NETLIB requires
  29. character pointers to be explicitly far.
  30. Note that all component name comparisons and parameter name
  31. comparisons are case-insensitive. This may not apply to parameter
  32. values, see the parameter type (INI_PARAM subclass) for details.
  33. FILE HISTORY
  34. jonn 29-May-1991 Created
  35. */
  36. #ifndef _NEWPROF_HXX_
  37. #define _NEWPROF_HXX_
  38. #include <base.hxx>
  39. /* Global constants and defines */
  40. extern "C"
  41. {
  42. #include <newprofc.h>
  43. }
  44. /*
  45. The internal include file contains stuff which needs to go before the
  46. class definition of INI_FILE_IMAGE, but which clients of this class
  47. don't need to know about.
  48. */
  49. #include <newprofi.hxx>
  50. /*************************************************************************
  51. NAME: INI_FILE_IMAGE
  52. SYNOPSIS: Stores an image of a single INI file, including component
  53. names, parameter names, and parameter values. Ignores blank
  54. lines, comments, whitespace, and all lines not of either
  55. "[section]" or "key = value" form.
  56. INTERFACE: INI_FILE_IMAGE() - Constructs a blank file image and
  57. remembers the specified filename.
  58. ~INI_FILE_IMAGE() - Destructs a file image.
  59. Read() - Reads the file image from the remembered file.
  60. Write() - Writes the file image to the remembered file.
  61. The following members are meant for use of the
  62. INI_PARAM classes rather than for external
  63. clients.
  64. QueryParam() - Asks after an individual parameter
  65. SetParam() - Changes an individual parameter value
  66. Clear() - Clears the file image
  67. FindComponent() - Finds the first component with the
  68. specified name
  69. RemoveComponent() - Removes the specified component
  70. SetFilename() - Change the remembered filename
  71. Trim() - Remove all but named component
  72. PARENT: BASE
  73. CAVEATS: Clients may not use the QueryParam and SetParam methods;
  74. these are for the use of the INI_PARAM classes.
  75. INI_FILE_IMAGE does not in general provide support for
  76. multiple parameters with the same name.
  77. NOTES: Most clients should use the wrappers to these classes supplied
  78. in newprof.h. Otherwise, LMUSER.INI clients should use the
  79. LMINI_FILE_IMAGE subclass.
  80. HISTORY:
  81. jonn 29-May-1991 Created
  82. *************************************************************************/
  83. DLL_CLASS INI_PARAM;
  84. DLL_CLASS LMINI_PARAM;
  85. DLL_CLASS INI_ITER;
  86. DLL_CLASS INI_FILE_IMAGE: public BASE
  87. {
  88. friend INI_PARAM;
  89. friend LMINI_PARAM; // must have access to SetParam
  90. friend INI_ITER; // must have access to _slcomponent
  91. private:
  92. TCHAR * _pchFilename;
  93. /*
  94. Clients do not need to know about this member object.
  95. COMPONENT is defined in newprofi.hxx.
  96. */
  97. SLIST_OF(COMPONENT) _slcomponent;
  98. APIERR QueryParam(
  99. CPSZ pchComponent,
  100. CPSZ pchParameter,
  101. BYTE * pbBuffer,
  102. USHORT cbBuffer
  103. ) const;
  104. APIERR SetParam(
  105. CPSZ pchComponent,
  106. CPSZ pchParameter,
  107. CPSZ pchValue
  108. );
  109. VOID Clear();
  110. COMPONENT * FindComponent(
  111. CPSZ pchComponent
  112. ) const;
  113. COMPONENT * RemoveComponent(
  114. COMPONENT * pcomponent
  115. ) const;
  116. protected:
  117. APIERR SetFilename( CPSZ pchFilename );
  118. public:
  119. INI_FILE_IMAGE( CPSZ pchFilename );
  120. ~INI_FILE_IMAGE();
  121. APIERR Read();
  122. APIERR Write() const;
  123. APIERR Trim( CPSZ pchComponent );
  124. };
  125. /*************************************************************************
  126. NAME: LMINI_FILE_IMAGE
  127. SYNOPSIS: Stores an image of the INI file used by the LanMan
  128. interface, for the file LANROOT\LMUSER.INI. This is a
  129. thin shell over INI_FILE_IMAGE, which uses WKSTA_1 to
  130. determine LANROOT.
  131. INTERFACE: LMINI_FILE_IMAGE() - Creates a blank file image.
  132. PARENT: INI_FILE_IMAGE
  133. NOTES: Most clients should use the wrappers to these
  134. classes supplied in newprof.h.
  135. HISTORY:
  136. jonn 30-May-1991 Created
  137. *************************************************************************/
  138. DLL_CLASS LMINI_FILE_IMAGE: public INI_FILE_IMAGE
  139. {
  140. public:
  141. LMINI_FILE_IMAGE();
  142. };
  143. /*************************************************************************
  144. NAME: INI_PARAM
  145. SYNOPSIS: Stores an image of a single parameter in an INI file.
  146. The INI_PARAM will remember the name of the component
  147. and the parameter, as well as the value of the
  148. parameter.
  149. The image of the parameter is stored independently of
  150. the INI_FILE_IMAGE; thus clients may delete the file
  151. image while keeping the parameter image, transfer the
  152. parameter image from one file image to another, etc.
  153. This class is meant as a superclass for more strongly
  154. typed parameter classes, and generally cannot be
  155. directly instantiated. Clients should avoid
  156. invoking INI_PARAM methods on objects of a subclass
  157. which redefines those methods, as this may leave the
  158. parameter with an invalid value for the parameter type
  159. defined by the subclass.
  160. INTERFACE: INI_PARAM()
  161. ~INI_PARAM()
  162. Load() - Loads the parameter value from an
  163. INI_FILE_IMAGE
  164. Set() - Changes the parameter value
  165. QueryValue() - Asks after the parameter value
  166. Store() - Stores the parameter into an
  167. INI_FILE_IMAGE
  168. Remove() - Removes this parameter from a file image
  169. PARENT: BASE
  170. CAVEATS: Clients should not instantiate objects of type INI_PARAM;
  171. they should use the subclasses instead. Clients should
  172. not override methods redefined by descendant classes of
  173. INI_PARAM with methods of INI_PARAM.
  174. It is possible to instantiate a blank INI_PARAM, but
  175. this is generally not possible for its descendant
  176. classes. The descendant classes generally combine their
  177. constructors with Load() or Set() operations.
  178. NOTES: Most clients should use the wrappers to these
  179. routines supplied in newprof.h.
  180. Users interested only in a single parameter should use
  181. the LMINI_PARAM methods QuickLoad() and QuickStore()
  182. instead of the corresponding LMINI_FILE_IMAGE operations.
  183. These methods are easier to use and will be considerably
  184. more efficient when the implementation shifts to the NT
  185. Configuration Manager.
  186. HISTORY:
  187. jonn 29-May-1991 Created
  188. *************************************************************************/
  189. DLL_CLASS INI_PARAM: public BASE
  190. {
  191. friend INI_ITER; // must have access to Set()
  192. private:
  193. PSZ _pchComponent;
  194. PSZ _pchParameter;
  195. PSZ _pchValue;
  196. protected:
  197. /* The constructor and destructor are protected */
  198. // Starts with a blank INI_PARAM; for use by descendant classes.
  199. INI_PARAM();
  200. ~INI_PARAM();
  201. virtual APIERR Set(
  202. CPSZ pchComponent,
  203. CPSZ pchParameter,
  204. CPSZ pchValue
  205. );
  206. CPSZ QueryComponent() const
  207. {
  208. UIASSERT( !QueryError() );
  209. UIASSERT( _pchComponent != NULL );
  210. return _pchComponent;
  211. }
  212. CPSZ QueryParamName() const
  213. {
  214. UIASSERT( !QueryError() );
  215. UIASSERT( _pchParameter != NULL );
  216. return _pchParameter;
  217. }
  218. CPSZ QueryParamValue() const
  219. {
  220. UIASSERT( !QueryError() );
  221. UIASSERT( _pchValue != NULL );
  222. return _pchValue;
  223. }
  224. APIERR QueryParamValue(
  225. BYTE * pbBuffer,
  226. USHORT cbBuffer
  227. ) const;
  228. public:
  229. APIERR Load(
  230. const INI_FILE_IMAGE& inifile
  231. );
  232. APIERR Store(
  233. INI_FILE_IMAGE * pinifile
  234. ) const;
  235. APIERR Remove(
  236. INI_FILE_IMAGE * pinifile
  237. ) const;
  238. };
  239. /*************************************************************************
  240. NAME: LMINI_PARAM
  241. SYNOPSIS: Adds to LMINI_PARAM the methods QuickLoad and QuickStore.
  242. INTERFACE: LMINI_PARAM()
  243. ~LMINI_PARAM()
  244. QuickLoad() - Loads the parameter value directly
  245. from a file.
  246. QuickStore() - Writes the parameter value directly to
  247. a file.
  248. PARENT: INI_PARAM
  249. CAVEATS: Clients should not instantiate objects of type LMINI_PARAM;
  250. they should use the subclasses instead. Clients should
  251. not override methods redefined by descendant classes of
  252. LMINI_PARAM with methods of LMINI_PARAM.
  253. It is possible to instantiate a blank LMINI_PARAM, but
  254. this is generally not possible for its descendant
  255. classes. The descendant classes generally combine their
  256. constructors with Load() or Set() operations.
  257. QuickLoad and QuickStore only work for LANROOT\LMUSER.INI.
  258. NOTES: Most clients should use the wrappers to these
  259. routines supplied in newprof.h.
  260. Users interested only in a single parameter should use
  261. QuickLoad() and QuickStore() instead of the corresponding
  262. LMINI_FILE_IMAGE operations. These methods are easier
  263. to use and will be considerably more efficient when the
  264. implementation shifts to the NT Configuration Manager.
  265. HISTORY:
  266. jonn 21-Jun-1991 Created
  267. *************************************************************************/
  268. DLL_CLASS LMINI_PARAM: public INI_PARAM
  269. {
  270. public:
  271. APIERR QuickLoad();
  272. APIERR QuickStore() const;
  273. };
  274. /*************************************************************************
  275. NAME: KEYED_INI_PARAM
  276. SYNOPSIS: Stores an image of a single string in an INI file. This
  277. class takes a USHORT key for the item to be accessed,
  278. rather than a component and parameter name; this key maps
  279. directly to a component and parameter name. External
  280. clients will use this in place of INI_PARAM for
  281. general-string-valued items.
  282. This class is protected; clients must use
  283. STRING_INI_PARAM or BOOL_INI_PARAM instead.
  284. INTERFACE: KEYED_INI_PARAM()
  285. ~KEYED_INI_PARAM()
  286. TranslateKey() - Returns the component/parameter names
  287. for a key
  288. SetKeyed() - Changes the parameter value
  289. PARENT: LMINI_PARAM
  290. CAVEATS: Clients must use STRING_INI_PARAM instead of this class.
  291. NOTES: Most clients should use the wrappers to these
  292. routines supplied in newprof.h.
  293. These methods return ERROR_INVALID_PARAMETER for an
  294. invalid key.
  295. HISTORY:
  296. jonn 29-May-1991 Created
  297. *************************************************************************/
  298. DLL_CLASS KEYED_INI_PARAM: public LMINI_PARAM
  299. {
  300. protected:
  301. KEYED_INI_PARAM(
  302. USHORT usKey,
  303. CPSZ pchValue
  304. );
  305. APIERR TranslateKey(
  306. USHORT usKey,
  307. CPSZ * ppchComponent,
  308. CPSZ * ppchParameter
  309. ) const;
  310. APIERR SetKeyed(
  311. CPSZ pchValue
  312. );
  313. };
  314. /*************************************************************************
  315. NAME: STRING_INI_PARAM
  316. SYNOPSIS: Stores an image of a single string in an INI file. This
  317. class is an accessor to KEYED_INI_PARAM.
  318. INTERFACE: STRING_INI_PARAM()
  319. ~STRING_INI_PARAM()
  320. SetString() - Changes the parameter value
  321. QueryString() - Returns the parameter value
  322. PARENT: KEYED_INI_PARAM
  323. CAVEATS: Clients should use this class instead of INI_PARAM.
  324. NOTES: Most clients should use the wrappers to these
  325. routines supplied in newprof.h.
  326. These methods return ERROR_INVALID_PARAMETER for an
  327. invalid key.
  328. HISTORY:
  329. jonn 18-Jun-1991 Created
  330. *************************************************************************/
  331. DLL_CLASS STRING_INI_PARAM: public KEYED_INI_PARAM
  332. {
  333. public:
  334. STRING_INI_PARAM(
  335. USHORT usKey,
  336. CPSZ pchValue
  337. ) : KEYED_INI_PARAM( usKey, pchValue )
  338. { }
  339. APIERR SetString(
  340. CPSZ pchValue
  341. )
  342. { return KEYED_INI_PARAM::SetKeyed( pchValue ); }
  343. CPSZ QueryString() const
  344. { return KEYED_INI_PARAM::QueryParamValue(); }
  345. APIERR QueryString(
  346. BYTE * pbBuffer,
  347. USHORT cbBuffer
  348. ) const
  349. { return KEYED_INI_PARAM::QueryParamValue( pbBuffer, cbBuffer ); }
  350. };
  351. /*************************************************************************
  352. NAME: BOOL_INI_PARAM
  353. SYNOPSIS: Stores an image of a single boolean parameter in an INI file.
  354. This class takes a USHORT key for the item to be accessed,
  355. rather than a component and parameter name; this key maps
  356. directly to a component and parameter name. External
  357. clients will use this in place of INI_PARAM for
  358. boolean-valued items.
  359. INTERFACE: BOOL_INI_PARAM()
  360. ~BOOL_INI_PARAM()
  361. Set() - Changes the parameter value
  362. EvaluateString()- Determines whether a string is a
  363. valid boolean value ("yes" or "no").
  364. QueryBool() - Asks after the parameter value
  365. SetBool() - Changes the parameter value, for clients
  366. PARENT: KEYED_INI_PARAM
  367. CAVEATS: Clients should use this class instead of INI_PARAM.
  368. Load() will return NERR_CfgParamNotFound for a parameter
  369. whose value is not a valid boolean.
  370. NOTES: Most clients should use the wrappers to these
  371. routines supplied in newprof.h.
  372. HISTORY:
  373. jonn 29-May-1991 Created
  374. *************************************************************************/
  375. DLL_CLASS BOOL_INI_PARAM: public KEYED_INI_PARAM
  376. {
  377. private:
  378. // returns ERROR_INVALID_PARAMETER for bad values
  379. static APIERR EvaluateString(
  380. CPSZ pchValue,
  381. BOOL * pfValue
  382. ) const;
  383. protected:
  384. virtual APIERR Set(
  385. CPSZ pchComponent,
  386. CPSZ pchParameter,
  387. CPSZ pchValue
  388. );
  389. public:
  390. BOOL_INI_PARAM(
  391. USHORT usKey,
  392. BOOL fValue
  393. );
  394. APIERR QueryBool(
  395. BOOL * pfValue
  396. ) const;
  397. APIERR SetBool(
  398. BOOL fValue
  399. );
  400. };
  401. /*************************************************************************
  402. NAME: PROFILE_INI_PARAM
  403. SYNOPSIS: Stores an image of a single device parameter in an INI file.
  404. This class takes a device name for the item to be accessed,
  405. and does not need a component name. External clients will
  406. use this in place of INI_PARAM for device connections.
  407. INTERFACE: PROFILE_INI_PARAM()
  408. ~PROFILE_INI_PARAM()
  409. W_SetProfile() - Sets profile value assuming canonicalized
  410. device name but not other params
  411. QueryProfile() - Asks after the parameter value
  412. Set() - Changes the parameter value
  413. PARENT: LMINI_PARAM
  414. CAVEATS: Clients should use this class instead of INI_PARAM.
  415. Load() will return NERR_CfgParamNotFound for a parameter
  416. whose value is not a valid boolean.
  417. NOTES: Most clients should use the wrappers to these
  418. routines supplied in newprof.h.
  419. The constructor variant without parameters can be used
  420. to construct an instance of PROFILE_INI_PARAM which is
  421. temporarily invalid. Such an instance should only be
  422. used for SetProfile() and PROFILE_INI_ITER::Next().
  423. This constructor is provided so that clients can create
  424. in instance of PROFILE_INI_PARAM for use by
  425. PROFILE_INI_ITER without having to fake initial data.
  426. The constructor with only a devicename parameter also
  427. creates an invalid instance. Such an instance should
  428. only be used for Load() or Remove().
  429. HISTORY:
  430. jonn 29-May-1991 Created
  431. *************************************************************************/
  432. DLL_CLASS PROFILE_INI_PARAM: public LMINI_PARAM
  433. {
  434. private:
  435. APIERR W_SetProfile(
  436. CPSZ pchCanonDeviceName,
  437. CPSZ pchRemoteName,
  438. short sAsgType,
  439. unsigned short usResType
  440. );
  441. protected:
  442. virtual APIERR Set(
  443. CPSZ pchComponent,
  444. CPSZ pchParameter,
  445. CPSZ pchValue
  446. );
  447. public:
  448. PROFILE_INI_PARAM(
  449. CPSZ pchDeviceName,
  450. CPSZ pchRemoteName,
  451. short sAsgType,
  452. unsigned short usResType
  453. );
  454. // Creates an instance which is temporarily invalid
  455. PROFILE_INI_PARAM();
  456. PROFILE_INI_PARAM(
  457. CPSZ cpszDeviceName
  458. );
  459. APIERR QueryProfile(
  460. BYTE * pbBuffer, // remote name
  461. USHORT cbBuffer,
  462. short * psAsgType,
  463. unsigned short * pusResType
  464. ) const;
  465. APIERR SetProfile(
  466. CPSZ pchRemoteName,
  467. short sAsgType,
  468. unsigned short usResType
  469. );
  470. CPSZ QueryDeviceName()
  471. { return QueryParamName(); }
  472. };
  473. /*************************************************************************
  474. NAME: INI_ITER
  475. SYNOPSIS: Iterates the parameters of the requested type. The
  476. iterator must be provided with an INI_PARAM into which
  477. to store each successive value. Use the INI_ITER
  478. subclass corresponding to the INI_PARAM subclass; at
  479. present, this means to use PROFILE_INI_ITER to
  480. iterate PROFILE_INI_PARAMs.
  481. INTERFACE: INI_ITER()
  482. ~INI_ITER()
  483. Next() - Store the next param of the specified type into
  484. the provided INI_PARAM *.
  485. PARENT: BASE
  486. CAVEATS: Next() requires a valid instance of PROFILE_INI_PARAM.
  487. Create the instance with any valid initial value.
  488. Do not modify the INI_FILE_IMAGE while the iterator is
  489. in scope.
  490. NOTES: Most clients should use the wrappers to these
  491. routines supplied in newprof.h.
  492. HISTORY:
  493. jonn 26-Jun-1991 Created
  494. *************************************************************************/
  495. DLL_CLASS INI_ITER: public BASE
  496. {
  497. private:
  498. PSZ _pchComponent;
  499. ITER_OF_PARAM *_piterparam;
  500. BOOL _fComponentFound;
  501. public:
  502. INI_ITER(
  503. const INI_FILE_IMAGE& inifile,
  504. CPSZ pchComponent
  505. );
  506. ~INI_ITER();
  507. APIERR Next(
  508. INI_PARAM * piniparam
  509. );
  510. };
  511. /*************************************************************************
  512. NAME: PROFILE_INI_ITER
  513. SYNOPSIS: Thin shell over INI_ITER; use for iterating
  514. objects of type PROFILE_INI_PARAM.
  515. INTERFACE: PROFILE_INI_ITER()
  516. PARENT: INI_ITER
  517. CAVEATS: When calling Next() on a PROFILE_INI_ITER, always pass
  518. a pointer to a PROFILE_INI_PARAM, instead of a pointer to
  519. another type of INI_PARAM. Use the PROFILE_INI_PARAM
  520. constructor which takes no parameters.
  521. HISTORY:
  522. jonn 26-Jun-1991 Created
  523. *************************************************************************/
  524. DLL_CLASS PROFILE_INI_ITER: public INI_ITER
  525. {
  526. public:
  527. PROFILE_INI_ITER(
  528. const INI_FILE_IMAGE& inifile
  529. );
  530. };
  531. #endif // _NEWPROF_HXX_- end of file