Merge branch 'stroke-timeout'
[strongswan.git] / src / libimcv / imv / imv_reason_string.c
1 /*
2 * Copyright (C) 2012 Andreas Steffen
3 * HSR Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 */
15
16 #include "imv_reason_string.h"
17
18 #include <utils/debug.h>
19
20 typedef struct private_imv_reason_string_t private_imv_reason_string_t;
21
22 /**
23 * Private data of an imv_reason_string_t object.
24 */
25 struct private_imv_reason_string_t {
26
27 /**
28 * Public members of imv_reason_string_t
29 */
30 imv_reason_string_t public;
31
32 /**
33 * Preferred language
34 */
35 char *lang;
36
37 /**
38 * Contains the concatenated reasons
39 */
40 chunk_t reasons;
41
42 };
43
44 METHOD(imv_reason_string_t, add_reason, void,
45 private_imv_reason_string_t *this, imv_lang_string_t reason[])
46 {
47 char *s_reason;
48
49 s_reason = imv_lang_string_select_string(reason, this->lang);
50
51 if (this->reasons.len)
52 {
53 /* append any further reasons */
54 this->reasons = chunk_cat("mcc", this->reasons, chunk_from_chars('\n'),
55 chunk_create(s_reason, strlen(s_reason)));
56 }
57 else
58 {
59 /* add the first reason */
60 this->reasons = chunk_clone(chunk_create(s_reason, strlen(s_reason)));
61 }
62 }
63
64 METHOD(imv_reason_string_t, get_encoding, chunk_t,
65 private_imv_reason_string_t *this)
66 {
67 return this->reasons;
68 }
69
70 METHOD(imv_reason_string_t, destroy, void,
71 private_imv_reason_string_t *this)
72 {
73 free(this->reasons.ptr);
74 free(this);
75 }
76
77 /**
78 * Described in header.
79 */
80 imv_reason_string_t *imv_reason_string_create(char *lang)
81 {
82 private_imv_reason_string_t *this;
83
84 INIT(this,
85 .public = {
86 .add_reason = _add_reason,
87 .get_encoding = _get_encoding,
88 .destroy = _destroy,
89 },
90 .lang = lang,
91 );
92
93 return &this->public;
94 }
95