<div dir="ltr">I ended up doing it the manually, I'm posting it so others who need it can try my method, I'm using cache_store in the startup route to avoid db lookups for every call, I use an attribute in the the dr_gateways to identify the row ID of the carrier in the registrar table I want to use.<br><br>In the startup_route I added the following, I will make a route to reload this so I don't need to restart opensips whenever I add a carrier.<br><br>avp_db_query("select id, registrar, proxy, aor, third_party_registrant, username, password, binding_URI, binding_params, expiry, forced_socket, state from registrant","$avp(reg_id); $avp(reg_registrar); $avp(reg_proxy); $avp(reg_aor); $avp(reg_third_party_registrant); $avp(reg_username); $avp(reg_password); $avp(reg_binding_URI); $avp(reg_binding_params); $avp(reg_expiry); $avp(reg_forced_socket); $avp(reg_state)");<div><br> $var(i) = 0;</div><div><br><div>set_count($avp(reg_id),$var(reg_counter));<br></div></div><div><br></div><div> while ($var(i) < $var(reg_counter)) {<br></div><div> cache_store("local", "registrar_username_$(avp(reg_id)[$var(i)])", "$(avp(reg_username)[$var(i)])");</div> cache_store("local", "registrar_password_$(avp(reg_id)[$var(i)])", "$(avp(reg_password)[$var(i)])");<br><div> }</div><div><br></div><div>in the main route I run the following on the INVITE:</div><div><br></div><div> if($(var(gw_attributes){s.substr,0,4})=="auth") #if auth is set in attributes it should be something like auth=10 where 10 is the id of the row in the registrar table<br> {<br> $var(regAuthId)=$(var(gw_attributes){s.select,1,=}); #pull the id from the attribute<br> cache_fetch("local","registrar_username_$var(regAuthId)",$var(registrar_username));<br> uac_replace_from("","sip:$var(registrar_username)@$socket_in(ip)"); #replace the from field</div><div> t_on_failure("dr"); <br> t_on_reply("dr");</div><div> }<br></div><div><br></div><div>In my "dr" failure route I added the following<br> if(t_check_status("407")){<br> if($(avp(gw_attributes){s.substr,0,4})=="auth")<br> {<br> $var(regAuthId)=$(avp(gw_attributes){s.select,1,=});<br> cache_fetch("local","registrar_username_$var(regAuthId)",$var(registrar_username));<br> cache_fetch("local","registrar_password_$var(regAuthId)",$var(registrar_password));<br> <br> if ($(<reply>hdr(Proxy-Authenticate)))<br> {<br> $var(raw_auth) = $(<reply>hdr(Proxy-Authenticate));<br> }<br> if ($(<reply>hdr(WWW-Authenticate)))<br> {<br> $var(raw_auth) = $(<reply>hdr(WWW-Authenticate));<br> }<br> $var(reg_start) = "/(.*?)realm=\"//g";<br> $var(reg_end) = "/\"(.*)//g";<br> $var(raw_auth) = $(var(raw_auth){re.subst,$var(reg_start)});<br> $var(raw_auth) = $(var(raw_auth){re.subst,$var(reg_end)});<br> $avp(uac_realm)=$var(raw_auth);<br> $avp(uac_username)=$var(registrar_username);<br> $avp(uac_password)=$var(registrar_password);<br> uac_auth();<br> if(!t_relay()){<br> t_reply (503, "Service not available");<br> }<br> }<br> }<br> </div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 6, 2023 at 9:18 AM S.Rosenberg <<a href="mailto:thesipguy@gmail.com">thesipguy@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi, I'm using the uac_auth to send calls to carriers that require username/password credentials, until now I only had a handful of carriers that don't support IP authentication so I hard coded the credentials, I was thinking of pulling it from the registrant table as most of the time I would want to register to them anyway.<br><br>I would like to know if OpenSIPS has a way to pull the registrant info via code without manually doing a DB query?<br><div><br></div><div>S. Rosenberg</div></div>
</blockquote></div>