]>
git.ipfire.org Git - thirdparty/cups.git/blob - scheduler/testdirsvc.c
2 * "$Id: testdirsvc.c 6649 2007-07-11 21:46:42Z mike $"
4 * Browsing test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products, all rights reserved.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Simulate one or more remote printers.
18 * usage() - Show program usage...
22 * Include necessary headers...
25 #include <cups/cups.h>
26 #include <cups/string.h>
35 static void usage(void);
39 * 'main()' - Simulate one or more remote printers.
42 int /* O - Exit status */
43 main(int argc
, /* I - Number of command-line arguments */
44 char *argv
[]) /* I - Command-line arguments */
46 int i
, /* Looping var */
47 printer
, /* Current printer */
48 num_printers
, /* Number of printers */
49 pclass
, /* Current printer class */
50 num_pclasses
, /* Number of printer classes */
51 server
, /* Current server */
52 num_servers
, /* Number of servers */
53 count
, /* Number of printers sent this cycle */
54 interval
, /* Browse Interval */
55 lease
, /* Browse lease-duration */
56 continuous
, /* Run continuously? */
57 port
, /* Browse port */
58 sock
, /* Browse socket */
59 val
, /* Socket option value */
60 seconds
, /* Seconds until next cycle */
61 verbose
; /* Verbose output? */
62 const char *options
; /* Options for URIs */
63 time_t curtime
; /* Current UNIX time */
64 struct tm
*curdate
; /* Current date and time */
65 struct sockaddr_in addr
; /* Broadcast address */
66 char packet
[1540]; /* Data packet */
67 static const char * const names
[26] = /* Printer names */
99 * Process command-line arguments...
112 for (i
= 1; i
< argc
; i
++)
114 if (!strcmp(argv
[i
], "-c"))
116 else if (!strcmp(argv
[i
], "-i"))
120 interval
= atoi(argv
[i
]);
126 else if (!strcmp(argv
[i
], "-l"))
130 lease
= atoi(argv
[i
]);
134 else if (!strcmp(argv
[i
], "-o"))
142 else if (!strcmp(argv
[i
], "-C"))
146 num_pclasses
= atoi(argv
[i
]);
150 else if (!strcmp(argv
[i
], "-p"))
154 num_printers
= atoi(argv
[i
]);
158 else if (!strcmp(argv
[i
], "-s"))
162 num_servers
= atoi(argv
[i
]);
166 else if (!strcmp(argv
[i
], "-v"))
168 else if (isdigit(argv
[i
][0] & 255))
170 port
= atoi(argv
[i
]);
176 if ((num_printers
<= 0 && num_pclasses
<= 0) || num_servers
<= 0 ||
177 interval
<= 0 || lease
< 1 || port
<= 0)
181 * Open a broadcast socket...
184 if ((sock
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
186 perror("Unable to open broadcast socket");
191 * Set the "broadcast" flag...
195 if (setsockopt(sock
, SOL_SOCKET
, SO_BROADCAST
, &val
, sizeof(val
)))
197 perror("Unable to put socket in broadcast mode");
204 * Broadcast to 127.0.0.1 (localhost)
207 memset(&addr
, 0, sizeof(addr
));
208 addr
.sin_addr
.s_addr
= htonl(0x7f000001);
209 addr
.sin_family
= AF_INET
;
210 addr
.sin_port
= htons(port
);
213 * Send virtual printers continuously until we are stopped.
219 * Start a new cycle of N printers...
222 printf("Sending %d printers from %d servers...\n", num_printers
,
225 count
= num_servers
* (num_printers
+ num_pclasses
) / interval
+ 1;
226 curtime
= time(NULL
);
227 curdate
= localtime(&curtime
);
230 for (i
= 0, printer
= 0; printer
< num_printers
; printer
++)
232 for (server
= 0; server
< num_servers
; server
++, i
++)
239 curtime
= time(NULL
);
240 curdate
= localtime(&curtime
);
243 snprintf(packet
, sizeof(packet
),
244 "%x %x ipp://testserver-%d/printers/%s-%d \"Server Room %d\" "
245 "\"Test Printer %d\" \"Acme Blazer 2000\"%s%s "
246 "lease-duration=%d\n",
247 CUPS_PRINTER_REMOTE
, IPP_PRINTER_IDLE
, server
+ 1,
248 names
[printer
% 26], printer
/ 26 + 1, server
+ 1,
249 printer
+ 1, options
? " ipp-options=" : "",
250 options
? options
: "", lease
);
253 printf("[%02d:%02d:%02d] %s", curdate
->tm_hour
, curdate
->tm_min
,
254 curdate
->tm_sec
, packet
);
256 if (sendto(sock
, packet
, strlen(packet
), 0,
257 (struct sockaddr
*)&addr
, sizeof(addr
)) < 0)
258 perror("Unabled to send packet");
263 for (i
= 0, pclass
= 0; pclass
< num_pclasses
; pclass
++)
265 for (server
= 0; server
< num_servers
; server
++, i
++)
272 curtime
= time(NULL
);
273 curdate
= localtime(&curtime
);
276 snprintf(packet
, sizeof(packet
),
277 "%x %x ipp://testserver-%d/classes/class-%s-%d \"Server Room %d\" "
278 "\"Test Class %d\" \"Acme Blazer 2000\"%s%s "
279 "lease-duration=%d\n",
280 CUPS_PRINTER_REMOTE
| CUPS_PRINTER_CLASS
, IPP_PRINTER_IDLE
,
281 server
+ 1, names
[pclass
% 26], pclass
/ 26 + 1, server
+ 1,
282 pclass
+ 1, options
? " ipp-options=" : "",
283 options
? options
: "", lease
);
286 printf("[%02d:%02d:%02d] %s", curdate
->tm_hour
, curdate
->tm_min
,
287 curdate
->tm_sec
, packet
);
289 if (sendto(sock
, packet
, strlen(packet
), 0,
290 (struct sockaddr
*)&addr
, sizeof(addr
)) < 0)
291 perror("Unabled to send packet");
299 * Sleep for any remaining time...
311 * 'usage()' - Show program usage...
317 puts("Usage: testdirsvc [-c] [-i interval] [-l lease-duration] "
318 "[-o ipp-options] [-p printers] "
319 "[-C classes] [-s servers] [-v] port");
325 * End of "$Id: testdirsvc.c 6649 2007-07-11 21:46:42Z mike $".