Skip to content

Commit d847b53

Browse files
committed
Update checkbox support code.
1 parent a994c73 commit d847b53

3 files changed

Lines changed: 14 additions & 111 deletions

File tree

cgi-bin/admin.c

Lines changed: 7 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
/*
22
* Administration CGI for CUPS.
33
*
4-
* Copyright © 2021-2023 by OpenPrinting
4+
* Copyright © 2021-2024 by OpenPrinting
55
* Copyright © 2007-2021 by Apple Inc.
66
* Copyright © 1997-2007 by Easy Software Products.
77
*
88
* Licensed under Apache License v2.0. See the file "LICENSE" for more
99
* information.
1010
*/
1111

12-
/*
13-
* Include necessary headers...
14-
*/
15-
1612
#include "cgi-private.h"
1713
#include <cups/http-private.h>
1814
#include <cups/ppd-private.h>
@@ -47,7 +43,6 @@ static void do_menu(http_t *http);
4743
static void do_set_allowed_users(http_t *http);
4844
static void do_set_default(http_t *http);
4945
static void do_set_options(http_t *http, int is_class);
50-
static void do_set_sharing(http_t *http);
5146
static char *get_option_value(ppd_file_t *ppd, const char *name,
5247
char *buffer, size_t bufsize);
5348
static double get_points(double number, const char *uval);
@@ -140,8 +135,6 @@ main(void)
140135
do_set_allowed_users(http);
141136
else if (!strcmp(op, "set-as-default"))
142137
do_set_default(http);
143-
else if (!strcmp(op, "set-sharing"))
144-
do_set_sharing(http);
145138
else if (!strcmp(op, "find-new-printers") ||
146139
!strcmp(op, "list-available-printers"))
147140
do_list_printers(http);
@@ -916,10 +909,10 @@ do_am_printer(http_t *http, /* I - HTTP connection */
916909

917910
#ifdef __APPLE__
918911
if (!strncmp(var, "usb:", 4))
919-
cgiSetVariable("printer_is_shared", "1");
912+
cgiSetVariable("PRINTER_IS_SHARED", "1");
920913
else
921914
#endif /* __APPLE__ */
922-
cgiSetVariable("printer_is_shared", "0");
915+
cgiSetVariable("PRINTER_IS_SHARED", "0");
923916

924917
cgiCopyTemplateLang("add-printer.tmpl");
925918
}
@@ -1166,9 +1159,7 @@ do_am_printer(http_t *http, /* I - HTTP connection */
11661159

11671160
ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-accepting-jobs", 1);
11681161

1169-
var = cgiGetCheckbox("printer_is_shared");
1170-
ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-shared",
1171-
var && (!strcmp(var, "1") || !strcmp(var, "on")));
1162+
ippAddBoolean(request, IPP_TAG_PRINTER, "printer-is-shared", cgiGetCheckbox("PRINTER_IS_SHARED"));
11721163

11731164
ippAddInteger(request, IPP_TAG_PRINTER, IPP_TAG_ENUM, "printer-state",
11741165
IPP_PRINTER_IDLE);
@@ -1313,7 +1304,7 @@ do_config_server(http_t *http) /* I - HTTP connection */
13131304
share_printers = cgiGetCheckbox("SHARE_PRINTERS") ? "1" : "0";
13141305
user_cancel_any = cgiGetCheckbox("USER_CANCEL_ANY") ? "1" : "0";
13151306

