4 * HTTP test program for CUPS.
6 * Copyright 2007-2013 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry.
23 * Include necessary headers...
26 #include "cups-private.h"
30 * Types and structures...
33 typedef struct uri_test_s
/**** URI test cases ****/
35 http_uri_status_t result
; /* Expected return value */
36 const char *uri
, /* URI */
37 *scheme
, /* Scheme string */
38 *username
, /* Username:password string */
39 *hostname
, /* Hostname string */
40 *resource
; /* Resource string */
41 int port
, /* Port number */
42 assemble_port
, /* Port number for httpAssembleURI() */
43 assemble_coding
;/* Coding for httpAssembleURI() */
51 static uri_test_t uri_tests
[] = /* URI test data */
53 /* Start with valid URIs */
54 { HTTP_URI_STATUS_OK
, "file:/filename",
55 "file", "", "", "/filename", 0, 0,
56 HTTP_URI_CODING_MOST
},
57 { HTTP_URI_STATUS_OK
, "file:/filename%20with%20spaces",
58 "file", "", "", "/filename with spaces", 0, 0,
59 HTTP_URI_CODING_MOST
},
60 { HTTP_URI_STATUS_OK
, "file:///filename",
61 "file", "", "", "/filename", 0, 0,
62 HTTP_URI_CODING_MOST
},
63 { HTTP_URI_STATUS_OK
, "file:///filename%20with%20spaces",
64 "file", "", "", "/filename with spaces", 0, 0,
65 HTTP_URI_CODING_MOST
},
66 { HTTP_URI_STATUS_OK
, "file://localhost/filename",
67 "file", "", "localhost", "/filename", 0, 0,
68 HTTP_URI_CODING_MOST
},
69 { HTTP_URI_STATUS_OK
, "file://localhost/filename%20with%20spaces",
70 "file", "", "localhost", "/filename with spaces", 0, 0,
71 HTTP_URI_CODING_MOST
},
72 { HTTP_URI_STATUS_OK
, "http://server/",
73 "http", "", "server", "/", 80, 0,
74 HTTP_URI_CODING_MOST
},
75 { HTTP_URI_STATUS_OK
, "http://username@server/",
76 "http", "username", "server", "/", 80, 0,
77 HTTP_URI_CODING_MOST
},
78 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server/",
79 "http", "username:password", "server", "/", 80, 0,
80 HTTP_URI_CODING_MOST
},
81 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server:8080/",
82 "http", "username:password", "server", "/", 8080, 8080,
83 HTTP_URI_CODING_MOST
},
84 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server:8080/directory/filename",
85 "http", "username:password", "server", "/directory/filename", 8080, 8080,
86 HTTP_URI_CODING_MOST
},
87 { HTTP_URI_STATUS_OK
, "http://[2000::10:100]:631/ipp",
88 "http", "", "2000::10:100", "/ipp", 631, 631,
89 HTTP_URI_CODING_MOST
},
90 { HTTP_URI_STATUS_OK
, "https://username:passwor%64@server/directory/filename",
91 "https", "username:password", "server", "/directory/filename", 443, 0,
92 HTTP_URI_CODING_MOST
},
93 { HTTP_URI_STATUS_OK
, "ipp://username:passwor%64@[::1]/ipp",
94 "ipp", "username:password", "::1", "/ipp", 631, 0,
95 HTTP_URI_CODING_MOST
},
96 { HTTP_URI_STATUS_OK
, "lpd://server/queue?reserve=yes",
97 "lpd", "", "server", "/queue?reserve=yes", 515, 0,
98 HTTP_URI_CODING_MOST
},
99 { HTTP_URI_STATUS_OK
, "mailto:user@domain.com",
100 "mailto", "", "", "user@domain.com", 0, 0,
101 HTTP_URI_CODING_MOST
},
102 { HTTP_URI_STATUS_OK
, "socket://server/",
103 "socket", "", "server", "/", 9100, 0,
104 HTTP_URI_CODING_MOST
},
105 { HTTP_URI_STATUS_OK
, "socket://192.168.1.1:9101/",
106 "socket", "", "192.168.1.1", "/", 9101, 9101,
107 HTTP_URI_CODING_MOST
},
108 { HTTP_URI_STATUS_OK
, "ipp://username:password@[v1.fe80::200:1234:5678:9abc+eth0]:999/ipp",
109 "ipp", "username:password", "fe80::200:1234:5678:9abc%eth0", "/ipp", 999, 999,
110 HTTP_URI_CODING_MOST
},
111 { HTTP_URI_STATUS_OK
, "ipp://username:password@[fe80::200:1234:5678:9abc%25eth0]:999/ipp",
112 "ipp", "username:password", "fe80::200:1234:5678:9abc%eth0", "/ipp", 999, 999,
113 HTTP_URI_CODING_MOST
| HTTP_URI_CODING_RFC6874
},
114 { HTTP_URI_STATUS_OK
, "http://server/admin?DEVICE_URI=usb://HP/Photosmart%25202600%2520series?serial=MY53OK70V10400",
115 "http", "", "server", "/admin?DEVICE_URI=usb://HP/Photosmart%25202600%2520series?serial=MY53OK70V10400", 80, 0,
116 HTTP_URI_CODING_MOST
},
117 { HTTP_URI_STATUS_OK
, "lpd://Acme%20Laser%20(01%3A23%3A45).local._tcp._printer/",
118 "lpd", "", "Acme Laser (01:23:45).local._tcp._printer", "/", 515, 0,
119 HTTP_URI_CODING_MOST
},
120 { HTTP_URI_STATUS_OK
, "ipp://HP%20Officejet%204500%20G510n-z%20%40%20Will's%20MacBook%20Pro%2015%22._ipp._tcp.local./",
121 "ipp", "", "HP Officejet 4500 G510n-z @ Will's MacBook Pro 15\"._ipp._tcp.local.", "/", 631, 0,
122 HTTP_URI_CODING_MOST
},
123 { HTTP_URI_STATUS_OK
, "ipp://%22%23%2F%3A%3C%3E%3F%40%5B%5C%5D%5E%60%7B%7C%7D/",
124 "ipp", "", "\"#/:<>?@[\\]^`{|}", "/", 631, 0,
125 HTTP_URI_CODING_MOST
},
128 { HTTP_URI_STATUS_MISSING_SCHEME
, "/path/to/file/index.html",
129 "file", "", "", "/path/to/file/index.html", 0, 0,
130 HTTP_URI_CODING_MOST
},
131 { HTTP_URI_STATUS_MISSING_SCHEME
, "//server/ipp",
132 "ipp", "", "server", "/ipp", 631, 0,
133 HTTP_URI_CODING_MOST
},
136 { HTTP_URI_STATUS_UNKNOWN_SCHEME
, "vendor://server/resource",
137 "vendor", "", "server", "/resource", 0, 0,
138 HTTP_URI_CODING_MOST
},
140 /* Missing resource */
141 { HTTP_URI_STATUS_MISSING_RESOURCE
, "socket://[::192.168.2.1]",
142 "socket", "", "::192.168.2.1", "/", 9100, 0,
143 HTTP_URI_CODING_MOST
},
144 { HTTP_URI_STATUS_MISSING_RESOURCE
, "socket://192.168.1.1:9101",
145 "socket", "", "192.168.1.1", "/", 9101, 0,
146 HTTP_URI_CODING_MOST
},
149 { HTTP_URI_STATUS_BAD_URI
, "",
150 "", "", "", "", 0, 0,
151 HTTP_URI_CODING_MOST
},
154 { HTTP_URI_STATUS_BAD_SCHEME
, "bad_scheme://server/resource",
155 "", "", "", "", 0, 0,
156 HTTP_URI_CODING_MOST
},
159 { HTTP_URI_STATUS_BAD_USERNAME
, "http://username:passwor%6@server/resource",
160 "http", "", "", "", 80, 0,
161 HTTP_URI_CODING_MOST
},
164 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://[/::1]/index.html",
165 "http", "", "", "", 80, 0,
166 HTTP_URI_CODING_MOST
},
167 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://[",
168 "http", "", "", "", 80, 0,
169 HTTP_URI_CODING_MOST
},
170 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://serve%7/index.html",
171 "http", "", "", "", 80, 0,
172 HTTP_URI_CODING_MOST
},
173 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://server with spaces/index.html",
174 "http", "", "", "", 80, 0,
175 HTTP_URI_CODING_MOST
},
176 { HTTP_URI_STATUS_BAD_HOSTNAME
, "ipp://\"#/:<>?@[\\]^`{|}/",
177 "ipp", "", "", "", 631, 0,
178 HTTP_URI_CODING_MOST
},
180 /* Bad port number */
181 { HTTP_URI_STATUS_BAD_PORT
, "http://127.0.0.1:9999a/index.html",
182 "http", "", "127.0.0.1", "", 0, 0,
183 HTTP_URI_CODING_MOST
},
186 { HTTP_URI_STATUS_BAD_RESOURCE
, "http://server/index.html%",
187 "http", "", "server", "", 80, 0,
188 HTTP_URI_CODING_MOST
},
189 { HTTP_URI_STATUS_BAD_RESOURCE
, "http://server/index with spaces.html",
190 "http", "", "server", "", 80, 0,
191 HTTP_URI_CODING_MOST
}
193 static const char * const base64_tests
[][2] =
198 /* 010000 010100 0010 */
200 /* 010000 010100 001001 000011 */
201 { "ABCD", "QUJDRA==" },
202 /* 010000 010100 001001 000011 010001 00 */
203 { "ABCDE", "QUJDREU=" },
204 /* 010000 010100 001001 000011 010001 000100 0101 */
205 { "ABCDEF", "QUJDREVG" },
206 /* 010000 010100 001001 000011 010001 000100 010101 000110 */
211 * 'main()' - Main entry.
214 int /* O - Exit status */
215 main(int argc
, /* I - Number of command-line arguments */
216 char *argv
[]) /* I - Command-line arguments */
218 int i
, j
, k
; /* Looping vars */
219 http_t
*http
; /* HTTP connection */
220 http_encryption_t encryption
; /* Encryption type */
221 http_status_t status
; /* Status of GET command */
222 int failures
; /* Number of test failures */
223 char buffer
[8192]; /* Input buffer */
224 long bytes
; /* Number of bytes read */
225 FILE *out
; /* Output file */
226 char encode
[256], /* Base64-encoded string */
227 decode
[256]; /* Base64-decoded string */
228 int decodelen
; /* Length of decoded string */
229 char scheme
[HTTP_MAX_URI
], /* Scheme from URI */
230 hostname
[HTTP_MAX_URI
], /* Hostname from URI */
231 username
[HTTP_MAX_URI
], /* Username:password from URI */
232 resource
[HTTP_MAX_URI
]; /* Resource from URI */
233 int port
; /* Port number from URI */
234 http_uri_status_t uri_status
; /* Status of URI separation */
235 http_addrlist_t
*addrlist
, /* Address list */
236 *addr
; /* Current address */
237 off_t length
, total
; /* Length and total bytes */
238 time_t start
, current
; /* Start and end time */
239 const char *encoding
; /* Negotiated Content-Encoding */
240 static const char * const uri_status_strings
[] =
242 "HTTP_URI_STATUS_OVERFLOW",
243 "HTTP_URI_STATUS_BAD_ARGUMENTS",
244 "HTTP_URI_STATUS_BAD_RESOURCE",
245 "HTTP_URI_STATUS_BAD_PORT",
246 "HTTP_URI_STATUS_BAD_HOSTNAME",
247 "HTTP_URI_STATUS_BAD_USERNAME",
248 "HTTP_URI_STATUS_BAD_SCHEME",
249 "HTTP_URI_STATUS_BAD_URI",
250 "HTTP_URI_STATUS_OK",
251 "HTTP_URI_STATUS_MISSING_SCHEME",
252 "HTTP_URI_STATUS_UNKNOWN_SCHEME",
253 "HTTP_URI_STATUS_MISSING_RESOURCE"
258 * Do API tests if we don't have a URL on the command-line...
266 * httpGetDateString()/httpGetDateTime()
269 fputs("httpGetDateString()/httpGetDateTime(): ", stdout
);
272 strlcpy(buffer
, httpGetDateString(start
), sizeof(buffer
));
273 current
= httpGetDateTime(buffer
);
275 i
= (int)(current
- start
);
285 printf(" Difference is %d seconds, %02d:%02d:%02d...\n", i
, i
/ 3600,
286 (i
/ 60) % 60, i
% 60);
287 printf(" httpGetDateString(%d) returned \"%s\"\n", (int)start
, buffer
);
288 printf(" httpGetDateTime(\"%s\") returned %d\n", buffer
, (int)current
);
289 printf(" httpGetDateString(%d) returned \"%s\"\n", (int)current
,
290 httpGetDateString(current
));
294 * httpDecode64_2()/httpEncode64_2()
297 fputs("httpDecode64_2()/httpEncode64_2(): ", stdout
);
299 for (i
= 0, j
= 0; i
< (int)(sizeof(base64_tests
) / sizeof(base64_tests
[0])); i
++)
301 httpEncode64_2(encode
, sizeof(encode
), base64_tests
[i
][0],
302 (int)strlen(base64_tests
[i
][0]));
303 decodelen
= (int)sizeof(decode
);
304 httpDecode64_2(decode
, &decodelen
, base64_tests
[i
][1]);
306 if (strcmp(decode
, base64_tests
[i
][0]))
316 printf(" httpDecode64_2() returned \"%s\", expected \"%s\"...\n",
317 decode
, base64_tests
[i
][0]);
320 if (strcmp(encode
, base64_tests
[i
][1]))
330 printf(" httpEncode64_2() returned \"%s\", expected \"%s\"...\n",
331 encode
, base64_tests
[i
][1]);
342 fputs("httpGetHostname(): ", stdout
);
344 if (httpGetHostname(NULL
, hostname
, sizeof(hostname
)))
345 printf("PASS (%s)\n", hostname
);
356 printf("httpAddrGetList(%s): ", hostname
);
358 addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, NULL
);
361 for (i
= 0, addr
= addrlist
; addr
; i
++, addr
= addr
->next
)
363 char numeric
[1024]; /* Numeric IP address */
366 httpAddrString(&(addr
->addr
), numeric
, sizeof(numeric
));
367 if (!strcmp(numeric
, "UNKNOWN"))
372 printf("FAIL (bad address for %s)\n", hostname
);
374 printf("PASS (%d address(es) for %s)\n", i
, hostname
);
376 httpAddrFreeList(addrlist
);
378 else if (isdigit(hostname
[0] & 255))
380 puts("FAIL (ignored because hostname is numeric)");
389 * Test httpSeparateURI()...
392 fputs("httpSeparateURI(): ", stdout
);
393 for (i
= 0, j
= 0; i
< (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0])); i
++)
395 uri_status
= httpSeparateURI(HTTP_URI_CODING_MOST
,
396 uri_tests
[i
].uri
, scheme
, sizeof(scheme
),
397 username
, sizeof(username
),
398 hostname
, sizeof(hostname
), &port
,
399 resource
, sizeof(resource
));
400 if (uri_status
!= uri_tests
[i
].result
||
401 strcmp(scheme
, uri_tests
[i
].scheme
) ||
402 strcmp(username
, uri_tests
[i
].username
) ||
403 strcmp(hostname
, uri_tests
[i
].hostname
) ||
404 port
!= uri_tests
[i
].port
||
405 strcmp(resource
, uri_tests
[i
].resource
))
415 printf(" \"%s\":\n", uri_tests
[i
].uri
);
417 if (uri_status
!= uri_tests
[i
].result
)
418 printf(" Returned %s instead of %s\n",
419 uri_status_strings
[uri_status
+ 8],
420 uri_status_strings
[uri_tests
[i
].result
+ 8]);
422 if (strcmp(scheme
, uri_tests
[i
].scheme
))
423 printf(" Scheme \"%s\" instead of \"%s\"\n",
424 scheme
, uri_tests
[i
].scheme
);
426 if (strcmp(username
, uri_tests
[i
].username
))
427 printf(" Username \"%s\" instead of \"%s\"\n",
428 username
, uri_tests
[i
].username
);
430 if (strcmp(hostname
, uri_tests
[i
].hostname
))
431 printf(" Hostname \"%s\" instead of \"%s\"\n",
432 hostname
, uri_tests
[i
].hostname
);
434 if (port
!= uri_tests
[i
].port
)
435 printf(" Port %d instead of %d\n",
436 port
, uri_tests
[i
].port
);
438 if (strcmp(resource
, uri_tests
[i
].resource
))
439 printf(" Resource \"%s\" instead of \"%s\"\n",
440 resource
, uri_tests
[i
].resource
);
445 printf("PASS (%d URIs tested)\n",
446 (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0])));
449 * Test httpAssembleURI()...
452 fputs("httpAssembleURI(): ", stdout
);
453 for (i
= 0, j
= 0, k
= 0;
454 i
< (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0]));
456 if (uri_tests
[i
].result
== HTTP_URI_STATUS_OK
&&
457 !strstr(uri_tests
[i
].uri
, "%64") &&
458 strstr(uri_tests
[i
].uri
, "//"))
461 uri_status
= httpAssembleURI(uri_tests
[i
].assemble_coding
,
462 buffer
, sizeof(buffer
),
464 uri_tests
[i
].username
,
465 uri_tests
[i
].hostname
,
466 uri_tests
[i
].assemble_port
,
467 uri_tests
[i
].resource
);
469 if (uri_status
!= HTTP_URI_STATUS_OK
)
479 printf(" \"%s\": %s\n", uri_tests
[i
].uri
,
480 uri_status_strings
[uri_status
+ 8]);
482 else if (strcmp(buffer
, uri_tests
[i
].uri
))
492 printf(" \"%s\": assembled = \"%s\"\n", uri_tests
[i
].uri
,
498 printf("PASS (%d URIs tested)\n", k
);
504 fputs("httpAssembleUUID: ", stdout
);
505 httpAssembleUUID("hostname.example.com", 631, "printer", 12345, buffer
,
507 if (strncmp(buffer
, "urn:uuid:", 9))
509 printf("FAIL (%s)\n", buffer
);
513 printf("PASS (%s)\n", buffer
);
516 * Show a summary and return...
520 printf("\n%d TESTS FAILED!\n", failures
);
522 puts("\nALL TESTS PASSED!");
526 else if (strstr(argv
[1], "._tcp"))
529 * Test resolving an mDNS name.
532 char resolved
[1024]; /* Resolved URI */
535 printf("_httpResolveURI(%s, _HTTP_RESOLVE_DEFAULT): ", argv
[1]);
538 if (!_httpResolveURI(argv
[1], resolved
, sizeof(resolved
),
539 _HTTP_RESOLVE_DEFAULT
, NULL
, NULL
))
545 printf("PASS (%s)\n", resolved
);
547 printf("_httpResolveURI(%s, _HTTP_RESOLVE_FQDN): ", argv
[1]);
550 if (!_httpResolveURI(argv
[1], resolved
, sizeof(resolved
),
551 _HTTP_RESOLVE_FQDN
, NULL
, NULL
))
556 else if (strstr(resolved
, ".local:"))
558 printf("FAIL (%s)\n", resolved
);
563 printf("PASS (%s)\n", resolved
);
567 else if (!strcmp(argv
[1], "-u") && argc
== 3)
570 * Test URI separation...
573 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
, argv
[2], scheme
,
574 sizeof(scheme
), username
, sizeof(username
),
575 hostname
, sizeof(hostname
), &port
,
576 resource
, sizeof(resource
));
577 printf("uri_status = %s\n", uri_status_strings
[uri_status
+ 8]);
578 printf("scheme = \"%s\"\n", scheme
);
579 printf("username = \"%s\"\n", username
);
580 printf("hostname = \"%s\"\n", hostname
);
581 printf("port = %d\n", port
);
582 printf("resource = \"%s\"\n", resource
);
588 * Test HTTP GET requests...
594 for (i
= 1; i
< argc
; i
++)
596 if (!strcmp(argv
[i
], "-o"))
602 out
= fopen(argv
[i
], "wb");
606 httpSeparateURI(HTTP_URI_CODING_MOST
, argv
[i
], scheme
, sizeof(scheme
),
607 username
, sizeof(username
),
608 hostname
, sizeof(hostname
), &port
,
609 resource
, sizeof(resource
));
611 if (!_cups_strcasecmp(scheme
, "https") || !_cups_strcasecmp(scheme
, "ipps") ||
613 encryption
= HTTP_ENCRYPTION_ALWAYS
;
615 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
617 http
= httpConnect2(hostname
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000,
624 printf("Checking file \"%s\"...\n", resource
);
628 if (!_cups_strcasecmp(httpGetField(http
, HTTP_FIELD_CONNECTION
), "close"))
630 httpClearFields(http
);
631 if (httpReconnect2(http
, 30000, NULL
))
633 status
= HTTP_STATUS_ERROR
;
638 httpClearFields(http
);
639 httpSetField(http
, HTTP_FIELD_AUTHORIZATION
, httpGetAuthString(http
));
640 httpSetField(http
, HTTP_FIELD_ACCEPT_LANGUAGE
, "en");
641 if (httpHead(http
, resource
))
643 if (httpReconnect2(http
, 30000, NULL
))
645 status
= HTTP_STATUS_ERROR
;
650 status
= HTTP_STATUS_UNAUTHORIZED
;
655 while ((status
= httpUpdate(http
)) == HTTP_STATUS_CONTINUE
);
657 if (status
== HTTP_STATUS_UNAUTHORIZED
)
660 * Flush any error message...
666 * See if we can do authentication...
669 if (cupsDoAuthentication(http
, "GET", resource
))
671 status
= HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
;
675 if (httpReconnect2(http
, 30000, NULL
))
677 status
= HTTP_STATUS_ERROR
;
684 else if (status
== HTTP_STATUS_UPGRADE_REQUIRED
)
686 /* Flush any error message... */
690 if (httpReconnect2(http
, 30000, NULL
))
692 status
= HTTP_STATUS_ERROR
;
696 /* Upgrade with encryption... */
697 httpEncryption(http
, HTTP_ENCRYPTION_REQUIRED
);
699 /* Try again, this time with encryption enabled... */
702 #endif /* HAVE_SSL */
704 while (status
== HTTP_STATUS_UNAUTHORIZED
||
705 status
== HTTP_STATUS_UPGRADE_REQUIRED
);
707 if (status
== HTTP_STATUS_OK
)
710 printf("HEAD failed with status %d...\n", status
);
712 encoding
= httpGetContentEncoding(http
);
714 printf("Requesting file \"%s\" (Accept-Encoding: %s)...\n", resource
,
715 encoding
? encoding
: "identity");
719 if (!_cups_strcasecmp(httpGetField(http
, HTTP_FIELD_CONNECTION
), "close"))
721 httpClearFields(http
);
722 if (httpReconnect2(http
, 30000, NULL
))
724 status
= HTTP_STATUS_ERROR
;
729 httpClearFields(http
);
730 httpSetField(http
, HTTP_FIELD_AUTHORIZATION
, httpGetAuthString(http
));
731 httpSetField(http
, HTTP_FIELD_ACCEPT_LANGUAGE
, "en");
732 httpSetField(http
, HTTP_FIELD_ACCEPT_ENCODING
, encoding
);
734 if (httpGet(http
, resource
))
736 if (httpReconnect2(http
, 30000, NULL
))
738 status
= HTTP_STATUS_ERROR
;
743 status
= HTTP_STATUS_UNAUTHORIZED
;
748 while ((status
= httpUpdate(http
)) == HTTP_STATUS_CONTINUE
);
750 if (status
== HTTP_STATUS_UNAUTHORIZED
)
753 * Flush any error message...
759 * See if we can do authentication...
762 if (cupsDoAuthentication(http
, "GET", resource
))
764 status
= HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
;
768 if (httpReconnect2(http
, 30000, NULL
))
770 status
= HTTP_STATUS_ERROR
;
777 else if (status
== HTTP_STATUS_UPGRADE_REQUIRED
)
779 /* Flush any error message... */
783 if (httpReconnect2(http
, 30000, NULL
))
785 status
= HTTP_STATUS_ERROR
;
789 /* Upgrade with encryption... */
790 httpEncryption(http
, HTTP_ENCRYPTION_REQUIRED
);
792 /* Try again, this time with encryption enabled... */
795 #endif /* HAVE_SSL */
797 while (status
== HTTP_STATUS_UNAUTHORIZED
|| status
== HTTP_STATUS_UPGRADE_REQUIRED
);
799 if (status
== HTTP_STATUS_OK
)
802 printf("GET failed with status %d...\n", status
);
805 length
= httpGetLength2(http
);
808 while ((bytes
= httpRead2(http
, buffer
, sizeof(buffer
))) > 0)
811 fwrite(buffer
, bytes
, 1, out
);
814 current
= time(NULL
);
815 if (current
== start
) current
++;
816 printf("\r" CUPS_LLFMT
"/" CUPS_LLFMT
" bytes ("
817 CUPS_LLFMT
" bytes/sec) ", CUPS_LLCAST total
,
818 CUPS_LLCAST length
, CUPS_LLCAST (total
/ (current
- start
)));
824 puts("Closing connection to server...");