s3-printing: rename queue->job sysjob
[ddiss/samba.git] / source3 / printing / print_cups.c
index b151511b21b2d7d190e5214a6622df04c8bf97da..88f143c0c7381788513046b4db775286ff2e17cf 100644 (file)
@@ -127,7 +127,7 @@ static bool send_pcap_blob(DATA_BLOB *pcap_blob, int fd)
                return false;
        }
 
-       DEBUG(10, ("successfully sent blob of len %ld\n", (int64_t)ret));
+       DEBUG(10, ("successfully sent blob of len %d\n", (int)ret));
        return true;
 }
 
@@ -152,7 +152,7 @@ static bool recv_pcap_blob(TALLOC_CTX *mem_ctx, int fd, DATA_BLOB *pcap_blob)
                return false;
        }
 
-       DEBUG(10, ("successfully recvd blob of len %ld\n", (int64_t)ret));
+       DEBUG(10, ("successfully recvd blob of len %d\n", (int)ret));
        return true;
 }
 
@@ -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;
@@ -398,7 +411,7 @@ static bool cups_pcap_load_async(struct tevent_context *ev,
                return false;
        }
 
-       pid = sys_fork();
+       pid = fork();
        if (pid == (pid_t)-1) {
                DEBUG(10,("cups_pcap_load_async: fork failed %s\n",
                        strerror(errno) ));
@@ -420,7 +433,7 @@ static bool cups_pcap_load_async(struct tevent_context *ev,
 
        close_all_print_db();
 
-       status = reinit_after_fork(msg_ctx, ev, procid_self(), true);
+       status = reinit_after_fork(msg_ctx, ev, true);
        if (!NT_STATUS_IS_OK(status)) {
                DEBUG(0,("cups_pcap_load_async: reinit_after_fork() failed\n"));
                smb_panic("cups_pcap_load_async: reinit_after_fork() failed");
@@ -478,31 +491,25 @@ 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"));
-                       break;
+                       goto err_out;
                }
        }
 
+       /* replace the system-wide pcap cache with a (possibly empty) new one */
+       ret_ok = pcap_cache_replace(tmp_pcap_cache);
        if (!ret_ok) {
-               DEBUG(0, ("failed to read a new printer list\n"));
-               pcap_cache_destroy_specific(&tmp_pcap_cache);
-       } else {
-               /*
-                * replace the system-wide pcap cache with a (possibly empty)
-                * new one.
-                */
-               ret_ok = pcap_cache_replace(tmp_pcap_cache);
-               if (!ret_ok) {
-                       DEBUG(0, ("failed to replace pcap cache\n"));
-               } else if (cb_args->post_cache_fill_fn != NULL) {
-                       /* Caller requested post cache fill callback */
-                       cb_args->post_cache_fill_fn(cb_args->event_ctx,
-                                                   cb_args->msg_ctx);
-               }
+               DEBUG(0, ("failed to replace pcap cache\n"));
+       } else if (cb_args->post_cache_fill_fn != NULL) {
+               /* Caller requested post cache fill callback */
+               cb_args->post_cache_fill_fn(cb_args->event_ctx,
+                                           cb_args->msg_ctx);
        }
 err_out:
+       pcap_cache_destroy_specific(&tmp_pcap_cache);
        TALLOC_FREE(frame);
        close(cb_args->pipe_fd);
        TALLOC_FREE(cb_args);
@@ -517,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;
        }
@@ -864,7 +871,6 @@ static int cups_job_submit(int snum, struct printjob *pjob)
        char *cupsoptions = NULL;
        char *filename = NULL;
        size_t size;
-       uint32_t jobid = (uint32_t)-1;
 
        DEBUG(5,("cups_job_submit(%d, %p)\n", snum, pjob));
 
@@ -926,21 +932,12 @@ static int cups_job_submit(int snum, struct printjob *pjob)
                     "job-originating-host-name", NULL,
                     pjob->clientmachine);
 
-       /* Get the jobid from the filename. */
-       jobid = print_parse_jobid(pjob->filename);
-       if (jobid == (uint32_t)-1) {
-               DEBUG(0,("cups_job_submit: failed to parse jobid from name %s\n",
-                               pjob->filename ));
-               jobid = 0;
-       }
-
        if (!push_utf8_talloc(frame, &jobname, pjob->jobname, &size)) {
                goto out;
        }
        new_jobname = talloc_asprintf(frame,
                        "%s%.8u %s", PRINT_SPOOL_PREFIX,
-                       (unsigned int)jobid,
-                       jobname);
+                       pjob->jobid, jobname);
        if (new_jobname == NULL) {
                goto out;
        }
@@ -1246,7 +1243,7 @@ static int cups_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 :
@@ -1580,178 +1577,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);