]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testhttp.c
Copyright update...
[thirdparty/cups.git] / cups / testhttp.c
CommitLineData
04c3c0a1 1/*
efb2f309 2 * "$Id: testhttp.c,v 1.12 2002/01/02 17:58:41 mike Exp $"
04c3c0a1 3 *
4 * HTTP test program for the Common UNIX Printing System (CUPS).
5 *
efb2f309 6 * Copyright 1997-2002 by Easy Software Products.
04c3c0a1 7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
8784b6a6 17 * 44141 Airport View Drive, Suite 204
04c3c0a1 18 * Hollywood, Maryland 20636-3111 USA
19 *
20 * Voice: (301) 373-9603
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * main() - Main entry.
27 */
28
29/*
30 * Include necessary headers...
31 */
32
3b960317 33#include <stdio.h>
04c3c0a1 34#include "http.h"
35
36
37/*
38 * 'main()' - Main entry.
39 */
40
0542e38e 41int /* O - Exit status */
42main(int argc, /* I - Number of command-line arguments */
43 char *argv[]) /* I - Command-line arguments */
04c3c0a1 44{
0542e38e 45 int i; /* Looping var */
46 http_t *http; /* HTTP connection */
47 http_status_t status; /* Status of GET command */
d0e6f0a0 48 char buffer[8192]; /* Input buffer */
d21a7597 49 long bytes; /* Number of bytes read */
0d1f75a3 50 FILE *out; /* Output file */
d0e6f0a0 51 char host[HTTP_MAX_URI],
52 method[HTTP_MAX_URI],
53 username[HTTP_MAX_URI],
54 resource[HTTP_MAX_URI];
55 int port;
56 long length, total;
57 time_t start, current;
0542e38e 58
59
0542e38e 60
d0e6f0a0 61 http = NULL;
0d1f75a3 62 out = stdout;
63
0542e38e 64 for (i = 1; i < argc; i ++)
65 {
0d1f75a3 66 if (strcmp(argv[i], "-o") == 0)
67 {
68 i ++;
69 out = fopen(argv[i], "wb");
70 continue;
71 }
72
d0e6f0a0 73 httpSeparate(argv[i], method, username, host, &port, resource);
74
75 http = httpConnect(host, port);
76 if (http == NULL)
77 {
78 perror(host);
79 continue;
80 }
81 printf("Requesting file \"%s\"...\n", resource);
0542e38e 82 httpClearFields(http);
9ae9d67c 83 httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
d0e6f0a0 84 httpGet(http, resource);
85 while ((status = httpUpdate(http)) == HTTP_CONTINUE);
0542e38e 86
87 if (status == HTTP_OK)
88 puts("GET OK:");
89 else
90 printf("GET failed with status %d...\n", status);
91
d0e6f0a0 92
93 start = time(NULL);
94 length = atoi(httpGetField(http, HTTP_FIELD_CONTENT_LENGTH));
95 total = 0;
96
0542e38e 97 while ((bytes = httpRead(http, buffer, sizeof(buffer))) > 0)
0d1f75a3 98 {
d0e6f0a0 99 total += bytes;
0d1f75a3 100 fwrite(buffer, bytes, 1, out);
101 if (out != stdout)
d0e6f0a0 102 {
103 current = time(NULL);
104 if (current == start) current ++;
105 printf("\r%ld/%ld bytes (%ld bytes/sec) ", total, length,
106 total / (current - start));
107 fflush(stdout);
108 }
0d1f75a3 109 }
0542e38e 110 }
111
112 puts("Closing connection to server...");
113 httpClose(http);
114
0d1f75a3 115 if (out != stdout)
116 fclose(out);
117
0542e38e 118 return (0);
04c3c0a1 119}
120
121
122/*
efb2f309 123 * End of "$Id: testhttp.c,v 1.12 2002/01/02 17:58:41 mike Exp $".
04c3c0a1 124 */