[svn-commits] russell: branch russell/messaging r297488 - in /team/russell/messaging: chann...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Dec 2 15:50:05 CST 2010


Author: russell
Date: Thu Dec  2 15:50:00 2010
New Revision: 297488

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=297488
Log:
Updates to MESSAGE support.

 - Make out of call MESSAGE support optional.  On by default.
 - Make MESSAGE auth optional.  On by default.

Modified:
    team/russell/messaging/channels/chan_sip.c
    team/russell/messaging/channels/sip/include/sip.h
    team/russell/messaging/configs/sip.conf.sample
    team/russell/messaging/doc/asterisk-messaging.txt

Modified: team/russell/messaging/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/channels/chan_sip.c?view=diff&rev=297488&r1=297487&r2=297488
==============================================================================
--- team/russell/messaging/channels/chan_sip.c (original)
+++ team/russell/messaging/channels/chan_sip.c Thu Dec  2 15:50:00 2010
@@ -1257,7 +1257,7 @@
 static int send_response(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
 static int send_request(struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno);
 static void copy_request(struct sip_request *dst, const struct sip_request *src);
-static void receive_message(struct sip_pvt *p, struct sip_request *req);
+static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
 static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward);
 static int sip_send_mwi_to_peer(struct sip_peer *peer, const struct ast_event *event, int cache_only);
 
@@ -1524,7 +1524,7 @@
 static int handle_request_bye(struct sip_pvt *p, struct sip_request *req);
 static int handle_request_register(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *sin, const char *e);
 static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req);
-static int handle_request_message(struct sip_pvt *p, struct sip_request *req);
+static int handle_request_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
 static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int seqno, const char *e);
 static void handle_request_info(struct sip_pvt *p, struct sip_request *req);
 static int handle_request_options(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e);
@@ -15373,7 +15373,7 @@
 /*! \brief  Receive SIP MESSAGE method messages
 \note	We only handle messages within current calls currently
 	Reference: RFC 3428 */
-static void receive_message(struct sip_pvt *p, struct sip_request *req)
+static void receive_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 {
 	struct ast_str *buf;
 	struct ast_frame f;
@@ -15419,16 +15419,37 @@
 		return;
 	}
 
