added notify/terminate option

This commit is contained in:
Richard Aas 2011-12-15 13:00:20 +00:00
parent 4bfebde51b
commit adca48e7ee
3 changed files with 33 additions and 15 deletions

View file

@ -20,7 +20,11 @@ enum sipevent_subst {
};
enum sipevent_reason {
SIPEVENT_TIMEOUT = 0,
SIPEVENT_DEACTIVATED = 0,
SIPEVENT_PROBATION,
SIPEVENT_REJECTED,
SIPEVENT_TIMEOUT,
SIPEVENT_GIVEUP,
SIPEVENT_NORESOURCE,
};
@ -60,9 +64,10 @@ int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock,
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, ...);
int sipevent_notify(struct sipnot *not, struct mbuf *mb);
int sipevent_notifyf(struct sipnot *not, struct mbuf **mbp,
const char *fmt, ...);
int sipevent_notify(struct sipnot *not, struct mbuf *mb, bool term,
enum sipevent_reason reason);
int sipevent_notifyf(struct sipnot *not, struct mbuf **mbp, bool term,
enum sipevent_reason reason, const char *fmt, ...);
/* Subscriber */

View file

@ -78,7 +78,7 @@ const char *sipevent_substate_name(enum sipevent_subst state)
case SIPEVENT_ACTIVE: return "active";
case SIPEVENT_PENDING: return "pending";
case SIPEVENT_TERMINATED: return "terminated";
default: return "???";
default: return "unknown";
}
}
@ -87,8 +87,12 @@ const char *sipevent_reason_name(enum sipevent_reason reason)
{
switch (reason) {
case SIPEVENT_TIMEOUT: return "timeout";
case SIPEVENT_NORESOURCE: return "noresource";
default: return "???";
case SIPEVENT_DEACTIVATED: return "deactivated";
case SIPEVENT_PROBATION: return "probation";
case SIPEVENT_REJECTED: return "rejected";
case SIPEVENT_TIMEOUT: return "timeout";
case SIPEVENT_GIVEUP: return "giveup";
case SIPEVENT_NORESOURCE: return "noresource";
default: return "unknown";
}
}

View file

@ -400,20 +400,29 @@ int sipevent_accept(struct sipnot **notp, struct sipevent_sock *sock,
}
int sipevent_notify(struct sipnot *not, struct mbuf *mb)
int sipevent_notify(struct sipnot *not, struct mbuf *mb, bool term,
enum sipevent_reason reason)
{
if (!not || not->terminated)
return EINVAL;
mem_deref(not->mb);
not->mb = mem_ref(mb);
if (mb || !term) {
mem_deref(not->mb);
not->mb = mem_ref(mb);
}
if (term) {
tmr_cancel(&not->tmr);
(void)terminate(not, reason);
return 0;
}
return sipnot_notify(not);
}
int sipevent_notifyf(struct sipnot *not, struct mbuf **mbp,
const char *fmt, ...)
int sipevent_notifyf(struct sipnot *not, struct mbuf **mbp, bool term,
enum sipevent_reason reason, const char *fmt, ...)
{
struct mbuf *mb;
va_list ap;
@ -423,7 +432,7 @@ int sipevent_notifyf(struct sipnot *not, struct mbuf **mbp,
return EINVAL;
if (mbp && *mbp)
return sipevent_notify(not, *mbp);
return sipevent_notify(not, *mbp, term, reason);
mb = mbuf_alloc(1024);
if (!mb)
@ -437,7 +446,7 @@ int sipevent_notifyf(struct sipnot *not, struct mbuf **mbp,
mb->pos = 0;
err = sipevent_notify(not, mb);
err = sipevent_notify(not, mb, term, reason);
if (err)
goto out;