Change all C code to return ndn_Error enum instead of char * error string.
diff --git a/ndn-cpp/c/encoding/BinaryXMLDecoder.c b/ndn-cpp/c/encoding/BinaryXMLDecoder.c
index 311b30a..025e679 100644
--- a/ndn-cpp/c/encoding/BinaryXMLDecoder.c
+++ b/ndn-cpp/c/encoding/BinaryXMLDecoder.c
@@ -30,9 +30,9 @@
* @param value
* @param valueLength
* @param resultOut output the parsed integer.
- * @return 0 for success, else an error string, including if an element of value is not a decimal digit.
+ * @return 0 for success, else an error code, including if an element of value is not a decimal digit.
*/
-static char *parseUnsignedDecimalInt(unsigned char *value, unsigned int valueLength, unsigned int *resultOut)
+static ndn_Error parseUnsignedDecimalInt(unsigned char *value, unsigned int valueLength, unsigned int *resultOut)
{
unsigned int result = 0;
@@ -40,7 +40,7 @@
for (i = 0; i < valueLength; ++i) {
unsigned char digit = value[i];
if (!(digit >= '0' && digit <= '9'))
- return "parseUnsignedDecimalInt: element of value is not a decimal digit";
+ return NDN_ERROR_element_of_value_is_not_a_decimal_digit;
result *= 10;
result += (unsigned int)(digit - '0');
@@ -50,20 +50,20 @@
return 0;
}
-char *ndn_BinaryXMLDecoder_decodeTypeAndValue(struct ndn_BinaryXMLDecoder *self, unsigned int *type, unsigned int *valueOut)
+ndn_Error ndn_BinaryXMLDecoder_decodeTypeAndValue(struct ndn_BinaryXMLDecoder *self, unsigned int *type, unsigned int *valueOut)
{
unsigned int value = 0;
int gotFirstOctet = 0;
while (1) {
if (self->offset >= self->inputLength)
- return "ndn_BinaryXMLDecoder_decodeTypeAndVal: read past the end of the input";
+ return NDN_ERROR_read_past_the_end_of_the_input;
unsigned int octet = unsafeReadOctet(self);
if (!gotFirstOctet) {
if (octet == 0)
- return "ndn_BinaryXMLDecoder_decodeTypeAndVal: the first header octet may not be zero";
+ return NDN_ERROR_the_first_header_octet_may_not_be_zero;
gotFirstOctet = 1;
}
@@ -82,49 +82,49 @@
return 0;
}
-char *ndn_BinaryXMLDecoder_readElementStartDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag)
+ndn_Error ndn_BinaryXMLDecoder_readElementStartDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag)
{
- char *error;
+ ndn_Error error;
unsigned int type;
unsigned int value;
if (error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &type, &value))
return error;
if (type != ndn_BinaryXML_DTAG)
- return "ndn_BinaryXMLDecoder_readElementStartDTag: header type is not a DTAG";
+ return NDN_ERROR_header_type_is_not_a_DTAG;
if (value != expectedTag)
- return "ndn_BinaryXMLDecoder_readElementStartDTag: did not get the expected DTAG";
+ return NDN_ERROR_did_not_get_the_expected_DTAG;
return 0;
}
-char *ndn_BinaryXMLDecoder_readElementClose(struct ndn_BinaryXMLDecoder *self)
+ndn_Error ndn_BinaryXMLDecoder_readElementClose(struct ndn_BinaryXMLDecoder *self)
{
if (self->offset >= self->inputLength)
- return "ndn_BinaryXMLDecoder_readElementClose: read past the end of the input";
+ return NDN_ERROR_read_past_the_end_of_the_input;
if (unsafeReadOctet(self) != ndn_BinaryXML_CLOSE)
- return "ndn_BinaryXMLDecoder_readElementStartDTag: did not get the expected element close";
+ return NDN_ERROR_did_not_get_the_expected_element_close;
return 0;
}
-char *ndn_BinaryXMLDecoder_peekDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int *gotExpectedTag)
+ndn_Error ndn_BinaryXMLDecoder_peekDTag(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int *gotExpectedTag)
{
// Default to 0.
*gotExpectedTag = 0;
// First check if it is an element close (which cannot be the expected tag).
if (self->offset >= self->inputLength)
- return "ndn_BinaryXMLDecoder_readElementClose: read past the end of the input";
+ return NDN_ERROR_read_past_the_end_of_the_input;
if (unsafeGetOctet(self) == 0)
return 0;
unsigned int type;
unsigned int value;
unsigned int saveOffset = self->offset;
- char *error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &type, &value);
+ ndn_Error error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &type, &value);
// Restore offset.
self->offset = saveOffset;
@@ -137,16 +137,16 @@
return 0;
}
-char *ndn_BinaryXMLDecoder_readBinaryDTagElement
+ndn_Error ndn_BinaryXMLDecoder_readBinaryDTagElement
(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int allowNull, unsigned char **value, unsigned int *valueLen)
{
- char *error;
+ ndn_Error error;
if (error = ndn_BinaryXMLDecoder_readElementStartDTag(self, expectedTag))
return error;
if (allowNull) {
if (self->offset >= self->inputLength)
- return "ndn_BinaryXMLDecoder_readBinaryDTagElement: read past the end of the input";
+ return NDN_ERROR_read_past_the_end_of_the_input;
if (unsafeGetOctet(self) == ndn_BinaryXML_CLOSE) {
// The binary item is missing, and this is allowed, so read the element close and return a null value.
@@ -170,10 +170,10 @@
return 0;
}
-char *ndn_BinaryXMLDecoder_readUDataDTagElement
+ndn_Error ndn_BinaryXMLDecoder_readUDataDTagElement
(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, unsigned char **value, unsigned int *valueLen)
{
- char *error;
+ ndn_Error error;
if (error = ndn_BinaryXMLDecoder_readElementStartDTag(self, expectedTag))
return error;
@@ -181,7 +181,7 @@
if (error = ndn_BinaryXMLDecoder_decodeTypeAndValue(self, &itemType, valueLen))
return error;
if (itemType != ndn_BinaryXML_UDATA)
- return "ndn_BinaryXMLDecoder_readUDataDTagElement: item is not UDATA";
+ return NDN_ERROR_item_is_not_UDATA;
*value = self->input + self->offset;
self->offset += *valueLen;
@@ -191,12 +191,12 @@
return 0;
}
-char *ndn_BinaryXMLDecoder_readUnsignedIntegerDTagElement
+ndn_Error ndn_BinaryXMLDecoder_readUnsignedIntegerDTagElement
(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, unsigned int *value)
{
unsigned char *udataValue;
unsigned int udataValueLength;
- char *error;
+ ndn_Error error;
if (error = ndn_BinaryXMLDecoder_readUDataDTagElement(self, expectedTag, &udataValue, &udataValueLength))
return error;
@@ -206,11 +206,11 @@
return 0;
}
-char *ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
+ndn_Error ndn_BinaryXMLDecoder_readOptionalUnsignedIntegerDTagElement
(struct ndn_BinaryXMLDecoder *self, unsigned int expectedTag, int *value)
{
int gotExpectedTag;
- char *error;
+ ndn_Error error;
if (error = ndn_BinaryXMLDecoder_peekDTag(self, expectedTag, &gotExpectedTag))
return error;