csQuaternion csQuaternion::SLerp (const csQuaternion& q2, float t) const { float omega, cosom, invsinom, scale0, scale1; csQuaternion quato(q2); // decide if one of the quaternions is backwards float a = (*this-q2).SquaredNorm (); float b = (*this+q2).SquaredNorm (); if (a > b) { quato = -q2; } // Calculate dot between quats cosom = Dot (quato); // Make sure the two quaternions are not exactly opposite? (within a little // slop). if (cosom > -0.9998f) { // Are they more than a little bit different? Avoid a divided by zero // and lerp if not. if (cosom < 0.9998f) { // Yes, do a slerp omega = acosf (cosom); invsinom = 1.0f / sinf (omega); scale0 = sinf ((1.0f - t) * omega) * invsinom; scale1 = sinf (t * omega) * invsinom; } else { // Not a very big difference, do a lerp scale0 = 1.0f - t; scale1 = t; } return csQuaternion ( scale0 * v.x + scale1 * quato.v.x, scale0 * v.y + scale1 * quato.v.y, scale0 * v.z + scale1 * quato.v.z, scale0 * w + scale1 * quato.w); } // The quaternions are nearly opposite so to avoid a divided by zero error // Calculate a perpendicular quaternion and slerp that direction scale0 = sin ((1.0f - t) * PI); scale1 = sin (t * PI); return csQuaternion ( scale0 * v.x + scale1 * -quato.v.y, scale0 * v.y + scale1 * quato.v.x, scale0 * v.z + scale1 * -quato.w, scale0 * w + scale1 * quato.v.z); }
void SIPBuilder::AuRegister( osip_message_t* msg, char** rtmeg, size_t* rtlen, std::string &via_branch_num, struct DialogInfo dlg_info, struct ReAuthInfo re_au) { string uas_ip = re_au.uas_ip; string uas_listen_port_str = re_au.uas_port_str; string local_dev_passwd_str = re_au.passwd; string remote_dev_name = re_au.remote_dev_name; string from_tag_num = dlg_info.from_tag_num; string call_id_num = dlg_info.call_id_num; int pos = 0; string realm; string nonce; if( NULL != msg) { while (!osip_list_eol (&msg->www_authenticates, pos)) { osip_www_authenticate_t* auth; auth = (osip_www_authenticate_t *) osip_list_get (&msg->www_authenticates, pos); realm = string(auth->realm); nonce = string(auth->nonce); break; } } string quato("\""); string uac_ip = _local_ip_str_; string uac_listen_port_str = _local_port_str_; string local_dev_name = _dev_name_; string protocol = "UDP"; string request_line; stringstream request_stream; request_stream<<"REGISTER sip:"<< remote_dev_name<<"@"<< uas_ip<<":"<< uas_listen_port_str<<" SIP/2.0\r\n"; request_line = request_stream.str(); string via_header; string randnum = _RandomNum(); via_branch_num = randnum; via_header = "Via: SIP/2.0/"+protocol+" "+uac_ip+":"+uac_listen_port_str+";rport;branch=z9hG4bK"+randnum+"\r\n"; string to_header; stringstream stream_to_header; stream_to_header << "To: <sip:" << local_dev_name << "@" << uac_ip << ":" << uac_listen_port_str<<">\r\n"; to_header = stream_to_header.str(); string from_header; string from_tag = string("tag=") + from_tag_num; stringstream stream_from_header; stream_from_header<< "From: <sip:"<< local_dev_name <<"@"<<uac_ip << ":" << uac_listen_port_str<<">;"<< from_tag<<"\r\n"; from_header = stream_from_header.str(); string call_id_header = string("Call-ID: " + call_id_num + "\r\n"); string cseq_header = string("CSeq: 2 REGISTER\r\n"); string contact_header; stringstream stream_contact_header; stream_contact_header<<"Contact: <sip:" << local_dev_name << "@" << uac_ip << ":"<< uac_listen_port_str<<">\r\n"; contact_header = stream_contact_header.str(); string uri = quato +"sip:" + remote_dev_name+ "@"+ uas_ip+":"+uas_listen_port_str + quato; string response = _RegisterMd5( local_dev_name, realm, local_dev_passwd_str, uri, nonce); string au_header; au_header = "Authorization: Digest username="******",realm="+ realm +",nonce=" + nonce + ",uri=" + uri + ",response="+ quato + response + quato+",algorithm=MD5\r\n"; string forwords = string("Max-Forwards: 70\r\n"); string expires = string("Expires: 3600\r\n"); string contentlenth = string("Content-Length: 0\r\n"); string cflr = string("\r\n"); string sip_msg_str = request_line + via_header + to_header + from_header + call_id_header + cseq_header + contact_header +au_header + forwords + expires + contentlenth + cflr; #ifdef DEBUG cout<<"check Re Au:"<<endl; cout<<sip_msg_str<<endl; #endif size_t sip_len = sip_msg_str.length(); char* sip_msg_c = (char*)malloc(sizeof(char)* sip_len); memcpy( sip_msg_c, sip_msg_str.c_str(), sip_len); *rtmeg = sip_msg_c; *rtlen = sip_len; return; }