]> git.ipfire.org Git - thirdparty/cups.git/blame - scheduler/printers.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / printers.c
CommitLineData
ef416fc2 1/*
bd7854cb 2 * "$Id: printers.c 5132 2006-02-19 14:57:11Z mike $"
ef416fc2 3 *
4 * Printer routines for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2006 by Easy Software Products, all rights reserved.
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
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * Contents:
25 *
26 * cupsdAddPrinter() - Add a printer to the system.
ef416fc2 27 * cupsdAddPrinterHistory() - Add the current printer state to the history.
28 * cupsdAddPrinterUser() - Add a user to the ACL.
29 * cupsdDeleteAllPrinters() - Delete all printers from the system.
30 * cupsdDeletePrinter() - Delete a printer from the system.
31 * cupsdDeletePrinterFilters() - Delete all MIME filters for a printer.
32 * cupsdFindPrinter() - Find a printer in the list.
33 * cupsdFreePrinterUsers() - Free allow/deny users.
34 * cupsdLoadAllPrinters() - Load printers from the printers.conf file.
fa73b229 35 * cupsdSaveAllPrinters() - Save all printer definitions to the
36 * printers.conf file.
37 * cupsdSetPrinterAttrs() - Set printer attributes based upon the PPD
38 * file.
ef416fc2 39 * cupsdSetPrinterReasons() - Set/update the reasons strings.
40 * cupsdSetPrinterState() - Update the current state of a printer.
41 * cupsdStopPrinter() - Stop a printer from printing any jobs...
42 * cupsdUpdatePrinters() - Update printers after a partial reload.
43 * cupsdValidateDest() - Validate a printer/class destination.
44 * cupsdWritePrintcap() - Write a pseudo-printcap file for older
45 * applications that need it...
46 * cupsdSanitizeURI() - Sanitize a device URI...
bd7854cb 47 * add_printer_filter() - Add a MIME filter for a printer.
48 * add_printer_formats() - Add document-format-supported values for
49 * a printer.
ef416fc2 50 * compare_printers() - Compare two printers.
bd7854cb 51 * transcode_nickname() - Convert the PPD NickName to UTF-8...
ef416fc2 52 * write_irix_config() - Update the config files used by the IRIX
53 * desktop tools.
fa73b229 54 * write_irix_state() - Update the status files used by IRIX
55 * printing desktop tools.
ef416fc2 56 */
57
58/*
59 * Include necessary headers...
60 */
61
62#include "cupsd.h"
bd7854cb 63#include <cups/transcode.h>
ef416fc2 64
65
66/*
67 * Local functions...
68 */
69
bd7854cb 70static void add_printer_filter(cupsd_printer_t *p, const char *filter);
71static void add_printer_formats(cupsd_printer_t *p);
ef416fc2 72static int compare_printers(void *first, void *second, void *data);
bd7854cb 73static void transcode_nickname(cupsd_printer_t *p, ppd_file_t *ppd);
ef416fc2 74#ifdef __sgi
75static void write_irix_config(cupsd_printer_t *p);
76static void write_irix_state(cupsd_printer_t *p);
77#endif /* __sgi */
78
79
80/*
81 * 'cupsdAddPrinter()' - Add a printer to the system.
82 */
83
84cupsd_printer_t * /* O - New printer */
85cupsdAddPrinter(const char *name) /* I - Name of printer */
86{
87 cupsd_printer_t *p; /* New printer */
88
89
90 /*
91 * Range check input...
92 */
93
94 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdAddPrinter(\"%s\")", name);
95
96 /*
97 * Create a new printer entity...
98 */
99
100 if ((p = calloc(1, sizeof(cupsd_printer_t))) == NULL)
101 {
102 cupsdLogMessage(CUPSD_LOG_CRIT, "Unable to allocate memory for printer - %s",
103 strerror(errno));
104 return (NULL);
105 }
106
107 cupsdSetString(&p->name, name);
108 cupsdSetString(&p->info, name);
109 cupsdSetString(&p->hostname, ServerName);
110
111 cupsdSetStringf(&p->uri, "ipp://%s:%d/printers/%s", ServerName, LocalPort, name);
112 cupsdSetStringf(&p->device_uri, "file:/dev/null");
113
114 p->state = IPP_PRINTER_STOPPED;
115 p->state_time = time(NULL);
116 p->accepting = 0;
fa73b229 117 p->shared = DefaultShared;
ef416fc2 118 p->filetype = mimeAddType(MimeDatabase, "printer", name);
119
120 cupsdSetString(&p->job_sheets[0], "none");
121 cupsdSetString(&p->job_sheets[1], "none");
122
123 cupsdSetString(&p->error_policy, "stop-printer");
124 cupsdSetString(&p->op_policy, DefaultPolicy);
125
126 p->op_policy_ptr = DefaultPolicyPtr;
127
128 if (MaxPrinterHistory)
129 p->history = calloc(MaxPrinterHistory, sizeof(ipp_t *));
130
131 /*
132 * Insert the printer in the printer list alphabetically...
133 */
134
135 if (!Printers)
136 Printers = cupsArrayNew(compare_printers, NULL);
137
138 cupsArrayAdd(Printers, p);
139
140 if (!ImplicitPrinters)
141 ImplicitPrinters = cupsArrayNew(compare_printers, NULL);
142
143 /*
144 * Return the new printer...
145 */
146
147 return (p);
148}
149
150
ef416fc2 151/*
152 * 'cupsdAddPrinterHistory()' - Add the current printer state to the history.
153 */
154
155void
156cupsdAddPrinterHistory(
157 cupsd_printer_t *p) /* I - Printer */
158{
159 ipp_t *history; /* History collection */
160
161
162 /*
163 * Stop early if we aren't keeping history data...
164 */
165
166 if (MaxPrinterHistory <= 0)
167 return;
168
169 /*
170 * Retire old history data as needed...
171 */
172
173 p->sequence_number ++;
174
175 if (p->num_history >= MaxPrinterHistory)
176 {
177 p->num_history --;
178 ippDelete(p->history[0]);
179 memmove(p->history, p->history + 1, p->num_history * sizeof(ipp_t *));
180 }
181
182 /*
183 * Create a collection containing the current printer-state, printer-up-time,
184 * printer-state-message, and printer-state-reasons attributes.
185 */
186
187 history = ippNew();
188 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
189 p->state);
190 ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-accepting-jobs",
191 p->accepting);
fa73b229 192 ippAddBoolean(history, IPP_TAG_PRINTER, "printer-is-shared", p->shared);
ef416fc2 193 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-state-message",
194 NULL, p->state_message);
e00b005a 195#ifdef __APPLE__
196 if (p->recoverable)
197 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_TEXT,
198 "com.apple.print.recoverable-message", NULL, p->recoverable);
199#endif /* __APPLE__ */
ef416fc2 200 if (p->num_reasons == 0)
201 ippAddString(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
202 "printer-state-reasons", NULL,
203 p->state == IPP_PRINTER_STOPPED ? "paused" : "none");
204 else
205 ippAddStrings(history, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
206 "printer-state-reasons", p->num_reasons, NULL,
207 (const char * const *)p->reasons);
208 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
209 "printer-state-change-time", p->state_time);
210 ippAddInteger(history, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
211 "printer-state-sequence-number", p->sequence_number);
212
213 p->history[p->num_history] = history;
214 p->num_history ++;
215}
216
217
218/*
219 * 'cupsdAddPrinterUser()' - Add a user to the ACL.
220 */
221
222void
223cupsdAddPrinterUser(
224 cupsd_printer_t *p, /* I - Printer */
225 const char *username) /* I - User */
226{
227 const char **temp; /* Temporary array pointer */
228
229
230 if (!p || !username)
231 return;
232
233 if (p->num_users == 0)
234 temp = malloc(sizeof(char **));
235 else
236 temp = realloc(p->users, sizeof(char **) * (p->num_users + 1));
237
238 if (!temp)
239 return;
240
241 p->users = temp;
242 temp += p->num_users;
243
244 if ((*temp = strdup(username)) != NULL)
245 p->num_users ++;
246}
247
248
249/*
250 * 'cupsdCreateCommonData()' - Create the common printer data.
251 */
252
253void
254cupsdCreateCommonData(void)
255{
256 int i; /* Looping var */
257 ipp_attribute_t *attr; /* Attribute data */
258 static const int nups[] = /* number-up-supported values */
259 { 1, 2, 4, 6, 9, 16 };
260 static const ipp_orient_t orients[4] =/* orientation-requested-supported values */
261 {
262 IPP_PORTRAIT,
263 IPP_LANDSCAPE,
264 IPP_REVERSE_LANDSCAPE,
265 IPP_REVERSE_PORTRAIT
266 };
267 static const char * const holds[] = /* job-hold-until-supported values */
268 {
269 "no-hold",
270 "indefinite",
271 "day-time",
272 "evening",
273 "night",
274 "second-shift",
275 "third-shift",
276 "weekend"
277 };
278 static const char * const versions[] =/* ipp-versions-supported values */
279 {
280 "1.0",
281 "1.1"
282 };
283 static const ipp_op_t ops[] = /* operations-supported values */
284 {
285 IPP_PRINT_JOB,
286 IPP_VALIDATE_JOB,
287 IPP_CREATE_JOB,
288 IPP_SEND_DOCUMENT,
289 IPP_CANCEL_JOB,
290 IPP_GET_JOB_ATTRIBUTES,
291 IPP_GET_JOBS,
292 IPP_GET_PRINTER_ATTRIBUTES,
293 IPP_HOLD_JOB,
294 IPP_RELEASE_JOB,
295 IPP_PAUSE_PRINTER,
296 IPP_RESUME_PRINTER,
297 IPP_PURGE_JOBS,
298 IPP_SET_JOB_ATTRIBUTES,
299 IPP_CREATE_PRINTER_SUBSCRIPTION,
300 IPP_CREATE_JOB_SUBSCRIPTION,
301 IPP_GET_SUBSCRIPTION_ATTRIBUTES,
302 IPP_GET_SUBSCRIPTIONS,
303 IPP_RENEW_SUBSCRIPTION,
304 IPP_CANCEL_SUBSCRIPTION,
305 IPP_GET_NOTIFICATIONS,
306 IPP_ENABLE_PRINTER,
307 IPP_DISABLE_PRINTER,
308 CUPS_GET_DEFAULT,
309 CUPS_GET_PRINTERS,
310 CUPS_ADD_PRINTER,
311 CUPS_DELETE_PRINTER,
312 CUPS_GET_CLASSES,
313 CUPS_ADD_CLASS,
314 CUPS_DELETE_CLASS,
315 CUPS_ACCEPT_JOBS,
316 CUPS_REJECT_JOBS,
317 CUPS_SET_DEFAULT,
318 CUPS_GET_DEVICES,
319 CUPS_GET_PPDS,
320 CUPS_MOVE_JOB,
321 CUPS_AUTHENTICATE_JOB,
322 IPP_RESTART_JOB
323 };
324 static const char * const charsets[] =/* charset-supported values */
325 {
326 "us-ascii",
327 "utf-8"
328 };
329 static const char * const compressions[] =
330 { /* document-compression-supported values */
331 "none"
332#ifdef HAVE_LIBZ
333 ,"gzip"
334#endif /* HAVE_LIBZ */
335 };
336 static const char * const multiple_document_handling[] =
337 { /* multiple-document-handling-supported values */
338 "separate-documents-uncollated-copies",
339 "separate-documents-collated-copies"
340 };
341 static const char * const errors[] = /* printer-error-policy-supported values */
342 {
343 "abort-job",
344 "retry-job",
345 "stop-printer"
346 };
347 static const char * const notify_attrs[] =
348 { /* notify-attributes-supported values */
349 "printer-state-change-time",
350 "notify-lease-expiration-time",
351 "notify-subscriber-user-name"
352 };
353 static const char * const notify_events[] =
354 { /* notify-events-supported values */
355 "job-completed",
356 "job-config-changed",
357 "job-created",
358 "job-progress",
359 "job-state-changed",
360 "job-stopped",
361 "printer-added",
362 "printer-changed",
363 "printer-config-changed",
364 "printer-deleted",
365 "printer-finishings-changed",
366 "printer-media-changed",
367 "printer-modified",
368 "printer-restarted",
369 "printer-shutdown",
370 "printer-state-changed",
371 "printer-stopped",
372 "server-audit",
373 "server-restarted",
374 "server-started",
375 "server-stopped"
376 };
377
378
379 if (CommonData)
380 ippDelete(CommonData);
381
382 CommonData = ippNew();
383
384 /*
385 * This list of attributes is sorted to improve performance when the
386 * client provides a requested-attributes attribute...
387 */
388
389 /* charset-configured */
390 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
391 "charset-configured", NULL, DefaultCharset);
392
393 /* charset-supported */
394 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_CHARSET,
395 "charset-supported", sizeof(charsets) / sizeof(charsets[0]),
396 NULL, charsets);
397
398 /* compression-supported */
399 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
400 "compression-supported",
401 sizeof(compressions) / sizeof(compressions[0]),
402 NULL, compressions);
403
404 /* TODO: move to printer-specific section! */
405 /* copies-default */
406 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
407 "copies-default", 1);
408
409 /* copies-supported */
410 ippAddRange(CommonData, IPP_TAG_PRINTER, "copies-supported", 1, MaxCopies);
411
412 /* TODO: move to printer-specific section! */
413 /* document-format-default */
414 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
415 "document-format-default", NULL, "application/octet-stream");
416
ef416fc2 417 /* generated-natural-language-supported */
418 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
419 "generated-natural-language-supported", NULL, DefaultLanguage);
420
421 /* ipp-versions-supported */
422 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
423 "ipp-versions-supported", sizeof(versions) / sizeof(versions[0]),
424 NULL, versions);
425
426 /* TODO: move to printer-specific section! */
427 /* job-hold-until-default */
428 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
429 "job-hold-until-default", NULL, "no-hold");
430
431 /* job-hold-until-supported */
432 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
433 "job-hold-until-supported", sizeof(holds) / sizeof(holds[0]),
434 NULL, holds);
435
436 /* TODO: move to printer-specific section! */
437 /* job-priority-default */
438 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
439 "job-priority-default", 50);
440
441 /* job-priority-supported */
442 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
443 "job-priority-supported", 100);
444
445 /* job-sheets-supported */
fa73b229 446 if (cupsArrayCount(Banners) > 0)
ef416fc2 447 {
448 /*
449 * Setup the job-sheets-supported attribute...
450 */
451
452 if (Classification && !ClassifyOverride)
453 attr = ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
454 "job-sheets-supported", NULL, Classification);
455 else
456 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
fa73b229 457 "job-sheets-supported", cupsArrayCount(Banners) + 1,
458 NULL, NULL);
ef416fc2 459
460 if (attr == NULL)
461 cupsdLogMessage(CUPSD_LOG_EMERG,
bd7854cb 462 "Unable to allocate memory for "
ef416fc2 463 "job-sheets-supported attribute: %s!", strerror(errno));
464 else if (!Classification || ClassifyOverride)
465 {
fa73b229 466 cupsd_banner_t *banner; /* Current banner */
467
468
4400e98d 469 attr->values[0].string.text = _cups_sp_alloc("none");
ef416fc2 470
fa73b229 471 for (i = 1, banner = (cupsd_banner_t *)cupsArrayFirst(Banners);
472 banner;
473 i ++, banner = (cupsd_banner_t *)cupsArrayNext(Banners))
4400e98d 474 attr->values[i].string.text = _cups_sp_alloc(banner->name);
ef416fc2 475 }
476 }
477 else
478 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
479 "job-sheets-supported", NULL, "none");
480
481 /* multiple-document-handling-supported */
482 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
483 "multiple-document-handling-supported",
484 sizeof(multiple_document_handling) /
485 sizeof(multiple_document_handling[0]), NULL,
486 multiple_document_handling);
487
488 /* multiple-document-jobs-supported */
489 ippAddBoolean(CommonData, IPP_TAG_PRINTER,
490 "multiple-document-jobs-supported", 1);
491
492 /* multiple-operation-time-out */
493 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
494 "multiple-operation-time-out", 60);
495
496 /* natural-language-configured */
497 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_LANGUAGE,
498 "natural-language-configured", NULL, DefaultLanguage);
499
500 /* notify-attributes-supported */
501 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
502 "notify-attributes-supported",
503 (int)(sizeof(notify_attrs) / sizeof(notify_attrs[0])),
504 NULL, notify_attrs);
505
506 /* TODO: move to printer-specific section! */
507 /* notify-lease-duration-default */
508 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
509 "notify-lease-duration-default", DefaultLeaseDuration);
510
511 /* notify-lease-duration-supported */
512 ippAddRange(CommonData, IPP_TAG_PRINTER,
513 "notify-lease-duration-supported", 0,
514 MaxLeaseDuration ? MaxLeaseDuration : 2147483647);
515
516 /* notify-max-events-supported */
517 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
518 "notify-max-events-supported", MaxEvents);
519
520 /* notify-notify-events-default */
521 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
522 "notify-events-default", NULL, "job-completed");
523
524 /* notify-notify-events-supported */
525 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
526 "notify-events-supported",
527 (int)(sizeof(notify_events) / sizeof(notify_events[0])),
528 NULL, notify_events);
529
530 /* notify-pull-method-supported */
531 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
532 "notify-pull-method-supported", NULL, "ippget");
533
534 /* TODO: scan notifier directory */
535 /* notify-schemes-supported */
536 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
537 "notify-schemes-supported", NULL, "mailto");
538
539 /* TODO: move to printer-specific section! */
540 /* number-up-default */
541 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
542 "number-up-default", 1);
543
544 /* number-up-supported */
545 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
546 "number-up-supported", sizeof(nups) / sizeof(nups[0]), nups);
547
548 /* operations-supported */
549 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
550 "operations-supported",
551 sizeof(ops) / sizeof(ops[0]) + JobFiles - 1, (int *)ops);
552
553 /* TODO: move to printer-specific section! */
554 /* orientation-requested-default */
555 ippAddInteger(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
556 "orientation-requested-default", IPP_PORTRAIT);
557
558 /* orientation-requested-supported */
559 ippAddIntegers(CommonData, IPP_TAG_PRINTER, IPP_TAG_ENUM,
560 "orientation-requested-supported", 4, (int *)orients);
561
562 /* page-ranges-supported */
563 ippAddBoolean(CommonData, IPP_TAG_PRINTER, "page-ranges-supported", 1);
564
565 /* pdf-override-supported */
566 ippAddString(CommonData, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
567 "pdl-override-supported", NULL, "not-attempted");
568
569 /* printer-error-policy-supported */
570 ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
571 "printer-error-policy-supported",
572 sizeof(errors) / sizeof(errors[0]), NULL, errors);
573
574 /* printer-op-policy-supported */
575 attr = ippAddStrings(CommonData, IPP_TAG_PRINTER, IPP_TAG_NAME,
576 "printer-op-policy-supported", NumPolicies, NULL, NULL);
577 for (i = 0; i < NumPolicies; i ++)
4400e98d 578 attr->values[i].string.text = _cups_sp_alloc(Policies[i]->name);
ef416fc2 579}
580
581
582/*
583 * 'cupsdDeleteAllPrinters()' - Delete all printers from the system.
584 */
585
586void
587cupsdDeleteAllPrinters(void)
588{
589 cupsd_printer_t *p; /* Pointer to current printer/class */
590
591
592 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
593 p;
594 p = (cupsd_printer_t *)cupsArrayNext(Printers))
595 if (!(p->type & CUPS_PRINTER_CLASS))
596 cupsdDeletePrinter(p, 0);
597}
598
599
600/*
601 * 'cupsdDeletePrinter()' - Delete a printer from the system.
602 */
603
604void
605cupsdDeletePrinter(
606 cupsd_printer_t *p, /* I - Printer to delete */
607 int update) /* I - Update printers.conf? */
608{
609 int i; /* Looping var */
610#ifdef __sgi
611 char filename[1024]; /* Interface script filename */
612#endif /* __sgi */
613
614
615 cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdDeletePrinter(p=%p(%s), update=%d)",
616 p, p->name, update);
617
618 /*
619 * Save the current position in the Printers array...
620 */
621
622 cupsArraySave(Printers);
623
624 /*
625 * Stop printing on this printer...
626 */
627
628 cupsdStopPrinter(p, update);
629
630 /*
631 * If this printer is the next for browsing, point to the next one...
632 */
633
634 if (p == BrowseNext)
635 {
636 cupsArrayFind(Printers, p);
637 BrowseNext = (cupsd_printer_t *)cupsArrayNext(Printers);
638 }
639
640 /*
641 * Remove the printer from the list...
642 */
643
644 cupsArrayRemove(Printers, p);
645
646 /*
647 * Remove the dummy interface/icon/option files under IRIX...
648 */
649
650#ifdef __sgi
651 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
652 unlink(filename);
653
654 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui",
655 p->name);
656 unlink(filename);
657
658 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
659 unlink(filename);
660
661 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
662 unlink(filename);
663
664 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
665 unlink(filename);
666
667 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
668 unlink(filename);
669#endif /* __sgi */
670
671 /*
e00b005a 672 * If p is the default printer, assign a different one...
ef416fc2 673 */
674
675 if (p == DefaultPrinter)
e00b005a 676 {
677 DefaultPrinter = NULL;
678
679 if (UseNetworkDefault)
680 {
681 /*
682 * Find the first network default printer and use it...
683 */
684
685 cupsd_printer_t *dp; /* New default printer */
686
687
688 for (dp = (cupsd_printer_t *)cupsArrayFirst(Printers);
689 dp;
690 dp = (cupsd_printer_t *)cupsArrayNext(Printers))
691 if (dp != p && (dp->type & CUPS_PRINTER_DEFAULT))
692 {
693 DefaultPrinter = p;
694 break;
695 }
696 }
697 }
ef416fc2 698
699 /*
700 * Remove this printer from any classes and send a browse delete message...
701 */
702
703 if (!(p->type & CUPS_PRINTER_IMPLICIT))
704 {
705 cupsdDeletePrinterFromClasses(p);
706 cupsdSendBrowseDelete(p);
707 }
708
709 /*
710 * Free all memory used by the printer...
711 */
712
713 if (p->printers != NULL)
714 free(p->printers);
715
716 if (MaxPrinterHistory)
717 {
718 for (i = 0; i < p->num_history; i ++)
719 ippDelete(p->history[i]);
720
721 free(p->history);
722 }
723
724 for (i = 0; i < p->num_reasons; i ++)
725 free(p->reasons[i]);
726
727 ippDelete(p->attrs);
728
729 cupsdDeletePrinterFilters(p);
730
fa73b229 731 mimeDeleteType(MimeDatabase, p->filetype);
732
ef416fc2 733 cupsdFreePrinterUsers(p);
734 cupsdFreeQuotas(p);
735
736 cupsdClearString(&p->uri);
737 cupsdClearString(&p->hostname);
738 cupsdClearString(&p->name);
739 cupsdClearString(&p->location);
740 cupsdClearString(&p->make_model);
741 cupsdClearString(&p->info);
742 cupsdClearString(&p->job_sheets[0]);
743 cupsdClearString(&p->job_sheets[1]);
744 cupsdClearString(&p->device_uri);
745 cupsdClearString(&p->port_monitor);
746 cupsdClearString(&p->op_policy);
747 cupsdClearString(&p->error_policy);
748
e00b005a 749#ifdef __APPLE__
750 cupsdClearString(&p->recoverable);
751#endif /* __APPLE__ */
752
ef416fc2 753 free(p);
754
755 /*
756 * Restore the previous position in the Printers array...
757 */
758
759 cupsArrayRestore(Printers);
760}
761
762
763/*
764 * 'cupsdDeletePrinterFilters()' - Delete all MIME filters for a printer.
765 */
766
767void
768cupsdDeletePrinterFilters(
769 cupsd_printer_t *p) /* I - Printer to remove from */
770{
ef416fc2 771 mime_filter_t *filter; /* MIME filter looping var */
772
773
774 /*
775 * Range check input...
776 */
777
778 if (p == NULL)
779 return;
780
781 /*
782 * Remove all filters from the MIME database that have a destination
783 * type == printer...
784 */
785
fa73b229 786 for (filter = mimeFirstFilter(MimeDatabase);
787 filter;
788 filter = mimeNextFilter(MimeDatabase))
ef416fc2 789 if (filter->dst == p->filetype)
790 {
791 /*
792 * Delete the current filter...
793 */
794
fa73b229 795 mimeDeleteFilter(MimeDatabase, filter);
ef416fc2 796 }
797}
798
799
800/*
801 * 'cupsdFindDest()' - Find a destination in the list.
802 */
803
804cupsd_printer_t * /* O - Destination in list */
805cupsdFindDest(const char *name) /* I - Name of printer or class to find */
806{
807 cupsd_printer_t key; /* Search key */
808
809
810 key.name = (char *)name;
811 return ((cupsd_printer_t *)cupsArrayFind(Printers, &key));
812}
813
814
815/*
816 * 'cupsdFindPrinter()' - Find a printer in the list.
817 */
818
819cupsd_printer_t * /* O - Printer in list */
820cupsdFindPrinter(const char *name) /* I - Name of printer to find */
821{
822 cupsd_printer_t *p; /* Printer in list */
823
824
825 if ((p = cupsdFindDest(name)) != NULL && (p->type & CUPS_PRINTER_CLASS))
826 return (NULL);
827 else
828 return (p);
829}
830
831
832/*
833 * 'cupsdFreePrinterUsers()' - Free allow/deny users.
834 */
835
836void
837cupsdFreePrinterUsers(
838 cupsd_printer_t *p) /* I - Printer */
839{
840 int i; /* Looping var */
841
842
843 if (!p || !p->num_users)
844 return;
845
846 for (i = 0; i < p->num_users; i ++)
847 free((void *)p->users[i]);
848
849 free(p->users);
850
851 p->num_users = 0;
852 p->users = NULL;
853}
854
855
856/*
857 * 'cupsdLoadAllPrinters()' - Load printers from the printers.conf file.
858 */
859
860void
861cupsdLoadAllPrinters(void)
862{
863 cups_file_t *fp; /* printers.conf file */
864 int linenum; /* Current line number */
865 char line[1024], /* Line from file */
866 *value, /* Pointer to value */
867 *valueptr; /* Pointer into value */
868 cupsd_printer_t *p; /* Current printer */
869
870
871 /*
872 * Open the printers.conf file...
873 */
874
875 snprintf(line, sizeof(line), "%s/printers.conf", ServerRoot);
876 if ((fp = cupsFileOpen(line, "r")) == NULL)
877 {
fa73b229 878 if (errno != ENOENT)
bd7854cb 879 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to open %s - %s", line,
fa73b229 880 strerror(errno));
ef416fc2 881 return;
882 }
883
884 /*
885 * Read printer configurations until we hit EOF...
886 */
887
888 linenum = 0;
889 p = NULL;
890
891 while (cupsFileGetConf(fp, line, sizeof(line), &value, &linenum))
892 {
893 /*
894 * Decode the directive...
895 */
896
897 if (!strcasecmp(line, "<Printer") ||
898 !strcasecmp(line, "<DefaultPrinter"))
899 {
900 /*
901 * <Printer name> or <DefaultPrinter name>
902 */
903
904 if (p == NULL && value)
905 {
906 /*
907 * Add the printer and a base file type...
908 */
909
bd7854cb 910 cupsdLogMessage(CUPSD_LOG_DEBUG, "Loading printer %s...", value);
ef416fc2 911
912 p = cupsdAddPrinter(value);
913 p->accepting = 1;
914 p->state = IPP_PRINTER_IDLE;
915
916 /*
917 * Set the default printer as needed...
918 */
919
920 if (!strcasecmp(line, "<DefaultPrinter"))
921 DefaultPrinter = p;
922 }
923 else
924 {
925 cupsdLogMessage(CUPSD_LOG_ERROR,
926 "Syntax error on line %d of printers.conf.", linenum);
927 return;
928 }
929 }
930 else if (!strcasecmp(line, "</Printer>"))
931 {
932 if (p != NULL)
933 {
934 /*
935 * Close out the current printer...
936 */
937
938 cupsdSetPrinterAttrs(p);
939 cupsdAddPrinterHistory(p);
940
941 if (p->device_uri && strncmp(p->device_uri, "file:", 5) &&
942 p->state != IPP_PRINTER_STOPPED)
943 {
944 /*
945 * See if the backend exists...
946 */
947
948 snprintf(line, sizeof(line), "%s/backend/%s", ServerBin,
949 p->device_uri);
950
951 if ((valueptr = strchr(line + strlen(ServerBin), ':')) != NULL)
952 *valueptr = '\0'; /* Chop everything but URI scheme */
953
954 if (access(line, 0))
955 {
956 /*
957 * Backend does not exist, stop printer...
958 */
959
960 p->state = IPP_PRINTER_STOPPED;
961 snprintf(p->state_message, sizeof(p->state_message),
962 "Backend %s does not exist!", line);
963 }
964 }
965
966 p = NULL;
967 }
968 else
969 {
970 cupsdLogMessage(CUPSD_LOG_ERROR,
971 "Syntax error on line %d of printers.conf.", linenum);
972 return;
973 }
974 }
975 else if (!p)
976 {
977 cupsdLogMessage(CUPSD_LOG_ERROR,
978 "Syntax error on line %d of printers.conf.", linenum);
979 return;
980 }
981 else if (!strcasecmp(line, "Info"))
982 {
983 if (value)
984 cupsdSetString(&p->info, value);
985 }
986 else if (!strcasecmp(line, "Location"))
987 {
988 if (value)
989 cupsdSetString(&p->location, value);
990 }
991 else if (!strcasecmp(line, "DeviceURI"))
992 {
993 if (value)
994 cupsdSetString(&p->device_uri, value);
995 else
996 {
997 cupsdLogMessage(CUPSD_LOG_ERROR,
998 "Syntax error on line %d of printers.conf.", linenum);
999 return;
1000 }
1001 }
1002 else if (!strcasecmp(line, "PortMonitor"))
1003 {
1004 if (value && strcmp(value, "none"))
1005 cupsdSetString(&p->port_monitor, value);
1006 else if (value)
1007 cupsdClearString(&p->port_monitor);
1008 else
1009 {
1010 cupsdLogMessage(CUPSD_LOG_ERROR,
1011 "Syntax error on line %d of printers.conf.", linenum);
1012 return;
1013 }
1014 }
1015 else if (!strcasecmp(line, "State"))
1016 {
1017 /*
1018 * Set the initial queue state...
1019 */
1020
1021 if (value && !strcasecmp(value, "idle"))
1022 p->state = IPP_PRINTER_IDLE;
1023 else if (value && !strcasecmp(value, "stopped"))
1024 p->state = IPP_PRINTER_STOPPED;
1025 else
1026 {
1027 cupsdLogMessage(CUPSD_LOG_ERROR,
1028 "Syntax error on line %d of printers.conf.", linenum);
1029 return;
1030 }
1031 }
1032 else if (!strcasecmp(line, "StateMessage"))
1033 {
1034 /*
1035 * Set the initial queue state message...
1036 */
1037
1038 if (value)
1039 strlcpy(p->state_message, value, sizeof(p->state_message));
1040 }
1041 else if (!strcasecmp(line, "StateTime"))
1042 {
1043 /*
1044 * Set the state time...
1045 */
1046
1047 if (value)
1048 p->state_time = atoi(value);
1049 }
1050 else if (!strcasecmp(line, "Accepting"))
1051 {
1052 /*
1053 * Set the initial accepting state...
1054 */
1055
1056 if (value &&
1057 (!strcasecmp(value, "yes") ||
1058 !strcasecmp(value, "on") ||
1059 !strcasecmp(value, "true")))
1060 p->accepting = 1;
1061 else if (value &&
1062 (!strcasecmp(value, "no") ||
1063 !strcasecmp(value, "off") ||
1064 !strcasecmp(value, "false")))
1065 p->accepting = 0;
1066 else
1067 {
1068 cupsdLogMessage(CUPSD_LOG_ERROR,
1069 "Syntax error on line %d of printers.conf.", linenum);
1070 return;
1071 }
1072 }
1073 else if (!strcasecmp(line, "Shared"))
1074 {
1075 /*
1076 * Set the initial shared state...
1077 */
1078
1079 if (value &&
1080 (!strcasecmp(value, "yes") ||
1081 !strcasecmp(value, "on") ||
1082 !strcasecmp(value, "true")))
1083 p->shared = 1;
1084 else if (value &&
1085 (!strcasecmp(value, "no") ||
1086 !strcasecmp(value, "off") ||
1087 !strcasecmp(value, "false")))
1088 p->shared = 0;
1089 else
1090 {
1091 cupsdLogMessage(CUPSD_LOG_ERROR,
1092 "Syntax error on line %d of printers.conf.", linenum);
1093 return;
1094 }
1095 }
1096 else if (!strcasecmp(line, "JobSheets"))
1097 {
1098 /*
1099 * Set the initial job sheets...
1100 */
1101
1102 if (value)
1103 {
1104 for (valueptr = value; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1105
1106 if (*valueptr)
1107 *valueptr++ = '\0';
1108
1109 cupsdSetString(&p->job_sheets[0], value);
1110
1111 while (isspace(*valueptr & 255))
1112 valueptr ++;
1113
1114 if (*valueptr)
1115 {
1116 for (value = valueptr; *valueptr && !isspace(*valueptr & 255); valueptr ++);
1117
1118 if (*valueptr)
1119 *valueptr++ = '\0';
1120
1121 cupsdSetString(&p->job_sheets[1], value);
1122 }
1123 }
1124 else
1125 {
1126 cupsdLogMessage(CUPSD_LOG_ERROR,
1127 "Syntax error on line %d of printers.conf.", linenum);
1128 return;
1129 }
1130 }
1131 else if (!strcasecmp(line, "AllowUser"))
1132 {
1133 if (value)
1134 {
1135 p->deny_users = 0;
1136 cupsdAddPrinterUser(p, value);
1137 }
1138 else
1139 {
1140 cupsdLogMessage(CUPSD_LOG_ERROR,
1141 "Syntax error on line %d of printers.conf.", linenum);
1142 return;
1143 }
1144 }
1145 else if (!strcasecmp(line, "DenyUser"))
1146 {
1147 if (value)
1148 {
1149 p->deny_users = 1;
1150 cupsdAddPrinterUser(p, value);
1151 }
1152 else
1153 {
1154 cupsdLogMessage(CUPSD_LOG_ERROR,
1155 "Syntax error on line %d of printers.conf.", linenum);
1156 return;
1157 }
1158 }
1159 else if (!strcasecmp(line, "QuotaPeriod"))
1160 {
1161 if (value)
1162 p->quota_period = atoi(value);
1163 else
1164 {
1165 cupsdLogMessage(CUPSD_LOG_ERROR,
1166 "Syntax error on line %d of printers.conf.", linenum);
1167 return;
1168 }
1169 }
1170 else if (!strcasecmp(line, "PageLimit"))
1171 {
1172 if (value)
1173 p->page_limit = atoi(value);
1174 else
1175 {
1176 cupsdLogMessage(CUPSD_LOG_ERROR,
1177 "Syntax error on line %d of printers.conf.", linenum);
1178 return;
1179 }
1180 }
1181 else if (!strcasecmp(line, "KLimit"))
1182 {
1183 if (value)
1184 p->k_limit = atoi(value);
1185 else
1186 {
1187 cupsdLogMessage(CUPSD_LOG_ERROR,
1188 "Syntax error on line %d of printers.conf.", linenum);
1189 return;
1190 }
1191 }
1192 else if (!strcasecmp(line, "OpPolicy"))
1193 {
1194 if (value)
1195 cupsdSetString(&p->op_policy, value);
1196 else
1197 {
1198 cupsdLogMessage(CUPSD_LOG_ERROR,
1199 "Syntax error on line %d of printers.conf.", linenum);
1200 return;
1201 }
1202 }
1203 else if (!strcasecmp(line, "ErrorPolicy"))
1204 {
1205 if (value)
1206 cupsdSetString(&p->error_policy, value);
1207 else
1208 {
1209 cupsdLogMessage(CUPSD_LOG_ERROR,
1210 "Syntax error on line %d of printers.conf.", linenum);
1211 return;
1212 }
1213 }
1214 else
1215 {
1216 /*
1217 * Something else we don't understand...
1218 */
1219
1220 cupsdLogMessage(CUPSD_LOG_ERROR,
1221 "Unknown configuration directive %s on line %d of printers.conf.",
1222 line, linenum);
1223 }
1224 }
1225
1226 cupsFileClose(fp);
1227}
1228
1229
1230/*
1231 * 'cupsdSaveAllPrinters()' - Save all printer definitions to the printers.conf
1232 * file.
1233 */
1234
1235void
1236cupsdSaveAllPrinters(void)
1237{
1238 int i; /* Looping var */
1239 cups_file_t *fp; /* printers.conf file */
1240 char temp[1024]; /* Temporary string */
1241 char backup[1024]; /* printers.conf.O file */
1242 cupsd_printer_t *printer; /* Current printer class */
1243 time_t curtime; /* Current time */
1244 struct tm *curdate; /* Current date */
1245
1246
1247 /*
1248 * Create the printers.conf file...
1249 */
1250
1251 snprintf(temp, sizeof(temp), "%s/printers.conf", ServerRoot);
1252 snprintf(backup, sizeof(backup), "%s/printers.conf.O", ServerRoot);
1253
1254 if (rename(temp, backup))
1255 {
1256 if (errno != ENOENT)
1257 cupsdLogMessage(CUPSD_LOG_ERROR,
1258 "Unable to backup printers.conf - %s", strerror(errno));
1259 }
1260
1261 if ((fp = cupsFileOpen(temp, "w")) == NULL)
1262 {
1263 cupsdLogMessage(CUPSD_LOG_ERROR,
1264 "Unable to save printers.conf - %s", strerror(errno));
1265
1266 if (rename(backup, temp))
1267 cupsdLogMessage(CUPSD_LOG_ERROR,
1268 "Unable to restore printers.conf - %s", strerror(errno));
1269 return;
1270 }
1271 else
1272 cupsdLogMessage(CUPSD_LOG_INFO, "Saving printers.conf...");
1273
1274 /*
1275 * Restrict access to the file...
1276 */
1277
1278 fchown(cupsFileNumber(fp), getuid(), Group);
fa73b229 1279 fchmod(cupsFileNumber(fp), 0600);
ef416fc2 1280
1281 /*
1282 * Write a small header to the file...
1283 */
1284
1285 curtime = time(NULL);
1286 curdate = localtime(&curtime);
1287 strftime(temp, sizeof(temp) - 1, "%Y-%m-%d %H:%M", curdate);
1288
1289 cupsFilePuts(fp, "# Printer configuration file for " CUPS_SVERSION "\n");
1290 cupsFilePrintf(fp, "# Written by cupsd on %s\n", temp);
1291
1292 /*
1293 * Write each local printer known to the system...
1294 */
1295
1296 for (printer = (cupsd_printer_t *)cupsArrayFirst(Printers);
1297 printer;
1298 printer = (cupsd_printer_t *)cupsArrayNext(Printers))
1299 {
1300 /*
1301 * Skip remote destinations and printer classes...
1302 */
1303
1304 if ((printer->type & CUPS_PRINTER_REMOTE) ||
1305 (printer->type & CUPS_PRINTER_CLASS) ||
1306 (printer->type & CUPS_PRINTER_IMPLICIT))
1307 continue;
1308
1309 /*
1310 * Write printers as needed...
1311 */
1312
1313 if (printer == DefaultPrinter)
1314 cupsFilePrintf(fp, "<DefaultPrinter %s>\n", printer->name);
1315 else
1316 cupsFilePrintf(fp, "<Printer %s>\n", printer->name);
1317
1318 if (printer->info)
1319 cupsFilePrintf(fp, "Info %s\n", printer->info);
1320
1321 if (printer->location)
1322 cupsFilePrintf(fp, "Location %s\n", printer->location);
1323
1324 if (printer->device_uri)
1325 cupsFilePrintf(fp, "DeviceURI %s\n", printer->device_uri);
1326
1327 if (printer->port_monitor)
1328 cupsFilePrintf(fp, "PortMonitor %s\n", printer->port_monitor);
1329
1330 if (printer->state == IPP_PRINTER_STOPPED)
1331 {
1332 cupsFilePuts(fp, "State Stopped\n");
1333 cupsFilePrintf(fp, "StateMessage %s\n", printer->state_message);
1334 }
1335 else
1336 cupsFilePuts(fp, "State Idle\n");
1337
1338 cupsFilePrintf(fp, "StateTime %d\n", (int)printer->state_time);
1339
1340 if (printer->accepting)
1341 cupsFilePuts(fp, "Accepting Yes\n");
1342 else
1343 cupsFilePuts(fp, "Accepting No\n");
1344
1345 if (printer->shared)
1346 cupsFilePuts(fp, "Shared Yes\n");
1347 else
1348 cupsFilePuts(fp, "Shared No\n");
1349
1350 cupsFilePrintf(fp, "JobSheets %s %s\n", printer->job_sheets[0],
1351 printer->job_sheets[1]);
1352
1353 cupsFilePrintf(fp, "QuotaPeriod %d\n", printer->quota_period);
1354 cupsFilePrintf(fp, "PageLimit %d\n", printer->page_limit);
1355 cupsFilePrintf(fp, "KLimit %d\n", printer->k_limit);
1356
1357 for (i = 0; i < printer->num_users; i ++)
1358 cupsFilePrintf(fp, "%sUser %s\n", printer->deny_users ? "Deny" : "Allow",
1359 printer->users[i]);
1360
1361 if (printer->op_policy)
1362 cupsFilePrintf(fp, "OpPolicy %s\n", printer->op_policy);
1363 if (printer->error_policy)
1364 cupsFilePrintf(fp, "ErrorPolicy %s\n", printer->error_policy);
1365
1366 cupsFilePuts(fp, "</Printer>\n");
1367
1368#ifdef __sgi
1369 /*
1370 * Make IRIX desktop & printer status happy
1371 */
1372
1373 write_irix_state(printer);
1374#endif /* __sgi */
1375 }
1376
1377 cupsFileClose(fp);
1378}
1379
1380
1381/*
1382 * 'cupsdSetPrinterAttrs()' - Set printer attributes based upon the PPD file.
1383 */
1384
1385void
1386cupsdSetPrinterAttrs(cupsd_printer_t *p)/* I - Printer to setup */
1387{
1388 char uri[HTTP_MAX_URI];
1389 /* URI for printer */
1390 char resource[HTTP_MAX_URI];
1391 /* Resource portion of URI */
1392 int i; /* Looping var */
1393 char filename[1024]; /* Name of PPD file */
1394 int num_media; /* Number of media options */
1395 cupsd_location_t *auth; /* Pointer to authentication element */
1396 const char *auth_supported;/* Authentication supported */
e00b005a 1397 cups_ptype_t printer_type; /* Printer type data */
ef416fc2 1398 ppd_file_t *ppd; /* PPD file data */
1399 ppd_option_t *input_slot, /* InputSlot options */
1400 *media_type, /* MediaType options */
1401 *page_size, /* PageSize options */
1402 *output_bin, /* OutputBin options */
1403 *media_quality; /* EFMediaQualityMode options */
1404 ppd_attr_t *ppdattr; /* PPD attribute */
1405 ipp_attribute_t *attr; /* Attribute data */
1406 ipp_value_t *val; /* Attribute value */
1407 int num_finishings; /* Number of finishings */
1408 ipp_finish_t finishings[5]; /* finishings-supported values */
1409 static const char * const sides[3] = /* sides-supported values */
1410 {
1411 "one",
1412 "two-long-edge",
1413 "two-short-edge"
1414 };
1415
1416
1417 DEBUG_printf(("cupsdSetPrinterAttrs: entering name = %s, type = %x\n", p->name,
1418 p->type));
1419
1420 /*
1421 * Make sure that we have the common attributes defined...
1422 */
1423
1424 if (!CommonData)
1425 cupsdCreateCommonData();
1426
1427 /*
1428 * Clear out old filters, if any...
1429 */
1430
1431 cupsdDeletePrinterFilters(p);
1432
1433 /*
1434 * Figure out the authentication that is required for the printer.
1435 */
1436
1437 auth_supported = "requesting-user-name";
1438 if (!(p->type & CUPS_PRINTER_REMOTE))
1439 {
1440 if (p->type & CUPS_PRINTER_CLASS)
1441 snprintf(resource, sizeof(resource), "/classes/%s", p->name);
1442 else
1443 snprintf(resource, sizeof(resource), "/printers/%s", p->name);
1444
1445 if ((auth = cupsdFindBest(resource, HTTP_POST)) == NULL)
1446 auth = cupsdFindPolicyOp(p->op_policy_ptr, IPP_PRINT_JOB);
1447
1448 if (auth)
1449 {
1450 if (auth->type == AUTH_BASIC || auth->type == AUTH_BASICDIGEST)
1451 auth_supported = "basic";
1452 else if (auth->type == AUTH_DIGEST)
1453 auth_supported = "digest";
1454
1455 if (auth->type != AUTH_NONE)
1456 p->type |= CUPS_PRINTER_AUTHENTICATED;
1457 else
1458 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
1459 }
1460 else
1461 p->type &= ~CUPS_PRINTER_AUTHENTICATED;
1462 }
1463
1464 /*
1465 * Create the required IPP attributes for a printer...
1466 */
1467
1468 if (p->attrs)
1469 ippDelete(p->attrs);
1470
1471 p->attrs = ippNew();
1472
1473 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1474 "uri-authentication-supported", NULL, auth_supported);
1475 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1476 "uri-security-supported", NULL, "none");
1477 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME, "printer-name", NULL,
1478 p->name);
1479 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-location",
1480 NULL, p->location ? p->location : "");
1481 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT, "printer-info",
1482 NULL, p->info ? p->info : "");
1483 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "printer-more-info",
1484 NULL, p->uri);
1485
1486 if (p->num_users)
1487 {
1488 if (p->deny_users)
1489 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1490 "requesting-user-name-denied", p->num_users, NULL,
1491 p->users);
1492 else
1493 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1494 "requesting-user-name-allowed", p->num_users, NULL,
1495 p->users);
1496 }
1497
1498 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1499 "job-quota-period", p->quota_period);
1500 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1501 "job-k-limit", p->k_limit);
1502 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1503 "job-page-limit", p->page_limit);
1504
fa73b229 1505 if (cupsArrayCount(Banners) > 0 && !(p->type & CUPS_PRINTER_REMOTE))
ef416fc2 1506 {
1507 /*
1508 * Setup the job-sheets-default attribute...
1509 */
1510
1511 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1512 "job-sheets-default", 2, NULL, NULL);
1513
1514 if (attr != NULL)
1515 {
4400e98d 1516 attr->values[0].string.text = _cups_sp_alloc(Classification ?
ef416fc2 1517 Classification : p->job_sheets[0]);
4400e98d 1518 attr->values[1].string.text = _cups_sp_alloc(Classification ?
ef416fc2 1519 Classification : p->job_sheets[1]);
1520 }
1521 }
1522
e00b005a 1523 printer_type = p->type;
ef416fc2 1524
1525 p->raw = 0;
1526
1527 if (p->type & CUPS_PRINTER_REMOTE)
1528 {
1529 /*
1530 * Tell the client this is a remote printer of some type...
1531 */
1532
1533 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
1534 "printer-uri-supported", NULL, p->uri);
1535
1536 if (p->make_model)
1537 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1538 "printer-make-and-model", NULL, p->make_model);
1539
fa73b229 1540 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
1541 p->uri);
1542
ef416fc2 1543 p->raw = 1;
1544 }
1545 else
1546 {
1547 /*
1548 * Assign additional attributes depending on whether this is a printer
1549 * or class...
1550 */
1551
1552 p->type &= ~CUPS_PRINTER_OPTIONS;
1553
1554 if (p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT))
1555 {
1556 p->raw = 1;
1557
1558 /*
1559 * Add class-specific attributes...
1560 */
1561
1562 if ((p->type & CUPS_PRINTER_IMPLICIT) && p->num_printers > 0 &&
1563 p->printers[0]->make_model)
1564 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1565 "printer-make-and-model", NULL, p->printers[0]->make_model);
1566 else
1567 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1568 "printer-make-and-model", NULL, "Local Printer Class");
1569
fa73b229 1570 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
1571 "file:///dev/null");
1572
ef416fc2 1573 if (p->num_printers > 0)
1574 {
1575 /*
1576 * Add a list of member URIs and names...
1577 */
1578
1579 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
1580 "member-uris", p->num_printers, NULL, NULL);
1581 p->type |= CUPS_PRINTER_OPTIONS;
1582
1583 for (i = 0; i < p->num_printers; i ++)
1584 {
1585 if (attr != NULL)
4400e98d 1586 attr->values[i].string.text = _cups_sp_alloc(p->printers[i]->uri);
ef416fc2 1587
1588 p->type &= ~CUPS_PRINTER_OPTIONS | p->printers[i]->type;
1589 }
1590
1591 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_NAME,
1592 "member-names", p->num_printers, NULL, NULL);
1593
1594 if (attr != NULL)
1595 {
1596 for (i = 0; i < p->num_printers; i ++)
4400e98d 1597 attr->values[i].string.text = _cups_sp_alloc(p->printers[i]->name);
ef416fc2 1598 }
1599 }
1600 }
1601 else
1602 {
1603 /*
1604 * Add printer-specific attributes... Start by sanitizing the device
1605 * URI so it doesn't have a username or password in it...
1606 */
1607
1608 if (!p->device_uri)
1609 strcpy(uri, "file:/dev/null");
1610 else if (strstr(p->device_uri, "://") != NULL)
1611 {
1612 /*
1613 * http://..., ipp://..., etc.
1614 */
1615
1616 cupsdSanitizeURI(p->device_uri, uri, sizeof(uri));
1617 }
1618 else
1619 {
1620 /*
1621 * file:..., serial:..., etc.
1622 */
1623
1624 strlcpy(uri, p->device_uri, sizeof(uri));
1625 }
1626
1627 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI, "device-uri", NULL,
1628 uri);
1629
1630 /*
1631 * Assign additional attributes from the PPD file (if any)...
1632 */
1633
1634 p->type |= CUPS_PRINTER_BW;
1635 finishings[0] = IPP_FINISHINGS_NONE;
1636 num_finishings = 1;
1637
1638 snprintf(filename, sizeof(filename), "%s/ppd/%s.ppd", ServerRoot,
1639 p->name);
1640
1641 if ((ppd = ppdOpenFile(filename)) != NULL)
1642 {
1643 /*
1644 * Add make/model and other various attributes...
1645 */
1646
1647 if (ppd->color_device)
1648 p->type |= CUPS_PRINTER_COLOR;
1649 if (ppd->variable_sizes)
1650 p->type |= CUPS_PRINTER_VARIABLE;
1651 if (!ppd->manual_copies)
1652 p->type |= CUPS_PRINTER_COPIES;
1653 if ((ppdattr = ppdFindAttr(ppd, "cupsFax", NULL)) != NULL)
1654 if (ppdattr->value && !strcasecmp(ppdattr->value, "true"))
1655 p->type |= CUPS_PRINTER_FAX;
1656
1657 ippAddBoolean(p->attrs, IPP_TAG_PRINTER, "color-supported",
1658 ppd->color_device);
1659 if (ppd->throughput)
1660 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_INTEGER,
1661 "pages-per-minute", ppd->throughput);
1662
1663 if (ppd->nickname)
bd7854cb 1664 {
1665 /*
1666 * The NickName can be localized in the character set specified
1667 * by the LanugageEncoding attribute. Convert as needed to
1668 * UTF-8...
1669 */
1670
1671 transcode_nickname(p, ppd);
1672 }
ef416fc2 1673 else if (ppd->modelname)
1674 cupsdSetString(&p->make_model, ppd->modelname);
1675 else
1676 cupsdSetString(&p->make_model, "Bad PPD File");
1677
bd7854cb 1678 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1679 "printer-make-and-model", NULL, p->make_model);
ef416fc2 1680
1681 /*
1682 * Add media options from the PPD file...
1683 */
1684
1685 if ((input_slot = ppdFindOption(ppd, "InputSlot")) != NULL)
1686 num_media = input_slot->num_choices;
1687 else
1688 num_media = 0;
1689
1690 if ((media_type = ppdFindOption(ppd, "MediaType")) != NULL)
1691 num_media += media_type->num_choices;
1692
1693 if ((page_size = ppdFindOption(ppd, "PageSize")) != NULL)
1694 num_media += page_size->num_choices;
1695
1696 if ((media_quality = ppdFindOption(ppd, "EFMediaQualityMode")) != NULL)
1697 num_media += media_quality->num_choices;
1698
1699 if (num_media == 0)
1700 {
bd7854cb 1701 cupsdLogMessage(CUPSD_LOG_CRIT,
1702 "The PPD file for printer %s "
1703 "contains no media options and is therefore "
1704 "invalid!", p->name);
ef416fc2 1705 }
1706 else
1707 {
1708 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1709 "media-supported", num_media, NULL, NULL);
1710 if (attr != NULL)
1711 {
1712 val = attr->values;
1713
1714 if (input_slot != NULL)
1715 for (i = 0; i < input_slot->num_choices; i ++, val ++)
4400e98d 1716 val->string.text = _cups_sp_alloc(input_slot->choices[i].choice);
ef416fc2 1717
1718 if (media_type != NULL)
1719 for (i = 0; i < media_type->num_choices; i ++, val ++)
4400e98d 1720 val->string.text = _cups_sp_alloc(media_type->choices[i].choice);
ef416fc2 1721
1722 if (media_quality != NULL)
1723 for (i = 0; i < media_quality->num_choices; i ++, val ++)
4400e98d 1724 val->string.text = _cups_sp_alloc(media_quality->choices[i].choice);
ef416fc2 1725
1726 if (page_size != NULL)
1727 {
1728 for (i = 0; i < page_size->num_choices; i ++, val ++)
4400e98d 1729 val->string.text = _cups_sp_alloc(page_size->choices[i].choice);
ef416fc2 1730
1731 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
1732 NULL, page_size->defchoice);
1733 }
1734 else if (input_slot != NULL)
1735 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
1736 NULL, input_slot->defchoice);
1737 else if (media_type != NULL)
1738 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
1739 NULL, media_type->defchoice);
1740 else if (media_quality != NULL)
1741 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
1742 NULL, media_quality->defchoice);
1743 else
1744 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "media-default",
1745 NULL, "none");
1746 }
1747 }
1748
1749 /*
1750 * Output bin...
1751 */
1752
1753 if ((output_bin = ppdFindOption(ppd, "OutputBin")) != NULL)
1754 {
1755 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1756 "output-bin-supported", output_bin->num_choices,
1757 NULL, NULL);
1758
1759 if (attr != NULL)
1760 {
1761 for (i = 0, val = attr->values;
1762 i < output_bin->num_choices;
1763 i ++, val ++)
4400e98d 1764 val->string.text = _cups_sp_alloc(output_bin->choices[i].choice);
ef416fc2 1765 }
1766 }
1767
1768 /*
1769 * Duplexing, etc...
1770 */
1771
1772 if (ppdFindOption(ppd, "Duplex") != NULL)
1773 {
1774 p->type |= CUPS_PRINTER_DUPLEX;
1775
1776 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-supported",
1777 3, NULL, sides);
1778 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "sides-default",
1779 NULL, "one");
1780 }
1781
1782 if (ppdFindOption(ppd, "Collate") != NULL)
1783 p->type |= CUPS_PRINTER_COLLATE;
1784
1785 if (ppdFindOption(ppd, "StapleLocation") != NULL)
1786 {
1787 p->type |= CUPS_PRINTER_STAPLE;
1788 finishings[num_finishings++] = IPP_FINISHINGS_STAPLE;
1789 }
1790
1791 if (ppdFindOption(ppd, "BindEdge") != NULL)
1792 {
1793 p->type |= CUPS_PRINTER_BIND;
1794 finishings[num_finishings++] = IPP_FINISHINGS_BIND;
1795 }
1796
1797 for (i = 0; i < ppd->num_sizes; i ++)
1798 if (ppd->sizes[i].length > 1728)
1799 p->type |= CUPS_PRINTER_LARGE;
1800 else if (ppd->sizes[i].length > 1008)
1801 p->type |= CUPS_PRINTER_MEDIUM;
1802 else
1803 p->type |= CUPS_PRINTER_SMALL;
1804
1805 /*
1806 * Add a filter from application/vnd.cups-raw to printer/name to
1807 * handle "raw" printing by users.
1808 */
1809
bd7854cb 1810 add_printer_filter(p, "application/vnd.cups-raw 0 -");
ef416fc2 1811
1812 /*
1813 * Add any filters in the PPD file...
1814 */
1815
1816 DEBUG_printf(("ppd->num_filters = %d\n", ppd->num_filters));
1817 for (i = 0; i < ppd->num_filters; i ++)
1818 {
1819 DEBUG_printf(("ppd->filters[%d] = \"%s\"\n", i, ppd->filters[i]));
bd7854cb 1820 add_printer_filter(p, ppd->filters[i]);
ef416fc2 1821 }
1822
1823 if (ppd->num_filters == 0)
1824 {
1825 /*
1826 * If there are no filters, add a PostScript printing filter.
1827 */
1828
bd7854cb 1829 add_printer_filter(p, "application/vnd.cups-postscript 0 -");
ef416fc2 1830 }
1831
1832 /*
1833 * Show current and available port monitors for this printer...
1834 */
1835
1836 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD, "port-monitor",
1837 NULL, p->port_monitor ? p->port_monitor : "none");
1838
1839
1840 for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
1841 ppdattr;
1842 i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL));
1843
1844 if (ppd->protocols)
1845 {
1846 if (strstr(ppd->protocols, "TBCP"))
1847 i ++;
1848 else if (strstr(ppd->protocols, "BCP"))
1849 i ++;
1850 }
1851
1852 attr = ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_KEYWORD,
1853 "port-monitor-supported", i, NULL, NULL);
1854
4400e98d 1855 attr->values[0].string.text = _cups_sp_alloc("none");
ef416fc2 1856
1857 for (i = 1, ppdattr = ppdFindAttr(ppd, "cupsPortMonitor", NULL);
1858 ppdattr;
1859 i ++, ppdattr = ppdFindNextAttr(ppd, "cupsPortMonitor", NULL))
4400e98d 1860 attr->values[i].string.text = _cups_sp_alloc(ppdattr->value);
ef416fc2 1861
1862 if (ppd->protocols)
1863 {
1864 if (strstr(ppd->protocols, "TBCP"))
4400e98d 1865 attr->values[i].string.text = _cups_sp_alloc("tbcp");
ef416fc2 1866 else if (strstr(ppd->protocols, "BCP"))
4400e98d 1867 attr->values[i].string.text = _cups_sp_alloc("bcp");
ef416fc2 1868 }
1869
1870 /*
1871 * Close the PPD and set the type...
1872 */
1873
1874 ppdClose(ppd);
1875
e00b005a 1876 printer_type = p->type;
ef416fc2 1877 }
1878 else if (!access(filename, 0))
1879 {
1880 int pline; /* PPD line number */
1881 ppd_status_t pstatus; /* PPD load status */
1882
1883
1884 pstatus = ppdLastError(&pline);
1885
1886 cupsdLogMessage(CUPSD_LOG_ERROR, "PPD file for %s cannot be loaded!", p->name);
1887
1888 if (pstatus <= PPD_ALLOC_ERROR)
1889 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", strerror(errno));
1890 else
1891 cupsdLogMessage(CUPSD_LOG_ERROR, "%s on line %d.", ppdErrorString(pstatus),
1892 pline);
1893
1894 cupsdLogMessage(CUPSD_LOG_INFO, "Hint: Run \"cupstestppd %s\" and fix any errors.",
1895 filename);
1896
1897 /*
1898 * Add a filter from application/vnd.cups-raw to printer/name to
1899 * handle "raw" printing by users.
1900 */
1901
bd7854cb 1902 add_printer_filter(p, "application/vnd.cups-raw 0 -");
ef416fc2 1903
1904 /*
1905 * Add a PostScript filter, since this is still possibly PS printer.
1906 */
1907
bd7854cb 1908 add_printer_filter(p, "application/vnd.cups-postscript 0 -");
ef416fc2 1909 }
1910 else
1911 {
1912 /*
1913 * If we have an interface script, add a filter entry for it...
1914 */
1915
1916 snprintf(filename, sizeof(filename), "%s/interfaces/%s", ServerRoot,
1917 p->name);
1918 if (access(filename, X_OK) == 0)
1919 {
1920 /*
1921 * Yes, we have a System V style interface script; use it!
1922 */
1923
1924 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1925 "printer-make-and-model", NULL, "Local System V Printer");
1926
1927 snprintf(filename, sizeof(filename), "*/* 0 %s/interfaces/%s",
1928 ServerRoot, p->name);
bd7854cb 1929 add_printer_filter(p, filename);
ef416fc2 1930 }
1931 else if (p->device_uri &&
1932 !strncmp(p->device_uri, "ipp://", 6) &&
1933 (strstr(p->device_uri, "/printers/") != NULL ||
1934 strstr(p->device_uri, "/classes/") != NULL))
1935 {
1936 /*
1937 * Tell the client this is really a hard-wired remote printer.
1938 */
1939
e00b005a 1940 printer_type |= CUPS_PRINTER_REMOTE;
ef416fc2 1941
1942 /*
1943 * Point the printer-uri-supported attribute to the
1944 * remote printer...
1945 */
1946
1947 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_URI,
1948 "printer-uri-supported", NULL, p->device_uri);
1949
1950 /*
1951 * Then set the make-and-model accordingly...
1952 */
1953
1954 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1955 "printer-make-and-model", NULL, "Remote Printer");
1956
1957 /*
1958 * Print all files directly...
1959 */
1960
1961 p->raw = 1;
1962 }
1963 else
1964 {
1965 /*
1966 * Otherwise we have neither - treat this as a "dumb" printer
1967 * with no PPD file...
1968 */
1969
1970 ippAddString(p->attrs, IPP_TAG_PRINTER, IPP_TAG_TEXT,
1971 "printer-make-and-model", NULL, "Local Raw Printer");
1972
1973 p->raw = 1;
1974 }
1975 }
1976
1977 ippAddIntegers(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
1978 "finishings-supported", num_finishings, (int *)finishings);
1979 ippAddInteger(p->attrs, IPP_TAG_PRINTER, IPP_TAG_ENUM,
1980 "finishings-default", IPP_FINISHINGS_NONE);
1981 }
1982 }
1983
bd7854cb 1984 /*
1985 * Populate the document-format-supported attribute...
1986 */
1987
1988 add_printer_formats(p);
1989
ef416fc2 1990 DEBUG_printf(("cupsdSetPrinterAttrs: leaving name = %s, type = %x\n", p->name,
1991 p->type));
1992
1993#ifdef __sgi
1994 /*
1995 * Write the IRIX printer config and status files...
1996 */
1997
1998 write_irix_config(p);
1999 write_irix_state(p);
2000#endif /* __sgi */
2001}
2002
2003
2004/*
2005 * 'cupsdSetPrinterReasons()' - Set/update the reasons strings.
2006 */
2007
2008void
2009cupsdSetPrinterReasons(
2010 cupsd_printer_t *p, /* I - Printer */
2011 const char *s) /* I - Reasons strings */
2012{
2013 int i; /* Looping var */
2014 const char *sptr; /* Pointer into reasons */
2015 char reason[255], /* Reason string */
2016 *rptr; /* Pointer into reason */
2017
2018
2019 if (s[0] == '-' || s[0] == '+')
2020 {
2021 /*
2022 * Add/remove reasons...
2023 */
2024
2025 sptr = s + 1;
2026 }
2027 else
2028 {
2029 /*
2030 * Replace reasons...
2031 */
2032
2033 sptr = s;
2034
2035 for (i = 0; i < p->num_reasons; i ++)
2036 free(p->reasons[i]);
2037
2038 p->num_reasons = 0;
2039 }
2040
2041 /*
2042 * Loop through all of the reasons...
2043 */
2044
2045 while (*sptr)
2046 {
2047 /*
2048 * Skip leading whitespace and commas...
2049 */
2050
2051 while (isspace(*sptr & 255) || *sptr == ',')
2052 sptr ++;
2053
2054 for (rptr = reason; *sptr && !isspace(*sptr & 255) && *sptr != ','; sptr ++)
2055 if (rptr < (reason + sizeof(reason) - 1))
2056 *rptr++ = *sptr;
2057
2058 if (rptr == reason)
2059 break;
2060
2061 *rptr = '\0';
2062
2063 if (s[0] == '-')
2064 {
2065 /*
2066 * Remove reason...
2067 */
2068
2069 for (i = 0; i < p->num_reasons; i ++)
2070 if (!strcasecmp(reason, p->reasons[i]))
2071 {
2072 /*
2073 * Found a match, so remove it...
2074 */
2075
2076 p->num_reasons --;
2077 free(p->reasons[i]);
2078
2079 if (i < p->num_reasons)
2080 memmove(p->reasons + i, p->reasons + i + 1,
2081 (p->num_reasons - i) * sizeof(char *));
2082
2083 i --;
2084 }
2085 }
2086 else if (p->num_reasons < (int)(sizeof(p->reasons) / sizeof(p->reasons[0])))
2087 {
2088 /*
2089 * Add reason...
2090 */
2091
2092 for (i = 0; i < p->num_reasons; i ++)
2093 if (!strcasecmp(reason, p->reasons[i]))
2094 break;
2095
2096 if (i >= p->num_reasons)
2097 {
2098 p->reasons[i] = strdup(reason);
2099 p->num_reasons ++;
2100 }
2101 }
2102 }
2103}
2104
2105
2106/*
2107 * 'cupsdSetPrinterState()' - Update the current state of a printer.
2108 */
2109
2110void
2111cupsdSetPrinterState(
2112 cupsd_printer_t *p, /* I - Printer to change */
2113 ipp_pstate_t s, /* I - New state */
2114 int update) /* I - Update printers.conf? */
2115{
2116 ipp_pstate_t old_state; /* Old printer state */
2117
2118
2119 /*
2120 * Can't set status of remote printers...
2121 */
2122
2123 if (p->type & CUPS_PRINTER_REMOTE)
2124 return;
2125
2126 /*
2127 * Set the new state...
2128 */
2129
2130 old_state = p->state;
2131 p->state = s;
2132
2133 if (old_state != s)
2134 {
2135 /*
2136 * Let the browse code know this needs to be updated...
2137 */
2138
2139 BrowseNext = p;
2140 p->state_time = time(NULL);
2141 p->browse_time = 0;
2142
2143#ifdef __sgi
2144 write_irix_state(p);
2145#endif /* __sgi */
2146 }
2147
2148 cupsdAddPrinterHistory(p);
2149
2150 /*
2151 * Save the printer configuration if a printer goes from idle or processing
2152 * to stopped (or visa-versa)...
2153 */
2154
2155 if ((old_state == IPP_PRINTER_STOPPED) != (s == IPP_PRINTER_STOPPED) &&
2156 update)
2157 {
2158 if (p->type & CUPS_PRINTER_CLASS)
2159 cupsdSaveAllClasses();
2160 else
2161 cupsdSaveAllPrinters();
2162 }
2163}
2164
2165
2166/*
2167 * 'cupsdStopPrinter()' - Stop a printer from printing any jobs...
2168 */
2169
2170void
2171cupsdStopPrinter(cupsd_printer_t *p, /* I - Printer to stop */
2172 int update)/* I - Update printers.conf? */
2173{
2174 cupsd_job_t *job; /* Active print job */
2175
2176
2177 /*
2178 * Set the printer state...
2179 */
2180
2181 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, update);
2182
2183 /*
2184 * See if we have a job printing on this printer...
2185 */
2186
2187 if (p->job)
2188 {
2189 /*
2190 * Get pointer to job...
2191 */
2192
2193 job = (cupsd_job_t *)p->job;
2194
2195 /*
2196 * Stop it...
2197 */
2198
2199 cupsdStopJob(job, 0);
2200
2201 /*
2202 * Reset the state to pending...
2203 */
2204
2205 job->state->values[0].integer = IPP_JOB_PENDING;
bd7854cb 2206 job->state_value = IPP_JOB_PENDING;
ef416fc2 2207
2208 cupsdSaveJob(job);
2209 }
2210}
2211
2212
2213/*
2214 * 'cupsdUpdatePrinters()' - Update printers after a partial reload.
2215 */
2216
2217void
2218cupsdUpdatePrinters(void)
2219{
2220 cupsd_printer_t *p; /* Current printer */
2221
2222
2223 /*
2224 * Loop through the printers and recreate the printer attributes
2225 * for any local printers since the policy and/or access control
2226 * stuff may have changed. Also, if browsing is disabled, remove
2227 * any remote printers...
2228 */
2229
2230 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2231 p;
2232 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2233 {
2234 if (!Browsing && (p->type & (CUPS_PRINTER_IMPLICIT | CUPS_PRINTER_REMOTE)))
2235 {
2236 if (p->type & CUPS_PRINTER_IMPLICIT)
2237 cupsArrayRemove(ImplicitPrinters, p);
2238
2239 cupsArraySave(Printers);
2240 cupsdDeletePrinter(p, 0);
2241 cupsArrayRestore(Printers);
2242 continue;
2243 }
2244 else if (!(p->type & CUPS_PRINTER_REMOTE))
2245 cupsdSetPrinterAttrs(p);
2246
2247 /*
2248 * Update the operation policy pointer...
2249 */
2250
2251 if ((p->op_policy_ptr = cupsdFindPolicy(p->op_policy)) == NULL)
2252 p->op_policy_ptr = DefaultPolicyPtr;
2253 }
2254}
2255
2256
2257/*
2258 * 'cupsdValidateDest()' - Validate a printer/class destination.
2259 */
2260
2261const char * /* O - Printer or class name */
2262cupsdValidateDest(
2263 const char *hostname, /* I - Host name */
2264 const char *resource, /* I - Resource name */
2265 cups_ptype_t *dtype, /* O - Type (printer or class) */
2266 cupsd_printer_t **printer) /* O - Printer pointer */
2267{
2268 cupsd_printer_t *p; /* Current printer */
2269 char localname[1024],/* Localized hostname */
2270 *lptr, /* Pointer into localized hostname */
2271 *sptr; /* Pointer into server name */
2272
2273
2274 DEBUG_printf(("cupsdValidateDest(\"%s\", \"%s\", %p, %p)\n", hostname, resource,
2275 dtype, printer));
2276
2277 /*
2278 * Initialize return values...
2279 */
2280
2281 if (printer)
2282 *printer = NULL;
2283
2284 *dtype = (cups_ptype_t)0;
2285
2286 /*
2287 * See if the resource is a class or printer...
2288 */
2289
2290 if (!strncmp(resource, "/classes/", 9))
2291 {
2292 /*
2293 * Class...
2294 */
2295
2296 resource += 9;
2297 }
2298 else if (!strncmp(resource, "/printers/", 10))
2299 {
2300 /*
2301 * Printer...
2302 */
2303
2304 resource += 10;
2305 }
2306 else
2307 {
2308 /*
2309 * Bad resource name...
2310 */
2311
2312 return (NULL);
2313 }
2314
2315 /*
2316 * See if the printer or class name exists...
2317 */
2318
2319 p = cupsdFindDest(resource);
2320
2321 if (p == NULL && strchr(resource, '@') == NULL)
2322 return (NULL);
2323 else if (p != NULL)
2324 {
2325 if (printer)
2326 *printer = p;
2327
2328 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
2329 CUPS_PRINTER_REMOTE);
2330 return (p->name);
2331 }
2332
2333 /*
2334 * Change localhost to the server name...
2335 */
2336
2337 if (!strcasecmp(hostname, "localhost"))
2338 hostname = ServerName;
2339
2340 strlcpy(localname, hostname, sizeof(localname));
2341
2342 if (!strcasecmp(hostname, ServerName))
2343 {
2344 /*
2345 * Localize the hostname...
2346 */
2347
2348 lptr = strchr(localname, '.');
2349 sptr = strchr(ServerName, '.');
2350
2351 if (sptr != NULL && lptr != NULL)
2352 {
2353 /*
2354 * Strip the common domain name components...
2355 */
2356
2357 while (lptr != NULL)
2358 {
2359 if (!strcasecmp(lptr, sptr))
2360 {
2361 *lptr = '\0';
2362 break;
2363 }
2364 else
2365 lptr = strchr(lptr + 1, '.');
2366 }
2367 }
2368 }
2369
2370 DEBUG_printf(("localized hostname is \"%s\"...\n", localname));
2371
2372 /*
2373 * Find a matching printer or class...
2374 */
2375
2376 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2377 p;
2378 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2379 if (!strcasecmp(p->hostname, localname) &&
2380 !strcasecmp(p->name, resource))
2381 {
2382 if (printer)
2383 *printer = p;
2384
2385 *dtype = p->type & (CUPS_PRINTER_CLASS | CUPS_PRINTER_IMPLICIT |
2386 CUPS_PRINTER_REMOTE);
2387 return (p->name);
2388 }
2389
2390 return (NULL);
2391}
2392
2393
2394/*
2395 * 'cupsdWritePrintcap()' - Write a pseudo-printcap file for older applications
2396 * that need it...
2397 */
2398
2399void
2400cupsdWritePrintcap(void)
2401{
2402 cups_file_t *fp; /* printcap file */
2403 cupsd_printer_t *p; /* Current printer */
2404
2405
2406#ifdef __sgi
2407 /*
2408 * Update the IRIX printer state for the default printer; if
2409 * no printers remain, then the default printer file will be
2410 * removed...
2411 */
2412
2413 write_irix_state(DefaultPrinter);
2414#endif /* __sgi */
2415
2416 /*
2417 * See if we have a printcap file; if not, don't bother writing it.
2418 */
2419
2420 if (!Printcap || !*Printcap)
2421 return;
2422
2423 /*
2424 * Open the printcap file...
2425 */
2426
2427 if ((fp = cupsFileOpen(Printcap, "w")) == NULL)
2428 return;
2429
2430 /*
2431 * Put a comment header at the top so that users will know where the
2432 * data has come from...
2433 */
2434
2435 cupsFilePuts(fp, "# This file was automatically generated by cupsd(8) from the\n");
2436 cupsFilePrintf(fp, "# %s/printers.conf file. All changes to this file\n",
2437 ServerRoot);
2438 cupsFilePuts(fp, "# will be lost.\n");
2439
2440 if (Printers)
2441 {
2442 /*
2443 * Write a new printcap with the current list of printers.
2444 */
2445
2446 switch (PrintcapFormat)
2447 {
2448 case PRINTCAP_BSD:
2449 /*
2450 * Each printer is put in the file as:
2451 *
2452 * Printer1:
2453 * Printer2:
2454 * Printer3:
2455 * ...
2456 * PrinterN:
2457 */
2458
2459 if (DefaultPrinter)
2460 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", DefaultPrinter->name,
2461 DefaultPrinter->info, ServerName, DefaultPrinter->name);
2462
2463 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2464 p;
2465 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2466 if (p != DefaultPrinter)
2467 cupsFilePrintf(fp, "%s|%s:rm=%s:rp=%s:\n", p->name, p->info,
2468 ServerName, p->name);
2469 break;
2470
2471 case PRINTCAP_SOLARIS:
2472 /*
2473 * Each printer is put in the file as:
2474 *
2475 * _all:all=Printer1,Printer2,Printer3,...,PrinterN
2476 * _default:use=DefaultPrinter
2477 * Printer1:\
2478 * :bsdaddr=ServerName,Printer1:\
2479 * :description=Description:
2480 * Printer2:
2481 * :bsdaddr=ServerName,Printer2:\
2482 * :description=Description:
2483 * Printer3:
2484 * :bsdaddr=ServerName,Printer3:\
2485 * :description=Description:
2486 * ...
2487 * PrinterN:
2488 * :bsdaddr=ServerName,PrinterN:\
2489 * :description=Description:
2490 */
2491
2492 cupsFilePuts(fp, "_all:all=");
2493 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2494 p;
2495 p = (cupsd_printer_t *)cupsArrayCurrent(Printers))
2496 cupsFilePrintf(fp, "%s%c", p->name,
2497 cupsArrayNext(Printers) ? ',' : '\n');
2498
2499 if (DefaultPrinter)
2500 cupsFilePrintf(fp, "_default:use=%s\n", DefaultPrinter->name);
2501
2502 for (p = (cupsd_printer_t *)cupsArrayFirst(Printers);
2503 p;
2504 p = (cupsd_printer_t *)cupsArrayNext(Printers))
2505 cupsFilePrintf(fp, "%s:\\\n"
2506 "\t:bsdaddr=%s,%s:\\\n"
2507 "\t:description=%s:\n",
2508 p->name, ServerName, p->name, p->info ? p->info : "");
2509 break;
2510 }
2511 }
2512
2513 /*
2514 * Close the file...
2515 */
2516
2517 cupsFileClose(fp);
2518}
2519
2520
2521/*
2522 * 'cupsdSanitizeURI()' - Sanitize a device URI...
2523 */
2524
2525char * /* O - New device URI */
2526cupsdSanitizeURI(const char *uri, /* I - Original device URI */
2527 char *buffer, /* O - New device URI */
2528 int buflen) /* I - Size of new device URI buffer */
2529{
2530 char *start, /* Start of data after scheme */
2531 *slash, /* First slash after scheme:// */
2532 *ptr; /* Pointer into user@host:port part */
2533
2534
2535 /*
2536 * Range check input...
2537 */
2538
2539 if (!uri || !buffer || buflen < 2)
2540 return (NULL);
2541
2542 /*
2543 * Copy the device URI to the new buffer...
2544 */
2545
2546 strlcpy(buffer, uri, buflen);
2547
2548 /*
2549 * Find the end of the scheme:// part...
2550 */
2551
2552 if ((ptr = strchr(buffer, ':')) == NULL)
2553 return (buffer); /* No scheme: part... */
2554
2555 for (start = ptr + 1; *start; start ++)
2556 if (*start != '/')
2557 break;
2558
2559 /*
2560 * Find the next slash (/) in the URI...
2561 */
2562
2563 if ((slash = strchr(start, '/')) == NULL)
2564 slash = start + strlen(start); /* No slash, point to the end */
2565
2566 /*
2567 * Check for an @ sign before the slash...
2568 */
2569
2570 if ((ptr = strchr(start, '@')) != NULL && ptr < slash)
2571 {
2572 /*
2573 * Found an @ sign and it is before the resource part, so we have
2574 * an authentication string. Copy the remaining URI over the
2575 * authentication string...
2576 */
2577
2578 _cups_strcpy(start, ptr + 1);
2579 }
2580
2581 /*
2582 * Return the new device URI...
2583 */
2584
2585 return (buffer);
2586}
2587
2588
bd7854cb 2589/*
2590 * 'add_printer_filter()' - Add a MIME filter for a printer.
2591 */
2592
2593static void
2594add_printer_filter(
2595 cupsd_printer_t *p, /* I - Printer to add to */
2596 const char *filter) /* I - Filter to add */
2597{
2598 char super[MIME_MAX_SUPER], /* Super-type for filter */
2599 type[MIME_MAX_TYPE], /* Type for filter */
2600 program[1024]; /* Program/filter name */
2601 int cost; /* Cost of filter */
2602 mime_type_t *temptype; /* MIME type looping var */
2603 char filename[1024]; /* Full filter filename */
2604
2605
2606 /*
2607 * Parse the filter string; it should be in the following format:
2608 *
2609 * super/type cost program
2610 */
2611
2612 if (sscanf(filter, "%15[^/]/%31s%d%1023s", super, type, &cost, program) != 4)
2613 {
2614 cupsdLogMessage(CUPSD_LOG_ERROR, "%s: invalid filter string \"%s\"!",
2615 p->name, filter);
2616 return;
2617 }
2618
2619 /*
2620 * See if the filter program exists; if not, stop the printer and flag
2621 * the error!
2622 */
2623
2624 if (program[0] == '/')
2625 strlcpy(filename, program, sizeof(filename));
2626 else
2627 snprintf(filename, sizeof(filename), "%s/filter/%s", ServerBin, program);
2628
2629 if (access(filename, X_OK))
2630 {
2631 snprintf(p->state_message, sizeof(p->state_message),
2632 "Filter \"%s\" for printer \"%s\" not available: %s",
2633 program, p->name, strerror(errno));
2634 cupsdSetPrinterState(p, IPP_PRINTER_STOPPED, 0);
2635 cupsdSetPrinterReasons(p, "+cups-missing-filter-error");
2636 cupsdAddPrinterHistory(p);
2637
2638 cupsdLogMessage(CUPSD_LOG_ERROR, "%s", p->state_message);
2639 }
2640
2641 /*
2642 * Add the filter to the MIME database, supporting wildcards as needed...
2643 */
2644
2645 for (temptype = mimeFirstType(MimeDatabase);
2646 temptype;
2647 temptype = mimeNextType(MimeDatabase))
2648 if (((super[0] == '*' && strcasecmp(temptype->super, "printer")) ||
2649 !strcasecmp(temptype->super, super)) &&
2650 (type[0] == '*' || !strcasecmp(temptype->type, type)))
2651 {
2652 cupsdLogMessage(CUPSD_LOG_DEBUG2,
2653 "add_printer_filter: %s: adding filter %s/%s %s/%s %d %s",
2654 p->name, temptype->super, temptype->type,
2655 p->filetype->super, p->filetype->type,
2656 cost, program);
2657 mimeAddFilter(MimeDatabase, temptype, p->filetype, cost, program);
2658 }
2659}
2660
2661
2662/*
2663 * 'add_printer_formats()' - Add document-format-supported values for a printer.
2664 */
2665
2666static void
2667add_printer_formats(cupsd_printer_t *p) /* I - Printer */
2668{
2669 int i; /* Looping var */
2670 mime_type_t *type; /* Current MIME type */
2671 cups_array_t *filters; /* Filters */
2672 int num_types; /* Number of supported types */
2673 const char **types; /* Array of supported type names */
2674 char mimetype[MIME_MAX_SUPER + MIME_MAX_TYPE + 2];
2675 /* MIME type name */
2676
2677
2678 /*
2679 * Raw (and remote) queues advertise all of the supported MIME
2680 * types...
2681 */
2682
2683 if (p->raw)
2684 {
2685 ippAddStrings(p->attrs, IPP_TAG_PRINTER,
2686 (ipp_tag_t)(IPP_TAG_MIMETYPE | IPP_TAG_COPY),
2687 "document-format-supported", NumMimeTypes, NULL, MimeTypes);
2688 return;
2689 }
2690
2691 /*
2692 * Otherwise, loop through the supported MIME types and see if there
2693 * are filters for them...
2694 */
2695
2696 if ((types = calloc(NumMimeTypes, sizeof(char *))) == NULL)
2697 {
2698 cupsdLogMessage(CUPSD_LOG_EMERG,
2699 "Unable to allocate memory for \"%s\" MIME type list!",
2700 p->name);
2701 return;
2702 }
2703
2704 cupsdLogMessage(CUPSD_LOG_DEBUG2, "add_printer_formats: %d types, %d filters",
2705 mimeNumTypes(MimeDatabase), mimeNumFilters(MimeDatabase));
2706
2707 types[0] = _cups_sp_alloc("application/octet-stream");
2708
2709 for (num_types = 1, type = mimeFirstType(MimeDatabase);
2710 type;
2711 type = mimeNextType(MimeDatabase))
2712 {
2713 if (!strcasecmp(type->super, "application") &&
2714 !strcasecmp(type->type, "octet-stream"))
2715 continue;
2716
2717 snprintf(mimetype, sizeof(mimetype), "%s/%s", type->super, type->type);
2718
2719 if ((filters = mimeFilter(MimeDatabase, type, p->filetype, NULL)) != NULL)
2720 {
2721 cupsdLogMessage(CUPSD_LOG_DEBUG2,
2722 "add_printer_formats: %s: %s needs %d filters",
2723 p->name, mimetype, cupsArrayCount(filters));
2724
2725 cupsArrayDelete(filters);
2726 types[num_types] = _cups_sp_alloc(mimetype);
2727 num_types ++;
2728 }
2729 else
2730 cupsdLogMessage(CUPSD_LOG_DEBUG2,
2731 "add_printer_formats: %s: %s not supported",
2732 p->name, mimetype);
2733 }
2734
2735 cupsdLogMessage(CUPSD_LOG_DEBUG2,
2736 "add_printer_formats: %s: %d supported types",
2737 p->name, num_types);
2738
2739 /*
2740 * Add the file formats that can be filtered...
2741 */
2742
2743 ippAddStrings(p->attrs, IPP_TAG_PRINTER, IPP_TAG_MIMETYPE,
2744 "document-format-supported", num_types, NULL, types);
2745
2746 /*
2747 * Free the temporary data...
2748 */
2749
2750 for (i = 0; i < num_types; i ++)
2751 _cups_sp_free(types[i]);
2752
2753 free(types);
2754}
2755
2756
ef416fc2 2757/*
2758 * 'compare_printers()' - Compare two printers.
2759 */
2760
2761static int /* O - Result of comparison */
2762compare_printers(void *first, /* I - First printer */
2763 void *second, /* I - Second printer */
2764 void *data) /* I - App data (not used) */
2765{
2766 return (strcasecmp(((cupsd_printer_t *)first)->name,
2767 ((cupsd_printer_t *)second)->name));
2768}
2769
2770
bd7854cb 2771/*
2772 * 'transcode_nickname()' - Convert the PPD NickName to UTF-8...
2773 */
2774
2775static void
2776transcode_nickname(cupsd_printer_t *p, /* I - Printer */
2777 ppd_file_t *ppd)/* I - PPD file */
2778{
2779 cups_utf8_t utf8[256]; /* UTF-8 version of nickname */
2780 cups_encoding_t encoding; /* Encoding of PPD file */
2781 const char *nickptr; /* Pointer into nickname */
2782
2783
2784 /*
2785 * See if we need to convert to UTF-8...
2786 */
2787
2788 if (!ppd->lang_encoding || !strcasecmp(ppd->lang_encoding, "UTF-8"))
2789 {
2790 /*
2791 * No language encoding, or encoding uses the non-standard UTF-8
2792 * value, so no transcoding is required...
2793 */
2794
2795 goto no_transcode;
2796 }
2797
2798 for (nickptr = ppd->nickname; *nickptr; nickptr ++)
2799 if (*nickptr & 0x80)
2800 break;
2801
2802 if (!*nickptr)
2803 {
2804 /*
2805 * No non-ASCII characters, so no transcoding is required...
2806 */
2807
2808 goto no_transcode;
2809 }
2810
2811 /*
2812 * OK, we need to transcode...
2813 */
2814
2815 if (!strcasecmp(ppd->lang_encoding, "ISOLatin1"))
2816 encoding = CUPS_ISO8859_1;
2817 else if (!strcasecmp(ppd->lang_encoding, "ISOLatin2"))
2818 encoding = CUPS_ISO8859_2;
2819 else if (!strcasecmp(ppd->lang_encoding, "ISOLatin5"))
2820 encoding = CUPS_ISO8859_5;
2821 else if (!strcasecmp(ppd->lang_encoding, "JIS83-RKSJ"))
2822 encoding = CUPS_WINDOWS_932;
2823 else if (!strcasecmp(ppd->lang_encoding, "MacStandard"))
2824 encoding = CUPS_MAC_ROMAN;
2825 else if (!strcasecmp(ppd->lang_encoding, "WindowsANSI"))
2826 encoding = CUPS_WINDOWS_1252;
2827 else
2828 {
2829 /*
2830 * Unknown encoding, treat as UTF-8...
2831 */
2832
2833 goto no_transcode;
2834 }
2835
2836 cupsCharsetToUTF8(utf8, ppd->nickname, sizeof(utf8), encoding);
2837
2838 cupsdSetString(&p->make_model, (char *)utf8);
2839
2840 return;
2841
2842 /*
2843 * Yeah, yeah, gotos are evil, but code bloat is more evil...
2844 */
2845
2846 no_transcode:
2847
2848 cupsdSetString(&p->make_model, ppd->nickname);
2849 return;
2850}
2851
2852
ef416fc2 2853#ifdef __sgi
2854/*
2855 * 'write_irix_config()' - Update the config files used by the IRIX
2856 * desktop tools.
2857 */
2858
2859static void
2860write_irix_config(cupsd_printer_t *p) /* I - Printer to update */
2861{
2862 char filename[1024]; /* Interface script filename */
2863 cups_file_t *fp; /* Interface script file */
2864
2865
2866
2867 /*
2868 * Add dummy interface and GUI scripts to fool SGI's "challenged" printing
2869 * tools. First the interface script that tells the tools what kind of
2870 * printer we have...
2871 */
2872
2873 snprintf(filename, sizeof(filename), "/var/spool/lp/interface/%s", p->name);
2874
2875 if (p->type & CUPS_PRINTER_CLASS)
2876 unlink(filename);
2877 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2878 {
2879 cupsFilePuts(fp, "#!/bin/sh\n");
2880
2881 if ((attr = ippFindAttribute(p->attrs, "printer-make-and-model",
2882 IPP_TAG_TEXT)) != NULL)
2883 cupsFilePrintf(fp, "NAME=\"%s\"\n", attr->values[0].string.text);
2884 else if (p->type & CUPS_PRINTER_CLASS)
2885 cupsFilePuts(fp, "NAME=\"Printer Class\"\n");
2886 else
2887 cupsFilePuts(fp, "NAME=\"Remote Destination\"\n");
2888
2889 if (p->type & CUPS_PRINTER_COLOR)
2890 cupsFilePuts(fp, "TYPE=ColorPostScript\n");
2891 else
2892 cupsFilePuts(fp, "TYPE=MonoPostScript\n");
2893
2894 cupsFilePrintf(fp, "HOSTNAME=%s\n", ServerName);
2895 cupsFilePrintf(fp, "HOSTPRINTER=%s\n", p->name);
2896
2897 cupsFileClose(fp);
2898
2899 chmod(filename, 0755);
2900 chown(filename, User, Group);
2901 }
2902
2903 /*
2904 * Then the member file that tells which device file the queue is connected
2905 * to... Networked printers use "/dev/null" in this file, so that's what
2906 * we use (the actual device URI can confuse some apps...)
2907 */
2908
2909 snprintf(filename, sizeof(filename), "/var/spool/lp/member/%s", p->name);
2910
2911 if (p->type & CUPS_PRINTER_CLASS)
2912 unlink(filename);
2913 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2914 {
2915 cupsFilePuts(fp, "/dev/null\n");
2916
2917 cupsFileClose(fp);
2918
2919 chmod(filename, 0644);
2920 chown(filename, User, Group);
2921 }
2922
2923 /*
2924 * The gui_interface file is a script or program that launches a GUI
2925 * option panel for the printer, using options specified on the
2926 * command-line in the third argument. The option panel must send
2927 * any printing options to stdout on a single line when the user
2928 * accepts them, or nothing if the user cancels the dialog.
2929 *
2930 * The default options panel program is /usr/bin/glpoptions, from
2931 * the ESP Print Pro software. You can select another using the
2932 * PrintcapGUI option.
2933 */
2934
2935 snprintf(filename, sizeof(filename), "/var/spool/lp/gui_interface/ELF/%s.gui", p->name);
2936
2937 if (p->type & CUPS_PRINTER_CLASS)
2938 unlink(filename);
2939 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2940 {
2941 cupsFilePuts(fp, "#!/bin/sh\n");
2942 cupsFilePrintf(fp, "%s -d %s -o \"$3\"\n", PrintcapGUI, p->name);
2943
2944 cupsFileClose(fp);
2945
2946 chmod(filename, 0755);
2947 chown(filename, User, Group);
2948 }
2949
2950 /*
2951 * The POD config file is needed by the printstatus command to show
2952 * the printer location and device.
2953 */
2954
2955 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.config", p->name);
2956
2957 if (p->type & CUPS_PRINTER_CLASS)
2958 unlink(filename);
2959 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
2960 {
2961 cupsFilePrintf(fp, "Printer Class | %s\n",
2962 (p->type & CUPS_PRINTER_COLOR) ? "ColorPostScript" : "MonoPostScript");
2963 cupsFilePrintf(fp, "Printer Model | %s\n", p->make_model ? p->make_model : "");
2964 cupsFilePrintf(fp, "Location Code | %s\n", p->location ? p->location : "");
2965 cupsFilePrintf(fp, "Physical Location | %s\n", p->info ? p->info : "");
2966 cupsFilePrintf(fp, "Port Path | %s\n", p->device_uri ? p->device_uri : "");
2967 cupsFilePrintf(fp, "Config Path | /var/spool/lp/pod/%s.config\n", p->name);
2968 cupsFilePrintf(fp, "Active Status Path | /var/spool/lp/pod/%s.status\n", p->name);
2969 cupsFilePuts(fp, "Status Update Wait | 10 seconds\n");
2970
2971 cupsFileClose(fp);
2972
2973 chmod(filename, 0664);
2974 chown(filename, User, Group);
2975 }
2976}
2977
2978
2979/*
2980 * 'write_irix_state()' - Update the status files used by IRIX printing
2981 * desktop tools.
2982 */
2983
2984static void
2985write_irix_state(cupsd_printer_t *p) /* I - Printer to update */
2986{
2987 char filename[1024]; /* Interface script filename */
2988 cups_file_t *fp; /* Interface script file */
2989 int tag; /* Status tag value */
2990
2991
2992 if (p)
2993 {
2994 /*
2995 * The POD status file is needed for the printstatus window to
2996 * provide the current status of the printer.
2997 */
2998
2999 snprintf(filename, sizeof(filename), "/var/spool/lp/pod/%s.status", p->name);
3000
3001 if (p->type & CUPS_PRINTER_CLASS)
3002 unlink(filename);
3003 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3004 {
3005 cupsFilePrintf(fp, "Operational Status | %s\n",
3006 (p->state == IPP_PRINTER_IDLE) ? "Idle" :
3007 (p->state == IPP_PRINTER_PROCESSING) ? "Busy" :
3008 "Faulted");
3009 cupsFilePrintf(fp, "Information | 01 00 00 | %s\n", CUPS_SVERSION);
3010 cupsFilePrintf(fp, "Information | 02 00 00 | Device URI: %s\n",
3011 p->device_uri ? p->device_uri : "");
3012 cupsFilePrintf(fp, "Information | 03 00 00 | %s jobs\n",
3013 p->accepting ? "Accepting" : "Not accepting");
3014 cupsFilePrintf(fp, "Information | 04 00 00 | %s\n", p->state_message);
3015
3016 cupsFileClose(fp);
3017
3018 chmod(filename, 0664);
3019 chown(filename, User, Group);
3020 }
3021
3022 /*
3023 * The activeicons file is needed to provide desktop icons for printers:
3024 *
3025 * [ quoted from /usr/lib/print/tagit ]
3026 *
3027 * --- Type of printer tags (base values)
3028 *
3029 * Dumb=66048 # 0x10200
3030 * DumbColor=66080 # 0x10220
3031 * Raster=66112 # 0x10240
3032 * ColorRaster=66144 # 0x10260
3033 * Plotter=66176 # 0x10280
3034 * PostScript=66208 # 0x102A0
3035 * ColorPostScript=66240 # 0x102C0
3036 * MonoPostScript=66272 # 0x102E0
3037 *
3038 * --- Printer state modifiers for local printers
3039 *
3040 * Idle=0 # 0x0
3041 * Busy=1 # 0x1
3042 * Faulted=2 # 0x2
3043 * Unknown=3 # 0x3 (Faulted due to unknown reason)
3044 *
3045 * --- Printer state modifiers for network printers
3046 *
3047 * NetIdle=8 # 0x8
3048 * NetBusy=9 # 0x9
3049 * NetFaulted=10 # 0xA
3050 * NetUnknown=11 # 0xB (Faulted due to unknown reason)
3051 */
3052
3053 snprintf(filename, sizeof(filename), "/var/spool/lp/activeicons/%s", p->name);
3054
3055 if (p->type & CUPS_PRINTER_CLASS)
3056 unlink(filename);
3057 else if ((fp = cupsFileOpen(filename, "w")) != NULL)
3058 {
3059 if (p->type & CUPS_PRINTER_COLOR)
3060 tag = 66240;
3061 else
3062 tag = 66272;
3063
3064 if (p->type & CUPS_PRINTER_REMOTE)
3065 tag |= 8;
3066
3067 if (p->state == IPP_PRINTER_PROCESSING)
3068 tag |= 1;
3069
3070 else if (p->state == IPP_PRINTER_STOPPED)
3071 tag |= 2;
3072
3073 cupsFilePuts(fp, "#!/bin/sh\n");
3074 cupsFilePrintf(fp, "#Tag %d\n", tag);
3075
3076 cupsFileClose(fp);
3077
3078 chmod(filename, 0755);
3079 chown(filename, User, Group);
3080 }
3081 }
3082
3083 /*
3084 * The default file is needed by the printers window to show
3085 * the default printer.
3086 */
3087
3088 snprintf(filename, sizeof(filename), "/var/spool/lp/default");
3089
3090 if (DefaultPrinter != NULL)
3091 {
3092 if ((fp = cupsFileOpen(filename, "w")) != NULL)
3093 {
3094 cupsFilePrintf(fp, "%s\n", DefaultPrinter->name);
3095
3096 cupsFileClose(fp);
3097
3098 chmod(filename, 0644);
3099 chown(filename, User, Group);
3100 }
3101 }
3102 else
3103 unlink(filename);
3104}
3105#endif /* __sgi */
3106
3107
3108/*
bd7854cb 3109 * End of "$Id: printers.c 5132 2006-02-19 14:57:11Z mike $".
ef416fc2 3110 */