123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- package bssoft.stack.sip;
- public class SIPAUTHENTICATEHeader {
- public String header = null;
- public String headerValue = null;
- public String realmValue = null;
- public String nonceValue = null;
- public String qopValue = null;
- public String strStale = null;
- public String strAlgorithm = null;
- public int headerType = SIPStack.SIP_HEADERTYPE_NONE;
- public boolean flag = false;
- public SIPAUTHENTICATEHeader(String header, int headerType) {
- if (header != null) {
- String keyWord;
- if (headerType == SIPStack.SIP_HEADERTYPE_WWWAUTHENTICATE) {
- keyWord = "WWW-Authenticate: ";
- } else if (headerType == SIPStack.SIP_HEADERTYPE_WwwAUTHENTICATE) {
- keyWord = "Www-Authenticate: ";
- } else if (headerType == SIPStack.SIP_HEADERTYPE_PROXYAUTHENTICATE) {
- keyWord = "Proxy-Authenticate: ";
- } else {
- keyWord = null;
- }
- if (keyWord != null)
- if (header.startsWith(keyWord)) {
- this.headerType = headerType;
- this.header = header;
- this.flag = true;
- int iS = 0;
- int iE = 0;
- String strRealm = null;
- iS = header.indexOf("realm=");
- iE = 0;
- if (iS >= 0) {
- iE = header.indexOf(",", iS);
- if (iE > 0) {
- strRealm = header.substring(iS, iE);
- } else if (iE < 0) {
- strRealm = header.substring(iS);
- }
- if (strRealm.length() > 0) {
- iS = strRealm.indexOf("=");
- String strValue = strRealm.substring(iS + 1);
- strValue = strValue.trim();
- if (strValue.indexOf("\"") == 0)
- iS = 1;
- if (iS > 0)
- iE = strValue.indexOf("\"", iS);
- this.realmValue = strValue.substring(iS, iE);
- }
- } else {
- this.realmValue = "";
- }
- String strQop = null;
- iS = header.indexOf("qop=");
- iE = 0;
- if (iS >= 0) {
- iE = header.indexOf(",", iS);
- if (iE > 0) {
- strQop = header.substring(iS, iE);
- } else if (iE < 0) {
- strQop = header.substring(iS);
- }
- this.qopValue = "";
- if (strQop.length() > 0) {
- iS = strQop.indexOf("=");
- String strValue = strQop.substring(iS + 1);
- strValue = strValue.trim();
- if (strValue.indexOf("\"") == 0)
- iS = 1;
- if (iS > 0)
- iE = strValue.indexOf("\"", iS);
- this.qopValue = strValue.substring(iS, iE);
- }
- } else {
- this.qopValue = "";
- }
- String strNonce = null;
- iS = header.indexOf("nonce=");
- iE = 0;
- if (iS >= 0) {
- iE = header.indexOf(",", iS);
- if (iE > 0) {
- strNonce = header.substring(iS, iE);
- } else if (iE < 0) {
- strNonce = header.substring(iS);
- }
- if (strNonce.length() > 0) {
- iS = strNonce.indexOf("=");
- String strValue = strNonce.substring(iS + 1);
- strValue = strValue.trim();
- if (strValue.indexOf("\"") == 0)
- iS = 1;
- if (iS > 0)
- iE = strValue.indexOf("\"", iS);
- this.nonceValue = strValue.substring(iS, iE);
- }
- } else {
- this.nonceValue = "";
- }
- iS = header.indexOf("stale=");
- iE = 0;
- if (iS >= 0) {
- iE = header.indexOf(",", iS);
- if (iE > 0) {
- this.strStale = header.substring(iS + 6, iE);
- } else if (iE < 0) {
- this.strStale = header.substring(iS + 6);
- }
- } else {
- this.strStale = "";
- }
- iS = header.indexOf("algorithm=");
- iE = 0;
- if (iS >= 0) {
- iE = header.indexOf(",", iS);
- if (iE > 0) {
- this.strAlgorithm = header.substring(iS + 10, iE);
- } else if (iE < 0) {
- this.strAlgorithm = header.substring(iS + 10);
- }
- } else {
- this.strAlgorithm = "";
- }
- }
- }
- }
- }
|