[Asterisk-Dev] SIP: Problem in recent Contact changes - results in peer context being ignored

Stephen Davies steve at daviesfam.org
Tue Apr 8 12:03:54 MST 2003


Hi Mark,

You've been moving things around in the chan_sip.c code, with the result
that you are now calling get_destination(), which needs the
sip_pvt->context, before you call check_user which copies the context from
the sip_user struct over into sip_pvt.

The result is that numbers dialled are always in the global context rather
than the context for the particular peer.

For instance:

                if (!p->lastinvite) {
                        /* Get destination right away */
                        gotdest = get_destination(p, NULL);
                        build_contact(p);
                        /* Handle authentication if this is our first invite */
                        res = check_user(p, req, cmd, e, 1);
                        if (res) {
                                if (res < 0) {
                                        ast_log(LOG_NOTICE, "Failed to authenticate user %s\n", get_header(req, "From"));
                                        p->needdestroy = 1;
                                }
                                return 0;
                        }


Similar problem when handling SUBSCRIBE.

Here's a patch that seems to fix but I'm not quite sure what your
objective was with moving things around and my patch makes the code a bit
less than elegant.

Regards,
Steve
-------------- next part --------------
Index: channels/chan_sip.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v
retrieving revision 1.55
diff -u -r1.55 chan_sip.c
--- channels/chan_sip.c	8 Apr 2003 15:00:57 -0000	1.55
+++ channels/chan_sip.c	8 Apr 2003 19:11:26 -0000
@@ -4084,11 +4084,11 @@
 		} else if (sipdebug)
 			ast_verbose("Ignoring this request\n");
 		if (!p->lastinvite) {
+			/* Handle authentication if this is our first invite */
+			res = check_user(p, req, cmd, e, 1);
 			/* Get destination right away */
 			gotdest = get_destination(p, NULL);
 			build_contact(p);
-			/* Handle authentication if this is our first invite */
-			res = check_user(p, req, cmd, e, 1);
 			if (res) {
 				if (res < 0) {
 					ast_log(LOG_NOTICE, "Failed to authenticate user %s\n", get_header(req, "From"));
@@ -4225,11 +4225,11 @@
 			ast_verbose("Ignoring this request\n");
 			
 		if (!p->lastinvite) {
+			/* Handle authentication if this is our first subscribe */
+			res = check_user(p, req, cmd, e, 0);
 			/* Get destination right away */
 			gotdest = get_destination(p, NULL);
 			build_contact(p);
-			/* Handle authentication if this is our first subscribe */
-			res = check_user(p, req, cmd, e, 0);
 			if (res) {
 				if (res < 0) {
 					ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From"));


More information about the asterisk-dev mailing list