]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/ipp-var.c
Sandboxed applications were not able to get the default printer (Issue #5676)
[thirdparty/cups.git] / cgi-bin / ipp-var.c
index 764cf8a4da17d27e6d4bdda5d10bf28950a35165..8c5a5616dd5232ab5c3f52b5239d96381f5034c0 100644 (file)
@@ -1,16 +1,10 @@
 /*
- * "$Id$"
- *
  * CGI <-> IPP variable routines for CUPS.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products.
  *
- * These coded instructions, statements, and computer programs are the
- * property of Apple Inc. and are protected by Federal copyright
- * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -222,6 +216,9 @@ cgiGetIPPObjects(ipp_t *response,   /* I - IPP response */
              break;
 
           case IPP_TAG_INTEGER :
+             if (!strncmp(ippGetName(attr), "time-at-", 8))
+               break;                  /* Ignore time-at-xxx */
+
              for (i = 0; !add && i < attr->num_values; i ++)
              {
                char    buf[255];       /* Number buffer */
@@ -939,7 +936,6 @@ cgiSetIPPObjectVars(
                        *nameptr,       /* Pointer into name */
                        value[16384],   /* Value(s) */
                        *valptr;        /* Pointer into value */
-  struct tm            *date;          /* Date information */
 
 
   fprintf(stderr, "DEBUG2: cgiSetIPPObjectVars(obj=%p, prefix=\"%s\", "
@@ -1167,17 +1163,9 @@ cgiSetIPPObjectVars(
        case IPP_TAG_INTEGER :
        case IPP_TAG_ENUM :
            if (strncmp(name, "time_at_", 8) == 0)
-           {
-             time_t    t;              /* Temporary time value */
-
-              t    = (time_t)attr->values[i].integer;
-             date = localtime(&t);
-
-             strftime(valptr, sizeof(value) - (size_t)(valptr - value), "%c", date);
-           }
+             _cupsStrDate(valptr, sizeof(value) - (size_t)(valptr - value), (time_t)ippGetInteger(attr, i));
            else
-             snprintf(valptr, sizeof(value) - (size_t)(valptr - value),
-                      "%d", attr->values[i].integer);
+             snprintf(valptr, sizeof(value) - (size_t)(valptr - value), "%d", ippGetInteger(attr, i));
            break;
 
        case IPP_TAG_BOOLEAN :
@@ -1211,21 +1199,7 @@ cgiSetIPPObjectVars(
              * Rewrite URIs...
              */
 
-              if (!strcmp(name, "member_uris"))
-             {
-               char    url[1024];      /* URL for class member... */
-
-
-               cgiRewriteURL(attr->values[i].string.text, url,
-                             sizeof(url), NULL);
-
-                snprintf(valptr, sizeof(value) - (size_t)(valptr - value),
-                        "<A HREF=\"%s\">%s</A>", url,
-                        strrchr(attr->values[i].string.text, '/') + 1);
-             }
-             else
-               cgiRewriteURL(attr->values[i].string.text, valptr,
-                             (int)(sizeof(value) - (size_t)(valptr - value)), NULL);
+             cgiRewriteURL(attr->values[i].string.text, valptr, (int)(sizeof(value) - (size_t)(valptr - value)), NULL);
               break;
             }
 
@@ -1345,7 +1319,7 @@ cgiSetIPPVars(ipp_t      *response,       /* I - Response data to be copied... */
     attr = cgiSetIPPObjectVars(attr, prefix, element);
   }
 
-  fprintf(stderr, "DEBUG2: Returing %d from cgiSetIPPVars()...\n", element);
+  fprintf(stderr, "DEBUG2: Returning %d from cgiSetIPPVars()...\n", element);
 
   return (element);
 }
@@ -1380,8 +1354,7 @@ cgiShowJobs(http_t     *http,             /* I - Connection to server */
                        *response;      /* IPP response */
   cups_array_t         *jobs;          /* Array of job objects */
   ipp_attribute_t      *job;           /* Job object */
-  int                  ascending,      /* Order of jobs (0 = descending) */
-                       first,          /* First job to show */
+  int                  first,          /* First job to show */
                        count;          /* Number of jobs */
   const char           *var,           /* Form variable */
                        *query,         /* Query string */
@@ -1417,6 +1390,17 @@ cgiShowJobs(http_t     *http,            /* I - Connection to server */
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs",
                  NULL, which_jobs);
 
+  if ((var = cgiGetVariable("FIRST")) != NULL)
+  {
+    if ((first = atoi(var)) < 0)
+      first = 0;
+  }
+  else
+    first = 0;
+
+  if (first > 0)
+    ippAddInteger(request, IPP_TAG_OPERATION, IPP_TAG_INTEGER, "first-index", first + 1);
+
   cgiGetAttributes(request, "jobs.tmpl");
 
  /*
@@ -1439,7 +1423,7 @@ cgiShowJobs(http_t     *http,             /* I - Connection to server */
     }
 
     jobs  = cgiGetIPPObjects(response, search);
-    count = cupsArrayCount(jobs);
+    count = cupsArrayCount(jobs) + first;
 
     if (search)
       cgiFreeSearch(search);
@@ -1448,25 +1432,6 @@ cgiShowJobs(http_t     *http,            /* I - Connection to server */
     * Figure out which jobs to display...
     */
 
-    if ((var = cgiGetVariable("FIRST")) != NULL)
-      first = atoi(var);
-    else
-      first = 0;
-
-    if (first >= count)
-      first = count - CUPS_PAGE_MAX;
-
-    first = (first / CUPS_PAGE_MAX) * CUPS_PAGE_MAX;
-
-    if (first < 0)
-      first = 0;
-
-    if ((var = cgiGetVariable("ORDER")) != NULL && *var)
-      ascending = !_cups_strcasecmp(var, "asc");
-    else
-      ascending = !which_jobs || !*which_jobs ||
-                  !_cups_strcasecmp(which_jobs, "not-completed");
-
     section = cgiGetVariable("SECTION");
 
     cgiClearVariables();
@@ -1474,8 +1439,6 @@ cgiShowJobs(http_t     *http,             /* I - Connection to server */
     if (query)
       cgiSetVariable("QUERY", query);
 
-    cgiSetVariable("ORDER", ascending ? "asc" : "dec");
-
     cgiSetVariable("SECTION", section);
 
     sprintf(val, "%d", count);
@@ -1484,20 +1447,10 @@ cgiShowJobs(http_t     *http,           /* I - Connection to server */
     if (which_jobs)
       cgiSetVariable("WHICH_JOBS", which_jobs);
 
-    if (ascending)
-    {
-      for (i = 0, job = (ipp_attribute_t *)cupsArrayIndex(jobs, first);
-          i < CUPS_PAGE_MAX && job;
-          i ++, job = (ipp_attribute_t *)cupsArrayNext(jobs))
-        cgiSetIPPObjectVars(job, NULL, i);
-    }
-    else
-    {
-      for (i = 0, job = (ipp_attribute_t *)cupsArrayIndex(jobs, count - first - 1);
-          i < CUPS_PAGE_MAX && job;
-          i ++, job = (ipp_attribute_t *)cupsArrayPrev(jobs))
-        cgiSetIPPObjectVars(job, NULL, i);
-    }
+    for (i = 0, job = (ipp_attribute_t *)cupsArrayFirst(jobs);
+        i < CUPS_PAGE_MAX && job;
+        i ++, job = (ipp_attribute_t *)cupsArrayNext(jobs))
+      cgiSetIPPObjectVars(job, NULL, i);
 
    /*
     * Save navigation URLs...
@@ -1526,6 +1479,12 @@ cgiShowJobs(http_t     *http,            /* I - Connection to server */
       cgiSetVariable("NEXT", val);
     }
 
+    if (count > CUPS_PAGE_MAX)
+    {
+      snprintf(val, sizeof(val), "%d", CUPS_PAGE_MAX * (count / CUPS_PAGE_MAX));
+      cgiSetVariable("LAST", val);
+    }
+
    /*
     * Then show everything...
     */
@@ -1567,8 +1526,3 @@ cgiText(const char *message)              /* I - Message */
 
   return (_cupsLangString(language, message));
 }
-
-
-/*
- * End of "$Id$".
- */