CIFSPrintSession.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (C) 2006-2010 Alfresco Software Limited.
  3. *
  4. * This file is part of Alfresco
  5. *
  6. * Alfresco is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * Alfresco is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package org.alfresco.jlan.client;
  20. import org.alfresco.jlan.client.info.FileInfo;
  21. import org.alfresco.jlan.server.filesys.FileAction;
  22. import org.alfresco.jlan.smb.PCShare;
  23. import org.alfresco.jlan.smb.PacketType;
  24. import org.alfresco.jlan.smb.SMBException;
  25. /**
  26. * SMB CIFS protocol print session class
  27. *
  28. * @author gkspencer
  29. */
  30. final class CIFSPrintSession extends PrintSession {
  31. /**
  32. * Class constructor
  33. *
  34. * @param shr Remote server details.
  35. * @param dialect SMB dialect that this session is using
  36. */
  37. protected CIFSPrintSession(PCShare shr, int dialect) {
  38. super(shr, dialect);
  39. }
  40. /**
  41. * Open a spool file on the remote print server.
  42. *
  43. * @param id Identifier string for this print request.
  44. * @param mode Print mode, either TextMode or GraphicsMode.
  45. * @param setuplen Length of data in the start of the spool file that is printer setup code.
  46. * @return SMBFile for the new spool file, else null.
  47. * @exception java.io.IOException If an I/O error occurs.
  48. * @exception SMBException If an SMB level error occurs
  49. */
  50. public final SMBFile OpenSpoolFile(String id, int mode, int setuplen)
  51. throws java.io.IOException, SMBException {
  52. // Initialize the SMB request to open a file
  53. m_pkt.setCommand(PacketType.OpenAndX);
  54. m_pkt.setFlags(getDefaultFlags());
  55. m_pkt.setFlags2(getDefaultFlags2());
  56. m_pkt.setUserId(this.getUserId());
  57. m_pkt.setTreeId(this.getTreeId());
  58. // Set the parameter words
  59. m_pkt.setParameterCount(15);
  60. m_pkt.setAndXCommand(0xFF); // no secondary command
  61. m_pkt.setParameter(1, 0); // offset to next command
  62. m_pkt.setParameter(2, 0x01); // return additional information
  63. m_pkt.setParameter(3, 0); // flags
  64. m_pkt.setParameter(4, 0); // normal files only for now
  65. m_pkt.setParameter(5, 0); // file attributes
  66. m_pkt.setParameter(6, 0); // creation time
  67. m_pkt.setParameter(7, 0); // creation date
  68. m_pkt.setParameter(8, FileAction.CreateNotExist + FileAction.TruncateExisting);
  69. m_pkt.setParameter(9, 0); // default allocation on create/truncate (long)
  70. m_pkt.setParameter(10, 0); // ... high word
  71. m_pkt.setParameter(11, 0);
  72. m_pkt.setParameter(12, 0);
  73. m_pkt.setParameter(13, 0);
  74. m_pkt.setParameter(14, 0);
  75. // Pack the file name string
  76. m_pkt.resetBytePointer();
  77. m_pkt.packString(id, m_pkt.isUnicode());
  78. m_pkt.setByteCount();
  79. // Send/receive the SMB file open packet
  80. m_pkt.ExchangeSMB(this, m_pkt, true);
  81. // Check if a valid response was received
  82. if ( m_pkt.isValidResponse()) {
  83. // Extract the file information from the received SMB packet
  84. int fid = m_pkt.getParameter(2);
  85. // Create a file information object
  86. FileInfo finfo = new FileInfo(id, 0, 0);
  87. // Create an SMB file object
  88. return new CIFSFile(this, finfo, fid);
  89. }
  90. // Invalid SMB response
  91. return null;
  92. }
  93. }