/*
- * "$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).
*
* '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"
+ };
/*
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)
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...
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...
*/
/*
- * 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 $".
*/
/*
- * "$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).
*
*
* 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.
#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...
*/
/*
- * 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 $".
*/
/*
- * "$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).
*
* 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 *,
/*
- * 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 $".
*/
/*
- * "$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).
*
* '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 */
/*
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...
*/
/*
- * 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 $".
*/
/*
- * "$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).
*
* '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...
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)
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...
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...
*/
/*
- * 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 $".
*/