• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Conditions Of Use
3  *
4  * This software was developed by employees of the National Institute of
5  * Standards and Technology (NIST), an agency of the Federal Government.
6  * Pursuant to title 15 Untied States Code Section 105, works of NIST
7  * employees are not subject to copyright protection in the United States
8  * and are considered to be in the public domain.  As a result, a formal
9  * license is not needed to use the software.
10  *
11  * This software is provided by NIST as a service and is expressly
12  * provided "AS IS."  NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
13  * OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
14  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
15  * AND DATA ACCURACY.  NIST does not warrant or make any representations
16  * regarding the use of the software or the results thereof, including but
17  * not limited to the correctness, accuracy, reliability or usefulness of
18  * the software.
19  *
20  * Permission to use this software is contingent upon your acceptance
21  * of the terms of this agreement.
22  *
23  */
24 package gov.nist.javax.sip.parser;
25 
26 import gov.nist.javax.sip.address.AddressImpl;
27 import gov.nist.javax.sip.address.SipUri;
28 import gov.nist.javax.sip.header.Contact;
29 import gov.nist.javax.sip.header.ContactList;
30 import gov.nist.javax.sip.header.SIPHeader;
31 
32 import javax.sip.address.URI;
33 import java.text.ParseException;
34 import java.util.HashSet;
35 import java.util.Iterator;
36 
37 /**
38  * A parser for The SIP contact header.
39  *
40  * @version 1.2 $Revision: 1.13 $ $Date: 2009/10/22 10:27:37 $
41  * @since 1.1
42  */
43 public class ContactParser extends AddressParametersParser {
44 
ContactParser(String contact)45     public ContactParser(String contact) {
46         super(contact);
47     }
48 
ContactParser(Lexer lexer)49     protected ContactParser(Lexer lexer) {
50         super(lexer);
51         this.lexer = lexer;
52     }
53 
parse()54     public SIPHeader parse() throws ParseException {
55         // past the header name and the colon.
56         headerName(TokenTypes.CONTACT);
57         ContactList retval = new ContactList();
58         while (true) {
59             Contact contact = new Contact();
60             if (lexer.lookAhead(0) == '*') {
61                 final char next = lexer.lookAhead(1);
62                 if (next == ' ' || next == '\t' || next == '\r' || next == '\n') {
63                     this.lexer.match('*');
64                     contact.setWildCardFlag(true);
65                 } else {
66                     super.parse(contact);
67                 }
68             } else {
69                 super.parse(contact);
70             }
71             retval.add(contact);
72             this.lexer.SPorHT();
73             char la = lexer.lookAhead(0);
74             if (la == ',') {
75                 this.lexer.match(',');
76                 this.lexer.SPorHT();
77             } else if (la == '\n' || la == '\0')
78                 break;
79             else
80                 throw createParseException("unexpected char");
81         }
82         return retval;
83     }
84 
85 }
86