int xj_jcon_del_jconf(xj_jcon jbc, str *sid, char dl, int flag) { xj_jconf jcf = NULL, p = NULL; if(!jbc || !sid || !sid->s || sid->len <= 0) return -1; #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_del_jconf: deleting conference of <%.*s>\n", sid->len, sid->s); #endif if((jcf = xj_jconf_new(sid))==NULL) return -1; if(xj_jconf_init_sip(jcf, jbc->jkey->id, dl)) { xj_jconf_free(jcf); return -1; } p = del234(jbc->jconf, (void*)jcf); if(p != NULL) { if(flag == XJ_JCMD_UNSUBSCRIBE) xj_jcon_jconf_presence(jbc, jcf, "unavailable", NULL); jbc->nrjconf--; xj_jconf_free(p); #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_del_jconf: conference deleted\n"); #endif } xj_jconf_free(jcf); return 0; }
xj_jconf xj_jcon_check_jconf(xj_jcon jbc, char* id) { str sid; xj_jconf jcf = NULL, p = NULL; if(!jbc || !id || !jbc->nrjconf) return NULL; #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_get_jconf: looking for conference\n"); #endif sid.s = id; sid.len = strlen(id); if((jcf = xj_jconf_new(&sid))==NULL) return NULL; if(xj_jconf_init_jab(jcf)) goto clean; if((p = find234(jbc->jconf, (void*)jcf, NULL)) != NULL) { #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_get_jconf: conference found\n"); #endif xj_jconf_free(jcf); return p; } clean: #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_get_jconf: conference not found\n"); #endif xj_jconf_free(jcf); return NULL; }
/** * check for expired connections */ void xj_worker_check_jcons(xj_wlist jwl, xj_jcon_pool jcp, int ltime, fd_set *pset) { int i; xj_jconf jcf; for(i = 0; i < jcp->len && main_loop; i++) { if(jcp->ojc[i] == NULL) continue; if(jcp->ojc[i]->jkey->flag==XJ_FLAG_OPEN && jcp->ojc[i]->expire > ltime) continue; #ifdef XJ_EXTRA_DEBUG DBG("XJAB:xj_worker:%d: connection expired for <%.*s> \n", _xj_pid, jcp->ojc[i]->jkey->id->len, jcp->ojc[i]->jkey->id->s); #endif xj_send_sip_msgz(_PADDR(jwl), jcp->ojc[i]->jkey->id, &jab_gw_name, XJ_DMSG_INF_JOFFLINE, NULL); #ifdef XJ_EXTRA_DEBUG DBG("XJAB:xj_worker:%d: connection's close flag =%d\n", _xj_pid, jcp->ojc[i]->jkey->flag); #endif // CLEAN JAB_WLIST xj_wlist_del(jwl, jcp->ojc[i]->jkey, _xj_pid); // looking for open conference rooms #ifdef XJ_EXTRA_DEBUG DBG("XJAB:xj_worker:%d: having %d open conferences\n", _xj_pid, jcp->ojc[i]->nrjconf); #endif while(jcp->ojc[i]->nrjconf > 0) { if((jcf=delpos234(jcp->ojc[i]->jconf,0))!=NULL) { // get out of room xj_jcon_jconf_presence(jcp->ojc[i],jcf, "unavailable", NULL); xj_jconf_free(jcf); } jcp->ojc[i]->nrjconf--; } // send offline presence to all subscribers if(jcp->ojc[i]->plist) { #ifdef XJ_EXTRA_DEBUG DBG("XJAB:xj_worker:%d: sending 'terminated' status to SIP" " subscriber\n", _xj_pid); #endif xj_pres_list_notifyall(jcp->ojc[i]->plist, XJ_PS_TERMINATED); } FD_CLR(jcp->ojc[i]->sock, pset); xj_jcon_disconnect(jcp->ojc[i]); xj_jcon_free(jcp->ojc[i]); jcp->ojc[i] = NULL; } }
xj_jconf xj_jcon_get_jconf(xj_jcon jbc, str* sid, char dl) { xj_jconf jcf = NULL, p; if(!jbc || !sid || !sid->s || sid->len <= 0) return NULL; #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_get_jconf: looking for conference\n"); #endif if((jcf = xj_jconf_new(sid))==NULL) return NULL; if(xj_jconf_init_sip(jcf, jbc->jkey->id, dl)) goto clean; if(jbc->nrjconf && (p = find234(jbc->jconf, (void*)jcf, NULL)) != NULL) { #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_get_jconf: conference found\n"); #endif xj_jconf_free(jcf); return p; } if(jbc->nrjconf >= XJ_MAX_JCONF) goto clean; if(jbc->nrjconf==0) if(jbc->jconf==NULL) if((jbc->jconf = newtree234(xj_jconf_cmp)) == NULL) goto clean; if((p = add234(jbc->jconf, (void*)jcf)) != NULL) { #ifdef XJ_EXTRA_DEBUG DBG("XJAB: xj_jcon_get_jconf: new conference created\n"); #endif jbc->nrjconf++; return p; } clean: DBG("XJAB: xj_jcon_get_jconf: error looking for conference\n"); xj_jconf_free(jcf); return NULL; }
/** * free the allocated memory space of a JABBER connection */ int xj_jcon_free(xj_jcon jbc) { xj_jconf jcf; if(jbc == NULL) return -1; #ifdef XJ_EXTRA_DEBUG DBG("XJAB:xj_jcon_free: -----START-----\n"); #endif //if(jbc->sock != -1) // jb_disconnect(jbc); if(jbc->hostname != NULL) _M_FREE(jbc->hostname); if(jbc->stream_id != NULL) _M_FREE(jbc->stream_id); if(jbc->resource != NULL) _M_FREE(jbc->resource); #ifdef XJ_EXTRA_DEBUG DBG("XJAB:xj_jcon_free: %d conferences\n", jbc->nrjconf); #endif while(jbc->nrjconf > 0) { if((jcf=delpos234(jbc->jconf,0))!=NULL) xj_jconf_free(jcf); jbc->nrjconf--; } xj_pres_list_free(jbc->plist); _M_FREE(jbc); #ifdef XJ_EXTRA_DEBUG DBG("XJAB:xj_jcon_free: -----END-----\n"); #endif return 0; }