/* * Convert char* parameter to pdomain_t* pointer */ static int subscribe_fixup(void** param, int param_no) { pdomain_t* d; if (param_no == 1) { LOG(L_ERR, "subscribe_fixup: pdomain name is %s\n", (char*)*param); if (register_pdomain((char*)*param, &d) < 0) { LOG(L_ERR, "subscribe_fixup(): Error while registering domain\n"); return E_UNSPEC; } *param = (void*)d; } return 0; }
int fifo_pa_watcherinfo(FILE *fifo, char *response_file) { char pdomain_s[MAX_P_URI]; char p_uri_s[MAX_P_URI]; pdomain_t *pdomain = NULL; presentity_t *presentity = NULL; str pdomain_name, p_uri; if (!read_line(pdomain_s, MAX_PDOMAIN, fifo, &pdomain_name.len) || pdomain_name.len == 0) { fifo_reply(response_file, "400 pa_watcherinfo: pdomain expected\n"); LOG(L_ERR, "ERROR: pa_watcherinfo: 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_watcherinfo: p_uri expected\n"); LOG(L_ERR, "ERROR: pa_watcherinfo: p_uri expected\n"); return 1; } p_uri.s = p_uri_s; register_pdomain(pdomain_s, &pdomain); if (!pdomain) { fifo_reply(response_file, "400 could not register pdomain\n"); LOG(L_ERR, "ERROR: pa_watcherinfo: 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) { db_read_watcherinfo(presentity); } unlock_pdomain(pdomain); fifo_reply(response_file, "200 watcherinfo updated\n", "(%.*s)\n", p_uri.len, ZSW(p_uri.s)); return 1; }
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; }