diff options
author | Vincent Untz <vuntz@novell.com> | 2008-11-21 00:01:27 +0100 |
---|---|---|
committer | Vincent Untz <vuntz@novell.com> | 2008-11-21 00:01:27 +0100 |
commit | f7554181d51e911e1b357934853c4d860667048a (patch) | |
tree | a4d45c13c8c8928305c774c1bc865426334974eb | |
parent | e64c2a9463a466d6499956b5549a194688b5c2a9 (diff) |
Add cph_cups_printer_get_uri() to get the URI of a printer based on its
name.
Also, a printer with an empty URI is local.
-rw-r--r-- | src/cups.c | 58 | ||||
-rw-r--r-- | src/cups.h | 3 |
2 files changed, 61 insertions, 0 deletions
@@ -665,6 +665,60 @@ cph_cups_last_status_to_string (CphCups *cups) return ippErrorString (cups->priv->last_status); } +char * +cph_cups_printer_get_uri (CphCups *cups, + const char *printer_name) +{ + const char * const attrs[1] = { "device-uri" }; + ipp_t *request; + const char *resource_char; + ipp_t *reply; + ipp_attribute_t *attr; + char *uri; + + g_return_val_if_fail (CPH_IS_CUPS (cups), NULL); + + request = ippNewRequest (IPP_GET_PRINTER_ATTRIBUTES); + _cph_cups_add_printer_uri (request, printer_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 NULL; + + uri = NULL; + + for (attr = reply->attrs; attr; attr = attr->next) { + while (attr && attr->group_tag != IPP_TAG_PRINTER) + attr = attr->next; + + if (attr == NULL) + break; + + while (attr && attr->group_tag == IPP_TAG_PRINTER) { + if (attr->name && + strcmp (attr->name, attrs[0]) == 0 && + attr->value_tag == IPP_TAG_URI) { + uri = g_strdup (attr->values[0].string.text); + break; + } + + attr = attr->next; + } + + if (uri != NULL || attr == NULL) + break; + } + + ippDelete (reply); + + return uri; +} + gboolean cph_cups_printer_add (CphCups *cups, const char *printer_name, @@ -1418,6 +1472,10 @@ cph_cups_is_printer_uri_local (const char *uri) g_return_val_if_fail (uri != NULL, FALSE); + /* empty URI: can only be local... */ + if (uri[0] == '\0') + return TRUE; + lower_uri = g_ascii_strdown (uri, -1); /* clearly local stuff */ @@ -54,6 +54,9 @@ CphCups *cph_cups_new (void); const char *cph_cups_last_status_to_string (CphCups *cups); +char *cph_cups_printer_get_uri (CphCups *cups, + const char *printer_name); + gboolean cph_cups_printer_add (CphCups *cups, const char *printer_name, const char *printer_uri, |