Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2005 TightVNC Team. All Rights Reserved. |
| 2 | * |
| 3 | * Developed by Dennis Syrovatsky. |
| 4 | * |
| 5 | * This is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This software is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this software; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 18 | * USA. |
| 19 | * |
Peter Åstrand | 7877cd6 | 2009-02-25 16:15:48 +0000 | [diff] [blame] | 20 | * |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | // -=- CFTMsgWriter.cxx |
| 25 | |
| 26 | #include <rfb/CFTMsgWriter.h> |
| 27 | |
| 28 | using namespace rfb; |
| 29 | |
| 30 | CFTMsgWriter::CFTMsgWriter(rdr::OutStream *pOS) |
| 31 | { |
| 32 | m_pOutStream = pOS; |
| 33 | } |
| 34 | |
| 35 | CFTMsgWriter::~CFTMsgWriter() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | bool |
| 40 | CFTMsgWriter::writeFileListRqst(unsigned short dirnameLen, char *pDirName, |
| 41 | bool bDirOnly) |
| 42 | { |
| 43 | if (dirnameLen >= FT_FILENAME_SIZE) return false; |
| 44 | |
| 45 | unsigned char flags = 0; |
| 46 | if (bDirOnly) flags = 0x10; |
| 47 | |
| 48 | m_pOutStream->writeU8(msgTypeFileListRequest); |
| 49 | m_pOutStream->writeU8(flags); |
| 50 | m_pOutStream->writeU16(dirnameLen); |
| 51 | m_pOutStream->writeBytes((void *)pDirName, dirnameLen); |
| 52 | m_pOutStream->flush(); |
| 53 | |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | |
| 58 | bool |
| 59 | CFTMsgWriter::writeFileDownloadCancel(unsigned short reasonLen, char *pReason) |
| 60 | { |
| 61 | m_pOutStream->writeU8(msgTypeFileDownloadCancel); |
| 62 | return writeU8U16StringMsg(reasonLen, pReason); |
| 63 | } |
| 64 | |
| 65 | bool |
| 66 | CFTMsgWriter::writeFileDownloadRqst(unsigned short filenameLen, char *pFilename, |
| 67 | unsigned int position) |
| 68 | { |
| 69 | if (filenameLen >= FT_FILENAME_SIZE) return false; |
| 70 | |
| 71 | m_pOutStream->writeU8(msgTypeFileDownloadRequest); |
| 72 | m_pOutStream->writeU8(0); |
| 73 | m_pOutStream->writeU16(filenameLen); |
| 74 | m_pOutStream->writeU32(position); |
| 75 | m_pOutStream->writeBytes(pFilename, filenameLen); |
| 76 | m_pOutStream->flush(); |
| 77 | |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | bool |
| 82 | CFTMsgWriter::writeFileUploadData(unsigned short dataSize, char *pData) |
| 83 | { |
| 84 | m_pOutStream->writeU8(msgTypeFileUploadData); |
| 85 | m_pOutStream->writeU8(0); |
| 86 | m_pOutStream->writeU16(dataSize); |
| 87 | m_pOutStream->writeU16(dataSize); |
| 88 | m_pOutStream->writeBytes(pData, dataSize); |
| 89 | m_pOutStream->flush(); |
| 90 | |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | bool |
| 95 | CFTMsgWriter::writeFileUploadData(unsigned int modTime) |
| 96 | { |
| 97 | m_pOutStream->writeU8(msgTypeFileUploadData); |
| 98 | m_pOutStream->writeU8(0); |
| 99 | m_pOutStream->writeU16(0); |
| 100 | m_pOutStream->writeU16(0); |
| 101 | m_pOutStream->writeU32(modTime); |
| 102 | m_pOutStream->flush(); |
| 103 | |
| 104 | return true; |
| 105 | } |
| 106 | |
| 107 | bool |
| 108 | CFTMsgWriter::writeFileUploadFailed(unsigned short reasonLen, char *pReason) |
| 109 | { |
| 110 | m_pOutStream->writeU8(msgTypeFileUploadFailed); |
| 111 | return writeU8U16StringMsg(reasonLen, pReason); |
| 112 | } |
| 113 | |
| 114 | bool |
| 115 | CFTMsgWriter::writeFileUploadRqst(unsigned short filenameLen, char *pFilename, |
| 116 | unsigned int position) |
| 117 | { |
| 118 | if (filenameLen >= FT_FILENAME_SIZE) return false; |
| 119 | |
| 120 | m_pOutStream->writeU8(msgTypeFileUploadRequest); |
| 121 | m_pOutStream->writeU8(0); |
| 122 | m_pOutStream->writeU16(filenameLen); |
| 123 | m_pOutStream->writeU32(position); |
| 124 | m_pOutStream->writeBytes((void *)pFilename, filenameLen); |
| 125 | m_pOutStream->flush(); |
| 126 | |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | bool |
| 131 | CFTMsgWriter::writeFileCreateDirRqst(unsigned short dirNameLen, char *pDirName) |
| 132 | { |
| 133 | if (dirNameLen >= FT_FILENAME_SIZE) return false; |
| 134 | |
| 135 | m_pOutStream->writeU8(msgTypeFileCreateDirRequest); |
| 136 | return writeU8U16StringMsg(dirNameLen, pDirName); |
| 137 | } |
| 138 | |
| 139 | bool |
| 140 | CFTMsgWriter::writeFileDirSizeRqst(unsigned short dirNameLen, char *pDirName) |
| 141 | { |
| 142 | if (dirNameLen >= FT_FILENAME_SIZE) return false; |
| 143 | |
| 144 | m_pOutStream->writeU8(msgTypeFileDirSizeRequest); |
| 145 | return writeU8U16StringMsg(dirNameLen, pDirName); |
| 146 | } |
| 147 | |
| 148 | bool |
| 149 | CFTMsgWriter::writeFileRenameRqst(unsigned short oldNameLen, unsigned short newNameLen, |
| 150 | char *pOldName, char *pNewName) |
| 151 | { |
| 152 | if ((oldNameLen >= FT_FILENAME_SIZE) || (newNameLen >= FT_FILENAME_SIZE)) return false; |
| 153 | |
| 154 | m_pOutStream->writeU8(msgTypeFileRenameRequest); |
| 155 | m_pOutStream->writeU8(0); |
| 156 | m_pOutStream->writeU16(oldNameLen); |
| 157 | m_pOutStream->writeU16(newNameLen); |
| 158 | m_pOutStream->writeBytes(pOldName, oldNameLen); |
| 159 | m_pOutStream->writeBytes(pNewName, newNameLen); |
| 160 | m_pOutStream->flush(); |
| 161 | |
| 162 | return true; |
| 163 | } |
| 164 | |
| 165 | bool |
| 166 | CFTMsgWriter::writeFileDeleteRqst(unsigned short nameLen, char *pName) |
| 167 | { |
| 168 | if (nameLen >= FT_FILENAME_SIZE) return false; |
| 169 | |
| 170 | m_pOutStream->writeU8(msgTypeFileDeleteRequest); |
| 171 | return writeU8U16StringMsg(nameLen, pName); |
| 172 | } |
| 173 | |
| 174 | bool |
| 175 | CFTMsgWriter::writeU8U16StringMsg(unsigned short strLength, char *pString) |
| 176 | { |
| 177 | m_pOutStream->writeU8(0); |
| 178 | m_pOutStream->writeU16(strLength); |
| 179 | m_pOutStream->writeBytes(pString, strLength); |
| 180 | m_pOutStream->flush(); |
| 181 | return true; |
| 182 | } |