SIPROUTEHeader.java 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package bssoft.stack.sip;
  2. public class SIPROUTEHeader {
  3. public String header = null;
  4. public String headerValue = null;
  5. public String username = null;
  6. public String sipuri = null;
  7. public String uriusertag = null;
  8. public String ip = null;
  9. public int port = 0;
  10. public String tag = null;
  11. public boolean flag = false;
  12. public SIPROUTEHeader(String header) {
  13. int iS = 0;
  14. int iE = 0;
  15. if (header != null && header.length() > 0 && header.startsWith("Route: ")) {
  16. this.header = header;
  17. this.headerValue = header.substring(7).trim();
  18. if (this.headerValue != null && this.headerValue.length() > 0) {
  19. iS = this.headerValue.indexOf("sip:");
  20. if (iS > 0) {
  21. String str = null;
  22. iE = this.headerValue.indexOf(">", iS + 4);
  23. if (iE < 0)
  24. iE = this.headerValue.indexOf(";", iS + 4);
  25. if (iE > 0) {
  26. str = this.headerValue.substring(iS, iE);
  27. } else {
  28. str = this.headerValue.substring(iS);
  29. }
  30. if (str != null && str.length() > 0)
  31. this.sipuri = str.trim();
  32. }
  33. if (this.sipuri != null && this.sipuri.length() > 0) {
  34. iS = this.sipuri.indexOf("@", 4);
  35. if (iS > 0)
  36. this.username = this.sipuri.substring(4, iS).trim();
  37. }
  38. if (this.sipuri != null && this.sipuri.length() > 0) {
  39. iS = this.sipuri.indexOf("@", 4);
  40. iE = this.sipuri.indexOf(";", 4);
  41. String str = null;
  42. if (iS >= 0 && iE >= 0) {
  43. str = this.sipuri.substring(iS + 1, iE).trim();
  44. } else if (iS >= 0) {
  45. str = this.sipuri.substring(iS + 1).trim();
  46. } else if (iE >= 0) {
  47. str = this.sipuri.substring(4, iE).trim();
  48. } else {
  49. str = this.sipuri.substring(4).trim();
  50. }
  51. this.port = 5060;
  52. if (str != null && str.length() > 0) {
  53. iS = str.indexOf(":");
  54. if (iS > 0) {
  55. this.port = Integer.parseInt(str.substring(iS + 1).trim());
  56. this.ip = str.substring(0, iS);
  57. } else {
  58. this.ip = str;
  59. }
  60. }
  61. }
  62. iS = this.headerValue.indexOf(";tag=");
  63. if (iS > 0) {
  64. String str = null;
  65. iE = this.headerValue.indexOf(";", iS + 5);
  66. if (iE >= 0) {
  67. if (iE > iS + 5) {
  68. str = this.headerValue.substring(iS + 5, iE);
  69. } else {
  70. str = "";
  71. }
  72. } else {
  73. str = this.headerValue.substring(iS + 5);
  74. }
  75. if (str != null && str.length() > 0)
  76. this.tag = str.trim();
  77. }
  78. iS = this.headerValue.indexOf("sip:");
  79. if (iS > 0) {
  80. String str = null;
  81. iE = this.headerValue.indexOf(">", iS + 4);
  82. if (iE > 0)
  83. str = this.headerValue.substring(iS, iE);
  84. if (str != null && str.length() > 0) {
  85. iS = str.indexOf(";user=", iS + 4);
  86. if (iS > 0) {
  87. this.uriusertag = str.substring(iS + 6);
  88. if (this.uriusertag != null && this.uriusertag.length() > 0 && this.uriusertag.indexOf(";") >= 0)
  89. if (this.uriusertag.indexOf(";") == 0) {
  90. this.uriusertag = null;
  91. } else {
  92. this.uriusertag = this.uriusertag.substring(0, this.uriusertag.indexOf(";")).trim();
  93. }
  94. }
  95. }
  96. }
  97. this.flag = true;
  98. }
  99. }
  100. }
  101. public String getUsername() {
  102. return this.username;
  103. }
  104. public String getSipuri() {
  105. return this.sipuri;
  106. }
  107. public String getSipuriusertag() {
  108. return this.uriusertag;
  109. }
  110. public String getIp() {
  111. return this.ip;
  112. }
  113. public int getPort() {
  114. return this.port;
  115. }
  116. public String getTag() {
  117. return this.tag;
  118. }
  119. }