s3-printing: pass lpq command to job_submit
[obnox/samba/samba-obnox.git] / source3 / printing / print_iprint.c
index 82095925b8bf1a42fac49231546419a30e680046..ea0c93778bcadedf1363efdf9bb4a555671205ee 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "includes.h"
 #include "printing.h"
+#include "printing/pcap.h"
 
 #ifdef HAVE_IPRINT
 #include <cups/cups.h>
@@ -296,7 +297,7 @@ static int iprint_cache_add_printer(http_t *http,
                */
 
                if (name != NULL && !secure && smb_enabled) 
-                       pcap_cache_add(name, info);
+                       pcap_cache_add(name, info, NULL);
        }
 
  out:
@@ -305,7 +306,7 @@ static int iprint_cache_add_printer(http_t *http,
        return(0);
 }
 
-BOOL iprint_cache_reload(void)
+bool iprint_cache_reload(void)
 {
        http_t          *http = NULL;           /* HTTP connection to server */
        ipp_t           *request = NULL,        /* IPP Request */
@@ -313,7 +314,7 @@ BOOL iprint_cache_reload(void)
        ipp_attribute_t *attr;                  /* Current attribute */
        cups_lang_t     *language = NULL;       /* Default language */
        int             i;
-       BOOL ret = False;
+       bool ret = False;
 
        DEBUG(5, ("reloading iprint printcap cache\n"));
 
@@ -574,7 +575,8 @@ static int iprint_job_pause(int snum, struct printjob *pjob)
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);
 
-       slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), PRINTERNAME(snum));
+       slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
+                lp_printername(snum));
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
 
@@ -587,7 +589,8 @@ static int iprint_job_pause(int snum, struct printjob *pjob)
        * Do the request and get back a response...
        */
 
-       slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s", PRINTERNAME(snum));
+       slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s",
+                lp_printername(snum));
 
        if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
                if (response->request.status.status_code >= IPP_OK_CONFLICT) {
@@ -672,7 +675,8 @@ static int iprint_job_resume(int snum, struct printjob *pjob)
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);
 
-       slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), PRINTERNAME(snum));
+       slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
+                lp_printername(snum));
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, uri);
 
@@ -685,7 +689,8 @@ static int iprint_job_resume(int snum, struct printjob *pjob)
        * Do the request and get back a response...
        */
 
-       slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s", PRINTERNAME(snum));
+       slprintf(httpPath, sizeof(httpPath) - 1, "/ipp/%s",
+                lp_printername(snum));
 
        if ((response = cupsDoRequest(http, request, httpPath)) != NULL) {
                if (response->request.status.status_code >= IPP_OK_CONFLICT) {
@@ -717,7 +722,9 @@ static int iprint_job_resume(int snum, struct printjob *pjob)
  * 'iprint_job_submit()' - Submit a job for printing.
  */
 
-static int iprint_job_submit(int snum, struct printjob *pjob)
+static int iprint_job_submit(int snum, struct printjob *pjob,
+                            enum printing_types printing_type,
+                            char *lpq_cmd)
 {
        int             ret = 1;                /* Return value */
        http_t          *http = NULL;           /* HTTP connection to server */
@@ -726,7 +733,6 @@ static int iprint_job_submit(int snum, struct printjob *pjob)
        ipp_attribute_t *attr;          /* Current attribute */
        cups_lang_t     *language = NULL;       /* Default language */
        char            uri[HTTP_MAX_URI]; /* printer-uri attribute */
-       const char      *clientname = NULL;     /* hostname of client for job-originating-host attribute */
 
        DEBUG(5,("iprint_job_submit(%d, %p (%d))\n", snum, pjob, pjob->sysjob));
 
@@ -770,7 +776,8 @@ static int iprint_job_submit(int snum, struct printjob *pjob)
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE,
                     "attributes-natural-language", NULL, language->language);
 
-       slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(), PRINTERNAME(snum));
+       slprintf(uri, sizeof(uri) - 1, "ipp://%s/ipp/%s", iprint_server(),
+                lp_printername(snum));
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
                     "printer-uri", NULL, uri);
@@ -778,14 +785,9 @@ static int iprint_job_submit(int snum, struct printjob *pjob)
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
                     NULL, pjob->user);
 
-       clientname = client_name();
-       if (strcmp(clientname, "UNKNOWN") == 0) {
-               clientname = client_addr();
-       }
-       
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME,
                     "job-originating-host-name", NULL,
-                    clientname);
+                    pjob->clientmachine);
 
        ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "job-name", NULL,
                     pjob->jobname);
@@ -794,17 +796,19 @@ static int iprint_job_submit(int snum, struct printjob *pjob)
        * Do the request and get back a response...
        */
 
-       slprintf(uri, sizeof(uri) - 1, "/ipp/%s", PRINTERNAME(snum));
+       slprintf(uri, sizeof(uri) - 1, "/ipp/%s", lp_printername(snum));
 
        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),
+                       DEBUG(0,("Unable to print file to %s - %s\n",
+                                lp_printername(snum),
                                 ippErrorString(cupsLastError())));
                } else {
                        ret = 0;
                }
        } else {
-               DEBUG(0,("Unable to print file to `%s' - %s\n", PRINTERNAME(snum),
+               DEBUG(0,("Unable to print file to `%s' - %s\n",
+                        lp_printername(snum),
                         ippErrorString(cupsLastError())));
        }
 
@@ -864,7 +868,6 @@ static int iprint_queue_get(const char *sharename,
        int             job_id;         /* job-id attribute */
        int             job_k_octets;   /* job-k-octets attribute */
        time_t          job_time;       /* time-at-creation attribute */
-       time_t          printer_current_time = 0;       /* printer's current time */
        time_t          printer_up_time = 0;    /* printer's uptime */
        ipp_jstate_t    job_status;     /* job-status attribute */
        int             job_priority;   /* job-priority attribute */
@@ -991,10 +994,6 @@ static int iprint_queue_get(const char *sharename,
                                     IPP_TAG_TEXT)) != NULL)
                fstrcpy(status->message, attr->values[0].string.text);
 
-       if ((attr = ippFindAttribute(response, "printer-current-time",
-                                    IPP_TAG_DATE)) != NULL)
-               printer_current_time = ippDateToTime(attr->values[0].date);
-
        if ((attr = ippFindAttribute(response, "printer-up-time",
                                     IPP_TAG_INTEGER)) != NULL)
                printer_up_time = attr->values[0].integer;
@@ -1160,7 +1159,7 @@ static int iprint_queue_get(const char *sharename,
                                continue;
                }
 
-               temp->job      = job_id;
+               temp->sysjob   = job_id;
                temp->size     = job_k_octets * 1024;
                temp->status   = job_status == IPP_JOB_PENDING ? LPQ_QUEUED :
                                 job_status == IPP_JOB_STOPPED ? LPQ_PAUSED :