Commit 43b5dee2 authored by Pekka Pessi's avatar Pekka Pessi

Added nua_generate_instance_identifier() to nua module.

darcs-hash:20060503103529-65a35-5b045e44599313c705fd2c099a10586369a86f02.gz
parent 41e398f5
......@@ -42,6 +42,7 @@
#include <sofia-sip/su_tag_class.h>
#include <sofia-sip/su_tag_class.h>
#include <sofia-sip/su_tagarg.h>
#include <sofia-sip/su_uniqueid.h>
#include <stdio.h>
......@@ -221,6 +222,23 @@ int nua_handle_unref(nua_handle_t *nh)
return su_home_unref(nh->nh_home);
}
/** Generate an instance identifier */
char const *nua_generate_instance_identifier(su_home_t *home)
{
char str[su_guid_strlen + 1];
su_guid_t guid[1];
su_guid_generate(guid);
/*
* Guid looks like "NNNNNNNN-NNNN-NNNN-NNNN-XXXXXXXXXXXX"
* where NNNNNNNN-NNNN-NNNN-NNNN is timestamp and XX is MAC address
* (but we use usually random ID for MAC because we do not have
* guid generator available for all processes within node)
*/
su_guid_sprintf(str, su_guid_strlen + 1, guid);
return su_strdup(home, str);
}
/** Get name for a NUA event. */
char const *nua_event_name(nua_event_t event)
......
......@@ -35,7 +35,6 @@
#include <sofia-sip/string0.h>
#include <sofia-sip/su_strlst.h>
#include <sofia-sip/sha1.h>
#include <sofia-sip/su_uniqueid.h>
#include <sofia-sip/token64.h>
#include <sofia-sip/su_tagarg.h>
......@@ -181,28 +180,12 @@ int nua_stack_init_instance(nua_handle_t *nh, tagi_t const *tags)
tl_gets(tags, NUTAG_INSTANCE_REF(instance), TAG_END());
if (instance == NONE) {
char str[su_guid_strlen + 1];
su_guid_t guid[1];
su_guid_generate(guid);
/*
* Guid looks like "NNNNNNNN-NNNN-NNNN-NNNN-XXXXXXXXXXXX"
* where NNNNNNNN-NNNN-NNNN-NNNN is timestamp and XX is MAC address
* (but we use usually random ID for MAC because we do not have
* guid generator available for all processes within node)
*/
su_guid_sprintf(str, su_guid_strlen + 1, guid);
NHP_SET(nhp, instance, su_sprintf(nh->nh_home, "urn:uuid:%s", str));
}
else {
if (instance != NONE) {
NHP_SET(nhp, instance, su_strdup(nh->nh_home, instance));
if (!instance && !nhp->nhp_instance)
return -1;
}
if (instance && !nhp->nhp_instance)
return -1;
return 0;
}
......
......@@ -307,6 +307,9 @@ void nua_respond(nua_handle_t *nh,
#define nua_handle_home(nh) ((su_home_t *)(nh))
/** Generate an instance identifier */
char const *nua_generate_instance_identifier(su_home_t *);
#ifndef NUA_SAVED_EVENT_T
#define NUA_SAVED_EVENT_T struct nua_saved_event *
#endif
......
......@@ -159,6 +159,8 @@ struct context
printer_function *printer;
char const *instance;
/* Per-call stuff */
struct call {
struct call *next;
......@@ -1472,6 +1474,8 @@ int test_init(struct context *ctx,
if (a_uri == NULL)
a_uri = p_uri;
ctx->a.instance = nua_generate_instance_identifier(ctx->home);
ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
NUTAG_PROXY(a_uri ? a_uri : o_proxy),
SIPTAG_FROM_STR("sip:alice@example.com"),
......@@ -1479,7 +1483,7 @@ int test_init(struct context *ctx,
TAG_IF(a_bind != a_bind2, NUTAG_SIPS_URL(a_bind2)),
SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
NTATAG_SIP_T1X64(4000),
NUTAG_KEEPALIVE(1),
NUTAG_INSTANCE(ctx->a.instance),
TAG_END());
TEST_1(ctx->a.nua);
......@@ -1501,11 +1505,14 @@ int test_init(struct context *ctx,
if (print_headings)
printf("TEST NUA-2.2.2: init endpoint B\n");
ctx->b.instance = nua_generate_instance_identifier(ctx->home);
ctx->b.nua = nua_create(ctx->root, b_callback, ctx,
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"),
NUTAG_INSTANCE(ctx->b.instance),
TAG_END());
TEST_1(ctx->b.nua);
......@@ -1526,11 +1533,14 @@ int test_init(struct context *ctx,
if (print_headings)
printf("TEST NUA-2.2.3: init endpoint C\n");
ctx->c.instance = nua_generate_instance_identifier(ctx->home);
ctx->c.nua = nua_create(ctx->root, c_callback, ctx,
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"),
NUTAG_INSTANCE(ctx->c.instance),
TAG_END());
TEST_1(ctx->c.nua);
......@@ -1631,7 +1641,8 @@ int test_register(struct context *ctx)
TEST_1(a_reg->nh = nua_handle(a->nua, a_reg, TAG_END()));
REGISTER(a, a_reg, a_reg->nh, SIPTAG_TO(a->to), TAG_END());
REGISTER(a, a_reg, a_reg->nh, SIPTAG_TO(a->to), NUTAG_KEEPALIVE(1),
TAG_END());
run_a_until(ctx, -1, save_until_final_response);
TEST_1(e = a->events->head);
......
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