Asterisk - The Open Source Telephony Project  21.4.1
res_pjsip_dlg_options.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2015, Digium, Inc.
5  *
6  * Yaron Nahum <nachum.yaron@gmail.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*** MODULEINFO
20  <depend>pjproject</depend>
21  <depend>res_pjsip</depend>
22  <depend>res_pjsip_session</depend>
23  <support_level>core</support_level>
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  /* Add appropriate headers */
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  * XXX TODO: pjsip doesn't care a lot about either of these headers -
65  * while it provides specific methods to create them, they are defined
66  * to be the standard string header creation. Hard coded here.
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 
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 );
Asterisk main include file. File version handling, generic pbx functions.
struct pjsip_inv_session * inv_session
A structure describing a SIP session.
A supplement to SIP message processing.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.