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

Function ospGetToHost

modules/osp/sipheader.c:398–433  ·  view source on GitHub ↗

* Get host info from To header * param msg SIP message * param tohost Host part of To header * param bufsize Size of tohost buffer * return 0 success, -1 failure */

Source from the content-addressed store, hash-verified

396 * return 0 success, -1 failure
397 */
398int ospGetToHost(
399 struct sip_msg* msg,
400 char* tohost,
401 int bufsize)
402{
403 struct to_body* to;
404 struct sip_uri uri;
405 int result = -1;
406
407 if ((tohost != NULL) && (bufsize > 0)) {
408 tohost[0] = '\0';
409 if (msg->to != NULL) {
410 if (parse_headers(msg, HDR_TO_F, 0) == 0) {
411 to = get_to(msg);
412 if (parse_uri(to->uri.s, to->uri.len, &uri) == 0) {
413 if (uri.port_no != 0) {
414 snprintf(tohost, bufsize, "%.*s:%d", uri.host.len, uri.host.s, uri.port_no);
415 } else {
416 ospCopyStrToBuffer(&uri.host, tohost, bufsize);
417 }
418 result = 0;
419 } else {
420 LM_ERR("failed to parse To uri\n");
421 }
422 } else {
423 LM_ERR("failed to parse To header\n");
424 }
425 } else {
426 LM_ERR("failed to find To header\n");
427 }
428 } else {
429 LM_ERR("bad parameters to parse hsto info from To header\n");
430 }
431
432 return result;
433}
434
435/*
436 * Get To header

Callers 1

ospRequestRoutingFunction · 0.85

Calls 2

parse_uriFunction · 0.85
ospCopyStrToBufferFunction · 0.85

Tested by

no test coverage detected