]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Mirror 1.1.x changes.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sun, 20 Jul 2003 03:49:46 +0000 (03:49 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Sun, 20 Jul 2003 03:49:46 +0000 (03:49 +0000)
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
cgi-bin/ipp-var.c
cgi-bin/ipp-var.h
cgi-bin/jobs.c
cgi-bin/printers.c

index 7a89a4ec563692e3c8c072c3f2893cf92bc81042..294956ee111e7504ca73969f7d09a7cc957bc9d1 100644 (file)
@@ -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).
  *
  * '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 $".
  */
index 819a6d2e69ceb0a364949ae9b624a4284c9213e0..92b066bbc3f974cb447ed863e5ca359e8b98258a 100644 (file)
@@ -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.
 #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 $".
  */
index cb2f12f36c6f308796f682f47d5ed206b22e4bfa..9cc8ee353ea32d91d02096fc8be8972d1b2d10b0 100644 (file)
@@ -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 $".
  */
index defab0b742cc7670d81eb079b130aa5a46b6af4d..229fc845501bedfb4bd604b4740c96cbbf621910 100644 (file)
@@ -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 $".
  */
index 9e0fa5f29c747e2ec41daf41ba73904dc7ed876f..b46ebf0cf24fa2c52d3a6cea7fffc065e5b50d62 100644 (file)
@@ -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).
  *
  * '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 $".
  */