library/src/blockclass/subclasses/BP_WebFormSubmitter.cc
// submit the form (result data will be in the request data)
submit the form (result data will be in the request data)
submit the form ( result data will be in the request data )
BP_ERROR_T BP_WebFormSubmitter::submitForm(P_BP_HTML_FORM_LIST form_element, P_FORM_SUBMIT_OVERRIDE_INPUT_FIELDS override_fields)
{
	if(!form_element)
		return ERR_FAILURE;
	char *data = NULL;
	P_BP_HTML_FORM_LIST form = form_element;
	P_BP_HTML_FORM_PROPERTY_LIST form_props = form_element->properties;
	P_BP_HTML_INPUT_LIST form_inputs = form_element->inputs->first;
	form_props = form_element->properties->first;
	size_t form_method = 0;
	char * form_action = NULL;
	for
	(
			form_element->properties = form_element->properties->first;
			form_element->properties;
			form_element->properties = form_element->properties->next
	)
	{
		if(BP_strncasecmp((char *) form_element->properties->name, "method", bpstrlen("method")) == 0)
		{
			if(BP_strncasecmp(form_element->properties->content, "post", bpstrlen("post")) == 0)
			{
				form_method = 1;
			}
		}
		if(BP_strncasecmp((char *) form_element->properties->name, "action", bpstrlen("action")) == 0)
		{
			form_action = bpstrdup(form_element->properties->content);
		}
	}
	form_element->properties = form_props;
	P_BP_HTML_INPUT_PROPERTY_LIST tmp_prop_list = NULL;
	BP_StringUtils * str_builder = new BP_StringUtils(data);
	char * param_name  = NULL;
	char * param_val   = NULL;
	for(form_inputs = form_inputs->first; form_inputs; form_inputs = form_inputs->next)
	{
		param_name = NULL;
		param_val  = NULL;
		for(tmp_prop_list = form_inputs->properties->first; tmp_prop_list; tmp_prop_list = tmp_prop_list->next)
		{
			if(BP_strncasecmp(tmp_prop_list->name, "name", 4) == 0)
			{
				printf("\n Got value?: %s", tmp_prop_list->content);
				param_name = tmp_prop_list->content;
			}
		}
		for(tmp_prop_list = form_inputs->properties->first; tmp_prop_list; tmp_prop_list = tmp_prop_list->next)
		{
			if(BP_strncasecmp(tmp_prop_list->name, "value", 5) == 0)
			{
				printf("\n Got value of form elem?: %s", tmp_prop_list->content);
				param_val = tmp_prop_list->content;
			}
		}
		if(this->getFieldBehaviorModificationByName(param_name))
		{
		}
		else if(this->getInputOverrideByName(param_name))
		{
			str_builder->BuildString(param_name);
			str_builder->BuildString("=");
			str_builder->BuildString(this->getInputOverrideByName(param_name)->input_override_val);
			if(form_inputs->next)
				str_builder->BuildString("&");
		}
		else
		{
			str_builder->BuildString(param_name);
			str_builder->BuildString("=");
			str_builder->BuildString(param_val);
			if(form_inputs->next)
				str_builder->BuildString("&");
		}
	}
	printf("\n Built String?: %s", str_builder->build_str);
	BP_StringUtils * request_url_builder = new BP_StringUtils(NULL);
	char * base_path = BP_ParseURLToPath(this->request->httpSession->lastRequestedHref, 1);
	request_url_builder->BuildString(base_path);
	if(base_path)
		bpfree(base_path);
	request_url_builder->BuildString(form_action);
	this->request->HttpSetPostData(str_builder->build_str);
	this->request->HttpMakeRequest(request_url_builder->build_str);
	printf("\n Final Action: %s", request_url_builder->build_str);
	printf("\n Making login request!");
	delete str_builder;
	delete request_url_builder;
}
BP_ERROR_T BP_WebFormSubmitter :: submitForm ( P_BP_HTML_FORM_LIST form_element , P_FORM_SUBMIT_OVERRIDE_INPUT_FIELDS override_fields ) { if ( ! form_element ) return ERR_FAILURE ; char * data = NULL ; P_BP_HTML_FORM_LIST form = form_element ; P_BP_HTML_FORM_PROPERTY_LIST form_props = form_element -> properties ; P_BP_HTML_INPUT_LIST form_inputs = form_element -> inputs -> first ; form_props = form_element -> properties -> first ; size_t form_method = 0 ; char * form_action = NULL ; for ( form_element -> properties = form_element -> properties -> first ; form_element -> properties ; form_element -> properties = form_element -> properties -> next ) { if ( BP_strncasecmp ( ( char * ) form_element -> properties -> name , " " , bpstrlen ( " " ) ) == 0 ) { if ( BP_strncasecmp ( form_element -> properties -> content , " " , bpstrlen ( " " ) ) == 0 ) { form_method = 1 ; } } if ( BP_strncasecmp ( ( char * ) form_element -> properties -> name , " " , bpstrlen ( " " ) ) == 0 ) { form_action = bpstrdup ( form_element -> properties -> content ) ; } } form_element -> properties = form_props ; P_BP_HTML_INPUT_PROPERTY_LIST tmp_prop_list = NULL ; BP_StringUtils * str_builder = new BP_StringUtils ( data ) ; char * param_name = NULL ; char * param_val = NULL ; for ( form_inputs = form_inputs -> first ; form_inputs ; form_inputs = form_inputs -> next ) { param_name = NULL ; param_val = NULL ; for ( tmp_prop_list = form_inputs -> properties -> first ; tmp_prop_list ; tmp_prop_list = tmp_prop_list -> next ) { if ( BP_strncasecmp ( tmp_prop_list -> name , " " , 4 ) == 0 ) { printf ( " \n " , tmp_prop_list -> content ) ; param_name = tmp_prop_list -> content ; } } for ( tmp_prop_list = form_inputs -> properties -> first ; tmp_prop_list ; tmp_prop_list = tmp_prop_list -> next ) { if ( BP_strncasecmp ( tmp_prop_list -> name , " " , 5 ) == 0 ) { printf ( " \n " , tmp_prop_list -> content ) ; param_val = tmp_prop_list -> content ; } } if ( this -> getFieldBehaviorModificationByName ( param_name ) ) { } else if ( this -> getInputOverrideByName ( param_name ) ) { str_builder -> BuildString ( param_name ) ; str_builder -> BuildString ( " " ) ; str_builder -> BuildString ( this -> getInputOverrideByName ( param_name ) -> input_override_val ) ; if ( form_inputs -> next ) str_builder -> BuildString ( " " ) ; } else { str_builder -> BuildString ( param_name ) ; str_builder -> BuildString ( " " ) ; str_builder -> BuildString ( param_val ) ; if ( form_inputs -> next ) str_builder -> BuildString ( " " ) ; } } printf ( " \n " , str_builder -> build_str ) ; BP_StringUtils * request_url_builder = new BP_StringUtils ( NULL ) ; char * base_path = BP_ParseURLToPath ( this -> request -> httpSession -> lastRequestedHref , 1 ) ; request_url_builder -> BuildString ( base_path ) ; if ( base_path ) bpfree ( base_path ) ; request_url_builder -> BuildString ( form_action ) ; this -> request -> HttpSetPostData ( str_builder -> build_str ) ; this -> request -> HttpMakeRequest ( request_url_builder -> build_str ) ; printf ( " \n " , request_url_builder -> build_str ) ; printf ( " \n " ) ; delete str_builder ; delete request_url_builder ; }
submit the form (result data will be in the request data)
submit the form ( result data will be in the request data )
// ensure we have a form element // will store the data generated via the form elements // initial form pointer saved // save form properties // save form inputs // get form method // 0 for get, 1 for post, 2 for etc // form action (url) to post to // iterate through properties and find method // check to see if the property name is "method" // if the value is post, set the form method to post (aka 1) // check to see if the property name is "method" // allocate form action // reset the properties // create new string builder // used in the loop below in order to set parameter names and values // walk form inputs and create string // set values to null on loop // get name // ========= Now Extract the Value Property ==================== // ======== Now Build Submit parameters =============================== // do nothing if behavior is being modified // add the string in // if we have a next element, add an ampersand // add the string in // if we have a next element, add an ampersand // display built string // create new request url builder // get last requested href parsed down // append action // set the post data for the request // this->request->HttpSetPostData(str_builder->build_str); // set method to post // curl_easy_setopt(this->request->httpSession->curl, CURLOPT_POST, 1); // set the build string as post data // curl_easy_setopt(this->request->httpSession->curl, CURLOPT_POSTFIELDS, str_builder->build_str); // HTTPGetCookieFromLastHeadersRecievedSetCookie(this->request->httpSession); // make the request /*
	*/ // destroy the string builders