void SIPCall::sendSIPInfo(const char *const body, const char *const subtype) { if (not inv or not inv->dlg) throw VoipLinkException("Couldn't get invite dialog"); pj_str_t methodName = CONST_PJ_STR("INFO"); pjsip_method method; pjsip_method_init_np(&method, &methodName); /* Create request message. */ pjsip_tx_data *tdata; if (pjsip_dlg_create_request(inv->dlg, &method, -1, &tdata) != PJ_SUCCESS) { RING_ERR("[call:%s] Could not create dialog", getCallId().c_str()); return; } /* Create "application/<subtype>" message body. */ pj_str_t content; pj_cstr(&content, body); const pj_str_t type = CONST_PJ_STR("application"); pj_str_t pj_subtype; pj_cstr(&pj_subtype, subtype); tdata->msg->body = pjsip_msg_body_create(tdata->pool, &type, &pj_subtype, &content); if (tdata->msg->body == NULL) pjsip_tx_data_dec_ref(tdata); else pjsip_dlg_send_request(inv->dlg, tdata, getSIPVoIPLink()->getModId(), NULL); }
void SIPPresence::fillDoc(pjsip_tx_data *tdata, const pres_msg_data *msg_data) { if (tdata->msg->type == PJSIP_REQUEST_MSG) { const pj_str_t STR_USER_AGENT = CONST_PJ_STR("User-Agent"); std::string useragent(acc_->getUserAgentName()); pj_str_t pJuseragent = pj_str((char*) useragent.c_str()); pjsip_hdr *h = (pjsip_hdr*) pjsip_generic_string_hdr_create(tdata->pool, &STR_USER_AGENT, &pJuseragent); pjsip_msg_add_hdr(tdata->msg, h); } if (msg_data == NULL) return; const pjsip_hdr *hdr; hdr = msg_data->hdr_list.next; while (hdr && hdr != &msg_data->hdr_list) { pjsip_hdr *new_hdr; new_hdr = (pjsip_hdr*) pjsip_hdr_clone(tdata->pool, hdr); DEBUG("adding header", new_hdr->name.ptr); pjsip_msg_add_hdr(tdata->msg, new_hdr); hdr = hdr->next; } if (msg_data->content_type.slen && msg_data->msg_body.slen) { pjsip_msg_body *body; const pj_str_t type = CONST_PJ_STR("application"); const pj_str_t subtype = CONST_PJ_STR("pidf+xml"); body = pjsip_msg_body_create(tdata->pool, &type, &subtype, &msg_data->msg_body); tdata->msg->body = body; } }
void SIPPresence::updateStatus(bool status, const std::string ¬e) { //char* pj_note = (char*) pj_pool_alloc(pool_, "50"); pjrpid_element rpid = { PJRPID_ELEMENT_TYPE_PERSON, CONST_PJ_STR("0"), PJRPID_ACTIVITY_UNKNOWN, pj_str((char *) note.c_str()) }; /* fill activity if user not available. */ if (note == "away") rpid.activity = PJRPID_ACTIVITY_AWAY; else if (note == "busy") rpid.activity = PJRPID_ACTIVITY_BUSY; /* else // TODO: is there any other possibilities DEBUG("Presence : no activity"); */ pj_bzero(&status_data_, sizeof(status_data_)); status_data_.info_cnt = 1; status_data_.info[0].basic_open = status; // at most we will have 3 digits + NULL termination char buf[4]; pj_utoa(rand() % 1000, buf); status_data_.info[0].id = pj_strdup3(pool_, buf); pj_memcpy(&status_data_.info[0].rpid, &rpid, sizeof(pjrpid_element)); /* "contact" field is optionnal */ }
/* Create client publish session */ pj_status_t SIPPresence::publish(SIPPresence *pres) { pj_status_t status; const pj_str_t STR_PRESENCE = CONST_PJ_STR("presence"); SIPAccount * acc = pres->getAccount(); pjsip_endpoint *endpt = ((SIPVoIPLink*) acc->getVoIPLink())->getEndpoint(); /* Create and init client publication session */ /* Create client publication */ status = pjsip_publishc_create(endpt, &my_publish_opt, pres, &publish_cb, &pres->publish_sess_); if (status != PJ_SUCCESS) { pres->publish_sess_ = NULL; ERROR("Failed to create a publish seesion."); return status; } /* Initialize client publication */ pj_str_t from = pj_strdup3(pres->pool_, acc->getFromUri().c_str()); status = pjsip_publishc_init(pres->publish_sess_, &STR_PRESENCE, &from, &from, &from, 0xFFFF); if (status != PJ_SUCCESS) { ERROR("Failed to init a publish session"); pres->publish_sess_ = NULL; return status; } /* Add credential for authentication */ if (acc->hasCredentials() and pjsip_publishc_set_credentials(pres->publish_sess_, acc->getCredentialCount(), acc->getCredInfo()) != PJ_SUCCESS) { ERROR("Could not initialize credentials for invite session authentication"); return status; } /* Set route-set */ // FIXME: is this really necessary? pjsip_regc *regc = acc->getRegistrationInfo(); if (regc and acc->hasServiceRoute()) pjsip_regc_set_route_set(regc, sip_utils::createRouteSet(acc->getServiceRoute(), pres->getPool())); /* Send initial PUBLISH request */ status = send_publish(pres); if (status != PJ_SUCCESS) return status; return PJ_SUCCESS; }