Commit 0b11f2f6 authored by Pekka Pessi's avatar Pekka Pessi

Fixed memeory management problem in ua_set_params().

darcs-hash:20051013114504-65a35-13958ca1480b210411729071e455d169cf83ba53.gz
parent 630fcdda
......@@ -1021,6 +1021,7 @@ int ua_set_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
else if (refresher <= nua_no_refresher)
refresher = nua_no_refresher;
/* Set int in handle pref structure */
#define NHP_SET(nhp, pref, value) \
(((nhp)->nhp_set.set_bits.nhp_##pref = (value) != (nhp)->nhp_##pref), \
(nhp)->nhp_##pref = value)
......@@ -1049,6 +1050,7 @@ int ua_set_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
NHP_SET(nhp, service_route_enable, service_route_enable != 0);
NHP_SET(nhp, path_enable, path_enable != 0);
/* Set string in handle pref structure */
#define NHP_SET_STR(nhp, name, str) \
if (str != NONE && str0cmp(str, nhp->nhp_##name)) { \
char *new_str = su_strdup(tmphome, str); \
......@@ -1060,6 +1062,7 @@ int ua_set_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
} \
}
/* Set header in handle pref structure */
#define NHP_SET_HEADER(nhp, name, header, str) \
if (header != NONE || str != NONE) { \
sip_##name##_t *new_header; \
......@@ -1093,6 +1096,7 @@ int ua_set_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
nua_handle_preferences_t *ahp = su_alloc(nh->nh_home, sizeof *ahp);
if (ahp && su_home_move(nh->nh_home, tmphome) >= 0) {
memcpy(ahp, nhp, sizeof *ahp);
/* Zap pointers which are not set */
#define NHP_ZAP_UNSET_PTR(nhp, pref) \
(!(nhp)->nhp_set.set_bits.nhp_##pref ? (nhp)->nhp_##pref = NULL : NULL)
......@@ -1114,8 +1118,18 @@ int ua_set_params(nua_t *nua, nua_handle_t *nh, nua_event_t e,
nua_handle_preferences_t tbf[1];
nhp->nhp_set.set_any |= ohp->nhp_set.set_any;
*tbf = *ohp; *ohp = *nhp;
su_free(nh->nh_home, tbf->nhp_supported);
su_free(nh->nh_home, tbf->nhp_allow);
/* Free changed items */
#define NHP_ZAP_OVERRIDEN(tbf, nhp, pref) \
((tbf)->nhp_set.set_bits.nhp_##pref \
&& (tbf)->nhp_##pref != (nhp)->nhp_##pref \
? su_free(nh->nh_home, (void *)(tbf)->nhp_##pref) : (void)0)
NHP_ZAP_OVERRIDEN(tbf, nhp, supported);
NHP_ZAP_OVERRIDEN(tbf, nhp, allow);
NHP_ZAP_OVERRIDEN(tbf, nhp, user_agent);
NHP_ZAP_OVERRIDEN(tbf, nhp, ua_name);
NHP_ZAP_OVERRIDEN(tbf, nhp, organization);
}
else
/* Fail miserably with ENOMEM */
......@@ -1217,9 +1231,13 @@ ua_get_params(nua_t *nua, nua_handle_t *nh, nua_event_t e, tagi_t const *tags)
media_params = soa_get_paramlist(nh->nh_soa, TAG_END());
/* Include tag in list returned to user
* if it has been earlier set (by user) */
#define TIF(TAG, pref) \
TAG_IF(nhp->nhp_set.set_bits.nhp_##pref, TAG(nhp->nhp_##pref))
/* Include string tag made out of SIP header
* if it has been earlier set (by user) */
#define TIF_STR(TAG, pref) \
TAG_IF(nhp->nhp_set.set_bits.nhp_##pref, \
TAG(nhp->nhp_set.set_bits.nhp_##pref && nhp->nhp_##pref \
......
......@@ -505,19 +505,36 @@ int test_params(struct context *ctx)
SIPTAG_FROM_STR("sip:alice@example.com"),
NUTAG_URL("sip:*:*;transport=udp"),
TAG_END());
TEST_1(ctx->a.nua);
from = sip_from_make(NULL, Alice);
from = sip_from_make(tmphome, Alice);
nh = nua_handle(ctx->a.nua, NULL, TAG_END());
nua_set_hparams(nh, NUTAG_INVITE_TIMER(90), TAG_END());
run_a_until(ctx, nua_r_set_params, condition_final_response);
/* Modify all pointer values */
nua_set_params(ctx->a.nua,
SIPTAG_FROM_STR(Alice),
SIPTAG_SUPPORTED_STR("test"),
SIPTAG_ALLOW_STR("DWIM, OPTIONS, INFO"),
SIPTAG_USER_AGENT_STR("test_nua/1.0"),
SIPTAG_ORGANIZATION_STR("Te-Ras y.r."),
NUTAG_REGISTRAR("sip:openlaboratory.net"),
TAG_END());
run_a_until(ctx, nua_r_set_params, condition_final_response);
/* Modify everything from their default value */
nua_set_params(ctx->a.nua,
SIPTAG_FROM(from),
NUTAG_RETRY_COUNT(5),
NUTAG_RETRY_COUNT(9),
NUTAG_MAX_SUBSCRIPTIONS(6),
NUTAG_ENABLEINVITE(0),
......@@ -541,20 +558,24 @@ int test_params(struct context *ctx)
NUTAG_SERVICE_ROUTE_ENABLE(0),
NUTAG_PATH_ENABLE(0),
SIPTAG_SUPPORTED_STR("humppaa,kuole"),
SIPTAG_ALLOW_STR("OPTIONS, INFO"),
SIPTAG_USER_AGENT_STR("test_nua"),
SIPTAG_SUPPORTED(sip_supported_make(tmphome, "humppaa,kuole")),
SIPTAG_ALLOW(sip_allow_make(tmphome, "OPTIONS, INFO")),
SIPTAG_USER_AGENT(sip_user_agent_make(tmphome, "test_nua")),
SIPTAG_ORGANIZATION_STR("Pussy Galore's Flying Circus"),
SIPTAG_ORGANIZATION(sip_organization_make(tmphome, "Pussy Galore's Flying Circus")),
NUTAG_MEDIA_ENABLE(0),
NUTAG_REGISTRAR("sip:sip.wonderland.org"),
NUTAG_REGISTRAR(url_hdup(tmphome, (url_t *)"sip:sip.wonderland.org")),
TAG_END());
run_a_until(ctx, nua_r_set_params, condition_final_response);
su_home_auto(tmphome, sizeof(tmphome));
/* Modify something... */
nua_set_params(ctx->a.nua,
NUTAG_RETRY_COUNT(5),
TAG_END());
run_a_until(ctx, nua_r_set_params, condition_final_response);
{
sip_from_t const *from = NONE;
......@@ -848,7 +869,7 @@ int test_init(struct context *ctx, char *argv[])
ctx->root = su_root_create(ctx); TEST_1(ctx->root);
/* Disable threading by command line switch? */
su_root_threading(ctx->root, 0);
su_root_threading(ctx->root, 1);
ctx->a.nua = nua_create(ctx->root, a_callback, ctx,
SIPTAG_FROM_STR("sip:alice@example.com"),
......
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