[asterisk-commits] oej: branch oej/teapot-1.8 r385355 - in /team/oej/teapot-1.8: ./ channels/sip...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 11 14:44:52 CDT 2013


Author: oej
Date: Thu Apr 11 14:44:50 2013
New Revision: 385355

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=385355
Log:
Adding missing files.

Added:
    team/oej/teapot-1.8/README.darjeeling   (with props)
    team/oej/teapot-1.8/README.earl-grey   (with props)
    team/oej/teapot-1.8/channels/sip/include/sip2cause.h   (with props)
    team/oej/teapot-1.8/channels/sip/sip2cause.c   (with props)
    team/oej/teapot-1.8/configs/sip2cause.conf.sample   (with props)
    team/oej/teapot-1.8/res/res_noise.c   (with props)

Added: team/oej/teapot-1.8/README.darjeeling
URL: http://svnview.digium.com/svn/asterisk/team/oej/teapot-1.8/README.darjeeling?view=auto&rev=385355
==============================================================================
--- team/oej/teapot-1.8/README.darjeeling (added)
+++ team/oej/teapot-1.8/README.darjeeling Thu Apr 11 14:44:50 2013
@@ -1,0 +1,130 @@
+Edvina AB
+Olle E. Johansson
+
+
+Project started: 2012-06-15
+
+
+
+
+
+Darjeeling-prack-1.8
+--------------------
+
+This branch will implement PRACK in the SIP stack of Asterisk.
+
+PRACK stands for reliable unreliable provisional responses.
+
+In SIP, the provisional responses are often sent over UDP, which means that they can
+get lost. Some of them are retransmitted every minute (to get at least one through
+once during a three minute period following RFC 3261). For some messages, it's 
+important that they get through immediately. Like if you want to play a message to
+the customer that his call will be cancelled due to lack of funds in his account.
+
+PRACK adds a retransmit and ACK mechanism to the 1xx messages excluding 100 (since
+it's transmitted hop-by-hop).
+
+Configuration
+=============
+Add prack=yes in the [general] section of sip.conf or in device configurations. 
+Asterisk will now add 100rel to the list of supported options. If the other device
+supports PRACK Asterisk will activate it or support it if the other side
+requires it.
+There's currently no support for requiring PRACK in a call.
+
+
+Technichal details
+==================
+
+If the INVITE contains
+	Supported: 100rel
+
+then the 1xx answer can add 
+	Require: 100rel
+	Rseq: 	42
+
+The Rseq is the PRACK sequence number
+The caller then needs to confirm the message with a new request, during the INVITE transaction
+	PRACK
+	RAck: 	42	<cseq #> <cseq method>
+
+And the callee confirms this (and close the PRACK transaction) with a 200 OK.
+
+If the PRACK is not received in time, the 1xx response will be retransmitted.
+There can only be ONE outstanding PRACK, which makes it easier to integrate in the
+Asterisk SIP stack that unfortunately lacks a transaction layer.
+
+PRACK is documented in RFC 3262.
+
+Retransmission works like the retransmission of responses to INVITE (like the 200 OK).
+It starts with T1 and doubles for each retransmission. Unlike INVITE responses,
+the retransmission timer does not cap at T2.
+
+If retransmission times out, a 5xx message should terminate the INVITE transaction.
+
+
+A PRACK received that does not match existing SIP_PVT is responded to with 481.
+
+* When to stop?
+---------------
+From the RFC: 
+"The UAS MAY send a final response to the initial request before having received PRACKs for all unacknowledged
+reliable provisional responses, unless the final response is 2xx and any of the unacknowledged
+reliable provisional responses contained a session description. In that case, it MUST NOT send a final response
+until those provisional responses are acknowledged. If the UAS does send a final response when
+reliable responses are still unacknowledged, it SHOULD NOT continue to retransmit the unacknowledged
+reliable provisional responses, but it MUST be prepared to process PRACK requests for those outstanding
+responses. A UAS MUST NOT send new reliable provisional responses (as opposed to retransmissions of
+unacknowledged ones) after sending a final response to a request"
+
+* Receive in order until final response
+---------------------------------------
+"Handling of subsequent reliable provisional responses for the same initial request follows the same rules
+as above, with the following difference: reliable provisional responses are guaranteed to be in order. As a
+result, if the UAC receives another reliable provisional response to the same request, and its RSeq value
+is not one higher than the value of the sequence number, that response MUST NOT be acknowledged with a
+PRACK, and MUST NOT be processed further by the UAC. An implementation MAY discard the response,
+or MAY cache the response in the hopes of receiving the missing responses.
+The UAC MAY acknowledge reliable provisional responses received after the final response or MAY discard
+them."
+
+* When do the call begin?
+-------------------------
+A corner case that I don't know if it's implemented: If we receive and INVITE without SDP, we MUST
+add SDP offer to the reliable answer and the caller must add an SDP answer to the PRACK. This means 
+that the session begins in the middle of the INVITE transaction.
+"Once an answer has been sent or received, the UA SHOULD establish the session based on the parameters of
+the offer and answer, even if the original INVITE itself has not been responded to." (section 5)
+
+* Security
+----------
+"The PRACK request can be injected by attackers to force retransmissions of reliable provisional responses to
+cease. As these responses can convey important information, PRACK messages SHOULD be authenticated
+as any other request." (section 9)
+
+Todo
+----
+* Add PRACK to the list of supported headers
+	- done
+* Should we be able to REQUIRE prack? Based on what? _SIPREQUIREPRACK ?
+	- not now
+* PRACK enabled globally and per device - user and peer
+	- done
+* PRACK working when Asterisk is the UAS
+	- done
+* PRACK working when Asterisk is the UAC
+	- done
+* PRACK with authentication
+	- not done
+* Requesting auth for PRACK
+	- not done
+* PRACK in "sip show settings"
+	- done
+* PRACK in "sip show peer xxx"
+	- done
+* PRACK in "sip show channel xxx"
+	- done
+
+---------------------
+The patch is (C) Copyright by Edvina AB, Sollentuna, Sweden. 
+Developed by Olle E. Johansson, oej at edvina.net

Propchange: team/oej/teapot-1.8/README.darjeeling
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/teapot-1.8/README.darjeeling
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/teapot-1.8/README.darjeeling
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/oej/teapot-1.8/README.earl-grey
URL: http://svnview.digium.com/svn/asterisk/team/oej/teapot-1.8/README.earl-grey?view=auto&rev=385355
==============================================================================
--- team/oej/teapot-1.8/README.earl-grey (added)
+++ team/oej/teapot-1.8/README.earl-grey Thu Apr 11 14:44:50 2013
@@ -1,0 +1,64 @@
+Edvina AB
+Olle E. Johansson
+
+
+Project start: 2012-11-28
+
+
+
+Earl Grey  - configuring sip2cause tables
+==========================================
+
+Asterisk internally use ISDN cause codes. In the SIP channel, we do have two
+tables - one for translating from an ISDN cause code at hangup, to a SIP response
+code and one for translating the other way. In some edge cases, not very common,
+one wants to modify these tables.
+
+This branch will make the table a configurable option and add a new configuration
+file, sip2cause.conf, that is not needed in normal usage of Asterisk.
+
+When do you need this?
+======================
+If you operate a SIP2ISDN gateway and need to fine-tune conversion between ISDN
+cause codes and Asterisk SIP channel responses, you need a dynamic way to 
+handle the conversion. 
+
+If you operate a SIP server outside of Asterisk, you might want to add extra
+non-standard SIP response codes that is converted to a separate cause code
+that you handle in the dial plan.
+
+Please note the warning in sip2cause.conf.sample. Changing the conversion table
+can lead to all kinds of damage to your Asterisk installation. In most cases,
+no animals will be hurt.
+Edvina AB
+Olle E. Johansson
+
+
+Project start: 2012-11-28
+
+
+
+Earl Grey  - configuring sip2cause tables
+==========================================
+
+Asterisk internally use ISDN cause codes. In the SIP channel, we do have two
+tables - one for translating from an ISDN cause code at hangup, to a SIP response
+code and one for translating the other way. In some edge cases, not very common,
+one wants to modify these tables.
+
+This branch will make the table a configurable option and add a new configuration
+file, sip2cause.conf, that is not needed in normal usage of Asterisk.
+
+When do you need this?
+======================
+If you operate a SIP2ISDN gateway and need to fine-tune conversion between ISDN
+cause codes and Asterisk SIP channel responses, you need a dynamic way to 
+handle the conversion. 
+
+If you operate a SIP server outside of Asterisk, you might want to add extra
+non-standard SIP response codes that is converted to a separate cause code
+that you handle in the dial plan.
+
+Please note the warning in sip2cause.conf.sample. Changing the conversion table
+can lead to all kinds of damage to your Asterisk installation. In most cases,
+no animals will be hurt.

Propchange: team/oej/teapot-1.8/README.earl-grey
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/teapot-1.8/README.earl-grey
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/teapot-1.8/README.earl-grey
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/oej/teapot-1.8/channels/sip/include/sip2cause.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/teapot-1.8/channels/sip/include/sip2cause.h?view=auto&rev=385355
==============================================================================
--- team/oej/teapot-1.8/channels/sip/include/sip2cause.h (added)
+++ team/oej/teapot-1.8/channels/sip/include/sip2cause.h Thu Apr 11 14:44:50 2013
@@ -1,0 +1,84 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief sip2cause header file
+ */
+
+#include "sip.h"
+
+#ifndef _SIP_CAUSE_H
+#define _SIP_CAUSE_H
+
+/*! \brief Convert SIP response code to ISDN or Asterisk-specific cause code */
+int hangup_sip2cause(int cause);
+
+/*! \brief Convert ISDN or Asterisk-specific cause code to SIP response code */
+char *hangup_cause2sip(int cause);
+
+/*! \brief Initialized sip2cause tables */
+void sip2cause_init(void);
+
+/*! \brief Free sip2cause tables */
+void sip2cause_free(void);
+
+/*! \brief Load configuration */
+int sip2cause_load(struct ast_config *s2c_config);
+
+#endif /* defined(_SIP_CAUSE_H) */
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2010, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief sip2cause header file
+ */
+
+#include "sip.h"
+
+#ifndef _SIP_CAUSE_H
+#define _SIP_CAUSE_H
+
+/*! \brief Convert SIP response code to ISDN or Asterisk-specific cause code */
+int hangup_sip2cause(int cause);
+
+/*! \brief Convert ISDN or Asterisk-specific cause code to SIP response code */
+char *hangup_cause2sip(int cause);
+
+/*! \brief Initialized sip2cause tables */
+void sip2cause_init(void);
+
+/*! \brief Free sip2cause tables */
+void sip2cause_free(void);
+
+/*! \brief Load configuration */
+int sip2cause_load(struct ast_config *s2c_config);
+
+#endif /* defined(_SIP_CAUSE_H) */

Propchange: team/oej/teapot-1.8/channels/sip/include/sip2cause.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/teapot-1.8/channels/sip/include/sip2cause.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/teapot-1.8/channels/sip/include/sip2cause.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/oej/teapot-1.8/channels/sip/sip2cause.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/teapot-1.8/channels/sip/sip2cause.c?view=auto&rev=385355
==============================================================================
--- team/oej/teapot-1.8/channels/sip/sip2cause.c (added)
+++ team/oej/teapot-1.8/channels/sip/sip2cause.c Thu Apr 11 14:44:50 2013
@@ -1,0 +1,289 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, Digium, inc
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*!
+ * \file
+ * \brief SIP-to-ISDN cause code conversions
+ *
+ * \author Olle E. Johansson <oej at edvina.net>
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+/*
+The sip2causestruct could potentially be used to provide translations of SIP reason codes in the future
+
+*/
+
+#include "asterisk.h"
+#include "asterisk/causes.h"
+#include "asterisk/strings.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#include "include/sip2cause.h"
+
+/*! \brief structure for conversion between ISDN and SIP codes */
+struct sip2causestruct {
+	int	sip;			/*!< SIP code (200-699) - no provisional codes */
+	int	cause;			/*!< ISDN cause code */
+	char	reason[64];		/*!< SIP reason text, like "486 Busy", "404 Inte min domän" or "500 Que?" */
+	int	private;		/*!< If 1 = private extension */
+	struct sip2causestruct *next;	/*!< Pointer to next entry */
+};
+
+/*! \brief Main structure for tables, including default values */
+struct sip2causetable {
+	struct sip2causestruct *table;
+	int	defaultcode;
+	char	*defaultreason;
+};
+
+/*! \brief Actual table for sip => ISDN lookups */
+struct sip2causetable sip2causelookup;
+
+/*! \brief Actual table for ISDN => sip lookups */
+struct sip2causetable cause2siplookup;
+
+/*! \brief Add conversion entry to table */
+static struct sip2causestruct *newsip2cause(int sip, int cause, const char *reason, int private, struct sip2causestruct *next)
+{
+	struct sip2causestruct *s2c = ast_calloc(1, sizeof(struct sip2causestruct));
+
+	if (!s2c) {
+		return NULL;
+	}
+	s2c->sip = sip;
+	s2c->cause = cause;
+	ast_copy_string(s2c->reason, reason, sizeof(s2c->reason));
+	s2c->next = next;
+	s2c->private = private;
+	ast_debug(4, "SIP2CAUSE adding %d %s <=> %d (%s) \n", sip, reason, cause, ast_cause2str(cause));
+	return(s2c);
+ }
+
+/*! \brief Initialize structure with default values */
+void sip2cause_init(void)
+{
+	/* Initialize table for SIP => ISDN codes */
+	sip2causelookup.table = newsip2cause(401, /* Unauthorized */ AST_CAUSE_CALL_REJECTED, "", 0, NULL);
+	sip2causelookup.table = newsip2cause(403, /* Not found */ AST_CAUSE_CALL_REJECTED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(404, /* Not found */ AST_CAUSE_UNALLOCATED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(405, /* Method not allowed */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(407, /* Proxy authentication required */ AST_CAUSE_CALL_REJECTED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(408, /* No reaction */ AST_CAUSE_NO_USER_RESPONSE, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(409, /* Conflict */ AST_CAUSE_NORMAL_TEMPORARY_FAILURE, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(410, /* Gone */ AST_CAUSE_NUMBER_CHANGED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(411, /* Length required */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(413, /* Request entity too large */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(414, /* Request URI too large */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(415, /* Unsupported media type */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(420, /* Bad extension */ AST_CAUSE_NO_ROUTE_DESTINATION, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(480, /* No answer */ AST_CAUSE_NO_ANSWER, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(481, /* No answer */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(482, /* Loop detected */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(483, /* Too many hops */ AST_CAUSE_NO_ANSWER, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(484, /* Address incomplete */ AST_CAUSE_INVALID_NUMBER_FORMAT, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(485, /* Ambiguous */ AST_CAUSE_UNALLOCATED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(486, /* Busy everywhere */ AST_CAUSE_BUSY, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(487, /* Request terminated */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(488, /* No codecs approved */ AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(491, /* Request pending */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(493, /* Undecipherable */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(500, /* Server internal failure */ AST_CAUSE_FAILURE, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(501, /* Call rejected */ AST_CAUSE_FACILITY_REJECTED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(502, AST_CAUSE_DESTINATION_OUT_OF_ORDER, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(503, /* Service unavailable */ AST_CAUSE_CONGESTION, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(504, /* Gateway timeout */ AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(505, /* SIP version not supported */ AST_CAUSE_INTERWORKING, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(600, /* Busy everywhere */ AST_CAUSE_USER_BUSY, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(603, /* Decline */ AST_CAUSE_CALL_REJECTED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(604, /* Does not exist anywhere */ AST_CAUSE_UNALLOCATED, "", 0, sip2causelookup.table);
+	sip2causelookup.table = newsip2cause(606, /* Not acceptable */ AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, "", 0, sip2causelookup.table);
+
+	/* Add the reverse table */
+	cause2siplookup.table = newsip2cause(404, AST_CAUSE_UNALLOCATED, "404 Not Found", 0, NULL);
+	cause2siplookup.table = newsip2cause(404, AST_CAUSE_NO_ROUTE_DESTINATION, "404 Not Found", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(404, AST_CAUSE_NO_ROUTE_TRANSIT_NET, "404 Not Found", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(503, AST_CAUSE_CONGESTION, "503 Service Unavailable", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(503, AST_CAUSE_SWITCH_CONGESTION, "503 Service Unavailable", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(408, AST_CAUSE_NO_USER_RESPONSE, "408 Request Timeout", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(480, AST_CAUSE_NO_ANSWER, "480 Temporarily unavailable", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(480, AST_CAUSE_UNREGISTERED, "480 Temporarily unavailable", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(403, AST_CAUSE_CALL_REJECTED, "403 Forbidden", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(410, AST_CAUSE_NUMBER_CHANGED, "410 Gone", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(480, AST_CAUSE_NORMAL_UNSPECIFIED, "480 Temporarily unavailable", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(484, AST_CAUSE_INVALID_NUMBER_FORMAT, "484 Address Incomplete", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(486, AST_CAUSE_USER_BUSY, "486 Busy here", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(500, AST_CAUSE_FAILURE, "500 Server internal failure", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(501, AST_CAUSE_FACILITY_REJECTED, "501 Not implemented", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(503, AST_CAUSE_CHAN_NOT_IMPLEMENTED, "503 Service unavailable", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(502, AST_CAUSE_DESTINATION_OUT_OF_ORDER, "502 Bad gateway", 0, cause2siplookup.table);
+	cause2siplookup.table = newsip2cause(488, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, "488 Not Acceptable Here", 0, cause2siplookup.table);
+
+}
+	
+
+/*! \brief Make sure we free the cause code list from memory */
+void sip2cause_free(void)
+{
+	struct sip2causestruct *s2c = sip2causelookup.table;
+	while (s2c) {
+		struct sip2causestruct *next = s2c->next;
+		ast_free(s2c);
+		s2c = next;
+	}
+	s2c = cause2siplookup.table;
+	while (s2c) {
+		struct sip2causestruct *next = s2c->next;
+		ast_free(s2c);
+		s2c = next;
+	}
+}
+
+
+/*! \brief Convert SIP hangup causes to Asterisk hangup causes */
+int hangup_sip2cause(int sipcode)
+{
+	struct sip2causestruct *s2c = sip2causelookup.table;
+	while (s2c) {
+		if (s2c->sip == sipcode) {
+			ast_debug(1, "SIP2CAUSE returning %d (%s) based on SIP code %d        [%s]\n", s2c->cause, ast_cause2str(s2c->cause), sipcode, s2c->private ? "config" : "default");
+			return s2c->cause;
+		}
+		s2c = s2c->next;
+	}
+
+	/* Possible values taken from causes.h */
+
+	if (sipcode < 500 && sipcode >= 400) {
+		/* 4xx class error that is unknown - someting wrong with our request */
+		ast_debug(4, "SIP2CAUSE returning default %d (%s) based on SIP code %d\n", AST_CAUSE_INTERWORKING, ast_cause2str(AST_CAUSE_INTERWORKING), sipcode);
+		return AST_CAUSE_INTERWORKING;
+	} else if (sipcode < 600 && sipcode >= 500) {
+		ast_debug(4, "SIP2CAUSE returning default %d (%s) based on SIP code %d\n", AST_CAUSE_CONGESTION, ast_cause2str(AST_CAUSE_CONGESTION), sipcode);
+		/* 5xx class error - problem in the remote end */
+		return AST_CAUSE_CONGESTION;
+	} else if (sipcode < 700 && sipcode >= 600) {
+		ast_debug(4, "SIP2CAUSE returning default %d (%s) based on SIP code %d\n", AST_CAUSE_INTERWORKING, ast_cause2str(AST_CAUSE_INTERWORKING), sipcode);
+		/* 6xx - global errors in the 4xx class */
+		return AST_CAUSE_INTERWORKING;
+	}
+	ast_debug(4, "SIP2CAUSE returning default %d (%s) based on SIP code %d\n", s2c->cause, ast_cause2str(s2c->cause), sipcode);
+	return AST_CAUSE_NORMAL;
+}
+
+/*! \brief Convert Asterisk hangup causes to SIP codes
+\verbatim
+ Possible values from causes.h
+        AST_CAUSE_NOTDEFINED    AST_CAUSE_NORMAL        AST_CAUSE_BUSY
+        AST_CAUSE_FAILURE       AST_CAUSE_CONGESTION    AST_CAUSE_UNALLOCATED
+
+	In addition to these, a lot of PRI codes is defined in causes.h
+	...should we take care of them too ?
+
+	Quote RFC 3398
+
+   ISUP Cause value                        SIP response
+   ----------------                        ------------
+   1  unallocated number                   404 Not Found
+   2  no route to network                  404 Not found
+   3  no route to destination              404 Not found
+   16 normal call clearing                 --- (*)
+   17 user busy                            486 Busy here
+   18 no user responding                   408 Request Timeout
+   19 no answer from the user              480 Temporarily unavailable
+   20 subscriber absent                    480 Temporarily unavailable
+   21 call rejected                        403 Forbidden (+)
+   22 number changed (w/o diagnostic)      410 Gone
+   22 number changed (w/ diagnostic)       301 Moved Permanently
+   23 redirection to new destination       410 Gone
+   26 non-selected user clearing           404 Not Found (=)
+   27 destination out of order             502 Bad Gateway
+   28 address incomplete                   484 Address incomplete
+   29 facility rejected                    501 Not implemented
+   31 normal unspecified                   480 Temporarily unavailable
+\endverbatim
+*/
+char *hangup_cause2sip(int cause)
+{
+	struct sip2causestruct *s2c = cause2siplookup.table;
+	while (s2c) {
+		if (s2c->cause == cause) {
+			ast_debug(4, "cause2sip returning %s based on ISDN cause %d - %s           [%s]\n", s2c->reason, cause, ast_cause2str(cause), s2c->private ? "config" : "default");
+			return s2c->reason;
+		}
+		s2c = s2c->next;
+	}
+	ast_debug(1, "AST hangup cause %d (no match found in SIP)\n", cause);
+	return NULL;
+}
+
+/*! \brief Load configuration
+
+- Check if SIP code is valid
+- Check if we can parse the cause code using functions in channel.c
+
+*/
+int sip2cause_load(struct ast_config *s2c_config)
+{
+	struct ast_variable *v;
+	int respcode;
+	int cause;
+	int number=0;
+
+	ast_debug(2, "AST sip2cause configuration parser");
+	if (!s2c_config) {
+		return 0;
+	}
+	for (v = ast_variable_browse(s2c_config, "sip2cause"); v; v = v->next) {
+		ast_debug(1, "====> SIP2cause ::: Name %s Value %s \n", v->name, v->value);
+		respcode = 42;
+		cause = 0;
+		number = sscanf(v->name, "%d", &respcode);
+		if (number != 1) {
+			ast_log(LOG_ERROR, "Unknown SIP response code format %s in sip2cause.conf section [sip2cause] Respcode %d Number %d\n", v->name, respcode, number);
+			continue;
+		}
+		if (respcode < 200 || respcode > 699) {
+			ast_log(LOG_ERROR, "Bad SIP response code:  Asterisk cause code \'%s=>%s\' in sip2cause.conf section [sip2cause] \n", v->name, v->value);
+			continue;
+		}
+		if ((cause = ast_str2cause(v->value)) == -1) {
+			ast_log(LOG_ERROR, "Unknown Asterisk cause code %s in sip2cause.conf section [sip2cause] Cause %d\n", v->value, cause);
+			continue;
+		} 
+		sip2causelookup.table = newsip2cause(respcode, cause, "", 1, sip2causelookup.table);
+	}
+	for (v = ast_variable_browse(s2c_config, "cause2sip"); v; v = v->next) {
+		ast_debug(1, "====> CAUSE2SIP ::: Name %s Value %s \n", v->name, v->value);
+		if ((cause = ast_str2cause(v->name)) == -1) {
+			ast_log(LOG_ERROR, "Unknown Asterisk cause code %s in sip2cause.conf section [cause2sip] \n", v->name);
+			continue;
+		} 
+		if (sscanf(v->value, "%d ", &respcode) != 1) {
+			ast_log(LOG_ERROR, "Bad syntax:  Asterisk cause code \'%s=>%s\' in sip2cause.conf section [cause2sip] \n", v->name, v->value);
+			continue;
+		}
+		if (respcode < 200 || respcode > 699) {
+			ast_log(LOG_ERROR, "Bad SIP response code:  \'%s=>%s\' in sip2cause.conf section [cause2sip] \n", v->name, v->value);
+			continue;
+		}
+		cause2siplookup.table = newsip2cause(respcode, cause, v->value, 1, cause2siplookup.table);
+	}
+	return 1;
+}

Propchange: team/oej/teapot-1.8/channels/sip/sip2cause.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/teapot-1.8/channels/sip/sip2cause.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/teapot-1.8/channels/sip/sip2cause.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/oej/teapot-1.8/configs/sip2cause.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/oej/teapot-1.8/configs/sip2cause.conf.sample?view=auto&rev=385355
==============================================================================
--- team/oej/teapot-1.8/configs/sip2cause.conf.sample (added)
+++ team/oej/teapot-1.8/configs/sip2cause.conf.sample Thu Apr 11 14:44:50 2013
@@ -1,0 +1,48 @@
+;
+; Conversion table additions for the translation between SIP hangup codes and ISDN cause codes
+; ============================================================================================
+; This table is used to convert a negative SIP response to an ISDN cause code, that is sent
+; over the PBX call bridge to the calling party, or to convert a received ISDN hangup cause
+; from the called party to a SIP response. Changes will not affect how Asterisk treats a SIP
+; response, but how the other party reacts to it.
+;
+; For reference, check Asterisk source code include/asterisk/causes.h
+; and channels/sip/sip2cause.c
+;
+; Note also that this translation is not used in all cases in the SIP implementation in Asterisk.
+; Fixes are always welcome.
+;
+; !!!!!!!!!!!!!!!!!!!! READ THIS SERIOUSLY !
+; Note: By changing the default translation, you can seriously jeopardize your Asterisk server functionality.
+;       Make sure you understand what you are doing, and that you are testing carefully.
+;       In 99.99% of Asterisk installations, you will not need to add ANYTHING to this file.
+;
+[sip2cause]
+; 404 => USER_BUSY
+
+[cause2sip]
+; USER_BUSY => 403 Forbidden
+;
+; Conversion table additions for the translation between SIP hangup codes and ISDN cause codes
+; ============================================================================================
+; This table is used to convert a negative SIP response to an ISDN cause code, that is sent
+; over the PBX call bridge to the calling party, or to convert a received ISDN hangup cause
+; from the called party to a SIP response. Changes will not affect how Asterisk treats a SIP
+; response, but how the other party reacts to it.
+;
+; For reference, check Asterisk source code include/asterisk/causes.h
+; and channels/sip/sip2cause.c
+;
+; Note also that this translation is not used in all cases in the SIP implementation in Asterisk.
+; Fixes are always welcome.
+;
+; !!!!!!!!!!!!!!!!!!!! READ THIS SERIOUSLY !
+; Note: By changing the default translation, you can seriously jeopardize your Asterisk server functionality.
+;       Make sure you understand what you are doing, and that you are testing carefully.
+;       In 99.99% of Asterisk installations, you will not need to add ANYTHING to this file.
+;
+[sip2cause]
+; 404 => USER_BUSY
+
+[cause2sip]
+; USER_BUSY => 403 Forbidden

Propchange: team/oej/teapot-1.8/configs/sip2cause.conf.sample
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/teapot-1.8/configs/sip2cause.conf.sample
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/teapot-1.8/configs/sip2cause.conf.sample
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: team/oej/teapot-1.8/res/res_noise.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/teapot-1.8/res/res_noise.c?view=auto&rev=385355
==============================================================================
--- team/oej/teapot-1.8/res/res_noise.c (added)
+++ team/oej/teapot-1.8/res/res_noise.c Thu Apr 11 14:44:50 2013
@@ -1,0 +1,164 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2005, Digium, Inc.
+ *
+ * Contributed by Carlos Antunes <cmantunes at gmail.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file 
+ *
+ * \brief Just generate white noise 
+ * 
+ */
+
+/*** MODULEINFO
+	<support_level>random</support_level>
+ ***/
+
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/lock.h"
+#include "asterisk/file.h"
+#include "asterisk/logger.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/module.h"
+#include "asterisk/app.h"
+
+#include <math.h>
+
+static char *app = "WhiteNoise";
+
+
+/*** DOCUMENTATION
+	<application name="WhiteNoise" language="en_US">
+		<synopsis>
+			Generates white noise
+		</synopsis>
+		<syntax>
+		<parameter name="args">
+			<argument name="timeout" required="true" />
+			<argument name="level" required="false" />
+		</parameter>
+		</syntax>
+		<description>
+			<para>Generates white noise at 'level' dBov's for 'timeout' seconds or indefinitely if timeout
+			is absent or is zero.</para>
+			<para>Level is a non-positive number. For example, WhiteNoise(0.0) generates
+			white noise at full power, while WhiteNoise(-3.0) generates white noise at
+			half full power. Every -3dBov's reduces white noise power in half. Full
+			power in this case is defined as noise that overloads the channel roughly 0.3%
+			of the time. Note that values below -69 dBov's start to give out silence
+			frequently, resulting in intermittent noise, i.e, alternating periods of
+			silence and noise.</para>
+
+		</description>
+	</application>
+***/
+
+static int noise_exec(struct ast_channel *chan, const char *data) {
+
+	struct ast_module_user *u;
+	char *excessdata;
+	float level = 0;
+	float timeout = 0;
+	char *s;
+	int res;
+	struct ast_noise_generator *gendata;
+
+        AST_DECLARE_APP_ARGS(args,
+                AST_APP_ARG(timeout);
+                AST_APP_ARG(level);
+        );
+
+	/* Verify we potentially have arguments and get local copy */
+        if (!data) {
+                ast_log(LOG_WARNING, "WhiteNoise usage following: WhiteNoise([timeout[, level]])\n");
+                return -1;
+        }
+	
+	/* Separate arguments */	
+        s = ast_strdupa(data);
+        AST_STANDARD_APP_ARGS(args, s);
+
+	if (args.timeout) {	
+		/* Extract second argument, if available, and validate
+		 * timeout is non-negative. Zero timeout means no timeout */
+		args.timeout = ast_trim_blanks(args.timeout);
+		timeout = strtof(args.timeout, &excessdata);
+		if ((excessdata && *excessdata) || timeout < 0) {
+			ast_log(LOG_WARNING, "Invalid argument 'timeout': WhiteNoise requires non-negative floating-point argument for timeout in seconds\n");				
+			return -1;
+		}
+
+		/* Convert timeout to milliseconds
+		 * and ensure minimum of 20ms      */
+		timeout = roundf(timeout * 1000.0);
+		if (timeout > 0 && timeout < 20) {
+			timeout = 20;
+		}
+	} 
+
+	if (args.level) {
+		/* Extract first argument and ensure we have
+		 * a valid noise level argument value        */
+		args.level = ast_trim_blanks(args.level);
+		level = strtof(args.level, &excessdata);
+		if ((excessdata && *excessdata) || level > 0) {
+			ast_log(LOG_ERROR, "Invalid argument 'level': WhiteNoise requires non-positive floating-point argument for noise level in dBov's\n");
+			return -1;
+		}
+	} 
+
+	ast_debug(1, "Setting up white noise generator with level %.1fdBov's and %.0fms %stimeout\n", level, timeout, timeout == 0 ? "(no) " : "");
+
+	u = ast_module_user_add(chan);
+	if (chan->_state != AST_STATE_UP) {
+		ast_answer(chan);
+	}
+	gendata = ast_channel_start_noise_generator(chan, level);
+	if (data == NULL)	{
+		ast_log(LOG_WARNING, "Failed to activate white noise generator on '%s'\n",chan->name);
+		res = -1;
+	} else {
+		/* Just do the noise... */
+		res = -1;
+		if (timeout > 0) {
+			res = ast_safe_sleep(chan, timeout);
+		} else  {
+			while(!ast_safe_sleep(chan, 10000));
+		}
+		ast_channel_stop_noise_generator(chan, gendata);
+	}
+	ast_module_user_remove(u);
+	return res;
+}
+
+static int unload_module(void) {
+	ast_module_user_hangup_all();
+	
+	return ast_unregister_application(app);
+}
+
+static int load_module(void) {
+	return ast_register_application_xml(app, noise_exec);
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS, "White Noise Generator Application",
+                .load = load_module,
+                .unload = unload_module,
+               );

Propchange: team/oej/teapot-1.8/res/res_noise.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/oej/teapot-1.8/res/res_noise.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/oej/teapot-1.8/res/res_noise.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list