1316-
advanced = cgiGetCheckbox("ADVANCEDSETTINGS") != NULL;
1307+
advanced = cgiGetCheckbox("ADVANCEDSETTINGS");
13171308
if (advanced)
13181309
{
13191310
/*
@@ -1375,7 +1366,9 @@ do_config_server(http_t *http) /* I - HTTP connection */
13751366
*/
13761367

13771368
if (cgiGetCheckbox("KERBEROS"))
1369+
{
13781370
strlcpy(default_auth_type, "Negotiate", sizeof(default_auth_type));
1371+
}
13791372
else
13801373
{
13811374
val = cupsGetOption("DefaultAuthType", num_settings, settings);
@@ -3361,99 +3354,6 @@ do_set_options(http_t *http, /* I - HTTP connection */
33613354
}
33623355

33633356

3364-
/*
3365-
* 'do_set_sharing()' - Set printer-is-shared value.
3366-
*/
3367-
3368-
static void
3369-
do_set_sharing(http_t *http) /* I - HTTP connection */
3370-
{
3371-
ipp_t *request, /* IPP request */
3372-
*response; /* IPP response */
3373-
char uri[HTTP_MAX_URI]; /* Printer URI */
3374-
const char *printer, /* Printer name */
3375-
*is_class, /* Is a class? */
3376-
*shared; /* Sharing value */
3377-
3378-
3379-
is_class = cgiGetVariable("IS_CLASS");
3380-
printer = cgiGetTextfield("PRINTER_NAME");
3381-
shared = cgiGetCheckbox("SHARED");
3382-
3383-
if (!printer || !shared)
3384-
{
3385-
cgiSetVariable("ERROR", cgiText(_("Missing form variable")));
3386-
cgiStartHTML(cgiText(_("Set Publishing")));
3387-
cgiCopyTemplateLang("error.tmpl");
3388-
cgiEndHTML();
3389-
return;
3390-
}
3391-
3392-
/*
3393-
* Build a CUPS-Add-Printer/CUPS-Add-Class request, which requires the
3394-
* following attributes:
3395-
*
3396-
* attributes-charset
3397-
* attributes-natural-language
3398-
* printer-uri
3399-
* printer-is-shared
3400-
*/
3401-
3402-
request = ippNewRequest(is_class ? CUPS_ADD_CLASS : CUPS_ADD_PRINTER);
3403-
3404-
httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
3405-
"localhost", 0, is_class ? "/classes/%s" : "/printers/%s",
3406-
printer);
3407-
ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
3408-
NULL, uri);
3409-
3410-
ippAddBoolean(request, IPP_TAG_OPERATION, "printer-is-shared", (char)atoi(shared));
3411-
3412-
/*
3413-
* Do the request and get back a response...
3414-
*/
3415-
3416-
if ((response = cupsDoRequest(http, request, "/admin/")) != NULL)
3417-
{
3418-
cgiSetIPPVars(response, NULL, NULL, NULL, 0);
3419-
3420-
ippDelete(response);
3421-
}
3422-
3423-
if (cupsLastError() == IPP_NOT_AUTHORIZED)
3424-
{
3425-
puts("Status: 401\n");
3426-
exit(0);
3427-
}
3428-
else if (cupsLastError() > IPP_OK_CONFLICT)
3429-
{
3430-
cgiStartHTML(cgiText(_("Set Publishing")));
3431-
cgiShowIPPError(_("Unable to change printer-is-shared attribute"));
3432-
}
3433-
else
3434-
{
3435-
/*
3436-
* Redirect successful updates back to the printer page...
3437-
*/
3438-
3439-
char url[1024], /* Printer/class URL */
3440-
refresh[1024]; /* Refresh URL */
3441-
3442-
3443-
cgiRewriteURL(uri, url, sizeof(url), NULL);
3444-
cgiFormEncode(uri, url, sizeof(uri));
3445-
snprintf(refresh, sizeof(refresh), "5;URL=/admin/?OP=redirect&URL=%s", uri);
3446-
cgiSetVariable("refresh_page", refresh);
3447-
3448-
cgiStartHTML(cgiText(_("Set Publishing")));
3449-
cgiCopyTemplateLang(is_class ? "class-modified.tmpl" :
3450-
"printer-modified.tmpl");
3451-
}
3452-
3453-
cgiEndHTML();
3454-
}
3455-
3456-
34573357
/*
34583358
* 'get_option_value()' - Return the value of an option.
34593359
*

cgi-bin/cgi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ extern char *cgiFormEncode(char *dst, const char *src,
7070
extern void cgiFreeSearch(void *search);
7171
extern char *cgiGetArray(const char *name, int element);
7272
extern void cgiGetAttributes(ipp_t *request, const char *tmpl);
73-
extern const char *cgiGetCheckbox(const char *name);
73+
extern int cgiGetCheckbox(const char *name);
7474
extern const char *cgiGetCookie(const char *name);
7575
extern const cgi_file_t *cgiGetFile(void);
7676
extern cups_array_t *cgiGetIPPObjects(ipp_t *response, void *search);

cgi-bin/var.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,18 @@ cgiGetArray(const char *name, /* I - Name of array variable */
182182
* 'cgiGetCheckbox()' - Get a checkbox value, deleting any invalid values.
183183
*/
184184

185-
const char * /* O - Value or NULL */
185+
int /* O - 1 if checked, 0 otherwise */
186186
cgiGetCheckbox(const char *name) /* I - Name of form field */
187187
{
188188
_cgi_var_t *var = cgi_find_variable(name);
189189
/* Found variable */
190190
const char *value = var ? var->values[var->nvalues - 1] : NULL;
191+
int ret; /* Return value */
192+
191193

194+
ret = value && !_cups_strcasecmp(value, "checkbox");
192195

193-
if (value && _cups_strcasecmp(value, "checkbox"))
196+
if (!ret && value)
194197
{
195198
/*
196199
* Delete the invalid checkbox value...
@@ -209,7 +212,7 @@ cgiGetCheckbox(const char *name) /* I - Name of form field */
209212
memmove(var, var + 1, (size_t)(form_count - i) * sizeof(_cgi_var_t));
210213
}
211214

212-
return (value);
215+
return (ret);
213216
}
214217

215218

0 commit comments

Comments
 (0)