| 1 |
package gov.nist.javax.sip.parser.extensions; |
| 2 |
|
| 3 |
import gov.nist.javax.sip.header.*; |
| 4 |
import gov.nist.javax.sip.header.extensions.*; |
| 5 |
import gov.nist.javax.sip.parser.*; |
| 6 |
|
| 7 |
import java.text.ParseException; |
| 8 |
|
| 9 |
// Parser for Join Header (RFC3911) |
| 10 |
// Extension by jean deruelle |
| 11 |
// |
| 12 |
// Join = "Join" HCOLON callid *(SEMI join-param) |
| 13 |
// join-param = to-tag / from-tag / generic-param |
| 14 |
// to-tag = "to-tag" EQUAL token |
| 15 |
// from-tag = "from-tag" EQUAL token |
| 16 |
// |
| 17 |
// |
| 18 |
|
| 19 |
public class JoinParser extends ParametersParser { |
| 20 |
|
| 21 |
/** |
| 22 |
* Creates new CallIDParser |
| 23 |
* @param callID message to parse |
| 24 |
*/ |
| 25 |
public JoinParser(String callID) { |
| 26 |
super(callID); |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructor |
| 31 |
* @param lexer Lexer to set |
| 32 |
*/ |
| 33 |
protected JoinParser(Lexer lexer) { |
| 34 |
super(lexer); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* parse the String message |
| 39 |
* @return SIPHeader (CallID object) |
| 40 |
* @throws ParseException if the message does not respect the spec. |
| 41 |
*/ |
| 42 |
public SIPHeader parse() throws ParseException { |
| 43 |
if (debug) |
| 44 |
dbg_enter("parse"); |
| 45 |
try { |
| 46 |
headerName(TokenTypes.JOIN_TO); |
| 47 |
|
| 48 |
Join join = new Join(); |
| 49 |
this.lexer.SPorHT(); |
| 50 |
String callId = lexer.byteStringNoSemicolon(); |
| 51 |
this.lexer.SPorHT(); |
| 52 |
super.parse(join); |
| 53 |
join.setCallId(callId); |
| 54 |
return join; |
| 55 |
} finally { |
| 56 |
if (debug) |
| 57 |
dbg_leave("parse"); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public static void main(String args[]) throws ParseException { |
| 62 |
String to[] = |
| 63 |
{ "Join: 12345th5z8z\n", |
| 64 |
"Join: 12345th5z8z;to-tag=tozght6-45;from-tag=fromzght789-337-2\n", |
| 65 |
}; |
| 66 |
|
| 67 |
for (int i = 0; i < to.length; i++) { |
| 68 |
JoinParser tp = new JoinParser(to[i]); |
| 69 |
Join t = (Join) tp.parse(); |
| 70 |
System.out.println("Parsing => " + to[i]); |
| 71 |
System.out.print("encoded = " + t.encode() + "==> "); |
| 72 |
System.out.println("callId " + t.getCallId() + " from-tag=" + t.getFromTag() |
| 73 |
+ " to-tag=" + t.getToTag()) ; |
| 74 |
|
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
} |