home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / dn511.exe / DSFILE.CPP < prev    next >
Text File  |  1995-01-09  |  5KB  |  148 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. **    DSFILTER.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 "dsfile.h"
  41.  
  42. # include <fcntl.h>
  43.  
  44. /*
  45. ** NWDSCCODE DSFile::create(NWPSTR object, NWPSTR attr)
  46. **
  47. **    Add the stream attribute to the object. If NWDSModifyObject() returns
  48. **    any of the error codes trapped then the attribute already exists.
  49. */
  50.  
  51. NWDSCCODE DSFile::create(NWPSTR object, NWPSTR attr)
  52. {
  53. NWDS_BUFFER NWFAR * buffer ;
  54.  
  55.     if ((Status = NWDSAllocBuf(DEFAULT_MESSAGE_LEN,& buffer)) != 0)
  56.         return Status ;
  57.  
  58.     NWDSInitBuf   (Context,DSV_MODIFY_ENTRY,buffer) ;
  59.     NWDSPutChange (Context,buffer,DS_ADD_ATTRIBUTE,attr) ;
  60.     NWDSPutChange (Context,buffer,DS_ADD_VALUE,attr) ;
  61.     NWDSPutAttrVal(Context,buffer,SYN_STREAM,0) ;
  62.  
  63.     Status = NWDSModifyObject(Context,object,0,0,buffer) ;
  64.  
  65.     if (Status == ERR_ATTRIBUTE_ALREADY_EXISTS ||
  66.         Status == ERR_DUPLICATE_VALUE ||
  67.         Status == ERR_CANT_HAVE_MULTIPLE_VALUES) Status = 0 ;
  68.  
  69.     NWDSFreeBuf(buffer) ;
  70.  
  71.     return Status ;
  72. }
  73.  
  74. /*
  75. ** NWDSCCODE DSFile::unlink(NWPSTR object, NWPSTR attr)
  76. **
  77. **    Delete the stream attribute value from the object. For efficiency
  78. **    reasons the attribute value is added again, this is so that the
  79. **    next call to NWDSOpenStream() succeeds without having to create the
  80. **    attribute.
  81. */
  82.  
  83. NWDSCCODE DSFile::unlink(NWPSTR object, NWPSTR attr)
  84. {
  85. NWDS_BUFFER NWFAR * buffer ;
  86.  
  87.     if ((Status = NWDSAllocBuf(DEFAULT_MESSAGE_LEN,& buffer)) != 0)
  88.         return Status ;
  89.  
  90.     NWDSInitBuf   (Context,DSV_MODIFY_ENTRY,buffer) ;
  91.     NWDSPutChange (Context,buffer,DS_REMOVE_ATTRIBUTE,attr) ;
  92.     NWDSPutChange (Context,buffer,DS_ADD_ATTRIBUTE,attr) ;
  93.     NWDSPutChange (Context,buffer,DS_ADD_VALUE,attr) ;
  94.     NWDSPutAttrVal(Context,buffer,SYN_STREAM,0) ;
  95.  
  96.     Status = NWDSModifyObject(Context,object,0,0,buffer) ;
  97.  
  98.     NWDSFreeBuf(buffer) ;
  99.  
  100.     return Status ;
  101. }
  102.  
  103. /*
  104. ** NWDS_LOGIN_FILE DSFile::open(NWPSTR object, NWPSTR attr, int mode)
  105. **
  106. **    Open the stream attribute for reading or writing. The only modes
  107. **    allowed are READ(1), WRITE(2) and READ/WRITE(3). The standard mode
  108. **    O_RDWR(4) is translated to (3).
  109. */
  110.  
  111. NWDS_LOGIN_FILE DSFile::open(NWPSTR object, NWPSTR attr, DWORD mode)
  112. {
  113.     if (Handle != -1) close() ;
  114.  
  115.     mode &= O_RDONLY|DS_READ_STREAM|DS_WRITE_STREAM ;
  116.  
  117.     if (mode == O_RDWR) mode = DS_READ_STREAM|DS_WRITE_STREAM ;
  118.     if (mode == DS_WRITE_STREAM) unlink(object,attr) ;
  119.  
  120.     Status = NWDSOpenStream(Context,object,attr,mode,& Handle) ;
  121.  
  122.     if (Status == ERR_NO_SUCH_VALUE ||
  123.         Status == ERR_NO_SUCH_ATTRIBUTE){
  124.         create(object,attr) ;
  125.         Status = NWDSOpenStream(Context,object,attr,mode,& Handle) ;
  126.         }
  127.     if (Status) Handle = -1 ;
  128.  
  129.     return Handle ;
  130. }
  131.  
  132. /*
  133. ** int DSFile::close()
  134. **
  135. **    Close the file descriptor.
  136. */
  137.  
  138. int DSFile::close()
  139. {
  140.     if (Handle != -1){
  141.         ::close(Handle) ;
  142.         Handle = -1 ;
  143.         }
  144.     return 0 ;
  145. }
  146.  
  147.  
  148.