1 /*
2 Bacula(R) - The Network Backup Solution
3
4 Copyright (C) 2000-2018 Kern Sibbald
5
6 The original author of Bacula is Kern Sibbald, with contributions
7 from many others, a complete list can be found in the file AUTHORS.
8
9 You may use this file and others of this release according to the
10 license defined in the LICENSE file, which includes the Affero General
11 Public License, v3.0 ("AGPLv3") and some additional permissions and
12 terms pursuant to its AGPLv3 Section 7.
13
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
16
17 Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20 * Written by James Harper, July 2010
21 *
22 * Used only in "old Exchange plugin" now deprecated.
23 */
24
25 #include "exchange-fd.h"
26
node_t(char * name,int type)27 node_t::node_t(char *name, int type)
28 {
29 this->type = type;
30 state = 0;
31 parent = NULL;
32 this->name = bstrdup(name);
33 full_path = make_full_path();
34 size = 0;
35 level = 0;
36 }
37
node_t(char * name,int type,node_t * parent_node)38 node_t::node_t(char *name, int type, node_t *parent_node)
39 {
40 this->type = type;
41 state = 0;
42 parent = parent_node;
43 this->name = bstrdup(name);
44 full_path = make_full_path();
45 size = 0;
46 level = parent->level + 1;
47 }
48
~node_t()49 node_t::~node_t()
50 {
51 safe_delete(name);
52 safe_delete(full_path);
53 }
54
55 char *
make_full_path()56 node_t::make_full_path()
57 {
58 node_t *curr_node;
59 int len;
60 char *retval;
61
62 for (len = 0, curr_node = this; curr_node != NULL; curr_node = curr_node->parent)
63 {
64 len += strlen(curr_node->name) + 1;
65 }
66 if (type == NODE_TYPE_FILE || type == NODE_TYPE_DATABASE_INFO)
67 {
68 retval = new char[len + 1];
69 retval[len] = 0;
70 }
71 else
72 {
73 retval = new char[len + 2];
74 retval[len] = '/';
75 retval[len + 1] = 0;
76 }
77 for (curr_node = this; curr_node != NULL; curr_node = curr_node->parent)
78 {
79 len -= strlen(curr_node->name);
80 memcpy(retval + len, curr_node->name, strlen(curr_node->name));
81 retval[--len] = '/';
82 }
83 return retval;
84 }
85
86 bRC
pluginIoOpen(exchange_fd_context_t * context,struct io_pkt * io)87 node_t::pluginIoOpen(exchange_fd_context_t *context, struct io_pkt *io)
88 {
89 _DebugMessage(100, "pluginIoOpen_Node\n");
90 io->status = 0;
91 io->io_errno = 0;
92 return bRC_OK;
93 }
94
95 bRC
pluginIoRead(exchange_fd_context_t * context,struct io_pkt * io)96 node_t::pluginIoRead(exchange_fd_context_t *context, struct io_pkt *io)
97 {
98 _DebugMessage(100, "pluginIoRead_Node\n");
99 io->status = 0;
100 io->io_errno = 0;
101 return bRC_OK;
102 }
103
104 bRC
pluginIoWrite(exchange_fd_context_t * context,struct io_pkt * io)105 node_t::pluginIoWrite(exchange_fd_context_t *context, struct io_pkt *io)
106 {
107 _DebugMessage(100, "pluginIoWrite_Node\n");
108 io->status = 0;
109 io->io_errno = 1;
110 return bRC_Error;
111 }
112
113 bRC
pluginIoClose(exchange_fd_context_t * context,struct io_pkt * io)114 node_t::pluginIoClose(exchange_fd_context_t *context, struct io_pkt *io)
115 {
116 _DebugMessage(100, "pluginIoClose_Node\n");
117 io->status = 0;
118 io->io_errno = 0;
119 return bRC_OK;
120 }
121