<commit_before>#include "gumbo.h"
#include "SecureFallback.h"

int
httpse_check_secure_fallback1(const GumboNode *node, const char *urlp)
{
	if(!node)
	{
		return 0;
	}

	if(node->type != GUMBO_NODE_ELEMENT)
	{
		return 0;
	}

	do
	{
		char mformat[1024];

		GumboAttribute *http_equiv = NULL; 
		GumboAttribute *content = NULL;

		if(node->v.element.tag != GUMBO_TAG_META)
		{
			break;
		}

		http_equiv = gumbo_get_attribute(&node->v.element
			.attributes, "http-equiv");

		content = gumbo_get_attribute(&node->v.element
			.attributes, "content");

		if(!http_equiv || !http_equiv->value || 
			strcasecmp(http_equiv->value, "refresh") != 0)
		{
			break;
		}

		if(!content || !content->value)
		{
			break;
		}

		snprintf(mformat, 1024, "url=%s", urlp);

		if(strcasestr(content->value, mformat))
		{
			return 1;
		}
	} while(0);

	size_t i, children_len = node->v.element.children.length;
	const GumboNode **children = (void *) node->v.element.children.data;

	for(i = 0; i < children_len; ++i)
	{
		if(1 == httpse_check_secure_fallback1(children[i], urlp))
		{
			return 1;
		}
	}
	return 0;
}

HttpseCode
httpse_check_secure_fallback(const HttpseTData *tdata)
{
	/* Variables */
	int fallback = 0;

	const char *url  = NULL;<commit_msg>Enhance meta refresh fallback detection functionality<commit_after>#include "gumbo.h"
#include "SecureFallback.h"

int
httpse_check_secure_fallback1(const GumboNode *node, const char *urlp)
{
	if(!node)
	{
		return 0;
	}

	if(node->type != GUMBO_NODE_ELEMENT)
	{
		return 0;
	}

	do
	{
		char mformat1[HTTPSE_XDATA_BUFSZ];
		char mformat2[HTTPSE_XDATA_BUFSZ];

		const GumboAttribute *http_equiv = NULL; 
		const GumboAttribute *content = NULL;

		if(node->v.element.tag != GUMBO_TAG_META)
		{
			break;
		}

		http_equiv = gumbo_get_attribute(&node->v.element
			.attributes, "http-equiv");

		content = gumbo_get_attribute(&node->v.element
			.attributes, "content");

		if(!http_equiv || !http_equiv->value || 
			strcasecmp(http_equiv->value, "refresh") != 0)
		{
			break;
		}

		if(!content || !content->value)
		{
			break;
		}

		snprintf(mformat1, HTTPSE_XDATA_BUFSZ, "url=%s", urlp);
		snprintf(mformat2, HTTPSE_XDATA_BUFSZ, "url=\'%s\'", urlp);

		if(strcasestr(content->value, mformat1))
		{
			return 1;
		}

		if(strcasestr(content->value, mformat2))
		{
			return 1;
		}
	} while(0);

	size_t i, children_len = node->v.element.children.length;
	const GumboNode **children = (void *) node->v.element.children.data;

	for(i = 0; i < children_len; ++i)
	{
		if(1 == httpse_check_secure_fallback1(children[i], urlp))
		{
			return 1;
		}
	}
	return 0;
}

HttpseCode
httpse_check_secure_fallback(const HttpseTData *tdata)
{
	/* Variables */
	int fallback = 0;

	const char *url  = NULL;
{'fraction_non_alphanumeric': 0.14972677595628414, 'fraction_numerical': 0.014207650273224045, 'mean_word_length': 3.894830659536542, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5422291', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1095, 'n_words': 194}