Commit 1269836a authored by Pekka Pessi's avatar Pekka Pessi

test_nat.[hc]: added application-provided pointer argument to filter prototype.

darcs-hash:20070226185327-55b16-12ae40de1d406c0e33c570c61b7552e2f7b6f70d.gz
parent 30e8c039
......@@ -948,15 +948,19 @@ int test_mime_negotiation(struct context *ctx)
/* ---------------------------------------------------------------------- */
size_t filter_200_OK(void *message, size_t len)
size_t filter_200_OK(void *arg, void *message, size_t len)
{
(void)arg;
if (len >= 11 && strncasecmp(message, "SIP/2.0 200", 11) == 0)
return 0;
return len;
}
size_t filter_ACK(void *message, size_t len)
size_t filter_ACK(void *arg, void *message, size_t len)
{
(void)arg;
if (len >= 7 && strncasecmp(message, "ACK sip", 7) == 0)
return 0;
return len;
......@@ -988,7 +992,7 @@ int test_call_timeouts(struct context *ctx)
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
TEST_1(f = test_nat_add_filter(ctx->nat, filter_200_OK, nat_inbound));
TEST_1(f = test_nat_add_filter(ctx->nat, filter_200_OK, NULL, nat_inbound));
INVITE(a, a_call, a_call->nh,
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
......@@ -1072,7 +1076,7 @@ int test_call_timeouts(struct context *ctx)
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
TEST_1(f = test_nat_add_filter(ctx->nat, filter_ACK, nat_outbound));
TEST_1(f = test_nat_add_filter(ctx->nat, filter_ACK, NULL, nat_outbound));
INVITE(a, a_call, a_call->nh,
TAG_IF(!ctx->proxy_tests, NUTAG_URL(b->contact->m_url)),
......
......@@ -815,10 +815,13 @@ int bye_when_completing(CONDITION_PARAMS);
static int ack_sent = 0;
size_t count_acks(void *message, size_t len)
size_t count_acks(void *arg, void *message, size_t len)
{
(void)arg;
if (strncasecmp(message, "ACK sip:", 8) == 0)
ack_sent++;
return len;
}
......@@ -920,7 +923,7 @@ int test_early_bye(struct context *ctx)
printf("TEST NUA-6.2: BYE call when completing\n");
if (ctx->nat)
TEST_1(f = test_nat_add_filter(ctx->nat, count_acks, nat_outbound));
TEST_1(f = test_nat_add_filter(ctx->nat, count_acks, NULL, nat_outbound));
ack_sent = 0;
TEST_1(a_call->nh = nua_handle(a->nua, a_call, SIPTAG_TO(b->to), TAG_END()));
......
......@@ -160,7 +160,8 @@ LIST_PROTOS(static, nat_filter, struct nat_filter);
struct nat_filter
{
struct nat_filter *next, **prev;
size_t (*condition)(void *message, size_t len);
size_t (*condition)(void *arg, void *message, size_t len);
void *arg;
};
/* nat entry point */
......@@ -694,7 +695,7 @@ static int udp_in_to_out(struct nat *nat, su_wait_t *wait, struct binding *b)
len = (size_t)n;
for (f = nat->out_filters; f; f = f->next) {
filtered = f->condition(nat->buffer, len);
filtered = f->condition(f->arg, nat->buffer, len);
if (filtered != len) {
if (nat->logging)
printf("nat: udp filtered "MOD_ZU" from %s => "MOD_ZU" to %s\n",
......@@ -736,7 +737,7 @@ static int udp_out_to_in(struct nat *nat, su_wait_t *wait, struct binding *b)
len = (size_t)n;
for (f = nat->in_filters; f; f = f->next) {
filtered = f->condition(nat->buffer, len);
filtered = f->condition(f->arg, nat->buffer, len);
if (filtered != len) {
if (nat->logging)
printf("nat: udp filtered "MOD_ZU" from %s => "MOD_ZU" to %s\n",
......@@ -951,8 +952,10 @@ int execute_nat_filter_remove(void *_args)
}
struct nat_filter *test_nat_add_filter(struct nat *nat,
size_t (*condition)(void *message,
size_t (*condition)(void *arg,
void *message,
size_t len),
void *arg,
int outbound)
{
struct args a[1];
......@@ -966,6 +969,7 @@ struct nat_filter *test_nat_add_filter(struct nat *nat,
if (a->f) {
a->f->condition = condition;
a->f->arg = arg;
if (su_task_execute(su_clone_task(nat->clone),
execute_nat_filter_insert, a, NULL) < 0)
su_free(nat->home, a->f), a->f = NULL;
......
......@@ -44,8 +44,10 @@ int test_nat_public(struct nat *nat, void const *address, int addrlen);
int test_nat_flush(struct nat *nat);
struct nat_filter *test_nat_add_filter(struct nat *nat,
size_t (*condition)(void *message,
size_t (*condition)(void *arg,
void *message,
size_t len),
void *arg,
int outbound);
enum { nat_inbound, nat_outbound };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment