diff options
author | Vincent Untz <vuntz@novell.com> | 2008-11-21 01:12:17 +0100 |
---|---|---|
committer | Vincent Untz <vuntz@novell.com> | 2008-11-21 01:12:17 +0100 |
commit | 3f64b841ef2ddf6d8b23a49ceabee461e0f26f0e (patch) | |
tree | bc6ec8aa42ba07434e31a0a00afb22505cb012f3 | |
parent | 20f6cda5f7884d6340c32f9d85a66fcc517cfde8 (diff) |
Add cph_cups_is_class().
-rw-r--r-- | src/cups.c | 38 | ||||
-rw-r--r-- | src/cups.h | 3 |
2 files changed, 41 insertions, 0 deletions
@@ -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) @@ -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); |