]> git.ipfire.org Git - thirdparty/cups.git/blob - scripting/java/src/com/easysw/cups/IPP.java
Load cups into easysw/current.
[thirdparty/cups.git] / scripting / java / src / com / easysw / cups / IPP.java
1 package com.easysw.cups;
2
3 /**
4 * @version 0.00 06-NOV-2001
5 * @author Easy Software Products
6 *
7 * Internet Printing Protocol definitions for the Common UNIX Printing
8 * System (CUPS).
9 *
10 * Copyright 1997-2002 by Easy Software Products.
11 *
12 * These coded instructions, statements, and computer programs are the
13 * property of Easy Software Products and are protected by Federal
14 * copyright law. Distribution and use rights are outlined in the file
15 * "LICENSE.txt" which should have been included with this file. If this
16 * file is missing or damaged please contact Easy Software Products
17 * at:
18 *
19 * Attn: CUPS Licensing Information
20 * Easy Software Products
21 * 44141 Airport View Drive, Suite 204
22 * Hollywood, Maryland 20636-3111 USA
23 *
24 * Voice: (301) 373-9603
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org
27 */
28
29 import java.util.*;
30
31 /**
32 * An <code>IPP</code> object is used to hold the various
33 * attributes and status of an ipp request..
34 *
35 * @author TDB
36 * @version 1.0
37 * @since JDK1.3
38 */
39 public class IPP
40 {
41 public IPPRequest request; // The request header
42 public IPPStatus status; // Status of request
43 public List attrs; // Attributes list.
44
45 short state; // Current IPP state (of request???)
46 int current; // Index into attributes array.
47 int last; // Index into attributes array.
48 short current_tag;
49
50
51 // ------------------------------------------------------------------
52 //
53 // Constructor
54 //
55 public IPP()
56 {
57 state = IPPDefs.IDLE;
58 attrs = new LinkedList();
59 current = -1;
60 last = -1;
61 current_tag = IPPDefs.TAG_ZERO;
62 }
63
64
65
66 /**
67 * Add an attribute to the attibutes list
68 * for later parsing.
69 *
70 * @param a <code>IPPAttribute</code> to add.
71 * @return <code>true</code> always returns <code>true</code>
72 * for now.
73 *
74 * @see IPPAttribute
75 * @see IPPValue
76 */
77 public boolean addAttribute( IPPAttribute a )
78 {
79 attrs.add(a);
80 return(true);
81 }
82
83 /**
84 * Get the current attribute pointed at by
85 * <code>current</code>.
86 *
87 * @return <code>IPPAttribute</code> Return the current attribute.
88 * @return <code>null</code> Return <code>null</code>
89 * if <code>current</code> is 0.
90 */
91 public IPPAttribute getCurrentAttribute()
92 {
93 if (current >= 0)
94 return( (IPPAttribute)attrs.get(current) );
95 else
96 return( null );
97 }
98
99 // public void setCurrentAttribute( IPPAttribute p_attr )
100 // {
101 // if (current >= 0)
102 // return( (IPPAttribute)attrs.get(current) );
103 // }
104
105
106 /**
107 *
108 * Find the named attribute of the correct type. Both must match.
109 * This methos searches from the beginning of the attribute list,
110 * rather than from the current position.
111 *
112 * @param p_name <code>String</code> containing the name.
113 * @param p_type <code>int</code> attribute type.
114 *
115 * @return <code>IPPAttribute</code> Matching attribute if found.
116 * @return <code>null</code> <code>null</code> if not found.
117 */
118 public IPPAttribute ippFindAttribute( String p_name, int p_type )
119 {
120 if (p_name.length() < 1)
121 return(null);
122 current = -1;
123 return(ippFindNextAttribute(p_name, p_type));
124 }
125
126
127
128
129 /**
130 *
131 * Find the named attribute of the correct type. Both must match.
132 * This methos searches from the current position in the attribute list.
133 *
134 * @param p_name <code>String</code> containing the name.
135 * @param p_type <code>int</code> attribute type.
136 *
137 * @return <code>IPPAttribute</code> Matching attribute if found.
138 * @return <code>null</code> <code>null</code> if not found.
139 */
140 public IPPAttribute ippFindNextAttribute( String p_name, int p_type )
141 {
142 int value_tag;
143
144 if (p_name.length() < 1)
145 return(null);
146
147 if ((current >= 0) && (current < (attrs.size() - 1)))
148 current++;
149 else
150 current = 0;
151
152 for (int i = current; i < attrs.size(); i++)
153 {
154 IPPAttribute tmp = (IPPAttribute)attrs.get(i);
155 value_tag = (tmp.value_tag & IPPDefs.TAG_MASK);
156 if ((tmp.name.length() > 0) && (tmp.name == p_name) &&
157 (value_tag == p_type || p_type == IPPDefs.TAG_ZERO ||
158 (value_tag == IPPDefs.TAG_TEXTLANG && p_type == IPPDefs.TAG_TEXT) ||
159 (value_tag == IPPDefs.TAG_NAMELANG && p_type == IPPDefs.TAG_NAME)))
160 {
161 current = i;
162 return(tmp);
163 }
164 }
165 return(null);
166 }
167
168
169 /**
170 * Get the size in bytes of an <code>IPP</code> request.
171 *
172 * @return <code>int</code> Number of bytes for the request.
173 */
174 public int sizeInBytes()
175 {
176 IPPAttribute a;
177 int bytes = 8;
178 int last_group = IPPDefs.TAG_ZERO;
179
180 for (int i=0; i < attrs.size(); i++)
181 {
182 a = (IPPAttribute)attrs.get(i);
183 bytes += a.sizeInBytes(last_group);
184 last_group = a.group_tag;
185 }
186 bytes++; // one for the end tag.
187
188 return(bytes);
189
190 } // End of IPP.sizeInBytes()
191
192
193
194
195
196 int ippBytes()
197 {
198 int i = 0;
199 return(0);
200 }
201
202
203
204 /**
205 * Set the <code>IPP</code> request ID.
206 *
207 * @param p_id <code>short</code> request id.
208 */
209 public void setRequestID( short p_id )
210 {
211 request.request_id = p_id;
212 }
213
214 /**
215 * Set the <code>IPP</code> operation ID.
216 *
217 * @param p_operation_id <code>short</code> operation id.
218 */
219 public void setRequestOperationID( short p_operation_id )
220 {
221 request.operation_id = p_operation_id;
222 }
223
224
225 //
226 // Dump a list - for debugging.
227 //
228 public void dump_response()
229 {
230 IPPAttribute a;
231 int last_group = IPPDefs.TAG_ZERO;
232
233 for (int i=0; i < attrs.size(); i++)
234 {
235 a = (IPPAttribute)attrs.get(i);
236 a.dump_values();
237 last_group = a.group_tag;
238 }
239 return;
240
241 } // End of IPP.dump_response()
242
243
244 } // End of IPP class
245
246
247
248
249 //
250 // End of IPP.java
251 //