2 * Copyright (C) 2012 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "imv_remediation_string.h"
18 #include <utils/debug.h>
20 typedef struct private_imv_remediation_string_t private_imv_remediation_string_t
;
23 * Private data of an imv_remediation_string_t object.
25 struct private_imv_remediation_string_t
{
28 * Public members of imv_remediation_string_t
30 imv_remediation_string_t
public;
33 * XML or plaintext encoding
43 * Contains the concatenated remediation instructions
49 METHOD(imv_remediation_string_t
, add_instruction
, void,
50 private_imv_remediation_string_t
*this, imv_lang_string_t title
[],
51 imv_lang_string_t description
[], imv_lang_string_t itemsheader
[],
54 char xml_format
[] = " <instruction>\n"
55 " <title>%s</title>\n"
56 " <description>%s</description>\n"
59 char *instruction
, *format
, *s_title
, *s_description
, *s_itemsheader
;
62 s_title
= imv_lang_string_select_string(title
, this->lang
);
63 s_description
= imv_lang_string_select_string(description
, this->lang
);
64 s_itemsheader
= imv_lang_string_select_string(itemsheader
, this->lang
);
65 len
= strlen(s_title
) + strlen(s_description
);
70 len
+= strlen(xml_format
) - 8;
74 format
= this->instructions
.len ?
"\n%s\n%s%s%s" : "%s\n%s%s%s";
77 instruction
= malloc(len
+ 1);
78 sprintf(instruction
, format
, s_title
, s_description
, "", "");
79 this->instructions
= chunk_cat("mm", this->instructions
,
80 chunk_create(instruction
, strlen(instruction
)));
83 METHOD(imv_remediation_string_t
, get_encoding
, chunk_t
,
84 private_imv_remediation_string_t
*this)
86 char xml_header
[] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
87 "<remediationinstructions>\n";
88 char xml_trailer
[] = "</remediationinstructions>";
90 if (!this->instructions
.len
)
96 this->instructions
= chunk_cat("cmc",
97 chunk_create(xml_header
, strlen(xml_header
)),
99 chunk_create(xml_trailer
, strlen(xml_trailer
))
102 return this->instructions
;
105 METHOD(imv_remediation_string_t
, destroy
, void,
106 private_imv_remediation_string_t
*this)
108 free(this->instructions
.ptr
);
113 * Described in header.
115 imv_remediation_string_t
*imv_remediation_string_create(bool as_xml
, char *lang
)
117 private_imv_remediation_string_t
*this;
121 .add_instruction
= _add_instruction
,
122 .get_encoding
= _get_encoding
,
129 return &this->public;