Debian Codegraph @

java/gov/nist/javax/sip/parser/ims/PChargingFunctionAddressesParser.java

raw
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 /*******************************************
27 * PRODUCT OF PT INOVACAO - EST DEPARTMENT *
28 *******************************************/
29
30 package gov.nist.javax.sip.parser.ims;
31
32 import gov.nist.core.NameValue;
33 import gov.nist.javax.sip.header.SIPHeader;
34 import gov.nist.javax.sip.header.ims.PChargingFunctionAddresses;
35 import gov.nist.javax.sip.parser.Lexer;
36 import gov.nist.javax.sip.parser.ParametersParser;
37 import gov.nist.javax.sip.parser.TokenTypes;
38
39 import java.text.ParseException;
40
41
42 /**
43 * P-Charging-Function-Addresses header parser.
44 *
45 * <p>Sintax (RFC 3455):</p>
46 * <pre>
47 * P-Charging-Addr = "P-Charging-Function-Addresses" HCOLON
48 * charge-addr-params
49 * * (SEMI charge-addr-params)
50 * charge-addr-params = ccf / ecf / generic-param
51 * ccf = "ccf" EQUAL gen-value
52 * ecf = "ecf" EQUAL gen-value
53 * gen-value = token / host / quoted-string
54 * host = hostname / IPv4address / IPv6reference
55 * hostname = *( domainlabel "." ) toplabel [ "." ]
56 * domainlabel = alphanum / alphanum *( alphanum / "-" ) alphanum
57 * toplabel = ALPHA / ALPHA *( alphanum / "-" ) alphanum
58 * ipv6reference = "[" IPv6address "]"
59 *
60 * </pre>
61 *
62 * @author ALEXANDRE MIGUEL SILVA SANTOS
63 * @author aayush.bhatnagar: proposed change to allow duplicate ecf and ccf header parameters.
64 */
65
66 public class PChargingFunctionAddressesParser
67 extends ParametersParser
68 implements TokenTypes {
69
70
71 public PChargingFunctionAddressesParser(String charging) {
72
73 super(charging);
74
75
76 }
77
78
79 protected PChargingFunctionAddressesParser(Lexer lexer) {
80 super(lexer);
81
82 }
83
84
85
86 public SIPHeader parse() throws ParseException {
87
88
89 if (debug)
90 dbg_enter("parse");
91 try {
92 headerName(TokenTypes.P_CHARGING_FUNCTION_ADDRESSES);
93 PChargingFunctionAddresses chargingFunctionAddresses = new PChargingFunctionAddresses();
94
95 try {
96 while (lexer.lookAhead(0) != '\n') {
97
98 this.parseParameter(chargingFunctionAddresses);
99 this.lexer.SPorHT();
100 char la = lexer.lookAhead(0);
101 if (la == '\n' || la == '\0')
102 break;
103
104 this.lexer.match(';');
105 this.lexer.SPorHT();
106 }
107 } catch (ParseException ex) {
108 throw ex;
109 }
110
111
112 super.parse(chargingFunctionAddresses);
113 return chargingFunctionAddresses;
114 } finally {
115 if (debug)
116 dbg_leave("parse");
117 }
118 }
119
120 protected void parseParameter(PChargingFunctionAddresses chargingFunctionAddresses) throws ParseException {
121
122 if (debug)
123 dbg_enter("parseParameter");
124 try {
125
126 NameValue nv = this.nameValue('=');
127
128 //chargingFunctionAddresses.setParameter(nv);
129 chargingFunctionAddresses.setMultiParameter(nv);
130
131 } finally {
132 if (debug)
133 dbg_leave("parseParameter");
134 }
135
136
137
138 }
139
140
141
142
143
144
145 /** Test program */
146
147 public static void main(String args[]) throws ParseException {
148 String r[] = {
149 "P-Charging-Function-Addresses: ccf=\"test str\"; ecf=token\n",
150 "P-Charging-Function-Addresses: ccf=192.1.1.1; ccf=192.1.1.2; ecf=192.1.1.3; ecf=192.1.1.4\n",
151 "P-Charging-Function-Addresses: ccf=[5555::b99:c88:d77:e66]; ccf=[5555::a55:b44:c33:d22]; " +
152 "ecf=[5555::1ff:2ee:3dd:4cc]; ecf=[5555::6aa:7bb:8cc:9dd]\n"
153
154 };
155
156
157 for (int i = 0; i < r.length; i++ )
158 {
159
160 PChargingFunctionAddressesParser parser =
161 new PChargingFunctionAddressesParser(r[i]);
162
163 System.out.println("original = " + r[i]);
164
165 PChargingFunctionAddresses chargAddr= (PChargingFunctionAddresses) parser.parse();
166 System.out.println("encoded = " + chargAddr.encode());
167 }
168
169
170 }
171
172
173
174
175
176
177
178 }