📄 publish.c
字号:
static int publish_presentity_xcap_change(struct sip_msg* _m, struct pdomain* _d, struct presentity* presentity, int *pchanged){ char *body = get_body(_m); LOG(L_ERR, "publish_presentity_xcap_change: body=%p\n", body); if (body) { /* cheesy hack to see if it is presence-lists or watcherinfo that was changed */ if (strstr(body, "presence-lists")) presentity->flags |= PFLAG_PRESENCE_LISTS_CHANGED; if (strstr(body, "watcherinfo")) presentity->flags |= PFLAG_WATCHERINFO_CHANGED; presentity->flags |= PFLAG_XCAP_CHANGED; LOG(L_ERR, "publish_presentity_xcap_change: got body, setting flags=%x", presentity->flags); if (pchanged) *pchanged = 1; } return 0;}static int publish_presentity(struct sip_msg* _m, struct pdomain* _d, struct presentity* presentity, int *pchanged){ event_t *parsed_event = NULL; int event_package = EVENT_OTHER; if (_m->event) parsed_event = (event_t *)_m->event->parsed; if (parsed_event) event_package = parsed_event->parsed; if (event_package == EVENT_PRESENCE) { publish_presentity_pidf(_m, _d, presentity, pchanged); } else if (event_package == EVENT_XCAP_CHANGE) { publish_presentity_xcap_change(_m, _d, presentity, pchanged); } else { str callid = { 0, 0 }; if (_m->callid) callid = _m->callid->body; LOG(L_WARN, "publish_presentity: no handler for event_package=%d" " callid=%.*s\n", event_package, callid.len, callid.s); } LOG(L_INFO, "publish_presentity: event_package=%d -1-\n", event_package); return 0;}/* * 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; LOG(L_ERR, "handle_publish -1- _m=%p\n", _m); if (parse_publish_hfs(_m) < 0) { LOG(L_ERR, "handle_publish(): Error while parsing message header\n"); goto error; } LOG(L_ERR, "handle_publish -1b-\n");#if 0 if (check_message(_m) < 0) { LOG(L_ERR, "handle_publish(): Error while checking message\n"); goto error; } LOG(L_ERR, "handle_publish -1c-\n");#endif 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; } LOG(L_ERR, "handle_publish -2-\n"); 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;}/* * FIFO function for publishing events */int fifo_pa_publish(FILE *stream, char *response_file){ /* not yet implemented */ return -1;}/* * FIFO function for publishing presence * * :pa_presence: * pdomain (registrar or jabber) * presentity_uri * presentity_basic * */#define MAX_P_URI 128#define MAX_PRESENCE 256#define MAX_PDOMAIN 256int 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;}/* * FIFO function for publishing location * * :pa_presence_contact: * pdomain (registrar or jabber) * presentity_uri * presentity_contact * basic * status * priority * expires * */#define MAX_P_URI 128#define MAX_LOCATION 256#define MAX_PDOMAIN 256int fifo_pa_presence_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) { LOG(L_ERR, "publish_presentity: no tuple for contact %.*s\n", p_contact.len, p_contact.s); find_presence_tuple(&p_uri, presentity, &tuple); } if (!tuple && new_tuple_on_publish) { new_presence_tuple(&p_contact, expires, presentity, &tuple); add_presence_tuple(presentity, tuple); 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 (tuple->expires != expires) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -