home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dn511.exe / DSBUFFER.CPP < prev    next >
Text File  |  1995-01-09  |  15KB  |  568 lines

  1. /*
  2. **    Copyright ⌐ 1994 Novell, Inc.  All rights reserved.
  3. **
  4. **    Permission is granted to the recipient of this work ("you") to use,
  5. **    reproduce and distribute Novell's original publication of the work free
  6. **    of charge provided that you reproduce the work in its entirety and
  7. **    include all Novell copyright notices as they originally appear.
  8. **
  9. **    Novell grants you permission to modify and distribute copies of this
  10. **    work including any portion of this work (a "modified work") provided
  11. **    that you include prominent notification of such modification along with
  12. **    the date of modification on a modified work; distribute or publish a
  13. **    modified work to third parties under the same conditions and granting
  14. **    the same rights as are extended to you by Novell under this under
  15. **    permission notice; and provided that you include a copy of Novell's
  16. **    original publication of the work along with any copy of a modified
  17. **    work.
  18. **
  19. **    NOVELL MAKES NO WARRANTY, REPRESENTATION OR PROMISE THAT THIS WORK OR A
  20. **    MODIFIED WORK WILL SATISFY YOUR REQUIREMENTS OR THAT THIS WORK OR A
  21. **    MODIFIED WORK IS WITHOUT DEFECT OR ERROR.  NOVELL DISCLAIMS AND
  22. **    EXCLUDES ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE OR
  23. **    FITNESS FOR A PARTICULAR PURPOSE.
  24. **
  25. **    IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL NOVELL OR ANY OTHER
  26. **    PARTY BE LIABLE FOR DAMAGES INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
  27. **    CONSEQUENTIAL, INDIRECT OR PUNATIVE DAMAGES ARISING OUT OF THE USE OF
  28. **    OR INABLITITY TO USE THE WORK OR A MODIFIED WORK.
  29. **
  30. **    DSBUFFER.CPP - October 1994
  31. **
  32. **    Initialisation, control and release of directory buffers.
  33. **
  34. **    Author: John Buckle, Asia Pacific Support Centre, Novell Australia
  35. **    ==================================================================
  36. **    9 Jan 1995           First release              John Buckle
  37. */
  38.  
  39. # include "dsdefs.h"
  40. # include "dsbuffer.h"
  41. # include "dsiterat.h"
  42.  
  43. /*
  44. ** DSBuffer::DSBuffer(NWPSTR context    = 0 ,
  45. **              DWORD  flags      = DS_CONTEXT_FLAGS,
  46. **              WORD   inputSize  = DEFAULT_MESSAGE_LEN,
  47. **              WORD   outputSize = DEFAULT_MESSAGE_LEN,
  48. **              WORD   filterSize = DEFAULT_MESSAGE_LEN)
  49. **
  50. **    Allocates memory for the three NDS buffers contained inside the
  51. **    object.
  52. */
  53.  
  54. DSBuffer::DSBuffer(NWPSTR context, DWORD flags,
  55.             WORD inputSize, WORD outputSize, WORD filterSize) :
  56.         DSContext(context,flags),
  57.         DSInput  (inputSize),
  58.         DSOutput (outputSize),
  59.         DSFilter (filterSize)
  60. {
  61. }
  62.  
  63. /*
  64. ** DSBuffer::~DSBuffer()
  65. **
  66. **    Release the memory used by the buffers.
  67. */
  68.  
  69. DSBuffer::~DSBuffer()
  70. {
  71. }
  72.  
  73. /*
  74. ** NWDSCCODE DSBuffer::CloseIteration(
  75. **            NWDS_ITERATION iterHandle,
  76. **            NWDS_OPERATION operation)
  77. **
  78. **    Recover any memory used by an iteration command. The command
  79. **    DSContext::CloseIteration() is not used since this modifies the
  80. **    Status member field.
  81. */
  82.  
  83. NWDSCCODE DSBuffer::CloseIteration(NWDS_ITERATION iterHandle, NWDS_OPERATION operation)
  84. {
  85.     return (iterHandle == -1) ? 0 : NWDSCloseIteration(dContext,iterHandle,operation) ;
  86. }
  87.  
  88. /*
  89. ** NWDSCCODE DSBuffer::InitFilter(NWDS_OPERATION function = DSV_SEARCH_FILTER)
  90. **
  91. **    Initialise the filter buffer and create an expression cursor.
  92. */
  93.  
  94. NWDSCCODE DSBuffer::InitFilter(NWDS_OPERATION function)
  95. {
  96.     return DSFilter::InitBuf(function) || AllocFilter() ;
  97. }
  98.  
  99. /*
  100. ** NWDSCCODE DSBuffer::ExitFilter()
  101. **
  102. **    Add an END token to the expression and record the expression in the
  103. **    filter buffer.
  104. */
  105.  
  106. NWDSCCODE DSBuffer::ExitFilter()
  107. {
  108.     return AddFilterToken(FTOK_END) || PutFilter() ;
  109. }
  110.  
  111. /*
  112. ** void DSBuffer::InitLoop(DSIteration * iteration)
  113. **
  114. **    Prepare for iteration.
  115. */
  116.  
  117. void DSBuffer::InitLoop(DSIteration * iteration)
  118. {
  119.     iteration->InitLoop() ;
  120.     DSInput ::InitLoop(iteration) ;
  121.     DSFilter::InitLoop(iteration) ;
  122.     DSOutput::InitLoop(iteration) ;
  123. }
  124.  
  125. /*
  126. ** void DSBuffer::ExitLoop(DSIteration * iteration)
  127. **
  128. **    Terminate iteration.
  129. */
  130.  
  131. void DSBuffer::ExitLoop(DSIteration * iteration)
  132. {
  133.     DSOutput::ExitLoop(iteration) ;
  134.     DSFilter::ExitLoop(iteration) ;
  135.     DSInput ::ExitLoop(iteration) ;
  136.     iteration->ExitLoop(Status) ;
  137. }
  138.  
  139. /*
  140. ** NWDSCCODE DSBuffer::DoesObjectExist(NWPSTR object)
  141. **
  142. **    Determine if the specified object exists.
  143. */
  144.  
  145. NWDSCCODE DSBuffer::DoesObjectExist(NWPSTR object)
  146. {
  147. NWDS_ITERATION    iterations = -1 ;
  148.  
  149.     return Status = NWDSRead(dContext,object,0,1,0,& iterations,Output) ;
  150. }
  151.  
  152. /*
  153. ** NWDSCCODE DSBuffer::GetObjectHostServerAddress(
  154. **                NWPSTR        object,
  155. **                NWPSTR        server,
  156. **                DSIteration *    iteration)
  157. **
  158. **    List the net addresses of an NDS object. This function only works for
  159. **    objects with a Host Resource Name attribute (such as Volume objects).
  160. **    NWDSGetObjectHostServerAddress iteration is managed by using a
  161. **    DSIteration object. Developers should derive their own classes from
  162. **    DSIteration and override the class's functions to receive the results.
  163. **
  164. **    DSIteration Protocol:
  165. **        InitLoop()
  166. **        SetAttrName(AttrName,SYN_NET_ADDRESS)
  167. **        For each address
  168. **            SetAttrValue(SYN_NET_ADDRESS,value)
  169. **        ExitLoop(Status)
  170. */
  171.  
  172. NWDSCCODE DSBuffer::GetObjectHostServerAddress(
  173.                 NWPSTR        object,
  174.                 NWPSTR        server,
  175.                 DSIteration *    iteration)
  176. {
  177.     InitLoop(iteration) ;
  178.  
  179.     Status = NWDSGetObjectHostServerAddress(dContext,object,server,Output) ;
  180.  
  181.     if (Status == 0) ListAttributes(iteration) ;
  182.  
  183.     ExitLoop(iteration) ;
  184.  
  185.     return Status ;
  186. }
  187.  
  188. /*
  189. ** NWDSCCODE DSBuffer::GetServerAddresses(
  190. **                NWCONN_HANDLE connHandle
  191. **                DSIteration *    iteration)
  192. **
  193. **    List the net addresses of a server object. NWDSGetServerAddresses
  194. **    iteration is managed by using a DSIteration object. Developers should
  195. **    derive their own classes from DSIteration and override the class's
  196. **    functions to receive the results.
  197. **
  198. **    DSIteration Protocol:
  199. **        InitLoop()
  200. **        For each address
  201. **            SetAttrValue(SYN_NET_ADDRESS,value)
  202. **        ExitLoop(Status)
  203. */
  204.  
  205. NWDSCCODE DSBuffer::GetServerAddresses(
  206.                 NWCONN_HANDLE    connHandle,
  207.                 DSIteration *    iteration)
  208. {
  209. NWCOUNT    count = 0 ;
  210.  
  211.     InitLoop(iteration) ;
  212.  
  213.     Status = NWDSGetServerAddresses(dContext,connHandle,& count,Output) ;
  214.  
  215.     if (Status == 0) ListAttributes(iteration) ;
  216.  
  217.     ExitLoop(iteration) ;
  218.  
  219.     return Status ;
  220. }
  221.  
  222. /*
  223. ** NWDSCCODE DSBuffer::List(NWPSTR object, DSIteration * iteration)
  224. **
  225. **    List the subordinate objects in the NDS tree using NWDSList().
  226. **    NWDSList iteration is managed by using a DSIteration object. Developers
  227. **    should derive their own classes from DSIteration and override the
  228. **    class's functions to receive the results from NWDSList.
  229. **
  230. **    DSIteration Protocol:
  231. **        InitLoop()
  232. **        For each object
  233. **            InitObject(ObjectName,ObjectInfo)
  234. **            ExitObject(ObjectName)
  235. **        ExitLoop(Status)
  236. */
  237.  
  238. NWDSCCODE DSBuffer::List(NWPSTR object, DSIteration * iteration)
  239. {
  240. NWDS_ITERATION    iterHandle = -1 ;
  241.  
  242.     InitLoop(iteration) ;
  243.  
  244.     do {
  245.         Status = NWDSList(dContext,     // Directory context
  246.                 object,              // Base of listing
  247.                   & iterHandle,       // Iteration handle
  248.                 Output) ;         // Object return buffer
  249.  
  250.         if (Status || ListObjects(iteration)) break ;
  251.  
  252.     } while (iterHandle != -1) ;
  253.  
  254.     ExitLoop(iteration) ;
  255.  
  256.     if (Status > 0) CloseIteration(iterHandle,DSV_LIST) ;
  257.  
  258.     return Status ;
  259. }
  260.  
  261. /*
  262. ** NWDSCCODE DSBuffer::ListByClassAndName(
  263. **            NWPSTR        object,
  264. **            NWPSTR        className,
  265. **            NWPSTR        subordinate,
  266. **            DSIteration *    iteration)
  267. **            TimeStamp_T *    timeStamp = DSCPP_NO_TIME_FILTER,
  268. **            WORD        onlyContainers = 0)
  269. **
  270. **    List the subordinate objects of the appropriate class and name.
  271. **    NWDSListByClassAndName iteration is managed by using a DSIteration
  272. **    object. Developers should derive their own classes from DSIteration and
  273. **    override the class's functions to receive the results.
  274. **
  275. **    DSIteration Protocol:
  276. **        InitLoop()
  277. **        For each object
  278. **            InitObject(ObjectName,ObjectInfo)
  279. **            ExitObject(ObjectName)
  280. **        ExitLoop(Status)
  281. */
  282.  
  283. NWDSCCODE DSBuffer::ListByClassAndName(
  284.                 NWPSTR        object,
  285.                 NWPSTR        className,
  286.                 NWPSTR        subordinate,
  287.                 DSIteration *    iteration,
  288.                 TimeStamp_T *    timeStamp,
  289.                 WORD        onlyContainers)
  290. {
  291. NWDS_ITERATION    iterHandle = -1 ;
  292.  
  293.     InitLoop(iteration) ;
  294.  
  295.     do {
  296.         Status = (timeStamp == DSCPP_NO_TIME_FILTER)
  297.             ? NWDSListByClassAndName(
  298.                 dContext,object,className,subordinate,& iterHandle,Output)
  299.             : NWDSExtSyncList(
  300.                 dContext,object,className,subordinate,& iterHandle,timeStamp,onlyContainers,Output) ;
  301.  
  302.  
  303.         if (Status || ListObjects(iteration)) break ;
  304.  
  305.     } while (iterHandle != -1) ;
  306.  
  307.     ExitLoop(iteration) ;
  308.  
  309.     if (Status > 0) CloseIteration(iterHandle,DSV_LIST) ;
  310.  
  311.     return Status ;
  312. }
  313.  
  314. /*
  315. ** NWDSCCODE DSBuffer::ListContainers(NWPSTR object, DSIteration * iteration)
  316. **
  317. **    List the subordinate container objects in the NDS tree.
  318. **    NWDSListContainers iteration is managed by using a DSIteration
  319. **    object. Developers should derive their own classes from DSIteration and
  320. **    override the class's functions to receive the results.
  321. **
  322. **    DSIteration Protocol:
  323. **        InitLoop()
  324. **        For each object
  325. **            InitObject(ObjectName,ObjectInfo)
  326. **            ExitObject(ObjectName)
  327. **        ExitLoop(Status)
  328. */
  329.  
  330. NWDSCCODE DSBuffer::ListContainers(NWPSTR object,DSIteration * iteration)
  331. {
  332. NWDS_ITERATION    iterHandle = -1 ;
  333.  
  334.     InitLoop(iteration) ;
  335.  
  336.     do {
  337.         Status = NWDSListContainers(
  338.                 dContext,     // Directory context
  339.                 object,              // Base of listing
  340.                   & iterHandle,       // Iteration handle
  341.                 Output) ;         // Object return buffer
  342.  
  343.         if (Status || ListObjects(iteration)) break ;
  344.  
  345.     } while (iterHandle != -1) ;
  346.  
  347.     ExitLoop(iteration) ;
  348.  
  349.     if (Status > 0) CloseIteration(iterHandle,DSV_LIST) ;
  350.  
  351.     return Status ;
  352. }
  353.  
  354. /*
  355. ** NWDSCCODE DSBuffer::ListAttrsEffectiveRights(
  356. **                NWPSTR        object,
  357. **                NWPSTR        subject,
  358. **                NWFLAGS        allAttrs,
  359. **                DSIteration *    iteration)
  360. **
  361. **    List the effective rights the subject has over the attributes of
  362. **    the object. NWDSListAttrsEffectiveRights iteration is managed by using
  363. **    a DSIteration object. Developers should derive their own classes from
  364. **    DSIteration and override the class's functions to receive the results.
  365. **
  366. **    DSIteration Protocol:
  367. **        InitLoop()
  368. **        For each attribute
  369. **            SetAttrName(AttrName,SYN_INTEGER)
  370. **            SetAttrValue(SYN_INTEGER,Rights)
  371. **        ExitLoop(Status)
  372. */
  373.  
  374. NWDSCCODE DSBuffer::ListAttrsEffectiveRights(
  375.                 NWPSTR        object,
  376.                 NWPSTR        subject,
  377.                 NWFLAGS        allAttrs,
  378.                 DSIteration *    iteration)
  379. {
  380. NWDS_ITERATION    iterHandle = -1 ;
  381.  
  382.     InitLoop(iteration) ;
  383.  
  384.     do {
  385.         Status = NWDSListAttrsEffectiveRights(
  386.                 dContext,     // Directory context
  387.                 object,              // Destination of rights
  388.                 subject,    // Source of rights
  389.                 allAttrs,         // Return requested attr only
  390.                 Input,              // Requested attributes
  391.                   & iterHandle,       // Iteration handle
  392.                 Output) ;         // Object return buffer
  393.  
  394.         if (Status || ListAttributes(iteration)) break ;
  395.  
  396.     } while (iterHandle != -1) ;
  397.  
  398.     ExitLoop(iteration) ;
  399.  
  400.     if (Status > 0) CloseIteration(iterHandle,DSV_READ) ;
  401.  
  402.     return Status ;
  403. }
  404.  
  405. /*
  406. ** NWDSCCODE DSBuffer::Read(
  407. **            NWPSTR        object,
  408. **            NWDS_TYPE    infoType,
  409. **            NWFLAGS        allAttrs,
  410. **            DSIteration *    iteration,
  411. **            TimeStamp_T *    timeStamp = DSCPP_NO_TIME_FILTER)
  412. **
  413. **    Execute a read of the NDS tree using NWDSRead(). NWDSRead iteration
  414. **    is managed by using a DSIteration object. Developers should derive
  415. **    their own classes from DSIteration and override the class's
  416. **    functions to receive the results from NWDSRead.
  417. **
  418. **    DSIteration Protocol:
  419. **        InitLoop()
  420. **        For each attribute
  421. **            SetAttrName(AttrName,Syntax)
  422. **            For each value in AttrName
  423. **                SetAttrValue(Syntax,Data)
  424. **        ExitLoop(Status)
  425. */
  426.  
  427. NWDSCCODE DSBuffer::Read(
  428.             NWPSTR        object,
  429.             NWDS_TYPE    infoType,
  430.             NWFLAGS        allAttrs,
  431.             DSIteration *    iteration,
  432.             TimeStamp_T *    timeStamp)
  433. {
  434. NWDS_ITERATION    iterHandle = -1 ;
  435.  
  436.     InitLoop(iteration) ;
  437.  
  438.     do {
  439.         Status = (timeStamp == DSCPP_NO_TIME_FILTER)
  440.             ? NWDSRead(
  441.                 dContext,object,infoType,allAttrs,Input,& iterHandle,Output)
  442.             : NWDSExtSyncRead(
  443.                 dContext,object,infoType,allAttrs,Input,& iterHandle,timeStamp,Output) ;
  444.  
  445.         if (Status || ListAttributes(iteration)) break ;
  446.  
  447.     } while (iterHandle != -1) ;
  448.  
  449.     ExitLoop(iteration) ;
  450.  
  451.     if (Status > 0) CloseIteration(iterHandle,DSV_READ) ;
  452.  
  453.     return Status ;
  454. }
  455.  
  456. /*
  457. ** NWDSCCODE DSBuffer::ReadReferences(
  458. **            NWPSTR        server,
  459. **            NWPSTR        object,
  460. **            NWDS_TYPE    infoType,
  461. **            NWFLAGS        allAttrs,
  462. **            DSIteration *    iteration,
  463. **            DWORD        timeStamp)
  464. **
  465. **    Execute a read of the NDS tree using NWDSReadReferences().
  466. **    NWDSRead iteration is managed by using a DSIteration object.
  467. **    Developers should derive their own classes from DSIteration and
  468. **    override the class's functions to receive the results.
  469. **
  470. **    DSIteration Protocol:
  471. **        InitLoop()
  472. **        For each attribute
  473. **            SetAttrName(AttrName,Syntax)
  474. **            For each value in AttrName
  475. **                SetAttrValue(Syntax,Data)
  476. **        ExitLoop(Status)
  477. */
  478.  
  479. NWDSCCODE DSBuffer::ReadReferences(
  480.             NWPSTR        server,
  481.             NWPSTR        object,
  482.             NWDS_TYPE    infoType,
  483.             NWFLAGS        allAttrs,
  484.             DSIteration *    iteration,
  485.             DWORD        timeStamp)
  486. {
  487. NWDS_ITERATION    iterHandle = -1 ;
  488.  
  489.     InitLoop(iteration) ;
  490.  
  491.     do {
  492.         Status = NWDSReadReferences(
  493.                 dContext,server,object,infoType,allAttrs,
  494.                 Input,timeStamp,& iterHandle,Output) ;
  495.  
  496.         if (Status || ListAttributes(iteration)) break ;
  497.  
  498.     } while (iterHandle != -1) ;
  499.  
  500.     ExitLoop(iteration) ;
  501.  
  502.     if (Status > 0) CloseIteration(iterHandle,DSV_READ) ;
  503.  
  504.     return Status ;
  505. }
  506.  
  507. /*
  508. ** NWDSCCODE DSBuffer::Search(
  509. **            NWPSTR            base,
  510. **            NWDS_SEARCH_SCOPE    scope,
  511. **            NWFLAGS            searchAliases,
  512. **            NWDS_TYPE        infoType,
  513. **            NWFLAGS            allAttrs,
  514. **            DSIteration *        iteration,
  515. **            TimeStamp_T *        timeStamp = DS_NO_TIME_FILTER)
  516. **
  517. **    Execute a search of the NDS tree using NWDSSearch(). NWDSSearch
  518. **    iteration is managed by using a DSIteration object. Developers should
  519. **    derive their own classes from DSIteration and override the class's
  520. **    functions to receive the results from NWDSSearch.
  521. **
  522. **    DSIteration Protocol:
  523. **        InitLoop()
  524. **        For each object
  525. **            InitObject(ObjectName,ObjectInfo)
  526. **            For each attribute
  527. **                SetAttrName(AttrName,Syntax)
  528. **                For each value in AttrName
  529. **                    SetAttrValue(Syntax,Data)
  530. **            ExitObject(ObjectName)
  531. **        ExitLoop(Status)
  532. */
  533.  
  534. NWDSCCODE DSBuffer::Search(
  535.             NWPSTR            base,
  536.             NWFLAGS            scope,
  537.             NWFLAGS            searchAliases,
  538.             NWDS_TYPE        infoType,
  539.             NWFLAGS            allAttrs,
  540.             DSIteration *        iteration,
  541.             TimeStamp_T *        timeStamp)
  542. {
  543. NWDS_ITERATION    iterHandle = -1 ;
  544.  
  545.     InitLoop(iteration) ;
  546.  
  547.     do {
  548.         Status = (timeStamp == DSCPP_NO_TIME_FILTER)
  549.             ? NWDSSearch(
  550.                 dContext,base,scope,searchAliases,Filter,
  551.                 infoType,allAttrs,Input,& iterHandle,0,0,Output)
  552.             : NWDSExtSyncSearch(
  553.                 dContext,base,scope,searchAliases,Filter,timeStamp,
  554.                 infoType,allAttrs,Input,& iterHandle,0,0,Output) ;
  555.  
  556.         if (Status || ListObjects(iteration)) break ;
  557.  
  558.     } while (iterHandle != -1) ;
  559.  
  560.     ExitLoop(iteration) ;
  561.  
  562.     if (Status > 0) CloseIteration(iterHandle,DSV_SEARCH) ;
  563.  
  564.     return Status ;
  565. }
  566.  
  567.  
  568.