From aba444d42980ca26fb837294b474b6832c75a283 Mon Sep 17 00:00:00 2001 From: Mark Michelson Date: Tue, 17 Jun 2014 16:33:13 +0000 Subject: [PATCH] Fix string growth algorithm for XML presence bodies. pjpidf_print() does not return < 0 if there is not enough room for the document to be printed. Rather, it returns 39, the length of the XML prolog. The algorithm also had a bug in that it would return if it attempted to grow the string larger. git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@416442 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- res/res_pjsip_pidf_body_generator.c | 8 ++++---- res/res_pjsip_xpidf_body_generator.c | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/res/res_pjsip_pidf_body_generator.c b/res/res_pjsip_pidf_body_generator.c index 50e8be9e77..875a65fda4 100644 --- a/res/res_pjsip_pidf_body_generator.c +++ b/res/res_pjsip_pidf_body_generator.c @@ -80,6 +80,7 @@ static int pidf_generate_body_content(void *body, void *data) } #define MAX_STRING_GROWTHS 3 +#define XML_PROLOG 39 static void pidf_to_string(void *body, struct ast_str **str) { @@ -89,14 +90,13 @@ static void pidf_to_string(void *body, struct ast_str **str) do { size = pjpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str) - 1); - if (size < 0) { + if (size == XML_PROLOG) { ast_str_make_space(str, ast_str_size(*str) * 2); ++growths; - return; } - } while (size < 0 && growths < MAX_STRING_GROWTHS); + } while (size == XML_PROLOG && growths < MAX_STRING_GROWTHS); - if (size < 0) { + if (size == XML_PROLOG) { ast_log(LOG_WARNING, "PIDF body text too large\n"); return; } diff --git a/res/res_pjsip_xpidf_body_generator.c b/res/res_pjsip_xpidf_body_generator.c index b68c9bba6c..fba6152b3c 100644 --- a/res/res_pjsip_xpidf_body_generator.c +++ b/res/res_pjsip_xpidf_body_generator.c @@ -97,6 +97,7 @@ static int xpidf_generate_body_content(void *body, void *data) } #define MAX_STRING_GROWTHS 3 +#define XML_PROLOG 39 static void xpidf_to_string(void *body, struct ast_str **str) { @@ -105,16 +106,14 @@ static void xpidf_to_string(void *body, struct ast_str **str) int size; do { - size = pjxpidf_print(pres, ast_str_buffer(*str), ast_str_size(*str)); - if (size < 0) { + if (size == XML_PROLOG) { ast_str_make_space(str, ast_str_size(*str) * 2); ++growths; - return; } - } while (size < 0 && growths < MAX_STRING_GROWTHS); + } while (size == XML_PROLOG && growths < MAX_STRING_GROWTHS); - if (size < 0) { + if (size == XML_PROLOG) { ast_log(LOG_WARNING, "XPIDF body text too large\n"); return; } -- 2.47.2