Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sofia-sip/sip_status.h>
- #include <sofia-sip/nua.h>
- su_root_t *root;
- nua_t * nua;
- void event_callback(nua_event_t event, int status, char const
- *phrase ,nua_t * nua,
- nua_magic_t * magic, nua_handle_t *nh,
- nua_hmagic_t *hmagic ,
- sip_t const *sip,tagi_t tags []) {
- printf("I have received an event %s status %d: %s\n", nua_event_name (event), status , phrase );
- switch(event) {
- case nua_i_invite:
- if (nh ==NULL)
- nh = nua_handle(nua,magic, TAG_END());
- printf(sip->sip_request->rq_method_name);
- nua_respond(nh,200,"OK",
- SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SOATAG_USER_SDP_STR("m=audio 1 RTP/AVP 0\n"
- "a=rtpmap:0 PCMU/8000"),
- TAG_END());
- break;
- case nua_i_register:
- if (nh ==NULL)
- nh = nua_handle(nua,magic, TAG_END());
- nua_respond(nh,200,"OK", NUTAG_WITH_THIS(nua) , TAG_END());
- break;
- case nua_i_state:
- if (nh ==NULL)
- nh = nua_handle(nua,magic, TAG_END());
- char const *l_sdp = NULL, *r_sdp = NULL;
- int audio = nua_active_inactive, video = nua_active_inactive, chat = nua_active_inactive;
- int offer_recv = 1, answer_recv = 1, offer_sent = 1, answer_sent = 1;
- int state = nua_callstate_init;
- tl_gets(tags, NUTAG_CALLSTATE_REF(state), TAG_END());
- printf("Call-State: '%s'\n", nua_callstate_name(state));
- break;
- case nua_i_bye:
- if (nh ==NULL)
- nh = nua_handle(nua, magic, TAG_END());
- nua_handle_destroy(nh);
- break;
- case nua_i_active:
- if (nh ==NULL)
- nh = nua_handle(nua, magic, TAG_END());
- break;
- default:
- ;
- };
- };
- void tests_event() {
- su_init();
- root = su_root_create(NULL);
- su_root_threading(root, 1);
- nua = nua_create(root,event_callback , NULL,
- NUTAG_URL("sip:0.0.0.0:5060"), TAG_END());
- nua_set_params(nua, NUTAG_ENABLEINVITE(1), NUTAG_ALLOW("REGISTER"),
- NUTAG_AUTOALERT(1), NUTAG_MEDIA_ENABLE(0), TAG_END());
- nua_handle_t *handle;
- handle = nua_handle (nua, NULL,
- SIPTAG_TO_STR ("sip:2@192.168.248.76:5060"),
- SIPTAG_FROM_STR ("sip:BOSS@192.168.248.154:5060"),
- SIPTAG_CONTACT_STR ("sip:BOSS@192.168.248.154:5060"),
- SIPTAG_CONTENT_TYPE_STR("application/sdp"),
- SOATAG_USER_SDP_STR("m=audio 5004 RTP/AVP 0 8"),
- TAG_END ());
- nua_invite (handle, NUTAG_ENABLEINVITE(1),
- NUTAG_AUTOALERT(1), NUTAG_AUTOACK(1), NUTAG_MEDIA_ENABLE(0),
- TAG_END());
- su_root_run(root);
- };
- void main(int argc, char *argv[]){
- tests_event();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement