From 19a4928fee5647b78f58d3b5457117360e09c54c Mon Sep 17 00:00:00 2001 From: Jonathan Rose Date: Fri, 23 Dec 2011 20:42:21 +0000 Subject: INFO/Record request configurable to use dynamic features Adds two new options to SIP peers allowing them to specify features (dynamic or builtin) to use when sending INFO/record requests. Recordonfeature activates whatever feature is specified when recieving a record: on request while recordofffeature activates whatever feature is specified when receiving a record: off request. Both of these features can be disabled by setting the feature to an empty string. (closes issue ASTERISK-16507) Reported by: Jon Bright Review: https://reviewboard.asterisk.org/r/1634/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@349098 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 50 +++++++++++++++++++++++++++++++++++++--------- channels/sip/include/sip.h | 6 ++++++ configs/sip.conf.sample | 12 +++++++++++ main/features.c | 3 ++- 4 files changed, 61 insertions(+), 10 deletions(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 3f12e6e1b..99fb9b024 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -17751,6 +17751,8 @@ static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct ao2_t_ref(credentials, -1, "Unref peer auth for show"); } ast_cli(fd, " Context : %s\n", peer->context); + ast_cli(fd, " Record On feature : %s\n", peer->record_on_feature); + ast_cli(fd, " Record Off feature : %s\n", peer->record_off_feature); ast_cli(fd, " Subscr.Cont. : %s\n", S_OR(peer->subscribecontext, "") ); ast_cli(fd, " Language : %s\n", peer->language); ast_cli(fd, " Tonezone : %s\n", peer->zone[0] != '\0' ? peer->zone : ""); @@ -18502,6 +18504,8 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_ ast_cli(a->fd, " Allowed transports: %s\n", get_transport_list(default_transports)); ast_cli(a->fd, " Outbound transport: %s\n", sip_get_transport(default_primary_transport)); ast_cli(a->fd, " Context: %s\n", sip_cfg.default_context); + ast_cli(a->fd, " Record on feature: %s\n", sip_cfg.default_record_on_feature); + ast_cli(a->fd, " Record off feature: %s\n", sip_cfg.default_record_off_feature); ast_cli(a->fd, " Force rport: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_NAT_FORCE_RPORT))); ast_cli(a->fd, " DTMF: %s\n", dtmfmode2str(ast_test_flag(&global_flags[0], SIP_DTMF))); ast_cli(a->fd, " Qualify: %d\n", default_qualify); @@ -19204,15 +19208,13 @@ static void handle_request_info(struct sip_pvt *p, struct sip_request *req) return; } else if (!ast_strlen_zero(c = sip_get_header(req, "Record"))) { /* INFO messages generated by some phones to start/stop recording - on phone calls. - OEJ: I think this should be something that is enabled/disabled - per device. I don't want incoming callers to record calls in my - pbx. - */ - - struct ast_call_feature *feat; + * on phone calls. + */ + + struct ast_call_feature *feat = NULL; int j; struct ast_frame f = { AST_FRAME_DTMF, }; + int suppress_warning = 0; /* Supress warning if the feature is blank */ if (!p->owner) { /* not a PBX call */ transmit_response(p, "481 Call leg/transaction does not exist", req); @@ -19222,9 +19224,27 @@ static void handle_request_info(struct sip_pvt *p, struct sip_request *req) /* first, get the feature string, if it exists */ ast_rdlock_call_features(); - feat = ast_find_call_feature("automon"); + if (p->relatedpeer) { + if (!strcasecmp(c, "on")) { + if (ast_strlen_zero(p->relatedpeer->record_on_feature)) { + suppress_warning = 1; + } else { + feat = ast_find_call_feature(p->relatedpeer->record_on_feature); + } + } else if (!strcasecmp(c, "off")) { + if (ast_strlen_zero(p->relatedpeer->record_on_feature)) { + suppress_warning = 1; + } else { + feat = ast_find_call_feature(p->relatedpeer->record_off_feature); + } + } else { + ast_log(LOG_ERROR, "Received INFO requesting to record with invalid value: %s\n", c); + } + } if (!feat || ast_strlen_zero(feat->exten)) { - ast_log(LOG_WARNING, "Recording requested, but no One Touch Monitor registered. (See features.conf)\n"); + if (!suppress_warning) { + ast_log(LOG_WARNING, "Recording requested, but no One Touch Monitor registered. (See features.conf)\n"); + } /* 403 means that we don't support this feature, so don't request it again */ transmit_response(p, "403 Forbidden", req); ast_unlock_call_features(); @@ -27666,6 +27686,8 @@ static void set_peer_defaults(struct sip_peer *peer) ast_copy_flags(&peer->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); ast_copy_flags(&peer->flags[2], &global_flags[2], SIP_PAGE3_FLAGS_TO_COPY); ast_string_field_set(peer, context, sip_cfg.default_context); + ast_string_field_set(peer, record_on_feature, sip_cfg.default_record_on_feature); + ast_string_field_set(peer, record_off_feature, sip_cfg.default_record_off_feature); ast_string_field_set(peer, messagecontext, sip_cfg.messagecontext); ast_string_field_set(peer, subscribecontext, sip_cfg.default_subscribecontext); ast_string_field_set(peer, language, default_language); @@ -27975,6 +27997,10 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str } else if (!strcasecmp(v->name, "context")) { ast_string_field_set(peer, context, v->value); ast_set_flag(&peer->flags[1], SIP_PAGE2_HAVEPEERCONTEXT); + } else if (!strcasecmp(v->name, "recordonfeature")) { + ast_string_field_set(peer, record_on_feature, v->value); + } else if (!strcasecmp(v->name, "recordofffeature")) { + ast_string_field_set(peer, record_off_feature, v->value); } else if (!strcasecmp(v->name, "outofcall_message_context")) { ast_string_field_set(peer, messagecontext, v->value); } else if (!strcasecmp(v->name, "subscribecontext")) { @@ -28734,6 +28760,8 @@ static int reload_config(enum channelreloadreason reason) /* Initialize some reasonable defaults at SIP reload (used both for channel and as default for devices */ ast_copy_string(sip_cfg.default_context, DEFAULT_CONTEXT, sizeof(sip_cfg.default_context)); + ast_copy_string(sip_cfg.default_record_on_feature, DEFAULT_RECORD_FEATURE, sizeof(sip_cfg.default_record_on_feature)); + ast_copy_string(sip_cfg.default_record_off_feature, DEFAULT_RECORD_FEATURE, sizeof(sip_cfg.default_record_off_feature)); sip_cfg.default_subscribecontext[0] = '\0'; sip_cfg.default_max_forwards = DEFAULT_MAX_FORWARDS; default_language[0] = '\0'; @@ -28801,6 +28829,10 @@ static int reload_config(enum channelreloadreason reason) if (!strcasecmp(v->name, "context")) { ast_copy_string(sip_cfg.default_context, v->value, sizeof(sip_cfg.default_context)); + } else if (!strcasecmp(v->name, "recordonfeature")) { + ast_copy_string(sip_cfg.default_record_on_feature, v->value, sizeof(sip_cfg.default_record_on_feature)); + } else if (!strcasecmp(v->name, "recordofffeature")) { + ast_copy_string(sip_cfg.default_record_off_feature, v->value, sizeof(sip_cfg.default_record_off_feature)); } else if (!strcasecmp(v->name, "subscribecontext")) { ast_copy_string(sip_cfg.default_subscribecontext, v->value, sizeof(sip_cfg.default_subscribecontext)); } else if (!strcasecmp(v->name, "callcounter")) { diff --git a/channels/sip/include/sip.h b/channels/sip/include/sip.h index 84f3af93b..ad9e7819f 100644 --- a/channels/sip/include/sip.h +++ b/channels/sip/include/sip.h @@ -34,6 +34,7 @@ #include "asterisk/astobj.h" #include "asterisk/indications.h" #include "asterisk/security_events.h" +#include "asterisk/features.h" #ifndef FALSE #define FALSE 0 @@ -182,6 +183,7 @@ */ /*@{*/ #define DEFAULT_CONTEXT "default" /*!< The default context for [general] section as well as devices */ +#define DEFAULT_RECORD_FEATURE "automon" /*!< The default feature specified for use with INFO */ #define DEFAULT_MOHINTERPRET "default" /*!< The default music class */ #define DEFAULT_MOHSUGGEST "" #define DEFAULT_VMEXTEN "asterisk" /*!< Default voicemail extension */ @@ -744,6 +746,8 @@ struct sip_settings { struct sip_proxy outboundproxy; /*!< Outbound proxy */ char default_context[AST_MAX_CONTEXT]; char default_subscribecontext[AST_MAX_CONTEXT]; + char default_record_on_feature[FEATURE_MAX_LEN]; + char default_record_off_feature[FEATURE_MAX_LEN]; struct ast_ha *contact_ha; /*! \brief Global list of addresses dynamic peers are not allowed to use */ struct ast_format_cap *caps; /*!< Supported codecs */ int tcp_enabled; @@ -1243,6 +1247,8 @@ struct sip_peer { AST_STRING_FIELD(engine); /*!< RTP Engine to use */ AST_STRING_FIELD(unsolicited_mailbox); /*!< Mailbox to store received unsolicited MWI NOTIFY messages information in */ AST_STRING_FIELD(zone); /*!< Tonezone for this device */ + AST_STRING_FIELD(record_on_feature); /*!< Feature to use when receiving INFO with record: on during a call */ + AST_STRING_FIELD(record_off_feature); /*!< Feature to use when receiving INFO with record: off during a call */ ); struct sip_socket socket; /*!< Socket used for this peer */ enum sip_transport default_outbound_transport; /*!< Peer Registration may change the default outbound transport. diff --git a/configs/sip.conf.sample b/configs/sip.conf.sample index 115b33709..358481143 100644 --- a/configs/sip.conf.sample +++ b/configs/sip.conf.sample @@ -143,6 +143,16 @@ allowoverlap=no ; Disable overlap dialing support. (Default is y ; In this case Realm will be based on request 'From'/'To' header ; and should match one of domain names. ; Otherwise default 'realm=...' will be used. +;recordonfeature=automixmon ; Default feature to use when receiving 'Record: on' header + ; from an INFO message. Defaults to 'automon'. Works with + ; dynamic features. Feature must be usable on requesting + ; channel for it to work. Setting this value to a blank + ; will disable it. +;recordofffeature=automixmon ; Default feature to use when receiving 'Record: off' header + ; from an INFO message. Defaults to 'automon'. Works with + ; dynamic features. Feature must be usable on requesting + ; channel for it to work. Setting this value to a blank + ; will disable it. ; With the current situation, you can do one of four things: ; a) Listen on a specific IPv4 address. Example: bindaddr=192.0.2.1 @@ -1268,6 +1278,8 @@ srvlookup=yes ; Enable DNS SRV lookups on outbound calls ;[grandstream1] ;type=friend ;context=from-sip ; Where to start in the dialplan when this phone calls +;recordonfeature=dynamicfeature1 ; Feature to use when INFO with Record: on is received. +;recordofffeature=dynamicfeature2 ; Feature to use when INFO with Record: off is received. ;callerid=John Doe <1234> ; Full caller ID, to override the phones config ; on incoming calls to Asterisk ;description=Courtesy Phone ; Description of the peer. Shown when doing 'sip show peers'. diff --git a/main/features.c b/main/features.c index ca6286bdc..7b595fb49 100644 --- a/main/features.c +++ b/main/features.c @@ -3015,7 +3015,8 @@ struct ast_call_feature *ast_find_call_feature(const char *name) if (!strcasecmp(name, builtin_features[x].sname)) return &builtin_features[x]; } - return NULL; + + return find_dynamic_feature(name); } /*! -- cgit v1.2.3