/* called upon incoming calls */ static void connect_handler(const struct sip_msg *msg, void *arg) { struct mbuf *mb; bool got_offer; int err; (void)arg; if (sess) { /* Already in a call */ (void)sip_treply(NULL, sip, msg, 486, "Busy Here"); return; } got_offer = (mbuf_get_left(msg->mb) > 0); /* Decode SDP offer if incoming INVITE contains SDP */ if (got_offer) { err = sdp_decode(sdp, msg->mb, true); if (err) { re_fprintf(stderr, "unable to decode SDP offer: %s\n", strerror(err)); goto out; } update_media(); } /* Encode SDP */ err = sdp_encode(&mb, sdp, !got_offer); if (err) { re_fprintf(stderr, "unable to encode SDP: %s\n", strerror(err)); goto out; } /* Answer incoming call */ err = sipsess_accept(&sess, sess_sock, msg, 200, "OK", name, "application/sdp", mb, auth_handler, NULL, false, offer_handler, answer_handler, establish_handler, NULL, NULL, close_handler, NULL, NULL); mem_deref(mb); /* free SDP buffer */ if (err) { re_fprintf(stderr, "session accept error: %s\n", strerror(err)); goto out; } out: if (err) { (void)sip_treply(NULL, sip, msg, 500, strerror(err)); } else { re_printf("accepting incoming call from <%r>\n", &msg->from.auri); } }
static void conn_handler(const struct sip_msg *msg, void *arg) { struct test *test = arg; int err; (void)arg; err = sipsess_accept(&test->b, test->sock, msg, 200, "OK", "b", "application/sdp", NULL, NULL, NULL, false, offer_handler, answer_handler, estab_handler_b, NULL, NULL, close_handler, test, NULL); if (err) { abort_test(test, err); } }
void tcsipcall_accept(struct tcsipcall*call) { int err; char *my_user; pl_strdup(&my_user, &call->local->uri.user); err = sipsess_accept(&call->sess, call->uac->sock, call->msg, 180, "Ringing", my_user, "application/sdp", NULL, NULL, call, false, offer_handler, answer_handler, establish_handler, NULL, NULL, close_handler, call, NULL); if(err) call->cstate |= CSTATE_ERR; mem_deref(my_user); }
int call_accept(struct call *call, struct sipsess_sock *sess_sock, const struct sip_msg *msg) { bool got_offer; int err; if (!call || !msg) return EINVAL; call->outgoing = false; got_offer = (mbuf_get_left(msg->mb) > 0); err = pl_strdup(&call->peer_uri, &msg->from.auri); if (err) return err; if (pl_isset(&msg->from.dname)) { err = pl_strdup(&call->peer_name, &msg->from.dname); if (err) return err; } if (got_offer) { struct sdp_media *m; const struct sa *raddr; err = sdp_decode(call->sdp, msg->mb, true); if (err) return err; call->got_offer = true; /* * Each media description in the SDP answer MUST * use the same network type as the corresponding * media description in the offer. * * See RFC 6157 */ m = stream_sdpmedia(audio_strm(call->audio)); raddr = sdp_media_raddr(m); if (sa_af(raddr) != call->af) { info("call: incompatible address-family" " (local=%s, remote=%s)\n", net_af2name(call->af), net_af2name(sa_af(raddr))); sip_treply(NULL, uag_sip(), msg, 488, "Not Acceptable Here"); call_event_handler(call, CALL_EVENT_CLOSED, "Wrong address family"); return 0; } /* Check if we have any common audio codecs, after * the SDP offer has been parsed */ if (!have_common_audio_codecs(call)) { info("call: no common audio codecs - rejected\n"); sip_treply(NULL, uag_sip(), msg, 488, "Not Acceptable Here"); call_event_handler(call, CALL_EVENT_CLOSED, "No audio codecs"); return 0; } } err = sipsess_accept(&call->sess, sess_sock, msg, 180, "Ringing", ua_cuser(call->ua), "application/sdp", NULL, auth_handler, call->acc, true, sipsess_offer_handler, sipsess_answer_handler, sipsess_estab_handler, sipsess_info_handler, sipsess_refer_handler, sipsess_close_handler, call, "Allow: %s\r\n", uag_allowed_methods()); if (err) { warning("call: sipsess_accept: %m\n", err); return err; } set_state(call, STATE_INCOMING); /* New call */ tmr_start(&call->tmr_inv, LOCAL_TIMEOUT*1000, invite_timeout, call); if (!call->acc->mnat) call_event_handler(call, CALL_EVENT_INCOMING, call->peer_uri); return err; }
int call_accept(struct call *call, struct sipsess_sock *sess_sock, const struct sip_msg *msg) { bool got_offer; int err; if (!call || !msg) return EINVAL; got_offer = (mbuf_get_left(msg->mb) > 0); err = pl_strdup(&call->peer_uri, &msg->from.auri); if (err) return err; if (pl_isset(&msg->from.dname)) { err = pl_strdup(&call->peer_name, &msg->from.dname); if (err) return err; } if (got_offer) { err = sdp_decode(call->sdp, msg->mb, true); if (err) return err; call->got_offer = true; /* Check if we have any common audio codecs, after * the SDP offer has been parsed */ if (!have_common_audio_codecs(call)) { info("call: no common audio codecs - rejected\n"); sip_treply(NULL, uag_sip(), msg, 488, "Not Acceptable Here"); call_event_handler(call, CALL_EVENT_CLOSED, "No audio codecs"); return 0; } } err = sipsess_accept(&call->sess, sess_sock, msg, 180, "Ringing", ua_cuser(call->ua), "application/sdp", NULL, auth_handler, call->acc, true, sipsess_offer_handler, sipsess_answer_handler, sipsess_estab_handler, sipsess_info_handler, sipsess_refer_handler, sipsess_close_handler, call, "Allow: %s\r\n", uag_allowed_methods()); if (err) { warning("call: sipsess_accept: %m\n", err); return err; } set_state(call, STATE_INCOMING); /* New call */ tmr_start(&call->tmr_inv, LOCAL_TIMEOUT*1000, invite_timeout, call); if (!call->acc->mnat) call_event_handler(call, CALL_EVENT_INCOMING, call->peer_uri); return err; }