2 * "$Id: testhttp.c 11445 2013-12-05 19:57:43Z msweet $"
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 * Include necessary headers...
22 #include "cups-private.h"
26 * Types and structures...
29 typedef struct uri_test_s
/**** URI test cases ****/
31 http_uri_status_t result
; /* Expected return value */
32 const char *uri
, /* URI */
33 *scheme
, /* Scheme string */
34 *username
, /* Username:password string */
35 *hostname
, /* Hostname string */
36 *resource
; /* Resource string */
37 int port
, /* Port number */
38 assemble_port
, /* Port number for httpAssembleURI() */
39 assemble_coding
;/* Coding for httpAssembleURI() */
47 static uri_test_t uri_tests
[] = /* URI test data */
49 /* Start with valid URIs */
50 { HTTP_URI_STATUS_OK
, "file:/filename",
51 "file", "", "", "/filename", 0, 0,
52 HTTP_URI_CODING_MOST
},
53 { HTTP_URI_STATUS_OK
, "file:/filename%20with%20spaces",
54 "file", "", "", "/filename with spaces", 0, 0,
55 HTTP_URI_CODING_MOST
},
56 { HTTP_URI_STATUS_OK
, "file:///filename",
57 "file", "", "", "/filename", 0, 0,
58 HTTP_URI_CODING_MOST
},
59 { HTTP_URI_STATUS_OK
, "file:///filename%20with%20spaces",
60 "file", "", "", "/filename with spaces", 0, 0,
61 HTTP_URI_CODING_MOST
},
62 { HTTP_URI_STATUS_OK
, "file://localhost/filename",
63 "file", "", "localhost", "/filename", 0, 0,
64 HTTP_URI_CODING_MOST
},
65 { HTTP_URI_STATUS_OK
, "file://localhost/filename%20with%20spaces",
66 "file", "", "localhost", "/filename with spaces", 0, 0,
67 HTTP_URI_CODING_MOST
},
68 { HTTP_URI_STATUS_OK
, "http://server/",
69 "http", "", "server", "/", 80, 0,
70 HTTP_URI_CODING_MOST
},
71 { HTTP_URI_STATUS_OK
, "http://username@server/",
72 "http", "username", "server", "/", 80, 0,
73 HTTP_URI_CODING_MOST
},
74 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server/",
75 "http", "username:password", "server", "/", 80, 0,
76 HTTP_URI_CODING_MOST
},
77 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server:8080/",
78 "http", "username:password", "server", "/", 8080, 8080,
79 HTTP_URI_CODING_MOST
},
80 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server:8080/directory/filename",
81 "http", "username:password", "server", "/directory/filename", 8080, 8080,
82 HTTP_URI_CODING_MOST
},
83 { HTTP_URI_STATUS_OK
, "http://[2000::10:100]:631/ipp",
84 "http", "", "2000::10:100", "/ipp", 631, 631,
85 HTTP_URI_CODING_MOST
},
86 { HTTP_URI_STATUS_OK
, "https://username:passwor%64@server/directory/filename",
87 "https", "username:password", "server", "/directory/filename", 443, 0,
88 HTTP_URI_CODING_MOST
},
89 { HTTP_URI_STATUS_OK
, "ipp://username:passwor%64@[::1]/ipp",
90 "ipp", "username:password", "::1", "/ipp", 631, 0,
91 HTTP_URI_CODING_MOST
},
92 { HTTP_URI_STATUS_OK
, "lpd://server/queue?reserve=yes",
93 "lpd", "", "server", "/queue?reserve=yes", 515, 0,
94 HTTP_URI_CODING_MOST
},
95 { HTTP_URI_STATUS_OK
, "mailto:user@domain.com",
96 "mailto", "", "", "user@domain.com", 0, 0,
97 HTTP_URI_CODING_MOST
},
98 { HTTP_URI_STATUS_OK
, "socket://server/",
99 "socket", "", "server", "/", 9100, 0,
100 HTTP_URI_CODING_MOST
},
101 { HTTP_URI_STATUS_OK
, "socket://192.168.1.1:9101/",
102 "socket", "", "192.168.1.1", "/", 9101, 9101,
103 HTTP_URI_CODING_MOST
},
104 { HTTP_URI_STATUS_OK
, "tel:8005551212",
105 "tel", "", "", "8005551212", 0, 0,
106 HTTP_URI_CODING_MOST
},
107 { HTTP_URI_STATUS_OK
, "ipp://username:password@[v1.fe80::200:1234:5678:9abc+eth0]:999/ipp",
108 "ipp", "username:password", "fe80::200:1234:5678:9abc%eth0", "/ipp", 999, 999,
109 HTTP_URI_CODING_MOST
},
110 { HTTP_URI_STATUS_OK
, "ipp://username:password@[fe80::200:1234:5678:9abc%25eth0]:999/ipp",
111 "ipp", "username:password", "fe80::200:1234:5678:9abc%eth0", "/ipp", 999, 999,
112 HTTP_URI_CODING_MOST
| HTTP_URI_CODING_RFC6874
},
113 { HTTP_URI_STATUS_OK
, "http://server/admin?DEVICE_URI=usb://HP/Photosmart%25202600%2520series?serial=MY53OK70V10400",
114 "http", "", "server", "/admin?DEVICE_URI=usb://HP/Photosmart%25202600%2520series?serial=MY53OK70V10400", 80, 0,
115 HTTP_URI_CODING_MOST
},
116 { HTTP_URI_STATUS_OK
, "lpd://Acme%20Laser%20(01%3A23%3A45).local._tcp._printer/",
117 "lpd", "", "Acme Laser (01:23:45).local._tcp._printer", "/", 515, 0,
118 HTTP_URI_CODING_MOST
},
119 { HTTP_URI_STATUS_OK
, "ipp://HP%20Officejet%204500%20G510n-z%20%40%20Will's%20MacBook%20Pro%2015%22._ipp._tcp.local./",
120 "ipp", "", "HP Officejet 4500 G510n-z @ Will's MacBook Pro 15\"._ipp._tcp.local.", "/", 631, 0,
121 HTTP_URI_CODING_MOST
},
122 { HTTP_URI_STATUS_OK
, "ipp://%22%23%2F%3A%3C%3E%3F%40%5B%5C%5D%5E%60%7B%7C%7D/",
123 "ipp", "", "\"#/:<>?@[\\]^`{|}", "/", 631, 0,
124 HTTP_URI_CODING_MOST
},
127 { HTTP_URI_STATUS_MISSING_SCHEME
, "/path/to/file/index.html",
128 "file", "", "", "/path/to/file/index.html", 0, 0,
129 HTTP_URI_CODING_MOST
},
130 { HTTP_URI_STATUS_MISSING_SCHEME
, "//server/ipp",
131 "ipp", "", "server", "/ipp", 631, 0,
132 HTTP_URI_CODING_MOST
},
135 { HTTP_URI_STATUS_UNKNOWN_SCHEME
, "vendor://server/resource",
136 "vendor", "", "server", "/resource", 0, 0,
137 HTTP_URI_CODING_MOST
},
139 /* Missing resource */
140 { HTTP_URI_STATUS_MISSING_RESOURCE
, "socket://[::192.168.2.1]",
141 "socket", "", "::192.168.2.1", "/", 9100, 0,
142 HTTP_URI_CODING_MOST
},
143 { HTTP_URI_STATUS_MISSING_RESOURCE
, "socket://192.168.1.1:9101",
144 "socket", "", "192.168.1.1", "/", 9101, 0,
145 HTTP_URI_CODING_MOST
},
148 { HTTP_URI_STATUS_BAD_URI
, "",
149 "", "", "", "", 0, 0,
150 HTTP_URI_CODING_MOST
},
153 { HTTP_URI_STATUS_BAD_SCHEME
, "bad_scheme://server/resource",
154 "", "", "", "", 0, 0,
155 HTTP_URI_CODING_MOST
},
158 { HTTP_URI_STATUS_BAD_USERNAME
, "http://username:passwor%6@server/resource",
159 "http", "", "", "", 80, 0,
160 HTTP_URI_CODING_MOST
},
163 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://[/::1]/index.html",
164 "http", "", "", "", 80, 0,
165 HTTP_URI_CODING_MOST
},
166 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://[",
167 "http", "", "", "", 80, 0,
168 HTTP_URI_CODING_MOST
},
169 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://serve%7/index.html",
170 "http", "", "", "", 80, 0,
171 HTTP_URI_CODING_MOST
},
172 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://server with spaces/index.html",
173 "http", "", "", "", 80, 0,
174 HTTP_URI_CODING_MOST
},
175 { HTTP_URI_STATUS_BAD_HOSTNAME
, "ipp://\"#/:<>?@[\\]^`{|}/",
176 "ipp", "", "", "", 631, 0,
177 HTTP_URI_CODING_MOST
},
179 /* Bad port number */
180 { HTTP_URI_STATUS_BAD_PORT
, "http://127.0.0.1:9999a/index.html",
181 "http", "", "127.0.0.1", "", 0, 0,
182 HTTP_URI_CODING_MOST
},
185 { HTTP_URI_STATUS_BAD_RESOURCE
, "http://server/index.html%",
186 "http", "", "server", "", 80, 0,
187 HTTP_URI_CODING_MOST
},
188 { HTTP_URI_STATUS_BAD_RESOURCE
, "http://server/index with spaces.html",
189 "http", "", "server", "", 80, 0,
190 HTTP_URI_CODING_MOST
}
192 static const char * const base64_tests
[][2] =
197 /* 010000 010100 0010 */
199 /* 010000 010100 001001 000011 */
200 { "ABCD", "QUJDRA==" },
201 /* 010000 010100 001001 000011 010001 00 */
202 { "ABCDE", "QUJDREU=" },
203 /* 010000 010100 001001 000011 010001 000100 0101 */
204 { "ABCDEF", "QUJDREVG" },
205 /* 010000 010100 001001 000011 010001 000100 010101 000110 */
210 * 'main()' - Main entry.
213 int /* O - Exit status */
214 main(int argc
, /* I - Number of command-line arguments */
215 char *argv
[]) /* I - Command-line arguments */
217 int i
, j
, k
; /* Looping vars */
218 http_t
*http
; /* HTTP connection */
219 http_encryption_t encryption
; /* Encryption type */
220 http_status_t status
; /* Status of GET command */
221 int failures
; /* Number of test failures */
222 char buffer
[8192]; /* Input buffer */
223 long bytes
; /* Number of bytes read */
224 FILE *out
; /* Output file */
225 char encode
[256], /* Base64-encoded string */
226 decode
[256]; /* Base64-decoded string */
227 int decodelen
; /* Length of decoded string */
228 char scheme
[HTTP_MAX_URI
], /* Scheme from URI */
229 hostname
[HTTP_MAX_URI
], /* Hostname from URI */
230 username
[HTTP_MAX_URI
], /* Username:password from URI */
231 resource
[HTTP_MAX_URI
]; /* Resource from URI */
232 int port
; /* Port number from URI */
233 http_uri_status_t uri_status
; /* Status of URI separation */
234 http_addrlist_t
*addrlist
, /* Address list */
235 *addr
; /* Current address */
236 off_t length
, total
; /* Length and total bytes */
237 time_t start
, current
; /* Start and end time */
238 const char *encoding
; /* Negotiated Content-Encoding */
239 static const char * const uri_status_strings
[] =
241 "HTTP_URI_STATUS_OVERFLOW",
242 "HTTP_URI_STATUS_BAD_ARGUMENTS",
243 "HTTP_URI_STATUS_BAD_RESOURCE",
244 "HTTP_URI_STATUS_BAD_PORT",
245 "HTTP_URI_STATUS_BAD_HOSTNAME",
246 "HTTP_URI_STATUS_BAD_USERNAME",
247 "HTTP_URI_STATUS_BAD_SCHEME",
248 "HTTP_URI_STATUS_BAD_URI",
249 "HTTP_URI_STATUS_OK",
250 "HTTP_URI_STATUS_MISSING_SCHEME",
251 "HTTP_URI_STATUS_UNKNOWN_SCHEME",
252 "HTTP_URI_STATUS_MISSING_RESOURCE"
257 * Do API tests if we don't have a URL on the command-line...
265 * httpGetDateString()/httpGetDateTime()
268 fputs("httpGetDateString()/httpGetDateTime(): ", stdout
);
271 strlcpy(buffer
, httpGetDateString(start
), sizeof(buffer
));
272 current
= httpGetDateTime(buffer
);
274 i
= (int)(current
- start
);
284 printf(" Difference is %d seconds, %02d:%02d:%02d...\n", i
, i
/ 3600,
285 (i
/ 60) % 60, i
% 60);
286 printf(" httpGetDateString(%d) returned \"%s\"\n", (int)start
, buffer
);
287 printf(" httpGetDateTime(\"%s\") returned %d\n", buffer
, (int)current
);
288 printf(" httpGetDateString(%d) returned \"%s\"\n", (int)current
,
289 httpGetDateString(current
));
293 * httpDecode64_2()/httpEncode64_2()
296 fputs("httpDecode64_2()/httpEncode64_2(): ", stdout
);
298 for (i
= 0, j
= 0; i
< (int)(sizeof(base64_tests
) / sizeof(base64_tests
[0])); i
++)
300 httpEncode64_2(encode
, sizeof(encode
), base64_tests
[i
][0],
301 (int)strlen(base64_tests
[i
][0]));
302 decodelen
= (int)sizeof(decode
);
303 httpDecode64_2(decode
, &decodelen
, base64_tests
[i
][1]);
305 if (strcmp(decode
, base64_tests
[i
][0]))
315 printf(" httpDecode64_2() returned \"%s\", expected \"%s\"...\n",
316 decode
, base64_tests
[i
][0]);
319 if (strcmp(encode
, base64_tests
[i
][1]))
329 printf(" httpEncode64_2() returned \"%s\", expected \"%s\"...\n",
330 encode
, base64_tests
[i
][1]);
341 fputs("httpGetHostname(): ", stdout
);
343 if (httpGetHostname(NULL
, hostname
, sizeof(hostname
)))
344 printf("PASS (%s)\n", hostname
);
355 printf("httpAddrGetList(%s): ", hostname
);
357 addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, NULL
);
360 for (i
= 0, addr
= addrlist
; addr
; i
++, addr
= addr
->next
)
362 char numeric
[1024]; /* Numeric IP address */
365 httpAddrString(&(addr
->addr
), numeric
, sizeof(numeric
));
366 if (!strcmp(numeric
, "UNKNOWN"))
371 printf("FAIL (bad address for %s)\n", hostname
);
373 printf("PASS (%d address(es) for %s)\n", i
, hostname
);
375 httpAddrFreeList(addrlist
);
377 else if (isdigit(hostname
[0] & 255))
379 puts("FAIL (ignored because hostname is numeric)");
388 * Test httpSeparateURI()...
391 fputs("httpSeparateURI(): ", stdout
);
392 for (i
= 0, j
= 0; i
< (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0])); i
++)
394 uri_status
= httpSeparateURI(HTTP_URI_CODING_MOST
,
395 uri_tests
[i
].uri
, scheme
, sizeof(scheme
),
396 username
, sizeof(username
),
397 hostname
, sizeof(hostname
), &port
,
398 resource
, sizeof(resource
));
399 if (uri_status
!= uri_tests
[i
].result
||
400 strcmp(scheme
, uri_tests
[i
].scheme
) ||
401 strcmp(username
, uri_tests
[i
].username
) ||
402 strcmp(hostname
, uri_tests
[i
].hostname
) ||
403 port
!= uri_tests
[i
].port
||
404 strcmp(resource
, uri_tests
[i
].resource
))
414 printf(" \"%s\":\n", uri_tests
[i
].uri
);
416 if (uri_status
!= uri_tests
[i
].result
)
417 printf(" Returned %s instead of %s\n",
418 uri_status_strings
[uri_status
+ 8],
419 uri_status_strings
[uri_tests
[i
].result
+ 8]);
421 if (strcmp(scheme
, uri_tests
[i
].scheme
))
422 printf(" Scheme \"%s\" instead of \"%s\"\n",
423 scheme
, uri_tests
[i
].scheme
);
425 if (strcmp(username
, uri_tests
[i
].username
))
426 printf(" Username \"%s\" instead of \"%s\"\n",
427 username
, uri_tests
[i
].username
);
429 if (strcmp(hostname
, uri_tests
[i
].hostname
))
430 printf(" Hostname \"%s\" instead of \"%s\"\n",
431 hostname
, uri_tests
[i
].hostname
);
433 if (port
!= uri_tests
[i
].port
)
434 printf(" Port %d instead of %d\n",
435 port
, uri_tests
[i
].port
);
437 if (strcmp(resource
, uri_tests
[i
].resource
))
438 printf(" Resource \"%s\" instead of \"%s\"\n",
439 resource
, uri_tests
[i
].resource
);
444 printf("PASS (%d URIs tested)\n",
445 (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0])));
448 * Test httpAssembleURI()...
451 fputs("httpAssembleURI(): ", stdout
);
452 for (i
= 0, j
= 0, k
= 0;
453 i
< (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0]));
455 if (uri_tests
[i
].result
== HTTP_URI_STATUS_OK
&&
456 !strstr(uri_tests
[i
].uri
, "%64") &&
457 strstr(uri_tests
[i
].uri
, "//"))
460 uri_status
= httpAssembleURI(uri_tests
[i
].assemble_coding
,
461 buffer
, sizeof(buffer
),
463 uri_tests
[i
].username
,
464 uri_tests
[i
].hostname
,
465 uri_tests
[i
].assemble_port
,
466 uri_tests
[i
].resource
);
468 if (uri_status
!= HTTP_URI_STATUS_OK
)
478 printf(" \"%s\": %s\n", uri_tests
[i
].uri
,
479 uri_status_strings
[uri_status
+ 8]);
481 else if (strcmp(buffer
, uri_tests
[i
].uri
))
491 printf(" \"%s\": assembled = \"%s\"\n", uri_tests
[i
].uri
,
497 printf("PASS (%d URIs tested)\n", k
);
503 fputs("httpAssembleUUID: ", stdout
);
504 httpAssembleUUID("hostname.example.com", 631, "printer", 12345, buffer
,
506 if (strncmp(buffer
, "urn:uuid:", 9))
508 printf("FAIL (%s)\n", buffer
);
512 printf("PASS (%s)\n", buffer
);
515 * Show a summary and return...
519 printf("\n%d TESTS FAILED!\n", failures
);
521 puts("\nALL TESTS PASSED!");
525 else if (strstr(argv
[1], "._tcp"))
528 * Test resolving an mDNS name.
531 char resolved
[1024]; /* Resolved URI */
534 printf("_httpResolveURI(%s, _HTTP_RESOLVE_DEFAULT): ", argv
[1]);
537 if (!_httpResolveURI(argv
[1], resolved
, sizeof(resolved
),
538 _HTTP_RESOLVE_DEFAULT
, NULL
, NULL
))
544 printf("PASS (%s)\n", resolved
);
546 printf("_httpResolveURI(%s, _HTTP_RESOLVE_FQDN): ", argv
[1]);
549 if (!_httpResolveURI(argv
[1], resolved
, sizeof(resolved
),
550 _HTTP_RESOLVE_FQDN
, NULL
, NULL
))
555 else if (strstr(resolved
, ".local:"))
557 printf("FAIL (%s)\n", resolved
);
562 printf("PASS (%s)\n", resolved
);
566 else if (!strcmp(argv
[1], "-u") && argc
== 3)
569 * Test URI separation...
572 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
, argv
[2], scheme
,
573 sizeof(scheme
), username
, sizeof(username
),
574 hostname
, sizeof(hostname
), &port
,
575 resource
, sizeof(resource
));
576 printf("uri_status = %s\n", uri_status_strings
[uri_status
+ 8]);
577 printf("scheme = \"%s\"\n", scheme
);
578 printf("username = \"%s\"\n", username
);
579 printf("hostname = \"%s\"\n", hostname
);
580 printf("port = %d\n", port
);
581 printf("resource = \"%s\"\n", resource
);
587 * Test HTTP GET requests...
593 for (i
= 1; i
< argc
; i
++)
595 if (!strcmp(argv
[i
], "-o"))
601 out
= fopen(argv
[i
], "wb");
605 httpSeparateURI(HTTP_URI_CODING_MOST
, argv
[i
], scheme
, sizeof(scheme
),
606 username
, sizeof(username
),
607 hostname
, sizeof(hostname
), &port
,
608 resource
, sizeof(resource
));
610 if (!_cups_strcasecmp(scheme
, "https") || !_cups_strcasecmp(scheme
, "ipps") ||
612 encryption
= HTTP_ENCRYPTION_ALWAYS
;
614 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
616 http
= httpConnect2(hostname
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000,
623 printf("Checking file \"%s\"...\n", resource
);
627 if (!_cups_strcasecmp(httpGetField(http
, HTTP_FIELD_CONNECTION
), "close"))
629 httpClearFields(http
);
630 if (httpReconnect2(http
, 30000, NULL
))
632 status
= HTTP_STATUS_ERROR
;
637 httpClearFields(http
);
638 httpSetField(http
, HTTP_FIELD_AUTHORIZATION
, httpGetAuthString(http
));
639 httpSetField(http
, HTTP_FIELD_ACCEPT_LANGUAGE
, "en");
640 if (httpHead(http
, resource
))
642 if (httpReconnect2(http
, 30000, NULL
))
644 status
= HTTP_STATUS_ERROR
;
649 status
= HTTP_STATUS_UNAUTHORIZED
;
654 while ((status
= httpUpdate(http
)) == HTTP_STATUS_CONTINUE
);
656 if (status
== HTTP_STATUS_UNAUTHORIZED
)
659 * Flush any error message...
665 * See if we can do authentication...
668 if (cupsDoAuthentication(http
, "GET", resource
))
670 status
= HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
;
674 if (httpReconnect2(http
, 30000, NULL
))
676 status
= HTTP_STATUS_ERROR
;
683 else if (status
== HTTP_STATUS_UPGRADE_REQUIRED
)
685 /* Flush any error message... */
689 if (httpReconnect2(http
, 30000, NULL
))
691 status
= HTTP_STATUS_ERROR
;
695 /* Upgrade with encryption... */
696 httpEncryption(http
, HTTP_ENCRYPTION_REQUIRED
);
698 /* Try again, this time with encryption enabled... */
701 #endif /* HAVE_SSL */
703 while (status
== HTTP_STATUS_UNAUTHORIZED
||
704 status
== HTTP_STATUS_UPGRADE_REQUIRED
);
706 if (status
== HTTP_STATUS_OK
)
709 printf("HEAD failed with status %d...\n", status
);
711 encoding
= httpGetContentEncoding(http
);
713 printf("Requesting file \"%s\" (Accept-Encoding: %s)...\n", resource
,
714 encoding
? encoding
: "identity");
718 if (!_cups_strcasecmp(httpGetField(http
, HTTP_FIELD_CONNECTION
), "close"))
720 httpClearFields(http
);
721 if (httpReconnect2(http
, 30000, NULL
))
723 status
= HTTP_STATUS_ERROR
;
728 httpClearFields(http
);
729 httpSetField(http
, HTTP_FIELD_AUTHORIZATION
, httpGetAuthString(http
));
730 httpSetField(http
, HTTP_FIELD_ACCEPT_LANGUAGE
, "en");
731 httpSetField(http
, HTTP_FIELD_ACCEPT_ENCODING
, encoding
);
733 if (httpGet(http
, resource
))
735 if (httpReconnect2(http
, 30000, NULL
))
737 status
= HTTP_STATUS_ERROR
;
742 status
= HTTP_STATUS_UNAUTHORIZED
;
747 while ((status
= httpUpdate(http
)) == HTTP_STATUS_CONTINUE
);
749 if (status
== HTTP_STATUS_UNAUTHORIZED
)
752 * Flush any error message...
758 * See if we can do authentication...
761 if (cupsDoAuthentication(http
, "GET", resource
))
763 status
= HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
;
767 if (httpReconnect2(http
, 30000, NULL
))
769 status
= HTTP_STATUS_ERROR
;
776 else if (status
== HTTP_STATUS_UPGRADE_REQUIRED
)
778 /* Flush any error message... */
782 if (httpReconnect2(http
, 30000, NULL
))
784 status
= HTTP_STATUS_ERROR
;
788 /* Upgrade with encryption... */
789 httpEncryption(http
, HTTP_ENCRYPTION_REQUIRED
);
791 /* Try again, this time with encryption enabled... */
794 #endif /* HAVE_SSL */
796 while (status
== HTTP_STATUS_UNAUTHORIZED
|| status
== HTTP_STATUS_UPGRADE_REQUIRED
);
798 if (status
== HTTP_STATUS_OK
)
801 printf("GET failed with status %d...\n", status
);
804 length
= httpGetLength2(http
);
807 while ((bytes
= httpRead2(http
, buffer
, sizeof(buffer
))) > 0)
810 fwrite(buffer
, bytes
, 1, out
);
813 current
= time(NULL
);
814 if (current
== start
) current
++;
815 printf("\r" CUPS_LLFMT
"/" CUPS_LLFMT
" bytes ("
816 CUPS_LLFMT
" bytes/sec) ", CUPS_LLCAST total
,
817 CUPS_LLCAST length
, CUPS_LLCAST (total
/ (current
- start
)));
823 puts("Closing connection to server...");
834 * End of "$Id: testhttp.c 11445 2013-12-05 19:57:43Z msweet $".