summaryrefslogtreecommitdiff
path: root/source3/printing/print_cups.c
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2003-01-28 01:58:38 +0000
committerGerald Carter <jerry@samba.org>2003-01-28 01:58:38 +0000
commitf4733888873da451813f542284aa86869f266256 (patch)
tree261d1bc235f9e691f9da5e29c904ece8a08a104d /source3/printing/print_cups.c
parent755e33ee3f25884096d3fa2ac4bd4cf64a794903 (diff)
downloadsamba-f4733888873da451813f542284aa86869f266256.tar.gz
samba-f4733888873da451813f542284aa86869f266256.tar.bz2
samba-f4733888873da451813f542284aa86869f266256.zip
CUPS-PRINTER_CLASS patch from Michael Sweet
(This used to be commit 8d0bde43156f5511df7a5a6865b361ebc2a933eb)
Diffstat (limited to 'source3/printing/print_cups.c')
-rw-r--r--source3/printing/print_cups.c103
1 files changed, 101 insertions, 2 deletions
diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index cc3941fe96..0c86c69ffd 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -1,7 +1,7 @@
/*
* Support code for the Common UNIX Printing System ("CUPS")
*
- * Copyright 1999-2001 by Michael R Sweet.
+ * Copyright 1999-2003 by Michael R Sweet.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -194,12 +194,111 @@ void cups_printer_fn(void (*fn)(char *, char *))
if (info == NULL || !info[0])
(*fn)(name, make_model);
else
- (*fn)(name,info);
+ (*fn)(name, info);
}
ippDelete(response);
+
+
+ /*
+ * Build a CUPS_GET_CLASSES request, which requires the following
+ * attributes:
+ *
+ * attributes-charset
+ * attributes-natural-language
+ * requested-attributes
+ */
+
+ request = ippNew();
+
+ request->request.op.operation_id = CUPS_GET_CLASSES;
+ request->request.op.request_id = 1;
+
+ language = cupsLangDefault();
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
+ "attributes-charset", NULL, cupsLangEncoding(language));
+
+ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
+ "attributes-natural-language", NULL, language->language);
+
+ ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
+ "requested-attributes",
+ (sizeof(requested) / sizeof(requested[0])),
+ NULL, requested);
+
+ /*
+ * Do the request and get back a response...
+ */
+
+ if ((response = cupsDoRequest(http, request, "/")) == NULL)
+ {
+ DEBUG(0,("Unable to get printer list - %s\n",
+ ippErrorString(cupsLastError())));
+ httpClose(http);
+ return;
+ }
+
+ for (attr = response->attrs; attr != NULL;)
+ {
+ /*
+ * Skip leading attributes until we hit a printer...
+ */
+
+ while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
+ attr = attr->next;
+
+ if (attr == NULL)
+ break;
+
+ /*
+ * Pull the needed attributes from this printer...
+ */
+
+ name = NULL;
+ make_model = NULL;
+ info = NULL;
+
+ while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
+ {
+ if (strcmp(attr->name, "printer-name") == 0 &&
+ attr->value_tag == IPP_TAG_NAME)
+ name = attr->values[0].string.text;
+
+ if (strcmp(attr->name, "printer-make-and-model") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ make_model = attr->values[0].string.text;
+
+ if (strcmp(attr->name, "printer-info") == 0 &&
+ attr->value_tag == IPP_TAG_TEXT)
+ info = attr->values[0].string.text;
+
+ attr = attr->next;
+ }
+
+ /*
+ * See if we have everything needed...
+ */
+
+ if (name == NULL)
+ break;
+
+ if (info == NULL || !info[0])
+ (*fn)(name, make_model);
+ else
+ (*fn)(name, info);
+
+
+ }
+
+ ippDelete(response);
+
+ /*
+ * Close the connection to the server...
+ */
+
httpClose(http);
}