Revision d03ed158 src/zone/Zone.cc

View differences:

src/zone/Zone.cc
15 15
/* ------------------------------------------------------------------------ */
16 16

  
17 17
#include "Zone.h"
18
#include "ZoneServer.h"
18 19

  
19 20
/* ------------------------------------------------------------------------ */
20 21

  
......
28 29
    "gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, "
29 30
    "UNIQUE(name))";
30 31

  
32
const char * ZoneServers::SERVER_NAME    = "SERVER";
33

  
34
const char * ZoneServers::SERVER_ID_NAME = "ID";
35

  
31 36
/* -------------------------------------------------------------------------- */
32 37
/* -------------------------------------------------------------------------- */
33 38

  
34 39
Zone::Zone(int id, Template* zone_template):
35
        PoolObjectSQL(id, ZONE, "", -1, -1, "", "", table)
40
        PoolObjectSQL(id, ZONE, "", -1, -1, "", "", table), servers_template(
41
                false, '=', "SERVER_POOL"), servers(0)
36 42
{
37 43
    if (zone_template != 0)
38 44
    {
......
50 56
Zone::~Zone()
51 57
{
52 58
    delete obj_template;
59

  
60
    delete servers;
53 61
};
54 62

  
55 63
/* ************************************************************************ */
......
63 71

  
64 72
    ostringstream oss;
65 73

  
66
    // ---------------------------------------------------------------------
74
    // -------------------------------------------------------------------------
67 75
    // Check default attributes
68
    // ---------------------------------------------------------------------
76
    // -------------------------------------------------------------------------
69 77

  
70 78
    erase_template_attribute("NAME", name);
71 79

  
......
82 90
        goto error_endpoint;
83 91
    }
84 92

  
85
    // ------------------------------------------------------------------------
93
    remove_template_attribute("SERVER");
94

  
95
    // -------------------------------------------------------------------------
86 96
    // Insert the Zone
87
    // ------------------------------------------------------------------------
97
    // -------------------------------------------------------------------------
88 98

  
89 99
    rc = insert_replace(db, false, error_str);
90 100

  
......
192 202

  
193 203
string& Zone::to_xml(string& xml) const
194 204
{
195
    ostringstream   oss;
196
    string          template_xml;
205
    ostringstream oss;
206

  
207
    string template_xml;
208
    string server_xml;
197 209

  
198 210
    oss <<
199 211
    "<ZONE>"    <<
200 212
        "<ID>"   << oid  << "</ID>"   <<
201 213
        "<NAME>" << name << "</NAME>" <<
202 214
        obj_template->to_xml(template_xml) <<
215
        servers_template.to_xml(server_xml) <<
203 216
    "</ZONE>";
204 217

  
205 218
    xml = oss.str();
......
207 220
    return xml;
208 221
}
209 222

  
210
/* ------------------------------------------------------------------------ */
211
/* ------------------------------------------------------------------------ */
223
/* -------------------------------------------------------------------------- */
224
/* -------------------------------------------------------------------------- */
212 225

  
213 226
int Zone::from_xml(const string& xml)
214 227
{
......
222 235
    rc += xpath(oid, "/ZONE/ID",   -1);
223 236
    rc += xpath(name,"/ZONE/NAME", "not_found");
224 237

  
225
    // Get associated classes
238
    // -------------------------------------------------------------------------
239
    // Zone template
240
    // -------------------------------------------------------------------------
226 241
    ObjectXML::get_nodes("/ZONE/TEMPLATE", content);
227 242

  
228 243
    if (content.empty())
......
230 245
        return -1;
231 246
    }
232 247

  
233
    // Template contents
234 248
    rc += obj_template->from_xml_node(content[0]);
235 249

  
236 250
    ObjectXML::free_nodes(content);
237 251
    content.clear();
238 252

  
253
    // -------------------------------------------------------------------------
254
    // Zone Server template
255
    // -------------------------------------------------------------------------
256
    ObjectXML::get_nodes("/ZONE/SERVER_POOL", content);
257

  
258
    if (content.empty())
259
    {
260
        return -1;
261
    }
262

  
263
    rc += servers_template.from_xml_node(content[0]);
264

  
265
    ObjectXML::free_nodes(content);
266
    content.clear();
267

  
239 268
    if (rc != 0)
240 269
    {
241 270
        return -1;
......
245 274
    set_user(0,"");
246 275
    set_group(0,"");
247 276

  
277
    servers = new ZoneServers(&servers_template);
278

  
248 279
    return 0;
249 280
}
250 281

  
251
/* ------------------------------------------------------------------------ */
252
/* ------------------------------------------------------------------------ */
282
/* -------------------------------------------------------------------------- */
283
/* -------------------------------------------------------------------------- */
253 284

  
254 285
int Zone::post_update_template(string& error)
255 286
{
......
261 292
        replace_template_attribute("ENDPOINT", "-");
262 293
    }
263 294

  
295
    remove_template_attribute("SERVER");
296

  
264 297
    return 0;
265 298
}
266 299

  
267
/* ------------------------------------------------------------------------ */
268
/* ------------------------------------------------------------------------ */
300
/* -------------------------------------------------------------------------- */
301
/* -------------------------------------------------------------------------- */

Also available in: Unified diff