#include <cups/cups-private.h>
int
main(int argc,
char *argv[])
{
int i;
char *command,
uri[1024],
*reason;
ipp_t *request;
ipp_op_t op;
int cancel;
_cupsSetLocale(argv);
if ((command = strrchr(argv[0], '/')) != NULL)
command ++;
else
command = argv[0];
cancel = 0;
if (!strcmp(command, "cupsaccept") || !strcmp(command, "accept"))
op = CUPS_ACCEPT_JOBS;
else if (!strcmp(command, "cupsreject") || !strcmp(command, "reject"))
op = CUPS_REJECT_JOBS;
else if (!strcmp(command, "cupsdisable") || !strcmp(command, "disable"))
op = IPP_PAUSE_PRINTER;
else if (!strcmp(command, "cupsenable") || !strcmp(command, "enable"))
op = IPP_RESUME_PRINTER;
else
{
_cupsLangPrintf(stderr, _("%s: Don't know what to do."), command);
return (1);
}
reason = NULL;
for (i = 1; i < argc; i ++)
if (argv[i][0] == '-')
{
switch (argv[i][1])
{
case 'E' :
#ifdef HAVE_SSL
cupsSetEncryption(HTTP_ENCRYPT_REQUIRED);
#else
_cupsLangPrintf(stderr,
_("%s: Sorry, no encryption support."), command);
#endif
break;
case 'U' :
if (argv[i][2] != '\0')
cupsSetUser(argv[i] + 2);
else
{
i ++;
if (i >= argc)
{
_cupsLangPrintf(stderr,
_("%s: Error - expected username after "
"\"-U\" option."), command);
return (1);
}
cupsSetUser(argv[i]);
}
break;
case 'c' :
cancel = 1;
break;
case 'h' :
if (argv[i][2] != '\0')
cupsSetServer(argv[i] + 2);
else
{
i ++;
if (i >= argc)
{
_cupsLangPrintf(stderr,
_("%s: Error - expected hostname after "
"\"-h\" option."), command);
return (1);
}
cupsSetServer(argv[i]);
}
break;
case 'r' :
if (argv[i][2] != '\0')
reason = argv[i] + 2;
else
{
i ++;
if (i >= argc)
{
_cupsLangPrintf(stderr,
_("%s: Error - expected reason text after "
"\"-r\" option."), command);
return (1);
}
reason = argv[i];
}
break;
case '-' :
if (!strcmp(argv[i], "--hold"))
op = IPP_HOLD_NEW_JOBS;
else if (!strcmp(argv[i], "--release"))
op = IPP_RELEASE_HELD_NEW_JOBS;
else
{
_cupsLangPrintf(stderr, _("%s: Error - unknown option \"%s\"."),
command, argv[i]);
return (1);
}
break;
default :
_cupsLangPrintf(stderr, _("%s: Error - unknown option \"%c\"."),
command, argv[i][1]);
return (1);
}
}
else
{
request = ippNewRequest(op);
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
"localhost", 0, "/printers/%s", argv[i]);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
"requesting-user-name", NULL, cupsUser());
if (reason != NULL)
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_TEXT,
"printer-state-message", NULL, reason);
ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/"));
if (cupsLastError() > IPP_OK_CONFLICT)
{
_cupsLangPrintf(stderr,
_("%s: Operation failed: %s"),
command, ippErrorString(cupsLastError()));
return (1);
}
if (cancel)
{
request = ippNewRequest(IPP_PURGE_JOBS);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
"printer-uri", NULL, uri);
ippDelete(cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/admin/"));
if (cupsLastError() > IPP_OK_CONFLICT)
{
_cupsLangPrintf(stderr, "%s: %s", command, cupsLastErrorString());
return (1);
}
}
}
return (0);
}