summaryrefslogtreecommitdiff
path: root/src/libimcv/imv/imv_reason_string.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@debian.org>2013-02-07 13:27:27 +0100
committerYves-Alexis Perez <corsac@debian.org>2013-02-07 13:27:27 +0100
commit7585facf05d927eb6df3929ce09ed5e60d905437 (patch)
treee4d14b4dc180db20356b6b01ce0112f3a2d7897e /src/libimcv/imv/imv_reason_string.c
parentc1343b3278cdf99533b7902744d15969f9d6fdc1 (diff)
downloadvyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.tar.gz
vyos-strongswan-7585facf05d927eb6df3929ce09ed5e60d905437.zip
Imported Upstream version 5.0.2
Diffstat (limited to 'src/libimcv/imv/imv_reason_string.c')
-rw-r--r--src/libimcv/imv/imv_reason_string.c95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/libimcv/imv/imv_reason_string.c b/src/libimcv/imv/imv_reason_string.c
new file mode 100644
index 000000000..18eade01b
--- /dev/null
+++ b/src/libimcv/imv/imv_reason_string.c
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2012 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program 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. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program 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.
+ */
+
+#include "imv_reason_string.h"
+
+#include <utils/debug.h>
+
+typedef struct private_imv_reason_string_t private_imv_reason_string_t;
+
+/**
+ * Private data of an imv_reason_string_t object.
+ */
+struct private_imv_reason_string_t {
+
+ /**
+ * Public members of imv_reason_string_t
+ */
+ imv_reason_string_t public;
+
+ /**
+ * Preferred language
+ */
+ char *lang;
+
+ /**
+ * Contains the concatenated reasons
+ */
+ chunk_t reasons;
+
+};
+
+METHOD(imv_reason_string_t, add_reason, void,
+ private_imv_reason_string_t *this, imv_lang_string_t reason[])
+{
+ char *s_reason;
+
+ s_reason = imv_lang_string_select_string(reason, this->lang);
+
+ if (this->reasons.len)
+ {
+ /* append any further reasons */
+ this->reasons = chunk_cat("cm", this->reasons, chunk_from_chars('\n'),
+ chunk_create(s_reason, strlen(s_reason)));
+ }
+ else
+ {
+ /* add the first reason */
+ this->reasons = chunk_clone(chunk_create(s_reason, strlen(s_reason)));
+ }
+}
+
+METHOD(imv_reason_string_t, get_encoding, chunk_t,
+ private_imv_reason_string_t *this)
+{
+ return this->reasons;
+}
+
+METHOD(imv_reason_string_t, destroy, void,
+ private_imv_reason_string_t *this)
+{
+ free(this->reasons.ptr);
+ free(this);
+}
+
+/**
+ * Described in header.
+ */
+imv_reason_string_t *imv_reason_string_create(char *lang)
+{
+ private_imv_reason_string_t *this;
+
+ INIT(this,
+ .public = {
+ .add_reason = _add_reason,
+ .get_encoding = _get_encoding,
+ .destroy = _destroy,
+ },
+ .lang = lang,
+ );
+
+ return &this->public;
+}
+