From ae6a971cddc31de3d42551dc7cfcfda46e83c746 Mon Sep 17 00:00:00 2001 From: mike Date: Sun, 20 Jul 2003 03:49:46 +0000 Subject: [PATCH] Mirror 1.1.x changes. git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3815 7a7537e8-13f0-0310-91df-b6672ffda945 --- cgi-bin/classes.c | 45 +++++++++------- cgi-bin/ipp-var.c | 127 ++++++++++++++++++++++++++++++++++++++++++++- cgi-bin/ipp-var.h | 6 ++- cgi-bin/jobs.c | 24 +++++---- cgi-bin/printers.c | 49 +++++++++-------- 5 files changed, 197 insertions(+), 54 deletions(-) diff --git a/cgi-bin/classes.c b/cgi-bin/classes.c index 7a89a4ec56..294956ee11 100644 --- a/cgi-bin/classes.c +++ b/cgi-bin/classes.c @@ -1,5 +1,5 @@ /* - * "$Id: classes.c,v 1.18.2.8 2003/04/08 03:48:03 mike Exp $" + * "$Id: classes.c,v 1.18.2.9 2003/07/20 03:49:45 mike Exp $" * * Class status CGI for the Common UNIX Printing System (CUPS). * @@ -37,21 +37,25 @@ * 'main()' - Main entry for CGI. */ -int /* O - Exit status */ -main(int argc, /* I - Number of command-line arguments */ - char *argv[]) /* I - Command-line arguments */ +int /* O - Exit status */ +main(int argc, /* I - Number of command-line arguments */ + char *argv[]) /* I - Command-line arguments */ { - cups_lang_t *language; /* Language information */ - char *pclass; /* Printer class name */ - http_t *http; /* Connection to the server */ - ipp_t *request, /* IPP request */ - *response; /* IPP response */ - ipp_attribute_t *attr; /* IPP attribute */ - ipp_status_t status; /* Operation status... */ - char uri[HTTP_MAX_URI]; - /* Printer URI */ - const char *which_jobs; /* Which jobs to show */ - const char *op; /* Operation to perform, if any */ + cups_lang_t *language; /* Language information */ + char *pclass; /* Printer class name */ + http_t *http; /* Connection to the server */ + ipp_t *request, /* IPP request */ + *response; /* IPP response */ + ipp_attribute_t *attr; /* IPP attribute */ + ipp_status_t status; /* Operation status... */ + char uri[HTTP_MAX_URI]; /* Printer URI */ + const char *which_jobs; /* Which jobs to show */ + const char *op; /* Operation to perform, if any */ + static const char *def_attrs[] = /* Attributes for default printer */ + { + "printer-name", + "printer-uri-supported" + }; /* @@ -113,6 +117,10 @@ main(int argc, /* I - Number of command-line arguments */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language->language); + ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, + "requested-attributes", + sizeof(def_attrs) / sizeof(def_attrs[0]), NULL, def_attrs); + if ((response = cupsDoRequest(http, request, "/")) != NULL) { if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL) @@ -202,8 +210,7 @@ main(int argc, /* I - Number of command-line arguments */ uri); } - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, - "requested-attributes", NULL, "all"); + ippGetAttributes(request, TEMPLATES, "classes.tmpl", getenv("LANG")); /* * Do the request and get back a response... @@ -256,6 +263,8 @@ main(int argc, /* I - Number of command-line arguments */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs", NULL, which_jobs); + ippGetAttributes(request, TEMPLATES, "jobs.tmpl", getenv("LANG")); + /* * Do the request and get back a response... */ @@ -359,5 +368,5 @@ main(int argc, /* I - Number of command-line arguments */ /* - * End of "$Id: classes.c,v 1.18.2.8 2003/04/08 03:48:03 mike Exp $". + * End of "$Id: classes.c,v 1.18.2.9 2003/07/20 03:49:45 mike Exp $". */ diff --git a/cgi-bin/ipp-var.c b/cgi-bin/ipp-var.c index 819a6d2e69..92b066bbc3 100644 --- a/cgi-bin/ipp-var.c +++ b/cgi-bin/ipp-var.c @@ -1,5 +1,5 @@ /* - * "$Id: ipp-var.c,v 1.23.2.11 2003/06/14 16:53:47 mike Exp $" + * "$Id: ipp-var.c,v 1.23.2.12 2003/07/20 03:49:45 mike Exp $" * * IPP variable routines for the Common UNIX Printing System (CUPS). * @@ -23,6 +23,8 @@ * * Contents: * + * ippGetAttributes() - Get the list of attributes that are needed + * by the template file. * ippGetTemplateDir() - Get the templates directory... * ippSetServerVersion() - Set the server name and CUPS version... * ippSetCGIVars() - Set CGI variables from an IPP response. @@ -35,6 +37,127 @@ #include "ipp-var.h" +/* + * 'ippGetAttributes()' - Get the list of attributes that are needed + * by the template file. + */ + +void +ippGetAttributes(ipp_t *request, /* I - IPP request */ + const char *directory, /* I - Directory */ + const char *tmpl, /* I - Base filename */ + const char *lang) /* I - Language */ +{ + int num_attrs; /* Number of attributes */ + char *attrs[1000]; /* Attributes */ + int i; /* Looping var */ + char filename[1024], /* Filename */ + locale[16]; /* Locale name */ + FILE *in; /* Input file */ + int ch; /* Character from file */ + char name[255], /* Name of variable */ + *nameptr; /* Pointer into name */ + + + /* + * Convert the language to a locale name... + */ + + if (lang != NULL) + { + for (i = 0; lang[i] && i < 15; i ++) + if (isalnum(lang[i])) + locale[i] = tolower(lang[i]); + else + locale[i] = '_'; + + locale[i] = '\0'; + } + else + locale[0] = '\0'; + + /* + * See if we have a template file for this language... + */ + + snprintf(filename, sizeof(filename), "%s/%s/%s", directory, locale, tmpl); + if (access(filename, 0)) + { + locale[2] = '\0'; + + snprintf(filename, sizeof(filename), "%s/%s/%s", directory, locale, tmpl); + if (access(filename, 0)) + snprintf(filename, sizeof(filename), "%s/%s", directory, tmpl); + } + + /* + * Open the template file... + */ + + if ((in = fopen(filename, "r")) == NULL) + return; + + /* + * Loop through the file adding attribute names as needed... + */ + + num_attrs = 0; + + while ((ch = getc(in)) != EOF) + if (ch == '\\') + getc(in); + else if (ch == '{' && num_attrs < (sizeof(attrs) / sizeof(attrs[0]))) + { + /* + * Grab the name... + */ + + for (nameptr = name; (ch = getc(in)) != EOF;) + if (strchr("}]<>=! \t\n", ch)) + break; + else if (nameptr > name && ch == '?') + break; + else if (nameptr < (name + sizeof(name) - 1)) + { + if (ch == '_') + *nameptr++ = '-'; + else + *nameptr++ = ch; + } + + *nameptr = '\0'; + + /* + * Possibly add it to the list of attributes... + */ + + for (i = 0; i < num_attrs; i ++) + if (!strcmp(attrs[i], name)) + break; + + if (i >= num_attrs) + { + attrs[num_attrs] = strdup(name); + num_attrs ++; + } + } + + /* + * If we have attributes, add a requested-attributes attribute to the + * request... + */ + + if (num_attrs > 0) + { + ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, + "requested-attributes", num_attrs, NULL, attrs); + + for (i = 0; i < num_attrs; i ++) + free(attrs[i]); + } +} + + /* * 'ippGetTemplateDir()' - Get the templates directory... */ @@ -383,5 +506,5 @@ ippSetCGIVars(ipp_t *response, /* I - Response data to be copied... */ /* - * End of "$Id: ipp-var.c,v 1.23.2.11 2003/06/14 16:53:47 mike Exp $". + * End of "$Id: ipp-var.c,v 1.23.2.12 2003/07/20 03:49:45 mike Exp $". */ diff --git a/cgi-bin/ipp-var.h b/cgi-bin/ipp-var.h index cb2f12f36c..9cc8ee353e 100644 --- a/cgi-bin/ipp-var.h +++ b/cgi-bin/ipp-var.h @@ -1,5 +1,5 @@ /* - * "$Id: ipp-var.h,v 1.5.2.4 2003/04/08 03:48:03 mike Exp $" + * "$Id: ipp-var.h,v 1.5.2.5 2003/07/20 03:49:45 mike Exp $" * * IPP variable definitions for the Common UNIX Printing System (CUPS). * @@ -44,6 +44,8 @@ * Prototype... */ +extern void ippGetAttributes(ipp_t *request, const char *directory, + const char *tmpl, const char *lang); extern char *ippGetTemplateDir(void); extern void ippSetServerVersion(void); extern void ippSetCGIVars(ipp_t *, const char *, const char *, @@ -51,5 +53,5 @@ extern void ippSetCGIVars(ipp_t *, const char *, const char *, /* - * End of "$Id: ipp-var.h,v 1.5.2.4 2003/04/08 03:48:03 mike Exp $". + * End of "$Id: ipp-var.h,v 1.5.2.5 2003/07/20 03:49:45 mike Exp $". */ diff --git a/cgi-bin/jobs.c b/cgi-bin/jobs.c index defab0b742..229fc84550 100644 --- a/cgi-bin/jobs.c +++ b/cgi-bin/jobs.c @@ -1,5 +1,5 @@ /* - * "$Id: jobs.c,v 1.15.2.10 2003/04/08 03:48:03 mike Exp $" + * "$Id: jobs.c,v 1.15.2.11 2003/07/20 03:49:46 mike Exp $" * * Job status CGI for the Common UNIX Printing System (CUPS). * @@ -45,16 +45,16 @@ static void do_job_op(http_t *http, cups_lang_t *language, ipp_op_t op); * 'main()' - Main entry for CGI. */ -int /* O - Exit status */ -main(int argc, /* I - Number of command-line arguments */ - char *argv[]) /* I - Command-line arguments */ +int /* O - Exit status */ +main(int argc, /* I - Number of command-line arguments */ + char *argv[]) /* I - Command-line arguments */ { - cups_lang_t *language; /* Language information */ - http_t *http; /* Connection to the server */ - const char *which_jobs; /* Which jobs to show */ - ipp_t *request, /* IPP request */ - *response; /* IPP response */ - const char *op; /* Operation name */ + cups_lang_t *language; /* Language information */ + http_t *http; /* Connection to the server */ + const char *which_jobs; /* Which jobs to show */ + ipp_t *request, /* IPP request */ + *response; /* IPP response */ + const char *op; /* Operation name */ /* @@ -139,6 +139,8 @@ main(int argc, /* I - Number of command-line arguments */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs", NULL, which_jobs); + ippGetAttributes(request, TEMPLATES, "jobs.tmpl", getenv("LANG")); + /* * Do the request and get back a response... */ @@ -255,5 +257,5 @@ do_job_op(http_t *http, /* I - HTTP connection */ /* - * End of "$Id: jobs.c,v 1.15.2.10 2003/04/08 03:48:03 mike Exp $". + * End of "$Id: jobs.c,v 1.15.2.11 2003/07/20 03:49:46 mike Exp $". */ diff --git a/cgi-bin/printers.c b/cgi-bin/printers.c index 9e0fa5f29c..b46ebf0cf2 100644 --- a/cgi-bin/printers.c +++ b/cgi-bin/printers.c @@ -1,5 +1,5 @@ /* - * "$Id: printers.c,v 1.21.2.9 2003/04/08 03:48:03 mike Exp $" + * "$Id: printers.c,v 1.21.2.10 2003/07/20 03:49:46 mike Exp $" * * Printer status CGI for the Common UNIX Printing System (CUPS). * @@ -37,24 +37,26 @@ * 'main()' - Main entry for CGI. */ -int /* O - Exit status */ -main(int argc, /* I - Number of command-line arguments */ - char *argv[]) /* I - Command-line arguments */ +int /* O - Exit status */ +main(int argc, /* I - Number of command-line arguments */ + char *argv[]) /* I - Command-line arguments */ { - cups_lang_t *language; /* Language information */ - char *printer; /* Printer name */ - http_t *http; /* Connection to the server */ - ipp_t *request, /* IPP request */ - *response; /* IPP response */ - ipp_attribute_t *attr; /* IPP attribute */ - ipp_status_t status; /* Operation status... */ - char uri[HTTP_MAX_URI]; - /* Printer URI */ - const char *which_jobs; /* Which jobs to show */ - const char *op; /* Operation to perform, if any */ - - - setbuf(stdout, NULL); + cups_lang_t *language; /* Language information */ + char *printer; /* Printer name */ + http_t *http; /* Connection to the server */ + ipp_t *request, /* IPP request */ + *response; /* IPP response */ + ipp_attribute_t *attr; /* IPP attribute */ + ipp_status_t status; /* Operation status... */ + char uri[HTTP_MAX_URI]; /* Printer URI */ + const char *which_jobs; /* Which jobs to show */ + const char *op; /* Operation to perform, if any */ + static const char *def_attrs[] = /* Attributes for default printer */ + { + "printer-name", + "printer-uri-supported" + }; + /* * Get any form variables... @@ -116,6 +118,10 @@ main(int argc, /* I - Number of command-line arguments */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, language->language); + ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, + "requested-attributes", + sizeof(def_attrs) / sizeof(def_attrs[0]), NULL, def_attrs); + if ((response = cupsDoRequest(http, request, "/")) != NULL) { if ((attr = ippFindAttribute(response, "printer-name", IPP_TAG_NAME)) != NULL) @@ -205,8 +211,7 @@ main(int argc, /* I - Number of command-line arguments */ uri); } - ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, - "requested-attributes", NULL, "all"); + ippGetAttributes(request, TEMPLATES, "printers.tmpl", getenv("LANG")); /* * Do the request and get back a response... @@ -265,6 +270,8 @@ main(int argc, /* I - Number of command-line arguments */ ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs", NULL, which_jobs); + ippGetAttributes(request, TEMPLATES, "jobs.tmpl", getenv("LANG")); + /* * Do the request and get back a response... */ @@ -371,5 +378,5 @@ main(int argc, /* I - Number of command-line arguments */ /* - * End of "$Id: printers.c,v 1.21.2.9 2003/04/08 03:48:03 mike Exp $". + * End of "$Id: printers.c,v 1.21.2.10 2003/07/20 03:49:46 mike Exp $". */ -- 2.47.3