Advertisement
Guest User

Untitled

a guest
Dec 27th, 2014
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.49 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.             nua_respond(nh,200,"OK",
  23.             SIPTAG_CONTENT_TYPE_STR("application/sdp"),
  24.             SOATAG_USER_SDP_STR("m=audio 1 RTP/AVP 0\n"
  25.                         "a=rtpmap:0 PCMU/8000"),
  26.             TAG_END());
  27.             break;
  28.         case nua_i_register:
  29.             if (nh ==NULL)
  30.                 nh = nua_handle(nua,magic, TAG_END());
  31.             nua_respond(nh,200,"OK", NUTAG_WITH_THIS(nua) , TAG_END());
  32.             break;
  33.         case nua_i_state:
  34.             if (nh ==NULL)
  35.                 nh = nua_handle(nua,magic, TAG_END());
  36.             char const *l_sdp = NULL, *r_sdp = NULL;
  37.             int audio = nua_active_inactive, video = nua_active_inactive, chat = nua_active_inactive;
  38.  
  39.             int offer_recv = 1, answer_recv = 1, offer_sent = 1, answer_sent = 1;
  40.             int state = nua_callstate_init;
  41.        
  42.             tl_gets(tags, NUTAG_CALLSTATE_REF(state), TAG_END());
  43.             printf("Call-State: '%s'\n", nua_callstate_name(state));
  44.             break;
  45.         case nua_i_bye:
  46.             if (nh ==NULL)
  47.                 nh = nua_handle(nua, magic, TAG_END());
  48.             nua_handle_destroy(nh);
  49.             break;
  50.         case nua_i_active:
  51.             if (nh ==NULL)
  52.                 nh = nua_handle(nua, magic, TAG_END());
  53.             break;
  54.         default:
  55.         ;
  56.     };
  57. };
  58.  
  59. void tests_event() {
  60.     su_init();
  61.     root = su_root_create(NULL);
  62.     su_root_threading(root, 1);
  63.     nua = nua_create(root,event_callback , NULL,
  64.     NUTAG_URL("sip:0.0.0.0:5060"), TAG_END());
  65.    
  66.     nua_set_params(nua, NUTAG_ENABLEINVITE(1), NUTAG_ALLOW("REGISTER"),
  67.     NUTAG_AUTOALERT(1), NUTAG_MEDIA_ENABLE(0), TAG_END());
  68.    
  69.     nua_handle_t *handle;
  70.     handle = nua_handle (nua, NULL,        
  71.             SIPTAG_TO_STR ("sip:2@192.168.248.76:5060"),
  72.             SIPTAG_FROM_STR ("sip:BOSS@192.168.248.154:5060"),
  73.             SIPTAG_CONTACT_STR ("sip:BOSS@192.168.248.154:5060"),
  74.             SIPTAG_CONTENT_TYPE_STR("application/sdp"),
  75.             SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
  76.             TAG_END ());
  77.        
  78.     nua_invite (handle, NUTAG_ENABLEINVITE(1),
  79.     NUTAG_AUTOALERT(1), NUTAG_AUTOACK(1), NUTAG_MEDIA_ENABLE(0),
  80.     TAG_END());
  81.    
  82.     su_root_run(root);
  83. };
  84.  
  85. void main(int argc, char *argv[]){
  86.     tests_event();
  87. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement