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

Function pv_get_acc_username

pvar.c:1928–1982  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1926}
1927
1928static int pv_get_acc_username(struct sip_msg *msg, pv_param_t *param,
1929 pv_value_t *res)
1930{
1931 static char buf[MAX_URI_SIZE];
1932 str* user;
1933 str* realm;
1934 struct sip_uri puri;
1935 struct to_body* from;
1936 str s;
1937
1938 /* try to take it from credentials */
1939 user = cred_user(msg);
1940 if (user) {
1941 realm = cred_realm(msg);
1942 if (realm) {
1943 s.len = user->len+1+realm->len;
1944 if (s.len > MAX_URI_SIZE) {
1945 LM_ERR("uri too long\n");
1946 return pv_get_null(msg, param, res);
1947 }
1948 s.s = buf;
1949 memcpy(s.s, user->s, user->len);
1950 (s.s)[user->len] = '@';
1951 memcpy(s.s+user->len+1, realm->s, realm->len);
1952 return pv_get_strval(msg, param, res, &s);
1953 }
1954 return pv_get_strval(msg, param, res, user);
1955 }
1956
1957 /* from from uri */
1958 if(parse_from_header(msg)<0)
1959 {
1960 LM_ERR("cannot parse FROM header\n");
1961 return pv_get_null(msg, param, res);
1962 }
1963 if (msg->from && (from=get_from(msg)) && from->uri.len) {
1964 if (parse_uri(from->uri.s, from->uri.len, &puri) < 0 ) {
1965 LM_ERR("bad From URI\n");
1966 return pv_get_null(msg, param, res);
1967 }
1968 s.len = puri.user.len + 1 + puri.host.len;
1969 if (s.len > MAX_URI_SIZE) {
1970 LM_ERR("from URI too long\n");
1971 return pv_get_null(msg, param, res);
1972 }
1973 s.s = buf;
1974 memcpy(s.s, puri.user.s, puri.user.len);
1975 (s.s)[puri.user.len] = '@';
1976 memcpy(s.s + puri.user.len + 1, puri.host.s, puri.host.len);
1977 } else {
1978 s.len = 0;
1979 s.s = 0;
1980 }
1981 return pv_get_strval(msg, param, res, &s);
1982}
1983
1984
1985#define BR_URI_S "uri"

Callers

nothing calls this directly

Calls 6

cred_userFunction · 0.85
cred_realmFunction · 0.85
pv_get_nullFunction · 0.85
pv_get_strvalFunction · 0.85
parse_from_headerFunction · 0.85
parse_uriFunction · 0.85

Tested by

no test coverage detected