]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/client.c
Import CUPS 1.4svn r7023 into easysw/current.
[thirdparty/cups.git] / scheduler / client.c
index 7cc7f670a72f946610f7da59aabd6ef5f601d871..f6c106a78039455e17ce82e0051f4e45fb00c914 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: client.c 6681 2007-07-16 20:11:52Z mike $"
+ * "$Id: client.c 6999 2007-09-28 19:46:53Z mike $"
  *
  *   Client routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -161,9 +161,13 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */
   if ((con->http.fd = accept(lis->fd, (struct sockaddr *)con->http.hostaddr,
                              &addrlen)) < 0)
   {
+    if (errno == ENFILE || errno == EMFILE)
+      cupsdPauseListening();
+
     cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to accept client connection - %s.",
                     strerror(errno));
     free(con);
+
     return;
   }
 
@@ -1024,7 +1028,7 @@ cupsdReadClient(cupsd_client_t *con)      /* I - Client to read from */
         snprintf(locale, sizeof(locale), "%s.%s",
                 con->http.fields[HTTP_FIELD_ACCEPT_LANGUAGE], DefaultCharset);
 
-      cupsdLogMessage(CUPSD_LOG_DEBUG,
+      cupsdLogMessage(CUPSD_LOG_DEBUG2,
                       "cupsdReadClient: %d Browser asked for language \"%s\"...",
                       con->http.fd, locale);
 
@@ -2392,7 +2396,7 @@ cupsdSendHeader(
   {
     if (auth_type == AUTH_NONE)
     {
-      if (!con->best || con->best->type == AUTH_NONE)
+      if (!con->best || con->best->type <= AUTH_NONE)
        auth_type = DefaultAuthType;
       else
        auth_type = con->best->type;
@@ -2406,13 +2410,12 @@ cupsdSendHeader(
       snprintf(auth_str, sizeof(auth_str), "Digest realm=\"CUPS\", nonce=\"%s\"",
               con->http.hostname);
 #ifdef HAVE_GSSAPI
-    else if (auth_type == AUTH_NEGOTIATE && !con->no_negotiate &&
-            con->gss_output_token.length == 0)
+    else if (auth_type == AUTH_NEGOTIATE && con->gss_output_token.length == 0)
       strlcpy(auth_str, "Negotiate", sizeof(auth_str));
 #endif /* HAVE_GSSAPI */
 
 #ifdef HAVE_AUTHORIZATION_H
-    if (con->best && strcmp(auth_str, "Negotiate"))
+    if (con->best && auth_type != AUTH_NEGOTIATE)
     {
       int       i;                     /* Looping var */
       char     *auth_key;              /* Auth key buffer */
@@ -2443,7 +2446,7 @@ cupsdSendHeader(
 
     if (auth_str[0])
     {
-      cupsdLogMessage(CUPSD_LOG_DEBUG2, "cupsdSendHeader: WWW-Authenticate: %s",
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdSendHeader: WWW-Authenticate: %s",
                       auth_str);
 
       if (httpPrintf(HTTP(con), "WWW-Authenticate: %s\r\n", auth_str) < 0)
@@ -2468,6 +2471,9 @@ cupsdSendHeader(
                   con->gss_output_token.length);
     gss_release_buffer(&minor_status, &con->gss_output_token);
 
+    cupsdLogMessage(CUPSD_LOG_DEBUG,
+                    "cupsdSendHeader: WWW-Authenticate: Negotiate %s", buf);
+
     if (httpPrintf(HTTP(con), "WWW-Authenticate: Negotiate %s\r\n", buf) < 0)
       return (0);
   }
@@ -3222,12 +3228,15 @@ get_file(cupsd_client_t *con,           /* I  - Client connection */
   int          status;                 /* Status of filesystem calls */
   char         *ptr;                   /* Pointer info filename */
   int          plen;                   /* Remaining length after pointer */
+  char         language[7];            /* Language subdirectory, if any */
 
 
  /*
   * Figure out the real filename...
   */
 
+  language[0] = '\0';
+
   if (!strncmp(con->uri, "/ppd/", 5))
     snprintf(filename, len, "%s%s", ServerRoot, con->uri);
   else if (!strncmp(con->uri, "/rss/", 5) && !strchr(con->uri + 5, '/'))
@@ -3236,18 +3245,20 @@ get_file(cupsd_client_t *con,           /* I  - Client connection */
     snprintf(filename, len, "%s%s", ServerRoot, con->uri + 11);
   else if (!strncmp(con->uri, "/admin/log/", 11))
   {
-    if (!strcmp(con->uri + 11, "access_log") && AccessLog[0] == '/')
+    if (!strncmp(con->uri + 11, "access_log", 10) && AccessLog[0] == '/')
       strlcpy(filename, AccessLog, len);
-    else if (!strcmp(con->uri + 11, "error_log") && ErrorLog[0] == '/')
+    else if (!strncmp(con->uri + 11, "error_log", 9) && ErrorLog[0] == '/')
       strlcpy(filename, ErrorLog, len);
-    else if (!strcmp(con->uri + 11, "page_log") && PageLog[0] == '/')
+    else if (!strncmp(con->uri + 11, "page_log", 8) && PageLog[0] == '/')
       strlcpy(filename, PageLog, len);
     else
       return (NULL);
   }
   else if (con->language)
-    snprintf(filename, len, "%s/%s%s", DocumentRoot, con->language->language,
-             con->uri);
+  {
+    snprintf(language, sizeof(language), "/%s", con->language->language);
+    snprintf(filename, len, "%s%s%s", DocumentRoot, language, con->uri);
+  }
   else
     snprintf(filename, len, "%s%s", DocumentRoot, con->uri);
 
@@ -3259,7 +3270,7 @@ get_file(cupsd_client_t *con,             /* I  - Client connection */
   * then fallback to the default one...
   */
 
-  if ((status = stat(filename, filestats)) != 0 && con->language &&
+  if ((status = stat(filename, filestats)) != 0 && language[0] &&
       strncmp(con->uri, "/ppd/", 5) &&
       strncmp(con->uri, "/admin/conf/", 12) &&
       strncmp(con->uri, "/admin/log/", 11))
@@ -3268,11 +3279,8 @@ get_file(cupsd_client_t *con,            /* I  - Client connection */
     * Drop the country code...
     */
 
-    char       ll[3];                  /* Short language name */
-
-
-    strlcpy(ll, con->language->language, sizeof(ll));
-    snprintf(filename, len, "%s/%s%s", DocumentRoot, ll, con->uri);
+    language[3] = '\0';
+    snprintf(filename, len, "%s%s%s", DocumentRoot, language, con->uri);
 
     if ((ptr = strchr(filename, '?')) != NULL)
       *ptr = '\0';
@@ -3283,6 +3291,7 @@ get_file(cupsd_client_t *con,             /* I  - Client connection */
       * Drop the language prefix and try the root directory...
       */
 
+      language[0] = '\0';
       snprintf(filename, len, "%s%s", DocumentRoot, con->uri);
 
       if ((ptr = strchr(filename, '?')) != NULL)
@@ -3298,52 +3307,86 @@ get_file(cupsd_client_t *con,           /* I  - Client connection */
 
   if (!status && S_ISDIR(filestats->st_mode))
   {
-    if (filename[strlen(filename) - 1] != '/')
-      strlcat(filename, "/", len);
+   /*
+    * Make sure the URI ends with a slash...
+    */
 
-    ptr  = filename + strlen(filename);
-    plen = len - (ptr - filename);
+    if (con->uri[strlen(con->uri) - 1] != '/')
+      strlcat(con->uri, "/", sizeof(con->uri));
 
-    strlcpy(ptr, "index.html", plen);
-    status = stat(filename, filestats);
+   /*
+    * Find the directory index file, trying every language...
+    */
 
-#ifdef HAVE_JAVA
-    if (status)
+    do
     {
-      strlcpy(ptr, "index.class", plen);
+      if (status && language[0])
+      {
+       /*
+        * Try a different language subset...
+       */
+
+       if (language[3])
+         language[0] = '\0';           /* Strip country code */
+       else
+         language[0] = '\0';           /* Strip language */
+      }
+
+     /*
+      * Look for the index file...
+      */
+
+      snprintf(filename, len, "%s%s%s", DocumentRoot, language, con->uri);
+
+      if ((ptr = strchr(filename, '?')) != NULL)
+       *ptr = '\0';
+
+      ptr  = filename + strlen(filename);
+      plen = len - (ptr - filename);
+
+      strlcpy(ptr, "index.html", plen);
       status = stat(filename, filestats);
-    }
+
+#ifdef HAVE_JAVA
+      if (status)
+      {
+       strlcpy(ptr, "index.class", plen);
+       status = stat(filename, filestats);
+      }
 #endif /* HAVE_JAVA */
 
 #ifdef HAVE_PERL
-    if (status)
-    {
-      strlcpy(ptr, "index.pl", plen);
-      status = stat(filename, filestats);
-    }
+      if (status)
+      {
+       strlcpy(ptr, "index.pl", plen);
+       status = stat(filename, filestats);
+      }
 #endif /* HAVE_PERL */
 
 #ifdef HAVE_PHP
-    if (status)
-    {
-      strlcpy(ptr, "index.php", plen);
-      status = stat(filename, filestats);
-    }
+      if (status)
+      {
+       strlcpy(ptr, "index.php", plen);
+       status = stat(filename, filestats);
+      }
 #endif /* HAVE_PHP */
 
 #ifdef HAVE_PYTHON
-    if (status)
-    {
-      strlcpy(ptr, "index.pyc", plen);
-      status = stat(filename, filestats);
-    }
+      if (status)
+      {
+       strlcpy(ptr, "index.pyc", plen);
+       status = stat(filename, filestats);
+      }
 
-    if (status)
-    {
-      strlcpy(ptr, "index.py", plen);
-      status = stat(filename, filestats);
-    }
+      if (status)
+      {
+       strlcpy(ptr, "index.py", plen);
+       status = stat(filename, filestats);
+      }
 #endif /* HAVE_PYTHON */
+
+    }
+    while (status && language[0]);
   }
 
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "get_file: %d filename=%s size=%d",
@@ -4192,6 +4235,7 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */
                script_name[1024],      /* SCRIPT_NAME environment variable */
                server_name[1024],      /* SERVER_NAME environment variable */
                server_port[1024];      /* SERVER_PORT environment variable */
+  ipp_attribute_t *attr;               /* attributes-natural-language attribute */
 
 
  /*
@@ -4246,8 +4290,6 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */
       commptr ++;
   }
 
-  cupsdLogMessage(CUPSD_LOG_INFO, "commptr=\"%s\"", commptr);
-
   if (*commptr == '?' && con->operation == HTTP_GET && !con->query_string)
   {
     commptr ++;
@@ -4329,8 +4371,45 @@ pipe_command(cupsd_client_t *con,        /* I - Client connection */
   else
     auth_type[0] = '\0';
 
-  if (con->language)
-    snprintf(lang, sizeof(lang), "LANG=%s.UTF-8", con->language->language);
+  if (con->request &&
+      (attr = ippFindAttribute(con->request, "attributes-natural-language",
+                               IPP_TAG_LANGUAGE)) != NULL)
+  {
+    switch (strlen(attr->values[0].string.text))
+    {
+      default :
+        /*
+         * This is an unknown or badly formatted language code; use
+         * the POSIX locale...
+         */
+
+         strcpy(lang, "LANG=C");
+         break;
+
+      case 2 :
+        /*
+         * Just the language code (ll)...
+         */
+
+         snprintf(lang, sizeof(lang), "LANG=%s.UTF8",
+                  attr->values[0].string.text);
+         break;
+
+      case 5 :
+        /*
+         * Language and country code (ll-cc)...
+         */
+
+         snprintf(lang, sizeof(lang), "LANG=%c%c_%c%c.UTF8",
+                  attr->values[0].string.text[0],
+                  attr->values[0].string.text[1],
+                  toupper(attr->values[0].string.text[3] & 255),
+                  toupper(attr->values[0].string.text[4] & 255));
+         break;
+    }
+  }
+  else if (con->language)
+    snprintf(lang, sizeof(lang), "LANG=%s.UTF8", con->language->language);
   else
     strcpy(lang, "LANG=C");
 
@@ -4491,7 +4570,8 @@ pipe_command(cupsd_client_t *con, /* I - Client connection */
     if (con->username[0])
       cupsdAddCert(pid, con->username);
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "CGI %s started - PID = %d", command, pid);
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "[CGI] %s started - PID = %d",
+                    command, pid);
 
     *outfile = fds[0];
     close(fds[1]);
@@ -4514,7 +4594,7 @@ write_file(cupsd_client_t *con,           /* I - Client connection */
 {
   con->file = open(filename, O_RDONLY);
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "write_file: %d file=%d", con->http.fd,
+  cupsdLogMessage(CUPSD_LOG_DEBUG2, "write_file: %d file=%d", con->http.fd,
                   con->file);
 
   if (con->file < 0)
@@ -4572,5 +4652,5 @@ write_pipe(cupsd_client_t *con)           /* I - Client connection */
 
 
 /*
- * End of "$Id: client.c 6681 2007-07-16 20:11:52Z mike $".
+ * End of "$Id: client.c 6999 2007-09-28 19:46:53Z mike $".
  */