Пример #1
0
int
vslq_runquery(const struct vslq_query *query, struct VSL_transaction * const ptrans[])
{
	struct VSL_transaction *t;
	struct VSL_cursor *c;
	int i, len;
	const char *data;

	CHECK_OBJ_NOTNULL(query, VSLQ_QUERY_MAGIC);
	AN(query->regex);

	t = ptrans[0];
	while (t) {
		c = t->c;
		while (1) {
			i = VSL_Next(c);
			if (i == 0)
				break;
			assert(i == 1);
			AN(c->rec.ptr);
			len = VSL_LEN(c->rec.ptr);
			data = VSL_CDATA(c->rec.ptr);
			i = VRE_exec(query->regex, data, len, 0, 0, NULL, 0,
			    NULL);
			if (i != VRE_ERROR_NOMATCH) {
				AZ(VSL_ResetCursor(c));
				return (1);
			}
		}
		AZ(VSL_ResetCursor(c));
		t = *++ptrans;
	}

	return (0);
}
Пример #2
0
static int
vsl_match_IX(struct VSL_data *vsl, const vslf_list *list, const struct VSL_cursor *c)
{
	enum VSL_tag_e tag;
	const char *cdata;
	int len;
	const struct vslf *vslf;

	(void)vsl;
	tag = VSL_TAG(c->rec.ptr);
	cdata = VSL_CDATA(c->rec.ptr);
	len = VSL_LEN(c->rec.ptr);

	VTAILQ_FOREACH(vslf, list, list) {
		CHECK_OBJ_NOTNULL(vslf, VSLF_MAGIC);
		if (vslf->tag >= 0 && vslf->tag != tag)
			continue;
		if (VRE_exec(vslf->vre, cdata, len, 0, 0, NULL, 0, NULL) >= 0)
			return (1);
	}
Пример #3
0
accumulate(struct VSL_data *vsl, struct VSL_transaction * const pt[],
	void *priv)
{
	struct top *tp, t;
	unsigned int u;
	unsigned tag;
	const char *b, *e, *p;
	unsigned len;
	struct VSL_transaction *tr;

	(void)priv;

	for (tr = pt[0]; tr != NULL; tr = *++pt) {
		while ((1 == VSL_Next(tr->c))) {
			if (!VSL_Match(vsl, tr->c))
				continue;
			tag = VSL_TAG(tr->c->rec.ptr);
			b = VSL_CDATA(tr->c->rec.ptr);
			e = b + VSL_LEN(tr->c->rec.ptr);
			u = 0;
			for (p = b; p <= e; p++) {
				if (*p == '\0')
					break;
				if (f_flag && (*p == ':' || isspace(*p)))
					break;
				u += *p;
			}
			len = p - b;
			if (len == 0)
				continue;

			t.hash = u;
			t.tag = tag;
			t.clen = len;
			t.rec_data = VSL_CDATA(tr->c->rec.ptr);

			AZ(pthread_mutex_lock(&mtx));
			tp = VRB_FIND(t_key, &h_key, &t);
			if (tp) {
				VRB_REMOVE(t_order, &h_order, tp);
				tp->count += 1.0;
				/* Reinsert to rebalance */
				VRB_INSERT(t_order, &h_order, tp);
			} else {
				ntop++;
				tp = calloc(sizeof *tp, 1);
				assert(tp != NULL);
				tp->hash = u;
				tp->count = 1.0;
				tp->clen = len;
				tp->tag = tag;
				tp->rec_buf = strdup(t.rec_data);
				tp->rec_data = tp->rec_buf;
				AN(tp->rec_data);
				VRB_INSERT(t_key, &h_key, tp);
				VRB_INSERT(t_order, &h_order, tp);
			}
			AZ(pthread_mutex_unlock(&mtx));

		}
	}

	return (0);
}