/* * Handle a publish Request */ int handle_publish(struct sip_msg* _m, char* _domain, char* _s2) { struct pdomain* d; struct presentity *p; str p_uri = { NULL, 0 }; int changed; get_act_time(); paerrno = PA_OK; if (parse_hfs(_m) < 0) { LOG(L_ERR, "handle_publish(): Error while parsing message header\n"); goto error; } if (check_message(_m) < 0) { LOG(L_ERR, "handle_publish(): Error while checking message\n"); goto error; } d = (struct pdomain*)_domain; if (get_pres_uri(_m, &p_uri) < 0 || p_uri.s == NULL || p_uri.len == 0) { LOG(L_ERR, "handle_publish(): Error while extracting presentity URI\n"); goto error; } lock_pdomain(d); LOG(L_ERR, "handle_publish -4- p_uri=%*.s p_uri.len=%d\n", p_uri.len, p_uri.s, p_uri.len); if (find_presentity(d, &p_uri, &p) > 0) { changed = 1; if (create_presentity_only(_m, d, &p_uri, &p) < 0) { goto error2; } } /* update presentity event state */ LOG(L_ERR, "handle_publish -5- presentity=%p\n", p); if (p) publish_presentity(_m, d, p, &changed); unlock_pdomain(d); if (send_reply(_m) < 0) return -1; LOG(L_ERR, "handle_publish -8- paerrno=%d\n", paerrno); return 1; error2: unlock_pdomain(d); error: send_reply(_m); return 0; }
int handle_publish(struct sip_msg* _m, char* _domain, char* _s2) { struct pdomain* d; struct presentity *p; str p_uri = STR_NULL; str uid = STR_NULL; xcap_query_params_t xcap_params; get_act_time(); paerrno = PA_OK; if (parse_publish_hfs(_m) < 0) { LOG(L_ERR, "handle_publish(): Error while parsing message header\n"); goto error; } d = (struct pdomain*)_domain; if (get_pres_uri(_m, &p_uri) < 0 || p_uri.s == NULL || p_uri.len == 0) { LOG(L_ERR, "handle_publish(): Error while extracting presentity URI\n"); goto error; } if (get_presentity_uid(&uid, _m) < 0) { ERR("Error while extracting presentity UID\n"); goto error; } lock_pdomain(d); if (find_presentity_uid(d, &uid, &p) > 0) { memset(&xcap_params, 0, sizeof(xcap_params)); if (fill_xcap_params) fill_xcap_params(_m, &xcap_params); if (new_presentity(d, &p_uri, &uid, &xcap_params, &p) < 0) { LOG(L_ERR, "handle_publish can't create presentity\n"); goto error2; } } /* update presentity event state */ if (p) publish_presentity(_m, d, p); unlock_pdomain(d); if (send_reply(_m) < 0) return -1; return 1; error2: unlock_pdomain(d); error: send_reply(_m); return 0; }
/* * Returns 1 if subscription exists and -1 if not */ int existing_subscription(struct sip_msg* _m, char* _domain, char* _s2) { struct pdomain* d; struct presentity* p; struct watcher* w; str p_uri, w_uri; str w_dn; int et = 0; if (_m->event) { event_t *event = (event_t*)(_m->event->parsed); et = event->parsed; } else { LOG(L_ERR, "existing_subscription defaulting to EVENT_PRESENCE\n"); et = EVENT_PRESENCE; } paerrno = PA_OK; if (parse_from_header(_m) < 0) { paerrno = PA_PARSE_ERR; LOG(L_ERR, "existing_subscription(): Error while parsing From header field\n"); goto error; } d = (struct pdomain*)_domain; if (get_pres_uri(_m, &p_uri) < 0) { LOG(L_ERR, "existing_subscription(): Error while extracting presentity URI\n"); goto error; } if (get_watch_uri(_m, &w_uri, &w_dn) < 0) { LOG(L_ERR, "existing_subscription(): Error while extracting watcher URI\n"); goto error; } lock_pdomain(d); if (find_presentity(d, &p_uri, &p) == 0) { if (find_watcher(p, &w_uri, et, &w) == 0) { LOG(L_ERR, "existing_subscription() found watcher\n"); unlock_pdomain(d); return 1; } } unlock_pdomain(d); return -1; error: send_reply(_m); return 0; }
/* * Handle a subscribe Request */ int handle_subscription(struct sip_msg* _m, char* _domain, char* _s2) { struct pdomain* d; struct presentity *p; struct watcher* w; str p_uri; LOG(L_ERR, "handle_subscription() entered\n"); get_act_time(); paerrno = PA_OK; if (parse_hfs(_m, 1) < 0) { LOG(L_ERR, "handle_subscription(): Error while parsing message header\n"); goto error; } if (check_message(_m) < 0) { LOG(L_ERR, "handle_subscription(): Error while checking message\n"); goto error; } d = (struct pdomain*)_domain; if (get_pres_uri(_m, &p_uri) < 0) { LOG(L_ERR, "handle_subscription(): Error while extracting presentity URI\n"); goto error; } lock_pdomain(d); if (find_presentity(d, &p_uri, &p) > 0) { if (create_presentity(_m, d, &p_uri, &p, &w) < 0) { LOG(L_ERR, "handle_subscription(): Error while creating new presentity\n"); goto error2; } } else { if (update_presentity(_m, d, p, &w) < 0) { LOG(L_ERR, "handle_subscription(): Error while updating presentity\n"); goto error2; } } if (send_reply(_m) < 0) { LOG(L_ERR, "handle_subscription(): Error while sending reply\n"); goto error2; } if (p) { p->flags |= PFLAG_WATCHERINFO_CHANGED; } if (w) { w->flags |= WFLAG_SUBSCRIPTION_CHANGED; } LOG(L_ERR, "handle_subscription about to return 1: w->event_package=%d w->accept=%d p->flags=%x w->flags=%x w=%p\n", (w ? w->event_package : -1), (w ? w->accept : -1), (p ? p->flags : -1), (w ? w->flags : -1), w); unlock_pdomain(d); return 1; error2: LOG(L_ERR, "handle_subscription about to return -1\n"); unlock_pdomain(d); return -1; error: LOG(L_ERR, "handle_subscription about to send_reply and return -2\n"); send_reply(_m); return -1; }