NIST SIP Parser and Stack (v1.2) API

gov.nist.javax.sip.parser
Class StringMsgParser

java.lang.Object
  |
  +--gov.nist.javax.sip.parser.StringMsgParser

public class StringMsgParser
extends Object

Parse SIP message and parts of SIP messages such as URI's etc from memory and return a structure. Intended use: UDP message processing. This class is used when you have an entire SIP message or SIPHeader or SIP URL in memory and you want to generate a parsed structure from it. For SIP messages, the payload can be binary or String. If you have a binary payload, use parseSIPMessage(byte[]) else use parseSIPMessage(String) The payload is accessible from the parsed message using the getContent and getContentBytes methods provided by the SIPMessage class. If SDP parsing is enabled using the parseContent method, then the SDP body is also parsed and can be accessed from the message using the getSDPAnnounce method. Currently only eager parsing of the message is supported (i.e. the entire message is parsed in one feld swoop).

Version:
JAIN-SIP-1.1
Author:
M. Ranganathan
This code is in the public domain.

Constructor Summary
StringMsgParser()
           
StringMsgParser(ParseExceptionListener exhandler)
          Constructor (given a parse exception handler).
 
Method Summary
 String getCurrentHeader()
          Get the current header.
 int getCurrentLineNumber()
          Get the current line number.
 String[] getHeaders()
          get the headers as an array of strings.
 AddressImpl parseAddress(String address)
          Parse an address (nameaddr or address spec) and return and address structure.
 Host parseHost(String host)
          Parse a host name and return a parsed structure.
 HostPort parseHostPort(String hostport)
          Parse a host:port and return a parsed structure.
 SIPHeader parseSIPHeader(String header)
          Parse an individual SIP message header from a string.
 gov.nist.javax.sip.message.SIPMessage parseSIPMessage(byte[] msgBuffer)
          Parse a buffer containing a single SIP Message where the body is an array of un-interpreted bytes.
 gov.nist.javax.sip.message.SIPMessage parseSIPMessage(String sipMessages)
          Parse a buffer containing one or more SIP Messages and return an array of SIPMessage parsed structures.
 RequestLine parseSIPRequestLine(String requestLine)
          Parse the SIP Request Line
 StatusLine parseSIPStatusLine(String statusLine)
          Parse the SIP Response message status line
 SipUri parseSIPUrl(String url)
          Parse a SIP url from a string and return a URI structure for it.
 TelephoneNumber parseTelephoneNumber(String telephone_number)
          Parse a telephone number return a parsed structure.
 GenericURI parseUrl(String url)
          Parse a uri from a string and return a URI structure for it.
 void setParseExceptionListener(ParseExceptionListener pexhandler)
          add a handler for header parsing errors.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringMsgParser

public StringMsgParser()
Since:
v0.9

StringMsgParser

public StringMsgParser(ParseExceptionListener exhandler)
Constructor (given a parse exception handler).

Parameters:
exhandler - is the parse exception listener for the message parser.
Since:
1.0
Method Detail

setParseExceptionListener

public void setParseExceptionListener(ParseExceptionListener pexhandler)
add a handler for header parsing errors.


parseSIPMessage

public gov.nist.javax.sip.message.SIPMessage parseSIPMessage(byte[] msgBuffer)
                                                      throws ParseException
Parse a buffer containing a single SIP Message where the body is an array of un-interpreted bytes. This is intended for parsing the message from a memory buffer when the buffer. Incorporates a bug fix for a bug that was noted by Will Sullin of Callcast

Parameters:
msgBuffer - a byte buffer containing the messages to be parsed. This can consist of multiple SIP Messages concatenated together.
Returns:
a SIPMessage[] structure (request or response) containing the parsed SIP message.
Throws:
SIPIllegalMessageException - is thrown when an illegal message has been encountered (and the rest of the buffer is discarded).
ParseException
See Also:
ParseExceptionListener

parseSIPMessage

