1 package com
.easysw
.cups
;
4 * @version 1.00 06-NOV-2002
5 * @author Easy Software Products
7 * Internet Printing Protocol definitions for the Common UNIX Printing
10 * Copyright 1997-2002 by Easy Software Products.
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
19 * Attn: CUPS Licensing Information
20 * Easy Software Products
21 * 44141 Airport View Drive, Suite 204
22 * Hollywood, Maryland 20636-3111 USA
24 * Voice: (301) 373-9603
25 * EMail: cups-info@cups.org
26 * WWW: http://www.cups.org
30 * An <code>IPPHttp</code> object is used for reading/writing to the cups
31 * server, and processing responses.
41 import java
.security
.*;
47 * Class constants - most not in use yet.
49 public static final int HTTP_WAITING
= 0x00;
50 public static final int HTTP_OPTIONS
= 0x01;
51 public static final int HTTP_GET
= 0x02;
52 public static final int HTTP_GET_SEND
= 0x03;
53 public static final int HTTP_HEAD
= 0x04;
54 public static final int HTTP_POST
= 0x05;
55 public static final int HTTP_POST_RECV
= 0x06;
56 public static final int HTTP_POST_SEND
= 0x07;
57 public static final int HTTP_PUT
= 0x08;
58 public static final int HTTP_PUT_RECV
= 0x09;
59 public static final int HTTP_DELETE
= 0x0A;
60 public static final int HTTP_TRACE
= 0x0B;
61 public static final int HTTP_CLOSE
= 0x0C;
62 public static final int HTTP_STATUS
= 0x0D;
64 public static final int HTTP_0_9
= 0x09;
65 public static final int HTTP_1_0
= 0x64;
66 public static final int HTTP_1_1
= 0x65;
68 public static final int HTTP_KEEPALIVE_OFF
= 0x00;
69 public static final int HTTP_KEEPALIVE_ON
= 0x01;
71 public static final int HTTP_ENCODE_LENGTH
= 0x00;
72 public static final int HTTP_ENCODE_CHUNKED
= 0x01;
74 public static final int HTTP_ENCRYPT_IF_REQUESTED
= 0x00;
75 public static final int HTTP_ENCRYPT_NEVER
= 0x01;
76 public static final int HTTP_ENCRYPT_REQUIRED
= 0x02;
77 public static final int HTTP_ENCRYPT_ALWAYS
= 0x03;
79 public static final int HTTP_AUTH_NONE
= 0x00;
80 public static final int HTTP_AUTH_BASIC
= 0x01;
81 public static final int HTTP_AUTH_MD5
= 0x02;
82 public static final int HTTP_AUTH_MD5_SESS
= 0x03;
83 public static final int HTTP_AUTH_MD5_INT
= 0x04;
84 public static final int HTTP_AUTH_MD5_SESS_INT
= 0x05;
86 public static final int HTTP_ERROR
= 0xFFFFFFFF;
87 public static final int HTTP_CONTINUE
= 0x64;
88 public static final int HTTP_SWITCHING_PROTOCOLS
= 0x65;
89 public static final int HTTP_OK
= 0xC8;
90 public static final int HTTP_CREATED
= 0xC9;
91 public static final int HTTP_ACCEPTED
= 0xCA;
92 public static final int HTTP_NOT_AUTHORITATIVE
= 0xCB;
93 public static final int HTTP_NO_CONTENT
= 0xCC;
94 public static final int HTTP_RESET_CONTENT
= 0xCD;
95 public static final int HTTP_PARTIAL_CONTENT
= 0xCE;
96 public static final int HTTP_MULTIPLE_CHOICES
= 0x12C;
97 public static final int HTTP_MOVED_PERMANENTLY
= 0x12D;
98 public static final int HTTP_MOVED_TEMPORARILY
= 0x12E;
99 public static final int HTTP_SEE_OTHER
= 0x12F;
100 public static final int HTTP_NOT_MODIFIED
= 0x130;
101 public static final int HTTP_USE_PROXY
= 0x131;
102 public static final int HTTP_BAD_REQUEST
= 0x190;
103 public static final int HTTP_UNAUTHORIZED
= 0x191;
104 public static final int HTTP_PAYMENT_REQUIRED
= 0x192;
105 public static final int HTTP_FORBIDDEN
= 0x193;
106 public static final int HTTP_NOT_FOUND
= 0x194;
107 public static final int HTTP_METHOD_NOT_ALLOWED
= 0x195;
108 public static final int HTTP_NOT_ACCEPTABLE
= 0x196;
109 public static final int HTTP_PROXY_AUTHENTICATION
= 0x197;
110 public static final int HTTP_REQUEST_TIMEOUT
= 0x198;
111 public static final int HTTP_CONFLICT
= 0x199;
112 public static final int HTTP_GONE
= 0x19A;
113 public static final int HTTP_LENGTH_REQUIRED
= 0x19B;
114 public static final int HTTP_PRECONDITION
= 0x19C;
115 public static final int HTTP_REQUEST_TOO_LARGE
= 0x19D;
116 public static final int HTTP_URI_TOO_LONG
= 0x19E;
117 public static final int HTTP_UNSUPPORTED_MEDIATYPE
= 0x19F;
118 public static final int HTTP_UPGRADE_REQUIRED
= 0x1AA;
119 public static final int HTTP_SERVER_ERROR
= 0x1F4;
120 public static final int HTTP_NOT_IMPLEMENTED
= 0x1F5;
121 public static final int HTTP_BAD_GATEWAY
= 0x1F6;
122 public static final int HTTP_SERVICE_UNAVAILABLE
= 0x1F7;
123 public static final int HTTP_GATEWAY_TIMEOUT
= 0x1F8;
125 public static final int HTTP_NOT_SUPPORTED
= 0x1F9;
127 public static final int HTTP_FIELD_UNKNOWN
= 0xFFFFFFFF;
128 public static final int HTTP_FIELD_ACCEPT_LANGUAGE
= 0x00;
129 public static final int HTTP_FIELD_ACCEPT_RANGES
= 0x01;
130 public static final int HTTP_FIELD_AUTHORIZATION
= 0x02;
131 public static final int HTTP_FIELD_CONNECTION
= 0x03;
132 public static final int HTTP_FIELD_CONTENT_ENCODING
= 0x04;
133 public static final int HTTP_FIELD_CONTENT_LANGUAGE
= 0x05;
134 public static final int HTTP_FIELD_CONTENT_LENGTH
= 0x06;
135 public static final int HTTP_FIELD_CONTENT_LOCATION
= 0x07;
136 public static final int HTTP_FIELD_CONTENT_MD5
= 0x08;
137 public static final int HTTP_FIELD_CONTENT_RANGE
= 0x09;
138 public static final int HTTP_FIELD_CONTENT_TYPE
= 0x0A;
139 public static final int HTTP_FIELD_CONTENT_VERSION
= 0x0B;
140 public static final int HTTP_FIELD_DATE
= 0x0C;
141 public static final int HTTP_FIELD_HOST
= 0x0D;
142 public static final int HTTP_FIELD_IF_MODIFIED_SINCE
= 0x0E;
143 public static final int HTTP_FIELD_IF_UNMODIFIED_SINCE
= 0x0F;
144 public static final int HTTP_FIELD_KEEP_ALIVE
= 0x10;
145 public static final int HTTP_FIELD_LAST_MODIFIED
= 0x11;
146 public static final int HTTP_FIELD_LINK
= 0x12;
147 public static final int HTTP_FIELD_LOCATION
= 0x13;
148 public static final int HTTP_FIELD_RANGE
= 0x14;
149 public static final int HTTP_FIELD_REFERER
= 0x15;
150 public static final int HTTP_FIELD_RETRY_AFTER
= 0x16;
151 public static final int HTTP_FIELD_TRANSFER_ENCODING
= 0x17;
152 public static final int HTTP_FIELD_UPGRADE
= 0x18;
153 public static final int HTTP_FIELD_USER_AGENT
= 0x19;
154 public static final int HTTP_FIELD_WWW_AUTHENTICATE
= 0x1A;
155 public static final int HTTP_FIELD_MAX
= 0x1B;
157 public static final String http_fields
[] =
174 "If-Unmodified-since",
187 public static final String days
[] =
197 public static final String months
[] =
216 // Private class members.
218 private URL url
; // URL of connection.
220 public Socket conn
; // Connection socket.
221 public boolean connected
; // True when connected.
223 public BufferedInputStream is
; // Input stream.
224 public BufferedReader br
;
225 public BufferedOutputStream os
; // Output stream.
227 private boolean encrypted
;
229 public int write_content_length
;
230 private char write_buffer
[];
231 private int write_buffer_head
;
232 private int write_buffer_tail
;
234 public String read_header_date
;
235 public String read_header_server
;
236 public String read_header_charset
;
237 public String read_header_content_language
;
238 public String read_header_content_type
;
239 public int read_header_content_length
;
241 public char read_buffer
[];
242 private int read_buffer_head
;
243 private int read_buffer_tail
;
246 public String status_text
;
247 public String version
;
251 public String hostname
; // Hostname from URL
252 public int port
; // Port from URL.
253 public String path
; // Path from URL.
254 public String user
; // User name
255 public String passwd
; // Password
257 public String auth_type
; // none, basic, digest
258 public String realm
; // For digest auth
259 public String opaque
; // For digest auth
260 public String nonce
; // For digest auth
261 public String resource
; // For digest auth
262 public String method
; // For digest auth
264 public String http_request
;
265 public int http_content_length
;
270 * Constructor using <code>URL</code>.
272 * @param request_url <code>URL</code> of server to connect to.
274 * @throw UnknownHostException
276 public IPPHttp( String request_url
)
277 throws IOException
, UnknownHostException
297 // Create the URL and split it up.
299 url
= new URL(request_url
);
300 hostname
= url
.getHost();
301 port
= url
.getPort();
302 path
= url
.getPath();
306 // Open the socket and set the options.
308 conn
= new Socket(hostname
, port
);
309 conn
.setSoTimeout(200);
312 // Create the input and output streams.
314 is
= new BufferedInputStream(new DataInputStream(conn
.getInputStream()));
315 os
= new BufferedOutputStream(new DataOutputStream(conn
.getOutputStream()));
318 catch(UnknownHostException unknownhostexception
)
320 throw unknownhostexception
;
322 catch(IOException ioexception
)
331 * Constructor using <code>URL, user and pass</code>.
333 * @param request_url <code>URL</code> of server to connect to.
334 * @param p_auth_type <code>String</code> basic or digest.
335 * @param p_user <code>String</code> User name.
336 * @param p_passwd <code>String</code> password.
338 * @throw UnknownHostException
340 public IPPHttp( String request_url
, String p_auth_type
,
341 String p_user
, String p_passwd
)
342 throws IOException
, UnknownHostException
352 auth_type
= p_auth_type
;
362 // Create the URL and split it up.
364 url
= new URL(request_url
);
365 hostname
= url
.getHost();
366 port
= url
.getPort();
367 path
= url
.getPath();
370 // Open the socket and set the options.
372 conn
= new Socket(hostname
, port
);
373 conn
.setSoTimeout(200);
376 // Create the input and output streams.
378 is
= new BufferedInputStream(new DataInputStream(conn
.getInputStream()));
379 os
= new BufferedOutputStream(new DataOutputStream(conn
.getOutputStream()));
382 catch(UnknownHostException unknownhostexception
)
384 throw unknownhostexception
;
386 catch(IOException ioexception
)
396 * Re-establish a dropped connection.
398 * @return <code>boolean</code> True if connected.
402 public boolean reConnect() throws IOException
410 // Open the socket and set the options.
412 conn
= new Socket(hostname
, port
);
413 conn
.setSoTimeout(200);
416 // Create the input and output streams.
418 is
= new BufferedInputStream(new DataInputStream(conn
.getInputStream()));
419 os
= new BufferedOutputStream(new DataOutputStream(conn
.getOutputStream()));
424 catch (IOException ioexception
)
436 * @param p_user <code>String</code> - user name.
438 public void setUser(String p_user
)
447 * @param p_passwd <code>String</code> - password.
449 public void setPassword(String p_passwd
)
458 * Write the request header bytes to the server.
460 * @param request <code>String</code> - the request.
461 * @param content_length <code>int</code> - size of the total request.
464 public int writeHeader(String request
, int content_length
)
468 http_request
= request
;
469 http_content_length
= content_length
;
473 String s1
= "POST " + request
+ " HTTP/1.0\r\n";
474 os
.write(s1
.getBytes(), 0, s1
.length());
476 s1
= "Content-type: application/ipp\r\n";
477 os
.write(s1
.getBytes(), 0, s1
.length());
481 // Do basic style authorization if needed.
483 if (auth_type
.compareTo("basic") == 0)
485 s1
= user
+ ":" + passwd
;
486 IPPBase64Encoder encoder
= new IPPBase64Encoder();
487 String auth_string
= encoder
.encode(s1
.getBytes());
488 s1
= "Authorization: Basic " + auth_string
+ "\r\n";
489 os
.write(s1
.getBytes(), 0, s1
.length());
491 else if (auth_type
.compareTo("digest") == 0)
495 IPPMD5 md5
= IPPMD5
.getInstance();
496 String auth_string
= md5
.MD5Digest(user
, passwd
, realm
,
497 "POST", path
, nonce
);
498 s1
= "Authorization: Digest " + "username=\"" + user
+ "\", " +
499 "realm=\"" + realm
+ "\", " +
500 "nonce=\"" + nonce
+ "\", " +
501 "response=\"" + auth_string
+ "\"\r\n";
503 os
.write(s1
.getBytes(), 0, s1
.length());
505 catch(NoSuchAlgorithmException e
)
507 System
.out
.println("No such algorithm: MD5.");
511 s1
= "Content-length: " + content_length
+ "\r\n\r\n";
512 os
.write(s1
.getBytes(), 0, s1
.length());
515 catch(IOException ioexception
)
524 int local_status
= 0;
527 // Check for any response.
529 if (is
.available() > 0)
531 StringBuffer http_version
= new StringBuffer(32);
532 StringBuffer http_status
= new StringBuffer(32);
533 StringBuffer http_text
= new StringBuffer(256);
538 while (is
.available() > 0)
540 read_buffer
= read_line();
542 if (read_buffer
.startsWith("HTTP/"))
545 String s2
= read_buffer
.substring(5);
548 for (i
=0;(i
< s2
.length() && s2
.charAt(i
) != ' '); i
++)
550 http_version
.append(s2
.charAt(i
));
552 while (i
< s2
.length() && s2
.charAt(i
) == ' ')
554 for (;(i
< s2
.length() && s2
.charAt(i
) != '\n' &&
555 s2
.charAt(i
) != '\r' && s2
.charAt(i
) != ' '); i
++)
557 http_status
.append(s2
.charAt(i
));
560 while (i
< s2
.length() && s2
.charAt(i
) == ' ')
562 for (n
=0;(n
< 256 && i
< s2
.length() && s2
.charAt(i
) != '\n' &&
563 s2
.charAt(i
) != '\r' && s2
.charAt(i
) != ' '); i
++)
565 http_text
.append(s2
.charAt(i
));
567 local_status
= Integer
.parseInt(http_status
.toString(), 10);
574 // See if we need to reconnect and send authorization.
576 switch( local_status
)
581 case HTTP_UNAUTHORIZED
: read_header();
582 return( local_status
);
585 catch(IOException ioexception
)
598 public int checkForResponse()
601 // Check for any response.
605 if (is
.available() > 0)
607 StringBuffer http_version
= new StringBuffer(32);
608 StringBuffer http_status
= new StringBuffer(32);
609 StringBuffer http_text
= new StringBuffer(256);
610 int local_status
= 0;
615 while (is
.available() > 0)
617 read_buffer
= read_line();
618 if (read_buffer
.startsWith("HTTP/"))
621 String s2
= read_buffer
.substring(5);
622 for (i
=0;(i
< s2
.length() && s2
.charAt(i
) != ' '); i
++)
624 http_version
.append(s2
.charAt(i
));
626 while (i
< s2
.length() && s2
.charAt(i
) == ' ')
628 for (;(i
< s2
.length() && s2
.charAt(i
) != '\n' &&
629 s2
.charAt(i
) != '\r' && s2
.charAt(i
) != ' '); i
++)
631 http_status
.append(s2
.charAt(i
));
634 while (i
< s2
.length() && s2
.charAt(i
) == ' ')
636 for (n
=0;(n
< 256 && i
< s2
.length() && s2
.charAt(i
) != '\n' &&
637 s2
.charAt(i
) != '\r' && s2
.charAt(i
) != ' '); i
++)
639 http_text
.append(s2
.charAt(i
));
641 local_status
= Integer
.parseInt(http_status
.toString(), 10);
642 status
= local_status
;
648 // See if we need to reconnect and send authorization.
650 switch( local_status
)
655 case HTTP_UNAUTHORIZED
: read_header();
656 return( local_status
);
660 catch (IOException e
)
669 * Write bytes to the output stream.
671 * @param bytes Array of bytes to write to the stream.
674 public void write(byte bytes
[])
679 os
.write(bytes
, 0, bytes
.length
);
682 catch(IOException ioexception
)
691 * Write bytes to the output stream.
693 * @param bytes Array of bytes to write to the stream.
694 * @param length Number of bytes to write to the stream.
697 public void write(byte bytes
[], int length
)
702 os
.write(bytes
, 0, length
);
705 catch(IOException ioexception
)
722 * Read the HTTP header from the input stream.
724 * @return <code>int</code> Content length of response.
725 * @return 0 Return zero on error.
728 public int read_header()
731 boolean done
= false;
732 read_header_content_length
= 0;
737 read_buffer
= read_line();
738 if (read_buffer
.startsWith("HTTP/"))
741 String s2
= read_buffer
.substring(5);
743 StringBuffer http_version
= new StringBuffer(32);
744 StringBuffer http_status
= new StringBuffer(32);
745 StringBuffer http_text
= new StringBuffer(256);
747 for (i
=0;(i
< s2
.length() && s2
.charAt(i
) != ' '); i
++)
749 http_version
.append(s2
.charAt(i
));
751 while (i
< s2
.length() && s2
.charAt(i
) == ' ')
753 for (;(i
< s2
.length() && s2
.charAt(i
) != '\n' &&
754 s2
.charAt(i
) != '\r' && s2
.charAt(i
) != ' '); i
++)
756 http_status
.append(s2
.charAt(i
));
759 while (i
< s2
.length() && s2
.charAt(i
) == ' ')
761 for (n
=0;(n
< 256 && i
< s2
.length() && s2
.charAt(i
) != '\n' &&
762 s2
.charAt(i
) != '\r' && s2
.charAt(i
) != ' '); i
++)
764 http_text
.append(s2
.charAt(i
));
766 version
= http_version
.toString();
767 status
= Integer
.parseInt(http_status
.toString(), 10);
768 status_text
= http_text
.toString();
770 else if (read_buffer
.startsWith("WWW-Authenticate: Basic"))
772 String s2
=read_buffer
.substring("WWW-Authenticate: Basic".length());
775 else if (read_buffer
.startsWith("WWW-Authenticate: Digest"))
777 String s2
=read_buffer
.substring("WWW-Authenticate: Digest".length());
778 auth_type
= "digest";
779 parseAuthenticate(s2
);
781 else if (read_buffer
.startsWith("Content-Length:"))
783 String s2
= read_buffer
.substring(15);
784 read_header_content_length
= Integer
.parseInt(s2
.trim(), 10);
786 else if (read_buffer
.startsWith("Content-Language:"))
788 String s3
= read_buffer
.substring(17);
789 read_header_content_language
= s3
.trim();
791 else if (read_buffer
.startsWith("Server:"))
793 String s4
= read_buffer
.substring(7);
794 read_header_server
= s4
.trim();
796 else if (read_buffer
.startsWith("Date:"))
798 String s5
= read_buffer
.substring(5);
799 read_header_date
= s5
.trim();
801 else if (read_buffer
.length() == 0)
804 return( read_header_content_length
);
813 * Read a line from the input stream.
815 * @return <code>String</code> Line read.
816 * @throw <code>IOException</code>
818 public String
read_line()
821 StringBuffer sb
= new StringBuffer();
826 while ((c
!= -1) && (c
!= 10))
836 default: sb
.append((char)c
);
840 catch (IOException e
)
844 return(sb
.toString());
852 * Read up to <code>count</code> bytes from the input stream.
854 * @param <code>count</code> Number of bytes to read.
855 * @return <code>char[]</code> Character array of data read.
856 * @throw <code>IOException</code>
858 public char[] read(int count
)
861 char ac
[] = new char[count
];
865 for (int k
= is
.read(); k
!= -1 && j
< count
; k
= is
.read())
870 catch(IOException ioexception
)
879 * Process the HTTP response from the server.
881 * @return <code>IPP</code> IPP object containing response data.
882 * @see <code>IPP</code>
883 * @see <code>IPPRequest</code>
884 * @see <code>IPPAttribute</code>
885 * @see <code>IPPValue</code>
886 * @see <code>IPPDefs</code>
888 public IPP
processResponse()
891 IPPAttribute attr
; // temp attribute
892 IPPValue val
; // temp value
894 short vtag
; // Current value tag
895 short gtag
; // Current group tag
900 ipp
.request
= new IPPRequest();
902 int read_buffer_bytes
= read_buffer
.length
;
903 int read_buffer_remaining
= read_buffer_bytes
;
908 ipp
.current
= -1; // current attritue??
909 ipp
.last
= -1; // last attr?
911 buffer
= read_buffer
;
916 // ---------------------------------------------------------------
917 // State machine to process response.
919 ipp
.state
= IPPDefs
.IDLE
;
920 while ((ipp
.state
!= IPPDefs
.TAG_END
) &&
921 (read_buffer_remaining
> 0))
926 ipp
.state
++; /* Avoid common problem... */
929 // Get the request header...
931 case IPPDefs
.HEADER
:
932 if (read_buffer_remaining
< 8)
938 // Verify the major version number...
940 if (buffer
[0] != (char)1)
946 // Then copy the request header over...
948 ipp
.request
.version
[0] = buffer
[bufferidx
++];
949 ipp
.request
.version
[1] = buffer
[bufferidx
++];
950 ipp
.request
.op_status
= (short)((short)buffer
[bufferidx
] << 8) |
951 (short)buffer
[bufferidx
+1];
955 // Get the text version of the request status ....
957 ipp
.status
= new IPPStatus(ipp
.request
.op_status
);
959 ipp
.request
.request_id
= (int)((int)buffer
[bufferidx
] << 24) |
960 ((int)buffer
[bufferidx
+1] << 16) |
961 ((int)buffer
[bufferidx
+2] << 8) |
962 ((int)buffer
[bufferidx
+3]);
964 read_buffer_remaining
-= 8;
966 ipp
.state
= IPPDefs
.ATTRIBUTE
;
968 ipp
.current_tag
= IPPDefs
.TAG_ZERO
;
971 case IPPDefs
.ATTRIBUTE
:
972 while (read_buffer_remaining
> 0)
975 // Read the value tag first.
977 vtag
= (short)buffer
[bufferidx
++];
978 read_buffer_remaining
--;
979 if (vtag
== IPPDefs
.TAG_END
)
982 // No more attributes left...
984 ipp
.state
= IPPDefs
.DATA
;
987 ipp
.addAttribute(attr
);
992 else if (vtag
< IPPDefs
.TAG_UNSUPPORTED_VALUE
)
996 ipp
.addAttribute(attr
);
1000 // Group tag... Set the current group and continue...
1004 // If still the same group ....
1005 if (ipp
.current_tag
== gtag
)
1010 attr
= new IPPAttribute(IPPDefs
.TAG_ZERO
,IPPDefs
.TAG_ZERO
,"");
1011 ipp
.addAttribute(attr
);
1016 ipp
.current_tag
= gtag
;
1024 n
= ((int)buffer
[bufferidx
] << 8) | (int)buffer
[bufferidx
+1];
1026 read_buffer_remaining
-= 2;
1031 // Parse Error, can't add additional values to null attr
1037 // More values for current attribute...
1041 // Make sure we aren't adding a new value of a different
1045 if (attr
.value_tag
== IPPDefs
.TAG_STRING
||
1046 (attr
.value_tag
>= IPPDefs
.TAG_TEXTLANG
&&
1047 attr
.value_tag
<= IPPDefs
.TAG_MIMETYPE
))
1050 // String values can sometimes come across in different
1051 // forms; accept sets of differing values...
1053 if (vtag
!= IPPDefs
.TAG_STRING
&&
1054 (vtag
< IPPDefs
.TAG_TEXTLANG
|| vtag
> IPPDefs
.TAG_MIMETYPE
))
1057 else if (attr
.value_tag
!= vtag
)
1064 ipp
.addAttribute(attr
);
1071 StringBuffer s
= new StringBuffer();
1072 for (int i
=0; i
< n
; i
++)
1074 s
.append((char)buffer
[bufferidx
++]);
1075 read_buffer_remaining
--;
1077 attr
= new IPPAttribute( gtag
, vtag
, s
.toString() );
1079 n
= ((short)buffer
[bufferidx
] << 8) | (short)buffer
[bufferidx
+1];
1081 read_buffer_remaining
-= 2;
1085 case IPPDefs
.TAG_INTEGER
:
1086 case IPPDefs
.TAG_ENUM
:
1087 n
= (int)(((int)buffer
[bufferidx
] << 24) |
1088 ((int)buffer
[bufferidx
+1] << 16) |
1089 ((int)buffer
[bufferidx
+2] << 8) |
1090 ((int)buffer
[bufferidx
+3]));
1092 read_buffer_remaining
-= 4;
1093 attr
.addInteger( n
);
1096 case IPPDefs
.TAG_BOOLEAN
:
1097 if ((byte)buffer
[bufferidx
++] > 0)
1098 attr
.addBoolean(true);
1100 attr
.addBoolean(false);
1101 read_buffer_remaining
--;
1104 case IPPDefs
.TAG_TEXT
:
1105 case IPPDefs
.TAG_NAME
:
1106 case IPPDefs
.TAG_KEYWORD
:
1107 case IPPDefs
.TAG_STRING
:
1108 case IPPDefs
.TAG_URI
:
1109 case IPPDefs
.TAG_URISCHEME
:
1110 case IPPDefs
.TAG_CHARSET
:
1111 case IPPDefs
.TAG_LANGUAGE
:
1112 case IPPDefs
.TAG_MIMETYPE
:
1113 StringBuffer s
= new StringBuffer();
1114 for (int i
=0; i
< n
; i
++ )
1116 s
.append( (char)buffer
[bufferidx
++] );
1117 read_buffer_remaining
--;
1119 attr
.addString( "", s
.toString() );
1123 case IPPDefs
.TAG_DATE
:
1124 char db
[] = new char[11];
1125 for (int i
=0; i
< 11; i
++ )
1127 db
[i
] = (char)buffer
[bufferidx
++];
1128 read_buffer_remaining
--;
1134 case IPPDefs
.TAG_RESOLUTION
:
1135 if (read_buffer_remaining
< 9)
1140 x
= (int)(((int)buffer
[bufferidx
] & 0xff000000) << 24) |
1141 (((int)buffer
[bufferidx
+1] & 0x00ff0000) << 16) |
1142 (((int)buffer
[bufferidx
+2] & 0x0000ff00) << 8) |
1143 (((int)buffer
[bufferidx
+3] & 0x000000ff));
1145 read_buffer_remaining
-= 4;
1147 y
= (int)(((int)buffer
[bufferidx
] & 0xff000000) << 24) |
1148 (((int)buffer
[bufferidx
+1] & 0x00ff0000) << 16) |
1149 (((int)buffer
[bufferidx
+2] & 0x0000ff00) << 8) |
1150 (((int)buffer
[bufferidx
+3] & 0x000000ff));
1152 read_buffer_remaining
-= 4;
1154 u
= (byte)buffer
[bufferidx
++];
1155 read_buffer_remaining
--;
1156 attr
.addResolution( u
, x
, y
);
1159 case IPPDefs
.TAG_RANGE
:
1160 if (read_buffer_remaining
< 8)
1164 lower
= (int)(((int)buffer
[bufferidx
] & 0xff000000) << 24) |
1165 (((int)buffer
[bufferidx
+1] & 0x00ff0000) << 16) |
1166 (((int)buffer
[bufferidx
+2] & 0x0000ff00) << 8) |
1167 (((int)buffer
[bufferidx
+3] & 0x000000ff));
1169 read_buffer_remaining
-= 4;
1171 upper
= (int)(((int)buffer
[bufferidx
] & 0xff000000) << 24) |
1172 (((int)buffer
[bufferidx
+1] & 0x00ff0000) << 16) |
1173 (((int)buffer
[bufferidx
+2] & 0x0000ff00) << 8) |
1174 (((int)buffer
[bufferidx
+3] & 0x000000ff));
1176 read_buffer_remaining
-= 4;
1178 attr
.addRange( (short)lower
, (short)upper
);
1181 case IPPDefs
.TAG_TEXTLANG
:
1182 case IPPDefs
.TAG_NAMELANG
:
1184 // text-with-language and name-with-language are composite
1193 n
= ((int)buffer
[bufferidx
] << 8) | (int)buffer
[bufferidx
+1];
1196 StringBuffer cs
= new StringBuffer();
1197 for (int i
=0; i
< n
; i
++ )
1199 cs
.append( (char)buffer
[bufferidx
++] );
1200 read_buffer_remaining
--;
1203 n
= ((int)buffer
[bufferidx
] << 8) | (int)buffer
[bufferidx
+1];
1206 StringBuffer tx
= new StringBuffer();
1207 for (int i
=0; i
< n
; i
++ )
1209 tx
.append( (char)buffer
[bufferidx
++] );
1210 read_buffer_remaining
--;
1213 attr
.addString( cs
.toString(), tx
.toString() );
1217 default : /* Other unsupported values */
1221 read_buffer_remaining
-= n
;
1229 ipp
.addAttribute(attr
);
1238 break; /* anti-compiler-warning-code */
1247 // Parse a WWW-Authenticate: Digest request
1249 public void parseAuthenticate( String p_auth
)
1256 while (tmp
.length() > 0)
1259 while (tmp
.length() > 0 && (tmp
.charAt(i
) == ' ' || tmp
.charAt(i
) == '"'))
1260 tmp
= tmp
.substring(1);
1263 if (tmp
.startsWith("realm="))
1265 i
= "realm=".length();
1266 tmp
= tmp
.substring(i
);
1268 while ((i
< tmp
.length()) &&
1269 (tmp
.charAt(i
) == ' ' ||
1270 tmp
.charAt(i
) == '"' ||
1271 tmp
.charAt(i
) == '='))
1275 val
= new StringBuffer(1024);
1276 while (i
< tmp
.length() && tmp
.charAt(i
) != '"')
1277 val
.append(tmp
.charAt(i
++));
1278 realm
= val
.toString();
1279 tmp
= tmp
.substring(i
);
1281 else if (tmp
.startsWith("nonce="))
1283 i
= "nonce=".length();
1284 tmp
= tmp
.substring(i
);
1286 while ((i
< tmp
.length()) &&
1287 (tmp
.charAt(i
) == ' ' ||
1288 tmp
.charAt(i
) == '"' ||
1289 tmp
.charAt(i
) == '='))
1293 val
= new StringBuffer(1024);
1294 while (i
< tmp
.length() && tmp
.charAt(i
) != '"')
1295 val
.append(tmp
.charAt(i
++));
1296 nonce
= val
.toString();
1297 tmp
= tmp
.substring(i
);
1299 else if (tmp
.startsWith("opaque="))
1301 i
= "opaque=".length();
1302 tmp
= tmp
.substring(i
);
1304 while ((i
< tmp
.length()) &&
1305 (tmp
.charAt(i
) == ' ' ||
1306 tmp
.charAt(i
) == '"' ||
1307 tmp
.charAt(i
) == '='))
1311 val
= new StringBuffer(1024);
1312 while (i
< tmp
.length() && tmp
.charAt(i
) != '"')
1313 val
.append(tmp
.charAt(i
++));
1314 opaque
= val
.toString();
1315 tmp
= tmp
.substring(i
);
1319 StringBuffer name
= new StringBuffer(256);
1320 while ((i
< tmp
.length()) &&
1321 (tmp
.charAt(i
) != ' ' ||
1322 tmp
.charAt(i
) != '"' ||
1323 tmp
.charAt(i
) != '='))
1325 name
.append(tmp
.charAt(i
++));
1328 i
= name
.toString().length();
1329 tmp
= tmp
.substring(i
);
1331 while ((i
< tmp
.length()) &&
1332 (tmp
.charAt(i
) == ' ' ||
1333 tmp
.charAt(i
) == '"' ||
1334 tmp
.charAt(i
) == '='))
1338 val
= new StringBuffer(1024);
1339 while (i
< tmp
.length() && tmp
.charAt(i
) != '"')
1340 val
.append(tmp
.charAt(i
++));
1341 //junk = val.toString();
1342 tmp
= tmp
.substring(i
);
1351 } // End of IPPHttp class