library/src/network/httpd/BP-HTTPdRequests.cc
// Adds a request to the request registry.
Adds a request to the request registry.
Adds a request to the request registry .
P_BP_HTTPD_REQUEST BP_HTTPdRequestAdd
(
		P_BP_HTTPD_SESSION         httpd,
		P_BP_HTTPD_REQUEST_HANDLER request_handler,
		struct MHD_Connection *    connection,
		const char *               url,
		const char *               method,
		const char *               version
)
{
	if(!httpd)
		return NULL;
	if(!httpd->request_hreg)
		return NULL;
	if(!request_handler)
		return NULL;
	if(!connection)
		return NULL;
	if(!url)
		return NULL;
	if(!method)
		return NULL;
	if(!version)
		return NULL;
	const MHD_ConnectionInfo * info_lookup = NULL;
	BP_BOOL is_https = BP_FALSE;
	info_lookup = MHD_get_connection_info(connection, MHD_CONNECTION_INFO_PROTOCOL);
	if(info_lookup)
		is_https = BP_TRUE;
	BP_HTTPD_REQUEST_TLS_VERSION secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_UNSET;
	if(is_https)
	{
		info_lookup = MHD_get_connection_info(connection, MHD_CONNECTION_INFO_PROTOCOL);
		switch(info_lookup->protocol)
		{
			case GNUTLS_SSL3:
				secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_SSLV3;
				break;
			case GNUTLS_TLS1_0:
				secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_0;
				break;
			case GNUTLS_TLS1_1:
				secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_1;
				break;
			case GNUTLS_TLS1_2:
				secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_2;
				break;
			default:
				secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_BADVAL;
				break;
		}
	}
	info_lookup = MHD_get_connection_info(connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS);
	if(!info_lookup)
		return NULL;
	if(info_lookup->client_addr->sa_family != AF_INET)
		return NULL;
	char ip_address[128] = {0};
	struct sockaddr_in * sockaddr_struct = (struct sockaddr_in *) info_lookup->client_addr;
	inet_ntop(info_lookup->client_addr->sa_family, &sockaddr_struct->sin_addr, (char *) &ip_address, INET_ADDRSTRLEN);
	P_BP_HTTPD_REQUEST request = BP_HTTPdRequestCreateNewEmpty(httpd);
	request->ip_address = bpstrdup(ip_address);
	request->httpd = httpd;
	request->request_handler = request_handler;
	if(is_https)
	{
		request->secure_client_request = BP_TRUE;
		request->secure_client_proto_version = secure_client_proto_version;
	}
	request->http_method = BP_HTTPdDetermineMethod((char *) method);
	if(request->http_method == BP_HTTPD_METHOD_POST)
	{
		request->pp = MHD_create_post_processor(connection, 1024, BP_HTTPdDefaultPostIteratorCallback, (void *) request);
	}
	request->arg_hreg = BP_CreateHashTableRegistry();
	BP_HTTPdCreateInitialRequestArgumentHashRegistryLayout(request);
	request->request_is_valid = BP_TRUE;
	printf("\n Finished creating request in hreg.");
	printf("\n");
	return request;
}
P_BP_HTTPD_REQUEST BP_HTTPdRequestAdd ( P_BP_HTTPD_SESSION httpd , P_BP_HTTPD_REQUEST_HANDLER request_handler , struct MHD_Connection * connection , const char * url , const char * method , const char * version ) { if ( ! httpd ) return NULL ; if ( ! httpd -> request_hreg ) return NULL ; if ( ! request_handler ) return NULL ; if ( ! connection ) return NULL ; if ( ! url ) return NULL ; if ( ! method ) return NULL ; if ( ! version ) return NULL ; const MHD_ConnectionInfo * info_lookup = NULL ; BP_BOOL is_https = BP_FALSE ; info_lookup = MHD_get_connection_info ( connection , MHD_CONNECTION_INFO_PROTOCOL ) ; if ( info_lookup ) is_https = BP_TRUE ; BP_HTTPD_REQUEST_TLS_VERSION secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_UNSET ; if ( is_https ) { info_lookup = MHD_get_connection_info ( connection , MHD_CONNECTION_INFO_PROTOCOL ) ; switch ( info_lookup -> protocol ) { case GNUTLS_SSL3 : secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_SSLV3 ; break ; case GNUTLS_TLS1_0 : secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_0 ; break ; case GNUTLS_TLS1_1 : secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_1 ; break ; case GNUTLS_TLS1_2 : secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_2 ; break ; default : secure_client_proto_version = BP_HTTPD_REQUEST_TLS_VERSION_TLS1_BADVAL ; break ; } } info_lookup = MHD_get_connection_info ( connection , MHD_CONNECTION_INFO_CLIENT_ADDRESS ) ; if ( ! info_lookup ) return NULL ; if ( info_lookup -> client_addr -> sa_family != AF_INET ) return NULL ; char ip_address [ 128 ] = { 0 } ; struct sockaddr_in * sockaddr_struct = ( struct sockaddr_in * ) info_lookup -> client_addr ; inet_ntop ( info_lookup -> client_addr -> sa_family , & sockaddr_struct -> sin_addr , ( char * ) & ip_address , INET_ADDRSTRLEN ) ; P_BP_HTTPD_REQUEST request = BP_HTTPdRequestCreateNewEmpty ( httpd ) ; request -> ip_address = bpstrdup ( ip_address ) ; request -> httpd = httpd ; request -> request_handler = request_handler ; if ( is_https ) { request -> secure_client_request = BP_TRUE ; request -> secure_client_proto_version = secure_client_proto_version ; } request -> http_method = BP_HTTPdDetermineMethod ( ( char * ) method ) ; if ( request -> http_method == BP_HTTPD_METHOD_POST ) { request -> pp = MHD_create_post_processor ( connection , 1024 , BP_HTTPdDefaultPostIteratorCallback , ( void * ) request ) ; } request -> arg_hreg = BP_CreateHashTableRegistry ( ) ; BP_HTTPdCreateInitialRequestArgumentHashRegistryLayout ( request ) ; request -> request_is_valid = BP_TRUE ; printf ( " \n " ) ; printf ( " \n " ) ; return request ; }
Adds a request to the request registry.
Adds a request to the request registry .
// run basic sanity checks // connection info lookup // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Initial Connection Determinations %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // this flag is used to indicate if a connection is https // Get https protocol.  If the return is null, we have a normal // http connection.  If it's non-null, we have a HTTPS connection. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Extract HTTPS Data If Necessary %%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // secure client proto // determine protocol information if we're https // get protocol // switch on the lookup to determine the correct ssl type. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Extract IP Information From Connection %%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to lookup the sockaddr information // ensure it's an IPv4 address (only IP4 supported as of now) // static buffer to hold ip address // set the sockaddr in from the client addr structure // convert ip address // NOTE: At this point we have verified that the request is reasonably legit. // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Create Request Struct in Registry %%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // create a new request // duplicate the ip address // set the httpd // set the request handler // set https parameters // mark the request as being https // set the secure client protocol version // ensure we have a method // if the request method is post, create a post processor // create new // create a new hash table registry // create the initial layout for arguments (GET/POST/COOKIE) // at this point we can mark the request as valid and exit, providing // the request back to the host. // return the request