Commit 8c9ccaf1 authored by Pekka Pessi's avatar Pekka Pessi

Added stateless operation to test_proxy.

Using nta_incoming_default() and nta_outgoing_default().

darcs-hash:20051215212228-65a35-b69a570879fa434a947711a195e40bb7fc5e7572.gz
parent 1ae8798f
......@@ -1056,6 +1056,7 @@ int test_init(struct context *ctx, int start_proxy, url_t const *o_proxy)
struct event *e;
sip_contact_t const *m = NULL;
sip_from_t const *sipaddress = NULL;
url_t const *p_uri; /* Proxy URI */
ctx->root = su_root_create(NULL); TEST_1(ctx->root);
......@@ -1075,8 +1076,10 @@ int test_init(struct context *ctx, int start_proxy, url_t const *o_proxy)
if (print_headings)
printf("TEST NUA-2.0.1: init endpoint A\n");
p_uri = test_proxy_uri(ctx->p);
ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
NUTAG_PROXY(ctx->p ? ctx->p->uri : o_proxy),
NUTAG_PROXY(p_uri ? p_uri : o_proxy),
SIPTAG_FROM_STR("sip:alice@example.com"),
NUTAG_URL("sip:0.0.0.0:*"),
SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
......@@ -1102,7 +1105,7 @@ int test_init(struct context *ctx, int start_proxy, url_t const *o_proxy)
printf("TEST NUA-2.0.2: init endpoint B\n");
ctx->b.nua = nua_create(ctx->root, b_callback, ctx,
NUTAG_PROXY(ctx->p ? ctx->p->uri : o_proxy),
NUTAG_PROXY(p_uri ? p_uri : o_proxy),
SIPTAG_FROM_STR("sip:bob@example.org"),
NUTAG_URL("sip:0.0.0.0:*"),
SOATAG_USER_SDP_STR("m=audio 5006 RTP/AVP 8 0"),
......@@ -1127,7 +1130,7 @@ int test_init(struct context *ctx, int start_proxy, url_t const *o_proxy)
printf("TEST NUA-2.0.3: init endpoint C\n");
ctx->c.nua = nua_create(ctx->root, c_callback, ctx,
NUTAG_PROXY(ctx->p ? ctx->p->uri : o_proxy),
NUTAG_PROXY(p_uri ? p_uri : o_proxy),
SIPTAG_FROM_STR("sip:charlie@example.net"),
NUTAG_URL("sip:0.0.0.0:*"),
SOATAG_USER_SDP_STR("m=audio 5400 RTP/AVP 8 0"),
......
......@@ -75,6 +75,20 @@ extern int LIST_DUMMY_VARIABLE
#include <test_proxy.h>
struct proxy {
su_home_t home[1];
su_clone_r clone;
su_root_t *root;
nta_agent_t *agent;
url_t const *uri;
nta_leg_t *defleg;
struct proxy_transaction *stateless;
struct proxy_transaction *transactions;
struct registration_entry *entries;
};
LIST_PROTOS(static, registration_entry, struct registration_entry);
static struct registration_entry *
registration_entry_new(struct proxy *, url_t const *);
......@@ -126,6 +140,8 @@ registration_entry_find(struct proxy const *proxy, url_t const *uri);
static int
test_proxy_init(su_root_t *root, struct proxy *proxy)
{
struct proxy_transaction *t;
proxy->root = root;
proxy->agent = nta_agent_create(root,
......@@ -143,6 +159,19 @@ test_proxy_init(su_root_t *root, struct proxy *proxy)
if (!proxy->defleg)
return -1;
t = su_zalloc(proxy->home, sizeof *t);
if (!t)
return -1;
proxy->stateless = t;
t->proxy = proxy;
t->server = nta_incoming_default(proxy->agent);
t->client = nta_outgoing_default(proxy->agent, proxy_response, t);
if (!t->client || !t->server)
return -1;
proxy->uri = nta_agent_contact(proxy->agent)->m_url;
return 0;
......@@ -151,6 +180,13 @@ test_proxy_init(su_root_t *root, struct proxy *proxy)
static void
test_proxy_deinit(su_root_t *root, struct proxy *proxy)
{
struct proxy_transaction *t;
if ((t = proxy->stateless)) {
nta_incoming_destroy(t->server), t->server = NULL;
nta_outgoing_destroy(t->client), t->client = NULL;
}
nta_agent_destroy(proxy->agent);
}
......@@ -170,6 +206,8 @@ struct proxy *test_proxy_create(su_root_t *root)
return p;
}
/* Destroy the proxy object */
void test_proxy_destroy(struct proxy *p)
{
if (p) {
......@@ -178,6 +216,12 @@ void test_proxy_destroy(struct proxy *p)
}
}
/* Return the proxy URI */
url_t const *test_proxy_uri(struct proxy const *p)
{
return p ? p->uri : NULL;
}
/** Forward request */
static
int proxy_request(struct proxy *proxy,
......@@ -309,6 +353,8 @@ proxy_transaction_new(struct proxy *proxy)
static
void proxy_transaction_destroy(struct proxy_transaction *t)
{
if (t == t->proxy->stateless)
return;
proxy_transaction_remove(t);
nta_incoming_destroy(t->server);
nta_outgoing_destroy(t->client);
......
......@@ -29,23 +29,10 @@
#include <nta.h>
struct proxy;
struct proxy_transaction;
struct registration_entry;
struct proxy {
su_home_t home[1];
su_clone_r clone;
su_root_t *root;
nta_agent_t *agent;
url_t const *uri;
nta_leg_t *defleg;
struct proxy_transaction *transactions;
struct registration_entry *entries;
};
struct proxy *test_proxy_create(su_root_t *);
void test_proxy_destroy(struct proxy *);
url_t const *test_proxy_uri(struct proxy const *);
#endif
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