library/src/network/httpd/BP-HTTPdRequests.cc
// Adds a variable to the registry according to type.
Adds a variable to the registry according to type.
Adds a variable to the registry according to type .
BP_ERROR_T BP_HTTPdRequestVarAddToArgRegistry
(
		P_BP_HTTPD_REQUEST             request,
		BP_HTTPD_REQUEST_VAR_TYPE      type,
		BP_HTTPD_REQUEST_CONTENT_TYPE  content_type,
		char *                         name,
		char *                         data,
		char *                         data_file,
		size_t                         data_size
)
{
	if(!request)
		return ERR_FAILURE;
	if(!request->arg_hreg)
		return ERR_FAILURE;
	if(!type)
		return ERR_FAILURE;
	if(!content_type)
		return ERR_FAILURE;
	if(!name)
		return ERR_FAILURE;
	char * var_table = NULL;
	switch(type)
	{
		case BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA:
			var_table = "POST";
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE:
			var_table = "POST";
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_HEADER:
			var_table = "HEADER";
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_GET:
			var_table = "GET";
			break;
		case BP_HTTPD_REQUEST_VAR_TYPE_COOKIE:
			var_table = "COOKIE";
			break;
		default:
			return ERR_FAILURE;
	}
	if(!var_table)
		return ERR_FAILURE;
	P_BP_HTTPD_REQUEST_VAR var = BP_HTTPdRequestVarArgRegistryLookup(request, type, name);
	if(var)
		return ERR_FAILURE;
	BP_HASH_TABLE_ENTER_CRITICAL_SECTION(request->arg_hreg);
	char * table_path[10] = {0};
	P_BP_HASH_TABLE_KEYED_ENTRY tmp_lookup = NULL;
	table_path[0] = var_table;
	table_path[1] = NULL;
	BP_ERROR_T retval = BP_HashRegAddDataToTableByPath
	(
			request->arg_hreg,
			table_path,
			name,
			BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB,
			NULL,
			sizeof(BP_HTTPD_REQUEST_VAR)
	);
	if(!retval)
		BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC(request->arg_hreg, ERR_FAILURE);
	var = BP_HTTPdRequestVarArgRegistryLookup(request, type, name);
	if(!var)
		return ERR_FAILURE;
	var->content_type = content_type;
	var->type = type;
	if(name)
		var->name = bpstrdup(name);
	var->file_descriptor = -1;
	if(data_file)
	{
		var->data_file = bpstrdup(data_file);
		var->file_descriptor =  BP_FDCreateSecureTempFile(var->data_file);
	}
	BP_HASH_TABLE_LEAVE_CRITICAL_SECTION(request->arg_hreg);
	return ERR_SUCCESS;
}
BP_ERROR_T BP_HTTPdRequestVarAddToArgRegistry ( P_BP_HTTPD_REQUEST request , BP_HTTPD_REQUEST_VAR_TYPE type , BP_HTTPD_REQUEST_CONTENT_TYPE content_type , char * name , char * data , char * data_file , size_t data_size ) { if ( ! request ) return ERR_FAILURE ; if ( ! request -> arg_hreg ) return ERR_FAILURE ; if ( ! type ) return ERR_FAILURE ; if ( ! content_type ) return ERR_FAILURE ; if ( ! name ) return ERR_FAILURE ; char * var_table = NULL ; switch ( type ) { case BP_HTTPD_REQUEST_VAR_TYPE_POST_DATA : var_table = " " ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_POST_TMPFILE : var_table = " " ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_HEADER : var_table = " " ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_GET : var_table = " " ; break ; case BP_HTTPD_REQUEST_VAR_TYPE_COOKIE : var_table = " " ; break ; default : return ERR_FAILURE ; } if ( ! var_table ) return ERR_FAILURE ; P_BP_HTTPD_REQUEST_VAR var = BP_HTTPdRequestVarArgRegistryLookup ( request , type , name ) ; if ( var ) return ERR_FAILURE ; BP_HASH_TABLE_ENTER_CRITICAL_SECTION ( request -> arg_hreg ) ; char * table_path [ 10 ] = { 0 } ; P_BP_HASH_TABLE_KEYED_ENTRY tmp_lookup = NULL ; table_path [ 0 ] = var_table ; table_path [ 1 ] = NULL ; BP_ERROR_T retval = BP_HashRegAddDataToTableByPath ( request -> arg_hreg , table_path , name , BP_HASH_TABLE_KEYED_ENTRY_TYPE_BINARY_BLOB , NULL , sizeof ( BP_HTTPD_REQUEST_VAR ) ) ; if ( ! retval ) BP_HASH_TABLE_LEAVE_CRITICAL_SECTION_AND_RETURN_FROM_FUNC ( request -> arg_hreg , ERR_FAILURE ) ; var = BP_HTTPdRequestVarArgRegistryLookup ( request , type , name ) ; if ( ! var ) return ERR_FAILURE ; var -> content_type = content_type ; var -> type = type ; if ( name ) var -> name = bpstrdup ( name ) ; var -> file_descriptor = -1 ; if ( data_file ) { var -> data_file = bpstrdup ( data_file ) ; var -> file_descriptor = BP_FDCreateSecureTempFile ( var -> data_file ) ; } BP_HASH_TABLE_LEAVE_CRITICAL_SECTION ( request -> arg_hreg ) ; return ERR_SUCCESS ; }
Adds a variable to the registry according to type.
Adds a variable to the registry according to type .
// ensure we have a request and argument registry // basic checks // variable table selected // switch on the variable type // http post tables // type is httpd header // http get table // cookie table // exit immediately if we have a type mismatch // ensure we have a table selected // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Basic Checks / Lookup %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // attempt to lookup the var (checks if it already exists) // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add New Var %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // enter critical section for the argument registry // declare dynamic table path // declare the lookup pointer // set initial path // add a new request var // exit if we cant create the new item // attempt lookup again, this time we can modify it // set content type // set type // set name // initialize fd as -1 // set data file // set the data file path // open the file for appending // leave the critical section // return indicating success