aboutsummaryrefslogtreecommitdiffstats
path: root/src/libtnccs
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2014-05-16 11:57:54 +0200
committerMartin Willi <martin@revosec.ch>2014-05-16 15:42:07 +0200
commit064fe9c963b7aa0ea904ab15443198d965175461 (patch)
treebaafea8cdeb46701d996a07fa2bbb2c54fdf3458 /src/libtnccs
parent9ee8b3b41f9dd24e49f4fd80c5891f134b38d161 (diff)
downloadstrongswan-064fe9c963b7aa0ea904ab15443198d965175461.tar.bz2
strongswan-064fe9c963b7aa0ea904ab15443198d965175461.tar.xz
enum: Return boolean result for enum_from_name() lookup
Handling the result for enum_from_name() is difficult, as checking for negative return values requires a cast if the enum type is unsigned. The new signature clearly differentiates lookup result from lookup value. Further, this actually allows to convert real -1 enum values, which could not be distinguished from "not-found" and the -1 return value. This also fixes several clang warnings where enums are unsigned.
Diffstat (limited to 'src/libtnccs')
-rw-r--r--src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c13
-rw-r--r--src/libtnccs/plugins/tnccs_11/messages/tnccs_error_msg.c5
-rw-r--r--src/libtnccs/plugins/tnccs_11/messages/tnccs_msg.c6
3 files changed, 12 insertions, 12 deletions
diff --git a/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c b/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c
index 56245015b..1a031582b 100644
--- a/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c
+++ b/src/libtnccs/plugins/tnc_imv/tnc_imv_manager.c
@@ -432,7 +432,7 @@ METHOD(imv_manager_t, destroy, void,
imv_manager_t* tnc_imv_manager_create(void)
{
private_tnc_imv_manager_t *this;
- recommendation_policy_t policy;
+ char *polname;
INIT(this,
.public = {
@@ -458,11 +458,12 @@ imv_manager_t* tnc_imv_manager_create(void)
.next_imv_id = 1,
);
- policy = enum_from_name(recommendation_policy_names,
- lib->settings->get_str(lib->settings,
- "%s.plugins.tnc-imv.recommendation_policy",
- "default", lib->ns));
- this->policy = (policy != -1) ? policy : RECOMMENDATION_POLICY_DEFAULT;
+ polname = lib->settings->get_str(lib->settings,
+ "%s.plugins.tnc-imv.recommendation_policy", "default", lib->ns);
+ if (!enum_from_name(recommendation_policy_names, polname, &this->policy))
+ {
+ this->policy = RECOMMENDATION_POLICY_DEFAULT;
+ }
DBG1(DBG_TNC, "TNC recommendation policy is '%N'",
recommendation_policy_names, this->policy);
diff --git a/src/libtnccs/plugins/tnccs_11/messages/tnccs_error_msg.c b/src/libtnccs/plugins/tnccs_11/messages/tnccs_error_msg.c
index 86b7c6aa5..26a6c032f 100644
--- a/src/libtnccs/plugins/tnccs_11/messages/tnccs_error_msg.c
+++ b/src/libtnccs/plugins/tnccs_11/messages/tnccs_error_msg.c
@@ -128,9 +128,8 @@ tnccs_msg_t *tnccs_error_msg_create_from_node(xmlNodePtr node)
error_type_name = xmlGetProp(node, "type");
if (error_type_name)
{
- this->error_type = enum_from_name(tnccs_error_type_names,
- error_type_name);
- if (this->error_type == -1)
+ if (!enum_from_name(tnccs_error_type_names, error_type_name,
+ &this->error_type))
{
this->error_type = TNCCS_ERROR_OTHER;
}
diff --git a/src/libtnccs/plugins/tnccs_11/messages/tnccs_msg.c b/src/libtnccs/plugins/tnccs_11/messages/tnccs_msg.c
index fa5ce8239..e3736560d 100644
--- a/src/libtnccs/plugins/tnccs_11/messages/tnccs_msg.c
+++ b/src/libtnccs/plugins/tnccs_11/messages/tnccs_msg.c
@@ -41,7 +41,7 @@ tnccs_msg_t* tnccs_msg_create_from_node(xmlNodePtr node, linked_list_t *errors)
char *error_msg, buf[BUF_LEN];
tnccs_error_type_t error_type = TNCCS_ERROR_MALFORMED_BATCH;
tnccs_msg_t *msg;
- tnccs_msg_type_t type = IMC_IMV_MSG;
+ tnccs_msg_type_t type = IMC_IMV_MSG, nametype;
if (streq((char*)node->name, "IMC-IMV-Message"))
{
@@ -103,7 +103,8 @@ tnccs_msg_t* tnccs_msg_create_from_node(xmlNodePtr node, linked_list_t *errors)
error_msg = "node is not in the TNCCS message namespace";
goto fatal;
}
- if (type != enum_from_name(tnccs_msg_type_names, (char*)cur->name))
+ if (!enum_from_name(tnccs_msg_type_names, cur->name, &nametype) ||
+ type != nametype)
{
error_msg = buf;
snprintf(buf, BUF_LEN, "expected '%N' node but was '%s'",
@@ -137,4 +138,3 @@ fatal:
errors->insert_last(errors, msg);
return NULL;
}
-