* 'httpGetHostname()' - Get the FQDN for the connection or local system.
*
* When "http" points to a connected socket, return the hostname or
- * address that was used in the call to httpConnect() or httpConnectEncrypt().
+ * address that was used in the call to httpConnect() or httpConnectEncrypt(),
+ * or the address of the client for the connection from httpAcceptConnection().
* Otherwise, return the FQDN for the local system using both gethostname()
* and gethostbyname() to get the local hostname with domain.
*
}
+/*
+ * 'httpResolveHostname()' - Resolve the hostname of the HTTP connection
+ * address.
+ *
+ * @since CUPS 2.0@
+ */
+
+const char * /* O - Resolved hostname or @code NULL@ */
+httpResolveHostname(http_t *http, /* I - HTTP connection */
+ char *buffer, /* I - Hostname buffer */
+ size_t bufsize) /* I - Size of buffer */
+{
+ if (!http)
+ return (NULL);
+
+ if (isdigit(http->hostname[0] & 255) || http->hostname[0] == '[')
+ {
+ char temp[1024]; /* Temporary string */
+
+ if (httpAddrLookup(http->hostaddr, temp, sizeof(temp)))
+ strlcpy(http->hostname, temp, sizeof(http->hostname));
+ else
+ return (NULL);
+ }
+
+ if (buffer)
+ {
+ if (http->hostname[0] == '/')
+ strlcpy(buffer, "localhost", bufsize);
+ else
+ strlcpy(buffer, http->hostname, bufsize);
+
+ return (buffer);
+ }
+ else if (http->hostname[0] == '/')
+ return ("localhost");
+ else
+ return (http->hostname);
+}
+
+
/*
* End of "$Id$".
*/
static void http_debug_hex(const char *prefix, const char *buffer,
int bytes);
#endif /* DEBUG */
-static http_field_t http_field(const char *name);
static ssize_t http_read(http_t *http, char *buffer, size_t length);
static ssize_t http_read_buffered(http_t *http, char *buffer, size_t length);
static ssize_t http_read_chunk(http_t *http, char *buffer, size_t length);
size_t length);
#ifdef HAVE_SSL
static int http_read_ssl(http_t *http, char *buf, int len);
-# ifdef HAVE_CDSASSL
static int http_set_credentials(http_t *http);
-# endif /* HAVE_CDSASSL */
#endif /* HAVE_SSL */
static off_t http_set_length(http_t *http);
static void http_set_timeout(int fd, double timeout);
static void http_set_wait(http_t *http);
-#ifdef DEBUG
-static const char *http_state_string(http_state_t state);
-#endif /* DEBUG */
#ifdef HAVE_SSL
static int http_setup_ssl(http_t *http);
static void http_shutdown_ssl(http_t *http);
}
+/*
+ * 'httpFieldValue()' - Return the HTTP field enumeration value for a field
+ * name.
+ */
+
+http_field_t /* O - Field index */
+httpFieldValue(const char *name) /* I - String name */
+{
+ int i; /* Looping var */
+
+
+ for (i = 0; i < HTTP_FIELD_MAX; i ++)
+ if (!_cups_strcasecmp(name, http_fields[i]))
+ return ((http_field_t)i);
+
+ return (HTTP_FIELD_UNKNOWN);
+}
+
+
/*
* 'httpFlush()' - Flush data from a HTTP connection.
*/
DEBUG_printf(("httpFlush(http=%p), state=%s", http,
- http_state_string(http->state)));
+ httpStateString(http->state)));
/*
* Nothing to do if we are in the "waiting" state...
DEBUG_printf(("2httpGetLength2(http=%p), state=%s", http,
- http_state_string(http->state)));
+ httpStateString(http->state)));
if (!http)
return (-1);
http->state = HTTP_STATE_STATUS;
DEBUG_printf(("1httpPeek: 0-length chunk, set state to %s.",
- http_state_string(http->state)));
+ httpStateString(http->state)));
/*
* Prevent future reads for this request...
http->state = HTTP_STATE_STATUS;
DEBUG_printf(("1httpRead2: End of content, set state to %s.",
- http_state_string(http->state)));
+ httpStateString(http->state)));
}
return (bytes);
else if (http->state != HTTP_STATE_WAITING)
{
DEBUG_printf(("1httpReadRequest: Bad state %s, returning HTTP_STATE_ERROR.",
- http_state_string(http->state)));
+ httpStateString(http->state)));
return (HTTP_STATE_ERROR);
}
}
DEBUG_printf(("1httpReadRequest: Set state to %s.",
- http_state_string(http->state)));
+ httpStateString(http->state)));
if (!strcmp(req_version, "HTTP/1.0"))
{
DEBUG_printf(("_httpUpdate(http=%p, status=%p), state=%s", http, status,
- http_state_string(http->state)));
+ httpStateString(http->state)));
/*
* Grab a single line from the connection...
http->state ++;
DEBUG_printf(("1_httpUpdate: Set state to %s.",
- http_state_string(http->state)));
+ httpStateString(http->state)));
case HTTP_STATE_POST_SEND :
case HTTP_STATE_HEAD :
httpSetCookie(http, value);
}
- else if ((field = http_field(line)) != HTTP_FIELD_UNKNOWN)
+ else if ((field = httpFieldValue(line)) != HTTP_FIELD_UNKNOWN)
httpSetField(http, field, value);
#ifdef DEBUG
else
DEBUG_printf(("httpUpdate(http=%p), state=%s", http,
- http_state_string(http->state)));
+ httpStateString(http->state)));
/*
* Flush pending data, if any...
http->state = HTTP_STATE_STATUS;
DEBUG_printf(("2httpWrite2: Changed state to %s.",
- http_state_string(http->state)));
+ httpStateString(http->state)));
}
DEBUG_printf(("1httpWrite2: Returning " CUPS_LLFMT ".", CUPS_LLCAST bytes));
http->state == HTTP_STATE_STATUS)
{
DEBUG_printf(("1httpWriteResponse: Resetting state to HTTP_STATE_WAITING, "
- "was %s.", http_state_string(http->state)));
+ "was %s.", httpStateString(http->state)));
http->state = HTTP_STATE_WAITING;
}
else
#endif /* DEBUG */
-/*
- * 'http_field()' - Return the field index for a field name.
- */
-
-static http_field_t /* O - Field index */
-http_field(const char *name) /* I - String name */
-{
- int i; /* Looping var */
-
-
- for (i = 0; i < HTTP_FIELD_MAX; i ++)
- if (_cups_strcasecmp(name, http_fields[i]) == 0)
- return ((http_field_t)i);
-
- return (HTTP_FIELD_UNKNOWN);
-}
-
-
/*
* 'http_read()' - Read a buffer from a HTTP connection.
*
DEBUG_printf(("http_set_length(http=%p) mode=%d state=%s", http, http->mode,
- http_state_string(http->state)));
+ httpStateString(http->state)));
if ((remaining = httpGetLength2(http)) >= 0)
{
#endif /* HAVE_SSL */
-#ifdef DEBUG
-/*
- * 'http_state_string()' - Return the string associated with a given HTTP state.
- */
-
-static const char * /* O - State string */
-http_state_string(http_state_t state) /* I - HTTP state */
-{
- static char buffer[255]; /* Unknown value buffer */
- static const char * const states[] = /* State strings */
- {
- "HTTP_STATE_ERROR",
- "HTTP_STATE_WAITING",
- "HTTP_STATE_OPTIONS",
- "HTTP_STATE_GET",
- "HTTP_STATE_GET_SEND",
- "HTTP_STATE_HEAD",
- "HTTP_STATE_POST",
- "HTTP_STATE_POST_RECV",
- "HTTP_STATE_POST_SEND",
- "HTTP_STATE_PUT",
- "HTTP_STATE_PUT_RECV",
- "HTTP_STATE_DELETE",
- "HTTP_STATE_TRACE",
- "HTTP_STATE_CONNECT",
- "HTTP_STATE_STATUS",
- "HTTP_STATE_UNKNOWN_METHOD",
- "HTTP_STATE_UNKNOWN_VERSION"
- };
-
- if (state >= HTTP_STATE_ERROR && state <= HTTP_STATE_UNKNOWN_VERSION)
- return (states[state - HTTP_STATE_ERROR]);
-
- snprintf(buffer, sizeof(buffer), "??? %d ???", (int)state);
- return (buffer);
-}
-#endif /* DEBUG */
-
-
#ifdef HAVE_SSL
/*
* 'http_upgrade()' - Force upgrade to TLS encryption.
void
cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */
{
+ const char *hostname; /* Hostname of client */
char name[256]; /* Hostname of client */
int count; /* Count of connections on a host */
-// int val; /* Parameter value */
cupsd_client_t *con, /* New client pointer */
*tempcon; /* Temporary client pointer */
-// http_addrlist_t *addrlist, /* List of adddresses for host */
-// *addr; /* Current address */
socklen_t addrlen; /* Length of address */
-// char *hostname; /* Hostname for address */
http_addr_t temp; /* Temporary address variable */
static time_t last_dos = 0; /* Time of last DoS attack */
#ifdef HAVE_TCPD_H
con->number = ++ LastClientNumber;
con->file = -1;
-// con->http->activity = time(NULL);
-// httpGetAddress(con->http) = &(con->clientaddr);
-// con->http->wait_value = 10000;
-// con->http->mode = _HTTP_MODE_SERVER;
if ((con->http = httpAcceptConnection(lis->fd, 0)) == NULL)
{
return;
}
-#if 0 /* Decide if we keep this, and where to store the name */
/*
* Get the hostname or format the IP address as needed...
*/
- if (httpAddrLocalhost(httpGetAddress(con->http)))
- {
- /*
- * Map accesses from the loopback interface to "localhost"...
- */
-
- strlcpy(httpGetHostname(con->http, NULL, 0), "localhost", sizeof(httpGetHostname(con->http, NULL, 0)));
- hostname = httpGetHostname(con->http, NULL, 0);
- }
+ if (HostNameLookups)
+ hostname = httpResolveHostname(con->http, NULL, 0);
else
- {
- /*
- * Map accesses from the same host to the server name.
- */
-
- if (HostNameLookups)
- hostname = httpAddrLookup(httpGetAddress(con->http), httpGetHostname(con->http, NULL, 0),
- sizeof(httpGetHostname(con->http, NULL, 0)));
- else
- {
- hostname = NULL;
- httpAddrString(httpGetAddress(con->http), httpGetHostname(con->http, NULL, 0),
- sizeof(httpGetHostname(con->http, NULL, 0)));
- }
- }
+ hostname = httpGetHostname(con->http, NULL, 0);
if (hostname == NULL && HostNameLookups == 2)
{
* Do double lookups as needed...
*/
- if ((addrlist = httpAddrGetList(httpGetHostname(con->http, NULL, 0), AF_UNSPEC, NULL))
- != NULL)
+ http_addrlist_t *addrlist, /* List of addresses */
+ *addr; /* Current address */
+
+ if ((addrlist = httpAddrGetList(hostname, AF_UNSPEC, NULL)) != NULL)
{
/*
* See if the hostname maps to the same IP address...
return;
}
}
-#endif /* 0 */
#ifdef HAVE_TCPD_H
/*