generate TNCCS-Error messages
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tnccs_batch.h"
|
#include "tnccs_batch.h"
|
||||||
|
#include "messages/tnccs_error_msg.h"
|
||||||
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <utils/linked_list.h>
|
#include <utils/linked_list.h>
|
||||||
@@ -48,6 +49,11 @@ struct private_tnccs_batch_t {
|
|||||||
*/
|
*/
|
||||||
linked_list_t *messages;
|
linked_list_t *messages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* linked list of TNCCS error messages
|
||||||
|
*/
|
||||||
|
linked_list_t *errors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML document
|
* XML document
|
||||||
*/
|
*/
|
||||||
@@ -92,7 +98,9 @@ METHOD(tnccs_batch_t, build, void,
|
|||||||
METHOD(tnccs_batch_t, process, status_t,
|
METHOD(tnccs_batch_t, process, status_t,
|
||||||
private_tnccs_batch_t *this)
|
private_tnccs_batch_t *this)
|
||||||
{
|
{
|
||||||
tnccs_msg_t *tnccs_msg;
|
tnccs_msg_t *tnccs_msg, *msg;
|
||||||
|
tnccs_error_type_t error_type = TNCCS_ERROR_OTHER;
|
||||||
|
char *error_msg, buf[BUF_LEN];
|
||||||
xmlNodePtr cur;
|
xmlNodePtr cur;
|
||||||
xmlNsPtr ns;
|
xmlNsPtr ns;
|
||||||
xmlChar *batchid, *recipient;
|
xmlChar *batchid, *recipient;
|
||||||
@@ -103,16 +111,18 @@ METHOD(tnccs_batch_t, process, status_t,
|
|||||||
this->doc = xmlParseMemory(this->encoding.ptr, this->encoding.len);
|
this->doc = xmlParseMemory(this->encoding.ptr, this->encoding.len);
|
||||||
if (!this->doc)
|
if (!this->doc)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "failed to parse XML message");
|
error_type = TNCCS_ERROR_MALFORMED_BATCH;
|
||||||
return FAILED;
|
error_msg = "failed to parse XML message";
|
||||||
|
goto fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check out the XML document */
|
/* check out the XML document */
|
||||||
cur = xmlDocGetRootElement(this->doc);
|
cur = xmlDocGetRootElement(this->doc);
|
||||||
if (!cur)
|
if (!cur)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "empty XML document");
|
error_type = TNCCS_ERROR_MALFORMED_BATCH;
|
||||||
return FAILED;
|
error_msg = "empty XML document";
|
||||||
|
goto fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check TNCCS namespace */
|
/* check TNCCS namespace */
|
||||||
@@ -120,24 +130,28 @@ METHOD(tnccs_batch_t, process, status_t,
|
|||||||
"http://www.trustedcomputinggroup.org/IWG/TNC/1_0/IF_TNCCS#");
|
"http://www.trustedcomputinggroup.org/IWG/TNC/1_0/IF_TNCCS#");
|
||||||
if (!ns)
|
if (!ns)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "TNCCS namespace not found");
|
error_type = TNCCS_ERROR_MALFORMED_BATCH;
|
||||||
return FAILED;
|
error_msg = "TNCCS namespace not found";
|
||||||
|
goto fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check XML document type */
|
/* check XML document type */
|
||||||
if (xmlStrcmp(cur->name, (const xmlChar*)"TNCCS-Batch"))
|
if (xmlStrcmp(cur->name, (const xmlChar*)"TNCCS-Batch"))
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "wrong XML document type '%s', expected TNCCS-Batch",
|
error_type = TNCCS_ERROR_MALFORMED_BATCH;
|
||||||
cur->name);
|
error_msg = buf;
|
||||||
return FAILED;
|
snprintf(buf, BUF_LEN, "wrong XML document type '%s', expected TNCCS-Batch",
|
||||||
|
cur->name);
|
||||||
|
goto fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check presence of BatchID property */
|
/* check presence of BatchID property */
|
||||||
batchid = xmlGetProp(cur, (const xmlChar*)"BatchId");
|
batchid = xmlGetProp(cur, (const xmlChar*)"BatchId");
|
||||||
if (!batchid)
|
if (!batchid)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "BatchId is missing");
|
error_type = TNCCS_ERROR_INVALID_BATCH_ID;
|
||||||
return FAILED;
|
error_msg = "BatchId is missing";
|
||||||
|
goto fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check BatchID */
|
/* check BatchID */
|
||||||
@@ -145,28 +159,36 @@ METHOD(tnccs_batch_t, process, status_t,
|
|||||||
xmlFree(batchid);
|
xmlFree(batchid);
|
||||||
if (batch_id != this->batch_id)
|
if (batch_id != this->batch_id)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "BatchID %d expected, got %d", this->batch_id, batch_id);
|
error_type = TNCCS_ERROR_INVALID_BATCH_ID;
|
||||||
return FAILED;
|
error_msg = buf;
|
||||||
|
snprintf(buf, BUF_LEN, "BatchId %d expected, got %d", this->batch_id,
|
||||||
|
batch_id);
|
||||||
|
goto fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check presence of Recipient property */
|
/* check presence of Recipient property */
|
||||||
recipient = xmlGetProp(cur, (const xmlChar*)"Recipient");
|
recipient = xmlGetProp(cur, (const xmlChar*)"Recipient");
|
||||||
if (!recipient)
|
if (!recipient)
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "Recipient is missing");
|
error_type = TNCCS_ERROR_INVALID_RECIPIENT_TYPE;
|
||||||
return FAILED;
|
error_msg = "Recipient is missing";
|
||||||
|
goto fatal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check recipient */
|
/* check recipient */
|
||||||
if (!streq((char*)recipient, this->is_server ? "TNCS" : "TNCC"))
|
if (!streq((char*)recipient, this->is_server ? "TNCS" : "TNCC"))
|
||||||
{
|
{
|
||||||
DBG1(DBG_TNC, "message recipient expected '%s', got '%s'",
|
error_type = TNCCS_ERROR_INVALID_RECIPIENT_TYPE;
|
||||||
this->is_server ? "TNCS" : "TNCC", (char*)recipient);
|
error_msg = buf;
|
||||||
|
snprintf(buf, BUF_LEN, "message recipient expected '%s', got '%s'",
|
||||||
|
this->is_server ? "TNCS" : "TNCC", (char*)recipient);
|
||||||
xmlFree(recipient);
|
xmlFree(recipient);
|
||||||
return FAILED;
|
goto fatal;
|
||||||
}
|
}
|
||||||
xmlFree(recipient);
|
xmlFree(recipient);
|
||||||
|
|
||||||
|
DBG2(DBG_TNC, "processing TNCCS Batch #%d", batch_id);
|
||||||
|
|
||||||
/* Now walk the tree, handling message nodes as we go */
|
/* Now walk the tree, handling message nodes as we go */
|
||||||
for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next)
|
for (cur = cur->xmlChildrenNode; cur != NULL; cur = cur->next)
|
||||||
{
|
{
|
||||||
@@ -190,6 +212,8 @@ METHOD(tnccs_batch_t, process, status_t,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DBG2(DBG_TNC, "processing %N message", tnccs_msg_type_names,
|
||||||
|
tnccs_msg->get_type(tnccs_msg));
|
||||||
status = tnccs_msg->process(tnccs_msg);
|
status = tnccs_msg->process(tnccs_msg);
|
||||||
if (status == FAILED)
|
if (status == FAILED)
|
||||||
{
|
{
|
||||||
@@ -199,6 +223,13 @@ METHOD(tnccs_batch_t, process, status_t,
|
|||||||
this->messages->insert_last(this->messages, tnccs_msg);
|
this->messages->insert_last(this->messages, tnccs_msg);
|
||||||
}
|
}
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
|
|
||||||
|
fatal:
|
||||||
|
DBG1(DBG_TNC, "%s", error_msg);
|
||||||
|
msg = tnccs_error_msg_create(error_type, error_msg);
|
||||||
|
this->errors->insert_last(this->errors, msg);
|
||||||
|
return FAILED;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(tnccs_batch_t, create_msg_enumerator, enumerator_t*,
|
METHOD(tnccs_batch_t, create_msg_enumerator, enumerator_t*,
|
||||||
@@ -212,6 +243,8 @@ METHOD(tnccs_batch_t, destroy, void,
|
|||||||
{
|
{
|
||||||
this->messages->destroy_offset(this->messages,
|
this->messages->destroy_offset(this->messages,
|
||||||
offsetof(tnccs_msg_t, destroy));
|
offsetof(tnccs_msg_t, destroy));
|
||||||
|
this->errors->destroy_offset(this->errors,
|
||||||
|
offsetof(tnccs_msg_t, destroy));
|
||||||
xmlFreeDoc(this->doc);
|
xmlFreeDoc(this->doc);
|
||||||
free(this->encoding.ptr);
|
free(this->encoding.ptr);
|
||||||
free(this);
|
free(this);
|
||||||
@@ -238,6 +271,7 @@ tnccs_batch_t* tnccs_batch_create(bool is_server, int batch_id)
|
|||||||
},
|
},
|
||||||
.is_server = is_server,
|
.is_server = is_server,
|
||||||
.messages = linked_list_create(),
|
.messages = linked_list_create(),
|
||||||
|
.errors = linked_list_create(),
|
||||||
.batch_id = batch_id,
|
.batch_id = batch_id,
|
||||||
.doc = xmlNewDoc(BAD_CAST "1.0"),
|
.doc = xmlNewDoc(BAD_CAST "1.0"),
|
||||||
);
|
);
|
||||||
@@ -276,6 +310,7 @@ tnccs_batch_t* tnccs_batch_create_from_data(bool is_server, int batch_id, chunk_
|
|||||||
.is_server = is_server,
|
.is_server = is_server,
|
||||||
.batch_id = batch_id,
|
.batch_id = batch_id,
|
||||||
.messages = linked_list_create(),
|
.messages = linked_list_create(),
|
||||||
|
.errors = linked_list_create(),
|
||||||
.encoding = chunk_clone(data),
|
.encoding = chunk_clone(data),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user