Merged revisions 280552 via svnmerge from
authorDavid Vossel <dvossel@digium.com>
Thu, 29 Jul 2010 20:44:37 +0000 (20:44 +0000)
committerDavid Vossel <dvossel@digium.com>
Thu, 29 Jul 2010 20:44:37 +0000 (20:44 +0000)
https://origsvn.digium.com/svn/asterisk/branches/1.8

................
  r280552 | dvossel | 2010-07-29 15:43:47 -0500 (Thu, 29 Jul 2010) | 17 lines

  Merged revisions 280551 via svnmerge from
  https://origsvn.digium.com/svn/asterisk/branches/1.6.2

  ........
    r280551 | dvossel | 2010-07-29 15:42:29 -0500 (Thu, 29 Jul 2010) | 11 lines

    fixes wrong SRV query for TLS connection

    (closes issue #17612)
    Reported by: marcelloceschia
    Patches:
          chan-sip_srvQuery.patch uploaded by marcelloceschia (license 1079)
          chan-sip_Trunk_srvQuery.patch uploaded by st (license 907)
          chan-sip_asterisk18b1_srvQuery.patch uploaded by marcelloceschia (license 1079)
    Tested by: marcelloceschia, st, pabelanger
  ........
................

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@280553 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_sip.c

index 6e825b0..38b1974 100644 (file)
@@ -3004,6 +3004,33 @@ static inline const char *get_transport(enum sip_transport t)
        return "UNKNOWN";
 }
 
+/*! \brief Return protocol string for srv dns query */
+static inline const char *get_srv_protocol(enum sip_transport t)
+{
+       switch (t) {
+       case SIP_TRANSPORT_UDP:
+               return "udp";
+       case SIP_TRANSPORT_TLS:
+       case SIP_TRANSPORT_TCP:
+               return "tcp";
+       }
+
+       return "udp";
+}
+
+/*! \brief Return service string for srv dns query */
+static inline const char *get_srv_service(enum sip_transport t)
+{
+       switch (t) {
+       case SIP_TRANSPORT_TCP:
+       case SIP_TRANSPORT_UDP:
+               return "sip";
+       case SIP_TRANSPORT_TLS:
+               return "sips";
+       }
+       return "sip";
+}
+
 /*! \brief Return transport of dialog.
        \note this is based on a false assumption. We don't always use the
        outbound proxy for all requests in a dialog. It depends on the
@@ -4971,7 +4998,9 @@ static int create_addr(struct sip_pvt *dialog, const char *opeer, struct ast_soc
                 * an A record lookup should be used instead of SRV.
                 */
                if (!hostport.port && sip_cfg.srvlookup) {
-                       snprintf(service, sizeof(service), "_sip._%s.%s", get_transport(dialog->socket.type), peername);
+                       snprintf(service, sizeof(service), "_%s._%s.%s", 
+                                get_srv_service(dialog->socket.type),
+                                get_srv_protocol(dialog->socket.type), peername);
                        if ((srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno,
                                                   service)) > 0) {
                                hostn = host;
@@ -11385,7 +11414,7 @@ static int __sip_subscribe_mwi_do(struct sip_subscription_mwi *mwi)
        /* If we have no DNS manager let's do a lookup */
        if (!mwi->dnsmgr) {
                char transport[MAXHOSTNAMELEN];
-               snprintf(transport, sizeof(transport), "_sip._%s", get_transport(mwi->transport));
+               snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(mwi->transport), get_srv_protocol(mwi->transport));
 
                mwi->us.ss.ss_family = get_address_family_filter(&bindaddr); /* Filter address family */
                ast_dnsmgr_lookup(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL);
@@ -12119,7 +12148,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, const char *
        if (r->dnsmgr == NULL) {
                char transport[MAXHOSTNAMELEN];
                peer = find_peer(r->hostname, NULL, TRUE, FINDPEERS, FALSE, 0);
-               snprintf(transport, sizeof(transport), "_sip._%s", get_transport(r->transport)); /* have to use static get_transport function */
+               snprintf(transport, sizeof(transport), "_%s._%s",get_srv_service(r->transport), get_srv_protocol(r->transport)); /* have to use static get_transport function */
                r->us.ss.ss_family = get_address_family_filter(&bindaddr); /* Filter address family */
                ast_dnsmgr_lookup(peer ? peer->tohost : r->hostname, &r->us, &r->dnsmgr, sip_cfg.srvlookup ? transport : NULL);
                if (peer) {
@@ -25960,7 +25989,7 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
                        *params++ = '\0';
                }
 
-               snprintf(transport, sizeof(transport), "_sip._%s", get_transport(peer->socket.type));
+               snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(peer->socket.type), get_srv_protocol(peer->socket.type));
 
                peer->addr.ss.ss_family = get_address_family_filter(&bindaddr); /* Filter address family */
                if (ast_dnsmgr_lookup(_srvlookup, &peer->addr, &peer->dnsmgr, sip_cfg.srvlookup && !peer->portinuri ? transport : NULL)) {