Asterisk - The Open Source Telephony Project  18.5.0
res_pjsip_dlg_options.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2015, Digium, Inc.
5  *
6  * Yaron Nahum <[email protected]>
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"
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. We never did add them
67  * in chan_sip, although RFC 3261 says they SHOULD. Hard coded here.
68  */
69  ast_sip_add_header(tdata, "Accept-Encoding", DEFAULT_ENCODING);
70  ast_sip_add_header(tdata, "Accept-Language", DEFAULT_LANGUAGE);
71 
72  status = pjsip_dlg_send_response(session->inv_session->dlg, pjsip_rdata_get_tsx(rdata), tdata);
73  if (status != PJ_SUCCESS) {
74  ast_log(LOG_ERROR, "Unable to send response (%d)\n", status);
75  }
76 
77  return status;
78 }
79 
81  .method = "OPTIONS",
82  .incoming_request = options_incoming_request,
83 };
84 
85 static int load_module(void)
86 {
87  ast_sip_session_register_supplement(&dlg_options_supplement);
88 
90 }
91 
92 static int unload_module(void)
93 {
94  ast_sip_session_unregister_supplement(&dlg_options_supplement);
95  return 0;
96 }
97 
98 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "SIP OPTIONS in dialog handler",
99  .support_level = AST_MODULE_SUPPORT_CORE,
100  .load = load_module,
101  .unload = unload_module,
102  .load_pri = AST_MODPRI_APP_DEPEND,
103  .requires = "res_pjsip,res_pjsip_session",
104 );
Asterisk main include file. File version handling, generic pbx functions.
void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
Unregister a an supplement to SIP session processing.
Definition: pjsip_session.c:63
#define NULL
Definition: resample.c:96
struct pjsip_inv_session * inv_session
A structure describing a SIP session.
int ast_sip_add_header(pjsip_tx_data *tdata, const char *name, const char *value)
Add a header to an outbound SIP message.
Definition: res_pjsip.c:5063
#define ast_log
Definition: astobj2.c:42
static struct ast_mansession session
#define DEFAULT_ENCODING
#define LOG_ERROR
Definition: logger.h:285
static int options_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
#define DEFAULT_LANGUAGE
static struct ast_sip_session_supplement dlg_options_supplement
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS|AST_MODFLAG_LOAD_ORDER, "HTTP Phone Provisioning",.support_level=AST_MODULE_SUPPORT_EXTENDED,.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DEPEND,.requires="http",)
A supplement to SIP message processing.
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:3718
static int load_module(void)
static int unload_module(void)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Asterisk module definitions.
jack_status_t status
Definition: app_jack.c:146
#define ast_sip_session_register_supplement(supplement)