blob: fa6a82f9c38bd0b21cac963b3dbdb5f1fe09c2fc [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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// -=- SFTMsgWriter.cxx
25
26#include <rfb/SFTMsgWriter.h>
27
28using namespace rfb;
29
30SFTMsgWriter::SFTMsgWriter(rdr::OutStream *pOS)
31{
32 m_pOS = pOS;
33}
34
35SFTMsgWriter::~SFTMsgWriter()
36{
37}
38
39bool
40SFTMsgWriter::writeFileListData(unsigned char flags, rfb::FileInfo *pFileInfo)
41{
42 unsigned int numFiles = pFileInfo->getNumEntries();
43
44 m_pOS->writeU8(msgTypeFileListData);
45 m_pOS->writeU8(flags);
46 m_pOS->writeU16(numFiles);
47
48 if (numFiles == 0) {
49 m_pOS->writeU16(0);
50 m_pOS->writeU16(0);
51 } else {
52 unsigned int filenamesSize = pFileInfo->getFilenamesSize() + numFiles;
53
54 m_pOS->writeU16(filenamesSize);
55 m_pOS->writeU16(filenamesSize);
56
57 char *pFilenames = new char [filenamesSize];
58 unsigned int pos = 0;
59
60 for (unsigned int i = 0; i < numFiles; i++) {
61 char *pName = pFileInfo->getNameAt(i);
62 unsigned int len = strlen(pName);
63
64 memcpy((void *)&pFilenames[pos], pName, len + 1);
65 pos += (len + 1);
66
67 if (pFileInfo->getFlagsAt(i) & FT_ATTR_DIR) {
68 m_pOS->writeU32(FT_NET_ATTR_DIR);
69 } else {
70 m_pOS->writeU32(pFileInfo->getSizeAt(i));
71 }
72 m_pOS->writeU32(pFileInfo->getDataAt(i));
73 }
74
75 m_pOS->writeBytes(pFilenames, filenamesSize);
76
77 delete [] pFilenames;
78 }
79
80 m_pOS->flush();
81
82 return true;
83}
84
85bool
86SFTMsgWriter::writeFileDownloadData(unsigned int dataSize, void *pData)
87{
88 m_pOS->writeU8(msgTypeFileDownloadData);
89 m_pOS->writeU8(0);
90 m_pOS->writeU16(dataSize);
91 m_pOS->writeU16(dataSize);
92 m_pOS->writeBytes(pData, dataSize);
93 m_pOS->flush();
94 return true;
95}
96
97bool
98SFTMsgWriter::writeFileDownloadData(unsigned int modTime)
99{
100 m_pOS->writeU8(msgTypeFileDownloadData);
101 m_pOS->writeU8(0);
102 m_pOS->writeU16(0);
103 m_pOS->writeU16(0);
104 m_pOS->writeU32(modTime);
105 m_pOS->flush();
106 return true;
107}
108
109bool
110SFTMsgWriter::writeFileUploadCancel(unsigned int reasonLen, char *pReason)
111{
112 m_pOS->writeU8(msgTypeFileUploadCancel);
113 return writeU8U16StringMsg(0, reasonLen, pReason);
114}
115
116bool
117SFTMsgWriter::writeFileDownloadFailed(unsigned int reasonLen, char *pReason)
118{
119 m_pOS->writeU8(msgTypeFileDownloadFailed);
120 return writeU8U16StringMsg(0, reasonLen, pReason);
121}
122
123bool
124SFTMsgWriter::writeFileDirSizeData(unsigned int dirSizeLow,
125 unsigned short dirSizeHigh)
126{
127 m_pOS->writeU8(msgTypeFileDirSizeData);
128 m_pOS->writeU8(0);
129 m_pOS->writeU16(dirSizeHigh);
130 m_pOS->writeU32(dirSizeLow);
131 m_pOS->flush();
132 return true;
133}
134
135bool
136SFTMsgWriter::writeFileLastRqstFailed(unsigned char lastRequest,
137 unsigned short reasonLen,
138 char *pReason)
139{
140 m_pOS->writeU8(msgTypeFileLastRequestFailed);
141 return writeU8U16StringMsg(lastRequest, reasonLen, pReason);
142}
143
144bool
145SFTMsgWriter::writeU8U16StringMsg(unsigned char p1, unsigned short p2, char *pP3)
146{
147 m_pOS->writeU8(p1);
148 m_pOS->writeU16(p2);
149 m_pOS->writeBytes(pP3, p2);
150 m_pOS->flush();
151 return true;
152}