2 * HTTP test program for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include "cups-private.h"
19 * Types and structures...
22 typedef struct uri_test_s
/**** URI test cases ****/
24 http_uri_status_t result
; /* Expected return value */
25 const char *uri
, /* URI */
26 *scheme
, /* Scheme string */
27 *username
, /* Username:password string */
28 *hostname
, /* Hostname string */
29 *resource
; /* Resource string */
30 int port
, /* Port number */
31 assemble_port
; /* Port number for httpAssembleURI() */
32 http_uri_coding_t assemble_coding
;/* Coding for httpAssembleURI() */
40 static uri_test_t uri_tests
[] = /* URI test data */
42 /* Start with valid URIs */
43 { HTTP_URI_STATUS_OK
, "file:/filename",
44 "file", "", "", "/filename", 0, 0,
45 HTTP_URI_CODING_MOST
},
46 { HTTP_URI_STATUS_OK
, "file:/filename%20with%20spaces",
47 "file", "", "", "/filename with spaces", 0, 0,
48 HTTP_URI_CODING_MOST
},
49 { HTTP_URI_STATUS_OK
, "file:///filename",
50 "file", "", "", "/filename", 0, 0,
51 HTTP_URI_CODING_MOST
},
52 { HTTP_URI_STATUS_OK
, "file:///filename%20with%20spaces",
53 "file", "", "", "/filename with spaces", 0, 0,
54 HTTP_URI_CODING_MOST
},
55 { HTTP_URI_STATUS_OK
, "file://localhost/filename",
56 "file", "", "localhost", "/filename", 0, 0,
57 HTTP_URI_CODING_MOST
},
58 { HTTP_URI_STATUS_OK
, "file://localhost/filename%20with%20spaces",
59 "file", "", "localhost", "/filename with spaces", 0, 0,
60 HTTP_URI_CODING_MOST
},
61 { HTTP_URI_STATUS_OK
, "http://server/",
62 "http", "", "server", "/", 80, 0,
63 HTTP_URI_CODING_MOST
},
64 { HTTP_URI_STATUS_OK
, "http://username@server/",
65 "http", "username", "server", "/", 80, 0,
66 HTTP_URI_CODING_MOST
},
67 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server/",
68 "http", "username:password", "server", "/", 80, 0,
69 HTTP_URI_CODING_MOST
},
70 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server:8080/",
71 "http", "username:password", "server", "/", 8080, 8080,
72 HTTP_URI_CODING_MOST
},
73 { HTTP_URI_STATUS_OK
, "http://username:passwor%64@server:8080/directory/filename",
74 "http", "username:password", "server", "/directory/filename", 8080, 8080,
75 HTTP_URI_CODING_MOST
},
76 { HTTP_URI_STATUS_OK
, "http://[2000::10:100]:631/ipp",
77 "http", "", "2000::10:100", "/ipp", 631, 631,
78 HTTP_URI_CODING_MOST
},
79 { HTTP_URI_STATUS_OK
, "https://username:passwor%64@server/directory/filename",
80 "https", "username:password", "server", "/directory/filename", 443, 0,
81 HTTP_URI_CODING_MOST
},
82 { HTTP_URI_STATUS_OK
, "ipp://username:passwor%64@[::1]/ipp",
83 "ipp", "username:password", "::1", "/ipp", 631, 0,
84 HTTP_URI_CODING_MOST
},
85 { HTTP_URI_STATUS_OK
, "lpd://server/queue?reserve=yes",
86 "lpd", "", "server", "/queue?reserve=yes", 515, 0,
87 HTTP_URI_CODING_MOST
},
88 { HTTP_URI_STATUS_OK
, "mailto:user@domain.com",
89 "mailto", "", "", "user@domain.com", 0, 0,
90 HTTP_URI_CODING_MOST
},
91 { HTTP_URI_STATUS_OK
, "socket://server/",
92 "socket", "", "server", "/", 9100, 0,
93 HTTP_URI_CODING_MOST
},
94 { HTTP_URI_STATUS_OK
, "socket://192.168.1.1:9101/",
95 "socket", "", "192.168.1.1", "/", 9101, 9101,
96 HTTP_URI_CODING_MOST
},
97 { HTTP_URI_STATUS_OK
, "tel:8005551212",
98 "tel", "", "", "8005551212", 0, 0,
99 HTTP_URI_CODING_MOST
},
100 { HTTP_URI_STATUS_OK
, "ipp://username:password@[v1.fe80::200:1234:5678:9abc+eth0]:999/ipp",
101 "ipp", "username:password", "fe80::200:1234:5678:9abc%eth0", "/ipp", 999, 999,
102 HTTP_URI_CODING_MOST
},
103 { HTTP_URI_STATUS_OK
, "ipp://username:password@[fe80::200:1234:5678:9abc%25eth0]:999/ipp",
104 "ipp", "username:password", "fe80::200:1234:5678:9abc%eth0", "/ipp", 999, 999,
105 (http_uri_coding_t
)(HTTP_URI_CODING_MOST
| HTTP_URI_CODING_RFC6874
) },
106 { HTTP_URI_STATUS_OK
, "http://server/admin?DEVICE_URI=usb://HP/Photosmart%25202600%2520series?serial=MY53OK70V10400",
107 "http", "", "server", "/admin?DEVICE_URI=usb://HP/Photosmart%25202600%2520series?serial=MY53OK70V10400", 80, 0,
108 HTTP_URI_CODING_MOST
},
109 { HTTP_URI_STATUS_OK
, "lpd://Acme%20Laser%20(01%3A23%3A45).local._tcp._printer/",
110 "lpd", "", "Acme Laser (01:23:45).local._tcp._printer", "/", 515, 0,
111 HTTP_URI_CODING_MOST
},
112 { HTTP_URI_STATUS_OK
, "ipp://HP%20Officejet%204500%20G510n-z%20%40%20Will's%20MacBook%20Pro%2015%22._ipp._tcp.local./",
113 "ipp", "", "HP Officejet 4500 G510n-z @ Will's MacBook Pro 15\"._ipp._tcp.local.", "/", 631, 0,
114 HTTP_URI_CODING_MOST
},
115 { HTTP_URI_STATUS_OK
, "ipp://%22%23%2F%3A%3C%3E%3F%40%5B%5C%5D%5E%60%7B%7C%7D/",
116 "ipp", "", "\"#/:<>?@[\\]^`{|}", "/", 631, 0,
117 HTTP_URI_CODING_MOST
},
118 { HTTP_URI_STATUS_UNKNOWN_SCHEME
, "smb://server/Some%20Printer",
119 "smb", "", "server", "/Some Printer", 0, 0,
120 HTTP_URI_CODING_ALL
},
123 { HTTP_URI_STATUS_MISSING_SCHEME
, "/path/to/file/index.html",
124 "file", "", "", "/path/to/file/index.html", 0, 0,
125 HTTP_URI_CODING_MOST
},
126 { HTTP_URI_STATUS_MISSING_SCHEME
, "//server/ipp",
127 "ipp", "", "server", "/ipp", 631, 0,
128 HTTP_URI_CODING_MOST
},
131 { HTTP_URI_STATUS_UNKNOWN_SCHEME
, "vendor://server/resource",
132 "vendor", "", "server", "/resource", 0, 0,
133 HTTP_URI_CODING_MOST
},
135 /* Missing resource */
136 { HTTP_URI_STATUS_MISSING_RESOURCE
, "socket://[::192.168.2.1]",
137 "socket", "", "::192.168.2.1", "/", 9100, 0,
138 HTTP_URI_CODING_MOST
},
139 { HTTP_URI_STATUS_MISSING_RESOURCE
, "socket://192.168.1.1:9101",
140 "socket", "", "192.168.1.1", "/", 9101, 0,
141 HTTP_URI_CODING_MOST
},
144 { HTTP_URI_STATUS_BAD_URI
, "",
145 "", "", "", "", 0, 0,
146 HTTP_URI_CODING_MOST
},
149 { HTTP_URI_STATUS_BAD_SCHEME
, "://server/ipp",
150 "", "", "", "", 0, 0,
151 HTTP_URI_CODING_MOST
},
152 { HTTP_URI_STATUS_BAD_SCHEME
, "bad_scheme://server/resource",
153 "", "", "", "", 0, 0,
154 HTTP_URI_CODING_MOST
},
157 { HTTP_URI_STATUS_BAD_USERNAME
, "http://username:passwor%6@server/resource",
158 "http", "", "", "", 80, 0,
159 HTTP_URI_CODING_MOST
},
162 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://[/::1]/index.html",
163 "http", "", "", "", 80, 0,
164 HTTP_URI_CODING_MOST
},
165 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://[",
166 "http", "", "", "", 80, 0,
167 HTTP_URI_CODING_MOST
},
168 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://serve%7/index.html",
169 "http", "", "", "", 80, 0,
170 HTTP_URI_CODING_MOST
},
171 { HTTP_URI_STATUS_BAD_HOSTNAME
, "http://server with spaces/index.html",
172 "http", "", "", "", 80, 0,
173 HTTP_URI_CODING_MOST
},
174 { HTTP_URI_STATUS_BAD_HOSTNAME
, "ipp://\"#/:<>?@[\\]^`{|}/",
175 "ipp", "", "", "", 631, 0,
176 HTTP_URI_CODING_MOST
},
178 /* Bad port number */
179 { HTTP_URI_STATUS_BAD_PORT
, "http://127.0.0.1:9999a/index.html",
180 "http", "", "127.0.0.1", "", 0, 0,
181 HTTP_URI_CODING_MOST
},
184 { HTTP_URI_STATUS_BAD_RESOURCE
, "mailto:\r\nbla",
185 "mailto", "", "", "", 0, 0,
186 HTTP_URI_CODING_MOST
},
187 { HTTP_URI_STATUS_BAD_RESOURCE
, "http://server/index.html%",
188 "http", "", "server", "", 80, 0,
189 HTTP_URI_CODING_MOST
},
190 { HTTP_URI_STATUS_BAD_RESOURCE
, "http://server/index with spaces.html",
191 "http", "", "server", "", 80, 0,
192 HTTP_URI_CODING_MOST
}
194 static const char * const base64_tests
[][2] =
199 /* 010000 010100 0010 */
201 /* 010000 010100 001001 000011 */
202 { "ABCD", "QUJDRA==" },
203 /* 010000 010100 001001 000011 010001 00 */
204 { "ABCDE", "QUJDREU=" },
205 /* 010000 010100 001001 000011 010001 000100 0101 */
206 { "ABCDEF", "QUJDREVG" },
207 /* 010000 010100 001001 000011 010001 000100 010101 000110 */
212 * 'main()' - Main entry.
215 int /* O - Exit status */
216 main(int argc
, /* I - Number of command-line arguments */
217 char *argv
[]) /* I - Command-line arguments */
219 int i
, j
, k
; /* Looping vars */
220 http_t
*http
; /* HTTP connection */
221 http_encryption_t encryption
; /* Encryption type */
222 http_status_t status
; /* Status of GET command */
223 int failures
; /* Number of test failures */
224 char buffer
[8192]; /* Input buffer */
225 long bytes
; /* Number of bytes read */
226 FILE *out
; /* Output file */
227 char encode
[256], /* Base64-encoded string */
228 decode
[256]; /* Base64-decoded string */
229 int decodelen
; /* Length of decoded string */
230 char scheme
[HTTP_MAX_URI
], /* Scheme from URI */
231 hostname
[HTTP_MAX_URI
], /* Hostname from URI */
232 username
[HTTP_MAX_URI
], /* Username:password from URI */
233 resource
[HTTP_MAX_URI
]; /* Resource from URI */
234 int port
; /* Port number from URI */
235 http_uri_status_t uri_status
; /* Status of URI separation */
236 http_addrlist_t
*addrlist
, /* Address list */
237 *addr
; /* Current address */
238 off_t length
, total
; /* Length and total bytes */
239 time_t start
, current
; /* Start and end time */
240 const char *encoding
; /* Negotiated Content-Encoding */
241 static const char * const uri_status_strings
[] =
243 "HTTP_URI_STATUS_OVERFLOW",
244 "HTTP_URI_STATUS_BAD_ARGUMENTS",
245 "HTTP_URI_STATUS_BAD_RESOURCE",
246 "HTTP_URI_STATUS_BAD_PORT",
247 "HTTP_URI_STATUS_BAD_HOSTNAME",
248 "HTTP_URI_STATUS_BAD_USERNAME",
249 "HTTP_URI_STATUS_BAD_SCHEME",
250 "HTTP_URI_STATUS_BAD_URI",
251 "HTTP_URI_STATUS_OK",
252 "HTTP_URI_STATUS_MISSING_SCHEME",
253 "HTTP_URI_STATUS_UNKNOWN_SCHEME",
254 "HTTP_URI_STATUS_MISSING_RESOURCE"
259 * Do API tests if we don't have a URL on the command-line...
267 * httpGetDateString()/httpGetDateTime()
270 fputs("httpGetDateString()/httpGetDateTime(): ", stdout
);
273 strlcpy(buffer
, httpGetDateString(start
), sizeof(buffer
));
274 current
= httpGetDateTime(buffer
);
276 i
= (int)(current
- start
);
286 printf(" Difference is %d seconds, %02d:%02d:%02d...\n", i
, i
/ 3600,
287 (i
/ 60) % 60, i
% 60);
288 printf(" httpGetDateString(%d) returned \"%s\"\n", (int)start
, buffer
);
289 printf(" httpGetDateTime(\"%s\") returned %d\n", buffer
, (int)current
);
290 printf(" httpGetDateString(%d) returned \"%s\"\n", (int)current
,
291 httpGetDateString(current
));
295 * httpDecode64_2()/httpEncode64_2()
298 fputs("httpDecode64_2()/httpEncode64_2(): ", stdout
);
300 for (i
= 0, j
= 0; i
< (int)(sizeof(base64_tests
) / sizeof(base64_tests
[0])); i
++)
302 httpEncode64_2(encode
, sizeof(encode
), base64_tests
[i
][0],
303 (int)strlen(base64_tests
[i
][0]));
304 decodelen
= (int)sizeof(decode
);
305 httpDecode64_2(decode
, &decodelen
, base64_tests
[i
][1]);
307 if (strcmp(decode
, base64_tests
[i
][0]))
317 printf(" httpDecode64_2() returned \"%s\", expected \"%s\"...\n",
318 decode
, base64_tests
[i
][0]);
321 if (strcmp(encode
, base64_tests
[i
][1]))
331 printf(" httpEncode64_2() returned \"%s\", expected \"%s\"...\n",
332 encode
, base64_tests
[i
][1]);
344 fputs("_httpDigest(MD5): ", stdout
);
345 if (!_httpDigest(buffer
, sizeof(buffer
), "MD5", "Mufasa", "http-auth@example.org", "Circle of Life", "7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v", 1, "f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ", "auth", "GET", "/dir/index.html"))
348 puts("FAIL (unable to calculate hash)");
350 else if (strcmp(buffer
, "8ca523f5e9506fed4657c9700eebdbec"))
353 printf("FAIL (got \"%s\", expected \"8ca523f5e9506fed4657c9700eebdbec\")\n", buffer
);
358 fputs("_httpDigest(SHA-256): ", stdout
);
359 if (!_httpDigest(buffer
, sizeof(buffer
), "SHA-256", "Mufasa", "http-auth@example.org", "Circle of Life", "7ypf/xlj9XXwfDPEoM4URrv/xwf94BcCAzFZH4GiTo0v", 1, "f2/wE4q74E6zIJEtWaHKaf5wv/H5QzzpXusqGemxURZJ", "auth", "GET", "/dir/index.html"))
362 puts("FAIL (unable to calculate hash)");
364 else if (strcmp(buffer
, "753927fa0e85d155564e2e272a28d1802ca10daf4496794697cf8db5856cb6c1"))
367 printf("FAIL (got \"%s\", expected \"753927fa0e85d155564e2e272a28d1802ca10daf4496794697cf8db5856cb6c1\")\n", buffer
);
377 fputs("httpGetHostname(): ", stdout
);
379 if (httpGetHostname(NULL
, hostname
, sizeof(hostname
)))
380 printf("PASS (%s)\n", hostname
);
391 printf("httpAddrGetList(%s): ", hostname
);
393 addrlist
= httpAddrGetList(hostname
, AF_UNSPEC
, NULL
);
396 for (i
= 0, addr
= addrlist
; addr
; i
++, addr
= addr
->next
)
398 char numeric
[1024]; /* Numeric IP address */
401 httpAddrString(&(addr
->addr
), numeric
, sizeof(numeric
));
402 if (!strcmp(numeric
, "UNKNOWN"))
407 printf("FAIL (bad address for %s)\n", hostname
);
409 printf("PASS (%d address(es) for %s)\n", i
, hostname
);
411 httpAddrFreeList(addrlist
);
413 else if (isdigit(hostname
[0] & 255))
415 puts("FAIL (ignored because hostname is numeric)");
424 * Test httpSeparateURI()...
427 fputs("httpSeparateURI(): ", stdout
);
428 for (i
= 0, j
= 0; i
< (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0])); i
++)
430 uri_status
= httpSeparateURI(HTTP_URI_CODING_MOST
,
431 uri_tests
[i
].uri
, scheme
, sizeof(scheme
),
432 username
, sizeof(username
),
433 hostname
, sizeof(hostname
), &port
,
434 resource
, sizeof(resource
));
435 if (uri_status
!= uri_tests
[i
].result
||
436 strcmp(scheme
, uri_tests
[i
].scheme
) ||
437 strcmp(username
, uri_tests
[i
].username
) ||
438 strcmp(hostname
, uri_tests
[i
].hostname
) ||
439 port
!= uri_tests
[i
].port
||
440 strcmp(resource
, uri_tests
[i
].resource
))
450 printf(" \"%s\":\n", uri_tests
[i
].uri
);
452 if (uri_status
!= uri_tests
[i
].result
)
453 printf(" Returned %s instead of %s\n",
454 uri_status_strings
[uri_status
+ 8],
455 uri_status_strings
[uri_tests
[i
].result
+ 8]);
457 if (strcmp(scheme
, uri_tests
[i
].scheme
))
458 printf(" Scheme \"%s\" instead of \"%s\"\n",
459 scheme
, uri_tests
[i
].scheme
);
461 if (strcmp(username
, uri_tests
[i
].username
))
462 printf(" Username \"%s\" instead of \"%s\"\n",
463 username
, uri_tests
[i
].username
);
465 if (strcmp(hostname
, uri_tests
[i
].hostname
))
466 printf(" Hostname \"%s\" instead of \"%s\"\n",
467 hostname
, uri_tests
[i
].hostname
);
469 if (port
!= uri_tests
[i
].port
)
470 printf(" Port %d instead of %d\n",
471 port
, uri_tests
[i
].port
);
473 if (strcmp(resource
, uri_tests
[i
].resource
))
474 printf(" Resource \"%s\" instead of \"%s\"\n",
475 resource
, uri_tests
[i
].resource
);
480 printf("PASS (%d URIs tested)\n",
481 (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0])));
484 * Test httpAssembleURI()...
487 fputs("httpAssembleURI(): ", stdout
);
488 for (i
= 0, j
= 0, k
= 0;
489 i
< (int)(sizeof(uri_tests
) / sizeof(uri_tests
[0]));
491 if (uri_tests
[i
].result
== HTTP_URI_STATUS_OK
&&
492 !strstr(uri_tests
[i
].uri
, "%64") &&
493 strstr(uri_tests
[i
].uri
, "//"))
496 uri_status
= httpAssembleURI(uri_tests
[i
].assemble_coding
,
497 buffer
, sizeof(buffer
),
499 uri_tests
[i
].username
,
500 uri_tests
[i
].hostname
,
501 uri_tests
[i
].assemble_port
,
502 uri_tests
[i
].resource
);
504 if (uri_status
!= HTTP_URI_STATUS_OK
)
514 printf(" \"%s\": %s\n", uri_tests
[i
].uri
,
515 uri_status_strings
[uri_status
+ 8]);
517 else if (strcmp(buffer
, uri_tests
[i
].uri
))
527 printf(" \"%s\": assembled = \"%s\"\n", uri_tests
[i
].uri
,
533 printf("PASS (%d URIs tested)\n", k
);
539 fputs("httpAssembleUUID: ", stdout
);
540 httpAssembleUUID("hostname.example.com", 631, "printer", 12345, buffer
,
542 if (strncmp(buffer
, "urn:uuid:", 9))
544 printf("FAIL (%s)\n", buffer
);
548 printf("PASS (%s)\n", buffer
);
551 * Show a summary and return...
555 printf("\n%d TESTS FAILED!\n", failures
);
557 puts("\nALL TESTS PASSED!");
561 else if (strstr(argv
[1], "._tcp"))
564 * Test resolving an mDNS name.
567 char resolved
[1024]; /* Resolved URI */
570 printf("_httpResolveURI(%s, _HTTP_RESOLVE_DEFAULT): ", argv
[1]);
573 if (!_httpResolveURI(argv
[1], resolved
, sizeof(resolved
),
574 _HTTP_RESOLVE_DEFAULT
, NULL
, NULL
))
580 printf("PASS (%s)\n", resolved
);
582 printf("_httpResolveURI(%s, _HTTP_RESOLVE_FQDN): ", argv
[1]);
585 if (!_httpResolveURI(argv
[1], resolved
, sizeof(resolved
),
586 _HTTP_RESOLVE_FQDN
, NULL
, NULL
))
591 else if (strstr(resolved
, ".local:"))
593 printf("FAIL (%s)\n", resolved
);
598 printf("PASS (%s)\n", resolved
);
602 else if (!strcmp(argv
[1], "-u") && argc
== 3)
605 * Test URI separation...
608 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
, argv
[2], scheme
,
609 sizeof(scheme
), username
, sizeof(username
),
610 hostname
, sizeof(hostname
), &port
,
611 resource
, sizeof(resource
));
612 printf("uri_status = %s\n", uri_status_strings
[uri_status
+ 8]);
613 printf("scheme = \"%s\"\n", scheme
);
614 printf("username = \"%s\"\n", username
);
615 printf("hostname = \"%s\"\n", hostname
);
616 printf("port = %d\n", port
);
617 printf("resource = \"%s\"\n", resource
);
623 * Test HTTP GET requests...
629 for (i
= 1; i
< argc
; i
++)
633 if (!strcmp(argv
[i
], "-o"))
639 out
= fopen(argv
[i
], "wb");
643 httpSeparateURI(HTTP_URI_CODING_MOST
, argv
[i
], scheme
, sizeof(scheme
),
644 username
, sizeof(username
),
645 hostname
, sizeof(hostname
), &port
,
646 resource
, sizeof(resource
));
648 if (!_cups_strcasecmp(scheme
, "https") || !_cups_strcasecmp(scheme
, "ipps") ||
650 encryption
= HTTP_ENCRYPTION_ALWAYS
;
652 encryption
= HTTP_ENCRYPTION_IF_REQUESTED
;
654 http
= httpConnect2(hostname
, port
, NULL
, AF_UNSPEC
, encryption
, 1, 30000, NULL
);
661 if (httpIsEncrypted(http
))
665 static const char *trusts
[] = { "OK", "Invalid", "Changed", "Expired", "Renewed", "Unknown" };
666 if (!httpCopyCredentials(http
, &creds
))
668 cups_array_t
*lcreds
;
669 http_trust_t trust
= httpCredentialsGetTrust(creds
, hostname
);
671 httpCredentialsString(creds
, info
, sizeof(info
));
673 printf("Count: %d\n", cupsArrayCount(creds
));
674 printf("Trust: %s\n", trusts
[trust
]);
675 printf("Expiration: %s\n", httpGetDateString(httpCredentialsGetExpiration(creds
)));
676 printf("IsValidName: %d\n", httpCredentialsAreValidForName(creds
, hostname
));
677 printf("String: \"%s\"\n", info
);
679 printf("LoadCredentials: %d\n", httpLoadCredentials(NULL
, &lcreds
, hostname
));
680 httpCredentialsString(lcreds
, info
, sizeof(info
));
681 printf(" Count: %d\n", cupsArrayCount(lcreds
));
682 printf(" String: \"%s\"\n", info
);
684 if (lcreds
&& cupsArrayCount(creds
) == cupsArrayCount(lcreds
))
686 http_credential_t
*cred
, *lcred
;
688 for (i
= 1, cred
= (http_credential_t
*)cupsArrayFirst(creds
), lcred
= (http_credential_t
*)cupsArrayFirst(lcreds
);
690 i
++, cred
= (http_credential_t
*)cupsArrayNext(creds
), lcred
= (http_credential_t
*)cupsArrayNext(lcreds
))
692 if (cred
->datalen
!= lcred
->datalen
)
693 printf(" Credential #%d: Different lengths (saved=%d, current=%d)\n", i
, (int)cred
->datalen
, (int)lcred
->datalen
);
694 else if (memcmp(cred
->data
, lcred
->data
, cred
->datalen
))
695 printf(" Credential #%d: Different data\n", i
);
697 printf(" Credential #%d: Matches\n", i
);
701 if (trust
!= HTTP_TRUST_OK
)
703 printf("SaveCredentials: %d\n", httpSaveCredentials(NULL
, creds
, hostname
));
704 trust
= httpCredentialsGetTrust(creds
, hostname
);
705 printf("New Trust: %s\n", trusts
[trust
]);
708 httpFreeCredentials(creds
);
711 puts("No credentials!");
714 printf("Checking file \"%s\"...\n", resource
);
720 if (!_cups_strcasecmp(httpGetField(http
, HTTP_FIELD_CONNECTION
), "close"))
722 httpClearFields(http
);
723 if (httpReconnect2(http
, 30000, NULL
))
725 status
= HTTP_STATUS_ERROR
;
730 if (http
->authstring
&& !strncmp(http
->authstring
, "Digest ", 7) && !new_auth
)
731 _httpSetDigestAuthString(http
, http
->nextnonce
, "HEAD", resource
);
733 httpClearFields(http
);
734 httpSetField(http
, HTTP_FIELD_AUTHORIZATION
, httpGetAuthString(http
));
735 httpSetField(http
, HTTP_FIELD_ACCEPT_LANGUAGE
, "en");
737 if (httpHead(http
, resource
))
739 if (httpReconnect2(http
, 30000, NULL
))
741 status
= HTTP_STATUS_ERROR
;
746 status
= HTTP_STATUS_UNAUTHORIZED
;
751 while ((status
= httpUpdate(http
)) == HTTP_STATUS_CONTINUE
);
755 if (status
== HTTP_STATUS_UNAUTHORIZED
)
758 * Flush any error message...
764 * See if we can do authentication...
769 if (cupsDoAuthentication(http
, "HEAD", resource
))
771 status
= HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
;
775 if (httpReconnect2(http
, 30000, NULL
))
777 status
= HTTP_STATUS_ERROR
;
784 else if (status
== HTTP_STATUS_UPGRADE_REQUIRED
)
786 /* Flush any error message... */
790 if (httpReconnect2(http
, 30000, NULL
))
792 status
= HTTP_STATUS_ERROR
;
796 /* Upgrade with encryption... */
797 httpEncryption(http
, HTTP_ENCRYPTION_REQUIRED
);
799 /* Try again, this time with encryption enabled... */
802 #endif /* HAVE_SSL */
804 while (status
== HTTP_STATUS_UNAUTHORIZED
||
805 status
== HTTP_STATUS_UPGRADE_REQUIRED
);
807 if (status
== HTTP_STATUS_OK
)
810 printf("HEAD failed with status %d...\n", status
);
812 encoding
= httpGetContentEncoding(http
);
814 printf("Requesting file \"%s\" (Accept-Encoding: %s)...\n", resource
,
815 encoding
? encoding
: "identity");
821 if (!_cups_strcasecmp(httpGetField(http
, HTTP_FIELD_CONNECTION
), "close"))
823 httpClearFields(http
);
824 if (httpReconnect2(http
, 30000, NULL
))
826 status
= HTTP_STATUS_ERROR
;
831 if (http
->authstring
&& !strncmp(http
->authstring
, "Digest ", 7) && !new_auth
)
832 _httpSetDigestAuthString(http
, http
->nextnonce
, "GET", resource
);
834 httpClearFields(http
);
835 httpSetField(http
, HTTP_FIELD_AUTHORIZATION
, httpGetAuthString(http
));
836 httpSetField(http
, HTTP_FIELD_ACCEPT_LANGUAGE
, "en");
837 httpSetField(http
, HTTP_FIELD_ACCEPT_ENCODING
, encoding
);
839 if (httpGet(http
, resource
))
841 if (httpReconnect2(http
, 30000, NULL
))
843 status
= HTTP_STATUS_ERROR
;
848 status
= HTTP_STATUS_UNAUTHORIZED
;
853 while ((status
= httpUpdate(http
)) == HTTP_STATUS_CONTINUE
);
857 if (status
== HTTP_STATUS_UNAUTHORIZED
)
860 * Flush any error message...
866 * See if we can do authentication...
871 if (cupsDoAuthentication(http
, "GET", resource
))
873 status
= HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
;
877 if (httpReconnect2(http
, 30000, NULL
))
879 status
= HTTP_STATUS_ERROR
;
886 else if (status
== HTTP_STATUS_UPGRADE_REQUIRED
)
888 /* Flush any error message... */
892 if (httpReconnect2(http
, 30000, NULL
))
894 status
= HTTP_STATUS_ERROR
;
898 /* Upgrade with encryption... */
899 httpEncryption(http
, HTTP_ENCRYPTION_REQUIRED
);
901 /* Try again, this time with encryption enabled... */
904 #endif /* HAVE_SSL */
906 while (status
== HTTP_STATUS_UNAUTHORIZED
|| status
== HTTP_STATUS_UPGRADE_REQUIRED
);
908 if (status
== HTTP_STATUS_OK
)
911 printf("GET failed with status %d...\n", status
);
914 length
= httpGetLength2(http
);
917 while ((bytes
= httpRead2(http
, buffer
, sizeof(buffer
))) > 0)
920 fwrite(buffer
, (size_t)bytes
, 1, out
);
923 current
= time(NULL
);
924 if (current
== start
)
927 printf("\r" CUPS_LLFMT
"/" CUPS_LLFMT
" bytes ("
928 CUPS_LLFMT
" bytes/sec) ", CUPS_LLCAST total
,
929 CUPS_LLCAST length
, CUPS_LLCAST (total
/ (current
- start
)));
938 puts("Closing connection to server...");