#include <ctype.h>
+typedef int (*fr_paircmp_func_t)(request_t *, fr_pair_t const *);
+
typedef struct paircmp_s paircmp_t;
struct paircmp_s {
fr_dict_attr_t const *da;
fr_dict_attr_t const *from;
bool first_only;
- void *instance; /* module instance */
fr_paircmp_func_t compare;
paircmp_t *next;
};
/*
* Compare the request packet type.
*/
-static int packet_cmp(UNUSED void *instance,
- request_t *request,
- fr_pair_t const *check_item)
+static int packet_cmp(request_t *request, fr_pair_t const *check_item)
{
PAIR_VERIFY(check_item);
/*
* Generic comparisons, via xlat.
*/
-static int generic_cmp(UNUSED void *instance,
- request_t *request,
- fr_pair_t const *check_item)
+static int generic_cmp(request_t *request, fr_pair_t const *check_item)
{
PAIR_VERIFY(check_item);
*/
for (c = cmp; c; c = c->next) {
if (c->da == check_item->da) {
- return (c->compare)(c->instance, request, check_item);
+ return (c->compare)(request, check_item);
}
}
vp->op = op;
fr_value_box_copy(vp, &vp->data, value);
- rcode = (c->compare)(c->instance, request, vp);
+ rcode = (c->compare)(request, vp);
talloc_free(vp);
return rcode;
}
return false;
}
+/** Unregister comparison function for an attribute
+ *
+ * @param[in] da dict reference to unregister for.
+ * @param[in] func comparison function to remove.
+ */
+static void paircmp_unregister(fr_dict_attr_t const *da, fr_paircmp_func_t func)
+{
+ paircmp_t *c, *last;
+
+ last = NULL;
+ for (c = cmp; c; c = c->next) {
+ if ((c->da == da) && (c->compare == func)) break;
+ last = c;
+ }
+
+ if (c == NULL) return;
+
+ if (last != NULL) {
+ last->next = c->next;
+ } else {
+ cmp = c->next;
+ }
+
+ talloc_free(c);
+}
+
/** Register a function as compare function.
*
* @param[in] da to register comparison function for.
* @param[in] first_only will decide if we loop over the request
* attributes or stop on the first one.
* @param[in] func comparison function.
- * @param[in] instance argument to comparison function.
* @return 0
*/
-int paircmp_register(fr_dict_attr_t const *da, fr_dict_attr_t const *from,
- bool first_only, fr_paircmp_func_t func, void *instance)
+static int paircmp_register(fr_dict_attr_t const *da, fr_dict_attr_t const *from,
+ bool first_only, fr_paircmp_func_t func)
{
paircmp_t *c;
c->da = da;
c->from = from;
c->first_only = first_only;
- c->instance = instance;
c->next = cmp;
cmp = c;
return 0;
}
-/** Unregister comparison function for an attribute
- *
- * @param[in] da dict reference to unregister for.
- * @param[in] func comparison function to remove.
- */
-void paircmp_unregister(fr_dict_attr_t const *da, fr_paircmp_func_t func)
-{
- paircmp_t *c, *last;
-
- last = NULL;
- for (c = cmp; c; c = c->next) {
- if ((c->da == da) && (c->compare == func)) break;
- last = c;
- }
-
- if (c == NULL) return;
-
- if (last != NULL) {
- last->next = c->next;
- } else {
- cmp = c->next;
- }
-
- talloc_free(c);
-}
-
/** Add built in pair comparisons
*
*/
return -1;
}
- paircmp_register(attr_packet_type, NULL, true, packet_cmp, NULL);
+ paircmp_register(attr_packet_type, NULL, true, packet_cmp);
- paircmp_register(attr_packet_src_ip_address, NULL, true, generic_cmp, NULL);
- paircmp_register(attr_packet_dst_ip_address, NULL, true, generic_cmp, NULL);
- paircmp_register(attr_packet_src_port, NULL, true, generic_cmp, NULL);
- paircmp_register(attr_packet_dst_port, NULL, true, generic_cmp, NULL);
- paircmp_register(attr_request_processing_stage, NULL, true, generic_cmp, NULL);
- paircmp_register(attr_packet_src_ipv6_address, NULL, true, generic_cmp, NULL);
- paircmp_register(attr_packet_dst_ipv6_address, NULL, true, generic_cmp, NULL);
- paircmp_register(attr_virtual_server, NULL, true, generic_cmp, NULL);
+ paircmp_register(attr_packet_src_ip_address, NULL, true, generic_cmp);
+ paircmp_register(attr_packet_dst_ip_address, NULL, true, generic_cmp);
+ paircmp_register(attr_packet_src_port, NULL, true, generic_cmp);
+ paircmp_register(attr_packet_dst_port, NULL, true, generic_cmp);
+ paircmp_register(attr_request_processing_stage, NULL, true, generic_cmp);
+ paircmp_register(attr_packet_src_ipv6_address, NULL, true, generic_cmp);
+ paircmp_register(attr_packet_dst_ipv6_address, NULL, true, generic_cmp);
+ paircmp_register(attr_virtual_server, NULL, true, generic_cmp);
return 0;
}