| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#include "asterisk.h" |
| 27 |
|
| 28 |
#include <pjsip.h> |
| 29 |
#include <pjsip_ua.h> |
| 30 |
#include <pjlib.h> |
| 31 |
|
| 32 |
#include "asterisk/module.h" |
| 33 |
#include "asterisk/res_pjsip.h" |
| 34 |
#include "asterisk/res_pjsip_session.h" |
| 35 |
|
| 36 |
#define DEFAULT_LANGUAGE "en" |
| 37 |
#define DEFAULT_ENCODING "identity" |
| 38 |
|
| 39 |
static int options_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata) |
| 40 |
{ |
| 41 |
pjsip_tx_data *tdata; |
| 42 |
pj_status_t status; |
| 43 |
const pjsip_hdr *hdr; |
| 44 |
pjsip_endpoint *endpt = ast_sip_get_pjsip_endpoint(); |
| 45 |
|
| 46 |
status = pjsip_dlg_create_response(session->inv_session->dlg, rdata, 200, NULL,&tdata); |
| 47 |
if (status != PJ_SUCCESS) { |
| 48 |
ast_log(LOG_ERROR, "Unable to create response (%d)\n", status); |
| 49 |
return status; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
if ((hdr = pjsip_endpt_get_capability(endpt, PJSIP_H_ACCEPT, NULL))) { |
| 54 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)pjsip_hdr_clone(tdata->pool, hdr)); |
| 55 |
} |
| 56 |
if ((hdr = pjsip_endpt_get_capability(endpt, PJSIP_H_ALLOW, NULL))) { |
| 57 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)pjsip_hdr_clone(tdata->pool, hdr)); |
| 58 |
} |
| 59 |
if ((hdr = pjsip_endpt_get_capability(endpt, PJSIP_H_SUPPORTED, NULL))) { |
| 60 |
pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr*)pjsip_hdr_clone(tdata->pool, hdr)); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ast_sip_add_header(tdata, "Accept-Encoding", DEFAULT_ENCODING); |
| 69 |
ast_sip_add_header(tdata, "Accept-Language", DEFAULT_LANGUAGE); |
| 70 |
|
| 71 |
status = pjsip_dlg_send_response(session->inv_session->dlg, pjsip_rdata_get_tsx(rdata), tdata); |
| 72 |
if (status != PJ_SUCCESS) { |
| 73 |
ast_log(LOG_ERROR, "Unable to send response (%d)\n", status); |
| 74 |
} |
| 75 |
|
| 76 |
return status; |
| 77 |
} |
| 78 |
|
| 79 |
static struct ast_sip_session_supplement dlg_options_supplement = { |
| 80 |
.method = "OPTIONS", |
| 81 |
.incoming_request = options_incoming_request, |
| 82 |
}; |
| 83 |
|
| 84 |
static int load_module(void) |
| 85 |
{ |
| 86 |
ast_sip_session_register_supplement(&dlg_options_supplement); |
| 87 |
|
| 88 |
return AST_MODULE_LOAD_SUCCESS; |
| 89 |
} |
| 90 |
|
| 91 |
static int unload_module(void) |
| 92 |
{ |
| 93 |
ast_sip_session_unregister_supplement(&dlg_options_supplement); |
| 94 |
return 0; |
| 95 |
} |
| 96 |
|
| 97 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP OPTIONS in dialog handler", |
| 98 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 99 |
.load = load_module, |
| 100 |
.unload = unload_module, |
| 101 |
.load_pri = AST_MODPRI_APP_DEPEND, |
| 102 |
.requires = "res_pjsip,res_pjsip_session", |
| 103 |
); |