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; }
static int publish(struct publisher *pub) { int err; const char *aor = ua_aor(pub->ua); struct mbuf *mb; mb = mbuf_alloc(1024); if (!mb) return ENOMEM; if (pub->expires && !pub->refresh) 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(ua_presence_status(pub->ua)), aor); else err = mbuf_printf(mb, ""); if (err) goto out; mb->pos = 0; /* XXX: can be simplified with 1 function call, by adding a print-handler that prints "SIP-If-Match: ETAG" */ if (pub->etag) err = sip_req_send(pub->ua, "PUBLISH", aor, pub->expires ? response_handler : NULL, pub, "%s" "Event: presence\r\n" "Expires: %u\r\n" "SIP-If-Match: %s\r\n" "Content-Length: %zu\r\n" "\r\n" "%b", pub->expires ? "Content-Type: application/pidf+xml\r\n" : "", pub->expires, pub->etag, mbuf_get_left(mb), mbuf_buf(mb), mbuf_get_left(mb)); else err = sip_req_send(pub->ua, "PUBLISH", aor, pub->expires ? response_handler : NULL, pub, "%s" "Event: presence\r\n" "Expires: %u\r\n" "Content-Length: %zu\r\n" "\r\n" "%b", pub->expires ? "Content-Type: application/pidf+xml\r\n" : "", pub->expires, mbuf_get_left(mb), mbuf_buf(mb), mbuf_get_left(mb)); if (err) { warning("publisher: send PUBLISH: (%m)\n", err); } out: mem_deref(mb); return err; }