|
@@ -1426,18 +1426,22 @@ int pv_set_spec_value(struct sip_msg* msg, pv_spec_p sp, int op,
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
-int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len)
|
|
|
+int pv_printf_mode(sip_msg_t* msg, pv_elem_t *list, int mode, char *buf, int *len)
|
|
|
{
|
|
|
int n;
|
|
|
pv_value_t tok;
|
|
|
pv_elem_p it;
|
|
|
char *cur;
|
|
|
|
|
|
- if(msg==NULL || list==NULL || buf==NULL || len==NULL)
|
|
|
+ if(msg==NULL || list==NULL || buf==NULL || len==NULL) {
|
|
|
+ LM_DBG("invalid parameters\n");
|
|
|
return -1;
|
|
|
+ }
|
|
|
|
|
|
- if(*len <= 0)
|
|
|
+ if(*len <= 0) {
|
|
|
+ LM_DBG("invalid value for output buffer size\n");
|
|
|
return -1;
|
|
|
+ }
|
|
|
|
|
|
*buf = '\0';
|
|
|
cur = buf;
|
|
@@ -1454,8 +1458,10 @@ int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len)
|
|
|
n += it->text.len;
|
|
|
cur += it->text.len;
|
|
|
} else {
|
|
|
- LM_ERR("no more space for text value - printed:%d token:%d buffer:%d\n",
|
|
|
+ if(likely(mode)) {
|
|
|
+ LM_ERR("no more space for text value - printed:%d token:%d buffer:%d\n",
|
|
|
n, it->text.len, *len);
|
|
|
+ }
|
|
|
goto overflow;
|
|
|
}
|
|
|
}
|
|
@@ -1474,8 +1480,10 @@ int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len)
|
|
|
cur += tok.rs.len;
|
|
|
}
|
|
|
} else {
|
|
|
- LM_ERR("no more space for spec value - printed:%d token:%d buffer:%d\n",
|
|
|
+ if(likely(mode)) {
|
|
|
+ LM_ERR("no more space for spec value - printed:%d token:%d buffer:%d\n",
|
|
|
n, tok.rs.len, *len);
|
|
|
+ }
|
|
|
goto overflow;
|
|
|
}
|
|
|
}
|
|
@@ -1484,8 +1492,10 @@ int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len)
|
|
|
goto done;
|
|
|
|
|
|
overflow:
|
|
|
- LM_ERR("buffer overflow -- increase the buffer size...\n");
|
|
|
- return -1;
|
|
|
+ if(likely(mode)) {
|
|
|
+ LM_ERR("buffer overflow -- increase the buffer size...\n");
|
|
|
+ }
|
|
|
+ return -2;
|
|
|
|
|
|
done:
|
|
|
#ifdef EXTRA_DEBUG
|
|
@@ -1496,6 +1506,47 @@ done:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int pv_printf(sip_msg_t* msg, pv_elem_t *list, char *buf, int *len)
|
|
|
+{
|
|
|
+ return pv_printf_mode(msg, list, 1, buf, len);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+int pv_printf_size(sip_msg_t* msg, pv_elem_t *list)
|
|
|
+{
|
|
|
+ int n;
|
|
|
+ pv_value_t tok;
|
|
|
+ pv_elem_t *it;
|
|
|
+
|
|
|
+ if(msg==NULL || list==NULL) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ n = 0;
|
|
|
+ for (it=list; it; it=it->next) {
|
|
|
+ /* count the static text */
|
|
|
+ if(it->text.s && it->text.len>0) {
|
|
|
+ n += it->text.len;
|
|
|
+ }
|
|
|
+ /* count the value of the specifier */
|
|
|
+ if(it->spec!=NULL && it->spec->type!=PVT_NONE
|
|
|
+ && pv_get_spec_value(msg, it->spec, &tok)==0)
|
|
|
+ {
|
|
|
+ if(tok.flags&PV_VAL_NULL) {
|
|
|
+ tok.rs = pv_str_null;
|
|
|
+ }
|
|
|
+ n += tok.rs.len;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return n;
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
*
|
|
|
*/
|