Asterisk - The Open Source Telephony Project GIT-master-f36a736
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 <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"
35
36#define DEFAULT_LANGUAGE "en"
37#define DEFAULT_ENCODING "identity"
38
39static 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
80 .method = "OPTIONS",
81 .incoming_request = options_incoming_request,
82};
83
84static int load_module(void)
85{
87
89}
90
91static int unload_module(void)
92{
94 return 0;
95}
96
97AST_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",
jack_status_t status
Definition: app_jack.c:146
Asterisk main include file. File version handling, generic pbx functions.
static struct ast_mansession session
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Asterisk module definitions.
@ AST_MODFLAG_LOAD_ORDER
Definition: module.h:331
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODPRI_APP_DEPEND
Definition: module.h:342
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
@ AST_MODULE_LOAD_SUCCESS
Definition: module.h:70
pjsip_endpoint * ast_sip_get_pjsip_endpoint(void)
Get a pointer to the PJSIP endpoint.
Definition: res_pjsip.c:520
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:2008
static int options_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
#define DEFAULT_ENCODING
#define DEFAULT_LANGUAGE
static struct ast_sip_session_supplement dlg_options_supplement
static int load_module(void)
static int unload_module(void)
#define ast_sip_session_register_supplement(supplement)
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
A supplement to SIP message processing.
A structure describing a SIP session.