MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / pv_printf

Function pv_printf

pvar.c:5569–5637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5567
5568
5569int pv_printf(struct sip_msg* msg, pv_elem_p list, char *buf, int *len)
5570{
5571 int n;
5572 pv_value_t tok;
5573 str print;
5574 pv_elem_p it;
5575 char *cur;
5576
5577 if(msg==NULL || list==NULL || buf==NULL || len==NULL)
5578 return -1;
5579
5580 if(*len <= 0)
5581 return -1;
5582
5583 *buf = '\0';
5584 cur = buf;
5585
5586 n = 0;
5587 for (it=list; it; it=it->next)
5588 {
5589 /* put the text */
5590 if(it->text.s && it->text.len>0)
5591 {
5592 if(n+it->text.len < *len)
5593 {
5594 memcpy(cur, it->text.s, it->text.len);
5595 n += it->text.len;
5596 cur += it->text.len;
5597 } else {
5598 LM_ERR("no more space for text [%d][%d]\n", n, it->text.len);
5599 goto overflow;
5600 }
5601 }
5602 /* put the value of the specifier */
5603 if(it->spec.type!=PVT_NONE
5604 && pv_get_spec_value(msg, &(it->spec), &tok)==0)
5605 {
5606 print = pv_value_print(&tok);
5607 if (n + print.len >= *len) {
5608 LM_ERR("no more space for spec value [%d][%d]\n",
5609 n, print.len);
5610 goto overflow;
5611 }
5612
5613 memcpy(cur, print.s, print.len);
5614 n += print.len;
5615 cur += print.len;
5616 }
5617 }
5618
5619 goto done;
5620
5621overflow:
5622 if (is_pv_print_buf(buf))
5623 LM_ERR("buffer too small -- increase 'pv_print_buf_size' from [%d]\n",
5624 *len);
5625 else
5626 LM_ERR("buffer too small -- increase the buffer size "

Callers 4

xl_print_logFunction · 0.85
pv_printf_sFunction · 0.85
msg_get_pseudoVarFunction · 0.85
l_siplua_pseudoVarFunction · 0.85

Calls 2

pv_get_spec_valueFunction · 0.85
pv_value_printFunction · 0.85

Tested by

no test coverage detected