Commit 933f5144 authored by Pekka Pessi's avatar Pekka Pessi

nua_publish.c: fixed refreshing. using normal restart mechanisms with 412.

Fixed test case, too.

Thanks for Jan van den Bosch for reporting the problem.

darcs-hash:20070419101842-55b16-ea6aa147c43015093c2961ef47ff08db70173b13.gz
parent bd6696ab
......@@ -236,6 +236,9 @@ static int nua_publish_client_init(nua_client_request_t *cr,
static int nua_publish_client_request(nua_client_request_t *cr,
msg_t *, sip_t *,
tagi_t const *tags);
static int nua_publish_client_check_restart(nua_client_request_t *cr,
int status, char const *phrase,
sip_t const *sip);
static int nua_publish_client_response(nua_client_request_t *cr,
int status, char const *phrase,
sip_t const *sip);
......@@ -251,7 +254,7 @@ static nua_client_methods_t const nua_publish_client_methods = {
nua_publish_client_template,
nua_publish_client_init,
nua_publish_client_request,
/* nua_publish_client_check_restart */ NULL,
nua_publish_client_check_restart,
nua_publish_client_response,
/* nua_publish_client_preliminary */ NULL
};
......@@ -348,6 +351,34 @@ int nua_publish_client_request(nua_client_request_t *cr,
TAG_NEXT(tags));
}
static int nua_publish_client_check_restart(nua_client_request_t *cr,
int status, char const *phrase,
sip_t const *sip)
{
char const *restarting = NULL;
if (cr->cr_terminating || !cr->cr_usage)
;
else if (status == 412)
restarting = phrase;
else if (200 <= status && status < 300 &&
sip->sip_expires && sip->sip_expires->ex_delta == 0)
restarting = "Immediate re-PUBLISH";
if (restarting) {
struct publish_usage *pu = nua_dialog_usage_private(cr->cr_usage);
if (pu) {
pu->pu_published = 0;
su_free(cr->cr_owner->nh_home, pu->pu_etag), pu->pu_etag = NULL;
if (nua_client_restart(cr, 100, restarting))
return 0;
}
}
return nua_base_client_check_restart(cr, status, phrase, sip);
}
static int nua_publish_client_response(nua_client_request_t *cr,
int status, char const *phrase,
sip_t const *sip)
......@@ -364,15 +395,7 @@ static int nua_publish_client_response(nua_client_request_t *cr,
if (pu->pu_etag)
su_free(nh->nh_home, pu->pu_etag), pu->pu_etag = NULL;
if (status == 412) {
if (nua_client_restart(cr, 100, phrase))
return 0;
}
else if (status < 300) {
if (ex && ex->ex_delta == 0 &&
nua_client_restart(cr, 100, "Trying re-PUBLISH"))
return 0;
if (status < 300) {
pu->pu_published = 1;
pu->pu_etag = sip_etag_dup(nh->nh_home, sip->sip_etag);
......@@ -384,6 +407,8 @@ static int nua_publish_client_response(nua_client_request_t *cr,
else
SET_STATUS1(NUA_INTERNAL_ERROR);
}
else
nua_dialog_usage_set_refresh(du, ex->ex_delta);
}
}
......
......@@ -243,6 +243,8 @@ int accept_request(CONDITION_PARAMS)
return 0;
}
char const *test_etag = "tagtag";
int respond_with_etag(CONDITION_PARAMS)
{
msg_t *with = nua_current_request(nua);
......@@ -256,18 +258,18 @@ int respond_with_etag(CONDITION_PARAMS)
char const *etag;
case nua_i_publish:
etag = sip->sip_if_match ? sip->sip_if_match->g_value : NULL;
if (sip->sip_if_match && (etag == NULL || strcmp(etag, "tagtag"))) {
if (sip->sip_if_match && (etag == NULL || strcmp(etag, test_etag))) {
RESPOND(ep, call, nh, SIP_412_PRECONDITION_FAILED,
NUTAG_WITH(with),
TAG_END());
}
else {
RESPOND(ep, call, nh, SIP_200_OK,
NUTAG_WITH(with),
SIPTAG_ETAG_STR("tagtag"),
SIPTAG_EXPIRES_STR("3600"),
SIPTAG_EXPIRES(sip->sip_expires), /* overrides 3600 */
TAG_END());
RESPOND(ep, call, nh, SIP_200_OK,
NUTAG_WITH(with),
SIPTAG_ETAG_STR(test_etag),
SIPTAG_EXPIRES_STR("3600"),
SIPTAG_EXPIRES(sip->sip_expires), /* overrides 3600 */
TAG_END());
}
return 1;
default:
......@@ -410,7 +412,7 @@ int test_publish(struct context *ctx)
TEST(e->data->e_status, 200);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(sip->sip_etag);
TEST_S(sip->sip_etag->g_string, "tagtag");
TEST_S(sip->sip_etag->g_string, test_etag);
TEST_1(!e->next);
/*
......@@ -427,9 +429,8 @@ int test_publish(struct context *ctx)
if (!ctx->expensive && 0)
goto skip_republish;
run_ab_until(ctx, -1, save_until_final_response, -1, respond_with_etag);
run_ab_until(ctx, -1, save_until_final_response, -1, respond_with_etag);
/* Client events: nua_r_publish
*/
......@@ -437,8 +438,10 @@ int test_publish(struct context *ctx)
TEST(e->data->e_status, 200);
TEST_1(sip = sip_object(e->data->e_msg));
TEST_1(sip->sip_etag);
TEST_S(sip->sip_etag->g_string, "tagtag");
TEST_S(sip->sip_etag->g_string, test_etag);
TEST_1(!e->next);
free_events_in_list(ctx, a->events);
/*
Server events:
......@@ -454,6 +457,9 @@ int test_publish(struct context *ctx)
TEST_1(!sip->sip_payload);
TEST_1(!e->next);
free_events_in_list(ctx, b->events);
nua_handle_destroy(b_call->nh), b_call->nh = NULL;
skip_republish:
UNPUBLISH(a, a_call, a_call->nh, TAG_END());
......
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