-#if 0
-	/* Message outside of a call, we do not support that */
-	transmit_response(p, "405 Method Not Allowed", req);
-	sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
-#endif
-
-	/*
-	 * XXX Need to optionally authenticate MESSAGE.  Also, make passing MESSAGE up to
-	 * the dialplan configurable.
-	 */
+	if (!sip_cfg.accept_outofcall_message) {
+		/* Message outside of a call, we do not support that */
+		ast_debug(1, "MESSAGE outside of a call administratively disabled.\n");
+		transmit_response(p, "405 Method Not Allowed", req);
+		sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
+		return;
+	}
+
+	if (sip_cfg.auth_message_requests) {
+		int res;
+
+		copy_request(&p->initreq, req);
+		set_pvt_allowed_methods(p, req);
+		res = check_user(p, req, SIP_MESSAGE, e, XMIT_UNRELIABLE, addr);
+		if (res == AUTH_CHALLENGE_SENT) {
+			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
+			return;
+		}
+		if (res < 0) { /* Something failed in authentication */
+			if (res == AUTH_FAKE_AUTH) {
+				ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From"));
+				transmit_fake_auth_response(p, SIP_OPTIONS, req, XMIT_UNRELIABLE);
+			} else {
+				ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", get_header(req, "From"));
+				transmit_response(p, "403 Forbidden", req);
+			}
+			sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT);
+			return;
+		}
+		/* Auth was successful.  Proceed. */
+	}
 
 	if (!(msg = ast_msg_alloc())) {
 		transmit_response(p, "500 Internal Server Error", req);
@@ -15444,7 +15465,7 @@
 	res = ast_msg_set_to(msg, "%s", to);
 	res |= ast_msg_set_from(msg, "%s", get_in_brackets(from));
 	res |= ast_msg_set_body(msg, "%s", ast_str_buffer(buf));
-	/* XXX set configurable context */
+	res |= ast_msg_set_context(msg, "%s", p->context);
 
 	if (res) {
 		ao2_ref(msg, -1);
@@ -22763,12 +22784,12 @@
 }
 
 /*! \brief Handle incoming MESSAGE request */
-static int handle_request_message(struct sip_pvt *p, struct sip_request *req)
+static int handle_request_message(struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 {
 	if (!req->ignore) {
 		if (req->debug)
 			ast_verbose("Receiving message!\n");
-		receive_message(p, req);
+		receive_message(p, req, addr, e);
 	} else
 		transmit_response(p, "202 Accepted", req);
 	return 1;
@@ -24003,7 +24024,7 @@
 		res = handle_request_bye(p, req);
 		break;
 	case SIP_MESSAGE:
-		res = handle_request_message(p, req);
+		res = handle_request_message(p, req, addr, e);
 		break;
 	case SIP_PUBLISH:
 		res = handle_request_publish(p, req, addr, seqno, e);
@@ -26846,6 +26867,8 @@
 	sip_cfg.directrtpsetup = FALSE;		/* Experimental feature, disabled by default */
 	sip_cfg.alwaysauthreject = DEFAULT_ALWAYSAUTHREJECT;
 	sip_cfg.auth_options_requests = DEFAULT_AUTH_OPTIONS;
+	sip_cfg.auth_message_requests = DEFAULT_AUTH_MESSAGE;
+	sip_cfg.accept_outofcall_message = DEFAULT_ACCEPT_OUTOFCALL_MESSAGE;
 	sip_cfg.allowsubscribe = FALSE;
 	sip_cfg.disallowed_methods = SIP_UNKNOWN;
 	sip_cfg.contact_ha = NULL;		/* Reset the contact ACL */
@@ -27091,6 +27114,14 @@
 		} else if (!strcasecmp(v->name, "auth_options_requests")) {
 			if (ast_true(v->value)) {
 				sip_cfg.auth_options_requests = 1;
+			}
+		} else if (!strcasecmp(v->name, "auth_message_requests")) {
+			if (ast_true(v->value)) {
+				sip_cfg.auth_message_requests = 1;
+			}
+		} else if (!strcasecmp(v->name, "accept_outofcall_message")) {
+			if (ast_true(v->value)) {
+				sip_cfg.accept_outofcall_message = 1;
 			}
 		} else if (!strcasecmp(v->name, "mohinterpret")) {
 			ast_copy_string(default_mohinterpret, v->value, sizeof(default_mohinterpret));

Modified: team/russell/messaging/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/channels/sip/include/sip.h?view=diff&rev=297488&r1=297487&r2=297488
==============================================================================
--- team/russell/messaging/channels/sip/include/sip.h (original)
+++ team/russell/messaging/channels/sip/include/sip.h Thu Dec  2 15:50:00 2010
@@ -208,6 +208,8 @@
 #define DEFAULT_CALLEVENTS     FALSE    /*!< Extra manager SIP call events */
 #define DEFAULT_ALWAYSAUTHREJECT  TRUE  /*!< Don't reject authentication requests always */
 #define DEFAULT_AUTH_OPTIONS  FALSE
+#define DEFAULT_AUTH_MESSAGE  TRUE
+#define DEFAULT_ACCEPT_OUTOFCALL_MESSAGE TRUE
 #define DEFAULT_REGEXTENONQUALIFY FALSE
 #define DEFAULT_T1MIN             100   /*!< 100 MS for minimal roundtrip time */
 #define DEFAULT_MAX_CALL_BITRATE (384)  /*!< Max bitrate for video */
@@ -676,6 +678,8 @@
 	int allowguest;             /*!< allow unauthenticated peers to connect? */
 	int alwaysauthreject;       /*!< Send 401 Unauthorized for all failing requests */
 	int auth_options_requests;  /*!< Authenticate OPTIONS requests */
+	int auth_message_requests;  /*!< Authenticate MESSAGE requests */
+	int accept_outofcall_message; /*!< Accept MESSAGE outside of a call */
 	int compactheaders;         /*!< send compact sip headers */
 	int allow_external_domains; /*!< Accept calls to external SIP domains? */
 	int callevents;             /*!< Whether we send manager events or not */

Modified: team/russell/messaging/configs/sip.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/configs/sip.conf.sample?view=diff&rev=297488&r1=297487&r2=297488
==============================================================================
--- team/russell/messaging/configs/sip.conf.sample (original)
+++ team/russell/messaging/configs/sip.conf.sample Thu Dec  2 15:50:00 2010
@@ -372,6 +372,16 @@
 
 ;auth_options_requests = yes    ; Enabling this option will authenticate OPTIONS requests just like
                                 ; INVITE requests are.  By default this option is disabled.
+
+;accept_outofcall_message = no  ; Disable this option to reject all MESSAGE requests outside of a
+                                ; call.  By default, this option is enabled.  When enabled, MESSAGE
+                                ; requests are passed in to the dialplan.
+
+;auth_message_requests = yes    ; Enabling this option will authenticate MESSAGE requests.
+                                ; By default this option is enabled.  However, it can be disabled
+                                ; should an application desire to not load the Asterisk server with
+                                ; doing authentication and implement end to end security in the
+                                ; message body.
 
 ;g726nonstandard = yes          ; If the peer negotiates G726-32 audio, use AAL2 packing
                                 ; order instead of RFC3551 packing order (this is required

Modified: team/russell/messaging/doc/asterisk-messaging.txt
URL: http://svnview.digium.com/svn/asterisk/team/russell/messaging/doc/asterisk-messaging.txt?view=diff&rev=297488&r1=297487&r2=297488
==============================================================================
--- team/russell/messaging/doc/asterisk-messaging.txt (original)
+++ team/russell/messaging/doc/asterisk-messaging.txt Thu Dec  2 15:50:00 2010
@@ -246,6 +246,13 @@
 --- 6) TODO / Ideas / Future Improvements
 --------------------------------------------------------------------------------
 
+Documentation:
+    -> Clearly document architectural approach to different types of text
+       messaging:
+         - one-off messages like SMS, most IMs
+         - session based IMs, like SIP with MSRP
+         - T.140 text streams, other text within a call
+
 Core:
 
     -> Add local: URI support which could be used with MessageSend() to allow an
@@ -257,11 +264,9 @@
 
     -> Use stringfields (for fields where it is appropriate)
 
+    -> Consider character set issues.
+
 SIP (chan_sip):
-
-    -> Make routing MESSAGE through the dialplan optional.
-    
-    -> Add optional authentication for MESSAGE.
 
     -> Should SIPAddHeader() support adding headers for outbound messages, too?
        Alternatively, should a separate application be created which allows




More information about the svn-commits mailing list