diff options
Diffstat (limited to 'source/printing/print_cups.c')
-rw-r--r-- | source/printing/print_cups.c | 595 |
1 files changed, 245 insertions, 350 deletions
diff --git a/source/printing/print_cups.c b/source/printing/print_cups.c index 5cc36d6e170..90af10c3736 100644 --- a/source/printing/print_cups.c +++ b/source/printing/print_cups.c @@ -33,11 +33,11 @@ static const char * /* O - Password or NULL */ cups_passwd_cb(const char *prompt) /* I - Prompt */ { - /* - * Always return NULL to indicate that no password is available... - */ + /* + * Always return NULL to indicate that no password is available... + */ - return (NULL); + return (NULL); } static const char *cups_server(void) @@ -52,19 +52,13 @@ static const char *cups_server(void) return cupsServer(); } -/* - * 'cups_printer_fn()' - Call a function for every printer known to the - * system. - */ - -void cups_printer_fn(void (*fn)(char *, char *)) +BOOL cups_cache_reload(void) { - /* I - Function to call */ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ + 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; /* Default language */ + cups_lang_t *language = NULL; /* Default language */ char *name, /* printer-name attribute */ *info; /* printer-info attribute */ static const char *requested[] =/* Requested attributes */ @@ -72,9 +66,9 @@ void cups_printer_fn(void (*fn)(char *, char *)) "printer-name", "printer-info" }; + BOOL ret = False; - - DEBUG(5,("cups_printer_fn(%p)\n", fn)); + DEBUG(5, ("reloading cups printcap cache\n")); /* * Make sure we don't ask for passwords... @@ -86,11 +80,10 @@ void cups_printer_fn(void (*fn)(char *, char *)) * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return; + goto out; } /* @@ -124,16 +117,13 @@ void cups_printer_fn(void (*fn)(char *, char *)) * Do the request and get back a response... */ - if ((response = cupsDoRequest(http, request, "/")) == NULL) - { + if ((response = cupsDoRequest(http, request, "/")) == NULL) { DEBUG(0,("Unable to get printer list - %s\n", ippErrorString(cupsLastError()))); - httpClose(http); - return; + goto out; } - for (attr = response->attrs; attr != NULL;) - { + for (attr = response->attrs; attr != NULL;) { /* * Skip leading attributes until we hit a printer... */ @@ -151,8 +141,7 @@ void cups_printer_fn(void (*fn)(char *, char *)) name = NULL; info = NULL; - while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) - { + 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; @@ -171,11 +160,13 @@ void cups_printer_fn(void (*fn)(char *, char *)) if (name == NULL) break; - (*fn)(name, info); + if (!pcap_cache_add(name, info)) { + goto out; + } } ippDelete(response); - + response = NULL; /* * Build a CUPS_GET_CLASSES request, which requires the following @@ -191,8 +182,6 @@ void cups_printer_fn(void (*fn)(char *, char *)) 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)); @@ -208,16 +197,13 @@ void cups_printer_fn(void (*fn)(char *, char *)) * Do the request and get back a response... */ - if ((response = cupsDoRequest(http, request, "/")) == NULL) - { + if ((response = cupsDoRequest(http, request, "/")) == NULL) { DEBUG(0,("Unable to get printer list - %s\n", ippErrorString(cupsLastError()))); - httpClose(http); - return; + goto out; } - for (attr = response->attrs; attr != NULL;) - { + for (attr = response->attrs; attr != NULL;) { /* * Skip leading attributes until we hit a printer... */ @@ -235,8 +221,7 @@ void cups_printer_fn(void (*fn)(char *, char *)) name = NULL; info = NULL; - while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) - { + 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; @@ -255,110 +240,24 @@ void cups_printer_fn(void (*fn)(char *, char *)) if (name == NULL) break; - (*fn)(name, info); + if (!pcap_cache_add(name, info)) { + goto out; + } } - ippDelete(response); - - /* - * Close the connection to the server... - */ - - httpClose(http); -} - - -/* - * 'cups_printername_ok()' - Provide the equivalent of pcap_printername_ok() - * for CUPS. - * O - 1 if printer name OK - * I - Name of printer - */ -int cups_printername_ok(const char *name) -{ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - cups_lang_t *language; /* Default language */ - char uri[HTTP_MAX_URI]; /* printer-uri attribute */ - - - DEBUG(5,("cups_printername_ok(\"%s\")\n", name)); + ret = True; - /* - * Make sure we don't ask for passwords... - */ - - cupsSetPasswordCB(cups_passwd_cb); - - /* - * Try to connect to the server... - */ - - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { - DEBUG(3,("Unable to connect to CUPS server %s - %s\n", - cups_server(), strerror(errno))); - return (0); - } - - /* - * Build an IPP_GET_PRINTER_ATTRS request, which requires the following - * attributes: - * - * attributes-charset - * attributes-natural-language - * requested-attributes - * printer-uri - */ - - 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, cupsLangEncoding(language)); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, - "attributes-natural-language", NULL, language->language); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, - "requested-attributes", NULL, "printer-uri"); - - slprintf(uri, sizeof(uri) - 1, "ipp://localhost/printers/%s", name); - - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, - "printer-uri", NULL, uri); + out: + if (response) + ippDelete(response); - /* - * Do the request and get back a response... - */ + if (language) + cupsLangFree(language); - if ((response = cupsDoRequest(http, request, "/")) == NULL) - { - DEBUG(3,("Unable to get printer status for %s - %s\n", name, - ippErrorString(cupsLastError()))); + if (http) httpClose(http); - return (0); - } - httpClose(http); - - if (response->request.status.status_code >= IPP_OK_CONFLICT) - { - DEBUG(3,("Unable to get printer status for %s - %s\n", name, - ippErrorString(response->request.status.status_code))); - ippDelete(response); - return (0); - } - else - { - ippDelete(response); - return (1); - } + return ret; } @@ -366,14 +265,13 @@ int cups_printername_ok(const char *name) * 'cups_job_delete()' - Delete a job. */ -static int -cups_job_delete(int snum, struct printjob *pjob) +static int cups_job_delete(int snum, struct printjob *pjob) { - int ret; /* Return value */ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - cups_lang_t *language; /* Default language */ + int ret = 1; /* Return value */ + http_t *http = NULL; /* HTTP connection to server */ + ipp_t *request = NULL, /* IPP Request */ + *response = NULL; /* IPP Response */ + cups_lang_t *language = NULL; /* Default language */ char uri[HTTP_MAX_URI]; /* printer-uri attribute */ @@ -389,11 +287,10 @@ cups_job_delete(int snum, struct printjob *pjob) * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return (1); + goto out; } /* @@ -430,25 +327,29 @@ cups_job_delete(int snum, struct printjob *pjob) * Do the request and get back a response... */ - ret = 1; - - if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) - { - if (response->request.status.status_code >= IPP_OK_CONFLICT) + if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { + DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob, + ippErrorString(cupsLastError()))); + } else { + ret = 0; + } + } else { DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob, - ippErrorString(cupsLastError()))); - else - ret = 0; - - ippDelete(response); + ippErrorString(cupsLastError()))); } - else - DEBUG(0,("Unable to cancel job %d - %s\n", pjob->sysjob, - ippErrorString(cupsLastError()))); - httpClose(http); + out: + if (response) + ippDelete(response); - return (ret); + if (language) + cupsLangFree(language); + + if (http) + httpClose(http); + + return ret; } @@ -456,14 +357,13 @@ cups_job_delete(int snum, struct printjob *pjob) * 'cups_job_pause()' - Pause a job. */ -static int -cups_job_pause(int snum, struct printjob *pjob) +static int cups_job_pause(int snum, struct printjob *pjob) { - int ret; /* Return value */ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - cups_lang_t *language; /* Default language */ + int ret = 1; /* Return value */ + http_t *http = NULL; /* HTTP connection to server */ + ipp_t *request = NULL, /* IPP Request */ + *response = NULL; /* IPP Response */ + cups_lang_t *language = NULL; /* Default language */ char uri[HTTP_MAX_URI]; /* printer-uri attribute */ @@ -479,11 +379,10 @@ cups_job_pause(int snum, struct printjob *pjob) * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return (1); + goto out; } /* @@ -520,25 +419,29 @@ cups_job_pause(int snum, struct printjob *pjob) * Do the request and get back a response... */ - ret = 1; - - if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) - { - if (response->request.status.status_code >= IPP_OK_CONFLICT) + if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { + DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob, + ippErrorString(cupsLastError()))); + } else { + ret = 0; + } + } else { DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob, - ippErrorString(cupsLastError()))); - else - ret = 0; - - ippDelete(response); + ippErrorString(cupsLastError()))); } - else - DEBUG(0,("Unable to hold job %d - %s\n", pjob->sysjob, - ippErrorString(cupsLastError()))); - httpClose(http); + out: + if (response) + ippDelete(response); - return (ret); + if (language) + cupsLangFree(language); + + if (http) + httpClose(http); + + return ret; } @@ -546,14 +449,13 @@ cups_job_pause(int snum, struct printjob *pjob) * 'cups_job_resume()' - Resume a paused job. */ -static int -cups_job_resume(int snum, struct printjob *pjob) +static int cups_job_resume(int snum, struct printjob *pjob) { - int ret; /* Return value */ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - cups_lang_t *language; /* Default language */ + int ret = 1; /* Return value */ + http_t *http = NULL; /* HTTP connection to server */ + ipp_t *request = NULL, /* IPP Request */ + *response = NULL; /* IPP Response */ + cups_lang_t *language = NULL; /* Default language */ char uri[HTTP_MAX_URI]; /* printer-uri attribute */ @@ -569,11 +471,10 @@ cups_job_resume(int snum, struct printjob *pjob) * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return (1); + goto out; } /* @@ -610,25 +511,29 @@ cups_job_resume(int snum, struct printjob *pjob) * Do the request and get back a response... */ - ret = 1; - - if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) - { - if (response->request.status.status_code >= IPP_OK_CONFLICT) + if ((response = cupsDoRequest(http, request, "/jobs")) != NULL) { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { + DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob, + ippErrorString(cupsLastError()))); + } else { + ret = 0; + } + } else { DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob, - ippErrorString(cupsLastError()))); - else - ret = 0; - - ippDelete(response); + ippErrorString(cupsLastError()))); } - else - DEBUG(0,("Unable to release job %d - %s\n", pjob->sysjob, - ippErrorString(cupsLastError()))); - httpClose(http); + out: + if (response) + ippDelete(response); - return (ret); + if (language) + cupsLangFree(language); + + if (http) + httpClose(http); + + return ret; } @@ -636,19 +541,18 @@ cups_job_resume(int snum, struct printjob *pjob) * 'cups_job_submit()' - Submit a job for printing. */ -static int -cups_job_submit(int snum, struct printjob *pjob) +static int cups_job_submit(int snum, struct printjob *pjob) { - int ret; /* Return value */ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - cups_lang_t *language; /* Default language */ + int ret = 1; /* Return value */ + http_t *http = NULL; /* HTTP connection to server */ + ipp_t *request = NULL, /* IPP Request */ + *response = NULL; /* IPP Response */ + cups_lang_t *language = NULL; /* Default language */ char uri[HTTP_MAX_URI]; /* printer-uri attribute */ - char *clientname; /* hostname of client for job-originating-host attribute */ + char *clientname = NULL; /* hostname of client for job-originating-host attribute */ pstring new_jobname; int num_options = 0; - cups_option_t *options; + cups_option_t *options = NULL; DEBUG(5,("cups_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob)); @@ -662,11 +566,10 @@ cups_job_submit(int snum, struct printjob *pjob) * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return (1); + goto out; } /* @@ -734,28 +637,33 @@ cups_job_submit(int snum, struct printjob *pjob) slprintf(uri, sizeof(uri) - 1, "/printers/%s", PRINTERNAME(snum)); - ret = 1; - if ((response = cupsDoFileRequest(http, request, uri, - pjob->filename)) != NULL) - { - if (response->request.status.status_code >= IPP_OK_CONFLICT) + if ((response = cupsDoFileRequest(http, request, uri, pjob->filename)) != NULL) { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { DEBUG(0,("Unable to print file to %s - %s\n", PRINTERNAME(snum), ippErrorString(cupsLastError()))); - else + } else { ret = 0; - - ippDelete(response); - } - else + } + } else { DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum), ippErrorString(cupsLastError()))); - - httpClose(http); + } if ( ret == 0 ) unlink(pjob->filename); /* else print_job_end will do it for us */ + out: + if (response) + ippDelete(response); + + if (language) + cupsLangFree(language); + + if (http) + httpClose(http); + + return ret; return (ret); } @@ -763,22 +671,21 @@ cups_job_submit(int snum, struct printjob *pjob) * 'cups_queue_get()' - Get all the jobs in the print queue. */ -static int -cups_queue_get(const char *printer_name, +static int cups_queue_get(const char *printer_name, enum printing_types printing_type, char *lpq_command, print_queue_struct **q, print_status_struct *status) { - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - ipp_attribute_t *attr; /* Current attribute */ - cups_lang_t *language; /* Default language */ + http_t *http = NULL; /* HTTP connection to server */ + ipp_t *request = NULL, /* IPP Request */ + *response = NULL; /* IPP Response */ + ipp_attribute_t *attr = NULL; /* Current attribute */ + cups_lang_t *language = NULL; /* Default language */ char uri[HTTP_MAX_URI]; /* printer-uri attribute */ - int qcount, /* Number of active queue entries */ - qalloc; /* Number of queue entries allocated */ - print_queue_struct *queue, /* Queue entries */ + int qcount = 0, /* Number of active queue entries */ + qalloc = 0; /* Number of queue entries allocated */ + print_queue_struct *queue = NULL, /* Queue entries */ *temp; /* Temporary pointer for queue */ const char *user_name, /* job-originating-user-name attribute */ *job_name; /* job-name attribute */ @@ -803,6 +710,7 @@ cups_queue_get(const char *printer_name, "printer-state-message" }; + *q = NULL; DEBUG(5,("cups_queue_get(%s, %p, %p)\n", printer_name, q, status)); @@ -816,11 +724,10 @@ cups_queue_get(const char *printer_name, * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return (0); + goto out; } /* @@ -864,22 +771,16 @@ cups_queue_get(const char *printer_name, * Do the request and get back a response... */ - if ((response = cupsDoRequest(http, request, "/")) == NULL) - { + if ((response = cupsDoRequest(http, request, "/")) == NULL) { DEBUG(0,("Unable to get jobs for %s - %s\n", uri, ippErrorString(cupsLastError()))); - httpClose(http); - return (0); + goto out; } - if (response->request.status.status_code >= IPP_OK_CONFLICT) - { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { DEBUG(0,("Unable to get jobs for %s - %s\n", uri, ippErrorString(response->request.status.status_code))); - ippDelete(response); - httpClose(http); - - return (0); + goto out; } /* @@ -890,8 +791,7 @@ cups_queue_get(const char *printer_name, qalloc = 0; queue = NULL; - for (attr = response->attrs; attr != NULL; attr = attr->next) - { + for (attr = response->attrs; attr != NULL; attr = attr->next) { /* * Skip leading attributes until we hit a job... */ @@ -905,20 +805,16 @@ cups_queue_get(const char *printer_name, /* * Allocate memory as needed... */ - if (qcount >= qalloc) - { + if (qcount >= qalloc) { qalloc += 16; temp = SMB_REALLOC_ARRAY(queue, print_queue_struct, qalloc); - if (temp == NULL) - { + if (temp == NULL) { DEBUG(0,("cups_queue_get: Not enough memory!")); - ippDelete(response); - httpClose(http); - + qcount = 0; SAFE_FREE(queue); - return (0); + goto out; } queue = temp; @@ -939,10 +835,8 @@ cups_queue_get(const char *printer_name, user_name = NULL; job_name = NULL; - while (attr != NULL && attr->group_tag == IPP_TAG_JOB) - { - if (attr->name == NULL) - { + while (attr != NULL && attr->group_tag == IPP_TAG_JOB) { + if (attr->name == NULL) { attr = attr->next; break; } @@ -982,12 +876,11 @@ cups_queue_get(const char *printer_name, * See if we have everything needed... */ - if (user_name == NULL || job_name == NULL || job_id == 0) - { - if (attr == NULL) - break; - else - continue; + if (user_name == NULL || job_name == NULL || job_id == 0) { + if (attr == NULL) + break; + else + continue; } temp->job = job_id; @@ -1004,10 +897,11 @@ cups_queue_get(const char *printer_name, qcount ++; if (attr == NULL) - break; + break; } ippDelete(response); + response = NULL; /* * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the @@ -1019,13 +913,9 @@ cups_queue_get(const char *printer_name, * printer-uri */ - 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, cupsLangEncoding(language)); @@ -1044,31 +934,25 @@ cups_queue_get(const char *printer_name, * Do the request and get back a response... */ - if ((response = cupsDoRequest(http, request, "/")) == NULL) - { + if ((response = cupsDoRequest(http, request, "/")) == NULL) { DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name, ippErrorString(cupsLastError()))); - httpClose(http); *q = queue; - return (qcount); + goto out; } - if (response->request.status.status_code >= IPP_OK_CONFLICT) - { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { DEBUG(0,("Unable to get printer status for %s - %s\n", printer_name, ippErrorString(response->request.status.status_code))); - ippDelete(response); - httpClose(http); *q = queue; - return (qcount); + goto out; } /* * Get the current printer status and convert it to the SAMBA values. */ - if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) - { + if ((attr = ippFindAttribute(response, "printer-state", IPP_TAG_ENUM)) != NULL) { if (attr->values[0].integer == IPP_PRINTER_STOPPED) status->status = LPSTAT_STOPPED; else @@ -1079,16 +963,23 @@ cups_queue_get(const char *printer_name, IPP_TAG_TEXT)) != NULL) fstrcpy(status->message, attr->values[0].string.text); - ippDelete(response); - /* * Return the job queue... */ - httpClose(http); - *q = queue; - return (qcount); + + out: + if (response) + ippDelete(response); + + if (language) + cupsLangFree(language); + + if (http) + httpClose(http); + + return qcount; } @@ -1096,15 +987,14 @@ cups_queue_get(const char *printer_name, * 'cups_queue_pause()' - Pause a print queue. */ -static int -cups_queue_pause(int snum) +static int cups_queue_pause(int snum) { extern userdom_struct current_user_info; - int ret; /* Return value */ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - cups_lang_t *language; /* Default language */ + int ret = 1; /* Return value */ + http_t *http = NULL; /* HTTP connection to server */ + ipp_t *request = NULL, /* IPP Request */ + *response = NULL; /* IPP Response */ + cups_lang_t *language = NULL; /* Default language */ char uri[HTTP_MAX_URI]; /* printer-uri attribute */ @@ -1120,11 +1010,10 @@ cups_queue_pause(int snum) * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return (1); + goto out; } /* @@ -1162,25 +1051,29 @@ cups_queue_pause(int snum) * Do the request and get back a response... */ - ret = 1; - - if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) - { - if (response->request.status.status_code >= IPP_OK_CONFLICT) + if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { + DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum), + ippErrorString(cupsLastError()))); + } else { + ret = 0; + } + } else { DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum), - ippErrorString(cupsLastError()))); - else - ret = 0; - - ippDelete(response); + ippErrorString(cupsLastError()))); } - else - DEBUG(0,("Unable to pause printer %s - %s\n", PRINTERNAME(snum), - ippErrorString(cupsLastError()))); - httpClose(http); + out: + if (response) + ippDelete(response); - return (ret); + if (language) + cupsLangFree(language); + + if (http) + httpClose(http); + + return ret; } @@ -1188,15 +1081,14 @@ cups_queue_pause(int snum) * 'cups_queue_resume()' - Restart a print queue. */ -static int -cups_queue_resume(int snum) +static int cups_queue_resume(int snum) { extern userdom_struct current_user_info; - int ret; /* Return value */ - http_t *http; /* HTTP connection to server */ - ipp_t *request, /* IPP Request */ - *response; /* IPP Response */ - cups_lang_t *language; /* Default language */ + int ret = 1; /* Return value */ + http_t *http = NULL; /* HTTP connection to server */ + ipp_t *request = NULL, /* IPP Request */ + *response = NULL; /* IPP Response */ + cups_lang_t *language = NULL; /* Default language */ char uri[HTTP_MAX_URI]; /* printer-uri attribute */ @@ -1212,11 +1104,10 @@ cups_queue_resume(int snum) * Try to connect to the server... */ - if ((http = httpConnect(cups_server(), ippPort())) == NULL) - { + if ((http = httpConnect(cups_server(), ippPort())) == NULL) { DEBUG(0,("Unable to connect to CUPS server %s - %s\n", cups_server(), strerror(errno))); - return (1); + goto out; } /* @@ -1254,25 +1145,29 @@ cups_queue_resume(int snum) * Do the request and get back a response... */ - ret = 1; - - if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) - { - if (response->request.status.status_code >= IPP_OK_CONFLICT) + if ((response = cupsDoRequest(http, request, "/admin/")) != NULL) { + if (response->request.status.status_code >= IPP_OK_CONFLICT) { + DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum), + ippErrorString(cupsLastError()))); + } else { + ret = 0; + } + } else { DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum), - ippErrorString(cupsLastError()))); - else - ret = 0; - - ippDelete(response); + ippErrorString(cupsLastError()))); } - else - DEBUG(0,("Unable to resume printer %s - %s\n", PRINTERNAME(snum), - ippErrorString(cupsLastError()))); - httpClose(http); + out: + if (response) + ippDelete(response); - return (ret); + if (language) + cupsLangFree(language); + + if (http) + httpClose(http); + + return ret; } /******************************************************************* |