summaryrefslogtreecommitdiff
path: root/cgi-bin
diff options
context:
space:
mode:
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2009-12-09 18:36:59 +0000
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>2009-12-09 18:36:59 +0000
commitef55b7453303a9a2b20590815c967d044a13da1d (patch)
tree948eaac8dcc2bfdff77ca367ea8ff058cda8c109 /cgi-bin
parent3fb9c47ea669977c856ad82b3ea593ec76d136ec (diff)
Merge changes from CUPS 1.5svn-r8916.
git-svn-id: svn+ssh://src.apple.com/svn/cups/easysw/current@1766 a1ca3aef-8c08-0410-bb20-df032aa958be
Diffstat (limited to 'cgi-bin')
-rw-r--r--cgi-bin/admin.c221
-rw-r--r--cgi-bin/cgi.h13
-rw-r--r--cgi-bin/classes.c1
-rw-r--r--cgi-bin/help-index.h12
-rw-r--r--cgi-bin/help.c11
-rw-r--r--cgi-bin/ipp-var.c44
-rw-r--r--cgi-bin/jobs.c1
-rw-r--r--cgi-bin/libcupscgi.exp1
-rw-r--r--cgi-bin/printers.c1
-rw-r--r--cgi-bin/template.c6
-rw-r--r--cgi-bin/var.c44
11 files changed, 259 insertions, 96 deletions
diff --git a/cgi-bin/admin.c b/cgi-bin/admin.c
index 520e6e50f..cdb1a2a89 100644
--- a/cgi-bin/admin.c
+++ b/cgi-bin/admin.c
@@ -49,14 +49,6 @@
/*
- * Local globals...
- */
-
-static int current_device; /* Current device for add/modify */
-static time_t last_device_time; /* Last update time for device list */
-
-
-/*
* Local functions...
*/
@@ -65,7 +57,7 @@ static void choose_device_cb(const char *device_class,
const char *device_make_and_model,
const char *device_uri,
const char *device_location,
- const char *title);
+ int *current_device);
static void do_add_rss_subscription(http_t *http);
static void do_am_class(http_t *http, int modify);
static void do_am_printer(http_t *http, int modify);
@@ -122,6 +114,7 @@ main(int argc, /* I - Number of command-line arguments */
*/
cgiSetVariable("SECTION", "admin");
+ cgiSetVariable("REFRESH_PAGE", "");
/*
* See if we have form data...
@@ -191,7 +184,7 @@ main(int argc, /* I - Number of command-line arguments */
}
else if (op && !strcmp(op, "redirect"))
{
- const char *url; /* Redirection URL... */
+ const char *url; /* Redirection URL... */
char prefix[1024]; /* URL prefix */
@@ -205,7 +198,50 @@ main(int argc, /* I - Number of command-line arguments */
fprintf(stderr, "DEBUG: redirecting with prefix %s!\n", prefix);
if ((url = cgiGetVariable("URL")) != NULL)
- printf("Location: %s%s\n\n", prefix, url);
+ {
+ char encoded[1024], /* Encoded URL string */
+ *ptr; /* Pointer into encoded string */
+
+
+ ptr = encoded;
+ if (*url != '/')
+ *ptr++ = '/';
+
+ for (; *url && ptr < (encoded + sizeof(encoded) - 4); url ++)
+ {
+ if (strchr("%@&+ <>#=", *url) || *url < ' ' || *url & 128)
+ {
+ /*
+ * Percent-encode this character; safe because we have at least 4
+ * bytes left in the array...
+ */
+
+ sprintf(ptr, "%%%02X", *url & 255);
+ ptr += 3;
+ }
+ else
+ *ptr++ = *url;
+ }
+
+ *ptr = '\0';
+
+ if (*url)
+ {
+ /*
+ * URL was too long, just redirect to the admin page...
+ */
+
+ printf("Location: %s/admin\n\n", prefix);
+ }
+ else
+ {
+ /*
+ * URL is OK, redirect there...
+ */
+
+ printf("Location: %s%s\n\n", prefix, encoded);
+ }
+ }
else
printf("Location: %s/admin\n\n", prefix);
}
@@ -246,37 +282,20 @@ choose_device_cb(
const char *device_make_and_model, /* I - Make and model */
const char *device_uri, /* I - Device URI */
const char *device_location, /* I - Location */
- const char *title) /* I - Page title */
+ int *current_device) /* I - Current device index */
{
/*
* Add the device to the array...
*/
- cgiSetArray("device_class", current_device, device_class);
- cgiSetArray("device_id", current_device, device_id);
- cgiSetArray("device_info", current_device, device_info);
- cgiSetArray("device_make_and_model", current_device, device_make_and_model);
- cgiSetArray("device_uri", current_device, device_uri);
- cgiSetArray("device_location", current_device, device_location);
-
- current_device ++;
-
- if (time(NULL) > last_device_time && cgiSupportsMultipart())
- {
- /*
- * Update the page...
- */
-
- if (!last_device_time)
- cgiStartMultipart();
-
- cgiStartHTML(title);
- cgiCopyTemplateLang("choose-device.tmpl");
- cgiEndHTML();
- fflush(stdout);
+ cgiSetArray("device_class", *current_device, device_class);
+ cgiSetArray("device_id", *current_device, device_id);
+ cgiSetArray("device_info", *current_device, device_info);
+ cgiSetArray("device_make_and_model", *current_device, device_make_and_model);
+ cgiSetArray("device_uri", *current_device, device_uri);
+ cgiSetArray("device_location", *current_device, device_location);
- time(&last_device_time);
- }
+ (*current_device) ++;
}
@@ -345,6 +364,31 @@ do_add_rss_subscription(http_t *http) /* I - HTTP connection */
* and classes and (re)show the add page...
*/
+ if (cgiGetVariable("EVENT_JOB_CREATED"))
+ cgiSetVariable("EVENT_JOB_CREATED", "CHECKED");
+ if (cgiGetVariable("EVENT_JOB_COMPLETED"))
+ cgiSetVariable("EVENT_JOB_COMPLETED", "CHECKED");
+ if (cgiGetVariable("EVENT_JOB_STOPPED"))
+ cgiSetVariable("EVENT_JOB_STOPPED", "CHECKED");
+ if (cgiGetVariable("EVENT_JOB_CONFIG_CHANGED"))
+ cgiSetVariable("EVENT_JOB_CONFIG_CHANGED", "CHECKED");
+ if (cgiGetVariable("EVENT_PRINTER_STOPPED"))
+ cgiSetVariable("EVENT_PRINTER_STOPPED", "CHECKED");
+ if (cgiGetVariable("EVENT_PRINTER_ADDED"))
+ cgiSetVariable("EVENT_PRINTER_ADDED", "CHECKED");
+ if (cgiGetVariable("EVENT_PRINTER_MODIFIED"))
+ cgiSetVariable("EVENT_PRINTER_MODIFIED", "CHECKED");
+ if (cgiGetVariable("EVENT_PRINTER_DELETED"))
+ cgiSetVariable("EVENT_PRINTER_DELETED", "CHECKED");
+ if (cgiGetVariable("EVENT_SERVER_STARTED"))
+ cgiSetVariable("EVENT_SERVER_STARTED", "CHECKED");
+ if (cgiGetVariable("EVENT_SERVER_STOPPED"))
+ cgiSetVariable("EVENT_SERVER_STOPPED", "CHECKED");
+ if (cgiGetVariable("EVENT_SERVER_RESTARTED"))
+ cgiSetVariable("EVENT_SERVER_RESTARTED", "CHECKED");
+ if (cgiGetVariable("EVENT_SERVER_AUDIT"))
+ cgiSetVariable("EVENT_SERVER_AUDIT", "CHECKED");
+
request = ippNewRequest(CUPS_GET_PRINTERS);
response = cupsDoRequest(http, request, "/");
@@ -467,6 +511,7 @@ do_am_class(http_t *http, /* I - HTTP connection */
ipp_attribute_t *attr; /* member-uris attribute */
char uri[HTTP_MAX_URI]; /* Device or printer URI */
const char *name, /* Pointer to class name */
+ *op, /* Operation name */
*ptr; /* Pointer to CGI variable */
const char *title; /* Title of page */
static const char * const pattrs[] = /* Requested printer attributes */
@@ -478,6 +523,7 @@ do_am_class(http_t *http, /* I - HTTP connection */
title = cgiText(modify ? _("Modify Class") : _("Add Class"));
+ op = cgiGetVariable("OP");
name = cgiGetVariable("PRINTER_NAME");
if (cgiGetVariable("PRINTER_LOCATION") == NULL)
@@ -502,6 +548,12 @@ do_am_class(http_t *http, /* I - HTTP connection */
* Do the request and get back a response...
*/
+ cgiClearVariables();
+ if (op)
+ cgiSetVariable("OP", op);
+ if (name)
+ cgiSetVariable("PRINTER_NAME", name);
+
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
/*
@@ -764,6 +816,7 @@ do_am_printer(http_t *http, /* I - HTTP connection */
const char *name, /* Pointer to class name */
*ptr; /* Pointer to CGI variable */
const char *title; /* Title of page */
+ int current_device; /* Index of current device */
static int baudrates[] = /* Baud rates */
{
1200,
@@ -924,31 +977,42 @@ do_am_printer(http_t *http, /* I - HTTP connection */
}
/*
- * Scan for devices for up to 30 seconds, updating the page as we find
- * them...
+ * For modern browsers, start a multi-part page so we can show that something
+ * is happening. Non-modern browsers just get everything at the end...
+ */
+
+ if (cgiSupportsMultipart())
+ {
+ cgiStartMultipart();
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("choose-device.tmpl");
+ cgiEndHTML();
+ fflush(stdout);
+ }
+
+ /*
+ * Scan for devices for up to 30 seconds...
*/
fputs("DEBUG: Getting list of devices...\n", stderr);
- last_device_time = 0;
- current_device = 0;
+ current_device = 0;
if (cupsGetDevices(http, 30, CUPS_INCLUDE_ALL, CUPS_EXCLUDE_NONE,
(cups_device_cb_t)choose_device_cb,
- (void *)title) == IPP_OK)
+ &current_device) == IPP_OK)
{
fputs("DEBUG: Got device list!\n", stderr);
- if (!cgiSupportsMultipart())
- {
- /*
- * Non-modern browsers that don't support multi-part documents get
- * everything at the end...
- */
+ if (cgiSupportsMultipart())
+ cgiStartMultipart();
- cgiStartHTML(title);
- cgiCopyTemplateLang("choose-device.tmpl");
- cgiEndHTML();
- }
+ cgiSetVariable("CUPS_GET_DEVICES_DONE", "1");
+ cgiStartHTML(title);
+ cgiCopyTemplateLang("choose-device.tmpl");
+ cgiEndHTML();
+
+ if (cgiSupportsMultipart())
+ cgiEndMultipart();
}
else
{
@@ -969,16 +1033,6 @@ do_am_printer(http_t *http, /* I - HTTP connection */
return;
}
}
-
- /*
- * Show the final selection page...
- */
-
- cgiSetVariable("CUPS_GET_DEVICES_DONE", "1");
- cgiStartHTML(title);
- cgiCopyTemplateLang("choose-device.tmpl");
- cgiEndHTML();
- cgiEndMultipart();
}
else if (strchr(var, '/') == NULL)
{
@@ -1044,6 +1098,11 @@ do_am_printer(http_t *http, /* I - HTTP connection */
if ((attr = ippFindAttribute(oldinfo, "printer-location",
IPP_TAG_TEXT)) != NULL)
cgiSetVariable("PRINTER_LOCATION", attr->values[0].string.text);
+
+ if ((attr = ippFindAttribute(oldinfo, "printer-is-shared",
+ IPP_TAG_BOOLEAN)) != NULL)
+ cgiSetVariable("PRINTER_IS_SHARED",
+ attr->values[0].boolean ? "1" : "0");
}
cgiCopyTemplateLang("modify-printer.tmpl");
@@ -1179,7 +1238,7 @@ do_am_printer(http_t *http, /* I - HTTP connection */
* Got the list of PPDs, see if the user has selected a make...
*/
- if (cgiSetIPPVars(response, NULL, NULL, NULL, 0) == 0)
+ if (cgiSetIPPVars(response, NULL, NULL, NULL, 0) == 0 && !modify)
{
/*
* No PPD files with this make, try again with all makes...
@@ -1215,8 +1274,11 @@ do_am_printer(http_t *http, /* I - HTTP connection */
*/
cgiStartHTML(title);
- cgiSetVariable("CURRENT_MAKE_AND_MODEL",
- cgiGetArray("PPD_MAKE_AND_MODEL", 0));
+ if (!cgiGetVariable("PPD_MAKE"))
+ cgiSetVariable("PPD_MAKE", cgiGetVariable("CURRENT_MAKE"));
+ if (!modify)
+ cgiSetVariable("CURRENT_MAKE_AND_MODEL",
+ cgiGetArray("PPD_MAKE_AND_MODEL", 0));
cgiCopyTemplateLang("choose-model.tmpl");
cgiEndHTML();
}
@@ -1508,7 +1570,7 @@ do_config_server(http_t *http) /* I - HTTP connection */
#ifdef HAVE_GSSAPI
char default_auth_type[255];
/* DefaultAuthType value */
- const char *val; /* Setting value */
+ const char *val; /* Setting value */
#endif /* HAVE_GSSAPI */
@@ -1580,7 +1642,7 @@ do_config_server(http_t *http) /* I - HTTP connection */
strcat(local_protocols, "slp");
}
#endif /* HAVE_SLP */
-
+
if (cgiGetVariable("BROWSE_REMOTE_CUPS"))
strcpy(remote_protocols, "cups");
else
@@ -1833,7 +1895,7 @@ do_config_server(http_t *http) /* I - HTTP connection */
cgiSetVariable("ERROR", strerror(errno));
cgiCopyTemplateLang("error.tmpl");
cgiEndHTML();
-
+
perror(tempfile);
return;
}
@@ -1845,7 +1907,7 @@ do_config_server(http_t *http) /* I - HTTP connection */
cgiSetVariable("ERROR", strerror(errno));
cgiCopyTemplateLang("error.tmpl");
cgiEndHTML();
-
+
perror(tempfile);
close(tempfd);
unlink(tempfile);
@@ -2621,7 +2683,9 @@ do_menu(http_t *http) /* I - HTTP connection */
if ((val = cupsGetOption("DefaultAuthType", num_settings,
settings)) != NULL && !strcasecmp(val, "Negotiate"))
cgiSetVariable("KERBEROS", "CHECKED");
+ else
#endif /* HAVE_GSSAPI */
+ cgiSetVariable("KERBEROS", "");
#ifdef HAVE_DNSSD
cgiSetVariable("HAVE_DNSSD", "1");
@@ -3233,11 +3297,16 @@ do_set_options(http_t *http, /* I - HTTP connection */
for (option = ppdFirstOption(ppd);
option;
option = ppdNextOption(ppd))
+ {
if ((var = cgiGetVariable(option->keyword)) != NULL)
{
have_options = 1;
ppdMarkOption(ppd, option->keyword, var);
+ fprintf(stderr, "DEBUG: Set %s to %s...\n", option->keyword, var);
}
+ else
+ fprintf(stderr, "DEBUG: Didn't find %s...\n", option->keyword);
+ }
}
if (!have_options || ppdConflicts(ppd))
@@ -3258,7 +3327,7 @@ do_set_options(http_t *http, /* I - HTTP connection */
((ppdattr = ppdFindAttr(ppd, "cupsCommands", NULL)) != NULL &&
ppdattr->value && strstr(ppdattr->value, "AutoConfigure")))
cgiSetVariable("HAVE_AUTOCONFIGURE", "YES");
- else
+ else
{
for (i = 0; i < ppd->num_filters; i ++)
if (!strncmp(ppd->filters[i], "application/vnd.cups-postscript", 31))
@@ -3344,6 +3413,16 @@ do_set_options(http_t *http, /* I - HTTP connection */
{
cgiSetArray("ckeyword", k, option->keyword);
cgiSetArray("ckeytext", k, option->text);
+
+ for (m = 0; m < option->num_choices; m ++)
+ {
+ if (option->choices[m].marked)
+ {
+ cgiSetArray("cchoice", k, option->choices[m].text);
+ break;
+ }
+ }
+
k ++;
}
@@ -3362,7 +3441,7 @@ do_set_options(http_t *http, /* I - HTTP connection */
cgiSetVariable("GROUP", group->text);
cgiCopyTemplateLang("option-header.tmpl");
-
+
for (j = group->num_options, option = group->options;
j > 0;
j --, option ++)
@@ -4006,7 +4085,7 @@ get_option_value(
snprintf(buffer, bufsize, "Custom.%gx%g%s", width, length, uval);
}
- else if (cupsArrayCount(coption->params) == 1)
+ else if (cupsArrayCount(coption->params) == 1)
{
cparam = ppdFirstCustomParam(coption);
snprintf(keyword, sizeof(keyword), "%s.%s", coption->keyword, cparam->name);
diff --git a/cgi-bin/cgi.h b/cgi-bin/cgi.h
index 5546d7ac5..52368ee35 100644
--- a/cgi-bin/cgi.h
+++ b/cgi-bin/cgi.h
@@ -34,6 +34,14 @@
/*
+ * C++ magic...
+ */
+
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+
+/*
* Types...
*/
@@ -54,6 +62,7 @@ typedef struct cgi_file_s /**** Uploaded file data ****/
extern void cgiAbort(const char *title, const char *stylesheet,
const char *format, ...);
extern int cgiCheckVariables(const char *names);
+extern void cgiClearVariables(void);
extern void *cgiCompileSearch(const char *query);
extern void cgiCopyTemplateFile(FILE *out, const char *tmpl);
extern void cgiCopyTemplateLang(const char *tmpl);
@@ -98,6 +107,10 @@ extern void cgiStartMultipart(void);
extern int cgiSupportsMultipart(void);
extern const char *cgiText(const char *message);
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+
#endif /* !_CUPS_CGI_H_ */
/*
diff --git a/cgi-bin/classes.c b/cgi-bin/classes.c
index b7ea287a5..7fa7eb80e 100644
--- a/cgi-bin/classes.c
+++ b/cgi-bin/classes.c
@@ -72,6 +72,7 @@ main(int argc, /* I - Number of command-line arguments */
*/
cgiSetVariable("SECTION", "classes");
+ cgiSetVariable("REFRESH_PAGE", "");
/*
* See if we are displaying a printer or all classes...
diff --git a/cgi-bin/help-index.h b/cgi-bin/help-index.h
index 0e6b0b1c7..d64cec02a 100644
--- a/cgi-bin/help-index.h
+++ b/cgi-bin/help-index.h
@@ -24,6 +24,14 @@
/*
+ * C++ magic...
+ */
+
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+
+/*
* Data structures...
*/
@@ -68,6 +76,10 @@ extern help_index_t *helpSearchIndex(help_index_t *hi, const char *query,
const char *filename);
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+
#endif /* !_CUPS_HELP_INDEX_H_ */
/*
diff --git a/cgi-bin/help.c b/cgi-bin/help.c
index 48ca55895..7c0b6b628 100644
--- a/cgi-bin/help.c
+++ b/cgi-bin/help.c
@@ -3,7 +3,7 @@
*
* Online help CGI for the Common UNIX Printing System (CUPS).
*
- * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2007-2009 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
@@ -63,6 +63,7 @@ main(int argc, /* I - Number of command-line arguments */
*/
cgiSetVariable("SECTION", "help");
+ cgiSetVariable("REFRESH_PAGE", "");
/*
* Load the help index...
@@ -102,7 +103,7 @@ main(int argc, /* I - Number of command-line arguments */
*/
for (i = 0; i < argc; i ++)
- fprintf(stderr, "argv[%d]=\"%s\"\n", i, argv[i]);
+ fprintf(stderr, "DEBUG: argv[%d]=\"%s\"\n", i, argv[i]);
if ((helpfile = getenv("PATH_INFO")) != NULL)
{
@@ -182,6 +183,12 @@ main(int argc, /* I - Number of command-line arguments */
topic = cgiGetVariable("TOPIC");
si = helpSearchIndex(hi, query, topic, helpfile);
+ cgiClearVariables();
+ if (query)
+ cgiSetVariable("QUERY", query);
+ if (topic)
+ cgiSetVariable("TOPIC", topic);
+
fprintf(stderr, "DEBUG: query=\"%s\", topic=\"%s\"\n",
query ? query : "(null)", topic ? topic : "(null)");
diff --git a/cgi-bin/ipp-var.c b/cgi-bin/ipp-var.c
index 1e9f3364f..4c1eb3b95 100644
--- a/cgi-bin/ipp-var.c
+++ b/cgi-bin/ipp-var.c
@@ -333,7 +333,7 @@ cgiMoveJobs(http_t *http, /* I - Connection to server */
NULL, job_uri);
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
"requested-attributes", NULL, "job-printer-uri");
-
+
if ((response = cupsDoRequest(http, request, "/")) != NULL)
{
if ((attr = ippFindAttribute(response, "job-printer-uri",
@@ -926,7 +926,7 @@ cgiRewriteURL(const char *uri, /* I - Current URI */
ishttps ? "https" : "http",
userpass, hostname, port, resource);
else
- snprintf(url, urlsize, "%s://%s:%d%s",
+ snprintf(url, urlsize, "%s://%s:%d%s",
ishttps ? "https" : "http",
hostname, port, resource);
}
@@ -1398,7 +1398,9 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
int ascending, /* Order of jobs (0 = descending) */
first, /* First job to show */
count; /* Number of jobs */
- const char *var; /* Form variable */
+ const char *var, /* Form variable */
+ *query, /* Query string */
+ *section; /* Section in web interface */
void *search; /* Search data */
char url[1024], /* Printer URI */
val[1024]; /* Form variable */
@@ -1442,11 +1444,14 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
* Get a list of matching job objects.
*/
- if ((var = cgiGetVariable("QUERY")) != NULL &&
+ if ((query = cgiGetVariable("QUERY")) != NULL &&
!cgiGetVariable("CLEAR"))
- search = cgiCompileSearch(var);
+ search = cgiCompileSearch(query);
else
+ {
+ query = NULL;
search = NULL;
+ }
jobs = cgiGetIPPObjects(response, search);
count = cupsArrayCount(jobs);
@@ -1471,16 +1476,27 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
if (first < 0)
first = 0;
- sprintf(val, "%d", count);
- cgiSetVariable("TOTAL", val);
-
if ((var = cgiGetVariable("ORDER")) != NULL)
ascending = !strcasecmp(var, "asc");
else
- {
ascending = !which_jobs || !strcasecmp(which_jobs, "not-completed");
- cgiSetVariable("ORDER", ascending ? "asc" : "dec");
- }
+
+ section = cgiGetVariable("SECTION");
+
+ cgiClearVariables();
+
+ if (query)
+ cgiSetVariable("QUERY", query);
+
+ cgiSetVariable("ORDER", ascending ? "asc" : "dec");
+
+ cgiSetVariable("SECTION", section);
+
+ sprintf(val, "%d", count);
+ cgiSetVariable("TOTAL", val);
+
+ if (which_jobs)
+ cgiSetVariable("WHICH_JOBS", which_jobs);
if (ascending)
{
@@ -1502,7 +1518,11 @@ cgiShowJobs(http_t *http, /* I - Connection to server */
*/
if (dest)
- snprintf(val, sizeof(val), "/%s/%s", cgiGetVariable("SECTION"), dest);
+ {
+ snprintf(val, sizeof(val), "/%s/%s", section, dest);
+ cgiSetVariable("PRINTER_NAME", dest);
+ cgiSetVariable("PRINTER_URI_SUPPORTED", val);
+ }
else
strlcpy(val, "/jobs/", sizeof(val));
diff --git a/cgi-bin/jobs.c b/cgi-bin/jobs.c
index 9af1dd744..cf1f6e680 100644
--- a/cgi-bin/jobs.c
+++ b/cgi-bin/jobs.c
@@ -57,6 +57,7 @@ main(int argc, /* I - Number of command-line arguments */
*/
cgiSetVariable("SECTION", "jobs");
+ cgiSetVariable("REFRESH_PAGE", "");
/*
* Connect to the HTTP server...
diff --git a/cgi-bin/libcupscgi.exp b/cgi-bin/libcupscgi.exp
index 73e309e96..1997cdb10 100644
--- a/cgi-bin/libcupscgi.exp
+++ b/cgi-bin/libcupscgi.exp
@@ -1,4 +1,5 @@
_cgiCheckVariables
+_cgiClearVariables
_cgiCompileSearch
_cgiCopyTemplateFile
_cgiCopyTemplateLang
diff --git a/cgi-bin/printers.c b/cgi-bin/printers.c
index e2fa42b8f..f57a4251e 100644
--- a/cgi-bin/printers.c
+++ b/cgi-bin/printers.c
@@ -73,6 +73,7 @@ main(int argc, /* I - Number of command-line arguments */
*/
cgiSetVariable("SECTION", "printers");
+ cgiSetVariable("REFRESH_PAGE", "");
/*
* See if we are displaying a printer or all printers...
diff --git a/cgi-bin/template.c b/cgi-bin/template.c
index f20a7a950..6e9cc5ec6 100644
--- a/cgi-bin/template.c
+++ b/cgi-bin/template.c
@@ -119,7 +119,7 @@ cgiCopyTemplateLang(const char *tmpl) /* I - Base filename */
*locptr = '\0'; /* Strip charset */
}
- fprintf(stderr, "DEBUG: lang=\"%s\", locale=\"%s\"...\n",
+ fprintf(stderr, "DEBUG2: lang=\"%s\", locale=\"%s\"...\n",
lang ? lang : "(null)", locale);
/*
@@ -675,6 +675,8 @@ cgi_puts(const char *s, /* I - String to output */
fputs("&gt;", out);
else if (*s == '\"')
fputs("&quot;", out);
+ else if (*s == '\'')
+ fputs("&#39;", out);
else if (*s == '&')
fputs("&amp;", out);
else
@@ -695,7 +697,7 @@ cgi_puturi(const char *s, /* I - String to output */
{
while (*s)
{
- if (strchr("%&+ <>#=", *s) || *s & 128)
+ if (strchr("%@&+ <>#=", *s) || *s < ' ' || *s & 128)
fprintf(out, "%%%02X", *s & 255);
else
putc(*s, out);
diff --git a/cgi-bin/var.c b/cgi-bin/var.c
index 628ce8add..1467bd878 100644
--- a/cgi-bin/var.c
+++ b/cgi-bin/var.c
@@ -15,6 +15,7 @@
* Contents:
*
* cgiCheckVariables() - Check for the presence of "required" variables.
+ * cgiClearVariables() - Clear all form variables.
* cgiGetArray() - Get an element from a form array...
* cgiGetFile() - Get the file (if any) that was submitted in the form.
* cgiGetSize() - Get the size of a form array value.
@@ -135,6 +136,31 @@ cgiCheckVariables(const char *names) /* I - Variables to look for */
/*
+ * 'cgiClearVariables()' - Clear all form variables.
+ */
+
+void
+cgiClearVariables(void)
+{
+ int i, j; /* Looping vars */
+ _cgi_var_t *v; /* Current variable */
+
+
+ for (v = form_vars, i = form_count; i > 0; v ++, i --)
+ {
+ _cupsStrFree(v->name);
+ for (j = 0; j < v->nvalues; j ++)
+ if (v->values[j])
+ _cupsStrFree(v->values[j]);
+ }
+
+ form_count = 0;
+
+ cgi_unlink_file();
+}
+
+
+/*
* 'cgiGetArray()' - Get an element from a form array...
*/
@@ -151,7 +177,7 @@ cgiGetArray(const char *name, /* I - Name of array variable */
if (element < 0 || element >= var->nvalues)
return (NULL);
- return (var->values[element]);
+ return (_cupsStrRetain(var->values[element]));
}
@@ -206,7 +232,7 @@ cgiGetVariable(const char *name) /* I - Name of variable */
var->values[var->nvalues - 1]));
#endif /* DEBUG */
- return ((var == NULL) ? NULL : var->values[var->nvalues - 1]);
+ return ((var == NULL) ? NULL : _cupsStrRetain(var->values[var->nvalues - 1]));
}
@@ -337,9 +363,9 @@ cgiSetArray(const char *name, /* I - Name of variable */
var->nvalues = element + 1;
}
else if (var->values[element])
- free((char *)var->values[element]);
+ _cupsStrFree((char *)var->values[element]);
- var->values[element] = strdup(value);
+ var->values[element] = _cupsStrAlloc(value);
}
}
@@ -384,7 +410,7 @@ cgiSetSize(const char *name, /* I - Name of variable */
{
for (i = size; i < var->nvalues; i ++)
if (var->values[i])
- free((void *)(var->values[i]));
+ _cupsStrFree((void *)(var->values[i]));
}
var->nvalues = size;
@@ -417,9 +443,9 @@ cgiSetVariable(const char *name, /* I - Name of variable */
{
for (i = 0; i < var->nvalues; i ++)
if (var->values[i])
- free((char *)var->values[i]);
+ _cupsStrFree((char *)var->values[i]);
- var->values[0] = strdup(value);
+ var->values[0] = _cupsStrAlloc(value);
var->nvalues = 1;
}
}
@@ -465,10 +491,10 @@ cgi_add_variable(const char *name, /* I - Variable name */
if ((var->values = calloc(element + 1, sizeof(char *))) == NULL)
return;
- var->name = strdup(name);
+ var->name = _cupsStrAlloc(name);
var->nvalues = element + 1;
var->avalues = element + 1;
- var->values[element] = strdup(value);
+ var->values[element] = _cupsStrAlloc(value);
form_count ++;
}