/*
- * "$Id: testhttp.c 7685 2008-06-23 16:49:18Z mike $"
+ * "$Id: testhttp.c 7742 2008-07-15 20:23:09Z mike $"
*
- * HTTP test program for the Common UNIX Printing System (CUPS).
+ * HTTP test program for CUPS.
*
- * Copyright 2007 by Apple Inc.
+ * Copyright 2007-2011 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* Include necessary headers...
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include "http.h"
-#include "string.h"
+#include "string-private.h"
+#include "http-private.h"
/*
"http", "", "server", "/admin?DEVICE_URI=usb://HP/Photosmart%25202600%2520series?serial=MY53OK70V10400", 80, 0 },
{ HTTP_URI_OK, "lpd://Acme%20Laser%20(01%3A23%3A45).local._tcp._printer/",
"lpd", "", "Acme Laser (01:23:45).local._tcp._printer", "/", 515, 0 },
+ { HTTP_URI_OK, "ipp://HP%20Officejet%204500%20G510n-z%20%40%20Will's%20MacBook%20Pro%2015%22._ipp._tcp.local./",
+ "ipp", "", "HP Officejet 4500 G510n-z @ Will's MacBook Pro 15\"._ipp._tcp.local.", "/", 631, 0 },
/* Missing scheme */
{ HTTP_URI_MISSING_SCHEME, "/path/to/file/index.html",
{
int i, j, k; /* Looping vars */
http_t *http; /* HTTP connection */
+ http_encryption_t encryption; /* Encryption type */
http_status_t status; /* Status of GET command */
int failures; /* Number of test failures */
char buffer[8192]; /* Input buffer */
for (i = 0, j = 0; i < (int)(sizeof(base64_tests) / sizeof(base64_tests[0])); i ++)
{
httpEncode64_2(encode, sizeof(encode), base64_tests[i][0],
- strlen(base64_tests[i][0]));
+ (int)strlen(base64_tests[i][0]));
decodelen = (int)sizeof(decode);
httpDecode64_2(decode, &decodelen, base64_tests[i][1]);
httpAddrFreeList(addrlist);
}
+ else if (isdigit(hostname[0] & 255))
+ {
+ puts("FAIL (ignored because hostname is numeric)");
+ }
else
{
failures ++;
return (failures);
}
+ else if (strstr(argv[1], "._tcp"))
+ {
+ /*
+ * Test resolving an mDNS name.
+ */
+
+ char resolved[1024]; /* Resolved URI */
+
+
+ printf("_httpResolveURI(%s, _HTTP_RESOLVE_DEFAULT): ", argv[1]);
+ fflush(stdout);
+
+ if (!_httpResolveURI(argv[1], resolved, sizeof(resolved),
+ _HTTP_RESOLVE_DEFAULT, NULL, NULL))
+ {
+ puts("FAIL");
+ return (1);
+ }
+ else
+ printf("PASS (%s)\n", resolved);
+
+ printf("_httpResolveURI(%s, _HTTP_RESOLVE_FQDN): ", argv[1]);
+ fflush(stdout);
+
+ if (!_httpResolveURI(argv[1], resolved, sizeof(resolved),
+ _HTTP_RESOLVE_FQDN, NULL, NULL))
+ {
+ puts("FAIL");
+ return (1);
+ }
+ else if (strstr(resolved, ".local:"))
+ {
+ printf("FAIL (%s)\n", resolved);
+ return (1);
+ }
+ else
+ {
+ printf("PASS (%s)\n", resolved);
+ return (0);
+ }
+ }
+ else if (!strcmp(argv[1], "-u") && argc == 3)
+ {
+ /*
+ * Test URI separation...
+ */
+
+ uri_status = httpSeparateURI(HTTP_URI_CODING_ALL, argv[2], scheme,
+ sizeof(scheme), username, sizeof(username),
+ hostname, sizeof(hostname), &port,
+ resource, sizeof(resource));
+ printf("uri_status = %s\n", uri_status_strings[uri_status + 8]);
+ printf("scheme = \"%s\"\n", scheme);
+ printf("username = \"%s\"\n", username);
+ printf("hostname = \"%s\"\n", hostname);
+ printf("port = %d\n", port);
+ printf("resource = \"%s\"\n", resource);
+
+ return (0);
+ }
/*
* Test HTTP GET requests...
hostname, sizeof(hostname), &port,
resource, sizeof(resource));
- http = httpConnectEncrypt(hostname, port, HTTP_ENCRYPT_IF_REQUESTED);
+ if (!_cups_strcasecmp(scheme, "https") || !_cups_strcasecmp(scheme, "ipps") ||
+ port == 443)
+ encryption = HTTP_ENCRYPT_ALWAYS;
+ else
+ encryption = HTTP_ENCRYPT_IF_REQUESTED;
+
+ http = httpConnectEncrypt(hostname, port, encryption);
if (http == NULL)
{
perror(hostname);
else
printf("GET failed with status %d...\n", status);
-
start = time(NULL);
length = httpGetLength2(http);
total = 0;
/*
- * End of "$Id: testhttp.c 7685 2008-06-23 16:49:18Z mike $".
+ * End of "$Id: testhttp.c 7742 2008-07-15 20:23:09Z mike $".
*/