Dennis Syrovatsky | f72f9fd | 2006-04-17 08:56:48 +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 | *
|
| 20 | * TightVNC distribution homepage on the Web: http://www.tightvnc.com/
|
| 21 | *
|
| 22 | */
|
| 23 |
|
| 24 | // -=- CFTMsgReader.cxx
|
| 25 |
|
| 26 | #include <rfb/CFTMsgReader.h>
|
| 27 |
|
| 28 | using namespace rfb;
|
| 29 |
|
| 30 | CFTMsgReader::CFTMsgReader(rdr::InStream *pIS)
|
| 31 | {
|
| 32 | m_pInStream = pIS;
|
| 33 | }
|
| 34 |
|
| 35 | CFTMsgReader::~CFTMsgReader()
|
| 36 | {
|
| 37 |
|
| 38 | }
|
| 39 |
|
| 40 | int
|
| 41 | CFTMsgReader::readFileListData(FileInfo *pFileInfo)
|
| 42 | {
|
| 43 | unsigned char flags = m_pInStream->readU8();
|
| 44 | int numFiles = m_pInStream->readU16();
|
| 45 | int dataSize = m_pInStream->readU16();
|
| 46 | int compressedSize = m_pInStream->readU16();
|
| 47 |
|
| 48 | if (flags & 0x80) {
|
| 49 | return -1;
|
| 50 | } else {
|
| 51 | if (numFiles > 0) {
|
| 52 | char *pFilenames = new char[compressedSize];
|
| 53 | SIZEDATAINFO *pSDI = new SIZEDATAINFO[numFiles];
|
| 54 | for (int i = 0; i < numFiles; i++) {
|
| 55 | pSDI[i].size = m_pInStream->readU32();
|
| 56 | pSDI[i].data = m_pInStream->readU32();
|
| 57 | }
|
| 58 | m_pInStream->readBytes((void *)pFilenames, compressedSize);
|
| 59 | createFileInfo(numFiles, pFileInfo, pSDI, pFilenames);
|
| 60 | delete [] pSDI;
|
| 61 | delete [] pFilenames;
|
| 62 | }
|
| 63 | }
|
| 64 | return numFiles;
|
| 65 | }
|
| 66 |
|
| 67 | void *
|
| 68 | CFTMsgReader::readFileDownloadData(unsigned int *pSize, unsigned int *pModTime)
|
| 69 | {
|
| 70 | unsigned char compressLevel = m_pInStream->readU8();
|
| 71 | int realSize = m_pInStream->readU16();
|
| 72 | int compressedSize = m_pInStream->readU16();
|
| 73 |
|
| 74 | if ((realSize == 0) && (compressedSize == 0)) {
|
| 75 | *pSize = 0;
|
| 76 | *pModTime = m_pInStream->readU32();
|
| 77 | return NULL;
|
| 78 | } else {
|
| 79 | char *pFile = new char [compressedSize];
|
| 80 | if (pFile == NULL) {
|
| 81 | m_pInStream->skip(compressedSize);
|
| 82 | *pModTime = 0;
|
| 83 | return NULL;
|
| 84 | } else {
|
| 85 | m_pInStream->readBytes(pFile, compressedSize);
|
| 86 | *pSize = compressedSize;
|
| 87 | return pFile;
|
| 88 | }
|
| 89 | }
|
| 90 | }
|
| 91 |
|
| 92 | char *
|
| 93 | CFTMsgReader::readFileUploadCancel(unsigned int *pReasonSize)
|
| 94 | {
|
| 95 | m_pInStream->skip(1);
|
| 96 | return readReasonMsg(pReasonSize);
|
| 97 | }
|
| 98 |
|
| 99 | char *
|
| 100 | CFTMsgReader::readFileDownloadFailed(unsigned int *pReasonSize)
|
| 101 | {
|
| 102 | m_pInStream->skip(1);
|
| 103 | return readReasonMsg(pReasonSize);
|
| 104 | }
|
| 105 |
|
| 106 | int
|
| 107 | CFTMsgReader::readFileDirSizeData(unsigned short *pDirSizeLow16,
|
| 108 | unsigned int *pDirSizeHigh32)
|
| 109 | {
|
| 110 | m_pInStream->skip(1);
|
| 111 | *pDirSizeLow16 = m_pInStream->readU16();
|
| 112 | *pDirSizeHigh32 = m_pInStream->readU32();
|
| 113 | return 1;
|
| 114 | }
|
| 115 |
|
| 116 | char *
|
| 117 | CFTMsgReader::readFileLastRqstFailed(int *pTypeOfRequest, unsigned int *pReasonSize)
|
| 118 | {
|
| 119 | *pTypeOfRequest = m_pInStream->readU8();
|
| 120 | return readReasonMsg(pReasonSize);
|
| 121 | }
|
| 122 |
|
| 123 | bool
|
| 124 | CFTMsgReader::createFileInfo(unsigned int numFiles, FileInfo *fi,
|
| 125 | SIZEDATAINFO *pSDInfo, char *pFilenames)
|
| 126 | {
|
| 127 | int pos = 0;
|
| 128 | int size = 0;
|
| 129 | for (unsigned int i = 0; i < numFiles; i++) {
|
| 130 | size = pSDInfo[i].size;
|
| 131 | if (size == FT_NET_ATTR_DIR) {
|
| 132 | fi->add((pFilenames + pos), size, pSDInfo[i].data, FT_ATTR_DIR);
|
| 133 | } else {
|
| 134 | fi->add((pFilenames + pos), size, pSDInfo[i].data, FT_ATTR_FILE);
|
| 135 | }
|
| 136 | pos += strlen(pFilenames + pos) + 1;
|
| 137 | }
|
| 138 | return true;
|
| 139 | }
|
| 140 |
|
| 141 | char *
|
| 142 | CFTMsgReader::readReasonMsg(unsigned int *pReasonSize)
|
| 143 | {
|
| 144 | int reasonLen = m_pInStream->readU16();
|
| 145 | int _reasonLen = reasonLen + 1;
|
| 146 | char *pReason;
|
| 147 | if (reasonLen == 0) {
|
| 148 | *pReasonSize = 0;
|
| 149 | return NULL;
|
| 150 | } else {
|
| 151 | pReason = new char [_reasonLen];
|
| 152 | if (pReason == NULL) {
|
| 153 | m_pInStream->skip(reasonLen);
|
| 154 | *pReasonSize = 0;
|
| 155 | return NULL;
|
| 156 | }
|
| 157 | m_pInStream->readBytes(pReason, reasonLen);
|
| 158 | memset(((char *)pReason+reasonLen), '\0', 1);
|
| 159 | return pReason;
|
| 160 | }
|
| 161 | }
|
| 162 |
|