propagate terminate substate

This commit is contained in:
Richard Aas 2011-12-19 07:30:33 +00:00
parent 91b33112e9
commit c1803bd705
6 changed files with 40 additions and 19 deletions

View file

@ -30,9 +30,9 @@ enum sipevent_reason {
struct sipevent_substate {
enum sipevent_subst state;
struct pl params;
enum sipevent_reason reason;
struct pl expires;
struct pl reason;
struct pl params;
};
int sipevent_event_decode(struct sipevent_event *se, const struct pl *pl);
@ -55,8 +55,6 @@ int sipevent_listen(struct sipevent_sock **sockp, struct sip *sip,
struct sipnot;
typedef void (sipevent_close_h)(int err, const struct sip_msg *msg, void *arg);
int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock,
const struct sip_msg *msg, struct sip_dialog *dlg,
const struct sipevent_event *event,
@ -64,7 +62,7 @@ int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock,
uint32_t expires_dfl, uint32_t expires_max,
const char *cuser, const char *ctype,
sip_auth_h *authh, void *aarg, bool aref,
sipevent_close_h *closeh, void *arg, const char *fmt, ...);
sip_resp_h *closeh, void *arg, const char *fmt, ...);
int sipevent_notify(struct sipnot *not, struct mbuf *mb,
enum sipevent_subst state, enum sipevent_reason reason,
uint32_t retry_after);
@ -81,6 +79,9 @@ typedef int (sipevent_fork_h)(struct sipsub **subp, struct sipsub *osub,
const struct sip_msg *msg, void *arg);
typedef void (sipevent_notify_h)(struct sip *sip, const struct sip_msg *msg,
void *arg);
typedef void (sipevent_close_h)(int err, const struct sip_msg *msg,
const struct sipevent_substate *substate,
void *arg);
int sipevent_subscribe(struct sipsub **subp, struct sipevent_sock *sock,
const char *uri, const char *from_name,

View file

@ -229,7 +229,7 @@ static void notify_handler(struct sipevent_sock *sock,
return;
if (!sub->terminated && state.state == SIPEVENT_TERMINATED)
sipsub_terminate(sub, 0, msg);
sipsub_terminate(sub, 0, msg, &state);
}

View file

@ -62,10 +62,26 @@ int sipevent_substate_decode(struct sipevent_substate *ss, const struct pl *pl)
else
ss->expires = pl_null;
if (!sip_param_decode(&ss->params, "reason", &param))
ss->reason = param;
else
ss->reason = pl_null;
if (!sip_param_decode(&ss->params, "reason", &param)) {
if (!pl_strcasecmp(&param, "deactivated"))
ss->reason = SIPEVENT_DEACTIVATED;
else if (!pl_strcasecmp(&param, "probation"))
ss->reason = SIPEVENT_PROBATION;
else if (!pl_strcasecmp(&param, "rejected"))
ss->reason = SIPEVENT_REJECTED;
else if (!pl_strcasecmp(&param, "timeout"))
ss->reason = SIPEVENT_TIMEOUT;
else if (!pl_strcasecmp(&param, "giveup"))
ss->reason = SIPEVENT_GIVEUP;
else if (!pl_strcasecmp(&param, "noresource"))
ss->reason = SIPEVENT_NORESOURCE;
else
ss->reason = -1;
}
else {
ss->reason = -1;
}
return 0;
}

View file

@ -59,7 +59,7 @@ static void destructor(void *arg)
if (!not->terminated) {
if (terminate(not, SIPEVENT_NORESOURCE))
if (terminate(not, SIPEVENT_DEACTIVATED))
return;
}
@ -82,7 +82,7 @@ static void sipnot_terminate(struct sipnot *not, int err,
const struct sip_msg *msg,
enum sipevent_reason reason)
{
sipevent_close_h *closeh;
sip_resp_h *closeh;
void *arg;
closeh = not->closeh;
@ -315,7 +315,7 @@ int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock,
uint32_t expires_dfl, uint32_t expires_max,
const char *cuser, const char *ctype,
sip_auth_h *authh, void *aarg, bool aref,
sipevent_close_h *closeh, void *arg, const char *fmt, ...)
sip_resp_h *closeh, void *arg, const char *fmt, ...)
{
struct sipnot *not;
uint32_t expires;

View file

@ -33,7 +33,7 @@ struct sipnot {
char *cuser;
char *hdrs;
char *ctype;
sipevent_close_h *closeh;
sip_resp_h *closeh;
void *arg;
uint32_t expires;
uint32_t expires_min;
@ -86,4 +86,5 @@ struct sipsub *sipsub_find(struct sipevent_sock *sock,
const struct sip_msg *msg,
const struct sipevent_event *evt, bool full);
void sipsub_reschedule(struct sipsub *sub, uint64_t wait);
void sipsub_terminate(struct sipsub *sub, int err, const struct sip_msg *msg);
void sipsub_terminate(struct sipsub *sub, int err, const struct sip_msg *msg,
const struct sipevent_substate *substate);

View file

@ -39,10 +39,12 @@ static void internal_notify_handler(struct sip *sip, const struct sip_msg *msg,
static void internal_close_handler(int err, const struct sip_msg *msg,
const struct sipevent_substate *substate,
void *arg)
{
(void)err;
(void)msg;
(void)substate;
(void)arg;
}
@ -108,7 +110,7 @@ static void tmr_handler(void *arg)
sipsub_reschedule(sub, RESUB_FAIL_WAIT);
}
else {
sipsub_terminate(sub, err, NULL);
sipsub_terminate(sub, err, NULL, NULL);
}
}
}
@ -122,7 +124,8 @@ void sipsub_reschedule(struct sipsub *sub, uint64_t wait)
}
void sipsub_terminate(struct sipsub *sub, int err, const struct sip_msg *msg)
void sipsub_terminate(struct sipsub *sub, int err, const struct sip_msg *msg,
const struct sipevent_substate *substate)
{
sipevent_close_h *closeh;
void *arg;
@ -133,7 +136,7 @@ void sipsub_terminate(struct sipsub *sub, int err, const struct sip_msg *msg)
tmr_cancel(&sub->tmr);
(void)terminate(sub);
closeh(err, msg, arg);
closeh(err, msg, substate, arg);
}
@ -271,7 +274,7 @@ static void response_handler(int err, const struct sip_msg *msg, void *arg)
if (sub->subscribed && ++sub->failc < RESUB_FAILC_MAX)
sipsub_reschedule(sub, RESUB_FAIL_WAIT);
else
sipsub_terminate(sub, err, msg);
sipsub_terminate(sub, err, msg, NULL);
}
}