/* Step through filter lines looking for a match. If a line matches, retval
* will be set to TR_FILTER_MATCH, so stop then. */
- this_fline = tr_filter_iter_first(filt_iter, filt);
- while(this_fline) {
+ for (this_fline = tr_filter_iter_first(filt_iter, filt);
+ this_fline != NULL;
+ this_fline = tr_filter_iter_next(filt_iter)) {
/* Assume we are going to succeed. If any specs fail to match, we'll set
* this to TR_FILTER_NO_MATCH. */
retval=TR_FILTER_MATCH;
- this_fspec = tr_fline_iter_first(fline_iter, this_fline);
- while(this_fspec) {
+ for (this_fspec = tr_fline_iter_first(fline_iter, this_fline);
+ this_fspec != NULL;
+ this_fspec = tr_fline_iter_next(fline_iter)) {
if (!tr_fspec_matches(this_fspec, filt->type, target)) {
retval=TR_FILTER_NO_MATCH; /* set this in case this is the last filter line */
break; /* give up on this filter line */
}
- this_fspec = tr_fline_iter_next(fline_iter);
}
if (retval==TR_FILTER_MATCH)
break;
- this_fline = tr_filter_iter_next(filt_iter);
}
if (retval==TR_FILTER_MATCH) {
talloc_free(fline);
}
-TR_FSPEC *tr_fline_add_spec(TR_FLINE *fline, TR_FSPEC *spec)
-{
- guint old_len = fline->specs->len;
- g_ptr_array_add(fline->specs, spec);
-
- if (old_len == fline->specs->len)
- return NULL; /* failed to add */
-
- talloc_steal(fline, spec);
- return spec;
-}
-
-static int tr_fline_destructor(void *object)
-{
- TR_FLINE *fline = talloc_get_type_abort(object, TR_FLINE);
- if (fline->specs)
- g_ptr_array_unref(fline->specs);
- return 0;
-}
-
TR_FLINE *tr_fline_new(TALLOC_CTX *mem_ctx)
{
TR_FLINE *fl = talloc(mem_ctx, TR_FLINE);
fl->action = TR_FILTER_ACTION_UNKNOWN;
fl->realm_cons = NULL;
fl->domain_cons = NULL;
- fl->specs = g_ptr_array_new();
+ fl->specs = tr_list_new(fl);
if (fl->specs == NULL) {
talloc_free(fl);
return NULL;
}
- talloc_set_destructor((void *)fl, tr_fline_destructor);
}
return fl;
}
return filt->type;
}
-TR_FLINE_ITER *tr_fline_iter_new(TALLOC_CTX *mem_ctx)
-{
- TR_FLINE_ITER *iter = talloc(mem_ctx, TR_FLINE_ITER);
- if (iter) {
- iter->fline = NULL;
- }
- return iter;
-}
-
-void tr_fline_iter_free(TR_FLINE_ITER *iter)
-{
- talloc_free(iter);
-}
-
-TR_FSPEC * tr_fline_iter_first(TR_FLINE_ITER *iter, TR_FLINE *fline)
-{
- if (!iter || !fline || !(fline->specs))
- return NULL;
-
- iter->fline = fline;
- iter->ii = 0;
- return tr_fline_iter_next(iter);
-}
-
-TR_FSPEC * tr_fline_iter_next(TR_FLINE_ITER *iter)
-{
- if (!iter)
- return NULL;
-
- if (iter->ii < iter->fline->specs->len)
- return g_ptr_array_index(iter->fline->specs, iter->ii++);
- return NULL;
-}
-
/**
* Check that a filter is valid, i.e., can be processed.
*
return 0; /* if we get here, either TR_FILTER_TYPE_UNKNOWN or an invalid value was found */
}
- this_fline = tr_filter_iter_first(filt_iter, filt);
- while(this_fline) {
+ for (this_fline = tr_filter_iter_first(filt_iter, filt);
+ this_fline != NULL;
+ this_fline = tr_filter_iter_next(filt_iter)) {
/* check that we recognize the action */
switch(this_fline->action) {
case TR_FILTER_ACTION_ACCEPT:
return 0;
}
- this_fspec = tr_fline_iter_first(fline_iter, this_fline);
- while(this_fspec) {
+ for (this_fspec = tr_fline_iter_first(fline_iter, this_fline);
+ this_fspec != NULL;
+ this_fspec = tr_fline_iter_next(fline_iter)) {
if (!tr_filter_validate_spec_field(filt->type, this_fspec)) {
talloc_free(tmp_ctx);
return 0;
talloc_free(tmp_ctx);
return 0;
}
- this_fspec = tr_fline_iter_next(fline_iter);
}
- this_fline = tr_filter_iter_next(filt_iter);
}
/* We ran the gauntlet. Success! */