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