0001: /*
0002: *
0003: *
0004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
0005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
0006: *
0007: * This program is free software; you can redistribute it and/or
0008: * modify it under the terms of the GNU General Public License version
0009: * 2 only, as published by the Free Software Foundation.
0010: *
0011: * This program is distributed in the hope that it will be useful, but
0012: * WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * General Public License version 2 for more details (a copy is
0015: * included at /legal/license.txt).
0016: *
0017: * You should have received a copy of the GNU General Public License
0018: * version 2 along with this work; if not, write to the Free Software
0019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020: * 02110-1301 USA
0021: *
0022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0023: * Clara, CA 95054 or visit www.sun.com if you need additional
0024: * information or have any questions.
0025: */
0026:
0027: package javax.microedition.sip;
0028:
0029: import java.util.Vector;
0030:
0031: import gov.nist.core.NameValueList;
0032: import gov.nist.core.ParseException;
0033: import gov.nist.microedition.sip.StackConnector;
0034: import gov.nist.siplite.header.Header;
0035:
0036: import com.sun.midp.i3test.TestCase;
0037:
0038: /**
0039: * SipHeaderChecker is a class to check SipHeader functionality
0040: *
0041: */
0042: class SipHeaderChecker {
0043: /** Short form of header. */
0044: private static String shortForm = "i call-id:m contact:e content-encoding:l content-length:"
0045: + "c content-type:f from:s subject:k supported:t to:v via:";
0046:
0047: /**
0048: * Output from short format string.
0049: * @param name label for format string
0050: * @return formatted string
0051: */
0052: public static String toShortForm(String name) {
0053:
0054: name = name.toLowerCase();
0055: int i = shortForm.indexOf(" " + name + ":");
0056: return i == -1 ? name : shortForm.substring(i - 1, i);
0057: }
0058:
0059: /**
0060: * Output to long format string.
0061: * @param name label to process
0062: * @return formatted string
0063: */
0064: public static String toLongForm(String name) {
0065:
0066: name = name.toLowerCase();
0067: int i = shortForm.indexOf(name + " ");
0068: return i == -1 ? name : shortForm.substring(i + 2, shortForm
0069: .indexOf(':', i));
0070: }
0071:
0072: /** Array of testcases. */
0073: static SipHeaderChecker[] testCases = {
0074:
0075: // # 1
0076: new SipHeaderChecker(
0077: "Accept:" + " application/sdp;level=1",
0078: "application/sdp",
0079: new String[][] { { "level", "1" } }),
0080:
0081: // # 2
0082: new SipHeaderChecker(
0083: "aCCEPT:" + " application/sdp;level=1",
0084: "application/sdp",
0085: new String[][] { { "level", "1" } }),
0086:
0087: // # 3
0088: new SipHeaderChecker("Accept:"
0089: + " application/sdp;gparam1=1;gparam2",
0090: "application/sdp", new String[][] {
0091: { "gparam2", "" }, { "gparam1", "1" } }),
0092:
0093: // # 4
0094: new SipHeaderChecker("Accept:"
0095: + " application/sdp;gparam2;gparam1=1",
0096: "application/sdp", new String[][] {
0097: { "gparam2", "" }, { "gparam1", "1" } }),
0098:
0099: // # 5
0100: new SipHeaderChecker(
0101: "Accept:" + " application/sdp;gparam2",
0102: "application/sdp",
0103: new String[][] { { "gparam2", "" } }),
0104:
0105: // # 6
0106: new SipHeaderChecker("Accept-Encoding:" + " gzip", "gzip",
0107: new String[][] {}),
0108:
0109: // # 7
0110: new SipHeaderChecker("Accept-EncoDING:" + " gzip", "gzip",
0111: new String[][] {}),
0112:
0113: // # 8
0114: new SipHeaderChecker("Accept-Language:" + " da", "da",
0115: new String[][] {}),
0116:
0117: // # 9
0118: new SipHeaderChecker("Accept-Language:" + " en-gb;q=0.8",
0119: "en-gb", new String[][] { { "q", "0.8" } }),
0120:
0121: // # 10
0122: new SipHeaderChecker("Accept-LanguaGE:" + " en-gb;q=0.8",
0123: "en-gb", new String[][] { { "q", "0.8" } }),
0124:
0125: // # 11
0126: new SipHeaderChecker("Accept-Language:" + " en-gb;Q=0.8",
0127: "en-gb", new String[][] { { "q", "0.8" } }),
0128:
0129: // # 12
0130: new SipHeaderChecker("Accept-Language:"
0131: + " en-gb;gparam2;gparam1=1", "en-gb",
0132: new String[][] { { "gparam2", "" },
0133: { "gparam1", "1" } }),
0134:
0135: // # 13
0136: new SipHeaderChecker("Alert-Info:"
0137: + " <http://www.example.com/sounds/moo.wav>",
0138: "<http://www.example.com/sounds/moo.wav>",
0139: new String[][] {}),
0140:
0141: // # 14
0142: new SipHeaderChecker("Alert-info:"
0143: + " <http://www.example.com/sounds/moo.wav>",
0144: "<http://www.example.com/sounds/moo.wav>",
0145: new String[][] {}),
0146:
0147: // # 15
0148: new SipHeaderChecker("Alert-Info:"
0149: + " <http://www.example.com/sounds/moo.wav>"
0150: + ";gparam2;gparam1=1",
0151: "<http://www.example.com/sounds/moo.wav>",
0152: new String[][] { { "gparam2", "" },
0153: { "gparam1", "1" } }),
0154:
0155: // # 16
0156: new SipHeaderChecker("Allow:" + " INVITE", "INVITE",
0157: new String[][] {}),
0158:
0159: // # 17
0160: new SipHeaderChecker("Allow:" + " ACK", "ACK",
0161: new String[][] {}),
0162:
0163: // # 18
0164: new SipHeaderChecker("Allow:" + " OPTIONS", "OPTIONS",
0165: new String[][] {}),
0166:
0167: // # 19
0168: new SipHeaderChecker("Allow:" + " CANCEL", "CANCEL",
0169: new String[][] {}),
0170:
0171: // # 20
0172: new SipHeaderChecker("Allow:" + " BYE", "BYE",
0173: new String[][] {}),
0174:
0175: // # 21
0176: new SipHeaderChecker("alloW:" + " INVITE", "INVITE",
0177: new String[][] {}),
0178:
0179: // # 22
0180: new SipHeaderChecker("Authentication-Info:"
0181: + " nextnonce=\"47364c23432d2e131a5fb210812c\"",
0182: "nextnonce=\"47364c23432d2e131a5fb210812c\"",
0183: new String[][] {}),
0184:
0185: // # 23
0186: new SipHeaderChecker("Authentication-INFO:"
0187: + " nextnonce=\"47364c23432d2e131a5fb210812c\"",
0188: "nextnonce=\"47364c23432d2e131a5fb210812c\"",
0189: new String[][] {}),
0190:
0191: // # 24
0192: new SipHeaderChecker(
0193: "Authorization:"
0194: + " Digest username=\"Alice\","
0195: + " realm=\"atlanta.com\","
0196: + " nonce=\"84a4cc6f3082121f32b42a2187831a9e\","
0197: + " response="
0198: + "\"7587245234b3434cc3412213e5f113a5432\"",
0199: "Digest",
0200: new String[][] {
0201: { "realm", "\"atlanta.com\"" },
0202: { "response",
0203: "\"7587245234b3434cc3412213e5f113a5432\"" },
0204: { "nonce",
0205: "\"84a4cc6f3082121f32b42a2187831a9e\"" },
0206: { "username", "\"Alice\"" } }),
0207:
0208: // # 25
0209: new SipHeaderChecker(
0210: "AuthorizatioN:"
0211: + " Digest username=\"Alice\","
0212: + " realm=\"atlanta.com\","
0213: + " nonce=\"84a4cc6f3082121f32b42a2187831a9e\","
0214: + " response="
0215: + "\"7587245234b3434cc3412213e5f113a5432\"",
0216: "Digest",
0217: new String[][] {
0218: { "realm", "\"atlanta.com\"" },
0219: { "response",
0220: "\"7587245234b3434cc3412213e5f113a5432\"" },
0221: { "nonce",
0222: "\"84a4cc6f3082121f32b42a2187831a9e\"" },
0223: { "username", "\"Alice\"" } }),
0224:
0225: // # 26
0226: new SipHeaderChecker(
0227: "Authorization:"
0228: + " Digest username=\"Alice\","
0229: + " realm=\"atlanta.com\","
0230: + " nonce=\"84a4cc6f3082121f32b42a2187831a9e\","
0231: + " response="
0232: + "\"7587245234b3434cc3412213e5f113a5432\","
0233: + "auth-param1=1,auth-param2=\"param2\"",
0234: "Digest",
0235: new String[][] {
0236: { "realm", "\"atlanta.com\"" },
0237: { "response",
0238: "\"7587245234b3434cc3412213e5f113a5432\"" },
0239: { "nonce",
0240: "\"84a4cc6f3082121f32b42a2187831a9e\"" },
0241: { "auth-param2", "\"param2\"" },
0242: { "auth-param1", "1" },
0243: { "username", "\"Alice\"" } }),
0244:
0245: // # 27
0246: new SipHeaderChecker(
0247: "Call-ID:"
0248: + " f81d4fae-7dec-11d0-a765-00a0c91e6bf6@biloxi.com",
0249: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@biloxi.com",
0250: new String[][] {}),
0251:
0252: // # 28
0253: new SipHeaderChecker("Call-ID:"
0254: + " f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
0255: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6",
0256: new String[][] {}),
0257:
0258: // # 29
0259: new SipHeaderChecker(
0260: "Call-Id:"
0261: + " f81d4fae-7dec-11d0-a765-00a0c91e6bf6@biloxi.com",
0262: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@biloxi.com",
0263: new String[][] {}),
0264:
0265: // # 30
0266: new SipHeaderChecker("i:"
0267: + "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.0.2.4",
0268: "f81d4fae-7dec-11d0-a765-00a0c91e6bf6@192.0.2.4",
0269: new String[][] {}),
0270:
0271: // # 31
0272: new SipHeaderChecker("Call-Info:"
0273: + " <http://wwww.example.com/alice/photo.jpg>"
0274: + " ;purpose=icon",
0275: "<http://wwww.example.com/alice/photo.jpg>",
0276: new String[][] { { "purpose", "icon" } }),
0277:
0278: // # 32
0279: new SipHeaderChecker("Call-INFO:"
0280: + " <http://wwww.example.com/alice/photo.jpg>"
0281: + " ;purpose=icon",
0282: "<http://wwww.example.com/alice/photo.jpg>",
0283: new String[][] { { "purpose", "icon" } }),
0284:
0285: // # 33
0286: new SipHeaderChecker("Call-Info:"
0287: + " <http://wwww.example.com/alice/photo.jpg>"
0288: + " ;purpose=icon;gparam2;gparam1=1",
0289: "<http://wwww.example.com/alice/photo.jpg>",
0290: new String[][] { { "purpose", "icon" },
0291: { "gparam2", "" }, { "gparam1", "1" } }),
0292:
0293: // # 34
0294: new SipHeaderChecker("Contact:" + " \"Mr. Watson\""
0295: + " <sip:watson@worcester.bell-telephone.com>;"
0296: + "q=0.7; expires=3600", "\"Mr. Watson\""
0297: + " <sip:watson@worcester.bell-telephone.com>",
0298: new String[][] { { "expires", "3600" },
0299: { "q", "0.7" } }),
0300:
0301: // # 35
0302: new SipHeaderChecker("ContacT:" + " \"Mr. Watson\""
0303: + " <sip:watson@worcester.bell-telephone.com>;"
0304: + "q=0.7; expires=3600", "\"Mr. Watson\""
0305: + " <sip:watson@worcester.bell-telephone.com>",
0306: new String[][] { { "expires", "3600" },
0307: { "q", "0.7" } }),
0308:
0309: // # 36
0310: new SipHeaderChecker(
0311: "Contact:"
0312: + " \"Mr. Watson\""
0313: + " <sip:watson@worcester.bell-telephone.com>;"
0314: + "q=0.7; expires=3600;gparam2;gparam1=1",
0315: "\"Mr. Watson\""
0316: + " <sip:watson@worcester.bell-telephone.com>",
0317: new String[][] { { "expires", "3600" },
0318: { "gparam2", "" }, { "gparam1", "1" },
0319: { "q", "0.7" } }),
0320:
0321: // # 37
0322: new SipHeaderChecker("m:"
0323: + " <sips:bob@192.0.2.4>;expires=60",
0324: "<sips:bob@192.0.2.4>", new String[][] { {
0325: "expires", "60" } }),
0326:
0327: // # 38
0328: new SipHeaderChecker("M:"
0329: + " <sips:bob@192.0.2.4>;expires=60",
0330: "<sips:bob@192.0.2.4>", new String[][] { {
0331: "expires", "60" } }),
0332:
0333: // # 39
0334: new SipHeaderChecker("Content-Disposition:" + " session",
0335: "session", new String[][] {}),
0336:
0337: // # 40
0338: new SipHeaderChecker("Content-DispositioN:" + " session",
0339: "session", new String[][] {}),
0340:
0341: // # 41
0342: new SipHeaderChecker("Content-Disposition:"
0343: + " session;gparam2;gparam1=1", "session",
0344: new String[][] { { "gparam2", "" },
0345: { "gparam1", "1" } }),
0346:
0347: // # 42
0348: new SipHeaderChecker("Content-Encoding:" + " gzip", "gzip",
0349: new String[][] {}),
0350:
0351: // # 43
0352: new SipHeaderChecker("Content-EncodinG:" + " gzip", "gzip",
0353: new String[][] {}),
0354:
0355: // # 44
0356: new SipHeaderChecker("e:" + " tar", "tar",
0357: new String[][] {}),
0358:
0359: // # 45
0360: new SipHeaderChecker("E:" + " tar", "tar",
0361: new String[][] {}),
0362:
0363: // # 46
0364: new SipHeaderChecker("Content-Language:" + " fr", "fr",
0365: new String[][] {}),
0366:
0367: // # 47
0368: new SipHeaderChecker("Content-LanguaGE:" + " fr", "fr",
0369: new String[][] {}),
0370:
0371: // # 48
0372: new SipHeaderChecker("Content-Length:" + " 349", "349",
0373: new String[][] {}),
0374:
0375: // # 49
0376: new SipHeaderChecker("Content-length:" + " 349", "349",
0377: new String[][] {}),
0378:
0379: // # 50
0380: new SipHeaderChecker("l:" + " 173", "173",
0381: new String[][] {}),
0382:
0383: // # 51
0384: new SipHeaderChecker("L:" + " 173", "173",
0385: new String[][] {}),
0386:
0387: // # 52
0388: new SipHeaderChecker("Content-Type:" + " application/sdp",
0389: "application/sdp", new String[][] {}),
0390:
0391: // # 53
0392: new SipHeaderChecker("Content-type:" + " application/sdp",
0393: "application/sdp", new String[][] {}),
0394:
0395: // # 54
0396: new SipHeaderChecker("Content-Type:"
0397: + " application/sdp;gparam1=1", "application/sdp",
0398: new String[][] { { "gparam1", "1" } }),
0399:
0400: // # 55
0401: new SipHeaderChecker("c:"
0402: + " text/html; charset=ISO-8859-4", "text/html",
0403: new String[][] { { "charset", "ISO-8859-4" } }),
0404:
0405: // # 56
0406: new SipHeaderChecker("CSeq:" + " 4711 INVITE",
0407: "4711 INVITE", new String[][] {}),
0408:
0409: // # 57
0410: new SipHeaderChecker("cSeq:" + " 4711 INVITE",
0411: "4711 INVITE", new String[][] {}),
0412:
0413: // # 58
0414: new SipHeaderChecker("Date:"
0415: + " Mon, 10 Jan 2005 23:29:00 GMT",
0416: "Mon, 10 Jan 2005 23:29:00 GMT", new String[][] {}),
0417:
0418: // # 59
0419: new SipHeaderChecker("Date:"
0420: + " Tue, 08 Feb 2005 23:29:00 GMT",
0421: "Tue, 08 Feb 2005 23:29:00 GMT", new String[][] {}),
0422:
0423: // # 60
0424: new SipHeaderChecker("Date:"
0425: + " Wed, 09 Mar 2005 23:29:00 GMT",
0426: "Wed, 09 Mar 2005 23:29:00 GMT", new String[][] {}),
0427:
0428: // # 61
0429: new SipHeaderChecker("Date:"
0430: + " Thu, 07 Apr 2005 23:29:00 GMT",
0431: "Thu, 07 Apr 2005 23:29:00 GMT", new String[][] {}),
0432:
0433: // # 62
0434: new SipHeaderChecker("Date:"
0435: + " Fri, 13 May 2005 23:29:00 GMT",
0436: "Fri, 13 May 2005 23:29:00 GMT", new String[][] {}),
0437:
0438: // # 63
0439: new SipHeaderChecker("Date:"
0440: + " Sat, 11 Jun 2005 23:29:00 GMT",
0441: "Sat, 11 Jun 2005 23:29:00 GMT", new String[][] {}),
0442:
0443: // # 64
0444: new SipHeaderChecker("Date:"
0445: + " Sun, 10 Jul 2005 23:29:00 GMT",
0446: "Sun, 10 Jul 2005 23:29:00 GMT", new String[][] {}),
0447:
0448: // # 65
0449: new SipHeaderChecker("Date:"
0450: + " Sat, 13 Aug 2005 23:29:00 GMT",
0451: "Sat, 13 Aug 2005 23:29:00 GMT", new String[][] {}),
0452:
0453: // # 66
0454: new SipHeaderChecker("Date:"
0455: + " Sat, 10 Sep 2005 23:29:00 GMT",
0456: "Sat, 10 Sep 2005 23:29:00 GMT", new String[][] {}),
0457:
0458: // # 67
0459: new SipHeaderChecker("Date:"
0460: + " Sat, 15 Oct 2005 23:29:00 GMT",
0461: "Sat, 15 Oct 2005 23:29:00 GMT", new String[][] {}),
0462:
0463: // # 68
0464: new SipHeaderChecker("Date:"
0465: + " Sat, 12 Nov 2005 23:29:00 GMT",
0466: "Sat, 12 Nov 2005 23:29:00 GMT", new String[][] {}),
0467:
0468: // # 69
0469: new SipHeaderChecker("Date:"
0470: + " Sat, 10 Dec 2005 23:29:00 GMT",
0471: "Sat, 10 Dec 2005 23:29:00 GMT", new String[][] {}),
0472:
0473: // # 70
0474: new SipHeaderChecker("DatE:"
0475: + " Sat, 13 Nov 2010 23:29:00 GMT",
0476: "Sat, 13 Nov 2010 23:29:00 GMT", new String[][] {}),
0477:
0478: // # 71
0479: new SipHeaderChecker("Error-Info:"
0480: + " <sip:not-in-service-recording@atlanta.com>",
0481: "<sip:not-in-service-recording@atlanta.com>",
0482: new String[][] {}),
0483:
0484: // # 72
0485: new SipHeaderChecker("Error-InfO:"
0486: + " <sip:not-in-service-recording@atlanta.com>",
0487: "<sip:not-in-service-recording@atlanta.com>",
0488: new String[][] {}),
0489:
0490: // # 73
0491: new SipHeaderChecker("Error-Info:"
0492: + " <sip:not-in-service-recording@atlanta.com>;"
0493: + "gparam2;gparam1=1",
0494: "<sip:not-in-service-recording@atlanta.com>",
0495: new String[][] { { "gparam2", "" },
0496: { "gparam1", "1" } }),
0497:
0498: // # 74
0499: new SipHeaderChecker("Expires:" + " 5", "5",
0500: new String[][] {}),
0501:
0502: // # 75
0503: new SipHeaderChecker("EXPIRES:" + " 5", "5",
0504: new String[][] {}),
0505:
0506: // # 76
0507: new SipHeaderChecker("From:"
0508: + " \"A. G. Bell\" <sip:agb@bell-telephone.com> ;"
0509: + "tag=a48s",
0510: "\"A. G. Bell\" <sip:agb@bell-telephone.com>",
0511: new String[][] { { "tag", "a48s" } }),
0512:
0513: // # 77
0514: new SipHeaderChecker("FROM:"
0515: + " \"A. G. Bell\" <sip:agb@bell-telephone.com> ;"
0516: + "tag=a48s",
0517: "\"A. G. Bell\" <sip:agb@bell-telephone.com>",
0518: new String[][] { { "tag", "a48s" } }),
0519:
0520: // # 78
0521: new SipHeaderChecker("From:"
0522: + " \"A. G. Bell\" <sip:agb@bell-telephone.com> ;"
0523: + "tag=a48s;gparam2;gparam1=1",
0524: "\"A. G. Bell\" <sip:agb@bell-telephone.com>",
0525: new String[][] { { "tag", "a48s" },
0526: { "gparam2", "" }, { "gparam1", "1" } }),
0527:
0528: // # 79
0529: new SipHeaderChecker("f:"
0530: + " Anonymous <sip:c8oqz84zk7z@privacy.org>;"
0531: + "tag=hyh8",
0532: "Anonymous <sip:c8oqz84zk7z@privacy.org>",
0533: new String[][] { { "tag", "hyh8" } }),
0534:
0535: // # 80
0536: new SipHeaderChecker("F:"
0537: + " Anonymous <sip:c8oqz84zk7z@privacy.org>;"
0538: + "tag=hyh8",
0539: "Anonymous <sip:c8oqz84zk7z@privacy.org>",
0540: new String[][] { { "tag", "hyh8" } }),
0541:
0542: // # 81
0543: new SipHeaderChecker("In-Reply-To:"
0544: + " 70710@saturn.bell-tel.com",
0545: "70710@saturn.bell-tel.com", new String[][] {}),
0546:
0547: // # 82
0548: new SipHeaderChecker("In-Reply-TO:"
0549: + " 70710@saturn.bell-tel.com",
0550: "70710@saturn.bell-tel.com", new String[][] {}),
0551:
0552: // # 83
0553: new SipHeaderChecker("Max-Forwards:" + " 6", "6",
0554: new String[][] {}),
0555:
0556: // # 84
0557: new SipHeaderChecker("Max-forwards:" + " 6", "6",
0558: new String[][] {}),
0559:
0560: // # 85
0561: new SipHeaderChecker("Min-Expires:" + " 60", "60",
0562: new String[][] {}),
0563:
0564: // # 86
0565: new SipHeaderChecker("Min-expires:" + " 60", "60",
0566: new String[][] {}),
0567:
0568: // # 87
0569: new SipHeaderChecker("MIME-Version:" + " 1.0", "1.0",
0570: new String[][] {}),
0571:
0572: // # 88
0573: new SipHeaderChecker("MIME-version:" + " 1.0", "1.0",
0574: new String[][] {}),
0575:
0576: // # 89
0577: new SipHeaderChecker("Organization:" + " Boxes by Bob",
0578: "Boxes by Bob", new String[][] {}),
0579:
0580: // # 90
0581: new SipHeaderChecker("organization:" + " Boxes by Bob",
0582: "Boxes by Bob", new String[][] {}),
0583:
0584: // # 91
0585: new SipHeaderChecker("Priority:" + " emergency",
0586: "emergency", new String[][] {}),
0587:
0588: // # 92
0589: new SipHeaderChecker("prioritY:" + " emergency",
0590: "emergency", new String[][] {}),
0591:
0592: // # 93
0593: new SipHeaderChecker("Priority:" + " token", "token",
0594: new String[][] {}),
0595:
0596: // # 94
0597: new SipHeaderChecker(
0598: "Proxy-Authenticate:"
0599: + " Digest realm=\"atlanta.com\","
0600: + "domain=\"sip:ss1.carrier.com\","
0601: + " qop=\"auth\","
0602: + "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\","
0603: + "opaque=\"\", stale=FALSE, algorithm=MD5",
0604: "Digest",
0605: new String[][] {
0606: { "realm", "\"atlanta.com\"" },
0607: { "algorithm", "MD5" },
0608: { "stale", "FALSE" },
0609: { "nonce",
0610: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
0611: { "opaque", "\"\"" },
0612: { "domain", "\"sip:ss1.carrier.com\"" },
0613: { "qop", "\"auth\"" } }),
0614:
0615: // # 95
0616: new SipHeaderChecker(
0617: "Proxy-Authenticate:"
0618: + " Digest realm=\"atlanta.com\","
0619: + "domain=\"sip:ss1.carrier.com\", "
0620: + "qop=\"auth\","
0621: + "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\","
0622: + "opaque=\"\", stale=TRUE, algorithm=MD5",
0623: "Digest",
0624: new String[][] {
0625: { "realm", "\"atlanta.com\"" },
0626: { "algorithm", "MD5" },
0627: { "stale", "TRUE" },
0628: { "nonce",
0629: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
0630: { "opaque", "\"\"" },
0631: { "domain", "\"sip:ss1.carrier.com\"" },
0632: { "qop", "\"auth\"" } }),
0633:
0634: // # 96
0635: new SipHeaderChecker(
0636: "PRoxy-Authenticate:"
0637: + " Digest realM=\"atlanta.com\","
0638: + "domaiN=\"sip:ss1.carrier.com\", "
0639: + "qoP=\"auth\","
0640: + "noncE=\"f84f1cec41e6cbe5aea9c8e88d359\","
0641: + "opaquE=\"\", stale=FALSe, algorithm=mD5",
0642: "Digest",
0643: new String[][] {
0644: { "realm", "\"atlanta.com\"" },
0645: { "algorithm", "mD5" },
0646: { "stale", "FALSe" },
0647: { "nonce",
0648: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
0649: { "opaque", "\"\"" },
0650: { "domain", "\"sip:ss1.carrier.com\"" },
0651: { "qop", "\"auth\"" } }),
0652:
0653: // # 97
0654: new SipHeaderChecker(
0655: "Proxy-Authenticate:"
0656: + " Digest realm=\"atlanta.com\","
0657: + "domain=\"sip:ss1.carrier.com\", "
0658: + "qop=\"auth\","
0659: + "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\","
0660: + "opaque=\"\", stale=FALSE, algorithm=MD5,"
0661: + "auth-param1=1,auth-param2=\"param2\"",
0662: "Digest",
0663: new String[][] {
0664: { "qop", "\"auth\"" },
0665: { "domain", "\"sip:ss1.carrier.com\"" },
0666: { "opaque", "\"\"" },
0667: { "realm", "\"atlanta.com\"" },
0668: { "nonce",
0669: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
0670: { "algorithm", "MD5" },
0671: { "stale", "FALSE" },
0672: { "auth-param2", "\"param2\"" },
0673: { "auth-param1", "1" } }),
0674:
0675: // # 98
0676: new SipHeaderChecker(
0677: "Proxy-Authorization:"
0678: + " Digest username=\"Alice\", "
0679: + "realm=\"atlanta.com\", "
0680: + "nonce=\"c60f3082ee1212b402a21831ae\", "
0681: + "response=\"245f23415f11432b3434341c022\"",
0682: "Digest",
0683: new String[][] {
0684: { "realm", "\"atlanta.com\"" },
0685: { "response",
0686: "\"245f23415f11432b3434341c022\"" },
0687: { "nonce", "\"c60f3082ee1212b402a21831ae\"" },
0688: { "username", "\"Alice\"" } }),
0689:
0690: // # 99
0691: new SipHeaderChecker(
0692: "PRoxy-Authorization:"
0693: + " Digest username=\"Alice\", "
0694: + "realm=\"atlanta.com\", "
0695: + "nonce=\"c60f3082ee1212b402a21831ae\", "
0696: + "response=\"245f23415f11432b3434341c022\"",
0697: "Digest",
0698: new String[][] {
0699: { "realm", "\"atlanta.com\"" },
0700: { "response",
0701: "\"245f23415f11432b3434341c022\"" },
0702: { "nonce", "\"c60f3082ee1212b402a21831ae\"" },
0703: { "username", "\"Alice\"" } }),
0704:
0705: // # 100
0706: new SipHeaderChecker(
0707: "Proxy-Authorization:"
0708: + " Digest username=\"Alice\", "
0709: + "realm=\"atlanta.com\", "
0710: + "nonce=\"c60f3082ee1212b402a21831ae\", "
0711: + "response=\"245f23415f11432b3434341c022\","
0712: + "auth-param1=1,auth-param2=\"param2\"",
0713: "Digest",
0714: new String[][] {
0715: { "realm", "\"atlanta.com\"" },
0716: { "response",
0717: "\"245f23415f11432b3434341c022\"" },
0718: { "nonce", "\"c60f3082ee1212b402a21831ae\"" },
0719: { "auth-param2", "\"param2\"" },
0720: { "auth-param1", "1" },
0721: { "username", "\"Alice\"" } }),
0722:
0723: // # 101
0724: new SipHeaderChecker("Proxy-Require:" + " foo", "foo",
0725: new String[][] {}),
0726:
0727: // # 102
0728: new SipHeaderChecker("Proxy-RequirE:" + " foo", "foo",
0729: new String[][] {}),
0730:
0731: // # 103
0732: new SipHeaderChecker("Record-Route:"
0733: + " <sip:server10.biloxi.com;lr>",
0734: "<sip:server10.biloxi.com;lr>", new String[][] {}),
0735:
0736: // # 104
0737: new SipHeaderChecker("Record-route:"
0738: + " <sip:server10.biloxi.com;lr>",
0739: "<sip:server10.biloxi.com;lr>", new String[][] {}),
0740:
0741: // # 105
0742: new SipHeaderChecker(
0743: "Record-Route:"
0744: + " <sip:server10.biloxi.com;lr>;gparam2;gparam1=1",
0745: "<sip:server10.biloxi.com;lr>", new String[][] {
0746: { "gparam2", "" }, { "gparam1", "1" } }),
0747:
0748: // # 106
0749: new SipHeaderChecker("Record-Route:"
0750: + " <sip:server10.biloxi.com>;gparam2;gparam1=1",
0751: "<sip:server10.biloxi.com>", new String[][] {
0752: { "gparam2", "" }, { "gparam1", "1" } }),
0753:
0754: // # 107
0755: new SipHeaderChecker("Reply-To:"
0756: + " Bob <sip:bob@biloxi.com>",
0757: "Bob <sip:bob@biloxi.com>", new String[][] {}),
0758:
0759: // # 108
0760: new SipHeaderChecker("Reply-to:"
0761: + " Bob <sip:bob@biloxi.com>",
0762: "Bob <sip:bob@biloxi.com>", new String[][] {}),
0763:
0764: // # 109
0765: new SipHeaderChecker("Reply-To:"
0766: + " Bob <sip:bob@biloxi.com>;gparam2;gparam1=1",
0767: "Bob <sip:bob@biloxi.com>", new String[][] {
0768: { "gparam2", "" }, { "gparam1", "1" } }),
0769:
0770: // # 110
0771: new SipHeaderChecker("Require:" + " 100rel", "100rel",
0772: new String[][] {}),
0773:
0774: // # 111
0775: new SipHeaderChecker("require:" + " 100rel", "100rel",
0776: new String[][] {}),
0777:
0778: // # 112
0779: new SipHeaderChecker("Retry-After:"
0780: + " 18000;duration=3600", "18000",
0781: new String[][] { { "duration", "3600" } }),
0782:
0783: // # 113
0784: new SipHeaderChecker("Retry-After:"
0785: + " 120 (I'm in a meeting)",
0786: "120 (I'm in a meeting)", new String[][] {}),
0787:
0788: // # 114
0789: new SipHeaderChecker("Retry-after:"
0790: + " 18000;duration=3600", "18000",
0791: new String[][] { { "duration", "3600" } }),
0792:
0793: // # 115
0794: new SipHeaderChecker(
0795: "Retry-After:"
0796: + " 18000;duration=3600;gparam2;gparam1=1",
0797: "18000",
0798: new String[][] { { "gparam2", "" },
0799: { "gparam1", "1" }, { "duration", "3600" } }),
0800:
0801: // # 116
0802: new SipHeaderChecker("Route:"
0803: + " <sip:bigbox3.site3.atlanta.com;lr>",
0804: "<sip:bigbox3.site3.atlanta.com;lr>",
0805: new String[][] {}),
0806:
0807: // # 117
0808: new SipHeaderChecker("RoutE:"
0809: + " <sip:bigbox3.site3.atlanta.com;lr>",
0810: "<sip:bigbox3.site3.atlanta.com;lr>",
0811: new String[][] {}),
0812:
0813: // # 118
0814: new SipHeaderChecker("Route:"
0815: + " <sip:bigbox3.site3.atlanta.com;lr>;"
0816: + "gparam2;gparam1=1",
0817: "<sip:bigbox3.site3.atlanta.com;lr>",
0818: new String[][] { { "gparam2", "" },
0819: { "gparam1", "1" } }),
0820:
0821: // # 119
0822: new SipHeaderChecker("Server:" + " HomeServer v2",
0823: "HomeServer v2", new String[][] {}),
0824:
0825: // # 120
0826: new SipHeaderChecker("server:" + " HomeServer v2",
0827: "HomeServer v2", new String[][] {}),
0828:
0829: // # 121
0830: new SipHeaderChecker("Subject:" + " Need more boxes",
0831: "Need more boxes", new String[][] {}),
0832:
0833: // # 122
0834: new SipHeaderChecker("SUbject:" + " Need more boxes",
0835: "Need more boxes", new String[][] {}),
0836:
0837: // # 123
0838: new SipHeaderChecker("s:" + " Tech Support",
0839: "Tech Support", new String[][] {}),
0840:
0841: // # 124
0842: new SipHeaderChecker("S:" + " Tech Support",
0843: "Tech Support", new String[][] {}),
0844:
0845: // # 125
0846: new SipHeaderChecker("Supported:" + " 100rel", "100rel",
0847: new String[][] {}),
0848:
0849: // # 126
0850: new SipHeaderChecker("SupporteD:" + " 100rel", "100rel",
0851: new String[][] {}),
0852:
0853: // # 127
0854: new SipHeaderChecker("Timestamp:" + " 54", "54",
0855: new String[][] {}),
0856:
0857: // # 128
0858: new SipHeaderChecker("TimestamP:" + " 54", "54",
0859: new String[][] {}),
0860:
0861: // # 129
0862: new SipHeaderChecker("To:"
0863: + " The Operator <sip:operator@cs.columbia.edu>;"
0864: + "tag=287447",
0865: "The Operator <sip:operator@cs.columbia.edu>",
0866: new String[][] { { "tag", "287447" } }),
0867:
0868: // # 130
0869: new SipHeaderChecker("TO:"
0870: + " The Operator <sip:operator@cs.columbia.edu>;"
0871: + "tag=287447",
0872: "The Operator <sip:operator@cs.columbia.edu>",
0873: new String[][] { { "tag", "287447" } }),
0874:
0875: // # 131
0876: new SipHeaderChecker("To:"
0877: + " The Operator <sip:operator@cs.columbia.edu>;"
0878: + "gparam2;gparam1=1",
0879: "The Operator <sip:operator@cs.columbia.edu>",
0880: new String[][] { { "gparam2", "" },
0881: { "gparam1", "1" } }),
0882:
0883: // # 132
0884: new SipHeaderChecker("t:"
0885: + " sip:+12125551212@server.phone2net.com",
0886: "sip:+12125551212@server.phone2net.com",
0887: new String[][] {}),
0888:
0889: // # 133
0890: new SipHeaderChecker("T:"
0891: + " sip:+12125551212@server.phone2net.com",
0892: "sip:+12125551212@server.phone2net.com",
0893: new String[][] {}),
0894:
0895: // # 134
0896: new SipHeaderChecker("t:"
0897: + " sip:+12125551212@server.phone2net.com;"
0898: + "gparam2;gparam1=1",
0899: "sip:+12125551212@server.phone2net.com",
0900: new String[][] { { "gparam2", "" },
0901: { "gparam1", "1" } }),
0902:
0903: // # 135
0904: new SipHeaderChecker("Unsupported:" + " foo", "foo",
0905: new String[][] {}),
0906:
0907: // # 136
0908: new SipHeaderChecker("UnsupporteD:" + " foo", "foo",
0909: new String[][] {}),
0910:
0911: // # 137
0912: new SipHeaderChecker("User-Agent:" + " Softphone Beta1.5",
0913: "Softphone Beta1.5", new String[][] {}),
0914:
0915: // # 138
0916: new SipHeaderChecker("User-agent:" + " Softphone Beta1.5",
0917: "Softphone Beta1.5", new String[][] {}),
0918:
0919: // # 139
0920: new SipHeaderChecker("Via:"
0921: + " SIP/2.0/UDP erlang.bell-telephone.com:5060;"
0922: + "branch=z9hG4bK87asdks7",
0923: "SIP/2.0/UDP erlang.bell-telephone.com:5060",
0924: new String[][] { { "branch", "z9hG4bK87asdks7" } }),
0925:
0926: // # 140
0927: new SipHeaderChecker("VIA:"
0928: + " SIP/2.0/UDP erlang.bell-telephone.com:5060;"
0929: + "branch=z9hG4bK87asdks7",
0930: "SIP/2.0/UDP erlang.bell-telephone.com:5060",
0931: new String[][] { { "branch", "z9hG4bK87asdks7" } }),
0932:
0933: // # 141
0934: new SipHeaderChecker("v:" + " SIP/2.0/UDP 192.0.2.1:5060 ;"
0935: + "received=192.0.2.207;branch=z9hG4bK77asjd",
0936: "SIP/2.0/UDP 192.0.2.1:5060", new String[][] {
0937: { "branch", "z9hG4bK77asjd" },
0938: { "received", "192.0.2.207" } }),
0939:
0940: // # 142
0941: new SipHeaderChecker("V:" + " SIP/2.0/UDP 192.0.2.1:5060 ;"
0942: + "received=192.0.2.207;branch=z9hG4bK77asjd",
0943: "SIP/2.0/UDP 192.0.2.1:5060", new String[][] {
0944: { "branch", "z9hG4bK77asjd" },
0945: { "received", "192.0.2.207" } }),
0946:
0947: // # 143
0948: new SipHeaderChecker(
0949: "Via:"
0950: + " SIP / 2.0 / UDP first.example.com: 4000;ttl=16;"
0951: + "maddr=224.2.0.1 ;branch=z9hG4bKa7c6a8dlze.1",
0952: "SIP/2.0/UDP first.example.com:4000",
0953: new String[][] { { "ttl", "16" },
0954: { "maddr", "224.2.0.1" },
0955: { "branch", "z9hG4bKa7c6a8dlze.1" } }),
0956:
0957: // # 144
0958: new SipHeaderChecker("Via:"
0959: + " SIP/2.0/UDP erlang.bell-telephone.com:5060;"
0960: + "gparam2;gparam1=1",
0961: "SIP/2.0/UDP erlang.bell-telephone.com:5060",
0962: new String[][] { { "gparam2", "" },
0963: { "gparam1", "1" } }),
0964:
0965: // # 145
0966: new SipHeaderChecker("Warning:"
0967: + " 307 isi.edu \"Session parameter 'foo' "
0968: + "not understood\"",
0969: "307 isi.edu \"Session parameter 'foo' "
0970: + "not understood\"", new String[][] {}),
0971:
0972: // # 146
0973: new SipHeaderChecker("WarninG:"
0974: + " 307 isi.edu \"Session parameter 'foo' "
0975: + "not understood\"",
0976: "307 isi.edu \"Session parameter 'foo' "
0977: + "not understood\"", new String[][] {}),
0978:
0979: // # 147
0980: new SipHeaderChecker(
0981: "WWW-Authenticate:"
0982: + " Digest realm=\"atlanta.com\","
0983: + "domain=\"sip:boxesbybob.com\", "
0984: + "qop=\"auth\","
0985: + "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\","
0986: + "opaque=\"\", stale=FALSE, algorithm=MD5",
0987: "Digest",
0988: new String[][] {
0989: { "realm", "\"atlanta.com\"" },
0990: { "algorithm", "MD5" },
0991: { "stale", "FALSE" },
0992: { "nonce",
0993: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
0994: { "opaque", "\"\"" },
0995: { "domain", "\"sip:boxesbybob.com\"" },
0996: { "qop", "\"auth\"" } }),
0997:
0998: // # 148
0999: new SipHeaderChecker(
1000: "WWW-Authenticate:"
1001: + "Digest realm=\"atlanta.com\","
1002: + "domain=\"sip:boxesbybob.com\", "
1003: + "qop=\"auth\","
1004: + "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\","
1005: + "opaque=\"\", stale=FALSE, algorithm=MD5",
1006: "Digest",
1007: new String[][] {
1008: { "realm", "\"atlanta.com\"" },
1009: { "algorithm", "MD5" },
1010: { "stale", "FALSE" },
1011: { "nonce",
1012: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
1013: { "opaque", "\"\"" },
1014: { "domain", "\"sip:boxesbybob.com\"" },
1015: { "qop", "\"auth\"" } }),
1016:
1017: // # 149
1018: new SipHeaderChecker(
1019: "WWW-Authenticate:"
1020: + " Digest realm=\"atlanta.com\" , "
1021: + "domain=\"sip:boxesbybob.com\" , "
1022: + "qop=\"auth\" , "
1023: + "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\","
1024: + "opaque=\"\", stale=FALSE, algorithm=MD5",
1025: "Digest",
1026: new String[][] {
1027: { "realm", "\"atlanta.com\"" },
1028: { "algorithm", "MD5" },
1029: { "stale", "FALSE" },
1030: { "nonce",
1031: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
1032: { "opaque", "\"\"" },
1033: { "domain", "\"sip:boxesbybob.com\"" },
1034: { "qop", "\"auth\"" } }),
1035:
1036: // # 150
1037: new SipHeaderChecker(
1038: "WWW-AuthenticatE:"
1039: + " DIGEST REALM=\"atlanta.com\""
1040: + ",DOMAIn=\"sip:boxesbybob.com\", "
1041: + "QoP=\"auth\","
1042: + "NONCE=\"f84f1cec41e6cbe5aea9c8e88d359\","
1043: + "OPAQUE=\"\", stale=true, algorithm=md5",
1044: "DIGEST",
1045: new String[][] {
1046: { "realm", "\"atlanta.com\"" },
1047: { "algorithm", "md5" },
1048: { "stale", "true" },
1049: { "nonce",
1050: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
1051: { "opaque", "\"\"" },
1052: { "domain", "\"sip:boxesbybob.com\"" },
1053: { "qop", "\"auth\"" } }),
1054:
1055: // # 151
1056: new SipHeaderChecker(
1057: "WWW-Authenticate:"
1058: + " Digest realm=\"atlanta.com\","
1059: + "domain=\"sip:boxesbybob.com\", "
1060: + "qop=\"auth\","
1061: + "nonce=\"f84f1cec41e6cbe5aea9c8e88d359\","
1062: + "opaque=\"\", stale=FALSE, "
1063: + "algorithm=MD5,auth-param1=1,"
1064: + "auth-param2=\"param2\"",
1065: "Digest",
1066: new String[][] {
1067: { "qop", "\"auth\"" },
1068: { "domain", "\"sip:boxesbybob.com\"" },
1069: { "opaque", "\"\"" },
1070: { "realm", "\"atlanta.com\"" },
1071: { "nonce",
1072: "\"f84f1cec41e6cbe5aea9c8e88d359\"" },
1073: { "algorithm", "MD5" },
1074: { "stale", "FALSE" },
1075: { "auth-param2", "\"param2\"" },
1076: { "auth-param1", "1" } }),
1077:
1078: // # 152
1079: new SipHeaderChecker("xxx:" + " unknown field type; "
1080: + "some_string_parameter=\"atlanta.com\"; "
1081: + "some_other_parameter=other_parameter_value; "
1082: + "empty_parameter", "unknown field type",
1083: new String[][] {
1084: { "some_other_parameter",
1085: "other_parameter_value" },
1086: { "some_string_parameter",
1087: "\"atlanta.com\"" },
1088: { "empty_parameter", "" } }),
1089:
1090: // # 153
1091: new SipHeaderChecker("xxx:" + "\tunknown\tfield\t\ttype;\t"
1092: + "some_string_parameter=\"atlanta.com\";\t"
1093: + "some_other_parameter=other_parameter_value;\t"
1094: + " \tempty_parameter", "unknown field type",
1095: new String[][] {
1096: { "some_other_parameter",
1097: "other_parameter_value" },
1098: { "some_string_parameter",
1099: "\"atlanta.com\"" },
1100: { "empty_parameter", "" } }),
1101:
1102: // # 154
1103: new SipHeaderChecker("xxx:" + " unknown field type;"
1104: + "some_string_parameter=\"atlanta.com\";"
1105: + "some_other_parameter=other_parameter_value",
1106: "unknown field type", new String[][] {
1107: { "some_other_parameter",
1108: "other_parameter_value" },
1109: { "some_string_parameter",
1110: "\"atlanta.com\"" } }),
1111:
1112: // # 155
1113: new SipHeaderChecker("xxx:" + " unknown field type ;"
1114: + "some_string_parameter=\"atlanta.com\";"
1115: + "some_other_parameter=other_parameter_value",
1116: "unknown field type", new String[][] {
1117: { "some_other_parameter",
1118: "other_parameter_value" },
1119: { "some_string_parameter",
1120: "\"atlanta.com\"" } }),
1121:
1122: // # 156
1123: new SipHeaderChecker("xxx:" + " unknown field type ; "
1124: + "some_string_parameter= \"atlanta.com\"; "
1125: + "some_other_parameter = "
1126: + "other_parameter_value", "unknown field type",
1127: new String[][] {
1128: { "some_other_parameter",
1129: "other_parameter_value" },
1130: { "some_string_parameter",
1131: "\"atlanta.com\"" } }),
1132:
1133: // # 157
1134: new SipHeaderChecker("xxx:" + " unknown field type;"
1135: + "some_string_parameter =\"atlanta.com\" ;"
1136: + "some_other_parameter = other_parameter_value",
1137: "unknown field type", new String[][] {
1138: { "some_other_parameter",
1139: "other_parameter_value" },
1140: { "some_string_parameter",
1141: "\"atlanta.com\"" } }),
1142:
1143: // # 158
1144: new SipHeaderChecker("xxx:" + " unknown field type",
1145: "unknown field type", new String[][] {}),
1146:
1147: // # 159
1148: new SipHeaderChecker("xxx:" + " unknown field type; "
1149: + "some_string_parameter=\"atlanta.com\"",
1150: "unknown field type",
1151: new String[][] { { "some_string_parameter",
1152: "\"atlanta.com\"" } }),
1153:
1154: // # 160
1155: new SipHeaderChecker("xxx:"
1156: + " unknown field type; empty_parameter ",
1157: "unknown field type", new String[][] { {
1158: "empty_parameter", "" } }),
1159:
1160: // # 161
1161: new SipHeaderChecker("xxx:"
1162: + "unknown field type;empty_parameter",
1163: "unknown field type", new String[][] { {
1164: "empty_parameter", "" } }),
1165:
1166: // # 162
1167: new SipHeaderChecker("1-.!%*_+`'~:"
1168: + "unknown field type;empty_parameter",
1169: "unknown field type", new String[][] { {
1170: "empty_parameter", "" } }),
1171:
1172: // # 163
1173: new SipHeaderChecker("Accept-Contact:"
1174: + " *;type=\"application/vnd.company.x-game\"",
1175: "*", new String[][] { { "type",
1176: "\"application/vnd.company.x-game\"" } }),
1177:
1178: // # 164
1179: new SipHeaderChecker("a:"
1180: + " *;type=\"application/vnd.company.x-game\"",
1181: "*", new String[][] { { "type",
1182: "\"application/vnd.company.x-game\"" } }) };
1183:
1184: /** Current name being processed. */
1185: String name;
1186: /** Current value being processed. */
1187: String value;
1188: /** Parsed header values. */
1189: String parsedHeaderValue;
1190: /** Extracted parameters. */
1191: String[][] parameters;
1192: /** Parsed name. */
1193: String parsedName;
1194:
1195: /**
1196: * Constructor for basic test case.
1197: * @param header the test input string
1198: * @param parsedHeaderValue expected value string
1199: * @param parameters expected paramaters from parsed header
1200: */
1201: public SipHeaderChecker(String header, String parsedHeaderValue,
1202: String[][] parameters) {
1203: int i = header.indexOf(':');
1204: name = header.substring(0, i);
1205: value = header.substring(i + 1);
1206: this .parsedHeaderValue = parsedHeaderValue;
1207: this .parameters = parameters;
1208: parsedName = toLongForm(name);
1209: }
1210:
1211: /**
1212: * Checks if test passed.
1213: * @return true if test passes
1214: */
1215: boolean check() {
1216:
1217: // DEBUG: System.out.println("Header: " + name + ":" + value);
1218:
1219: SipHeader h;
1220: try {
1221: h = new SipHeader(name, value);
1222: } catch (IllegalArgumentException e) {
1223: System.out.println("Error parsing the header:" + e
1224: + " name=" + name + " value=" + value);
1225: e.printStackTrace();
1226: return false;
1227: }
1228:
1229: String strValue = h.toString();
1230:
1231: boolean ok = true;
1232:
1233: ok &= checkName(h);
1234: ok &= checkValue(h);
1235: ok &= checkParameters(h);
1236:
1237: // DEBUG: System.out.println("Checking getHeaderValue result");
1238:
1239: try {
1240: h = new SipHeader(h.getName(), h.getHeaderValue());
1241: } catch (IllegalArgumentException e) {
1242: System.out
1243: .println("Error parsing values returned by parser "
1244: + e + " name=" + h.getName() + " value="
1245: + h.getHeaderValue());
1246: e.printStackTrace();
1247: return false;
1248: }
1249:
1250: ok &= checkName(h);
1251: ok &= checkValue(h);
1252: ok &= checkParameters(h);
1253:
1254: // DEBUG: System.out.println("Checking toString result");
1255:
1256: int i = strValue.indexOf(':');
1257:
1258: try {
1259: h = new SipHeader(strValue.substring(0, i).trim(), strValue
1260: .substring(i + 1).trim());
1261: } catch (IllegalArgumentException e) {
1262: System.out.println("Error parsing toString result " + e
1263: + " name=" + strValue.substring(0, i).trim()
1264: + " value=" + strValue.substring(i + 1).trim());
1265: e.printStackTrace();
1266: return false;
1267: }
1268:
1269: ok &= checkName(h);
1270: ok &= checkValue(h);
1271: ok &= checkParameters(h);
1272:
1273: return ok;
1274: }
1275:
1276: /**
1277: * Checks for valid name in hedaer.
1278: * @param h the header to be validated
1279: * @return true if name is valid
1280: */
1281: boolean checkName(SipHeader h) {
1282:
1283: String pname = h.getName();
1284:
1285: if (!(parsedName.equalsIgnoreCase(pname) || toShortForm(
1286: parsedName).equalsIgnoreCase(pname))) {
1287: System.out.println("Invalid name " + h.getName());
1288: return false;
1289: }
1290: return true;
1291: }
1292:
1293: /**
1294: * Checks for valid value in header.
1295: * @param h the header to be validated
1296: * @return true if value is valid
1297: */
1298: boolean checkValue(SipHeader h) {
1299:
1300: String pValue = h.getValue();
1301:
1302: if ((pValue == null || parsedHeaderValue == null)
1303: && pValue != parsedHeaderValue) {
1304: System.out.println("getValue(): Invalid value '"
1305: + h.getValue() + "', must be '" + parsedHeaderValue
1306: + "'");
1307: return false;
1308: }
1309:
1310: pValue = fixSpaces(pValue);
1311: String name = toShortForm(h.getName());
1312:
1313: // In case of "t:"/"T:" header, parsedHeaderValue is
1314: // a SIP URI, so add "<"/">" around the value.
1315: if (name.equalsIgnoreCase("t")) {
1316: if (!pValue.startsWith("<")) {
1317: pValue = "<" + pValue + ">";
1318: }
1319:
1320: if (!parsedHeaderValue.startsWith("<")) {
1321: parsedHeaderValue = "<" + parsedHeaderValue + ">";
1322: }
1323: }
1324:
1325: boolean isSensitive = name.equals("i") || name.equals("cseq")
1326: || name.equals("date");
1327:
1328: if (!(isSensitive ? pValue.equals(parsedHeaderValue) : pValue
1329: .equalsIgnoreCase(parsedHeaderValue))) {
1330: System.out.println("Invalid value '" + h.getValue()
1331: + "', must be '" + parsedHeaderValue + "'");
1332: return false;
1333: }
1334: return true;
1335: }
1336:
1337: /**
1338: * Checks for valid parameters in header.
1339: * @param h the header to be validated
1340: * @return true if parameters are valid
1341: */
1342: boolean checkParameters(SipHeader h) {
1343:
1344: String[] paramNames = h.getParameterNames();
1345:
1346: if (parameters.length == 0) {
1347: if (paramNames != null) {
1348: System.out
1349: .println("getParameterNames must return null");
1350: return false;
1351: }
1352: return true;
1353: }
1354:
1355: if (paramNames == null) {
1356: System.out.println("getParameterNames returns null");
1357: return false;
1358: }
1359: if (parameters.length != paramNames.length) {
1360: System.out.println("getParameterNames returns invalid "
1361: + "number of parameters: " + paramNames.length
1362: + ", must be " + parameters.length);
1363: return false;
1364: }
1365:
1366: for (int i = 0; i < parameters.length; i++) {
1367:
1368: String paramName = parameters[i][0];
1369: String paramValue = parameters[i][1];
1370:
1371: boolean found = false;
1372: for (int j = 0; j < paramNames.length; j++) {
1373: if (paramName.equalsIgnoreCase(paramNames[j])) {
1374: found = true;
1375: break;
1376: }
1377: }
1378:
1379: if (!found) {
1380: System.out.println(paramName
1381: + "not found in results of getParameterNames");
1382: return false;
1383: }
1384:
1385: String v = h.getParameter(paramName);
1386:
1387: if (paramValue == null) {
1388: if (v != null) {
1389: System.out.println("null expected: " + paramName);
1390: return false;
1391: }
1392: } else {
1393: if (v == null) {
1394: System.out.println("parameter " + paramName
1395: + " not found");
1396: return false;
1397: }
1398:
1399: v = fixSpaces(v);
1400:
1401: boolean isSensitive = v.startsWith("\"");
1402:
1403: if (!(isSensitive ? v.equals(paramValue) : v
1404: .equalsIgnoreCase(paramValue))) {
1405: System.out.println("Invalid parameter value: " + v
1406: + ".");
1407: return false;
1408: }
1409: }
1410: }
1411: return true;
1412: }
1413:
1414: /**
1415: * Inserts white space into string.
1416: * @param src input string to be processed
1417: * @return expanded whitespace string
1418: */
1419: public static String fixSpaces(String src) {
1420:
1421: if (src == null) {
1422: return null;
1423: }
1424:
1425: StringBuffer dst = new StringBuffer();
1426:
1427: boolean quoted = false;
1428: boolean prevBlank = false;
1429: for (int i = 0; i < src.length(); i++) {
1430: char c = src.charAt(i);
1431:
1432: if (c == '\"') {
1433: quoted = !quoted;
1434: }
1435:
1436: if (c == '\t') {
1437: c = ' ';
1438: }
1439: boolean isBlank = c == ' ';
1440: if (quoted || !(prevBlank && isBlank)) {
1441: dst.append(c);
1442: }
1443: prevBlank = isBlank;
1444: }
1445: return dst.toString();
1446: }
1447:
1448: /**
1449: * Extracts quoted strings.
1450: * @param src input string to be processed
1451: * @return quoted string
1452: */
1453: static String fixString(String src) {
1454: if (src == null) {
1455: return null;
1456: }
1457: if (src.indexOf('\"') == -1) {
1458: return src;
1459: }
1460: StringBuffer s = new StringBuffer();
1461: for (int i = 0; i < src.length(); i++) {
1462: char c = src.charAt(i);
1463: if (c == '\"') {
1464: s.append('\\');
1465: }
1466: if (c == '\t') {
1467: s.append('\\');
1468: c = 't';
1469: }
1470: s.append(c);
1471: }
1472: return s.toString();
1473: }
1474:
1475: /**
1476: * Runs the set of tests.
1477: * @return number of failed tests
1478: */
1479: public static int runTests() {
1480: int failed = 0, passed = 0;
1481:
1482: for (int i = 0; i < testCases.length; i++) {
1483: if (testCases[i].check()) {
1484: passed++;
1485: } else {
1486: System.out.println("\n*** " + i + " "
1487: + testCases[i].name + ":" + testCases[i].value);
1488: failed++;
1489: }
1490: }
1491: if (failed > 0) {
1492: System.out.println("\n*** RESULT: " + passed + " passed, "
1493: + failed + " failed; " + "total = "
1494: + (passed + failed) + "\n");
1495: }
1496: return failed;
1497: }
1498: }
1499:
1500: /**
1501: * TestAllSipHeader class is a wrapper for SipHeaderChecker
1502: */
1503: public class TestAllSipHeader extends TestCase {
1504: /**
1505: * Body of the test 1.
1506: *
1507: * Calls SipHeaderChecker.runTests().
1508: */
1509: void Test1() {
1510: int failed = SipHeaderChecker.runTests();
1511:
1512: assertTrue("Number of failed tests: " + failed, failed == 0);
1513: }
1514:
1515: /**
1516: * Run the test
1517: */
1518: public void runTests() {
1519: declare("SipHeader test");
1520: Test1();
1521: }
1522: }
|