cb7360f41ef41b9d9a30c2b0107f91008d29bd78
[strongswan.git] / src / libcharon / plugins / tnccs_11 / messages / tnccs_msg.c
1 /*
2 * Copyright (C) 2006 Mike McCauley (mikem@open.com.au)
3 * Copyright (C) 2010 Andreas Steffen, 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 "tnccs_msg.h"
17 #include "imc_imv_msg.h"
18 #include "tnccs_error_msg.h"
19 #include "tnccs_preferred_language_msg.h"
20 #include "tnccs_reason_strings_msg.h"
21 #include "tnccs_recommendation_msg.h"
22 #include "tnccs_tncs_contact_info_msg.h"
23
24 #include <library.h>
25 #include <debug.h>
26
27 ENUM(tnccs_msg_type_names, IMC_IMV_MSG, TNCCS_MSG_ROOF,
28 "IMC-IMV",
29 "TNCCS-Recommendation",
30 "TNCCS-Error",
31 "TNCCS-PreferredLanguage",
32 "TNCCS-ReasonStrings",
33 "TNCCS-TNCSContactInfo"
34 );
35
36 /**
37 * See header
38 */
39 tnccs_msg_t* tnccs_msg_create_from_node(xmlNodePtr node)
40 {
41 tnccs_msg_type_t type = IMC_IMV_MSG;
42
43 if (streq((char*)node->name, "IMC-IMV-Message"))
44 {
45 return imc_imv_msg_create_from_node(node);
46 }
47 else if (streq((char*)node->name, "TNCC-TNCS-Message"))
48 {
49 bool found = FALSE;
50 xmlNsPtr ns = node->ns;
51 xmlNodePtr cur = node->xmlChildrenNode;
52
53 while (cur)
54 {
55 if (streq((char*)cur->name, "Type") && cur->ns == ns)
56 {
57 xmlChar *content = xmlNodeGetContent(cur);
58
59 type = strtol((char*)content, NULL, 16);
60 xmlFree(content);
61 found = TRUE;
62 break;
63 }
64 cur = cur->next;
65 }
66 if (!found)
67 {
68 DBG1(DBG_TNC, "ignoring TNCC-TNCS-Messsage without type");
69 return NULL;
70 }
71 switch (type)
72 {
73 case TNCCS_MSG_RECOMMENDATION:
74 return tnccs_recommendation_msg_create_from_node(node);
75 case TNCCS_MSG_ERROR:
76 return tnccs_error_msg_create_from_node(node);
77 case TNCCS_MSG_PREFERRED_LANGUAGE:
78 return tnccs_preferred_language_msg_create_from_node(node);
79 case TNCCS_MSG_REASON_STRINGS:
80 return tnccs_reason_strings_msg_create_from_node(node);
81 case TNCCS_MSG_TNCS_CONTACT_INFO:
82 return tnccs_tncs_contact_info_msg_create_from_node(node);
83 default:
84 DBG1(DBG_TNC, "ignoring TNCC-TNCS-Message with type %d", type);
85 return NULL;
86 }
87 }
88 DBG1(DBG_TNC, "ignoring unknown message node '%s'", (char*)node->name);
89 return NULL;
90 }
91