void heap_init(align_t* memory, size_t length) { heap = to_header(memory); heap_size = length; init_element(heap, length, HT_FREE); free_list = heap; HEAP_VALIDATE; }
void SIPBuilder::CameraInfoAck(osip_message_t* msg, char** rtmsg, size_t* rtlen) { string head_line("SIP/2.0 200 OK\r\n"); osip_via_t *via; char* via_c = NULL; if( !osip_list_eol (&msg->vias, 0)) { via = (osip_via_t *) osip_list_get (&msg->vias, 0); osip_via_to_str( via, &via_c); }else{ return; } string via_header(via_c); via_header = string("Via: ")+via_header+string("\r\n"); char* from_tag_c; osip_from_to_str( msg->from, &from_tag_c ); string from_header(from_tag_c); from_header = string("From: ")+from_header+string("\r\n"); char* to_tag_c; osip_to_to_str( msg->to, &to_tag_c ); string to_header(to_tag_c); string to_tag_num = _RandomNum(); to_header = to_header + ";tag="+to_tag_num; to_header = string("To: ")+to_header+string("\r\n"); string call_id_num = string(msg->call_id->number); string call_header = string("Call-ID: ")+call_id_num+("\r\n"); string cseq_num = string(msg->cseq->number); string cseq_header = string("Cseq: ")+cseq_num+string(" MESSAGE\r\n"); string content_type_header = "Content-Type: APPLICATION/SDP\r\n"; string forwords = string("Max-Forwards: 70\r\n"); string expires = string("Expires: 3000\r\n"); string contentlenth = string("Content-Length: 0")+string("\r\n"); string cflr = string("\r\n"); string sip_msg_str = head_line + via_header + to_header + from_header + call_header + cseq_header + content_type_header + forwords + expires + contentlenth + cflr; #ifdef DEBUG cout<<"check 200ok camerainfoack:"<<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); *rtmsg = sip_msg_c; *rtlen = sip_len; /*send 200ok, wait ack*/ return; }
void SIPBuilder::BeenInvited( osip_message_t* msg, string port,char** rtmsg, size_t *rtlen, int*state, struct DialogInfo &dlg_info) { string uac_ip = _local_ip_str_; string uac_listen_port_str = _local_port_str_; string local_dev_name = _dev_name_; string head_line("SIP/2.0 200 OK\r\n"); osip_via_t *via; char* via_c = NULL; if( !osip_list_eol (&msg->vias, 0)) { via = (osip_via_t *) osip_list_get (&msg->vias, 0); osip_via_to_str( via, &via_c); }else{ *state = -1; return; } string via_header(via_c); via_header = string("Via: ")+via_header+string("\r\n"); char* from_tag_c; osip_from_to_str( msg->from, &from_tag_c ); string from_header(from_tag_c); from_header = string("From: ")+from_header+string("\r\n"); char* to_tag_c; osip_to_to_str( msg->to, &to_tag_c ); string to_header(to_tag_c); string to_tag_num = _RandomNum(); to_header = to_header + ";tag="+to_tag_num; to_header = string("To: ")+to_header+string("\r\n"); dlg_info.to_tag_num = to_tag_num; 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 call_id_num = string(msg->call_id->number); string call_header = string("Call-ID: ")+call_id_num+("\r\n"); string cseq_num = string(msg->cseq->number); string cseq_header = string("Cseq: ")+cseq_num+string(" INVITE\r\n"); string content_type_header = "Content-Type: APPLICATION/SDP\r\n"; string forwords = string("Max-Forwards: 70\r\n"); string expires = string("Expires: 3000\r\n"); string sdp_msg = _sdp_builder_.toString( string("##2015"), port); stringstream sdp_msg_length; sdp_msg_length<< sdp_msg.length(); string contentlenth = string("Content-Length: ")+sdp_msg_length.str()+string("\r\n"); string cflr = string("\r\n"); string sip_msg_str = head_line + via_header + to_header + from_header + call_header + cseq_header + contact_header + content_type_header + forwords + expires + contentlenth + cflr + sdp_msg; #ifdef DEBUG cout<<"check Been Invite:"<<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); *rtmsg = sip_msg_c; *rtlen = sip_len; /*send 200ok, wait ack*/ *state = 0; return; }
void SIPBuilder::InviteACK( osip_message_t* msg, char** rtmeg , size_t *rtlen, int* state) {//todo:小心内存泄漏 int pos = 0; string request_line = "ACK sip:"+ _dev_name_ + "@" + _local_ip_str_ + ":" + _local_port_str_ + " SIP/2.0" +"\r\n"; char* via_header_c; int ret = ::osip_via_to_str( (osip_via_t *) osip_list_get (&msg->vias, pos), &via_header_c); if( ret != 0 ) { #ifdef DEBUG cout<<"via to str error"<<endl; #endif *state = -1; return; } string via_header("Via: "); via_header = via_header + via_header_c + string("\r\n"); char* from_header_c; ret = ::osip_from_to_str( msg->from, &from_header_c); if( ret != 0 ) { #ifdef DEBUG cout<<"from to str error"<<endl; #endif *state = -1; return; } string from_header("From: "); from_header = from_header + from_header_c+ string("\r\n"); char* to_header_c; ret = ::osip_to_to_str( msg->to, &to_header_c); if( ret != 0 ) { #ifdef DEBUG cout<<"to to str error"<<endl; #endif *state = -1; return; } string to_header("To: "); to_header = to_header + to_header_c + string("\r\n"); char* callid_header_c; ret = ::osip_call_id_to_str( msg->call_id, &callid_header_c); if( ret != 0 ) { #ifdef DEBUG cout<<"to to str error"<<endl; #endif *state = -1; return; } string callid_header("Call-ID: "); callid_header = callid_header + callid_header_c + string("\r\n"); string contact_heaer = "Contact: <sip:"+ _dev_name_ + "@" + _local_ip_str_ + ":" + _local_port_str_ +">"+"\r\n"; string cseq_header ="CSeq: 20 ACK\r\n"; string forwords = string("Max-Forwards: 70\r\n"); string expires = string("Expires: 3000\r\n"); string cflr = string("\r\n"); string sip_msg_str = request_line + via_header + from_header + to_header + callid_header + contact_heaer + cseq_header + forwords + expires + cflr; 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; *state = 1; #ifdef DEBUG cout<<"invite ack meg'string :\n"<<*rtmeg << endl; #endif return; }