implemented TNCCS 1.1 without libtnc
[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_preferred_language_msg.h"
19
20 #include <library.h>
21 #include <debug.h>
22
23 ENUM(tnccs_msg_type_names, IMC_IMV_MSG, TNCCS_MSG_ROOF,
24 "IMC-IMV",
25 "TNCCS-Recommendation",
26 "TNCCS-Error",
27 "TNCCS-PreferredLanguage",
28 "TNCCS-ReasonStrings",
29 "TNCCS-TNCSContactInfo"
30 );
31
32 /**
33 * See header
34 */
35 tnccs_msg_t* tnccs_msg_create_from_node(xmlNodePtr node)
36 {
37 tnccs_msg_type_t type = IMC_IMV_MSG;
38
39 if (streq((char*)node->name, "IMC-IMV-Message"))
40 {
41 return imc_imv_msg_create_from_node(node);
42 }
43 else if (streq((char*)node->name, "TNCC-TNCS-Message"))
44 {
45 bool found = FALSE;
46 xmlNsPtr ns = node->ns;
47 xmlNodePtr cur = node->xmlChildrenNode;
48
49 while (cur)
50 {
51 if (streq((char*)cur->name, "Type") && cur->ns == ns)
52 {
53 xmlChar *content = xmlNodeGetContent(cur);
54
55 type = strtol((char*)content, NULL, 16);
56 xmlFree(content);
57 found = TRUE;
58 break;
59 }
60 }
61 if (!found)
62 {
63 DBG1(DBG_TNC, "ignoring TNCC-TNCS-Messsage without type");
64 return NULL;
65 }
66 switch (type)
67 {
68 case TNCCS_MSG_RECOMMENDATION:
69 return tnccs_recommendation_msg_create_from_node(node);
70 case TNCCS_MSG_ERROR:
71 return tnccs_error_msg_create_from_node(node);
72 case TNCCS_MSG_PREFERRED_LANGUAGE:
73 return tnccs_preferred_language_msg_create_from_node(node);
74 case TNCCS_MSG_REASON_STRINGS:
75 return tnccs_reason_strings_msg_create_from_node(node);
76 case TNCCS_MSG_TNCS_CONTACT_INFO:
77 return tnccs_tncs_contact_info_msg_create_from_node(node);
78 default:
79 DBG1(DBG_TNC, "ignoring TNCC-TNCS-Message with type %d", type);
80 return NULL;
81 }
82 }
83 DBG1(DBG_TNC, "ignoring unknown message node '%s'", (char*)node->name);
84 return NULL;
85 }
86