public gov.nist.javax.sip.message.SIPMessage parseSIPMessage(String sipMessages)
                                                      throws ParseException
Parse a buffer containing one or more SIP Messages and return an array of SIPMessage parsed structures. Note that the current limitation is that this does not handle content encoding properly. The message content is just assumed to be encoded using the same encoding as the sip message itself (i.e. binary encodings such as gzip are not supported).

Parameters:
sipMessages - a String containing the messages to be parsed. This can consist of multiple SIP Messages concatenated together.
Returns:
a SIPMessage structure (request or response) containing the parsed SIP message.
Throws:
SIPIllegalMessageException - is thrown when an illegal message has been encountered (and the rest of the buffer is discarded).
ParseException
See Also:
ParseExceptionListener

parseAddress

public AddressImpl parseAddress(String address)
                         throws ParseException
Parse an address (nameaddr or address spec) and return and address structure.

Parameters:
address - is a String containing the address to be parsed.
Returns:
a parsed address structure.
Throws:
ParseException - when the address is badly formatted.
Since:
v1.0

parseHostPort

public HostPort parseHostPort(String hostport)
                       throws ParseException
Parse a host:port and return a parsed structure.

Parameters:
hostport - is a String containing the host:port to be parsed
Returns:
a parsed address structure.
Throws:
throws - a ParseException when the address is badly formatted.
ParseException
Since:
v1.0

parseHost

public Host parseHost(String host)
               throws ParseException
Parse a host name and return a parsed structure.

Parameters:
host - is a String containing the host name to be parsed
Returns:
a parsed address structure.
Throws:
throws - a ParseException when the hostname is badly formatted.
ParseException
Since:
v1.0

parseTelephoneNumber

public TelephoneNumber parseTelephoneNumber(String telephone_number)
                                     throws ParseException
Parse a telephone number return a parsed structure.

Returns:
a parsed address structure.
Throws:
throws - a ParseException when the address is badly formatted.
ParseException
Since:
v1.0

parseSIPUrl

public SipUri parseSIPUrl(String url)
                   throws ParseException
Parse a SIP url from a string and return a URI structure for it.

Parameters:
url - a String containing the URI structure to be parsed.
Returns:
A parsed URI structure
Throws:
ParseException - if there was an error parsing the message.

parseUrl

public GenericURI parseUrl(String url)
                    throws ParseException
Parse a uri from a string and return a URI structure for it.

Parameters:
url - a String containing the URI structure to be parsed.
Returns:
A parsed URI structure
Throws:
ParseException - if there was an error parsing the message.

parseSIPHeader

public SIPHeader parseSIPHeader(String header)
                         throws ParseException
Parse an individual SIP message header from a string.

Parameters:
header - String containing the SIP header.
Returns:
a SIPHeader structure.
Throws:
ParseException - if there was an error parsing the message.

parseSIPRequestLine

public RequestLine parseSIPRequestLine(String requestLine)
                                throws ParseException
Parse the SIP Request Line

Parameters:
requestLine - a String containing the request line to be parsed.
Returns:
a RequestLine structure that has the parsed RequestLine
Throws:
ParseException - if there was an error parsing the requestLine.

parseSIPStatusLine

public StatusLine parseSIPStatusLine(String statusLine)
                              throws ParseException
Parse the SIP Response message status line

Parameters:
statusLine - a String containing the Status line to be parsed.
Returns:
StatusLine class corresponding to message
Throws:
ParseException - if there was an error parsing
See Also:
StatusLine

getCurrentHeader

public String getCurrentHeader()
Get the current header.


getHeaders

public String[] getHeaders()
get the headers as an array of strings.


getCurrentLineNumber

public int getCurrentLineNumber()
Get the current line number.


NIST SIP Parser and Stack (v1.2) API

A product of the NIST/ITL Advanced Networking Technologies Division.
See conditions of use.
Get the latest distribution.
Submit a bug report or feature request.