Let mbus_str_xml_encode return a resultcode

This commit is contained in:
Stefan Wahren 2016-01-31 17:55:09 +00:00
parent 3699d25b10
commit 0927f23ee7
2 changed files with 46 additions and 40 deletions

View File

@ -3654,7 +3654,7 @@ mbus_data_error_print(int error)
/// Encode string to XML /// Encode string to XML
/// ///
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void int
mbus_str_xml_encode(unsigned char *dst, const unsigned char *src, size_t max_len) mbus_str_xml_encode(unsigned char *dst, const unsigned char *src, size_t max_len)
{ {
size_t i, len; size_t i, len;
@ -3663,10 +3663,16 @@ mbus_str_xml_encode(unsigned char *dst, const unsigned char *src, size_t max_len
len = 0; len = 0;
if (dst == NULL) if (dst == NULL)
return;
if (src != NULL)
{ {
return -1;
}
if (src == NULL)
{
dst[len] = '\0';
return -2;
}
while((len+6) < max_len) while((len+6) < max_len)
{ {
if (src[i] == '\0') if (src[i] == '\0')
@ -3703,9 +3709,9 @@ mbus_str_xml_encode(unsigned char *dst, const unsigned char *src, size_t max_len
i++; i++;
} }
}
dst[len] = '\0'; dst[len] = '\0';
return 0;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------

View File

@ -498,7 +498,7 @@ typedef struct _mbus_data_secondary_address {
// //
unsigned int mbus_manufacturer_id(char *manufacturer); unsigned int mbus_manufacturer_id(char *manufacturer);
// Since libmbus writes some special characters (ASCII > 0x7F) into the XML output (e.g. °C for centigrade == ASCII 0xB0) // Since libmbus writes some special characters (ASCII > 0x7F) into the XML output (e.g. <EFBFBD>C for centigrade == ASCII 0xB0)
// it is useful to attach the appropriate code page for postprocessing. // it is useful to attach the appropriate code page for postprocessing.
#define MBUS_XML_PROCESSING_INSTRUCTION "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" #define MBUS_XML_PROCESSING_INSTRUCTION "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
@ -569,7 +569,7 @@ mbus_slave_data *mbus_slave_data_get(size_t i);
// //
// XML generating functions // XML generating functions
// //
void mbus_str_xml_encode(unsigned char *dst, const unsigned char *src, size_t max_len); int mbus_str_xml_encode(unsigned char *dst, const unsigned char *src, size_t max_len);
char *mbus_data_xml(mbus_frame_data *data); char *mbus_data_xml(mbus_frame_data *data);
char *mbus_data_variable_xml(mbus_data_variable *data); char *mbus_data_variable_xml(mbus_data_variable *data);
char *mbus_data_fixed_xml(mbus_data_fixed *data); char *mbus_data_fixed_xml(mbus_data_fixed *data);