]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/testdirsvc.c
2 * "$Id: testdirsvc.c 4821 2005-11-04 19:36:39Z mike $"
4 * Browsing test program for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2005 by Easy Software Products, all rights reserved.
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
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Simulate one or more remote printers.
27 * usage() - Show program usage...
31 * Include necessary headers...
34 #include <cups/cups.h>
35 #include <cups/string.h>
48 * 'main()' - Simulate one or more remote printers.
51 int /* O - Exit status */
52 main(int argc
, /* I - Number of command-line arguments */
53 char *argv
[]) /* I - Command-line arguments */
55 int i
, /* Looping var */
56 printer
, /* Current printer */
57 num_printers
, /* Number of printers */
58 server
, /* Current server */
59 num_servers
, /* Number of servers */
60 count
, /* Number of printers sent this cycle */
61 interval
, /* Browse Interval */
62 continuous
, /* Run continuously? */
63 port
, /* Browse port */
64 sock
, /* Browse socket */
65 val
, /* Socket option value */
66 seconds
, /* Seconds until next cycle */
67 verbose
; /* Verbose output? */
68 const char *options
; /* Options for URIs */
69 time_t curtime
; /* Current UNIX time */
70 struct tm
*curdate
; /* Current date and time */
71 struct sockaddr_in addr
; /* Broadcast address */
72 char packet
[1540]; /* Data packet */
73 static const char * const names
[26] = /* Printer names */
105 * Process command-line arguments...
116 for (i
= 1; i
< argc
; i
++)
118 if (!strcmp(argv
[i
], "-c"))
120 if (!strcmp(argv
[i
], "-v"))
122 else if (!strcmp(argv
[i
], "-i"))
126 interval
= atoi(argv
[i
]);
130 else if (!strcmp(argv
[i
], "-o"))
138 else if (!strcmp(argv
[i
], "-p"))
142 num_printers
= atoi(argv
[i
]);
146 else if (!strcmp(argv
[i
], "-s"))
150 num_servers
= atoi(argv
[i
]);
154 else if (isdigit(argv
[i
][0] & 255))
156 port
= atoi(argv
[i
]);
162 if (num_printers
<= 0 || num_servers
<= 0 || interval
<= 0 || port
<= 0)
166 * Open a broadcast socket...
169 if ((sock
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
171 perror("Unable to open broadcast socket");
176 * Set the "broadcast" flag...
180 if (setsockopt(sock
, SOL_SOCKET
, SO_BROADCAST
, &val
, sizeof(val
)))
182 perror("Unable to put socket in broadcast mode");
189 * Broadcast to 127.0.0.1 (localhost)
192 memset(&addr
, 0, sizeof(addr
));
193 addr
.sin_addr
.s_addr
= htonl(0x7f000001);
194 addr
.sin_family
= AF_INET
;
195 addr
.sin_port
= htons(port
);
198 * Send virtual printers continuously until we are stopped.
204 * Start a new cycle of N printers...
207 printf("Sending %d printers from %d servers...\n", num_printers
,
210 count
= num_servers
* num_printers
/ interval
+ 1;
211 curtime
= time(NULL
);
212 curdate
= localtime(&curtime
);
215 for (i
= 0, printer
= 0; printer
< num_printers
; printer
++)
217 for (server
= 0; server
< num_servers
; server
++, i
++)
224 curtime
= time(NULL
);
225 curdate
= localtime(&curtime
);
228 snprintf(packet
, sizeof(packet
),
229 "%x %x ipp://testserver-%d/printers/%s-%d \"Server Room %d\" "
230 "\"Test Printer %d\" \"Acme Blazer 2000\"%s%s\n",
231 CUPS_PRINTER_REMOTE
, IPP_PRINTER_IDLE
, server
+ 1,
232 names
[printer
% 26], printer
/ 26 + 1, server
+ 1,
233 printer
+ 1, options
? " ipp-options=" : "",
234 options
? options
: "");
237 printf("[%02d:%02d:%02d] %s", curdate
->tm_hour
, curdate
->tm_min
,
238 curdate
->tm_sec
, packet
);
240 if (sendto(sock
, packet
, strlen(packet
), 0,
241 (struct sockaddr
*)&addr
, sizeof(addr
)) < 0)
242 perror("Unabled to send packet");
250 * Sleep for any remaining time...
262 * 'usage()' - Show program usage...
268 puts("Usage: testdirsvc [-i interval] [-o ipp-options] [-p printers] [-s servers] [-v] port");
274 * End of "$Id: testdirsvc.c 4821 2005-11-04 19:36:39Z mike $".