void SuperFamicomCartridge::write_hash(netnode & node) const
{
  node.hashset("rom_size", rom_size);
  node.hashset("ram_size", ram_size);
  node.hashset("firmware_appended", firmware_appended ? 1 : 0);

  node.hashset("header_offset", header_offset);

  node.hashset("type", type_string());
  node.hashset("region", region_string());
  node.hashset("mapper", mapper_string());
  node.hashset("dsp1_mapper", dsp1_mapper_string());

  node.hashset("has_bsx_slot", has_bsx_slot ? 1 : 0);
  node.hashset("has_superfx", has_superfx ? 1 : 0);
  node.hashset("has_sa1", has_sa1 ? 1 : 0);
  node.hashset("has_sharprtc", has_sharprtc ? 1 : 0);
  node.hashset("has_epsonrtc", has_epsonrtc ? 1 : 0);
  node.hashset("has_sdd1", has_sdd1 ? 1 : 0);
  node.hashset("has_spc7110", has_spc7110 ? 1 : 0);
  node.hashset("has_cx4", has_cx4 ? 1 : 0);
  node.hashset("has_dsp1", has_dsp1 ? 1 : 0);
  node.hashset("has_dsp2", has_dsp2 ? 1 : 0);
  node.hashset("has_dsp3", has_dsp3 ? 1 : 0);
  node.hashset("has_dsp4", has_dsp4 ? 1 : 0);
  node.hashset("has_obc1", has_obc1 ? 1 : 0);
  node.hashset("has_st010", has_st010 ? 1 : 0);
  node.hashset("has_st011", has_st011 ? 1 : 0);
  node.hashset("has_st018", has_st018 ? 1 : 0);
}
Beispiel #2
0
isc_boolean_t
dns_geoip_match(const isc_netaddr_t *reqaddr, isc_uint8_t *scope,
		const dns_geoip_databases_t *geoip,
		const dns_geoip_elem_t *elt)
{
#ifndef HAVE_GEOIP
	UNUSED(reqaddr);
	UNUSED(geoip);
	UNUSED(elt);

	return (ISC_FALSE);
#else
	GeoIP *db;
	GeoIPRecord *record;
	GeoIPRegion *region;
	dns_geoip_subtype_t subtype;
	isc_uint32_t ipnum = 0;
	int maxlen = 0, id, family;
	const char *cs;
	char *s;
#ifdef HAVE_GEOIP_V6
	const geoipv6_t *ipnum6 = NULL;
#else
	const void *ipnum6 = NULL;
#endif

	INSIST(geoip != NULL);

	family = reqaddr->family;
	switch (family) {
	case AF_INET:
		ipnum = ntohl(reqaddr->type.in.s_addr);
		break;
	case AF_INET6:
#ifdef HAVE_GEOIP_V6
		ipnum6 = &reqaddr->type.in6;
		break;
#else
		return (ISC_FALSE);
#endif
	default:
		return (ISC_FALSE);
	}

	subtype = fix_subtype(reqaddr, geoip, elt->subtype);

	switch (subtype) {
	case dns_geoip_country_code:
		maxlen = 2;
		goto getcountry;

	case dns_geoip_country_code3:
		maxlen = 3;
		goto getcountry;

	case dns_geoip_country_name:
		maxlen = 255;
 getcountry:
		db = DB46(reqaddr, geoip, country);
		if (db == NULL)
			return (ISC_FALSE);

		INSIST(elt->as_string != NULL);

		cs = country_lookup(db, subtype, family, ipnum, ipnum6, scope);
		if (cs != NULL && strncasecmp(elt->as_string, cs, maxlen) == 0)
			return (ISC_TRUE);
		break;

	case dns_geoip_city_countrycode:
	case dns_geoip_city_countrycode3:
	case dns_geoip_city_countryname:
	case dns_geoip_city_region:
	case dns_geoip_city_regionname:
	case dns_geoip_city_name:
	case dns_geoip_city_postalcode:
	case dns_geoip_city_continentcode:
	case dns_geoip_city_timezonecode:
		INSIST(elt->as_string != NULL);

		db = DB46(reqaddr, geoip, city);
		if (db == NULL)
			return (ISC_FALSE);

		record = city_lookup(db, subtype, family,
				     ipnum, ipnum6, scope);
		if (record == NULL)
			break;

		s = city_string(record, subtype, &maxlen);
		INSIST(maxlen != 0);
		if (s != NULL && strncasecmp(elt->as_string, s, maxlen) == 0)
			return (ISC_TRUE);
		break;

	case dns_geoip_city_metrocode:
		db = DB46(reqaddr, geoip, city);
		if (db == NULL)
			return (ISC_FALSE);

		record = city_lookup(db, subtype, family,
				     ipnum, ipnum6, scope);
		if (record == NULL)
			break;

		if (elt->as_int == record->metro_code)
			return (ISC_TRUE);
		break;

	case dns_geoip_city_areacode:
		db = DB46(reqaddr, geoip, city);
		if (db == NULL)
			return (ISC_FALSE);

		record = city_lookup(db, subtype, family,
				     ipnum, ipnum6, scope);
		if (record == NULL)
			break;

		if (elt->as_int == record->area_code)
			return (ISC_TRUE);
		break;

	case dns_geoip_region_countrycode:
	case dns_geoip_region_code:
	case dns_geoip_region_name:
	case dns_geoip_region:
		if (geoip->region == NULL)
			return (ISC_FALSE);

		INSIST(elt->as_string != NULL);

		/* Region DB is not supported for IPv6 */
		if (family == AF_INET6)
			return (ISC_FALSE);

		region = region_lookup(geoip->region, subtype, ipnum, scope);
		if (region == NULL)
			break;

		s = region_string(region, subtype, &maxlen);
		INSIST(maxlen != 0);
		if (s != NULL && strncasecmp(elt->as_string, s, maxlen) == 0)
			return (ISC_TRUE);
		break;

	case dns_geoip_isp_name:
		db = geoip->isp;
		goto getname;

	case dns_geoip_org_name:
		db = geoip->org;
		goto getname;

	case dns_geoip_as_asnum:
		db = geoip->as;
		goto getname;

	case dns_geoip_domain_name:
		db = geoip->domain;

 getname:
		if (db == NULL)
			return (ISC_FALSE);

		INSIST(elt->as_string != NULL);
		/* ISP, Org, AS, and Domain are not supported for IPv6 */
		if (family == AF_INET6)
			return (ISC_FALSE);

		s = name_lookup(db, subtype, ipnum, scope);
		if (s != NULL) {
			size_t l;
			if (strcasecmp(elt->as_string, s) == 0)
				return (ISC_TRUE);
			if (subtype != dns_geoip_as_asnum)
				break;
			/*
			 * Just check if the ASNNNN value matches.
			 */
			l = strlen(elt->as_string);
			if (l > 0U && strchr(elt->as_string, ' ') == NULL &&
			    strncasecmp(elt->as_string, s, l) == 0 &&
			    s[l] == ' ')
				return (ISC_TRUE);
		}
		break;

	case dns_geoip_netspeed_id:
		INSIST(geoip->netspeed != NULL);

		/* Netspeed DB is not supported for IPv6 */
		if (family == AF_INET6)
			return (ISC_FALSE);

		id = netspeed_lookup(geoip->netspeed, subtype, ipnum, scope);
		if (id == elt->as_int)
			return (ISC_TRUE);
		break;

	case dns_geoip_countrycode:
	case dns_geoip_countrycode3:
	case dns_geoip_countryname:
	case dns_geoip_regionname:
		/*
		 * If these were not remapped by fix_subtype(),
		 * the database was unavailable. Always return false.
		 */
		break;

	default:
		INSIST(0);
	}

	return (ISC_FALSE);
#endif
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {

	if( nrhs != 2 ) mexErrMsgTxt("Exactly one string input argument and one cell array argument required.");
	if( nlhs != 0 ) mexErrMsgTxt("No output arguments required.");

	char* path = getString(prhs[0]);

	std::vector<Region*> regions;

	if (!mxIsCell(prhs[1]))
		mexErrMsgTxt("Second argument must be a cell array");

	int length = MAX(mxGetM(prhs[1]), mxGetN(prhs[1]));

	if ( MIN(mxGetM(prhs[1]), mxGetN(prhs[1])) != 1 )
		mexErrMsgTxt("Cell array must be a vector");

	for (int i = 0; i < length; i++) {

		mxArray* val = mxGetCell (prhs[1], i);
		double *d = (double*) mxGetPr(val);
		Region* region = NULL;

		int l = MAX(mxGetM(val), mxGetN(val));

		if (MIN(mxGetM(val), mxGetN(val)) == 1) { 

			if (l == 1) {

				region = region_create_special(d[0]);

			} else if (l == 4) {

				region = region_create_rectangle(d[0], d[1], d[2], d[3]);

			} else if (l > 5 && l % 2 == 0) {

				region = region_create_polygon(l / 2);

				for (int j = 0; j < l / 2; j++) {
					region->data.polygon.x[j] = d[j * 2];
					region->data.polygon.y[j] = d[j * 2 + 1];
				}
			}

		}

		if (region) {
			regions.push_back(region);
		} else {
			char message[128];
			sprintf(message, "Not a valid region at position %d, skipping", i+1);
			mexWarnMsgTxt(message);
		}

	}

	std::ofstream ofs;
	ofs.open (path, std::ofstream::out | std::ofstream::app);

	if (ofs.is_open()) {

    	for (int i = 0; i < regions.size(); i++) {

			Region* region = regions[i];

			char * tmp = region_string(region);

			if (tmp) {
				ofs << tmp << "\n";
				free(tmp);
			}
			
			region_release(&region);

		}

	} else {

		free(path);
		mexErrMsgTxt("Unable to open file for writing.");
	}

	ofs.close();
	free(path);
}