diff options
Diffstat (limited to 'source3/printing/print_cups.c')
-rw-r--r-- | source3/printing/print_cups.c | 192 |
1 files changed, 17 insertions, 175 deletions
diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c index da42cb6f85..b8bbddfebd 100644 --- a/source3/printing/print_cups.c +++ b/source3/printing/print_cups.c @@ -163,6 +163,7 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx, ipp_attribute_t *attr; char *name; char *info; + char *location = NULL; struct pcap_printer *printer; bool ret_ok = false; @@ -206,6 +207,16 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx, } } + if (strcmp(attr->name, "printer-location") == 0 && + attr->value_tag == IPP_TAG_TEXT) { + if (!pull_utf8_talloc(mem_ctx, + &location, + attr->values[0].string.text, + &size)) { + goto err_out; + } + } + attr = attr->next; } @@ -229,6 +240,7 @@ static bool process_cups_printers_response(TALLOC_CTX *mem_ctx, pcap_data->printers = printer; pcap_data->printers[pcap_data->count].name = name; pcap_data->printers[pcap_data->count].info = info; + pcap_data->printers[pcap_data->count].location = location; pcap_data->count++; } @@ -252,7 +264,8 @@ static bool cups_cache_reload_async(int fd) static const char *requested[] =/* Requested attributes */ { "printer-name", - "printer-info" + "printer-info", + "printer-location" }; bool ret = False; enum ndr_err_code ndr_ret; @@ -478,7 +491,8 @@ static void cups_async_callback(struct event_context *event_ctx, for (i = 0; i < pcap_data.count; i++) { ret_ok = pcap_cache_add_specific(&tmp_pcap_cache, pcap_data.printers[i].name, - pcap_data.printers[i].info); + pcap_data.printers[i].info, + pcap_data.printers[i].location); if (!ret_ok) { DEBUG(0, ("failed to add to tmp pcap cache\n")); goto err_out; @@ -510,7 +524,7 @@ bool cups_cache_reload(struct tevent_context *ev, struct cups_async_cb_args *cb_args; int *p_pipe_fd; - cb_args = TALLOC_P(NULL, struct cups_async_cb_args); + cb_args = talloc(NULL, struct cups_async_cb_args); if (cb_args == NULL) { return false; } @@ -1573,178 +1587,6 @@ struct printif cups_printif = cups_job_submit, }; -bool cups_pull_comment_location(TALLOC_CTX *mem_ctx, - const char *printername, - char **comment, - char **location) -{ - TALLOC_CTX *frame = talloc_stackframe(); - http_t *http = NULL; /* HTTP connection to server */ - ipp_t *request = NULL, /* IPP Request */ - *response = NULL; /* IPP Response */ - ipp_attribute_t *attr; /* Current attribute */ - cups_lang_t *language = NULL; /* Default language */ - char uri[HTTP_MAX_URI]; - char *server = NULL; - char *sharename = NULL; - char *name = NULL; - static const char *requested[] =/* Requested attributes */ - { - "printer-name", - "printer-info", - "printer-location" - }; - bool ret = False; - size_t size; - - DEBUG(5, ("pulling %s location\n", printername)); - - /* - * Make sure we don't ask for passwords... - */ - - cupsSetPasswordCB(cups_passwd_cb); - - /* - * Try to connect to the server... - */ - - if ((http = cups_connect(frame)) == NULL) { - goto out; - } - - request = ippNew(); - - request->request.op.operation_id = IPP_GET_PRINTER_ATTRIBUTES; - request->request.op.request_id = 1; - - language = cupsLangDefault(); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET, - "attributes-charset", NULL, "utf-8"); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, - "attributes-natural-language", NULL, language->language); - - if (lp_cups_server() != NULL && strlen(lp_cups_server()) > 0) { - if (!push_utf8_talloc(frame, &server, lp_cups_server(), &size)) { - goto out; - } - } else { - server = talloc_strdup(frame,cupsServer()); - } - if (server) { - goto out; - } - if (!push_utf8_talloc(frame, &sharename, printername, &size)) { - goto out; - } - slprintf(uri, sizeof(uri) - 1, "ipp://%s/printers/%s", - server, sharename); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, - "printer-uri", NULL, uri); - - 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 attributes - %s\n", - ippErrorString(cupsLastError()))); - goto out; - } - - 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... - */ - - while ( attr && (attr->group_tag == IPP_TAG_PRINTER) ) { - if (strcmp(attr->name, "printer-name") == 0 && - attr->value_tag == IPP_TAG_NAME) { - if (!pull_utf8_talloc(frame, - &name, - attr->values[0].string.text, - &size)) { - goto out; - } - } - - /* Grab the comment if we don't have one */ - if ( (strcmp(attr->name, "printer-info") == 0) - && (attr->value_tag == IPP_TAG_TEXT)) - { - if (!pull_utf8_talloc(mem_ctx, - comment, - attr->values[0].string.text, - &size)) { - goto out; - } - DEBUG(5,("cups_pull_comment_location: Using cups comment: %s\n", - *comment)); - } - - /* Grab the location if we don't have one */ - if ( (strcmp(attr->name, "printer-location") == 0) - && (attr->value_tag == IPP_TAG_TEXT)) - { - if (!pull_utf8_talloc(mem_ctx, - location, - attr->values[0].string.text, - &size)) { - goto out; - } - DEBUG(5,("cups_pull_comment_location: Using cups location: %s\n", - *location)); - } - - attr = attr->next; - } - - /* - * We have everything needed... - */ - - if (name != NULL) - break; - } - - ret = True; - - out: - if (response) - ippDelete(response); - - if (request) { - ippDelete(request); - } - - if (language) - cupsLangFree(language); - - if (http) - httpClose(http); - - TALLOC_FREE(frame); - return ret; -} - #else /* this keeps fussy compilers happy */ void print_cups_dummy(void); |