summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Untz <vuntz@novell.com>2008-11-21 01:12:17 +0100
committerVincent Untz <vuntz@novell.com>2008-11-21 01:12:17 +0100
commit3f64b841ef2ddf6d8b23a49ceabee461e0f26f0e (patch)
treebc6ec8aa42ba07434e31a0a00afb22505cb012f3
parent20f6cda5f7884d6340c32f9d85a66fcc517cfde8 (diff)
Add cph_cups_is_class().
-rw-r--r--src/cups.c38
-rw-r--r--src/cups.h3
2 files changed, 41 insertions, 0 deletions
diff --git a/src/cups.c b/src/cups.c
index 0762f4d..4c79e65 100644
--- a/src/cups.c
+++ b/src/cups.c
@@ -665,6 +665,44 @@ cph_cups_last_status_to_string (CphCups *cups)
return ippErrorString (cups->priv->last_status);
}
+gboolean
+cph_cups_is_class (CphCups *cups,
+ const char *name)
+{
+ const char * const attrs[1] = { "member-names" };
+ ipp_t *request;
+ const char *resource_char;
+ ipp_t *reply;
+ gboolean retval;
+
+ g_return_val_if_fail (CPH_IS_CUPS (cups), FALSE);
+
+ if (!_cph_cups_is_class_name_valid (cups, name))
+ return FALSE;
+
+ request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES);
+ _cph_cups_add_class_uri (request, name);
+ ippAddStrings (request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
+ "requested-attributes", 1, NULL, attrs);
+
+ resource_char = _cph_cups_get_resource (CPH_RESOURCE_ROOT);
+ reply = cupsDoRequest (cups->priv->connection,
+ request, resource_char);
+
+ if (!reply)
+ return FALSE;
+
+ /* Note: we need to look if the attribute is there, since we get a
+ * reply if the name is a printer name and not a class name. The
+ * attribute is the only way to distinguish the two cases. */
+ retval = ippFindAttribute (reply, attrs[0], IPP_TAG_NAME) != NULL;
+
+ if (reply)
+ ippDelete (reply);
+
+ return retval;
+}
+
char *
cph_cups_printer_get_uri (CphCups *cups,
const char *printer_name)
diff --git a/src/cups.h b/src/cups.h
index 1b069dd..a520b8b 100644
--- a/src/cups.h
+++ b/src/cups.h
@@ -54,6 +54,9 @@ CphCups *cph_cups_new (void);
const char *cph_cups_last_status_to_string (CphCups *cups);
+gboolean cph_cups_is_class (CphCups *cups,
+ const char *name);
+
char *cph_cups_printer_get_uri (CphCups *cups,
const char *printer_name);