Guest User

Untitled

a guest
Dec 28th, 2014
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #include <sofia-sip/sip_status.h>
  5. #include <sofia-sip/nua.h>
  6.  
  7. su_root_t *root;
  8. nua_t * nua;
  9.  
  10. void event_callback(nua_event_t event, int status, char const
  11.                     *phrase ,nua_t * nua,
  12.                     nua_magic_t * magic, nua_handle_t *nh,
  13.                     nua_hmagic_t *hmagic ,
  14.                     sip_t const *sip,tagi_t tags []) {
  15.     printf("I have received an event %s status %d: %s\n", nua_event_name (event), status , phrase );
  16.  
  17.     switch(event) {
  18.         case nua_i_invite:
  19.             if (nh ==NULL)
  20.                 nh = nua_handle(nua,magic, TAG_END());
  21.             printf(sip->sip_request->rq_method_name);
  22.            
  23.             // Здесь отправляю ответ на INVITE
  24.            
  25.             nua_respond(nh, SIP_200_OK,
  26.                         SIPTAG_CONTENT_TYPE_STR("application/sdp"),
  27.                         SIPTAG_PAYLOAD_STR("v=0\n"
  28.                             "o=LCR-Sofia-SIP 0 0 IN IP4 %s\n"
  29.                             "s=SIP Call\n"
  30.                             "c=IN IP4 %s\n"
  31.                             "t=0 0\n"
  32.                             "m=audio %d RTP/AVP %d\n"
  33.                             "a=rtpmap:%d %s/8000\n"),
  34.                         TAG_END());
  35.  
  36.             // ответ не уходит
  37.             // и в WireShark не отображается.
  38.             // Соответственно, ACK не проходит и по истечении времени
  39.             // вызов завершается.
  40.  
  41.             break;
  42.         case nua_i_register:
  43.             if (nh ==NULL)
  44.                 nh = nua_handle(nua,magic, TAG_END());
  45.             nua_respond(nh,200,"OK", NUTAG_WITH_THIS(nua) , TAG_END());
  46.             break;
  47.         case nua_i_state:
  48.             if (nh ==NULL)
  49.                 nh = nua_handle(nua,magic, TAG_END());
  50.             char const *l_sdp = NULL, *r_sdp = NULL;
  51.             int audio = nua_active_inactive, video = nua_active_inactive, chat = nua_active_inactive;
  52.  
  53.             int offer_recv = 1, answer_recv = 1, offer_sent = 1, answer_sent = 1;
  54.             int state = nua_callstate_init;
  55.        
  56.             tl_gets(tags, NUTAG_CALLSTATE_REF(state), TAG_END());
  57.             printf("Call-State: '%s'\n", nua_callstate_name(state));
  58.             break;
  59.         case nua_i_bye:
  60.             if (nh ==NULL)
  61.                 nh = nua_handle(nua, magic, TAG_END());
  62.             nua_handle_destroy(nh);
  63.             break;
  64.         case nua_i_active:
  65.             if (nh ==NULL)
  66.                 nh = nua_handle(nua, magic, TAG_END());
  67.             break;
  68.         default:
  69.         ;
  70.     };
  71. };
  72.  
  73. void tests_event() {
  74.     su_init();
  75.     root = su_root_create(NULL);
  76.     su_root_threading(root, 1);
  77.     nua = nua_create(root,event_callback , NULL,
  78.     NUTAG_URL("sip:0.0.0.0:5060"), TAG_END());
  79.    
  80.     nua_set_params(nua, NUTAG_ENABLEINVITE(1), NUTAG_ALLOW("REGISTER"),
  81.     NUTAG_AUTOALERT(1), NUTAG_AUTOACK(1), NUTAG_MEDIA_ENABLE(0), TAG_END());
  82.    
  83.     nua_handle_t *handle;
  84.     /*handle = nua_handle (nua, NULL,      
  85.             SIPTAG_TO_STR ("sip:[email protected]:5060"),
  86.             TAG_END ());
  87.        
  88.     /*nua_invite (handle,
  89.             NUTAG_AUTOACK(1),
  90.             NUTAG_MEDIA_ENABLE(0),
  91.             TAG_END());*/
  92.    
  93.     su_root_run(root);
  94. };
  95.  
  96. void main(int argc, char *argv[]){
  97.     tests_event();
  98. };
Advertisement
Add Comment
Please, Sign In to add comment