summaryrefslogtreecommitdiff
path: root/src/lib/upload_destination.cc
blob: c91ba6a6fc6ca6e008f1710bf3c485115b6bae8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
    Copyright (C) 2025 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/


#include "upload_destination.h"
#include <libcxml/cxml.h>
#include <fmt/format.h>


UploadDestination::UploadDestination(cxml::ConstNodePtr node)
	: name(node->string_child("Name"))
	, protocol(file_transfer_protocol_from_string(node->string_child("Protocol")))
	, passive_ftp(node->bool_child("PassiveFTP"))
	, maximum_connections(node->optional_number_child<int>("MaximumConnections"))
	, host(node->string_child("Host"))
	, path(node->string_child("Path"))
	, user(node->string_child("User"))
	, password(node->string_child("Password"))
{

}


void
UploadDestination::as_xml(xmlpp::Element* parent) const
{
	cxml::add_text_child(parent, "Name", name);
	cxml::add_text_child(parent, "Protocol", file_transfer_protocol_to_string(protocol));
	cxml::add_text_child(parent, "PassiveFTP", passive_ftp ? "1" : "0");
	if (maximum_connections) {
		cxml::add_text_child(parent, "MaximumConnections", fmt::to_string(*maximum_connections));
	}
	cxml::add_text_child(parent, "Host", host);
	cxml::add_text_child(parent, "Path", path);
	cxml::add_text_child(parent, "User", user);
	cxml::add_text_child(parent, "Password", password);
}


bool
operator==(UploadDestination const& a, UploadDestination const& b)
{
	return a.name == b.name
		&& a.protocol == b.protocol
		&& a.passive_ftp == b.passive_ftp
		&& a.maximum_connections == b.maximum_connections
		&& a.host == b.host
		&& a.path == b.path
		&& a.user == b.user
		&& a.password == b.password;
}