int call_notify_sipfrag(struct call *call, uint16_t scode, const char *reason, ...) { struct mbuf *mb; va_list ap; int err; if (!call) return EINVAL; mb = mbuf_alloc(512); if (!mb) return ENOMEM; va_start(ap, reason); (void)mbuf_printf(mb, "SIP/2.0 %u %v\n", scode, reason, &ap); va_end(ap); mb->pos = 0; if (scode >= 200) { err = sipevent_notify(call->not, mb, SIPEVENT_TERMINATED, SIPEVENT_NORESOURCE, 0); call->not = mem_deref(call->not); } else { err = sipevent_notify(call->not, mb, SIPEVENT_ACTIVE, SIPEVENT_NORESOURCE, 0); } mem_deref(mb); return err; }
int sipevent_notifyf(struct sipnot *not, struct mbuf **mbp, enum sipevent_subst state, enum sipevent_reason reason, uint32_t retry_after, const char *fmt, ...) { struct mbuf *mb; va_list ap; int err; if (!not || not->terminated || !fmt) return EINVAL; if (mbp && *mbp) return sipevent_notify(not, *mbp, state, reason, retry_after); mb = mbuf_alloc(1024); if (!mb) return ENOMEM; va_start(ap, fmt); err = mbuf_vprintf(mb, fmt, ap); va_end(ap); if (err) goto out; mb->pos = 0; err = sipevent_notify(not, mb, state, reason, retry_after); if (err) goto out; out: if (err || !mbp) mem_deref(mb); else *mbp = mb; return err; }
static int notify(struct notifier *not, enum presence_status status) { const char *aor = ua_aor(not->ua); struct mbuf *mb; int err; mb = mbuf_alloc(1024); if (!mb) return ENOMEM; err = mbuf_printf(mb, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\r\n" "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\"\r\n" " xmlns:dm=\"urn:ietf:params:xml:ns:pidf:data-model\"\r\n" " xmlns:rpid=\"urn:ietf:params:xml:ns:pidf:rpid\"\r\n" " entity=\"%s\">\r\n" " <dm:person id=\"p4159\"><rpid:activities/></dm:person>\r\n" " <tuple id=\"t4109\">\r\n" " <status>\r\n" " <basic>%s</basic>\r\n" " </status>\r\n" " <contact>%s</contact>\r\n" " </tuple>\r\n" "</presence>\r\n" ,aor, presence_status_str(status), aor); if (err) goto out; mb->pos = 0; err = sipevent_notify(not->not, mb, SIPEVENT_ACTIVE, 0, 0); if (err) { warning("presence: notify to %s failed (%m)\n", aor, err); } out: mem_deref(mb); return err; }