<commit_before>// vim:syntax=lpc

string policy;
mapping _stream_policy = ([]);

void create(mixed ... args) {
    allow_port_range(@args);
}

void allow_port_range(string domain, int min, void|int max, 
		      int(0..1)|void insecure) {

    if (!max) {
	max = min;
    }

    _stream_policy[domain] = ({ min, max, insecure });
    policy = UNDEFINED;
}

void deny_domain(string domain) {
    if (m_delete(_stream_policy, domain)) {
	policy = UNDEFINED;
    }
}


string render_policy() {
    if (policy) return policy;

    policy = "<cross-domain-policy>";
    foreach (_stream_policy; string domain; array a) {
	string range, fmt;

	if (!a[0]) {
	    range = "*";
	} else {
	    sprintf(range, "%d-%d", @a);
	}

	if (a[2]) { // insecure	
	    fmt = "<allow-access-from domain=\"%s\" to-ports=\"%s\" secure=\"false\" \\>";
	} else {
	    fmt = "<allow-access-from domain=\"%s\" to-ports=\"%s\" \\>";
	}
	policy += sprintf(fmt, domain, range);
    }
    policy += "</cross-domain-policy>\0";
}<commit_msg>some bad bugs in crossdomain policy rendering. didnt test.<commit_after>// vim:syntax=lpc

string policy;
mapping _stream_policy = ([]);

void create(mixed ... args) {
    if (sizeof(args)) 
	allow_port_range(@args);
}

void allow_port_range(string domain, int min, void|int max, 
		      int(0..1)|void insecure) {

    if (!max) {
	max = min;
    }

    _stream_policy[domain] = ({ min, max, insecure });
    policy = UNDEFINED;
}

void deny_domain(string domain) {
    if (m_delete(_stream_policy, domain)) {
	policy = UNDEFINED;
    }
}


string render_policy() {
    if (policy) return policy;

    policy = "<cross-domain-policy>";
    foreach (_stream_policy; string domain; array a) {
	string range, fmt;

	if (!a[0]) {
	    range = "*";
	} else {
	    range = sprintf("%d-%d", @a);
	}

	if (a[2]) { // insecure	
	    fmt = "<allow-access-from domain=\"%s\" to-ports=\"%s\" secure=\"false\" \\>";
	} else {
	    fmt = "<allow-access-from domain=\"%s\" to-ports=\"%s\" \\>";
	}
	policy += sprintf(fmt, domain, range);
    }
    policy += "</cross-domain-policy>\0";

    return policy;
}
{'fraction_non_alphanumeric': 0.1907706945765937, 'fraction_numerical': 0.004757373929590866, 'mean_word_length': 2.945590994371482, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '7651247', 'n_tokens_mistral': 778, 'n_tokens_neox': 737, 'n_words': 172}