001: /*
002: * Portions Copyright 2000-2007 Sun Microsystems, Inc. All Rights
003: * Reserved. Use is subject to license terms.
004: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License version
008: * 2 only, as published by the Free Software Foundation.
009: *
010: * This program is distributed in the hope that it will be useful, but
011: * WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * General Public License version 2 for more details (a copy is
014: * included at /legal/license.txt).
015: *
016: * You should have received a copy of the GNU General Public License
017: * version 2 along with this work; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019: * 02110-1301 USA
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022: * Clara, CA 95054 or visit www.sun.com if you need additional
023: * information or have any questions.
024: */
025: package gov.nist.siplite.parser;
026:
027: import gov.nist.siplite.header.*;
028: import gov.nist.core.*;
029:
030: /**
031: * A parser for The SIP contact header.
032: *
033: * @version JAIN-SIP-1.1
034: *
035: *
036: * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
037: *
038: */
039: public class ContactParser extends AddressParametersParser {
040: /** Default constructor. */
041: ContactParser() {
042: }
043:
044: /**
045: * Constructor with initial contact string.
046: * @param contact initial contact field to be processed.
047: */
048: public ContactParser(String contact) {
049: super (contact);
050: }
051:
052: /**
053: * Constructor with initial lexer engine.
054: * @param lexer initial lexer engine
055: */
056: protected ContactParser(Lexer lexer) {
057: super (lexer);
058: this .lexer = lexer;
059: }
060:
061: /**
062: * Invokes the parser for the contact header field.
063: * @return theparsed contact header
064: */
065: public Header parse() throws ParseException {
066: // past the header name and the colon.
067: headerName(TokenTypes.CONTACT);
068: ContactList retval = new ContactList();
069: while (true) {
070: ContactHeader contact = new ContactHeader();
071: if (lexer.lookAhead(0) == '*') {
072: this .lexer.match('*');
073: contact.setWildCardFlag(true);
074: } else
075: super .parse(contact);
076: retval.add(contact);
077: this .lexer.SPorHT();
078: if (lexer.lookAhead(0) == ',') {
079: this .lexer.match(',');
080: this .lexer.SPorHT();
081: } else if (lexer.lookAhead(0) == '\n')
082: break;
083: else
084: throw createParseException("unexpected char");
085: }
086: return retval;
087: }
088: /*
089: public static void main(String args[]) throws ParseException {
090: String contact[] = {
091: "Contact:<sip:utente@127.0.0.1:5000;transport=TCP>;expires=3600\n",
092: "Contact:BigGuy<sip:utente@127.0.0.1:5000>;expires=3600\n",
093: "Contact: sip:4855@166.35.224.216:5060\n",
094: "Contact: sip:user@host.company.com\n",
095: "Contact: Bo Bob Biggs\n"+
096: "< sip:user@example.com?Route=%3Csip:sip.example.com%3E >\n",
097: "Contact: Joe Bob Briggs <sip:mranga@nist.gov>\n",
098: "Contact: \"Mr. Watson\" <sip:watson@worcester.bell-telephone.com>"+
099: " ; q=0.7; expires=3600,\"Mr. Watson\" "
100: + "<mailto:watson@bell-telephone.com>"+
101: ";q=0.1\n",
102: "Contact: LittleGuy <sip:UserB@there.com;user=phone>"+
103: ",<sip:+1-972-555-2222@gw1.wcom.com;user=phone>,"
104: + "tel:+1-972-555-2222"+
105: "\n",
106: "Contact:*\n",
107: "Contact:BigGuy<sip:utente@127.0.0.1;5000>;Expires=3600\n"
108: };
109:
110: for (int i = 0; i < contact.length; i++) {
111: ContactParser cp =
112: new ContactParser(contact[i]);
113: ContactList cl = (ContactList) cp.parse();
114: ContactHeader c = (ContactHeader) cl.getFirst();
115: System.out.println("encoded = " + c.toString());
116: System.out.println("address = " + c.getAddress());
117: System.out.println();
118: }
119: }
120: */
121: }
|