]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testhttp.c
Change the end copyright for Easy Software Products files to 2003.
[thirdparty/cups.git] / cups / testhttp.c
CommitLineData
04c3c0a1 1/*
997fbfa7 2 * "$Id: testhttp.c,v 1.14 2002/12/17 18:56:43 swdev Exp $"
04c3c0a1 3 *
4 * HTTP test program for the Common UNIX Printing System (CUPS).
5 *
997fbfa7 6 * Copyright 1997-2003 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 *
34410ef2 24 * This file is subject to the Apple OS-Developed Software exception.
25 *
04c3c0a1 26 * Contents:
27 *
28 * main() - Main entry.
29 */
30
31/*
32 * Include necessary headers...
33 */
34
3b960317 35#include <stdio.h>
04c3c0a1 36#include "http.h"
37
38
39/*
40 * 'main()' - Main entry.
41 */
42
0542e38e 43int /* O - Exit status */
44main(int argc, /* I - Number of command-line arguments */
45 char *argv[]) /* I - Command-line arguments */
04c3c0a1 46{
0542e38e 47 int i; /* Looping var */
48 http_t *http; /* HTTP connection */
49 http_status_t status; /* Status of GET command */
d0e6f0a0 50 char buffer[8192]; /* Input buffer */
d21a7597 51 long bytes; /* Number of bytes read */
0d1f75a3 52 FILE *out; /* Output file */
d0e6f0a0 53 char host[HTTP_MAX_URI],
54 method[HTTP_MAX_URI],
55 username[HTTP_MAX_URI],
56 resource[HTTP_MAX_URI];
57 int port;
58 long length, total;
59 time_t start, current;
0542e38e 60
61
0542e38e 62
d0e6f0a0 63 http = NULL;
0d1f75a3 64 out = stdout;
65
0542e38e 66 for (i = 1; i < argc; i ++)
67 {
0d1f75a3 68 if (strcmp(argv[i], "-o") == 0)
69 {
70 i ++;
71 out = fopen(argv[i], "wb");
72 continue;
73 }
74
d0e6f0a0 75 httpSeparate(argv[i], method, username, host, &port, resource);
76
77 http = httpConnect(host, port);
78 if (http == NULL)
79 {
80 perror(host);
81 continue;
82 }
83 printf("Requesting file \"%s\"...\n", resource);
0542e38e 84 httpClearFields(http);
9ae9d67c 85 httpSetField(http, HTTP_FIELD_ACCEPT_LANGUAGE, "en");
d0e6f0a0 86 httpGet(http, resource);
87 while ((status = httpUpdate(http)) == HTTP_CONTINUE);
0542e38e 88
89 if (status == HTTP_OK)
90 puts("GET OK:");
91 else
92 printf("GET failed with status %d...\n", status);
93
d0e6f0a0 94
95 start = time(NULL);
96 length = atoi(httpGetField(http, HTTP_FIELD_CONTENT_LENGTH));
97 total = 0;
98
0542e38e 99 while ((bytes = httpRead(http, buffer, sizeof(buffer))) > 0)
0d1f75a3 100 {
d0e6f0a0 101 total += bytes;
0d1f75a3 102 fwrite(buffer, bytes, 1, out);
103 if (out != stdout)
d0e6f0a0 104 {
105 current = time(NULL);
106 if (current == start) current ++;
107 printf("\r%ld/%ld bytes (%ld bytes/sec) ", total, length,
108 total / (current - start));
109 fflush(stdout);
110 }
0d1f75a3 111 }
0542e38e 112 }
113
114 puts("Closing connection to server...");
115 httpClose(http);
116
0d1f75a3 117 if (out != stdout)
118 fclose(out);
119
0542e38e 120 return (0);
04c3c0a1 121}
122
123
124/*
997fbfa7 125 * End of "$Id: testhttp.c,v 1.14 2002/12/17 18:56:43 swdev Exp $".
04c3c0a1 126 */