int resource_subscriptions(subs_t* subs, xmlNodePtr rl_node) { char* uri= NULL; subs_info_t s; str wuri= {0, 0}; str did_str= {0, 0}; str *tmp_str; int cont_no= 0; static str ehdr= {SUBS_EXTRA_HDRS, SUBS_EXTRA_HDRS_LEN}; list_entry_t *rls_contact_list = NULL; list_entry_t *rls_subs_list = NULL; void* params[2] = {&s, &rls_contact_list}; /* if is initial send an initial Subscribe * else search in hash table for a previous subscription */ if(CONSTR_RLSUBS_DID(subs, &did_str)< 0) { LM_ERR("Failed to create did\n"); return -1; } memset(&s, 0, sizeof(subs_info_t)); if( uandd_to_uri(subs->from_user, subs->from_domain, &wuri)< 0) { LM_ERR("while constructing uri from user and domain\n"); goto error; } s.id= did_str; s.watcher_uri= &wuri; s.to_uri.s=0; s.contact= &server_address; s.event= get_event_flag(&subs->event->name); if(presence_server.s) s.outbound_proxy= &presence_server; if(s.event< 0) { LM_ERR("not recognized event\n"); goto error; } s.expires= subs->expires; s.source_flag= RLS_SUBSCRIBE; s.extra_headers= &ehdr; s.internal_update_flag = subs->internal_update_flag; if(process_list_and_exec(rl_node, subs->from_user, subs->from_domain, send_resource_subs, params, &cont_no) < 0) { LM_ERR("while processing list\n"); goto error; } LM_INFO("Subscription from %.*s for resource list uri %.*s expanded to" " %d contacts\n", wuri.len, wuri.s, subs->pres_uri.len, subs->pres_uri.s, cont_no); if (s.internal_update_flag) { s.internal_update_flag = 0; rls_subs_list = pua_get_subs_list(&did_str); while ((tmp_str = list_pop(&rls_contact_list)) != NULL) { rls_subs_list = list_remove(*tmp_str, rls_subs_list); pkg_free(tmp_str->s); pkg_free(tmp_str); } while ((tmp_str = list_pop(&rls_subs_list)) != NULL) { LM_DBG("Removing subscription for %.*s\n", tmp_str->len, tmp_str->s); s.expires = 0; send_resource_subs(tmp_str->s, params); pkg_free(tmp_str->s); pkg_free(tmp_str); } } if (rls_contact_list != NULL) { list_free(&rls_contact_list); } pkg_free(wuri.s); pkg_free(did_str.s); return 0; error: if(wuri.s) pkg_free(wuri.s); if(uri) xmlFree(uri); if(did_str.s) pkg_free(did_str.s); return -1; }
/** * send subscriptions to the list from XML node */ int resource_subscriptions(subs_t* subs, xmlNodePtr xmlnode) { subs_info_t s; str wuri= {0, 0}; str extra_headers; str did_str= {0, 0}; str *tmp_str; list_entry_t *rls_contact_list = NULL; list_entry_t *rls_subs_list = NULL; void* params[2] = {&s, &rls_contact_list}; /* if is initial send an initial Subscribe * else search in hash table for a previous subscription */ if(CONSTR_RLSUBS_DID(subs, &did_str)<0) { LM_ERR("cannot build rls subs did\n"); goto error; } memset(&s, 0, sizeof(subs_info_t)); if(uandd_to_uri(subs->watcher_user, subs->watcher_domain, &wuri)<0) { LM_ERR("while constructing uri from user and domain\n"); goto error; } s.id = did_str; s.watcher_uri = &wuri; s.contact = &rls_server_address; s.event = get_event_flag(&subs->event->name); if(s.event<0) { LM_ERR("not recognized event\n"); goto error; } s.expires = subs->expires; s.source_flag = RLS_SUBSCRIBE; if(rls_outbound_proxy.s) s.outbound_proxy = &rls_outbound_proxy; extra_headers.s = "Supported: eventlist\r\n" "Accept: application/pidf+xml, application/rlmi+xml," " application/watcherinfo+xml," " multipart/related\r\n"; extra_headers.len = strlen(extra_headers.s); s.extra_headers = &extra_headers; s.internal_update_flag = subs->internal_update_flag; counter = 0; if(process_list_and_exec(xmlnode, subs->watcher_user, subs->watcher_domain, send_resource_subs, params)<0) { LM_ERR("while processing list\n"); goto error; } if (rls_max_backend_subs > 0 && counter > rls_max_backend_subs) LM_WARN("%.*s has too many contacts. Max: %d, has: %d\n", wuri.len, wuri.s, rls_max_backend_subs, counter); if (s.internal_update_flag == INTERNAL_UPDATE_TRUE) { counter = 0; s.internal_update_flag = 0; rls_subs_list = pua_get_subs_list(&did_str); while ((tmp_str = list_pop(&rls_contact_list)) != NULL) { LM_DBG("Finding and removing %.*s from subscription list\n", tmp_str->len, tmp_str->s); rls_subs_list = list_remove(*tmp_str, rls_subs_list); pkg_free(tmp_str->s); pkg_free(tmp_str); } while ((tmp_str = list_pop(&rls_subs_list)) != NULL) { LM_DBG("Removing subscription for %.*s\n", tmp_str->len, tmp_str->s); s.expires = 0; send_resource_subs(tmp_str->s, params); pkg_free(tmp_str->s); pkg_free(tmp_str); } } if (rls_contact_list != NULL) list_free(&rls_contact_list); pkg_free(wuri.s); pkg_free(did_str.s); return 0; error: if(wuri.s) pkg_free(wuri.s); if(did_str.s) pkg_free(did_str.s); if(rls_contact_list) list_free(&rls_contact_list); return -1; }