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; }
int fifo_pa_location_contact(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char p_contact_s[MAX_P_URI]; char location_s[MAX_LOCATION]; char priority_s[MAX_LOCATION]; char expires_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, p_contact, location, priority_str, expires_str; time_t expires; double priority; int changed = 0; char *msg = "no error"; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location_contact: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(p_contact_s, MAX_P_URI, fifo, &p_contact.len) || p_contact.len == 0) { fifo_reply(response_file, "400 pa_location_contact: p_contact expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: p_contact expected\n"); return 1; } p_contact.s = p_contact_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location_contact: location expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: location expected\n"); return 1; } location.s = location_s; if (!read_line(priority_s, MAX_LOCATION, fifo, &priority_str.len) || priority_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: priority expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: priority expected\n"); return 1; } priority = strtod(priority_s, NULL); if (!read_line(expires_s, MAX_LOCATION, fifo, &expires_str.len) || expires_str.len == 0) { fifo_reply(response_file, "400 pa_location_contact: expires expected\n"); LOG(L_ERR, "ERROR: pa_location_contact: expires expected\n"); return 1; } expires = strtoul(expires_s, NULL, 0); register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location_contact: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { msg = "400 could not find presentity\n"; LOG(L_ERR, "ERROR: pa_location_contact: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } find_presence_tuple(&p_contact, presentity, &tuple); if (!tuple && new_tuple_on_publish) { new_presence_tuple(&p_contact, expires, presentity, &tuple); add_presence_tuple(presentity, tuple); tuple->state = PS_ONLINE; changed = 1; } if (!tuple) { LOG(L_ERR, "publish_presentity: no tuple for %.*s\n", presentity->uri.len, presentity->uri.s); msg = "400 could not find presence tuple\n"; goto error; } changed = 1; if (1 || (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0)) { changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (tuple->priority != priority) { tuple->priority = priority; changed = 1; } if (expires < 7*24*3600) { /* must be seconds */ get_act_time(); expires = act_time + expires; } if (tuple->expires != expires) { tuple->expires = expires; changed = 1; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; error: unlock_pdomain(pdomain); fifo_reply(response_file, msg); return 1; }
int fifo_pa_location(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char location_s[MAX_LOCATION]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; presence_tuple_t *tuple = NULL; str pdomain_name, p_uri, location; int changed = 0; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_location: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_location: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 pa_location: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_location: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(location_s, MAX_LOCATION, fifo, &location.len) || location.len == 0) { fifo_reply(response_file, "400 pa_location: location expected\n"); LOG(L_ERR, "ERROR: pa_location: location expected\n"); return 1; } location.s = location_s; register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } lock_pdomain(pdomain); find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); changed = 1; } if (!presentity) { unlock_pdomain(pdomain); fifo_reply(response_file, "400 could not find presentity\n"); LOG(L_ERR, "ERROR: pa_location: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } changed = 1; for (tuple = presentity->tuples; tuple; tuple = tuple->next) { if (tuple->location.loc.len && str_strcasecmp(&tuple->location.room, &location) != 0) changed = 1; LOG(L_ERR, "Setting room of contact=%.*s to %.*s\n", tuple->contact.len, tuple->contact.s, tuple->location.room.len, tuple->location.room.s); strncpy(tuple->location.room.s, location.s, location.len); tuple->location.room.len = location.len; strncpy(tuple->location.loc.s, location.s, location.len); tuple->location.loc.len = location.len; } if (changed) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); unlock_pdomain(pdomain); fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), location.len, ZSW(location.s)); return 1; }
int fifo_pa_presence(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; char presence_s[MAX_PRESENCE]; // pdomain_t *pdomain = NULL; // presentity_t *presentity = NULL; str pdomain_name, p_uri, presence; // int origstate, newstate; // int allocated_presentity = 0; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 ul_add: pdomain expected\n"); LOG(L_ERR, "ERROR: ul_add: pdomain expected\n"); return 1; } pdomain_name.s = pdomain_s; if (!read_line(p_uri_s, MAX_P_URI, fifo, &p_uri.len) || p_uri.len == 0) { fifo_reply(response_file, "400 ul_add: p_uri expected\n"); LOG(L_ERR, "ERROR: ul_add: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; if (!read_line(presence_s, MAX_PRESENCE, fifo, &presence.len) || presence.len == 0) { fifo_reply(response_file, "400 ul_add: presence expected\n"); LOG(L_ERR, "ERROR: ul_add: presence expected\n"); return 1; } presence.s = presence_s; #if 0 register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_location: could not register pdomain %.*s\n", pdomain_name.len, pdomain_name.s); return 1; } find_presentity(pdomain, &p_uri, &presentity); if (!presentity) { new_presentity(pdomain, &p_uri, &presentity); add_presentity(pdomain, presentity); allocated_presentity = 1; } if (!presentity) { fifo_reply(response_file, "400 could not find presentity %s\n", p_uri_s); LOG(L_ERR, "ERROR: pa_location: could not find presentity %.*s\n", p_uri.len, p_uri.s); return 1; } origstate = presentity->state; presentity->state = newstate = (strcasecmp(presence_s, "online") == 0) ? PS_ONLINE : PS_OFFLINE; if (origstate != newstate || allocated_presentity) { presentity->flags |= PFLAG_PRESENCE_CHANGED; } db_update_presentity(presentity); #endif fifo_reply(response_file, "200 published\n", "(%.*s %.*s)\n", p_uri.len, ZSW(p_uri.s), presence.len, ZSW(presence.s)); return 1; }
/* * Create a new presentity and corresponding watcher list */ int create_presentity(struct sip_msg* _m, struct pdomain* _d, str* _puri, struct presentity** _p, struct watcher** _w) { time_t e; dlg_t* dialog; str watch_uri; str watch_dn; event_t *event = NULL; int et = 0; if (_m->event) { event = (event_t*)(_m->event->parsed); et = event->parsed; } else { et = EVENT_PRESENCE; } if (_m->expires) { e = ((exp_body_t*)_m->expires->parsed)->val; } else { e = default_expires; } if (e == 0) { *_p = 0; *_w = 0; DBG("create_presentity(): expires = 0\n"); return 0; } /* Convert to absolute time */ e += act_time; if (get_watch_uri(_m, &watch_uri, &watch_dn) < 0) { LOG(L_ERR, "create_presentity(): Error while extracting watcher URI\n"); return -1; } if (new_presentity(_d, _puri, _p) < 0) { LOG(L_ERR, "create_presentity(): Error while creating presentity\n"); return -2; } if (tmb.new_dlg_uas(_m, 200, &dialog) < 0) { paerrno = PA_DIALOG_ERR; LOG(L_ERR, "create_presentity(): Error while creating dialog state\n"); free_presentity(*_p); return -3; } if (et != EVENT_PRESENCE_WINFO) { if (add_watcher(*_p, &watch_uri, e, et, acc, dialog, &watch_dn, _w) < 0) { LOG(L_ERR, "create_presentity(): Error while adding a watcher\n"); tmb.free_dlg(dialog); free_presentity(*_p); return -4; } } else if (et == EVENT_PRESENCE_WINFO) { if (add_winfo_watcher(*_p, &watch_uri, e, et, acc, dialog, &watch_dn, _w) < 0) { LOG(L_ERR, "create_presentity(): Error while adding a winfo watcher\n"); tmb.free_dlg(dialog); free_presentity(*_p); return -5; } } add_presentity(_d, *_p); _d->reg(&watch_uri, _puri, (void*)callback, *_p); return 0; }