PJ_DECL(pj_status_t) csipsimple_init_acc_msg_data(pj_pool_t* pool, pjsua_acc_id acc_id, pjsua_msg_data* msg_data){ csipsimple_acc_config *additional_acc_cfg = NULL; // P-Asserted-Identity header pj_str_t hp_preferred_identity_name = { "P-Preferred-Identity", 20 }; // Sanity check PJ_ASSERT_RETURN(msg_data != NULL, PJ_EINVAL); // Get acc infos if(pjsua_acc_is_valid(acc_id)){ additional_acc_cfg = (csipsimple_acc_config *) pjsua_acc_get_user_data(acc_id); } // Process additionnal config for this account if(additional_acc_cfg != NULL){ if(additional_acc_cfg->p_preferred_identity.slen > 0){ // Create new P-Asserted-Identity hdr if necessary pjsip_generic_string_hdr* hdr = pjsip_generic_string_hdr_create(pool, &hp_preferred_identity_name, &additional_acc_cfg->p_preferred_identity); // Push it to msg data pj_list_push_back(&msg_data->hdr_list, hdr); } } return PJ_SUCCESS; }
// ZRTP and other media dispatcher pjmedia_transport* on_transport_created_wrapper(pjsua_call_id call_id, unsigned media_idx, pjmedia_transport *base_tp, unsigned flags) { pj_status_t status = PJ_SUCCESS; pjsua_call_info call_info; void* acc_user_data; int acc_use_zrtp = -1; // By default, use default global def pj_bool_t use_zrtp = css_var.default_use_zrtp; status = pjsua_call_get_info(call_id, &call_info); if(status == PJ_SUCCESS && pjsua_acc_is_valid (call_info.acc_id)){ acc_user_data = pjsua_acc_get_user_data(call_info.acc_id); if(acc_user_data != NULL){ acc_use_zrtp = ((csipsimple_acc_config *) acc_user_data)->use_zrtp; if(acc_use_zrtp >= 0){ use_zrtp = (acc_use_zrtp == 1) ? PJ_TRUE : PJ_FALSE; } } } #if defined(PJMEDIA_HAS_ZRTP) && PJMEDIA_HAS_ZRTP!=0 if(use_zrtp){ PJ_LOG(4, (THIS_FILE, "Dispatch transport creation on ZRTP one")); return on_zrtp_transport_created(call_id, media_idx, base_tp, flags); } #endif return base_tp; }
//---------------------------------------------------------------------- void SipPhone::unregister() { LogInfo info(LogInfo::STATUS_MESSAGE, "pjsip", 0, "Unregister account"); signalLogData(info); if (pjsua_acc_is_valid(acc_id_)) { hangUpAll(); pjsua_acc_del(acc_id_); } }
BlabbleAccountPtr PjsuaManager::FindAcc(int acc_id) { if (pjsua_acc_is_valid(acc_id) == PJ_TRUE) { BlabbleAccountMap::iterator it = accounts_.find(acc_id); if (it != accounts_.end()) { return it->second; } } return BlabbleAccountPtr(); }
//---------------------------------------------------------------------- void SipPhone::getAccountInfo(QVariantMap &account_info) { if (!pjsua_acc_is_valid(acc_id_)) { LogInfo info(LogInfo::STATUS_WARNING, "pjsip", 0, "There is no active account"); signalLogData(info); return; } pjsua_acc_info ai; pjsua_acc_get_info(acc_id_, &ai); account_info.insert("address", Qt::escape(ai.acc_uri.ptr)); account_info.insert("status", Qt::escape(ai.status_text.ptr)); account_info.insert("online_status", Qt::escape(ai.online_status_text.ptr)); }
bool SelectSIPAccount(CString number, pjsua_acc_id &acc_id, pj_str_t &pj_uri) { SIPURI sipuri; ParseSIPURI(number, &sipuri); if (pjsua_acc_is_valid(account) && pjsua_acc_is_valid(account_local)) { acc_id = account; if (accountSettings.account.domain != sipuri.domain) { int pos = sipuri.domain.Find(_T(":")); CString domainWithoutPort = RemovePort(sipuri.domain); if (domainWithoutPort.CompareNoCase(_T("localhost"))==0 || IsIP(domainWithoutPort)) { acc_id = account_local; } } } else if (pjsua_acc_is_valid(account)) { acc_id = account; } else if (pjsua_acc_is_valid(account_local)) { acc_id = account_local; } else { return false; } pj_uri = StrToPjStr ( GetSIPURI(number, acc_id == account_local, acc_id == account_local) ); return true; }
static void ui_cycle_account() { int i; char buf[128]; if (!simple_input("Enter account ID to select", buf, sizeof(buf))) return; i = my_atoi(buf); if (pjsua_acc_is_valid(i)) { pjsua_acc_set_default(i); PJ_LOG(3,(THIS_FILE, "Current account changed to %d", i)); } else { PJ_LOG(3,(THIS_FILE, "Invalid account id %d", i)); } }
static void ui_delete_account() { char buf[128]; int i; if (!simple_input("Enter account ID to delete", buf, sizeof(buf))) return; i = my_atoi(buf); if (!pjsua_acc_is_valid(i)) { printf("Invalid account id %d\n", i); } else { pjsua_acc_del(i); printf("Account %d deleted\n", i); } }
//---------------------------------------------------------------------- int SipPhone::registerUser(const Account &acc) { QString user = acc.getUserName(); QString password = acc.getPassword(); QString domain = acc.getHost(); if (pjsua_acc_is_valid(acc_id_)) { LogInfo info(LogInfo::STATUS_WARNING, "pjsip", 0, "Account already exists"); signalLogData(info); return -1; } /* Register to SIP server by creating SIP account. */ pjsua_acc_config cfg; pjsua_acc_config_default(&cfg); QString id = "sip:"; id.append(user); id.append("@"); id.append(domain); QString reg_uri = "sip:"; reg_uri.append(domain); char ch_id[150]; char ch_reg_uri[100]; char ch_user[100]; char ch_password[100]; if (id.size() > 149 || reg_uri.size() > 99 || user.size() > 99 || password.size() > 99) { LogInfo info(LogInfo::STATUS_ERROR, "pjsip", 0, "Error adding account, data too long"); signalLogData(info); return -1; } strcpy(ch_id, id.toLocal8Bit().data()); ch_id[id.size()] = 0; strcpy(ch_reg_uri, reg_uri.toLocal8Bit().data()); ch_reg_uri[reg_uri.size()] = 0; strcpy(ch_user, user.toLocal8Bit().data()); ch_user[user.size()] = 0; strcpy(ch_password, password.toLocal8Bit().data()); ch_password[password.size()] = 0; cfg.id = pj_str(ch_id); cfg.reg_uri = pj_str(ch_reg_uri); cfg.cred_count = 1; cfg.cred_info[0].realm = pj_str((char*)"*"); cfg.cred_info[0].scheme = pj_str((char*)"digest"); cfg.cred_info[0].username = pj_str(ch_user); cfg.cred_info[0].data_type = 0; cfg.cred_info[0].data = pj_str(ch_password); pj_status_t status = pjsua_acc_add(&cfg, PJ_TRUE, &acc_id_); if (status != PJ_SUCCESS) { LogInfo info(LogInfo::STATUS_ERROR, "pjsip", status, "Error adding account"); signalLogData(info); return -1; } LogInfo info(LogInfo::STATUS_MESSAGE, "pjsip", 0, "Registered user with account-id " + QString::number(acc_id_)); signalLogData(info); return acc_id_; }
//---------------------------------------------------------------------- bool SipPhone::checkAccountStatus() { return pjsua_acc_is_valid(acc_id_); }