From 25d5205abcc1344d0d872bad97ead7a4ef0281f3 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 12 Sep 2008 16:27:43 +0000 Subject: [PATCH] Wed Sep 3 13:35:21 EDT 2008 Pekka Pessi * sofia-sip/msg_header.h: added msg_header_add_format(() git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9541 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- libs/sofia-sip/.update | 2 +- .../libsofia-sip-ua/msg/msg_parser.c | 38 +++++++++++++++++++ .../msg/sofia-sip/msg_header.h | 6 +++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libs/sofia-sip/.update b/libs/sofia-sip/.update index 645cb091ae..848230d853 100644 --- a/libs/sofia-sip/.update +++ b/libs/sofia-sip/.update @@ -1 +1 @@ -Fri Sep 12 12:06:16 EDT 2008 +Fri Sep 12 12:27:38 EDT 2008 diff --git a/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser.c b/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser.c index 1ba3c1181d..a037c95aec 100644 --- a/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser.c +++ b/libs/sofia-sip/libsofia-sip-ua/msg/msg_parser.c @@ -2732,6 +2732,44 @@ int msg_header_add_make(msg_t *msg, return msg_header_add(msg, pub, hh, h); } +/** Add formatting result to message. + * + * Parse result from printf-formatted params as a given header field and add + * result to the message. + */ +int msg_header_add_format(msg_t *msg, + msg_pub_t *pub, + msg_hclass_t *hc, + char const *fmt, + ...) +{ + msg_header_t *h, **hh; + va_list va; + + if (msg == NULL) + return -1; + if (pub == NULL) + pub = msg->m_object; + + hh = msg_hclass_offset(msg->m_class, pub, hc); + + if (hh == NULL) + return -1; + + if (!fmt) + return 0; + + va_start(va, fmt); + h = msg_header_vformat(msg_home(msg), hc, fmt, va); + va_end(va); + + if (!h) + return -1; + + return msg_header_add(msg, pub, hh, h); +} + + /**Add string contents to message. * * Duplicate a string containing headers (or a message body, if the string diff --git a/libs/sofia-sip/libsofia-sip-ua/msg/sofia-sip/msg_header.h b/libs/sofia-sip/libsofia-sip-ua/msg/sofia-sip/msg_header.h index 251b1be608..b80aeccd94 100644 --- a/libs/sofia-sip/libsofia-sip-ua/msg/sofia-sip/msg_header.h +++ b/libs/sofia-sip/libsofia-sip-ua/msg/sofia-sip/msg_header.h @@ -142,6 +142,12 @@ SOFIAPUBFUN int msg_header_add_make(msg_t *msg, msg_hclass_t *hc, char const *s); +SOFIAPUBFUN int msg_header_add_format(msg_t *msg, + msg_pub_t *pub, + msg_hclass_t *hc, + char const *fmt, + ...); + SOFIAPUBFUN int msg_header_prepend(msg_t *msg, msg_pub_t *pub, msg_header_t **hh,