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

Function tr_eval_via

transformations.c:1319–1482  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1317static struct via_body *_tr_parsed_via = 0;
1318
1319int tr_eval_via(struct sip_msg *msg, tr_param_t *tp, int subtype,
1320 pv_value_t *val)
1321{
1322 pv_value_t v;
1323 str sv;
1324 struct via_param *pit;
1325
1326 if (!val)
1327 return -1;
1328
1329 if (val->flags & PV_VAL_NULL)
1330 return 0;
1331
1332 // WATCHOUT: need at least 2 chars so \r\n check wont segfault
1333 if(!(val->flags&PV_VAL_STR) || val->rs.len<=2) {
1334 val->flags = PV_VAL_NULL;
1335 return -1;
1336 }
1337
1338 if(_tr_via_buf_len==0 || _tr_via.len!=val->rs.len ||
1339 strncmp(_tr_via.s, val->rs.s, val->rs.len)!=0
1340 || _tr_parsed_via==0)
1341 {
1342 if (val->rs.len+4 > _tr_via_buf_len)
1343 {
1344 if(_tr_via.s) pkg_free(_tr_via.s);
1345 _tr_via.s = (char*)pkg_malloc((val->rs.len+4)*sizeof(char));
1346 if(_tr_via.s==NULL)
1347 {
1348 _tr_via_buf_len = 0;
1349 LM_ERR("no more private memory\n");
1350 goto error;
1351 }
1352 _tr_via_buf_len = val->rs.len+4;
1353 }
1354 _tr_via.len = val->rs.len;
1355 memcpy(_tr_via.s, val->rs.s, val->rs.len);
1356 // $hdr PV strips off the terminating CRLR
1357 // parse_via wants to parse a full message (including
1358 // multiple vias), not just a header line. Fake this
1359 _tr_via.s[_tr_via.len+0] = '\r';
1360 _tr_via.s[_tr_via.len+1] = '\n';
1361 _tr_via.s[_tr_via.len+2] = 'A'; // anything other than V
1362 _tr_via.s[_tr_via.len+3] = '\0';
1363 /* reset old values */
1364 free_via_list(_tr_parsed_via);
1365 if ( (_tr_parsed_via=pkg_malloc(sizeof(struct via_body))) == NULL ) {
1366 LM_ERR("no more private memory\n");
1367 goto error;
1368 }
1369 memset(_tr_parsed_via, 0, sizeof(struct via_body));
1370 parse_via(_tr_via.s, _tr_via.s+_tr_via.len+4, _tr_parsed_via);
1371 if(_tr_parsed_via->error != PARSE_OK) {
1372 LM_ERR("invalid via [%.*s]\n", val->rs.len,
1373 val->rs.s);
1374 goto error;
1375 }
1376 }

Callers

nothing calls this directly

Calls 3

free_via_listFunction · 0.85
parse_viaFunction · 0.85
pv_get_spec_valueFunction · 0.85

Tested by

no test coverage detected