[asterisk-commits] oej: branch oej/obproxy r173847 - in /team/oej/obproxy: ./ channels/chan_sip.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Feb 6 04:15:50 CST 2009
Author: oej
Date: Fri Feb 6 04:15:50 2009
New Revision: 173847
URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=173847
Log:
Reset automerge, resolve conflicts
Modified:
team/oej/obproxy/ (props changed)
team/oej/obproxy/channels/chan_sip.c
Propchange: team/oej/obproxy/
------------------------------------------------------------------------------
automerge = http://www.codename-pineapple.org/
Propchange: team/oej/obproxy/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Fri Feb 6 04:15:50 2009
@@ -1,1 +1,1 @@
-/branches/1.4:1-173732
+/branches/1.4:1-173843
Modified: team/oej/obproxy/channels/chan_sip.c
URL: http://svn.digium.com/svn-view/asterisk/team/oej/obproxy/channels/chan_sip.c?view=diff&rev=173847&r1=173846&r2=173847
==============================================================================
--- team/oej/obproxy/channels/chan_sip.c (original)
+++ team/oej/obproxy/channels/chan_sip.c Fri Feb 6 04:15:50 2009
@@ -1192,6 +1192,7 @@
int refresh; /*!< How often to refresh */
struct sip_pvt *call; /*!< create a sip_pvt structure for each outbound "registration dialog" in progress */
enum sipregistrystate regstate; /*!< Registration state (see above) */
+ unsigned int needdns:1; /*!< Set if we need a new dns lookup before we try to transmit */
time_t regtime; /*!< Last succesful registration time */
int callid_valid; /*!< 0 means we haven't chosen callid for this registry yet. */
unsigned int ocseq; /*!< Sequence number we got to for REGISTERs for this registry */
@@ -1529,7 +1530,7 @@
static const struct sockaddr_in *sip_real_dst(const struct sip_pvt *p);
static void build_via(struct sip_pvt *p);
static int create_addr_from_peer(struct sip_pvt *r, struct sip_peer *peer);
-static int create_addr(struct sip_pvt *dialog, const char *opeer);
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin);
static char *generate_random_string(char *buf, size_t size);
static void build_callid_pvt(struct sip_pvt *pvt);
static void build_callid_registry(struct sip_registry *reg, struct in_addr ourip, const char *fromdomain);
@@ -1883,7 +1884,14 @@
case ECONNREFUSED: /* ICMP port unreachable */
res = XMIT_ERROR; /* Don't bother with trying to transmit again */
}
- }
+
+ if (p->registry && p->registry->regstate < REG_STATE_REGISTERED) {
+ AST_SCHED_DEL(sched, p->registry->timeout);
+ p->registry->needdns = TRUE;
+ p->registry->timeout = ast_sched_add(sched, 1, sip_reg_timeout, p->registry);
+ }
+ }
+
if (res != len)
ast_log(LOG_WARNING, "sip_xmit of %p (len %d) to %s:%d returned %d: %s\n", data, len, ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), res, strerror(errno));
return res;
@@ -3002,7 +3010,7 @@
/*! \brief create address structure from peer name
* Or, if peer not found, find it in the global DNS
* returns TRUE (-1) on failure, FALSE on success */
-static int create_addr(struct sip_pvt *dialog, const char *opeer)
+static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin)
{
struct hostent *hp;
struct ast_hostent ahp;
@@ -3041,26 +3049,38 @@
/* Let's see if we can find the host in DNS. First try DNS SRV records,
then hostname lookup
*/
- hostn = peer;
- portno = port ? atoi(port) : STANDARD_SIP_PORT;
- if (srvlookup) {
- char service[MAXHOSTNAMELEN];
- int tportno;
- int ret;
-
- snprintf(service, sizeof(service), "_sip._udp.%s", peer);
- ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service);
- if (ret > 0) {
- hostn = host;
- portno = tportno;
- }
- }
- hp = ast_gethostbyname(hostn, &ahp);
- if (!hp) {
- ast_log(LOG_WARNING, "No such host: %s\n", peer);
- return -1;
- }
- memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
+
+ if (sin) {
+ memcpy(&dialog->sa.sin_addr, &sin->sin_addr, sizeof(dialog->sa.sin_addr));
+ if (!sin->sin_port) {
+ if (ast_strlen_zero(port) || sscanf(port, "%u", &portno) != 1) {
+ portno = STANDARD_SIP_PORT;
+ }
+ } else {
+ portno = ntohs(sin->sin_port);
+ }
+ } else {
+ hostn = peer;
+ portno = port ? atoi(port) : STANDARD_SIP_PORT;
+ if (srvlookup) {
+ char service[MAXHOSTNAMELEN];
+ int tportno;
+ int ret;
+
+ snprintf(service, sizeof(service), "_sip._udp.%s", peer);
+ ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service);
+ if (ret > 0) {
+ hostn = host;
+ portno = tportno;
+ }
+ }
+ hp = ast_gethostbyname(hostn, &ahp);
+ if (!hp) {
+ ast_log(LOG_WARNING, "No such host: %s\n", peer);
+ return -1;
+ }
+ memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr));
+ }
dialog->sa.sin_port = htons(portno);
dialog->recv = dialog->sa;
return 0;
@@ -4920,6 +4940,7 @@
reg->portno = portnum;
reg->callid_valid = FALSE;
reg->ocseq = INITIAL_CSEQ;
+ reg->needdns = TRUE;
ASTOBJ_CONTAINER_LINK(®l, reg); /* Add the new registry entry to the list */
ASTOBJ_UNREF(reg,sip_registry_destroy);
return 0;
@@ -7750,6 +7771,7 @@
} else {
r->regstate = REG_STATE_UNREGISTERED;
r->timeout = -1;
+ r->needdns = TRUE;
res=transmit_register(r, SIP_REGISTER, NULL, NULL);
}
manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelDriver: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate));
@@ -7801,8 +7823,9 @@
p->outboundproxy = obproxy_get(p, NULL);
- /* Find address to hostname */
- if (create_addr(p, r->hostname)) {
+ /* Find address to hostname if we haven't tried to connect
+ * or a connection error has occurred */
+ if (create_addr(p, r->hostname, r->needdns ? NULL : &r->us)) {
/* we have what we hope is a temporary network error,
* probably DNS. We need to reschedule a registration try */
sip_destroy(p);
@@ -7817,6 +7840,10 @@
r->regattempts++;
return 0;
}
+ if (r->needdns) {
+ memcpy(&r->us, &p->sa, sizeof(r->us));
+ }
+ r->needdns = FALSE;
/* Copy back Call-ID in case create_addr changed it */
ast_string_field_set(r, callid, p->callid);
if (r->portno) {
@@ -11679,7 +11706,7 @@
return RESULT_FAILURE;
}
- if (create_addr(p, argv[i])) {
+ if (create_addr(p, argv[i], NULL)) {
/* Maybe they're not registered, etc. */
sip_destroy(p);
ast_cli(fd, "Could not create address for '%s'\n", argv[i]);
@@ -16798,7 +16825,7 @@
host = tmp;
}
- if (create_addr(p, host)) {
+ if (create_addr(p, host, NULL)) {
*cause = AST_CAUSE_UNREGISTERED;
if (option_debug > 2)
ast_log(LOG_DEBUG, "Cant create SIP call - target device not registred\n");
More information about the asterisk-commits
mailing list