+
+
+/*********************************************************************
+ *
+ * Function : save_connection_destination
+ *
+ * Description : Remembers a connection for reuse later on.
+ *
+ * Parameters :
+ * 1 : sfd = Open socket to remember.
+ * 2 : http = The destination for the connection.
+ * 3 : fwd = The forwarder settings used.
+ * 3 : server_connection = storage.
+ *
+ * Returns : void
+ *
+ *********************************************************************/
+void save_connection_destination(jb_socket sfd,
+ const struct http_request *http,
+ const struct forward_spec *fwd,
+ struct reusable_connection *server_connection)
+{
+ assert(sfd != JB_INVALID_SOCKET);
+ assert(NULL != http->host);
+ server_connection->host = strdup(http->host);
+ if (NULL == server_connection->host)
+ {
+ log_error(LOG_LEVEL_FATAL, "Out of memory saving socket.");
+ }
+ server_connection->port = http->port;
+
+ assert(NULL != fwd);
+ assert(server_connection->gateway_host == NULL);
+ assert(server_connection->gateway_port == 0);
+ assert(server_connection->forwarder_type == 0);
+ assert(server_connection->forward_host == NULL);
+ assert(server_connection->forward_port == 0);
+
+ server_connection->forwarder_type = fwd->type;
+ if (NULL != fwd->gateway_host)
+ {
+ server_connection->gateway_host = strdup(fwd->gateway_host);
+ if (NULL == server_connection->gateway_host)
+ {
+ log_error(LOG_LEVEL_FATAL, "Out of memory saving gateway_host.");
+ }
+ }
+ else
+ {
+ server_connection->gateway_host = NULL;
+ }
+ server_connection->gateway_port = fwd->gateway_port;
+
+ if (NULL != fwd->forward_host)
+ {
+ server_connection->forward_host = strdup(fwd->forward_host);
+ if (NULL == server_connection->forward_host)
+ {
+ log_error(LOG_LEVEL_FATAL, "Out of memory saving forward_host.");
+ }
+ }
+ else
+ {
+ server_connection->forward_host = NULL;
+ }
+ server_connection->forward_port = fwd->forward_port;
+}