SIPAUTHENTICATEHeader.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. package bssoft.stack.sip;
  2. public class SIPAUTHENTICATEHeader {
  3. public String header = null;
  4. public String headerValue = null;
  5. public String realmValue = null;
  6. public String nonceValue = null;
  7. public String qopValue = null;
  8. public String strStale = null;
  9. public String strAlgorithm = null;
  10. public int headerType = SIPStack.SIP_HEADERTYPE_NONE;
  11. public boolean flag = false;
  12. public SIPAUTHENTICATEHeader(String header, int headerType) {
  13. if (header != null) {
  14. String keyWord;
  15. if (headerType == SIPStack.SIP_HEADERTYPE_WWWAUTHENTICATE) {
  16. keyWord = "WWW-Authenticate: ";
  17. } else if (headerType == SIPStack.SIP_HEADERTYPE_WwwAUTHENTICATE) {
  18. keyWord = "Www-Authenticate: ";
  19. } else if (headerType == SIPStack.SIP_HEADERTYPE_PROXYAUTHENTICATE) {
  20. keyWord = "Proxy-Authenticate: ";
  21. } else {
  22. keyWord = null;
  23. }
  24. if (keyWord != null)
  25. if (header.startsWith(keyWord)) {
  26. this.headerType = headerType;
  27. this.header = header;
  28. this.flag = true;
  29. int iS = 0;
  30. int iE = 0;
  31. String strRealm = null;
  32. iS = header.indexOf("realm=");
  33. iE = 0;
  34. if (iS >= 0) {
  35. iE = header.indexOf(",", iS);
  36. if (iE > 0) {
  37. strRealm = header.substring(iS, iE);
  38. } else if (iE < 0) {
  39. strRealm = header.substring(iS);
  40. }
  41. if (strRealm.length() > 0) {
  42. iS = strRealm.indexOf("=");
  43. String strValue = strRealm.substring(iS + 1);
  44. strValue = strValue.trim();
  45. if (strValue.indexOf("\"") == 0)
  46. iS = 1;
  47. if (iS > 0)
  48. iE = strValue.indexOf("\"", iS);
  49. this.realmValue = strValue.substring(iS, iE);
  50. }
  51. } else {
  52. this.realmValue = "";
  53. }
  54. String strQop = null;
  55. iS = header.indexOf("qop=");
  56. iE = 0;
  57. if (iS >= 0) {
  58. iE = header.indexOf(",", iS);
  59. if (iE > 0) {
  60. strQop = header.substring(iS, iE);
  61. } else if (iE < 0) {
  62. strQop = header.substring(iS);
  63. }
  64. this.qopValue = "";
  65. if (strQop.length() > 0) {
  66. iS = strQop.indexOf("=");
  67. String strValue = strQop.substring(iS + 1);
  68. strValue = strValue.trim();
  69. if (strValue.indexOf("\"") == 0)
  70. iS = 1;
  71. if (iS > 0)
  72. iE = strValue.indexOf("\"", iS);
  73. this.qopValue = strValue.substring(iS, iE);
  74. }
  75. } else {
  76. this.qopValue = "";
  77. }
  78. String strNonce = null;
  79. iS = header.indexOf("nonce=");
  80. iE = 0;
  81. if (iS >= 0) {
  82. iE = header.indexOf(",", iS);
  83. if (iE > 0) {
  84. strNonce = header.substring(iS, iE);
  85. } else if (iE < 0) {
  86. strNonce = header.substring(iS);
  87. }
  88. if (strNonce.length() > 0) {
  89. iS = strNonce.indexOf("=");
  90. String strValue = strNonce.substring(iS + 1);
  91. strValue = strValue.trim();
  92. if (strValue.indexOf("\"") == 0)
  93. iS = 1;
  94. if (iS > 0)
  95. iE = strValue.indexOf("\"", iS);
  96. this.nonceValue = strValue.substring(iS, iE);
  97. }
  98. } else {
  99. this.nonceValue = "";
  100. }
  101. iS = header.indexOf("stale=");
  102. iE = 0;
  103. if (iS >= 0) {
  104. iE = header.indexOf(",", iS);
  105. if (iE > 0) {
  106. this.strStale = header.substring(iS + 6, iE);
  107. } else if (iE < 0) {
  108. this.strStale = header.substring(iS + 6);
  109. }
  110. } else {
  111. this.strStale = "";
  112. }
  113. iS = header.indexOf("algorithm=");
  114. iE = 0;
  115. if (iS >= 0) {
  116. iE = header.indexOf(",", iS);
  117. if (iE > 0) {
  118. this.strAlgorithm = header.substring(iS + 10, iE);
  119. } else if (iE < 0) {
  120. this.strAlgorithm = header.substring(iS + 10);
  121. }
  122. } else {
  123. this.strAlgorithm = "";
  124. }
  125. }
  126. }
  127. }
  128. }