]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/http.c
Merge changes from CUPS trunk, r6739.
[thirdparty/cups.git] / cups / http.c
index b2de909e56378e00fb486e41a2148914febdee92..9efa1a365d7140c982e6b35bbcff4b7343cdba2b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: http.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id: http.c 6724 2007-07-25 20:39:33Z mike $"
  *
  *   HTTP routines for the Common UNIX Printing System (CUPS).
  *
@@ -34,6 +34,7 @@
  *   httpFlush()          - Flush data from a HTTP connection.
  *   httpFlushWrite()     - Flush data in write buffer.
  *   httpGet()            - Send a GET request to the server.
+ *   httpGetAuthString()  - Get the current authorization string.
  *   httpGetBlocking()    - Get the blocking/non-block state of a connection.
  *   httpGetCookie()      - Get any cookie data from the response.
  *   httpGetFd()          - Get the file descriptor associated with a
@@ -58,6 +59,7 @@
  *   _httpReadCDSA()      - Read function for the CDSA library.
  *   _httpReadGNUTLS()    - Read function for the GNU TLS library.
  *   httpReconnect()      - Reconnect to a HTTP server...
+ *   httpSetAuthString()  - Set the current authorization string.
  *   httpSetCookie()      - Set the cookie value(s)...
  *   httpSetExpect()      - Set the Expect: header in a request.
  *   httpSetField()       - Set the value of an HTTP header.
@@ -605,6 +607,27 @@ httpGet(http_t     *http,          /* I - HTTP connection */
 }
 
 
+/*
+ * 'httpGetAuthString()' - Get the current authorization string.
+ *
+ * The authorization string is set by cupsDoAuthentication() and
+ * httpSetAuthString().  Use httpGetAuthString() to retrieve the
+ * string to use with httpSetField() for the HTTP_FIELD_AUTHORIZATION
+ * value.
+ *
+ * @since CUPS 1.3@
+ */
+
+char *                                 /* O - Authorization string */
+httpGetAuthString(http_t *http)                /* I - HTTP connection */
+{
+  if (http)
+    return (http->authstring);
+  else
+    return (NULL);
+}
+
+
 /*
  * 'httpGetBlocking()' - Get the blocking/non-block state of a connection.
  *
@@ -1677,6 +1700,61 @@ httpReconnect(http_t *http)              /* I - HTTP connection */
 }
 
 
+/*
+ * 'httpSetAuthString()' - Set the current authorization string.
+ *
+ * This function just stores a copy of the current authorization string in
+ * the HTTP connection object.  You must still call httpSetField() to set
+ * HTTP_FIELD_AUTHORIZATION prior to issuing a HTTP request using httpGet(),
+ * httpHead(), httpOptions(), httpPost, or httpPut().
+ *
+ * @since CUPS 1.3@
+ */
+
+void
+httpSetAuthString(http_t     *http,    /* I - HTTP connection */
+                  const char *scheme,  /* I - Auth scheme (NULL to clear it) */
+                 const char *data)     /* I - Auth data (NULL for none) */
+{
+ /*
+  * Range check input...
+  */
+
+  if (!http)
+    return;
+
+  if (http->authstring && http->authstring != http->_authstring)
+    free(http->authstring);
+
+  http->authstring = http->_authstring;
+
+  if (scheme)
+  {
+   /*
+    * Set the current authorization string...
+    */
+
+    int len = (int)strlen(scheme) + (data ? (int)strlen(data) + 1 : 0) + 1;
+
+    if (len > (int)sizeof(http->_authstring))
+      http->authstring = malloc(len);
+
+    if (data)
+      snprintf(http->authstring, len, "%s %s", scheme, data);
+    else
+      strlcpy(http->authstring, scheme, len);
+  }
+  else
+  {
+   /*
+    * Clear the current authorization string...
+    */
+
+    http->_authstring[0] = '\0';
+  }
+}
+
+
 /*
  * 'httpSetCookie()' - Set the cookie value(s)...
  *
@@ -3155,5 +3233,5 @@ http_write_ssl(http_t     *http,  /* I - HTTP connection */
 
 
 /*
- * End of "$Id: http.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id: http.c 6724 2007-07-25 20:39:33Z mike $".
  */