<html>
<head>
<meta name="viewport" content="width=device-width" />
<base href="https://wiki.asterisk.org/wiki" />
<style type="text/css">
body, #email-content, #email-content-inner { font-family: Arial,FreeSans,Helvetica,sans-serif; }
body, p, blockquote, pre, code, td, th, li, dt, dd { font-size: 13px; }
small { font-size: 11px; }
body { width:100% !important; -webkit-font-smoothing: antialiased; }
body,
#email-wrapper { background-color: #f0f0f0; }
#email-wrapper-inner { padding: 20px; text-align: center; }
#email-content-inner { background-color: #fff; border: 1px solid #bbb; color: $menuTxtColour; padding:20px; text-align:left; }
#email-wrapper-inner > table { width: 100%; }
#email-wrapper-inner.thin > table { margin: 0 auto; width: 50%; }
#email-footer { padding: 0 16px 32px 16px; margin: 0; }
.email-indent { margin: 8px 0 16px 0; }
.email-comment { margin: 0 0 0 56px; }
.email-comment.removed { background-color: #ffe7e7; border: 1px solid #df9898; padding: 0 8px;}
#email-title-avatar { text-align: left; vertical-align: top; width: 48px; padding-right: 8px; }
#email-title-flavor { margin: 0; padding: 0 0 4px 0; }
#email-title-heading { font-size: 16px; line-height: 20px; min-height: 20px; margin: 0; padding: 0; }
#email-title .icon { border: 0; padding: 0 5px 0 0; text-align: left; vertical-align: middle; }
#email-actions { border-top: 1px solid #bbb; color: #505050; margin: 8px 0 0 0; padding: 0; }
#email-actions td { padding-top: 8px; }
#email-actions .left { max-width: 45%; text-align: left; }
#email-actions .right { text-align: right; }
.email-reply-divider { border-top: 1px solid #bbb; color: #505050; margin: 32px 0 8px 0; padding: 8px 0; }
.email-section-title { border-bottom: 1px solid #bbb; margin: 8px 0; padding: 8px 0 0 0; }
.email-metadata { color: #505050; }
a { color: #326ca6; text-decoration: none; }
a:hover { color: #336ca6; text-decoration: underline; }
a:active {color: #326ca6; }
a.email-footer-link { color: #505050; font-size: 11px; }
.email-item-list { list-style: none; margin: 4px 0; padding-left: 0; }
.email-item-list li { list-style: none; margin: 0; padding: 4px 0; }
.email-list-divider { color: #505050; padding: 0 0.35em; }
.email-operation-icon { padding-right: 5px; }
.avatar { -ms-interpolation-mode: bicubic; border-radius: 3px;}
.avatar-link { margin: 2px; }
.tableview th { border-bottom: 1px solid #69C; font-weight: bold; text-align: left; }
.tableview td { border-bottom: 1px solid #bbbbbb; text-align: left; padding: 4px 16px 4px 0; }
.aui-message { margin: 1em 0; padding: 8px; }
.aui-message.info { background-color: #e0f0ff; border: 1px solid #9eb6d4; }
.aui-message.success { background-color: #ddfade; border: 1px solid #93c49f; }
.aui-message.error,
.aui-message.removed { background-color: #ffe7e7; border: 1px solid #df9898; color: #000; }
.call-to-action-table { margin: 10px 1px 1px 1px;}
.call-to-cancel-container, .call-to-action-container { padding: 5px 20px; }
.call-to-cancel-container { border: 1px solid #aaa; background-color: #eee; border-radius: 3px; }
.call-to-cancel-container a.call-to-cancel-button { background-color: #eee; font-size: 14px; line-height: 1; padding: 0; margin: 0; color: #666; font-family: sans-serif;}
.call-to-action-container { border: 1px solid #486582; background-color: #3068A2; border-radius: 3px; padding: 4px 10px; }
.call-to-action-container a.call-to-action-button { background-color: #3068A2; font-size: 14px; line-height: 1; padding: 0; margin: 0; color: #fff; font-weight: bold; font-family: sans-serif; }
/** The span around the inline task checkbox image */
.diff-inline-task-overlay {
display: inline-block;
text-align: center;
height: 1.5em;
padding: 5px 0px 1px 5px;
margin-right: 5px;
/** Unfortunately, the negative margin-left is stripped out in gmail */
margin-left: -5px;
}
@media handheld, only screen and (max-device-width: 480px) {
div, a, p, td, th, li, dt, dd { -webkit-text-size-adjust: auto; }
small, small a { -webkit-text-size-adjust: 90%; }
td[id=email-wrapper-inner] { padding: 2px !important; }
td[id=email-content-inner] { padding: 8px !important; }
td[id="email-wrapper-inner"][class="thin"] > table { text-align: left !important; width: 100% !important; }
td[id=email-footer] { padding: 8px 12px !important; }
div[class=email-indent] { margin: 8px 0px !important; }
div[class=email-comment] { margin: 0 !important; }
p[id=email-title-flavor] a { display: block; } /* puts the username and the action on separate lines */
p[id=email-permalink] { padding: 4px 0 0 0 !important; }
table[id=email-actions] td { padding-top: 0 !important; }
table[id=email-actions] td.right { text-align: right !important; }
table[id=email-actions] .email-list-item { display: block; margin: 1em 0 !important; word-wrap: normal !important; }
span[class=email-list-divider] { display: none; }
}
</style>
</head>
<body style="font-family: Arial, FreeSans, Helvetica, sans-serif; font-size: 13px; width: 100%; -webkit-font-smoothing: antialiased; background-color: #f0f0f0">
<table id="email-wrapper" width="100%" cellspacing="0" cellpadding="0" border="0" style="background-color: #f0f0f0">
<tbody>
<tr valign="middle">
<td id="email-wrapper-inner" style="font-size: 13px; padding: 20px; text-align: center">
<table id="email-content" cellspacing="0" cellpadding="0" border="0" style="font-family: Arial, FreeSans, Helvetica, sans-serif; width: 100%">
<tbody>
<tr valign="top">
<td id="email-content-inner" align="left" style="font-family: Arial, FreeSans, Helvetica, sans-serif; font-size: 13px; background-color: #fff; border: 1px solid #bbb; padding: 20px; text-align: left">
<table id="email-title" cellpadding="0" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td id="email-title-avatar" rowspan="2" style="font-size: 13px; text-align: left; vertical-align: top; width: 48px; padding-right: 8px"> <img class="avatar" src="cid:avatar_99ed0aa29d6f204db4785296f8170422" border="0" height="48" width="48" style="-ms-interpolation-mode: bicubic; border-radius: 3px" /> </td>
<td valign="top" style="font-size: 13px">
<div id="email-title-flavor" class="email-metadata" style="margin: 0; padding: 0 0 4px 0; color: #505050">
<a href=" https://wiki.asterisk.org/wiki/display/~mmichelson " style="color:#326ca6;text-decoration:none;; color: #326ca6; text-decoration: none">Mark Michelson</a> edited the page:
</div> </td>
</tr>
<tr>
<td valign="top" style="font-size: 13px"> <h2 id="email-title-heading" style="font-size: 16px; line-height: 20px; min-height: 20px; margin: 0; padding: 0"> <a href="https://wiki.asterisk.org/wiki/display/AST/Writing+a+SIP+Session+Supplement" style="color: #326ca6; text-decoration: none"> <img class="icon" src="cid:page-icon" alt="" style="border: 0; padding: 0 5px 0 0; text-align: left; vertical-align: middle" /> <strong style="font-size:16px;line-height:20px;vertical-align:top;">Writing a SIP Session Supplement</strong> </a> </h2> </td>
</tr>
</tbody>
</table>
<div class="email-indent" style="margin: 8px 0 16px 0">
<p class="aui-message info" style="font-size: 13px; margin: 1em 0; padding: 8px; background-color: #e0f0ff; border: 1px solid #9eb6d4"> <b>Comment:</b> Update based on API changes and correct some errors </p>
<div class="email-diff">
<div id="page-diffs" class="wiki-content">
<p class="diff-block-context" style="font-size: 13px">If you are unfamiliar with what a SIP session supplement is, please see <a class="confluence-link unresolved" href="#" style="color: #326ca6; text-decoration: none">this</a> for an explanation.</p>
<p class="diff-block-target" style="font-size: 13px"> </p>
<table class="diff-macro bodyless diff-html-changed" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;margin: 5px 0; padding: 0; width: auto;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="diff-html-changed" id="changed-diff-0" style="background-color: #d6f0ff;"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/images/icons/macrobrowser/dropdown/toc.png" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Table of Contents</span></th>
</tr>
</thead>
</table>
<p style="font-size: 13px"></p>
<h1 id="WritingaSIPSessionSupplement-Problemoverview" class="diff-block-context">Problem overview</h1>
<p class="diff-block-context" style="font-size: 13px">For our tutorial, we will be implementing (a simple version of) <a href="http://tools.ietf.org/html/rfc5373" class="external-link" rel="nofollow" style="color: #326ca6; text-decoration: none">RFC 5373</a>. This RFC defines a way to indicate to a user agent that it should automatically respond to the incoming INVITE with a 200 OK response. For this tutorial, we will be implementing the UAC version of this so that Asterisk can request that outgoing calls are automatically answered by the recipient.</p>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-target" style="font-size: 13px">Let's start by creating a new file called <code style="font-size: 13px">res_<span class="diff-html-removed" id="removed-diff-0" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-0" style="font-size: 100%; background-color: #ddfade;">pjsip</span>_auto_answer.c</code> and place it in the <code style="font-size: 13px">res</code> directory of the Asterisk source. Placing the file there will automatically result in a loadable module being built when a <code style="font-size: 13px">make</code> command is run.</p>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Let's consider what we need to do for this feature to work. All we have to do is conditionally add headers to outbound INVITE requests. We don't need to do anything with inbound requests or responses and we don't need to do anything with outbound responses. Given that, let's go ahead and define the session supplement we're going to use:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">title</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">res_<span class="diff-html-removed" id="removed-diff-1" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-1" style="font-size: 100%; background-color: #ddfade;">pjsip</span>_auto_answer.c</td>
</tr>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px"><span class="diff-html-removed" id="removed-diff-2" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">language</span></td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px"><span class="diff-html-removed" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">c</span></td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>#include "asterisk.h"
#include <pjsip.h>
#include <span class="diff-html-added" id="added-diff-2" style="font-size: 100%; background-color: #ddfade;"><pjsip_ua.h>
#include </span><pjlib.h>
#include "asterisk/res_<span class="diff-html-removed" id="removed-diff-3" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip_</span><span class="diff-html-added" id="added-diff-3" style="font-size: 100%; background-color: #ddfade;">pjsip.h"
#include "asterisk/res_pjsip_</span>session.h"
#include "asterisk/module.h"
/*** MODULEINFO
<span class="diff-html-removed" id="removed-diff-4" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span><span class="diff-html-added" id="added-diff-4" style="font-size: 100%; background-color: #ddfade;"> </span><depend>pjproject</depend>
<span class="diff-html-removed" id="removed-diff-5" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span><span class="diff-html-added" id="added-diff-5" style="font-size: 100%; background-color: #ddfade;"> <depend>res_pjsip</depend>
</span><depend>res_<span class="diff-html-removed" id="removed-diff-6" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-6" style="font-size: 100%; background-color: #ddfade;">pjsip</span>_session</depend>
***/
static void auto_answer_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
{
/* STUB */
}
static struct ast_sip_session_supplement auto_answer_supplement = {
.method = "INVITE",
.outgoing_request = auto_answer_outgoing_request,
};
static int load_module(void)
{
if (ast_sip_session_register_supplement(&auto_answer_supplement)) {
return AST_MODULE_LOAD_DECLINE;
}
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
ast_sip_session_unregister_supplement(&auto_answer_supplement)<span class="diff-html-removed" id="removed-diff-7" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">)</span>;
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP Auto Answer Support",
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_APP_DEPEND,
);
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Let's go into deeper detail about what we have just written. Let's start at the top:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-8" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>#include "asterisk.h"
#include <pjsip.h>
#include <span class="diff-html-added" id="added-diff-7" style="font-size: 100%; background-color: #ddfade;"><pjsip_ua.h>
#include </span><pjlib.h>
#include "asterisk/res_<span class="diff-html-removed" id="removed-diff-9" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip_</span><span class="diff-html-added" id="added-diff-8" style="font-size: 100%; background-color: #ddfade;">pjsip.h"
#include "asterisk/res_pjsip_</span>session.h"
#include "asterisk/module.h"
/*** MODULEINFO
<depend>pjproject</depend>
<span class="diff-html-added" id="added-diff-9" style="font-size: 100%; background-color: #ddfade;"> <depend>res_pjsip</depend></span>
<span class="diff-html-added" id="added-diff-10" style="font-size: 100%; background-color: #ddfade;"> </span><depend>res_<span class="diff-html-removed" id="removed-diff-10" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-11" style="font-size: 100%; background-color: #ddfade;">pjsip</span>_session</depend>
***/
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-block-target diff-block-context" style="font-size: 13px">The <code style="font-size: 13px">#includes</code> here grab the necessary headers we will need. All code in Asterisk starts by including <code style="font-size: 13px">asterisk.h</code>. After that, we will need the <code style="font-size: 13px">pjsip.h</code><span class="diff-html-removed" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span><span class="diff-html-removed" id="removed-diff-11" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">and </span><code style="font-size: 13px"><span class="diff-html-added" id="added-diff-12" style="font-size: 100%; background-color: #ddfade;">, </span><code style="font-size: 13px"><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">pjsip_ua.h</span></code><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">,</span></code><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;"> and </span><code style="font-size: 13px">pjlib.h</code> files in order to make use of PJSIP functions. We will use these later in the tutorial. The inclusion of <code style="font-size: 13px">asterisk/res_<span class="diff-html-removed" id="removed-diff-12" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip_</span><span class="diff-html-added" id="added-diff-13" style="font-size: 100%; background-color: #ddfade;">pjsip.h</span></code><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;"> and </span><code style="font-size: 13px"><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">asterisk/res_pjsip_</span>session.h</code> is what allows us to be able to create a session supplement. Finally, the inclusion of <code style="font-size: 13px">asterisk/module.h</code> is necessary since our file is going to be a loadable module in Asterisk.</p>
<p class="diff-block-target" style="font-size: 13px">The <code style="font-size: 13px">MODULEINFO</code> block is used by the menuselect system in Asterisk in order to allow for the module to only be selectable if the necessary dependencies are met. In our case, we need the PJPROJECT library to be present, and we need <code style="font-size: 13px">res_<span class="diff-html-removed" id="removed-diff-13" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-14" style="font-size: 100%; background-color: #ddfade;">pjsip</span></code><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;"> and </span><code style="font-size: 13px"><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">res</span>_<span class="diff-html-added" id="added-diff-15" style="font-size: 100%; background-color: #ddfade;">pjsip_</span>session</code> to be built as well, since <span class="diff-html-removed" id="removed-diff-14" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">it supplies </span><span class="diff-html-added" id="added-diff-16" style="font-size: 100%; background-color: #ddfade;">they supply </span>the <span class="diff-html-removed" id="removed-diff-15" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">API </span><span class="diff-html-added" id="added-diff-17" style="font-size: 100%; background-color: #ddfade;">APIs </span>for using session supplements.</p>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Next let's jump down to the bottom of the file:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-16" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>static int load_module(void)
{
if (ast_sip_session_register_supplement(&auto_answer_supplement)) {
return AST_MODULE_LOAD_DECLINE;
}
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
ast_sip_session_unregister_supplement(&auto_answer_supplement)<span class="diff-html-removed" id="removed-diff-17" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">)</span>;
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP Auto Answer Support",
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_APP_DEPEND,
);
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-block-target" style="font-size: 13px">We will not go into a lot of detail about the module-specific code here since it is covered in a tutorial <a class="confluence-link unresolved" href="#" style="color: #326ca6; text-decoration: none">here</a>. However, notice that when the module loads, it registers the <code style="font-size: 13px">auto_answer_supplement</code> with <code style="font-size: 13px">res_<span class="diff-html-removed" id="removed-diff-18" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-18" style="font-size: 100%; background-color: #ddfade;">pjsip</span>_session</code> and when the module unloads, it unregisters the <code style="font-size: 13px">auto_answer_supplement</code>.</p>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Now let's have a look at the important part of the code:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-19" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>static void auto_answer_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
{
/* STUB */
}
static struct ast_sip_session_supplement auto_answer_supplement = {
.method = "INVITE",
.outgoing_request = auto_answer_outgoing_request,
};
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-block-target" style="font-size: 13px">Let's start with the bottom struct declaration. It defines a session supplement called <code style="font-size: 13px">auto_answer_supplement</code>. For this supplement, the important fields to fill out are the <code style="font-size: 13px">method</code> and the <code style="font-size: 13px">outgoing_request</code> fields. By setting <code style="font-size: 13px">.method = "INVITE"</code> it tells <code style="font-size: 13px">res_<span class="diff-html-removed" id="removed-diff-20" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-19" style="font-size: 100%; background-color: #ddfade;">pjsip</span>_session</code> only to call into this supplement on INVITEs and not for other methods. If the method had been left empty, then the supplement would be called into for all SIP method types. We also set <code style="font-size: 13px">.outgoing_request</code>. This makes it so that on outgoing SIP requests, our method will be called. Combined with the earlier <code style="font-size: 13px">method</code> setting, it means that our session will only be called into for outgoing INVITE requests. Other session supplement fields are as follows:</p>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Let's take a look at where we are currently with our callback:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-21" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>static void auto_answer_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
{
/* STUB */
}
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">So let's add these headers:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-22" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>static void auto_answer_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
{
static const pj_str_t answer_mode_name = { "Answer-Mode", 11 };
static const pj_str_t answer_mode_value = { "auto", 4 };
static const pj_str_t require_value = { "answermode", 10 };
pjsip_generic_string_hdr *answer_mode;
pjsip_require_hdr *require;
/* Let's add the require header. There could already be a require header present in the
* request. If so, then we just need to add "answermode" to the list of requirements. Otherwise,
* we need to create a require header and add "answermode" to it.
*/
require = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_REQUIRE, NULL);
if (!require) {
require = pjsip_require_hdr_create(tdata->pool);
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) require);
}
pj_strdup(tdata->pool, &require->values[require->count++], &require_value);
/* Now we can add the Answer-Mode header. This is easier since nothing else should be adding this
* header to the message before we get it.
*/
answer_mode = pjsip_generic_<span class="diff-html-added" id="added-diff-20" style="font-size: 100%; background-color: #ddfade;">string_</span>hdr_create(tdata->pool, &answer_mode_name, &answer_mode_value);
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) answer_mode);
}
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Now we have some content! Let's go into it in more detail, starting from the top:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-23" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span>static const pj_str_t answer_mode_name = { "Answer-Mode", 11 };
static const pj_str_t answer_mode_value = { "auto", 4 };
static const pj_str_t require_value = { "answermode", 10 };
pjsip_generic_string_hdr *answer_mode;
pjsip_require_hdr *require;
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Next, let's have a look at what we are doing with the Require header:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-24" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span>require = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_REQUIRE, NULL);
if (!require) {
require = pjsip_require_hdr_create(tdata->pool);
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) require);
}
pj_cstr(&require->values[require->count++], &require_value);
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">Next, let's have a look at what we are doing with the Auto-Answer header:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-25" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span>answer_mode = pjsip_generic_<span class="diff-html-added" id="added-diff-21" style="font-size: 100%; background-color: #ddfade;">string_</span>hdr_create(tdata->pool, &answer_mode_name, &answer_mode_value);
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) answer_mode);
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">At this point, we have a simple session supplement written, but we don't actually want to add the auto-answer information to every single outgoing INVITE. Instead, we want to do so based on the presence of the SIP_AUTO_ANSWER channel variable on the outbound channel. Let's modify the code to do this. We will insert the code just before our Require header handling:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-26" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span>...
pjsip_require_hdr *require;
int add_auto_answer;
ast_channel_lock(session->channel);
add_auto_answer = ast_true(pbx_builtin_getvar_helper(session->channel, "SIP_AUTO_ANSWER"));
ast_channel_unlock(session->channel);
if (!add_auto_answer) {
return;
}
/* Let's add the require header. There could already be a require header present in the
...
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-block-target" style="font-size: 13px">With this new code, we'll check the <code style="font-size: 13px">SIP_AUTO_ANSWER</code> channel variable to see if it tells us we should add auto-answer headers. The <code style="font-size: 13px">ast_true</code> function checks that the header checks a string's value for words like "yes", "on", or "1" in order to be sure that it is intentional for the auto-answer feature to be invoked. The <code style="font-size: 13px">pbx_builtin_getvar_helper</code> function requires that the channel is locked while it is called and the value returned by it is used. <span class="diff-html-added" id="added-diff-22" style="font-size: 100%; background-color: #ddfade;">In order to use </span><code style="font-size: 13px"><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">pbx_builtin_getvar_helper</span></code><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;"> we will need to include </span><code style="font-size: 13px"><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">asterisk/pbx.h</span></code><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">.</span> </p>
<h3 id="WritingaSIPSessionSupplement-Afinaladjustment" class="diff-block-context">A final adjustment</h3>
<p class="diff-block-context" style="font-size: 13px">So now we have code that will conditionally add the auto-answer headers. We only have one final change to make. Think about when this callback is called. It's called on outbound INVITE requests. The thing is, that means it will be called both for the initial outbound INVITE for a session and it will be called on reinvites as well. Auto-answer does not pertain to reinvites, so we should add code to ensure that we only attempt to add the headers for initial outbound INVITEs.</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">language</td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px">c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-27" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;"> </span>...
int add_auto_answer;
if (session->inv_session->state >= PJSIP_INV_<span class="diff-html-added" id="added-diff-23" style="font-size: 100%; background-color: #ddfade;">STATE_</span>CONFIRMED) {
return;
}
ast_channel_lock(session->channel);
...
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
<p class="diff-block-context" style="font-size: 13px">At this point, we are finished. So let's put it all together and see what we have:</p>
<table class="diff-macro diff-block-target" style="background-color: #f0f0f0;border: 1px solid #dddddd;margin: 10px 1px;padding: 0 2px 2px;width: 100%;">
<thead>
<tr>
<th class="diff-macro-title" style="background-color: transparent; text-align: left; font-weight: normal;padding: 5px;; font-size: 13px"><span class="icon macro-placeholder-icon" style="background-color: ;line-height: 20px;"><img src="https://wiki.asterisk.org/wiki/s/en_GB-1988229788/4252/6ac85e9b14675c5514a674e1aecae99c9505ed36.48/_/plugins/servlet/confluence/placeholder/macro-icon?name=code" style="padding-right: 5px; vertical-align: text-bottom;" /> </span>Code Block</th>
</tr>
</thead>
<tbody>
<tr>
<td class="diff-macro-properties" style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;padding: 0; border: 1px solid #dddddd;; font-size: 13px">
<table>
<tbody>
<tr>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px"><span class="diff-html-removed" id="removed-diff-28" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">language</span></td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px"><span class="diff-html-added" id="added-diff-24" style="font-size: 100%; background-color: #ddfade;">title</span></td>
<td style="background-color: #fafafa; padding: 0 0 0 5px; font-size: 12px; text-align: left;; font-size: 13px"><span class="diff-html-added" style="font-size: 100%; background-color: #ddfade;">res_pjsip_auto_answer.</span>c</td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
<tbody>
<tr>
<td class="diff-macro-body" style="background-color: #fff;border: 1px solid #dddddd;padding: 10px;; font-size: 13px"> <pre style="font-size: 13px">
<span class="diff-html-removed" id="removed-diff-29" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">
</span>#include "asterisk.h"
#include <pjsip.h>
#include <span class="diff-html-added" id="added-diff-25" style="font-size: 100%; background-color: #ddfade;"><pjsip_ua.h>
#include </span><pjlib.h>
#include "asterisk/res_<span class="diff-html-removed" id="removed-diff-30" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip_</span><span class="diff-html-added" id="added-diff-26" style="font-size: 100%; background-color: #ddfade;">pjsip.h"
#include "asterisk/res_pjsip_</span>session.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
/*** MODULEINFO
<depend>pjproject</depend>
<span class="diff-html-added" id="added-diff-27" style="font-size: 100%; background-color: #ddfade;"> <depend>res_pjsip</depend></span>
<span class="diff-html-added" id="added-diff-28" style="font-size: 100%; background-color: #ddfade;"> </span><depend>res_<span class="diff-html-removed" id="removed-diff-31" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">sip</span><span class="diff-html-added" id="added-diff-29" style="font-size: 100%; background-color: #ddfade;">pjsip</span>_session</depend>
***/
static void auto_answer_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
{
static const pj_str_t answer_mode_name = { "Answer-Mode", 11 };
static const pj_str_t answer_mode_value = { "auto", 4 };
static const pj_str_t require_value = { "answermode", 10 };
pjsip_generic_string_hdr *answer_mode;
pjsip_require_hdr *require;
int add_auto_answer;
if (session->inv_session->state >= PJSIP_INV_CONFIRMED) {
return;
}
ast_channel_lock(session->channel);
add_auto_answer = ast_true(pbx_builtin_getvar_helper(session->channel, "SIP_AUTO_ANSWER"));
ast_channel_unlock(session->channel);
if (!add_auto_answer) {
return;
}
/* Let's add the require header. There could already be a require header present in the
* request. If so, then we just need to add "answermode" to the list of requirements. Otherwise,
* we need to create a require header and add "answermode" to it.
*/
require = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_REQUIRE, NULL);
if (!require) {
require = pjsip_require_hdr_create(tdata->pool);
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) require);
}
pj_strdup(tdata->pool, &require->values[require->count++], &require_value);
/* Now we can add the Answer-Mode header. This is easier since nothing else should be adding this
* header to the message before we get it.
*/
answer_mode = pjsip_generic_<span class="diff-html-added" id="added-diff-30" style="font-size: 100%; background-color: #ddfade;">string_</span>hdr_create(tdata->pool, &answer_mode_name, &answer_mode_value);
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *) answer_mode);
}
static struct ast_sip_session_supplement auto_answer_supplement = {
.method = "INVITE",
.outgoing_request = auto_answer_outgoing_request,
};
static int load_module(void)
{
if (ast_sip_session_register_supplement(&auto_answer_supplement)) {
return AST_MODULE_LOAD_DECLINE;
}
return AST_MODULE_LOAD_SUCCESS;
}
static int unload_module(void)
{
ast_sip_session_unregister_supplement(&auto_answer_supplement)<span class="diff-html-removed" id="removed-diff-32" style="font-size: 100%; background-color: #ffe7e7; text-decoration: line-through;">)</span>;
return 0;
}
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP Auto Answer Support",
.load = load_module,
.unload = unload_module,
.load_pri = AST_MODPRI_APP_DEPEND,
);
</pre> </td>
</tr>
</tbody>
</table>
<p class="diff-context-placeholder" style="font-size: 13px">...</p>
</div>
</div>
</div>
<table id="email-actions" class="email-metadata" cellspacing="0" cellpadding="0" border="0" width="100%" style="border-top: 1px solid #bbb; color: #505050; margin: 8px 0 0 0; padding: 0; color: #505050">
<tbody>
<tr>
<td class="left" valign="top" style="font-size: 13px; padding-top: 8px; max-width: 45%; text-align: left"> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/display/AST/Writing+a+SIP+Session+Supplement" style="color: #326ca6; text-decoration: none">View Online</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">·</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/plugins/likes/like.action?contentId=22773976" style="color: #326ca6; text-decoration: none">Like</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">·</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=22773976&revisedVersion=4&originalVersion=3" style="color: #326ca6; text-decoration: none">View Changes</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">·</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/display/AST/Writing+a+SIP+Session+Supplement?showComments=true&showCommentArea=true#addcomment" style="color: #326ca6; text-decoration: none">Add Comment</a> </span> </td>
<td class="right" width="50%" valign="top" style="font-size: 13px; padding-top: 8px; text-align: right"> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST" style="color: #326ca6; text-decoration: none">Stop watching space</a> </span> <span class="email-list-divider" style="color: #505050; padding: 0 0.350em">·</span> <span class="email-list-item"><a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action" style="color: #326ca6; text-decoration: none">Manage Notifications</a> </span> </td>
</tr>
</tbody>
</table> </td>
</tr>
</tbody>
</table> </td>
</tr>
<tr>
<td id="email-footer" align="center" style="font-size: 13px; padding: 0 16px 32px 16px; margin: 0"> <small style="font-size: 11px"> This message was sent by <a class="email-footer-link" style="color:#505050;font-size:11px;text-decoration:none;; color: #326ca6; text-decoration: none; color: #505050; font-size: 11px" href="http://www.atlassian.com/software/confluence">Atlassian Confluence</a> 5.1.5, <a class="email-footer-link" style="color:#505050;font-size:11px;text-decoration:none;; color: #326ca6; text-decoration: none; color: #505050; font-size: 11px" href="http://www.atlassian.com/software/confluence/overview/team-collaboration-software?utm_source=email-footer">Team Collaboration Software</a> </small> </td>
</tr>
</tbody>
</table>
</body>
</html>