[asterisk-commits] file: branch group/pimp_my_sip r379224 - /team/group/pimp_my_sip/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jan 16 10:59:54 CST 2013
Author: file
Date: Wed Jan 16 10:59:50 2013
New Revision: 379224
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379224
Log:
Add a supplement which reacts to new sessions by creating an Asterisk channel and sending it into the dialplan.
Modified:
team/group/pimp_my_sip/channels/chan_gulp.c
Modified: team/group/pimp_my_sip/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/channels/chan_gulp.c?view=diff&rev=379224&r1=379223&r2=379224
==============================================================================
--- team/group/pimp_my_sip/channels/chan_gulp.c (original)
+++ team/group/pimp_my_sip/channels/chan_gulp.c Wed Jan 16 10:59:50 2013
@@ -100,6 +100,14 @@
.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER
};
+/*! \brief SIP session interaction functions */
+static int gulp_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata);
+
+/*! \brief SIP session supplement structure */
+static struct ast_sip_session_supplement gulp_supplement = {
+ .incoming_request = gulp_incoming_request,
+};
+
/*! \brief Function called by RTP engine to get local RTP peer */
static enum ast_rtp_glue_result gulp_get_rtp_peer(struct ast_channel *chan, struct ast_rtp_instance **instance)
{
@@ -124,6 +132,32 @@
.get_codec = gulp_get_codec,
.update_peer = gulp_set_rtp_peer,
};
+
+/*! \brief Function called to create a new Gulp Asterisk channel */
+static struct ast_channel *gulp_new(struct ast_sip_session *session, int state, const char *exten, const char *title, const char *linkedid, const char *cid_name)
+{
+ struct ast_channel *chan;
+
+ /* TODO: Fix channel name generation */
+ if (!(chan = ast_channel_alloc(1, state, "", S_OR(cid_name, ""), "", "", "", linkedid, 0, "Gulp/%04lx", ast_random() & 0xffff))) {
+ return NULL;
+ }
+
+ ast_channel_tech_set(chan, &gulp_tech);
+ ast_channel_tech_pvt_set(chan, session);
+
+ if (state == AST_STATE_RING) {
+ ast_channel_rings_set(chan, 1);
+ }
+
+ ast_channel_adsicpe_set(chan, AST_ADSI_UNAVAILABLE);
+
+ ast_channel_context_set(chan, "default");
+ ast_channel_exten_set(chan, S_OR(exten, "s"));
+ ast_channel_priority_set(chan, 1);
+
+ return chan;
+}
/*! \brief Function called by core when we should answer a Gulp session */
static int gulp_answer(struct ast_channel *ast)
@@ -411,6 +445,48 @@
return 0;
}
+/*! \brief Function called when a request is received on the session */
+static int gulp_incoming_request(struct ast_sip_session *session, struct pjsip_rx_data *rdata)
+{
+ int res = AST_PBX_FAILED;
+
+ /* We only care about new sessions */
+ if ((rdata->msg_info.msg->line.req.method.id != PJSIP_INVITE_METHOD) ||
+ (session->channel)) {
+ return 0;
+ }
+
+ if (!(session->channel = gulp_new(session, AST_STATE_DOWN, NULL, NULL, NULL, NULL))) {
+ pjsip_tx_data *packet = NULL;
+
+ if (pjsip_inv_end_session(session->inv_session, 503, NULL, &packet) == PJ_SUCCESS) {
+ pjsip_inv_send_msg(session->inv_session, packet);
+ }
+
+ return -1;
+ }
+
+ res = ast_pbx_start(session->channel);
+
+ switch (res) {
+ case AST_PBX_FAILED:
+ ast_log(LOG_WARNING, "Failed to start PBX ;(\n");
+ ast_channel_hangupcause_set(session->channel, AST_CAUSE_SWITCH_CONGESTION);
+ ast_hangup(session->channel);
+ break;
+ case AST_PBX_CALL_LIMIT:
+ ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n");
+ ast_channel_hangupcause_set(session->channel, AST_CAUSE_SWITCH_CONGESTION);
+ ast_hangup(session->channel);
+ break;
+ case AST_PBX_SUCCESS:
+ default:
+ break;
+ }
+
+ return (res == AST_PBX_SUCCESS) ? 0 : -1;
+}
+
/*!
* \brief Load the module
*
@@ -436,6 +512,11 @@
goto end;
}
+ if (ast_sip_session_register_supplement(&gulp_supplement)) {
+ ast_log(LOG_ERROR, "Unable to register Gulp supplement\n");
+ goto end;
+ }
+
return 0;
end:
@@ -453,6 +534,7 @@
/*! \brief Unload the Gulp channel from Asterisk */
static int unload_module(void)
{
+ ast_sip_session_unregister_supplement(&gulp_supplement);
ast_channel_unregister(&gulp_tech);
ast_rtp_glue_unregister(&gulp_rtp_glue);
More information about the asterisk-commits
mailing list