]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/libimcv/imv/imv_reason_string.c
Update copyright headers after acquisition by secunet
[thirdparty/strongswan.git] / src / libimcv / imv / imv_reason_string.c
CommitLineData
ee6aeca8
AS
1/*
2 * Copyright (C) 2012 Andreas Steffen
19ef2aec
TB
3 *
4 * Copyright (C) secunet Security Networks AG
ee6aeca8
AS
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 */
16
17#include "imv_reason_string.h"
18
19#include <utils/debug.h>
20
21typedef struct private_imv_reason_string_t private_imv_reason_string_t;
22
23/**
24 * Private data of an imv_reason_string_t object.
25 */
26struct private_imv_reason_string_t {
27
28 /**
29 * Public members of imv_reason_string_t
30 */
31 imv_reason_string_t public;
32
33 /**
34 * Preferred language
35 */
36 char *lang;
37
81d49c5c
AS
38 /**
39 * Separator concatenating multiple reasons
40 */
41 char *separator;
42
ee6aeca8
AS
43 /**
44 * Contains the concatenated reasons
45 */
46 chunk_t reasons;
47
48};
49
50METHOD(imv_reason_string_t, add_reason, void,
51 private_imv_reason_string_t *this, imv_lang_string_t reason[])
52{
53 char *s_reason;
54
55 s_reason = imv_lang_string_select_string(reason, this->lang);
56
57 if (this->reasons.len)
58 {
59 /* append any further reasons */
81d49c5c
AS
60 this->reasons = chunk_cat("mcc", this->reasons,
61 chunk_from_str(this->separator),
ee6aeca8
AS
62 chunk_create(s_reason, strlen(s_reason)));
63 }
64 else
65 {
66 /* add the first reason */
67 this->reasons = chunk_clone(chunk_create(s_reason, strlen(s_reason)));
68 }
69}
70
71METHOD(imv_reason_string_t, get_encoding, chunk_t,
72 private_imv_reason_string_t *this)
73{
74 return this->reasons;
75}
76
77METHOD(imv_reason_string_t, destroy, void,
78 private_imv_reason_string_t *this)
79{
80 free(this->reasons.ptr);
81 free(this);
82}
83
84/**
85 * Described in header.
86 */
81d49c5c 87imv_reason_string_t *imv_reason_string_create(char *lang, char *separator)
ee6aeca8
AS
88{
89 private_imv_reason_string_t *this;
90
91 INIT(this,
92 .public = {
93 .add_reason = _add_reason,
94 .get_encoding = _get_encoding,
95 .destroy = _destroy,
96 },
97 .lang = lang,
81d49c5c 98 .separator = separator,
ee6aeca8
AS
99 );
100
101 return &this->public;
102}
103