]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Mirror 1.1.x changes.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 29 Aug 2003 23:58:38 +0000 (23:58 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 29 Aug 2003 23:58:38 +0000 (23:58 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/branches/branch-1.2@3892 7a7537e8-13f0-0310-91df-b6672ffda945

CHANGES-1.1.txt
cups/cups.h
cups/http.c
cups/http.h
cups/util.c

index 184ec97eb4aff4da67a02bb91b83e1c23e960b6d..6b59d72d5e8b40d976ac577940ac2042896e006d 100644 (file)
@@ -3,6 +3,9 @@ CHANGES-1.1.txt
 
 CHANGES IN CUPS V1.1.20rc1
 
+       - Added new cupsDoAuthentication(), cupsGetFd(),
+         cupsGetFile(), cupsPutFd(), and cupsPutFile() functions
+         to the CUPS API (STR #112)
        - The PDF filter always scaled and offset pages; this
          caused problems under MacOS X, so now the "fitplot"
          option controls whether PDF files are scaled to fit
index f2ef09596d873e7f5b18bcbcdf822639634b7237..0913e07d97ab874011f7ae1b1a77e6b262e72908 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: cups.h,v 1.32.2.11 2003/07/20 12:51:40 mike Exp $"
+ * "$Id: cups.h,v 1.32.2.12 2003/08/29 23:58:37 mike Exp $"
  *
  *   API definitions for the Common UNIX Printing System (CUPS).
  *
@@ -170,6 +170,16 @@ extern void                cupsSetServer(const char *server);
 extern void            cupsSetUser(const char *user);
 extern const char      *cupsUser(void);
 
+/**** New in CUPS 1.1.20 ****/
+extern int             cupsDoAuthentication(http_t *http, const char *method,
+                                            const char *resource);
+extern http_status_t   cupsGetFile(http_t *http, const char *resource,
+                                   const char *filename);
+extern http_status_t   cupsGetFd(http_t *http, const char *resource, int fd);
+extern http_status_t   cupsPutFile(http_t *http, const char *resource,
+                                   const char *filename);
+extern http_status_t   cupsPutFd(http_t *http, const char *resource, int fd);
+
 
 #  ifdef __cplusplus
 }
@@ -178,5 +188,5 @@ extern const char   *cupsUser(void);
 #endif /* !_CUPS_CUPS_H_ */
 
 /*
- * End of "$Id: cups.h,v 1.32.2.11 2003/07/20 12:51:40 mike Exp $".
+ * End of "$Id: cups.h,v 1.32.2.12 2003/08/29 23:58:37 mike Exp $".
  */
index 944b10bfa6cbc8ee30750a86bdb6284468e6d418..ada80afbf4b4cab1b84898ff709bbe3c11bc34bf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: http.c,v 1.82.2.38 2003/08/28 15:16:26 mike Exp $"
+ * "$Id: http.c,v 1.82.2.39 2003/08/29 23:58:37 mike Exp $"
  *
  *   HTTP routines for the Common UNIX Printing System (CUPS).
  *
@@ -1124,7 +1124,7 @@ httpWrite(http_t     *http,               /* I - HTTP data */
     {
      /*
       * A zero-length chunk ends a transfer; unless we are sending POST
-      * data, go idle...
+      * or PUT data, go idle...
       */
 
       DEBUG_puts("httpWrite: changing states...");
@@ -1191,13 +1191,16 @@ httpWrite(http_t     *http,             /* I - HTTP data */
   if (http->data_remaining == 0 && http->data_encoding == HTTP_ENCODE_LENGTH)
   {
    /*
-    * Finished with the transfer; unless we are sending POST data, go idle...
+    * Finished with the transfer; unless we are sending POST or PUT
+    * data, go idle...
     */
 
     DEBUG_puts("httpWrite: changing states...");
 
     if (http->state == HTTP_POST_RECV)
       http->state ++;
+    else if (http->state == HTTP_PUT_RECV)
+      http->state = HTTP_STATUS;
     else
       http->state = HTTP_WAITING;
   }
@@ -2450,5 +2453,5 @@ CDSAWriteFunc(SSLConnectionRef connection,        /* I  - SSL/TLS connection */
 
 
 /*
- * End of "$Id: http.c,v 1.82.2.38 2003/08/28 15:16:26 mike Exp $".
+ * End of "$Id: http.c,v 1.82.2.39 2003/08/29 23:58:37 mike Exp $".
  */
index 13c37fe9a440cb531ee199db761d9f88de1f0c24..466110905d7699f970cb9ecf94865abdd0a9afea 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: http.h,v 1.33.2.19 2003/07/20 03:13:07 mike Exp $"
+ * "$Id: http.h,v 1.33.2.20 2003/08/29 23:58:38 mike Exp $"
  *
  *   Hyper-Text Transport Protocol definitions for the Common UNIX Printing
  *   System (CUPS).
@@ -322,6 +322,12 @@ typedef struct
   fd_set               *input_set;     /* select() set for httpWait() */
   http_status_t                expect;         /* Expect: header */
   char                 *cookie;        /* Cookie value(s) */
+  /**** New in CUPS 1.1.20 ****/
+  char                 authstring[HTTP_MAX_VALUE],
+                                       /* Current Authentication value */
+                       userpass[HTTP_MAX_VALUE];
+                                       /* Username:password string */
+  int                  digest_tries;   /* Number of tries for digest auth */
   /**** New in CUPS 1.2 ****/
   http_addr_t          hostaddr;       /* Host address and port */
 } http_t;
@@ -410,5 +416,5 @@ extern char         *httpAddrString(const http_addr_t *addr,
 #endif /* !_IPP_HTTP_H_ */
 
 /*
- * End of "$Id: http.h,v 1.33.2.19 2003/07/20 03:13:07 mike Exp $".
+ * End of "$Id: http.h,v 1.33.2.20 2003/08/29 23:58:38 mike Exp $".
  */
index 9de91b6c4ebe22f448407ce26e5114b3e959bfcc..b8c7367cb24f2de9a5a9d3833a4e01d4a0cf059c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: util.c,v 1.81.2.24 2003/08/20 17:21:33 mike Exp $"
+ * "$Id: util.c,v 1.81.2.25 2003/08/29 23:58:38 mike Exp $"
  *
  *   Printing utilities for the Common UNIX Printing System (CUPS).
  *
@@ -37,8 +37,6 @@
  *   cupsPrintFile()     - Print a file to a printer or class.
  *   cupsPrintFiles()    - Print one or more files to a printer or class.
  *   cups_connect()      - Connect to the specified host...
- *   cups_local_auth()   - Get the local authorization certificate if
- *                         available/applicable...
  */
 
 /*
@@ -67,7 +65,6 @@
 
 static http_t          *cups_server = NULL;    /* Current server connection */
 static ipp_status_t    last_error = IPP_OK;    /* Last IPP error */
-static char            authstring[1024] = "";  /* Authorization string */
 
 
 /*
@@ -75,16 +72,15 @@ static char         authstring[1024] = "";  /* Authorization string */
  */
 
 static char    *cups_connect(const char *name, char *printer, char *hostname);
-static int     cups_local_auth(http_t *http);
 
 
 /*
  * 'cupsCancelJob()' - Cancel a print job.
  */
 
-int                            /* O - 1 on success, 0 on failure */
-cupsCancelJob(const char *name,        /* I - Name of printer or class */
-              int        job)  /* I - Job ID */
+int                                    /* O - 1 on success, 0 on failure */
+cupsCancelJob(const char *name,                /* I - Name of printer or class */
+              int        job)          /* I - Job ID */
 {
   char         printer[HTTP_MAX_URI],  /* Printer name */
                hostname[HTTP_MAX_URI], /* Hostname */
@@ -175,12 +171,6 @@ cupsDoFileRequest(http_t     *http,        /* I - HTTP connection to server */
   struct stat  fileinfo;               /* File information */
   int          bytes;                  /* Number of bytes read/written */
   char         buffer[32768];          /* Output buffer */
-  const char   *password;              /* Password string */
-  char         realm[HTTP_MAX_VALUE],  /* realm="xyz" string */
-               nonce[HTTP_MAX_VALUE],  /* nonce="xyz" string */
-               plain[255],             /* Plaintext username:password */
-               encode[512];            /* Encoded username:password */
-  char         prompt[1024];           /* Prompt string */
 
 
   DEBUG_printf(("cupsDoFileRequest(%p, %p, \'%s\', \'%s\')\n",
@@ -213,7 +203,11 @@ cupsDoFileRequest(http_t     *http,        /* I - HTTP connection to server */
       return (NULL);
     }
 
+#ifdef WIN32
+    if (fileinfo.st_mode & _S_IFDIR)
+#else
     if (S_ISDIR(fileinfo.st_mode))
+#endif /* WIN32 */
     {
      /*
       * Can't send a directory...
@@ -262,9 +256,9 @@ cupsDoFileRequest(http_t     *http, /* I - HTTP connection to server */
     httpClearFields(http);
     httpSetField(http, HTTP_FIELD_CONTENT_LENGTH, length);
     httpSetField(http, HTTP_FIELD_CONTENT_TYPE, "application/ipp");
-    httpSetField(http, HTTP_FIELD_AUTHORIZATION, authstring);
+    httpSetField(http, HTTP_FIELD_AUTHORIZATION, http->authstring);
 
-    DEBUG_printf(("cupsDoFileRequest: authstring=\"%s\"\n", authstring));
+    DEBUG_printf(("cupsDoFileRequest: authstring=\"%s\"\n", http->authstring));
 
    /*
     * Try the request...
@@ -325,60 +319,17 @@ cupsDoFileRequest(http_t     *http,       /* I - HTTP connection to server */
       */
 
       httpFlush(http);
-      httpReconnect(http);
-
-     /*
-      * See if we can do local authentication...
-      */
-
-      if (cups_local_auth(http))
-        continue;
 
      /*
-      * Nope - get a password from the user...
+      * See if we can do authentication...
       */
 
-      snprintf(prompt, sizeof(prompt), "Password for %s on %s? ", cupsUser(),
-               http->hostname);
-
-      if ((password = cupsGetPassword(prompt)) != NULL)
-      {
-       /*
-       * Got a password; send it to the server...
-       */
-
-        if (!password[0])
-          break;
-
-        if (strncmp(http->fields[HTTP_FIELD_WWW_AUTHENTICATE], "Basic", 5) == 0)
-        {
-        /*
-         * Basic authentication...
-         */
-
-         snprintf(plain, sizeof(plain), "%s:%s", cupsUser(), password);
-         httpEncode64(encode, plain);
-         snprintf(authstring, sizeof(authstring), "Basic %s", encode);
-       }
-        else
-       {
-        /*
-         * Digest authentication...
-         */
+      if (cupsDoAuthentication(http, "POST", resource))
+        break;
 
-          httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, "realm", realm);
-          httpGetSubField(http, HTTP_FIELD_WWW_AUTHENTICATE, "nonce", nonce);
+      httpReconnect(http);
 
-         httpMD5(cupsUser(), realm, password, encode);
-         httpMD5Final(nonce, "POST", resource, encode);
-         snprintf(authstring, sizeof(authstring),
-                  "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", "
-                  "response=\"%s\"", cupsUser(), realm, nonce, encode);
-       }
-        continue;
-      }
-      else
-        break;
+      continue;
     }
     else if (status == HTTP_ERROR)
     {
@@ -400,6 +351,12 @@ cupsDoFileRequest(http_t     *http,        /* I - HTTP connection to server */
 
       httpFlush(http);
 
+     /*
+      * Upgrade with encryption...
+      */
+
+      httpEncryption(http, HTTP_ENCRYPT_REQUIRED);
+
      /*
       * Try again, this time with encryption enabled...
       */
@@ -485,10 +442,10 @@ cupsDoFileRequest(http_t     *http,       /* I - HTTP connection to server */
  */
 
 void
-cupsFreeJobs(int        num_jobs,/* I - Number of jobs */
-             cups_job_t *jobs) /* I - Jobs */
+cupsFreeJobs(int        num_jobs,      /* I - Number of jobs */
+             cups_job_t *jobs)         /* I - Jobs */
 {
-  int  i;                      /* Looping var */
+  int  i;                              /* Looping var */
 
 
   if (num_jobs <= 0 || jobs == NULL)
@@ -510,15 +467,15 @@ cupsFreeJobs(int        num_jobs,/* I - Number of jobs */
  * 'cupsGetClasses()' - Get a list of printer classes.
  */
 
-int                            /* O - Number of classes */
-cupsGetClasses(char ***classes)        /* O - Classes */
+int                                    /* O - Number of classes */
+cupsGetClasses(char ***classes)                /* O - Classes */
 {
-  int          n;              /* Number of classes */
-  ipp_t                *request,       /* IPP Request */
-               *response;      /* IPP Response */
-  ipp_attribute_t *attr;       /* Current attribute */
-  cups_lang_t  *language;      /* Default language */
-  char         **temp;         /* Temporary pointer */
+  int          n;                      /* Number of classes */
+  ipp_t                *request,               /* IPP Request */
+               *response;              /* IPP Response */
+  ipp_attribute_t *attr;               /* Current attribute */
+  cups_lang_t  *language;              /* Default language */
+  char         **temp;                 /* Temporary pointer */
 
 
   if (classes == NULL)
@@ -619,15 +576,15 @@ cupsGetClasses(char ***classes)   /* O - Classes */
  * 'cupsGetDefault()' - Get the default printer or class.
  */
 
-const char *                   /* O - Default printer or NULL */
+const char *                           /* O - Default printer or NULL */
 cupsGetDefault(void)
 {
-  ipp_t                *request,       /* IPP Request */
-               *response;      /* IPP Response */
-  ipp_attribute_t *attr;       /* Current attribute */
-  cups_lang_t  *language;      /* Default language */
-  const char   *var;           /* Environment variable */
-  static char  def_printer[256];/* Default printer */
+  ipp_t                *request,               /* IPP Request */
+               *response;              /* IPP Response */
+  ipp_attribute_t *attr;               /* Current attribute */
+  cups_lang_t  *language;              /* Default language */
+  const char   *var;                   /* Environment variable */
+  static char  def_printer[256];       /* Default printer */
 
 
  /*
@@ -977,13 +934,7 @@ cupsGetPPD(const char *name)               /* I - Printer name */
                hostname[HTTP_MAX_URI], /* Hostname */
                resource[HTTP_MAX_URI]; /* Resource name */
   int          port;                   /* Port number */
-  const char   *password;              /* Password string */
-  char         realm[HTTP_MAX_VALUE],  /* realm="xyz" string */
-               nonce[HTTP_MAX_VALUE],  /* nonce="xyz" string */
-               plain[255],             /* Plaintext username:password */
-               encode[512];            /* Encoded username:password */
   http_status_t        status;                 /* HTTP status from server */
-  char         prompt[1024];           /* Prompt string */
   static char  filename[HTTP_MAX_URI]; /* Local filename */
   static const char * const requested_attrs[] =
                {                       /* Requested attributes */
@@ -993,6 +944,10 @@ cupsGetPPD(const char *name)               /* I - Printer name */
                };
 
 
+ /*
+  * Range check input...
+  */
+
   if (name == NULL)
   {
     last_error = IPP_INTERNAL_ERROR;
@@ -1145,103 +1100,9 @@ cupsGetPPD(const char *name)            /* I - Printer name */
 
   snprintf(resource, sizeof(resource), "/printers/%s.ppd", printer);
 
-  do
-  {
-    httpClearFields(cups_server);
-    httpSetField(cups_server, HTTP_FIELD_HOST, hostname);
-    httpSetField(cups_server, HTTP_FIELD_AUTHORIZATION, authstring);
-
-    if (httpGet(cups_server, resource))
-    {
-      if (httpReconnect(cups_server))
-      {
-        status = HTTP_ERROR;
-       break;
-      }
-      else
-      {
-        status = HTTP_UNAUTHORIZED;
-        continue;
-      }
-    }
-
-    while ((status = httpUpdate(cups_server)) == HTTP_CONTINUE);
-
-    if (status == HTTP_ERROR && httpError(cups_server) == EPIPE)
-    {
-      if (httpReconnect(cups_server))
-       break;
-      else
-      {
-        status = HTTP_UNAUTHORIZED;
-        continue;
-      }
-    }
-    else if (status == HTTP_UNAUTHORIZED)
-    {
-      DEBUG_puts("cupsGetPPD: unauthorized...");
-
-     /*
-      * Flush any error message...
-      */
-
-      httpFlush(cups_server);
-
-     /*
-      * See if we can do local authentication...
-      */
-
-      if (cups_local_auth(cups_server))
-        continue;
-
-     /*
-      * Nope, get a password from the user...
-      */
-
-      snprintf(prompt, sizeof(prompt), "Password for %s on %s? ", cupsUser(),
-               cups_server->hostname);
-
-      if ((password = cupsGetPassword(prompt)) != NULL)
-      {
-       /*
-       * Got a password; send it to the server...
-       */
-
-        if (!password[0])
-          break;
-
-        if (strncmp(cups_server->fields[HTTP_FIELD_WWW_AUTHENTICATE], "Basic", 5) == 0)
-        {
-        /*
-         * Basic authentication...
-         */
-
-         snprintf(plain, sizeof(plain), "%s:%s", cupsUser(), password);
-         httpEncode64(encode, plain);
-         snprintf(authstring, sizeof(authstring), "Basic %s", encode);
-       }
-        else
-       {
-        /*
-         * Digest authentication...
-         */
-
-          httpGetSubField(cups_server, HTTP_FIELD_WWW_AUTHENTICATE, "realm", realm);
-          httpGetSubField(cups_server, HTTP_FIELD_WWW_AUTHENTICATE, "nonce", nonce);
+  status = cupsGetFd(cups_server, resource, fd);
 
-         httpMD5(cupsUser(), realm, password, encode);
-         httpMD5Final(nonce, "GET", resource, encode);
-         snprintf(authstring, sizeof(authstring),
-                  "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", "
-                  "response=\"%s\"", cupsUser(), realm, nonce, encode);
-       }
-        continue;
-      }
-      else
-        break;
-    }
-  }
-  while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED);
+  close(fd);
 
  /*
   * See if we actually got the file or an error...
@@ -1274,14 +1135,9 @@ cupsGetPPD(const char *name)             /* I - Printer name */
   }
 
  /*
-  * OK, we need to copy the file...
+  * Return the PPD file...
   */
 
-  while ((bytes = httpRead(cups_server, buffer, sizeof(buffer))) > 0)
-    write(fd, buffer, bytes);
-
-  close(fd);
-
   return (filename);
 }
 
@@ -1293,12 +1149,12 @@ cupsGetPPD(const char *name)            /* I - Printer name */
 int                                    /* O - Number of printers */
 cupsGetPrinters(char ***printers)      /* O - Printers */
 {
-  int          n;              /* Number of printers */
-  ipp_t                *request,       /* IPP Request */
-               *response;      /* IPP Response */
-  ipp_attribute_t *attr;       /* Current attribute */
-  cups_lang_t  *language;      /* Default language */
-  char         **temp;         /* Temporary pointer */
+  int          n;                      /* Number of printers */
+  ipp_t                *request,               /* IPP Request */
+               *response;              /* IPP Response */
+  ipp_attribute_t *attr;               /* Current attribute */
+  cups_lang_t  *language;              /* Default language */
+  char         **temp;                 /* Temporary pointer */
 
 
   if (printers == NULL)
@@ -1399,7 +1255,7 @@ cupsGetPrinters(char ***printers) /* O - Printers */
  * 'cupsLastError()' - Return the last IPP error that occurred.
  */
 
-ipp_status_t           /* O - IPP error code */
+ipp_status_t                           /* O - IPP error code */
 cupsLastError(void)
 {
   return (last_error);
@@ -1433,7 +1289,8 @@ cupsPrintFiles(const char    *name,       /* I - Printer or class name */
                int           num_files,        /* I - Number of files */
                const char    **files,  /* I - File(s) to print */
               const char    *title,    /* I - Title of job */
-               int           num_options,/* I - Number of options */
+               int           num_options,
+                                       /* I - Number of options */
               cups_option_t *options)  /* I - Options */
 {
   int          i;                      /* Looping var */
@@ -1666,93 +1523,5 @@ cups_connect(const char *name,           /* I - Destination (printer[@host]) */
 
 
 /*
- * 'cups_local_auth()' - Get the local authorization certificate if
- *                       available/applicable...
- */
-
-static int                     /* O - 1 if available, 0 if not */
-cups_local_auth(http_t *http)  /* I - Connection */
-{
-#if defined(WIN32) || defined(__EMX__)
- /*
-  * Currently WIN32 and OS-2 do not support the CUPS server...
-  */
-
-  return (0);
-#else
-  int          pid;            /* Current process ID */
-  FILE         *fp;            /* Certificate file */
-  char         filename[1024], /* Certificate filename */
-               certificate[33];/* Certificate string */
-  const char   *root;          /* Server root directory */
-
-
-  DEBUG_printf(("cups_local_auth(http=%p) hostname=\"%s\"\n",
-                http, http->hostname));
-
- /*
-  * See if we are accessing localhost...
-  */
-
-  if (strcasecmp(http->hostname, "localhost") != 0)
-  {
-    DEBUG_puts("cups_local_auth: Not a local connection!");
-    return (0);
-  }
-
-  if (!httpAddrLocalhost(&(http->hostaddr)))
-  {
-    DEBUG_puts("cups_local_auth: Not a local connection!");
-    return (0);
-  }
-
- /*
-  * Try opening a certificate file for this PID.  If that fails,
-  * try the root certificate...
-  */
-
-  if ((root = getenv("CUPS_SERVERROOT")) == NULL)
-    root = CUPS_SERVERROOT;
-
-  pid = getpid();
-  snprintf(filename, sizeof(filename), "%s/certs/%d", root, pid);
-  if ((fp = fopen(filename, "r")) == NULL && pid > 0)
-  {
-    DEBUG_printf(("cups_local_auth: Unable to open file %s: %s\n",
-                  filename, strerror(errno)));
-
-    snprintf(filename, sizeof(filename), "%s/certs/0", root);
-    fp = fopen(filename, "r");
-  }
-
-  if (fp == NULL)
-  {
-    DEBUG_printf(("cups_local_auth: Unable to open file %s: %s\n",
-                  filename, strerror(errno)));
-    return (0);
-  }
-
- /*
-  * Read the certificate from the file...
-  */
-
-  fgets(certificate, sizeof(certificate), fp);
-  fclose(fp);
-
- /*
-  * Set the authorization string and return...
-  */
-
-  snprintf(authstring, sizeof(authstring), "Local %s", certificate);
-
-  DEBUG_printf(("cups_local_auth: Returning authstring = \"%s\"\n",
-                authstring));
-
-  return (1);
-#endif /* WIN32 || __EMX__ */
-}
-
-
-/*
- * End of "$Id: util.c,v 1.81.2.24 2003/08/20 17:21:33 mike Exp $".
+ * End of "$Id: util.c,v 1.81.2.25 2003/08/29 23:58:38 mike Exp $".
  */