ViaHeader via=req.getViaHeader();
req.removeViaHeader();
via.setBranch(SipProvider.pickBranch());
req.addViaHeader(via);
req.setCSeqHeader(req.getCSeqHeader().incSequenceNumber());
WwwAuthenticateHeader wah;
if (code==401) wah=msg.getWwwAuthenticateHeader();
else wah=msg.getProxyAuthenticateHeader();
String qop_options=wah.getQopOptionsParam();
qop=(qop_options!=null)? "auth" : null;
RequestLine rl=req.getRequestLine();
DigestAuthentication digest=new DigestAuthentication(rl.getMethod(),rl.getAddress().toString(),wah,qop,null,username,passwd);
AuthorizationHeader ah;
if (code==401) ah=digest.getAuthorizationHeader();