Exemplo n.º 1
0
void spatial_index<Value, Filter, InputStream, BBox>::query_node(Filter const& filter, InputStream& in, std::vector<Value>& results)
{
    int offset = read_ndr_integer(in);
    typename spatial_index<Value, Filter, InputStream, BBox>::bbox_type node_ext;
    read_envelope(in, node_ext);
    int num_shapes = read_ndr_integer(in);
    if (!filter.pass(node_ext))
    {
        in.seekg(offset + num_shapes * sizeof(Value) + 4, std::ios::cur);
        return;
    }

    for (int i = 0; i < num_shapes; ++i)
    {
        Value item;
        in.read(reinterpret_cast<char*>(&item), sizeof(Value));
        results.push_back(std::move(item));
    }

    int children = read_ndr_integer(in);
    for (int j = 0; j < children; ++j)
    {
        query_node(filter, in, results);
    }
}
Exemplo n.º 2
0
void spatial_index<Value, Filter, InputStream>::query_first_n_impl(Filter const& filter, InputStream& in, std::vector<Value>& results, std::size_t count)
{
    if (results.size() == count) return;
    int offset = read_ndr_integer(in);
    box2d<double> node_ext;
    read_envelope(in, node_ext);
    int num_shapes = read_ndr_integer(in);
    if (!filter.pass(node_ext))
    {
        in.seekg(offset + num_shapes * sizeof(Value) + 4, std::ios::cur);
        return;
    }

    for (int i = 0; i < num_shapes; ++i)
    {
        Value item;
        in.read(reinterpret_cast<char*>(&item), sizeof(Value));
        if (results.size() < count) results.push_back(std::move(item));
    }
    int children = read_ndr_integer(in);
    for (int j = 0; j < children; ++j)
    {
        query_first_n_impl(filter, in, results, count);
    }
}
Exemplo n.º 3
0
box2d<double> spatial_index<Value, Filter, InputStream>::bounding_box(InputStream& in)
{
    if (!check_header(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
    in.seekg(16 + 4, std::ios::beg);
    box2d<double> box;
    read_envelope(in, box);
    in.seekg(0, std::ios::beg);
    return box;
}
Exemplo n.º 4
0
BBox spatial_index<Value, Filter, InputStream, BBox>::bounding_box(InputStream& in)
{
    static_assert(std::is_standard_layout<Value>::value, "Values stored in quad-tree must be standard layout type");
    if (!check_spatial_index(in)) throw std::runtime_error("Invalid index file (regenerate with shapeindex)");
    in.seekg(16 + 4, std::ios::beg);
    typename spatial_index<Value, Filter, InputStream, BBox>::bbox_type box;
    read_envelope(in, box);
    in.seekg(0, std::ios::beg);
    return box;
}
Exemplo n.º 5
0
int main(void) {
	int     spamc_out_len = 0;
	char    buf[4096];
	ssize_t len;
	int     status;
	char    *val;

	if ((val = getenv("SPAMDLIMIT"))) {
		max_mail_size = atoi(val);
		if (max_mail_size <= 0) max_mail_size = DEFAULT_LIMIT;
	}
	if ((val = getenv("QSPAMEXIT"))) {
		spamexit = atoi(val);
	}

	mail = malloc((size_t)max_mail_size);
	/* Pass it through if we're low on memory */
	if (!mail) pass_through("out of mem");
	while ((len = read(0, mail + mail_size, (size_t)(max_mail_size - mail_size))) > 0) {
		mail_size += len;
		/* Pass it through if it's too big */
		if (mail_size == max_mail_size) pass_through("mail too big");
	}
	/* Fail if there was a problem reading the mail */
	if (len < 0) _exit(FAIL_BUG);
	if (!mail_size) _exit(FAIL_BUG);

	read_envelope();
	run_spamc();
	run_qqueue();

	/* Feed the mail to spamc */
	len = write(spamc_in[1], mail, (size_t)mail_size);
	/* Pass the mail through if this fails */
	if (len != mail_size) pass_through("spamc write failure");
	close(spamc_in[1]);

	write_header("X-Spam-Queue: Filtered for <%s>\n", user ? user : "******", 0);
	/* Copy the mail from spamc to qmail-queue */
	while ((len = read(spamc_out[0], buf, sizeof(buf))) > 0) {
		spamc_out_len += len;
		if (write(qq_mail[1], buf, (size_t)len) != len) {
			/* Problem writing to spamc -> pass original through */
			pass_through("spamc read failure");
		}
	}
	/* Pass the original message through if we had a read error from spamc. */
	if (len < 0) pass_through("spamc returned incomplete mail");
	/* Or if we didn't get at least as much back from spamc as we put in */
	if (spamc_out_len < mail_size) pass_through("spamc returned short mail");

	if (waitpid(spamc_pid, &status, 0) != spamc_pid) _exit(FAIL_BUG);
	if (!WIFEXITED(status)) _exit(FAIL_BUG);
	switch (WEXITSTATUS(status)) {
		case 1:
			if (spamexit != -1) _exit(spamexit);
			break;
		case 0:
			break;
		default:
			_exit(FAIL_BUG);
			break;
	}

	/* Ok, this is not spam, and we have copied the message to qmail-queue without problems */
	/* Now we transfer the envelope */
	qq_write_envelope();
	/* And we're done. */
	qq_done();
}