2 * "$Id: lpadmin.c 4906 2006-01-10 20:53:28Z mike $"
4 * "lpadmin" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
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() - Parse options and configure the scheduler.
27 * add_printer_to_class() - Add a printer to a class.
28 * default_printer() - Set the default printing destination.
29 * delete_printer() - Delete a printer from the system...
30 * delete_printer_from_class() - Delete a printer from a class.
31 * enable_printer() - Enable a printer...
32 * set_printer_device() - Set the device-uri attribute.
33 * set_printer_file() - Set the interface script or PPD file.
34 * set_printer_info() - Set the printer description string.
35 * set_printer_location() - Set the printer location string.
36 * set_printer_model() - Set the driver model file.
37 * set_printer_options() - Set the printer options.
38 * validate_name() - Make sure the printer name only contains
43 * Include necessary headers...
50 #include <cups/string.h>
51 #include <cups/cups.h>
52 #include <cups/i18n.h>
53 #include <cups/debug.h>
56 #endif /* HAVE_LIBZ */
63 static int add_printer_to_class(http_t
*, char *, char *);
64 static int default_printer(http_t
*, char *);
65 static int delete_printer(http_t
*, char *);
66 static int delete_printer_from_class(http_t
*, char *, char *);
67 static int enable_printer(http_t
*, char *);
68 static char *get_line(char *, int, FILE *fp
);
69 static int set_printer_device(http_t
*, char *, char *);
70 static int set_printer_file(http_t
*, char *, char *);
71 static int set_printer_info(http_t
*, char *, char *);
72 static int set_printer_location(http_t
*, char *, char *);
73 static int set_printer_model(http_t
*, char *, char *);
74 static int set_printer_options(http_t
*, char *, int, cups_option_t
*);
75 static int validate_name(const char *);
79 * 'main()' - Parse options and configure the scheduler.
83 main(int argc
, /* I - Number of command-line arguments */
84 char *argv
[]) /* I - Command-line arguments */
86 int i
; /* Looping var */
87 http_t
*http
; /* Connection to server */
88 char *printer
, /* Destination printer */
89 *pclass
, /* Printer class name */
90 *val
; /* Pointer to allow/deny value */
91 int num_options
; /* Number of options */
92 cups_option_t
*options
; /* Options */
100 for (i
= 1; i
< argc
; i
++)
101 if (argv
[i
][0] == '-')
104 case 'c' : /* Add printer to class */
107 http
= httpConnectEncrypt(cupsServer(), ippPort(),
112 _cupsLangPrintf(stderr
, NULL
,
113 _("lpadmin: Unable to connect to server: %s\n"),
121 _cupsLangPuts(stderr
, NULL
,
122 _("lpadmin: Unable to add a printer to the class:\n"
123 " You must specify a printer name "
129 pclass
= argv
[i
] + 2;
136 _cupsLangPuts(stderr
, NULL
,
137 _("lpadmin: Expected class name after \'-c\' "
145 if (!validate_name(pclass
))
147 _cupsLangPuts(stderr
, NULL
,
148 _("lpadmin: Class name can only contain printable "
153 if (add_printer_to_class(http
, printer
, pclass
))
157 case 'd' : /* Set as default destination */
160 http
= httpConnectEncrypt(cupsServer(), ippPort(),
165 _cupsLangPrintf(stderr
, NULL
,
166 _("lpadmin: Unable to connect to server: %s\n"),
173 printer
= argv
[i
] + 2;
180 _cupsLangPuts(stderr
, NULL
,
181 _("lpadmin: Expected printer name after \'-d\' "
189 if (!validate_name(printer
))
191 _cupsLangPuts(stderr
, NULL
,
192 _("lpadmin: Printer name can only contain "
193 "printable characters!\n"));
197 if (default_printer(http
, printer
))
203 case 'h' : /* Connect to host */
210 if (argv
[i
][2] != '\0')
211 cupsSetServer(argv
[i
] + 2);
218 _cupsLangPuts(stderr
, NULL
,
219 _("lpadmin: Expected hostname after \'-h\' "
224 cupsSetServer(argv
[i
]);
228 case 'i' : /* Use the specified interface script */
231 http
= httpConnectEncrypt(cupsServer(), ippPort(),
236 _cupsLangPrintf(stderr
, NULL
,
237 _("lpadmin: Unable to connect to server: %s\n"),
245 _cupsLangPuts(stderr
, NULL
,
246 _("lpadmin: Unable to set the interface script:\n"
247 " You must specify a printer name "
254 if (set_printer_file(http
, printer
, argv
[i
] + 2))
263 _cupsLangPuts(stderr
, NULL
,
264 _("lpadmin: Expected interface after \'-i\' "
269 if (set_printer_file(http
, printer
, argv
[i
]))
274 case 'E' : /* Enable the printer */
278 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
281 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
283 _cupsLangPrintf(stderr
, NULL
,
284 _("%s: Sorry, no encryption support compiled in!\n"),
286 #endif /* HAVE_SSL */
292 http
= httpConnectEncrypt(cupsServer(), ippPort(),
297 _cupsLangPrintf(stderr
, NULL
,
298 _("lpadmin: Unable to connect to server: %s\n"),
304 if (enable_printer(http
, printer
))
308 case 'm' : /* Use the specified standard script/PPD file */
311 http
= httpConnectEncrypt(cupsServer(), ippPort(),
316 _cupsLangPrintf(stderr
, NULL
,
317 _("lpadmin: Unable to connect to server: %s\n"),
325 _cupsLangPuts(stderr
, NULL
,
326 _("lpadmin: Unable to set the interface script or "
328 " You must specify a printer name "
335 if (set_printer_model(http
, printer
, argv
[i
] + 2))
344 _cupsLangPuts(stderr
, NULL
,
345 _("lpadmin: Expected model after \'-m\' "
350 if (set_printer_model(http
, printer
, argv
[i
]))
355 case 'o' : /* Set option */
357 num_options
= cupsParseOptions(argv
[i
] + 2, num_options
, &options
);
364 _cupsLangPuts(stderr
, NULL
,
365 _("lpadmin: Expected name=value after \'-o\' "
370 num_options
= cupsParseOptions(argv
[i
], num_options
, &options
);
374 case 'p' : /* Add/modify a printer */
377 http
= httpConnectEncrypt(cupsServer(), ippPort(),
382 _cupsLangPrintf(stderr
, NULL
,
383 _("lpadmin: Unable to connect to server: %s\n"),
390 printer
= argv
[i
] + 2;
397 _cupsLangPuts(stderr
, NULL
,
398 _("lpadmin: Expected printer after \'-p\' "
406 if (!validate_name(printer
))
408 _cupsLangPuts(stderr
, NULL
,
409 _("lpadmin: Printer name can only contain "
410 "printable characters!\n"));
415 case 'r' : /* Remove printer from class */
418 http
= httpConnectEncrypt(cupsServer(), ippPort(),
423 _cupsLangPrintf(stderr
, NULL
,
424 _("lpadmin: Unable to connect to server: %s\n"),
432 _cupsLangPuts(stderr
, NULL
,
433 _("lpadmin: Unable to remove a printer from the "
435 " You must specify a printer name "
441 pclass
= argv
[i
] + 2;
448 _cupsLangPuts(stderr
, NULL
,
449 _("lpadmin: Expected class after \'-r\' "
457 if (!validate_name(pclass
))
459 _cupsLangPuts(stderr
, NULL
,
460 _("lpadmin: Class name can only contain printable "
465 if (delete_printer_from_class(http
, printer
, pclass
))
469 case 'u' : /* Allow/deny users */
478 _cupsLangPuts(stderr
, NULL
,
479 _("lpadmin: Expected allow/deny:userlist after "
480 "\'-u\' option!\n"));
487 if (!strncasecmp(val
, "allow:", 6))
488 num_options
= cupsAddOption("requesting-user-name-allowed",
489 val
+ 6, num_options
, &options
);
490 else if (!strncasecmp(val
, "deny:", 5))
491 num_options
= cupsAddOption("requesting-user-name-denied",
492 val
+ 5, num_options
, &options
);
495 _cupsLangPrintf(stderr
, NULL
,
496 _("lpadmin: Unknown allow/deny option \"%s\"!\n"),
502 case 'v' : /* Set the device-uri attribute */
505 http
= httpConnectEncrypt(cupsServer(), ippPort(),
510 _cupsLangPrintf(stderr
, NULL
,
511 _("lpadmin: Unable to connect to server: %s\n"),
519 _cupsLangPuts(stderr
, NULL
,
520 _("lpadmin: Unable to set the device URI:\n"
521 " You must specify a printer name "
528 if (set_printer_device(http
, printer
, argv
[i
] + 2))
537 _cupsLangPuts(stderr
, NULL
,
538 _("lpadmin: Expected device URI after \'-v\' "
543 if (set_printer_device(http
, printer
, argv
[i
]))
548 case 'x' : /* Delete a printer */
551 http
= httpConnectEncrypt(cupsServer(), ippPort(),
556 _cupsLangPrintf(stderr
, NULL
,
557 _("lpadmin: Unable to connect to server: %s\n"),
564 printer
= argv
[i
] + 2;
571 _cupsLangPuts(stderr
, NULL
,
572 _("lpadmin: Expected printer or class after "
573 "\'-x\' option!\n"));
580 if (!validate_name(printer
))
582 _cupsLangPuts(stderr
, NULL
,
583 _("lpadmin: Printer name can only contain "
584 "printable characters!\n"));
588 if (delete_printer(http
, printer
))
594 case 'D' : /* Set the printer-info attribute */
597 http
= httpConnectEncrypt(cupsServer(), ippPort(),
602 _cupsLangPrintf(stderr
, NULL
,
603 _("lpadmin: Unable to connect to server: %s\n"),
611 _cupsLangPuts(stderr
, NULL
,
612 _("lpadmin: Unable to set the printer "
614 " You must specify a printer name "
621 if (set_printer_info(http
, printer
, argv
[i
] + 2))
630 _cupsLangPuts(stderr
, NULL
,
631 _("lpadmin: Expected description after "
632 "\'-D\' option!\n"));
636 if (set_printer_info(http
, printer
, argv
[i
]))
641 case 'I' : /* Set the supported file types (ignored) */
646 _cupsLangPuts(stderr
, NULL
,
647 _("lpadmin: Expected file type(s) after \'-I\' "
652 _cupsLangPuts(stderr
, NULL
,
653 _("lpadmin: Warning - content type list ignored!\n"));
656 case 'L' : /* Set the printer-location attribute */
659 http
= httpConnectEncrypt(cupsServer(), ippPort(),
664 _cupsLangPrintf(stderr
, NULL
,
665 _("lpadmin: Unable to connect to server: %s\n"),
673 _cupsLangPuts(stderr
, NULL
,
674 _("lpadmin: Unable to set the printer location:\n"
675 " You must specify a printer name "
682 if (set_printer_location(http
, printer
, argv
[i
] + 2))
691 _cupsLangPuts(stderr
, NULL
,
692 _("lpadmin: Expected location after \'-L\' "
697 if (set_printer_location(http
, printer
, argv
[i
]))
702 case 'P' : /* Use the specified PPD file */
705 http
= httpConnectEncrypt(cupsServer(), ippPort(),
710 _cupsLangPrintf(stderr
, NULL
,
711 _("lpadmin: Unable to connect to server: %s\n"),
719 _cupsLangPuts(stderr
, NULL
,
720 _("lpadmin: Unable to set the PPD file:\n"
721 " You must specify a printer name "
728 if (set_printer_file(http
, printer
, argv
[i
] + 2))
737 _cupsLangPuts(stderr
, NULL
,
738 _("lpadmin: Expected PPD after \'-P\' option!\n"));
742 if (set_printer_file(http
, printer
, argv
[i
]))
748 _cupsLangPrintf(stderr
, NULL
,
749 _("lpadmin: Unknown option \'%c\'!\n"), argv
[i
][1]);
754 _cupsLangPrintf(stderr
, NULL
, _("lpadmin: Unknown argument \'%s\'!\n"),
760 * Set options as needed...
767 http
= httpConnectEncrypt(cupsServer(), ippPort(), cupsEncryption());
771 _cupsLangPrintf(stderr
, NULL
,
772 _("lpadmin: Unable to connect to server: %s\n"),
780 _cupsLangPuts(stderr
, NULL
,
781 _("lpadmin: Unable to set the printer options:\n"
782 " You must specify a printer name first!\n"));
786 if (set_printer_options(http
, printer
, num_options
, options
))
792 _cupsLangPuts(stdout
, NULL
,
795 " lpadmin [-h server] -d destination\n"
796 " lpadmin [-h server] -x destination\n"
797 " lpadmin [-h server] -p printer [-c add-class] "
798 "[-i interface] [-m model]\n"
799 " [-r remove-class] [-v device] "
801 " [-P ppd-file] [-o name=value]\n"
802 " [-u allow:user,user] "
803 "[-u deny:user,user]\n"
815 * 'add_printer_to_class()' - Add a printer to a class.
818 static int /* O - 0 on success, 1 on fail */
819 add_printer_to_class(http_t
*http
, /* I - Server connection */
820 char *printer
, /* I - Printer to add */
821 char *pclass
) /* I - Class to add to */
823 int i
; /* Looping var */
824 ipp_t
*request
, /* IPP Request */
825 *response
; /* IPP Response */
826 ipp_attribute_t
*attr
, /* Current attribute */
827 *members
; /* Members in class */
828 cups_lang_t
*language
; /* Default language */
829 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
832 DEBUG_printf(("add_printer_to_class(%p, \"%s\", \"%s\")\n", http
,
836 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
840 * attributes-natural-language
844 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
845 "/classes/%s", pclass
);
849 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
850 request
->request
.op
.request_id
= 1;
852 language
= cupsLangDefault();
854 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
855 "attributes-charset", NULL
, cupsLangEncoding(language
));
857 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
858 "attributes-natural-language", NULL
, language
->language
);
860 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
861 "printer-uri", NULL
, uri
);
864 * Do the request and get back a response...
867 response
= cupsDoRequest(http
, request
, "/");
870 * Build a CUPS_ADD_CLASS request, which requires the following
874 * attributes-natural-language
881 request
->request
.op
.operation_id
= CUPS_ADD_CLASS
;
882 request
->request
.op
.request_id
= 1;
884 language
= cupsLangDefault();
886 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
887 "attributes-charset", NULL
, cupsLangEncoding(language
));
889 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
890 "attributes-natural-language", NULL
, language
->language
);
892 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
893 "printer-uri", NULL
, uri
);
896 * See if the printer is already in the class...
899 if (response
!= NULL
&&
900 (members
= ippFindAttribute(response
, "member-names", IPP_TAG_NAME
)) != NULL
)
901 for (i
= 0; i
< members
->num_values
; i
++)
902 if (strcasecmp(printer
, members
->values
[i
].string
.text
) == 0)
904 fprintf(stderr
, "lpadmin: Printer %s is already a member of class %s.\n",
912 * OK, the printer isn't part of the class, so add it...
915 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
916 "/printers/%s", printer
);
918 if (response
!= NULL
&&
919 (members
= ippFindAttribute(response
, "member-uris", IPP_TAG_URI
)) != NULL
)
922 * Add the printer to the existing list...
925 attr
= ippAddStrings(request
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
926 "member-uris", members
->num_values
+ 1, NULL
, NULL
);
927 for (i
= 0; i
< members
->num_values
; i
++)
928 attr
->values
[i
].string
.text
= strdup(members
->values
[i
].string
.text
);
930 attr
->values
[i
].string
.text
= strdup(uri
);
933 attr
= ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "member-uris", NULL
, uri
);
936 * Then send the request...
941 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
943 fprintf(stderr
, "lpadmin: add-class failed: %s\n",
944 ippErrorString(cupsLastError()));
948 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
950 fprintf(stderr
, "lpadmin: add-class failed: %s\n",
951 ippErrorString(response
->request
.status
.status_code
));
967 * 'default_printer()' - Set the default printing destination.
970 static int /* O - 0 on success, 1 on fail */
971 default_printer(http_t
*http
, /* I - Server connection */
972 char *printer
) /* I - Printer name */
974 ipp_t
*request
, /* IPP Request */
975 *response
; /* IPP Response */
976 cups_lang_t
*language
; /* Default language */
977 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
980 DEBUG_printf(("default_printer(%p, \"%s\")\n", http
, printer
));
983 * Build a CUPS_SET_DEFAULT request, which requires the following
987 * attributes-natural-language
991 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
992 "/printers/%s", printer
);
996 request
->request
.op
.operation_id
= CUPS_SET_DEFAULT
;
997 request
->request
.op
.request_id
= 1;
999 language
= cupsLangDefault();
1001 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1002 "attributes-charset", NULL
, cupsLangEncoding(language
));
1004 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1005 "attributes-natural-language", NULL
, language
->language
);
1007 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1008 "printer-uri", NULL
, uri
);
1011 * Do the request and get back a response...
1014 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1016 fprintf(stderr
, "lpadmin: set-default failed: %s\n",
1017 ippErrorString(cupsLastError()));
1021 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1023 fprintf(stderr
, "lpadmin: set-default failed: %s\n",
1024 ippErrorString(response
->request
.status
.status_code
));
1026 ippDelete(response
);
1032 ippDelete(response
);
1040 * 'delete_printer()' - Delete a printer from the system...
1043 static int /* O - 0 on success, 1 on fail */
1044 delete_printer(http_t
*http
, /* I - Server connection */
1045 char *printer
) /* I - Printer to delete */
1047 ipp_t
*request
, /* IPP Request */
1048 *response
; /* IPP Response */
1049 cups_lang_t
*language
; /* Default language */
1050 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1053 DEBUG_printf(("delete_printer(%p, \"%s\")\n", http
, printer
));
1056 * Build a CUPS_DELETE_PRINTER request, which requires the following
1059 * attributes-charset
1060 * attributes-natural-language
1064 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1065 "/printers/%s", printer
);
1069 request
->request
.op
.operation_id
= CUPS_DELETE_PRINTER
;
1070 request
->request
.op
.request_id
= 1;
1072 language
= cupsLangDefault();
1074 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1075 "attributes-charset", NULL
, cupsLangEncoding(language
));
1077 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1078 "attributes-natural-language", NULL
, language
->language
);
1080 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1081 "printer-uri", NULL
, uri
);
1084 * Do the request and get back a response...
1087 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1089 fprintf(stderr
, "lpadmin: delete-printer failed: %s\n",
1090 ippErrorString(cupsLastError()));
1094 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1096 fprintf(stderr
, "lpadmin: delete-printer failed: %s\n",
1097 ippErrorString(response
->request
.status
.status_code
));
1099 ippDelete(response
);
1105 ippDelete(response
);
1113 * 'delete_printer_from_class()' - Delete a printer from a class.
1116 static int /* O - 0 on success, 1 on fail */
1117 delete_printer_from_class(http_t
*http
, /* I - Server connection */
1119 /* I - Printer to remove */
1121 /* I - Class to remove from */
1123 int i
, j
, k
; /* Looping vars */
1124 ipp_t
*request
, /* IPP Request */
1125 *response
; /* IPP Response */
1126 ipp_attribute_t
*attr
, /* Current attribute */
1127 *members
; /* Members in class */
1128 cups_lang_t
*language
; /* Default language */
1129 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1132 DEBUG_printf(("delete_printer_from_class(%p, \"%s\", \"%s\")\n", http
,
1136 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the following
1139 * attributes-charset
1140 * attributes-natural-language
1144 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1145 "/classes/%s", pclass
);
1149 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
1150 request
->request
.op
.request_id
= 1;
1152 language
= cupsLangDefault();
1154 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1155 "attributes-charset", NULL
, cupsLangEncoding(language
));
1157 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1158 "attributes-natural-language", NULL
, language
->language
);
1160 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1161 "printer-uri", NULL
, uri
);
1164 * Do the request and get back a response...
1167 if ((response
= cupsDoRequest(http
, request
, "/classes/")) == NULL
||
1168 response
->request
.status
.status_code
== IPP_NOT_FOUND
)
1170 ippDelete(response
);
1171 fprintf(stderr
, "lpadmin: Class %s does not exist!\n", pclass
);
1176 * See if the printer is already in the class...
1179 if ((members
= ippFindAttribute(response
, "member-names", IPP_TAG_NAME
)) == NULL
)
1181 ippDelete(response
);
1182 fputs("lpadmin: No member names were seen!\n", stderr
);
1186 for (i
= 0; i
< members
->num_values
; i
++)
1187 if (strcasecmp(printer
, members
->values
[i
].string
.text
) == 0)
1190 if (i
>= members
->num_values
)
1192 fprintf(stderr
, "lpadmin: Printer %s is not a member of class %s.\n",
1194 ippDelete(response
);
1198 if (members
->num_values
== 1)
1201 * Build a CUPS_DELETE_CLASS request, which requires the following
1204 * attributes-charset
1205 * attributes-natural-language
1211 request
->request
.op
.operation_id
= CUPS_DELETE_CLASS
;
1212 request
->request
.op
.request_id
= 1;
1214 language
= cupsLangDefault();
1216 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1217 "attributes-charset", NULL
, cupsLangEncoding(language
));
1219 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1220 "attributes-natural-language", NULL
, language
->language
);
1222 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1223 "printer-uri", NULL
, uri
);
1228 * Build a CUPS_ADD_CLASS request, which requires the following
1231 * attributes-charset
1232 * attributes-natural-language
1239 request
->request
.op
.operation_id
= CUPS_ADD_CLASS
;
1240 request
->request
.op
.request_id
= 1;
1242 language
= cupsLangDefault();
1244 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1245 "attributes-charset", NULL
, cupsLangEncoding(language
));
1247 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1248 "attributes-natural-language", NULL
, language
->language
);
1250 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1251 "printer-uri", NULL
, uri
);
1254 * Delete the printer from the class...
1257 members
= ippFindAttribute(response
, "member-uris", IPP_TAG_URI
);
1258 attr
= ippAddStrings(request
, IPP_TAG_PRINTER
, IPP_TAG_URI
,
1259 "member-uris", members
->num_values
- 1, NULL
, NULL
);
1261 for (j
= 0, k
= 0; j
< members
->num_values
; j
++)
1263 attr
->values
[k
++].string
.text
= strdup(members
->values
[j
].string
.text
);
1267 * Then send the request...
1270 ippDelete(response
);
1272 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1274 fprintf(stderr
, "lpadmin: add/delete-class failed: %s\n",
1275 ippErrorString(cupsLastError()));
1278 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1280 fprintf(stderr
, "lpadmin: add/delete-class failed: %s\n",
1281 ippErrorString(response
->request
.status
.status_code
));
1283 ippDelete(response
);
1289 ippDelete(response
);
1297 * 'enable_printer()' - Enable a printer...
1300 static int /* O - 0 on success, 1 on fail */
1301 enable_printer(http_t
*http
, /* I - Server connection */
1302 char *printer
) /* I - Printer to enable */
1304 ipp_t
*request
, /* IPP Request */
1305 *response
; /* IPP Response */
1306 cups_lang_t
*language
; /* Default language */
1307 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1310 DEBUG_printf(("enable_printer(%p, \"%s\")\n", http
, printer
));
1313 * Build a CUPS_ADD_PRINTER request, which requires the following
1316 * attributes-charset
1317 * attributes-natural-language
1320 * printer-is-accepting-jobs
1323 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1324 "/printers/%s", printer
);
1328 request
->request
.op
.operation_id
= CUPS_ADD_PRINTER
;
1329 request
->request
.op
.request_id
= 1;
1331 language
= cupsLangDefault();
1333 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1334 "attributes-charset", NULL
, cupsLangEncoding(language
));
1336 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1337 "attributes-natural-language", NULL
, language
->language
);
1339 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1340 "printer-uri", NULL
, uri
);
1342 ippAddInteger(request
, IPP_TAG_PRINTER
, IPP_TAG_ENUM
, "printer-state",
1345 ippAddBoolean(request
, IPP_TAG_PRINTER
, "printer-is-accepting-jobs", 1);
1348 * Do the request and get back a response...
1351 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1353 fprintf(stderr
, "lpadmin: add-printer (enable) failed: %s\n",
1354 ippErrorString(cupsLastError()));
1357 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1359 fprintf(stderr
, "lpadmin: add-printer (enable) failed: %s\n",
1360 ippErrorString(response
->request
.status
.status_code
));
1362 ippDelete(response
);
1368 ippDelete(response
);
1376 * 'get_line()' - Get a line that is terminated by a LF, CR, or CR LF.
1379 static char * /* O - Pointer to buf or NULL on EOF */
1380 get_line(char *buf
, /* I - Line buffer */
1381 int length
, /* I - Length of buffer */
1382 FILE *fp
) /* I - File to read from */
1384 char *bufptr
; /* Pointer into buffer */
1385 int ch
; /* Character from file */
1391 while ((ch
= getc(fp
)) != EOF
)
1395 else if (ch
== '\r')
1402 if (ch
!= '\n' && ch
!= EOF
)
1424 * 'set_printer_device()' - Set the device-uri attribute.
1427 static int /* O - 0 on success, 1 on fail */
1428 set_printer_device(http_t
*http
, /* I - Server connection */
1429 char *printer
, /* I - Printer */
1430 char *device
) /* I - New device URI */
1432 ipp_t
*request
, /* IPP Request */
1433 *response
; /* IPP Response */
1434 cups_lang_t
*language
; /* Default language */
1435 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1438 DEBUG_printf(("set_printer_device(%p, \"%s\", \"%s\")\n", http
, printer
,
1442 * Build a CUPS_ADD_PRINTER request, which requires the following
1445 * attributes-charset
1446 * attributes-natural-language
1450 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1451 "/printers/%s", printer
);
1455 request
->request
.op
.operation_id
= CUPS_ADD_PRINTER
;
1456 request
->request
.op
.request_id
= 1;
1458 language
= cupsLangDefault();
1460 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1461 "attributes-charset", NULL
, cupsLangEncoding(language
));
1463 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1464 "attributes-natural-language", NULL
, language
->language
);
1466 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1467 "printer-uri", NULL
, uri
);
1470 * Add the device URI...
1473 if (device
[0] == '/')
1476 * Convert filename to URI...
1479 snprintf(uri
, sizeof(uri
), "file:%s", device
);
1480 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1484 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_URI
, "device-uri", NULL
,
1488 * Do the request and get back a response...
1491 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1493 fprintf(stderr
, "lpadmin: add-printer (set device) failed: %s\n",
1494 ippErrorString(cupsLastError()));
1497 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1499 fprintf(stderr
, "lpadmin: add-printer (set device) failed: %s\n",
1500 ippErrorString(response
->request
.status
.status_code
));
1502 ippDelete(response
);
1508 ippDelete(response
);
1516 * 'set_printer_file()' - Set the interface script or PPD file.
1519 static int /* O - 0 on success, 1 on fail */
1520 set_printer_file(http_t
*http
, /* I - Server connection */
1521 char *printer
, /* I - Printer */
1522 char *file
) /* I - PPD file or interface script */
1524 ipp_status_t status
; /* IPP status code */
1525 ipp_t
*request
, /* IPP Request */
1526 *response
; /* IPP Response */
1527 cups_lang_t
*language
; /* Default language */
1528 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1530 char tempfile
[1024]; /* Temporary filename */
1531 int fd
; /* Temporary file */
1532 gzFile
*gz
; /* GZIP'd file */
1533 char buffer
[8192]; /* Copy buffer */
1534 int bytes
; /* Bytes in buffer */
1537 DEBUG_printf(("set_printer_file(%p, \"%s\", \"%s\")\n", http
, printer
,
1541 * See if the file is gzip'd; if so, unzip it to a temporary file and
1542 * send the uncompressed file.
1545 if (!strcmp(file
+ strlen(file
) - 3, ".gz"))
1548 * Yes, the file is compressed; uncompress to a temp file...
1551 if ((fd
= cupsTempFd(tempfile
, sizeof(tempfile
))) < 0)
1553 _cupsLangPrintf(stderr
, NULL
,
1554 _("lpadmin: Unable to create temporary file: %s\n"),
1559 if ((gz
= gzopen(file
, "rb")) == NULL
)
1561 _cupsLangPrintf(stderr
, NULL
,
1562 _("lpadmin: Unable to open file \"%s\": %s\n"),
1563 file
, strerror(errno
));
1569 while ((bytes
= gzread(gz
, buffer
, sizeof(buffer
))) > 0)
1570 write(fd
, buffer
, bytes
);
1577 #endif /* HAVE_LIBZ */
1580 * Build a CUPS_ADD_PRINTER request, which requires the following
1583 * attributes-charset
1584 * attributes-natural-language
1588 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1589 "/printers/%s", printer
);
1593 request
->request
.op
.operation_id
= CUPS_ADD_PRINTER
;
1594 request
->request
.op
.request_id
= 1;
1596 language
= cupsLangDefault();
1598 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1599 "attributes-charset", NULL
, cupsLangEncoding(language
));
1601 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1602 "attributes-natural-language", NULL
, language
->language
);
1604 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1605 "printer-uri", NULL
, uri
);
1608 * Do the request and get back a response...
1611 if ((response
= cupsDoFileRequest(http
, request
, "/admin/", file
)) == NULL
)
1612 status
= cupsLastError();
1615 status
= response
->request
.status
.status_code
;
1616 ippDelete(response
);
1621 * Remove the temporary file as needed...
1624 if (file
== tempfile
)
1626 #endif /* HAVE_LIBZ */
1628 if (status
> IPP_OK_CONFLICT
)
1630 _cupsLangPrintf(stderr
, NULL
,
1631 _("lpadmin: add-printer (set model) failed: %s\n"),
1632 ippErrorString(status
));
1642 * 'set_printer_info()' - Set the printer description string.
1645 static int /* O - 0 on success, 1 on fail */
1646 set_printer_info(http_t
*http
, /* I - Server connection */
1647 char *printer
, /* I - Printer */
1648 char *info
) /* I - New description string */
1650 ipp_t
*request
, /* IPP Request */
1651 *response
; /* IPP Response */
1652 cups_lang_t
*language
; /* Default language */
1653 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1656 DEBUG_printf(("set_printer_info(%p, \"%s\", \"%s\")\n", http
, printer
,
1660 * Build a CUPS_ADD_PRINTER request, which requires the following
1663 * attributes-charset
1664 * attributes-natural-language
1668 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1669 "/printers/%s", printer
);
1673 request
->request
.op
.operation_id
= CUPS_ADD_PRINTER
;
1674 request
->request
.op
.request_id
= 1;
1676 language
= cupsLangDefault();
1678 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1679 "attributes-charset", NULL
, cupsLangEncoding(language
));
1681 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1682 "attributes-natural-language", NULL
, language
->language
);
1684 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1685 "printer-uri", NULL
, uri
);
1688 * Add the info string...
1691 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-info", NULL
,
1695 * Do the request and get back a response...
1698 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1700 _cupsLangPrintf(stderr
, NULL
,
1701 _("lpadmin: add-printer (set description) failed: %s\n"),
1702 ippErrorString(cupsLastError()));
1705 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1707 _cupsLangPrintf(stderr
, NULL
,
1708 _("lpadmin: add-printer (set description) failed: %s\n"),
1709 ippErrorString(response
->request
.status
.status_code
));
1711 ippDelete(response
);
1717 ippDelete(response
);
1725 * 'set_printer_location()' - Set the printer location string.
1728 static int /* O - 0 on success, 1 on fail */
1729 set_printer_location(http_t
*http
, /* I - Server connection */
1730 char *printer
, /* I - Printer */
1731 char *location
) /* I - New location string */
1733 ipp_t
*request
, /* IPP Request */
1734 *response
; /* IPP Response */
1735 cups_lang_t
*language
; /* Default language */
1736 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1739 DEBUG_printf(("set_printer_location(%p, \"%s\", \"%s\")\n", http
, printer
,
1743 * Build a CUPS_ADD_PRINTER request, which requires the following
1746 * attributes-charset
1747 * attributes-natural-language
1751 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1752 "/printers/%s", printer
);
1756 request
->request
.op
.operation_id
= CUPS_ADD_PRINTER
;
1757 request
->request
.op
.request_id
= 1;
1759 language
= cupsLangDefault();
1761 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1762 "attributes-charset", NULL
, cupsLangEncoding(language
));
1764 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1765 "attributes-natural-language", NULL
, language
->language
);
1767 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1768 "printer-uri", NULL
, uri
);
1771 * Add the location string...
1774 ippAddString(request
, IPP_TAG_PRINTER
, IPP_TAG_TEXT
, "printer-location", NULL
,
1778 * Do the request and get back a response...
1781 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1783 _cupsLangPrintf(stderr
, NULL
,
1784 _("lpadmin: add-printer (set location) failed: %s\n"),
1785 ippErrorString(cupsLastError()));
1789 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1791 _cupsLangPrintf(stderr
, NULL
,
1792 _("lpadmin: add-printer (set location) failed: %s\n"),
1793 ippErrorString(response
->request
.status
.status_code
));
1795 ippDelete(response
);
1801 ippDelete(response
);
1809 * 'set_printer_model()' - Set the driver model file.
1812 static int /* O - 0 on success, 1 on fail */
1813 set_printer_model(http_t
*http
, /* I - Server connection */
1814 char *printer
, /* I - Printer */
1815 char *model
) /* I - Driver model file */
1817 ipp_t
*request
, /* IPP Request */
1818 *response
; /* IPP Response */
1819 cups_lang_t
*language
; /* Default language */
1820 char uri
[HTTP_MAX_URI
]; /* URI for printer/class */
1824 * Build a CUPS_ADD_PRINTER request, which requires the following
1827 * attributes-charset
1828 * attributes-natural-language
1833 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1834 "/printers/%s", printer
);
1838 request
->request
.op
.operation_id
= CUPS_ADD_PRINTER
;
1839 request
->request
.op
.request_id
= 1;
1841 language
= cupsLangDefault();
1843 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1844 "attributes-charset", NULL
, cupsLangEncoding(language
));
1846 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1847 "attributes-natural-language", NULL
, language
->language
);
1849 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1850 "printer-uri", NULL
, uri
);
1852 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
,
1853 "ppd-name", NULL
, model
);
1856 * Do the request and get back a response...
1859 if ((response
= cupsDoRequest(http
, request
, "/admin/")) == NULL
)
1861 _cupsLangPrintf(stderr
, NULL
,
1862 _("lpadmin: add-printer (set model) failed: %s\n"),
1863 ippErrorString(cupsLastError()));
1867 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1869 _cupsLangPrintf(stderr
, NULL
,
1870 _("lpadmin: add-printer (set model) failed: %s\n"),
1871 ippErrorString(response
->request
.status
.status_code
));
1873 ippDelete(response
);
1879 ippDelete(response
);
1887 * 'set_printer_options()' - Set the printer options.
1890 static int /* O - 0 on success, 1 on fail */
1891 set_printer_options(http_t
*http
,/* I - Server connection */
1895 /* I - Number of options */
1896 cups_option_t
*options
)
1899 ipp_t
*request
, /* IPP Request */
1900 *response
; /* IPP Response */
1901 ipp_attribute_t
*attr
; /* IPP attribute */
1902 cups_lang_t
*language
; /* Default language */
1903 ipp_op_t op
; /* Operation to perform */
1904 const char *val
, /* Option value */
1905 *ppdfile
; /* PPD filename */
1906 char uri
[HTTP_MAX_URI
], /* URI for printer/class */
1907 line
[1024], /* Line from PPD file */
1908 keyword
[1024], /* Keyword from Default line */
1909 *keyptr
, /* Pointer into keyword... */
1910 tempfile
[1024]; /* Temporary filename */
1911 FILE *in
, /* PPD file */
1912 *out
; /* Temporary file */
1913 int outfd
; /* Temporary file descriptor */
1914 const char *protocol
; /* Protocol */
1917 DEBUG_printf(("set_printer_options(%p, \"%s\", %d, %p)\n", http
, printer
,
1918 num_options
, options
));
1920 language
= cupsLangDefault();
1922 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1923 "/printers/%s", printer
);
1926 * Build a GET_PRINTER_ATTRIBUTES request, which requires the following
1929 * attributes-charset
1930 * attributes-natural-language
1932 * requested-attributes
1937 request
->request
.op
.operation_id
= IPP_GET_PRINTER_ATTRIBUTES
;
1938 request
->request
.op
.request_id
= 1;
1940 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1941 "attributes-charset", NULL
, cupsLangEncoding(language
));
1943 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1944 "attributes-natural-language", NULL
, language
->language
);
1946 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1947 "printer-uri", NULL
, uri
);
1949 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1950 "requested-attributes", NULL
, "printer-type");
1956 op
= CUPS_ADD_PRINTER
;
1958 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1961 * See what kind of printer or class it is...
1964 if ((attr
= ippFindAttribute(response
, "printer-type", IPP_TAG_ENUM
)) != NULL
)
1966 if (attr
->values
[0].integer
& (CUPS_PRINTER_CLASS
| CUPS_PRINTER_IMPLICIT
))
1968 op
= CUPS_ADD_CLASS
;
1969 httpAssembleURIf(uri
, sizeof(uri
), "ipp", NULL
, "localhost", 0,
1970 "/classes/%s", printer
);
1974 ippDelete(response
);
1978 * Build a CUPS_ADD_PRINTER or CUPS_ADD_CLASS request, which requires
1979 * the following attributes:
1981 * attributes-charset
1982 * attributes-natural-language
1989 request
->request
.op
.operation_id
= op
;
1990 request
->request
.op
.request_id
= 1;
1992 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_CHARSET
,
1993 "attributes-charset", NULL
, cupsLangEncoding(language
));
1995 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_LANGUAGE
,
1996 "attributes-natural-language", NULL
, language
->language
);
1998 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1999 "printer-uri", NULL
, uri
);
2002 * Add the options...
2005 cupsEncodeOptions(request
, num_options
, options
);
2007 if (op
== CUPS_ADD_PRINTER
)
2008 ppdfile
= cupsGetPPD(printer
);
2012 if (ppdfile
!= NULL
)
2015 * Set default options in the PPD file...
2018 if ((outfd
= cupsTempFd(tempfile
, sizeof(tempfile
))) < 0)
2020 _cupsLangPrintf(stderr
, NULL
,
2021 _("lpadmin: Unable to create temporary file - %s\n"),
2028 if ((in
= fopen(ppdfile
, "rb")) == NULL
)
2030 _cupsLangPrintf(stderr
, NULL
,
2031 _("lpadmin: Unable to open PPD file \"%s\" - %s\n"),
2032 ppdfile
, strerror(errno
));
2040 out
= fdopen(outfd
, "wb");
2041 protocol
= cupsGetOption("protocol", num_options
, options
);
2043 while (get_line(line
, sizeof(line
), in
) != NULL
)
2045 if (!strncmp(line
, "*cupsProtocol:", 14) && protocol
)
2048 * Set a new output protocol (BCP or TBCP) below...
2053 else if (strncmp(line
, "*Default", 8))
2054 fprintf(out
, "%s\n", line
);
2058 * Get default option name...
2061 strlcpy(keyword
, line
+ 8, sizeof(keyword
));
2063 for (keyptr
= keyword
; *keyptr
; keyptr
++)
2064 if (*keyptr
== ':' || isspace(*keyptr
& 255))
2069 if (strcmp(keyword
, "PageRegion") == 0)
2070 val
= cupsGetOption("PageSize", num_options
, options
);
2072 val
= cupsGetOption(keyword
, num_options
, options
);
2075 fprintf(out
, "*Default%s: %s\n", keyword
, val
);
2077 fprintf(out
, "%s\n", line
);
2082 fprintf(out
, "*cupsProtocol: \"%s\"\n", protocol
);
2092 response
= cupsDoFileRequest(http
, request
, "/admin/", tempfile
);
2095 * Clean up temp files... (TODO: catch signals in case we CTRL-C during
2105 * No PPD file - just set the options...
2108 response
= cupsDoRequest(http
, request
, "/admin/");
2112 * Check the response...
2115 if (response
== NULL
)
2117 _cupsLangPrintf(stderr
, NULL
, _("lpadmin: %s failed: %s\n"),
2118 op
== CUPS_ADD_PRINTER
? "add-printer" : "add-class",
2119 ippErrorString(cupsLastError()));
2123 else if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
2125 _cupsLangPrintf(stderr
, NULL
, _("lpadmin: %s failed: %s\n"),
2126 op
== CUPS_ADD_PRINTER
? "add-printer" : "add-class",
2127 ippErrorString(response
->request
.status
.status_code
));
2129 ippDelete(response
);
2135 ippDelete(response
);
2143 * 'validate_name()' - Make sure the printer name only contains valid chars.
2146 static int /* O - 0 if name is no good, 1 if name is good */
2147 validate_name(const char *name
) /* I - Name to check */
2149 const char *ptr
; /* Pointer into name */
2153 * Scan the whole name...
2156 for (ptr
= name
; *ptr
; ptr
++)
2159 else if ((*ptr
>= 0 && *ptr
<= ' ') || *ptr
== 127 || *ptr
== '/' ||
2164 * All the characters are good; validate the length, too...
2167 return ((ptr
- name
) < 128);
2172 * End of "$Id: lpadmin.c 4906 2006-01-10 20:53:28Z mike $".