Home | History | Annotate | Download | only in parser
      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 *
     25 */
     26 package gov.nist.javax.sip.parser;
     27 
     28 import gov.nist.javax.sip.address.*;
     29 import java.text.ParseException;
     30 import gov.nist.javax.sip.header.*;
     31 
     32 /**
     33  * Parser for the SIP request line.
     34  *
     35  * @version 1.2
     36  *
     37  * @author M. Ranganathan   <br/>
     38  *
     39  *
     40  */
     41 public class RequestLineParser extends Parser {
     42     public RequestLineParser(String requestLine) {
     43         this.lexer = new Lexer("method_keywordLexer", requestLine);
     44     }
     45     public RequestLineParser(Lexer lexer) {
     46         this.lexer = lexer;
     47         this.lexer.selectLexer("method_keywordLexer");
     48     }
     49 
     50     public RequestLine parse() throws ParseException {
     51         if (debug)
     52             dbg_enter("parse");
     53         try {
     54             RequestLine retval = new RequestLine();
     55             String m = method();
     56             lexer.SPorHT();
     57             retval.setMethod(m);
     58             this.lexer.selectLexer("sip_urlLexer");
     59             URLParser urlParser = new URLParser(this.getLexer());
     60             GenericURI url = urlParser.uriReference(true);
     61             lexer.SPorHT();
     62             retval.setUri(url);
     63             this.lexer.selectLexer("request_lineLexer");
     64             String v = sipVersion();
     65             retval.setSipVersion(v);
     66             lexer.SPorHT();
     67             lexer.match('\n');
     68             return retval;
     69         } finally {
     70             if (debug)
     71                 dbg_leave("parse");
     72         }
     73     }
     74 
     75             public static void main(String args[]) throws ParseException {
     76             String requestLines[] = {
     77                 "REGISTER sip:192.168.0.68 SIP/2.0\n",
     78                 "REGISTER sip:company.com SIP/2.0\n",
     79                 "INVITE sip:3660 (at) 166.35.231.140 SIP/2.0\n",
     80                 "INVITE sip:user (at) company.com SIP/2.0\n",
     81                 "REGISTER sip:[2001::1]:5060;transport=tcp SIP/2.0\n", // Added by Daniel J. Martinez Manzano <dani (at) dif.um.es>
     82                 "REGISTER sip:[2002:800:700:600:30:4:6:1]:5060;transport=udp SIP/2.0\n", // Added by Daniel J. Martinez Manzano <dani (at) dif.um.es>
     83                 "REGISTER sip:[3ffe:800:700::30:4:6:1]:5060;transport=tls SIP/2.0\n", // Added by Daniel J. Martinez Manzano <dani (at) dif.um.es>
     84                 "REGISTER sip:[2001:720:1710:0:201:29ff:fe21:f403]:5060;transport=udp SIP/2.0\n",
     85                 "OPTIONS sip:135.180.130.133 SIP/2.0\n" };
     86             for (int i = 0; i < requestLines.length; i++ ) {
     87                 RequestLineParser rlp =
     88                   new RequestLineParser(requestLines[i]);
     89                 RequestLine rl = rlp.parse();
     90                 System.out.println("encoded = " + rl.encode());
     91             }
     92 
     93         }
     94 
     95 }
     96 /*
     97  * $Log: RequestLineParser.java,v $
     98  * Revision 1.11  2009/10/22 10:27:38  jbemmel
     99  * Fix for issue #230, restructured the code such that parsing for any address appearing without '<' '>'
    100  * stops at ';', then parameters are assigned to the header as expected
    101  *
    102  * Revision 1.10  2009/09/15 02:55:27  mranga
    103  * Issue number:  222
    104  * Add HeaderFactoryExt.createStatusLine(String) and HeaderFactoryExt.createRequestLine(String)
    105  * Allows users to easily parse SipFrag bodies (for example NOTIFY bodies
    106  * during call transfer).
    107  *
    108  * Revision 1.9  2009/07/17 18:58:03  emcho
    109  * Converts indentation tabs to spaces so that we have a uniform indentation policy in the whole project.
    110  *
    111  * Revision 1.8  2006/07/13 09:02:14  mranga
    112  * Issue number:
    113  * Obtained from:
    114  * Submitted by:  jeroen van bemmel
    115  * Reviewed by:   mranga
    116  * Moved some changes from jain-sip-1.2 to java.net
    117  *
    118  * CVS: ----------------------------------------------------------------------
    119  * CVS: Issue number:
    120  * CVS:   If this change addresses one or more issues,
    121  * CVS:   then enter the issue number(s) here.
    122  * CVS: Obtained from:
    123  * CVS:   If this change has been taken from another system,
    124  * CVS:   then name the system in this line, otherwise delete it.
    125  * CVS: Submitted by:
    126  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    127  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    128  * CVS:   address here. If this is your work then delete this line.
    129  * CVS: Reviewed by:
    130  * CVS:   If we are doing pre-commit code reviews and someone else has
    131  * CVS:   reviewed your changes, include their name(s) here.
    132  * CVS:   If you have not had it reviewed then delete this line.
    133  *
    134  * Revision 1.3  2006/06/19 06:47:27  mranga
    135  * javadoc fixups
    136  *
    137  * Revision 1.2  2006/06/16 15:26:28  mranga
    138  * Added NIST disclaimer to all public domain files. Clean up some javadoc. Fixed a leak
    139  *
    140  * Revision 1.1.1.1  2005/10/04 17:12:35  mranga
    141  *
    142  * Import
    143  *
    144  *
    145  * Revision 1.6  2004/10/28 19:02:50  mranga
    146  * Submitted by:  Daniel Martinez
    147  * Reviewed by:   M. Ranganathan
    148  *
    149  * Added changes for TLS support contributed by Daniel Martinez
    150  *
    151  * Revision 1.5  2004/06/27 00:41:51  mranga
    152  * Submitted by:  Thomas Froment and Pierre De Rop
    153  * Reviewed by:   mranga
    154  * Performance improvements
    155  * (auxiliary data structure for fast lookup of transactions).
    156  *
    157  * Revision 1.4  2004/01/22 13:26:31  sverker
    158  * Issue number:
    159  * Obtained from:
    160  * Submitted by:  sverker
    161  * Reviewed by:   mranga
    162  *
    163  * Major reformat of code to conform with style guide. Resolved compiler and javadoc warnings. Added CVS tags.
    164  *
    165  * CVS: ----------------------------------------------------------------------
    166  * CVS: Issue number:
    167  * CVS:   If this change addresses one or more issues,
    168  * CVS:   then enter the issue number(s) here.
    169  * CVS: Obtained from:
    170  * CVS:   If this change has been taken from another system,
    171  * CVS:   then name the system in this line, otherwise delete it.
    172  * CVS: Submitted by:
    173  * CVS:   If this code has been contributed to the project by someone else; i.e.,
    174  * CVS:   they sent us a patch or a set of diffs, then include their name/email
    175  * CVS:   address here. If this is your work then delete this line.
    176  * CVS: Reviewed by:
    177  * CVS:   If we are doing pre-commit code reviews and someone else has
    178  * CVS:   reviewed your changes, include their name(s) here.
    179  * CVS:   If you have not had it reviewed then delete this line.
    180  *
    181  */
    182