eXosip使用实例 下载本文

内容发布更新时间 : 2024/12/25 12:41:06星期一 下面是文章的全部内容请认真阅读。

eXosip_lock(); eXosip_default_action(je); eXosip_unlock(); #else osip_message_t *reg_m = NULL; eXosip_event_t * je = NULL; if(eXosip_register_build_register(g_r_id,0,®_m) != 0) { printf(\ exit(1); } eXosip_register_send_register(g_r_id,reg_m); je = eXosip_event_wait(1,0); eXosip_lock(); eXosip_default_action(je); eXosip_unlock(); #endif return 0; }

int invite() { int i = 0,invite_flg = 0; osip_message_t * invite_m = NULL; osip_message_t * ack_m = NULL; eXosip_event_t * je = NULL; static char body[4096] = {0}; char dial[20] = {0}; char inv_from[50] = {0}; char inv_to[50] = {0}; printf(\ scanf(\ getchar(); sprintf(inv_from,\ sprintf(inv_to,\ i = eXosip_call_build_initial_invite(&invite_m,inv_to,inv_from,NULL,\is a call for conversation\ if(i != 0) {

printf(\ return -1; } memset(body,0,4096); snprintf(body,4096, \ \ \ \ \ \ \ \ \ \ localip,localip); g_body = body; osip_message_set_body(invite_m,body,strlen(body)); osip_message_set_content_type(invite_m,\ eXosip_lock(); eXosip_call_send_initial_invite(invite_m); //invite SIP INVITE message to send eXosip_unlock(); invite_flg = 1; while(invite_flg) {

printf(\ je = eXosip_event_wait(ring_timeout,0); printf(\ if(je != NULL) ;//printEventType(je); else { printf(\ return -2; } eXosip_lock(); eXosip_default_action(je); eXosip_automatic_refresh(); eXosip_unlock(); switch(je->type) {

case EXOSIP_CALL_INVITE: printf(\ break; case EXOSIP_CALL_PROCEEDING: //收到100try printf(\ break; case EXOSIP_CALL_RINGING: printf(\ break;

case EXOSIP_CALL_ANSWERED: printf(\ g_call_id = je->cid; g_dialog_id = je->did; eXosip_lock(); eXosip_call_build_ack(je->did,&ack_m); eXosip_call_send_ack(je->did,ack_m); eXosip_unlock(); invite_flg = 0; break; case EXOSIP_CALL_CLOSED: //a BYE was received for this call printf(\ break; case EXOSIP_CALL_ACK: printf(\ break;

default: printf(\ if(je->response && (je->response->status_code == 486)) { osip_header_t* retryafter = NULL; osip_message_get_retry_after(je->response, 0, &retryafter); printf(\ invite_flg = 0; //eXosip_event_free(je); } break; } //end switch

eXosip_event_free(je);

} //end while return 0; }

int bye() { int i = 0; eXosip_event_t * je = NULL; eXosip_lock(); i = eXosip_call_terminate(g_call_id,g_dialog_id); if(i < 0) { printf(\ } eXosip_unlock(); je = eXosip_event_wait(1,0); if(je != NULL) ;//printEventType(je); eXosip_lock(); eXosip_default_action(je); eXosip_unlock(); printf(\ return 0; }

int hold() { int invite_flg = 1; osip_message_t * invite_m = NULL; eXosip_event_t * je = NULL; osip_message_t * ack_m = NULL; static char body[4096] = {0}; if(eXosip_call_build_request(g_dialog_id, \ { printf(\ return -1; }

memset(body,0,4096); snprintf(body,4096, \ \ \ \ \ \在这里的port 12000不可以写为0,应该和初始invite的值一样。 //如果写为0,就会被eyebeam认为是一个新的呼叫。 //用xlite打eyebeam,然后hold,抓包看也是只有c行的ip为全0。port没有变 \ \ \ \ localip); osip_message_set_body(invite_m,body,strlen(body)); osip_message_set_content_type(invite_m,\ eXosip_lock(); eXosip_call_send_request(g_dialog_id, invite_m); eXosip_unlock(); while(invite_flg) {

printf(\ je = eXosip_event_wait(ring_timeout,0); printf(\ if(je != NULL) ;//printEventType(je); else { printf(\ return -2; } eXosip_lock(); eXosip_default_action(je); eXosip_automatic_refresh(); eXosip_unlock(); switch(je->type) {