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

Function set_dst_host_port

parser/msg_parser.c:1091–1200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1089}
1090
1091int set_dst_host_port(struct sip_msg *msg, str *host, str *port)
1092{
1093 char *tmp, *end, *crt, *new_uri;
1094 int len;
1095 struct sip_uri uri;
1096 int user = 0;
1097
1098 tmp = msg->dst_uri.s;
1099 len = msg->dst_uri.len;
1100
1101 if (tmp == NULL || len == 0) {
1102 LM_ERR("failure - null uri\n");
1103 return -1;
1104 }
1105 if (host && (host->s == NULL || host->len == 0)) {
1106 LM_ERR("cannot set a null uri domain\n");
1107 return -1;
1108 }
1109 if (parse_uri(tmp, len, &uri)<0) {
1110 LM_ERR("bad uri <%.*s>, dropping packet\n", len, tmp);
1111 return -1;
1112 }
1113 new_uri=pkg_malloc(MAX_URI_SIZE);
1114 if (new_uri == NULL) {
1115 LM_ERR("memory allocation failure\n");
1116 return -1;
1117 }
1118 end=new_uri+MAX_URI_SIZE;
1119 crt=new_uri;
1120 len = (uri.user.len?uri.user.s:uri.host.s) - tmp;
1121 if (crt+len>end) goto error_uri;
1122 memcpy(crt,tmp,len);
1123 crt += len;
1124 /* user */
1125 tmp = uri.user.s;
1126 len = uri.user.len;
1127 if (tmp) {
1128 if (crt+len>end) goto error_uri;
1129 memcpy(crt,tmp,len);
1130 crt += len;
1131 user = 1;
1132 }
1133 /* passwd */
1134 tmp = uri.passwd.s;
1135 len = uri.passwd.len;
1136 if (tmp) {
1137 if (crt+len+1>end) goto error_uri;
1138 *crt++=':';
1139 memcpy(crt, tmp, len);
1140 crt += len;
1141 }
1142 /* host */
1143 if (host) {
1144 tmp = host->s;
1145 len = host->len;
1146 } else {
1147 tmp = uri.host.s;
1148 len = uri.host.len;

Callers 2

pv_set_dsturi_hostFunction · 0.85
pv_set_dsturi_portFunction · 0.85

Calls 1

parse_uriFunction · 0.85

Tested by

no test coverage detected