1 /*****************************************************************************\
3 * Name : file_transfer_infoton *
4 * Author : Chris Koeritz *
6 *******************************************************************************
7 * Copyright (c) 2005-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 #include "file_transfer_infoton.h"
17 #include <basis/mutex.h>
18 #include <structures/string_array.h>
19 #include <structures/static_memory_gremlin.h>
21 using namespace basis;
22 using namespace filesystem;
23 using namespace structures;
27 file_transfer_infoton::file_transfer_infoton()
28 : infoton(file_transfer_classifier()),
29 _success(common::OKAY),
31 _command(TREE_COMPARISON),
37 file_transfer_infoton::file_transfer_infoton(const outcome &success,
38 bool request, commands command,
39 const astring &source, const astring &destination,
40 const byte_array &packed_data)
41 : infoton(file_transfer_classifier()),
44 _command(abyte(command)),
46 _dest_root(destination),
47 _packed_data(packed_data)
50 file_transfer_infoton::~file_transfer_infoton()
54 void file_transfer_infoton::text_form(basis::base_string &fill) const
56 fill.assign(astring(class_name()) + ": unimplemented text_form.");
59 const char *file_transfer_constant = "#ftran";
61 SAFE_STATIC_CONST(string_array,
62 file_transfer_infoton::file_transfer_classifier,
63 (1, &file_transfer_constant))
65 int file_transfer_infoton::packed_size() const
69 + _src_root.length() + 1
70 + _dest_root.length() + 1
71 + _packed_data.length() + sizeof(int);
74 void file_transfer_infoton::package_tree_info(const directory_tree &tree,
75 const string_array &includes)
78 tree.pack(_packed_data);
79 includes.pack(_packed_data);
82 void file_transfer_infoton::pack(byte_array &packed_form) const
84 attach(packed_form, _success.value());
85 attach(packed_form, abyte(_request));
86 attach(packed_form, _command);
87 _src_root.pack(packed_form);
88 _dest_root.pack(packed_form);
89 attach(packed_form, _packed_data);
92 bool file_transfer_infoton::unpack(byte_array &packed_form)
95 if (!detach(packed_form, temp_o)) return false;
98 if (!detach(packed_form, temp)) return false;
100 if (!detach(packed_form, _command)) return false;
101 if (!_src_root.unpack(packed_form)) return false;
102 if (!_dest_root.unpack(packed_form)) return false;
103 if (!detach(packed_form, _packed_data)) return false;