library/src/decoders/HTML/BP-HTMLDecoder.cc
// Retrieves variables embedded in anchors using a delimiter set
Retrieves variables embedded in anchors using a delimiter set
Retrieves variables embedded in anchors using a delimiter set
P_BP_HTML_ANCHOR_VAR_LIST HTMLGetAnchorEmbeddedVariables(char *href, P_BP_HTML_ANCHOR_DELIMITERS delims, size_t len, P_BP_GARBAGE_COLLECTOR_DATA gc)
{
	if(delims == NULL) return NULL;
	if(href == NULL) return NULL;
	size_t hrefLen = strnlen(href, 10000);
	if(hrefLen == 10000)
		href[10000] = '\0';
	char * startString = strstr(href, delims->startDelimiter);
	if(startString == NULL)
		return NULL;
	if( bpstrlen(startString) == 0  )
		return NULL;
	char * varNamePosition = NULL;
	char *varName;
	char *varValue = NULL;
	int i = 0;
	P_BP_HTML_ANCHOR_VAR_LIST varList = NULL;
	for( varNamePosition = startString; varNamePosition != NULL; ){
		if(varList == NULL){
			varList = (P_BP_HTML_ANCHOR_VAR_LIST) BP_calloc(gc, NULL, sizeof(BP_HTML_ANCHOR_VAR_LIST), 1);
			varList->first = varList;
			varList->prev = NULL;
			varList->next = NULL;
		} else {
			if(varList->next == NULL)
				varList->next =(P_BP_HTML_ANCHOR_VAR_LIST) BP_calloc(gc, NULL, sizeof(BP_HTML_ANCHOR_VAR_LIST), 1);
			varList->next->first = varList->first;
			varList->next->prev = varList;
			varList->next->next = NULL;
			varList = varList->next;
		}
		i++;
		varName = HTMLGetAnchorEmbeddedVariableName(varNamePosition, delims, bpstrlen(varNamePosition), gc);
		if(varName)
			varValue = HTMLGetAnchorEmbeddedVariableValue(&varNamePosition[bpstrlen(varName)+1], delims, bpstrlen(&varNamePosition[bpstrlen(varName)]+1), gc);
		varList->name = varName;
		if(varName)
			varList->nameLen = bpstrlen(varName);
		varList->content    = varValue;
		if(varList->content)
			varList->contentLen = bpstrlen(varValue);
		varNamePosition = strstr(&varNamePosition[1], delims->nextDelimiter);
		if(varNamePosition == NULL)
			break;
	}
	return varList->first;
}
P_BP_HTML_ANCHOR_VAR_LIST HTMLGetAnchorEmbeddedVariables ( char * href , P_BP_HTML_ANCHOR_DELIMITERS delims , size_t len , P_BP_GARBAGE_COLLECTOR_DATA gc ) { if ( delims == NULL ) return NULL ; if ( href == NULL ) return NULL ; size_t hrefLen = strnlen ( href , 10000 ) ; if ( hrefLen == 10000 ) href [ 10000 ] = ' \0 ' ; char * startString = strstr ( href , delims -> startDelimiter ) ; if ( startString == NULL ) return NULL ; if ( bpstrlen ( startString ) == 0 ) return NULL ; char * varNamePosition = NULL ; char * varName ; char * varValue = NULL ; int i = 0 ; P_BP_HTML_ANCHOR_VAR_LIST varList = NULL ; for ( varNamePosition = startString ; varNamePosition != NULL ; ) { if ( varList == NULL ) { varList = ( P_BP_HTML_ANCHOR_VAR_LIST ) BP_calloc ( gc , NULL , sizeof ( BP_HTML_ANCHOR_VAR_LIST ) , 1 ) ; varList -> first = varList ; varList -> prev = NULL ; varList -> next = NULL ; } else { if ( varList -> next == NULL ) varList -> next = ( P_BP_HTML_ANCHOR_VAR_LIST ) BP_calloc ( gc , NULL , sizeof ( BP_HTML_ANCHOR_VAR_LIST ) , 1 ) ; varList -> next -> first = varList -> first ; varList -> next -> prev = varList ; varList -> next -> next = NULL ; varList = varList -> next ; } i ++ ; varName = HTMLGetAnchorEmbeddedVariableName ( varNamePosition , delims , bpstrlen ( varNamePosition ) , gc ) ; if ( varName ) varValue = HTMLGetAnchorEmbeddedVariableValue ( & varNamePosition [ bpstrlen ( varName ) + 1 ] , delims , bpstrlen ( & varNamePosition [ bpstrlen ( varName ) ] + 1 ) , gc ) ; varList -> name = varName ; if ( varName ) varList -> nameLen = bpstrlen ( varName ) ; varList -> content = varValue ; if ( varList -> content ) varList -> contentLen = bpstrlen ( varValue ) ; varNamePosition = strstr ( & varNamePosition [ 1 ] , delims -> nextDelimiter ) ; if ( varNamePosition == NULL ) break ; } return varList -> first ; }
Retrieves variables embedded in anchors using a delimiter set
Retrieves variables embedded in anchors using a delimiter set
// default null checks // get string length (MAX 10K CHARS) // null terminate at 10000 if not terminated (potentially could be a null byte write bug) // find the first instance of the delimiter in the string //---------------------------------------------------------------------- // Main Variable Extraction Loop // holds the name string // initialize // initialize // iterate through embedded variables // initial list creation // create anchor list element // move pointer forward // ------------------------------------------------------------------- // List should now be prepared to recieve one variable set //	printf("\n\t\t extracted var: %s =- %s", varName, varValue); // set name directly // calculate name length // set content directly // get content // return the var list