[asterisk-commits] oej: branch oej/libmidcom-new r48347 - /team/oej/libmidcom-new/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Dec 7 01:47:06 MST 2006


Author: oej
Date: Thu Dec  7 02:47:06 2006
New Revision: 48347

URL: http://svn.digium.com/view/asterisk?view=rev&rev=48347
Log:
More cleanups, still doesn't compile cleanly

Modified:
    team/oej/libmidcom-new/res_netsec.c
    team/oej/libmidcom-new/res_netsec.h

Modified: team/oej/libmidcom-new/res_netsec.c
URL: http://svn.digium.com/view/asterisk/team/oej/libmidcom-new/res_netsec.c?view=diff&rev=48347&r1=48346&r2=48347
==============================================================================
--- team/oej/libmidcom-new/res_netsec.c (original)
+++ team/oej/libmidcom-new/res_netsec.c Thu Dec  7 02:47:06 2006
@@ -37,6 +37,9 @@
  *  - fix autoconfigure to set MIDCOM_EXISTS flag if libmidcom is installed
 */
 
+/*** MODULEINFO
+        <depend>libmidcom</depend>
+ ***/
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -76,6 +79,8 @@
 static char cert[512];
 static char* config = "midcom.conf";
 static int midcom_enabled = 1;
+static int told_them_that_midcom_is_not_enabled = 0;
+
 
 static int usecnt = 0;
 AST_MUTEX_DEFINE_STATIC(usecnt_lock);
@@ -187,12 +192,12 @@
 static void midcom_get_vredirip_video_hook(void *r, struct sockaddr_in *vredirip);
 static void midcom_rtp_get_their_nat_audio_hook(struct ast_rtp *rtp, void *r);
 static void midcom_rtp_get_their_nat_video_hook(struct ast_rtp *vrtp, void *r);
-static void midcom_sip_helper_register(struct ast_sip_helper_cb *cb);
+static void midcom_sip_helper_register(struct ast_rtp_helper_cb *cb);
 static void midcom_sip_helper_unregister(void);
 
 static struct midcom_rule *get_peer_rule(struct midcom_rule *r);
 
-static struct ast_sip_helper_cb *channel_cb = NULL;
+static struct ast_rtp_helper_cb *channel_cb = NULL;
 
 struct ast_sip_hook_cb *midcom_cb = NULL; /*move this to the core asterisk files */
 
@@ -250,7 +255,7 @@
 };
 
 /*! \brief Register callback function */
-static void midcom_sip_helper_register(struct ast_sip_helper_cb *cb)
+static void midcom_sip_helper_register(struct ast_rtp_helper_cb *cb)
 {
 	channel_cb = cb;
 }
@@ -344,19 +349,12 @@
 	return 0;
 }
 
-int usecount()
-{
-	return usecnt;
-}
-
-char *key()
-{
-	return ASTERISK_GPL_KEY;
-}
-
-char *description()
-{
-	return (char *) desc;
+static void midcom_warning(void)
+{
+	if(!told_them_that_midcom_is_not_enabled ) {
+		ast_log(LOG_WARNING, "Midcom: Module not enabled\n");
+		told_them_that_midcom_is_not_enabled = 1;
+	}
 }
 
 /*! \brief Turn on Midcom firewall (CLI command) */
@@ -394,7 +392,6 @@
 
 	struct midcom_rule *r = midcom_rule_head;
 	char name[256];
-	char iabuf1[INET_ADDRSTRLEN], iabuf2[INET_ADDRSTRLEN], iabuf3[INET_ADDRSTRLEN];
 	struct ast_channel *peer_chan;
 	struct midcom_rule *peer_rule;
 	struct sockaddr_in peer_ip;
@@ -451,11 +448,11 @@
 		  strncpy(status, "Deleted", sizeof(status));
 
 		ast_cli(fd, FORMAT, name, 
-		r->our_internal_addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_internal_addr.sin_addr) : "(Unspecified)",
+		r->our_internal_addr.sin_addr.s_addr ? ast_inet_ntoa(r->our_internal_addr.sin_addr) : "(Unspecified)",
 		ntohs(r->our_internal_addr.sin_port),
-		r->our_natted_addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf2, sizeof(iabuf2), r->our_natted_addr.sin_addr) : "(Unspecified)",
+		r->our_natted_addr.sin_addr.s_addr ? ast_inet_ntoa(r->our_natted_addr.sin_addr) : "(Unspecified)",
 		ntohs(r->our_natted_addr.sin_port),
-		peer_ip.sin_addr.s_addr ? ast_inet_ntoa(iabuf3, sizeof(iabuf3), peer_ip.sin_addr) : "(Unspecified)",
+		peer_ip.sin_addr.s_addr ? ast_inet_ntoa( peer_ip.sin_addr) : "(Unspecified)",
 		ntohs(peer_ip.sin_port),
 		"Audio",
 		status);
@@ -463,11 +460,11 @@
 
 		   peer_ip = peer_rule->our_natted_vaddr;
 		   ast_cli(fd, FORMAT, name, 
-		r->our_internal_vaddr.sin_addr.s_addr ? ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_internal_vaddr.sin_addr) : "(Unspecified)",
+		r->our_internal_vaddr.sin_addr.s_addr ? ast_inet_ntoa(r->our_internal_vaddr.sin_addr) : "(Unspecified)",
 		ntohs(r->our_internal_vaddr.sin_port),
-		r->our_natted_vaddr.sin_addr.s_addr ? ast_inet_ntoa(iabuf2, sizeof(iabuf2), r->our_natted_vaddr.sin_addr) : "(Unspecified)",
+		r->our_natted_vaddr.sin_addr.s_addr ? ast_inet_ntoa(r->our_natted_vaddr.sin_addr) : "(Unspecified)",
 		ntohs(r->our_natted_vaddr.sin_port),
-		peer_ip.sin_addr.s_addr ? ast_inet_ntoa(iabuf3, sizeof(iabuf3), peer_ip.sin_addr) : "(Unspecified)",
+		peer_ip.sin_addr.s_addr ? ast_inet_ntoa(peer_ip.sin_addr) : "(Unspecified)",
 		ntohs(peer_ip.sin_port),
 		"Video",
 		status);
@@ -530,83 +527,84 @@
 	struct connection *conn, *curr, *prev = NULL;
 	struct ast_variable *v;
 	int dupl = 0;
-	char iabuf[INET_ADDRSTRLEN];
+
+	told_them_that_midcom_is_not_enabled = 0;	/* Reset */
 
 	cfg = ast_config_load(config);
 	if (cfg) {
 		if ((s = ast_variable_retrieve(cfg, "general", "midcomnat"))) {
-		  if (!strcasecmp(s, "nearend"))
-	midcomnat = NEAREND;
-		  else if (!strcasecmp(s, "farend"))
-	midcomnat = FAREND;
-		  else {
-	midcomnat = NO_MIDCOM;
-	midcom_enabled = 0;
-		  }
+			if (!strcasecmp(s, "nearend"))
+			midcomnat = NEAREND;
+			else if (!strcasecmp(s, "farend"))
+			midcomnat = FAREND;
+			else {
+			midcomnat = NO_MIDCOM;
+			midcom_enabled = 0;
+			}
 		}
 		if ((s = ast_variable_retrieve(cfg, "general", "certificate"))) {
-		  ast_copy_string(cert, s, sizeof(cert));
+			ast_copy_string(cert, s, sizeof(cert));
 		}
 		if ((s = ast_variable_retrieve(cfg, "general", "lb"))) {
 		}
 
 		cat = ast_category_browse(cfg, NULL);
 		while (cat) {
-		  if (strcasecmp(cat, "general")) {
+			if (strcasecmp(cat, "general")) {
 	utype = ast_variable_retrieve(cfg, cat, "type");
 	if (utype) {
-	  if (!strcasecmp(utype, "midbox")) {
-	    conn = (struct connection*)malloc(sizeof(struct connection));
-	    if (!conn)
-	      break;
-	    memset(conn, 0, sizeof(struct connection));
-	    ast_copy_string(conn->name, cat, sizeof(conn->name));
-	    v = ast_variable_browse(cfg, cat);
-	    while (v) {
-	      if (!strcasecmp(v->name, "ip")) {
+		if (!strcasecmp(utype, "midbox")) {
+			conn = (struct connection*)malloc(sizeof(struct connection));
+			if (!conn)
+				break;
+			memset(conn, 0, sizeof(struct connection));
+			ast_copy_string(conn->name, cat, sizeof(conn->name));
+			v = ast_variable_browse(cfg, cat);
+			while (v) {
+				if (!strcasecmp(v->name, "ip")) {
 		inet_aton(v->value, &(conn->ipaddress));
-	      } else if (!strcasecmp(v->name, "username")) {
+				} else if (!strcasecmp(v->name, "username")) {
 		ast_copy_string(conn->username, v->value, sizeof(conn->username));
-	      } else if (!strcasecmp(v->name, "password")) {
+				} else if (!strcasecmp(v->name, "password")) {
 		ast_copy_string(conn->password, v->value, sizeof(conn->password));
-	      } else if (!strcasecmp(v->name, "transport")) {
+				} else if (!strcasecmp(v->name, "transport")) {
 		if (!strcasecmp(v->value, "tls"))
-		  conn->tls = 1;
-	      } else if (!strcasecmp(v->name, "mode")) {
+			conn->tls = 1;
+				} else if (!strcasecmp(v->name, "mode")) {
 		if (!strcasecmp(v->value, "farend"))
-		  conn->mode = FAREND;
+			conn->mode = FAREND;
 		else
-		  conn->mode = NEAREND;
-	      }
-	      v= v->next;
-	    }
-
-	    prev = NULL;
-	    curr = connl;
-	    while (curr) {
-	      if (curr->ipaddress.s_addr == conn->ipaddress.s_addr) {
+			conn->mode = NEAREND;
+				}
+				v= v->next;
+			}
+
+			prev = NULL;
+			curr = connl;
+			while (curr) {
+				if (curr->ipaddress.s_addr == conn->ipaddress.s_addr) {
 		dupl = 1;
 		break;
-	      }
-	      prev = curr;
-	      curr = curr->next;
-	    }
-	    if (!dupl) {
-	      if (!prev)
+				}
+				prev = curr;
+				curr = curr->next;
+			}
+			if (!dupl) {
+				if (!prev)
 		connl = conn;
-	      else
+				else
 		prev->next = conn;
 
-	    } else {
-	      ast_log(LOG_NOTICE, "Ignoring device '%s' as %s is already defined before.", cat, ast_inet_ntoa(iabuf, sizeof(iabuf), conn->ipaddress));
-	    }
-	  } else {
-	    ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config);
-	  }
+			} else {
+				ast_log(LOG_NOTICE, "Ignoring device '%s' as %s is already defined before.", cat, ast_inet_ntoa(conn->ipaddress));
+			}
+		} else {
+			ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, config);
+		}
 	} else
-	  ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
-		  }
-		  cat = ast_category_browse(cfg, cat);
+		ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
+			}
+			cat = ast_category_browse(cfg, cat);
 		}
 		ast_config_destroy(cfg);
 	} else {
@@ -640,21 +638,18 @@
 static int midcom_handle_request_invite_hook(void *p)
 {
 	struct sockaddr_in caller;
-	char iabuf[INET_ADDRSTRLEN];
 	struct midcom_rule *r = NULL;
 
 	if (!midcom_enabled) {
 		if (option_debug > 1)
-			ast_log(LOG_DEBUG, "Midcom: Module not enabled\n");
-		if (option_verbose > 1)
-		  ast_verbose("Midcom: Module currently disabled\n");
+		midcom_warning();
 		return 1;
 	}
 
 	if (!channel_cb) {
 		ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
 		if (option_verbose > 1)
-		   ast_verbose("Midcom: Error!! - Module not initialized\n");
+			 ast_verbose("Midcom: Error!! - Module not initialized\n");
 		return 0;
 	}
 
@@ -666,74 +661,71 @@
 
 		if (channel_cb->ast_cmp_sa_addr(p, &caller)) { /* not forwarded from another softswitch */
 
-		  r = midcom_rule_alloc(p);
-		  if (r == NULL)
+			r = midcom_rule_alloc(p);
+			if (r == NULL)
 	return 0;
-		  /* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
-		  if ( get_lb_midbox_ip(&r->midbox_addr) == -1)
+			/* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
+			if ( get_lb_midbox_ip(&r->midbox_addr) == -1)
 	return 0;
-		  
-		  if (!r->nat_done) {
+			
+			if (!r->nat_done) {
 	if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
-	  if (midcom_reserve_nat(r->con, &r->ruleid, &r->our_natted_addr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
-	    free(r);
-	    return 0;
-	  }
-
-	  if (!r->novideo) {
-	    if (midcom_reserve_nat(r->con, &r->vruleid, &r->our_natted_vaddr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
-	      free(r);
-	      return 0;
-	    }
-	  }
-	  
+		if (midcom_reserve_nat(r->con, &r->ruleid, &r->our_natted_addr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
+			free(r);
+			return 0;
+		}
+
+		if (!r->novideo) {
+			if (midcom_reserve_nat(r->con, &r->vruleid, &r->our_natted_vaddr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
+				free(r);
+				return 0;
+			}
+		}
+		
 	} else {
-	  ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), r->midbox_addr));
-	  free(r);
-	  return 0;
-	}
-		  }
-		  
-		  r->nat_done = 1;
-
-		  ast_mutex_lock(&usecnt_lock);
-		  usecnt++;
-		  ast_mutex_unlock(&usecnt_lock);      
-		  ast_update_use_count();
-
-		  channel_cb->ast_map_hook_struct(p, (void *)r);
-		  r->p = p;
-		  r->next = midcom_rule_head;
-		  midcom_rule_head = r;
+		ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(r->midbox_addr));
+		free(r);
+		return 0;
+	}
+			}
+			
+			r->nat_done = 1;
+
+			ast_mutex_lock(&usecnt_lock);
+			usecnt++;
+			ast_mutex_unlock(&usecnt_lock);			
+			ast_update_use_count();
+
+			channel_cb->ast_map_hook_struct(p, (void *)r);
+			r->p = p;
+			r->next = midcom_rule_head;
+			midcom_rule_head = r;
 
 		} else {
-		  /* The caller might be forwarded from another softswitch */;
+			/* The caller might be forwarded from another softswitch */;
 		}
 	}
 	else
 		{
-		  /* farend */
-		  r = NULL;
+			/* farend */
+			r = NULL;
 		}
 	return 1;
 }
 
 static int midcom_handle_response_invite_hook(void *p)
 {
-	char iabuf[INET_ADDRSTRLEN];
 	struct midcom_rule *r = NULL;
 
 	if (!midcom_enabled) {
-		ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
-		if (option_verbose > 1)
-		   ast_verbose("Midcom: Module currently disabled\n");
+		midcom_warning();
 		return 1;
 	}
 
 	if (!channel_cb) {
 		ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
 		if (option_verbose > 1)
-		   ast_verbose("Midcom: Error!! - Module not initialized\n");
+			 ast_verbose("Midcom: Error!! - Module not initialized\n");
 		return 0;
 	}
 
@@ -758,65 +750,65 @@
 
 	if (is_nearend_nat())
 		{
-		  if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
+			if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
 	if (midcom_reserve_nat(r->con, &r->ruleid, &r->our_natted_addr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
-	  ast_log(LOG_NOTICE, "Failed to NAT user %s for audio\n", r->username);
-	  free(r);
-	  return 0;
+		ast_log(LOG_NOTICE, "Failed to NAT user %s for audio\n", r->username);
+		free(r);
+		return 0;
 	}
 	
 	if (!r->novideo) {
-	  if (midcom_reserve_nat(r->con, &r->vruleid, &r->our_natted_vaddr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
-	    ast_log(LOG_NOTICE, "Failed to NAT user %s for video\n", r->username);
-	    free(r);
-	    return 0;
-	  }
+		if (midcom_reserve_nat(r->con, &r->vruleid, &r->our_natted_vaddr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
+			ast_log(LOG_NOTICE, "Failed to NAT user %s for video\n", r->username);
+			free(r);
+			return 0;
+		}
 	}
 	
 	r->nat_done = 1;
-		  
-		  } else {
-	ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), r->midbox_addr));
+			
+			} else {
+	ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(r->midbox_addr));
 	free(r);
 	return 0;
-		  }
-		  
+			}
+			
 		}
 	else 
 		{
-		  /* farend */
-		  struct sockaddr_in sin;
-		  struct sockaddr_in vsin;
-		  int codec = 0;
-
-		  if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
+			/* farend */
+			struct sockaddr_in sin;
+			struct sockaddr_in vsin;
+			int codec = 0;
+
+			if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
 	channel_cb->ast_rtp_get_us_audio_helper(p, &sin);
 	if (!r->novideo)
-	  channel_cb->ast_rtp_get_us_video_helper(p, &vsin);
+		channel_cb->ast_rtp_get_us_video_helper(p, &vsin);
 	
 	codec = channel_cb->ast_get_capability_helper(p);
 	if (midcom_open_firewall(r->con, &r->ruleid, &r->our_internal_addr, &sin, &r->lifetime, (codec & 0x0000FFFF)) != 0) {
-	  free(r);
-	  r = NULL;
-	  return 0;
+		free(r);
+		r = NULL;
+		return 0;
 	}
 	if (!r->novideo) {
-	  if (midcom_open_firewall(r->con, &r->vruleid, &r->our_internal_vaddr, &vsin, &r->lifetime, (codec & 0xFFFF0000)) != 0) {
-	    free(r);
-	    r = NULL;
-	    return 0;
-	  }
+		if (midcom_open_firewall(r->con, &r->vruleid, &r->our_internal_vaddr, &vsin, &r->lifetime, (codec & 0xFFFF0000)) != 0) {
+			free(r);
+			r = NULL;
+			return 0;
+		}
 	}
 
 	r->firewall_done = 1;
 	midcom_disconnect(r->con, r->is_cached);
 	timer_setup_tick(r, sizeof(struct midcom_rule), r->lifetime, &r->timer_handle);
 
-		  } else {
-		  ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), r->midbox_addr));
-		  free(r);
-		  return 0;
-		  }
+			} else {
+			ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(r->midbox_addr));
+			free(r);
+			return 0;
+			}
 		
 		}
 
@@ -835,23 +827,20 @@
 
 static int midcom_transmit_response_with_sdp_hook(void *p)
 {
-	char iabuf[INET_ADDRSTRLEN];
 	struct midcom_rule *r = NULL;
 	struct sockaddr_in sin;
 	struct sockaddr_in vsin;
 	int codec = 0;
 
 	if (!midcom_enabled) {
-		ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
-		if (option_verbose > 1)
-		  ast_verbose("Midcom: Module currently disabled\n");
+		midcom_warning();
 		return 1;
 	}
 
 	if (!channel_cb) {
 		ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
 		if (option_verbose > 1)
-		   ast_verbose("Midcom: Error!! - Module not initialized\n");
+			 ast_verbose("Midcom: Error!! - Module not initialized\n");
 		return 0;
 	}
 
@@ -860,68 +849,67 @@
 
 	if (is_farend_nat())
 		{
-		  r = midcom_rule_alloc(p);
-		  if (r == NULL)
+			r = midcom_rule_alloc(p);
+			if (r == NULL)
 	return 0;
-		  
-		  if (!r->username[0])
-		  strncpy(r->username, channel_cb->ast_get_username(p), 256);
-
-		  if (option_verbose > 1)
-		    ast_verbose("Midcom: Allocating new rule for phone: %s\n", r->username);
-		  /* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
-		  if ( get_lb_midbox_ip(&r->midbox_addr) == -1)
-		    return 0;
+			
+			if (!r->username[0])
+			strncpy(r->username, channel_cb->ast_get_username(p), 256);
+
+			if (option_verbose > 1)
+				ast_verbose("Midcom: Allocating new rule for phone: %s\n", r->username);
+			/* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
+			if ( get_lb_midbox_ip(&r->midbox_addr) == -1)
+				return 0;
 		
-		  if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
-		  
-		  channel_cb->ast_rtp_get_us_audio_helper(p, &sin);
-		  if (!r->novideo)
+			if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
+			
+			channel_cb->ast_rtp_get_us_audio_helper(p, &sin);
+			if (!r->novideo)
 			 channel_cb->ast_rtp_get_us_video_helper(p, &vsin);
-		  
-		  codec = channel_cb->ast_get_capability_helper(p);
-		  if (midcom_open_firewall(r->con, &r->ruleid, &r->our_internal_addr, &sin, &r->lifetime, (codec & 0x0000FFFF)) != 0) {
-		                     if (option_verbose > 1)
-			   ast_verbose("Midcom: Failed to open dynamic pinhole for Audio stream from phone: %s\n", r->username); 
+			
+			codec = channel_cb->ast_get_capability_helper(p);
+			if (midcom_open_firewall(r->con, &r->ruleid, &r->our_internal_addr, &sin, &r->lifetime, (codec & 0x0000FFFF)) != 0) {
+												 if (option_verbose > 1)
+				 ast_verbose("Midcom: Failed to open dynamic pinhole for Audio stream from phone: %s\n", r->username); 
 			 free(r);
 			 r = NULL;
 			 return 0;
-		  }
-		  if (!r->novideo) {
+			}
+			if (!r->novideo) {
 			 if (midcom_open_firewall(r->con, &r->vruleid, &r->our_internal_vaddr, &vsin, &r->lifetime, (codec & 0xFFFF0000)) != 0) {
-		                            if (option_verbose > 1)
-			           ast_verbose("Midcom: Failed to open dynamic pinhole for Video stream from phone: %s\n", r->username); 
+																if (option_verbose > 1)
+								 ast_verbose("Midcom: Failed to open dynamic pinhole for Video stream from phone: %s\n", r->username); 
 				free(r);
 				r = NULL;
 				return 0;
 			 }
-		  }
-		  } else {
-		  ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), r->midbox_addr));
-		  free(r);
-		  return 0;
-		  }
-		  
-		  r->firewall_done = 1;
-		  midcom_disconnect(r->con, r->is_cached);
-		  timer_setup_tick(r, sizeof(struct midcom_rule), r->lifetime, &r->timer_handle);
-
-		  ast_mutex_lock(&usecnt_lock);
-		  usecnt++;
-		  ast_mutex_unlock(&usecnt_lock);
-		  ast_update_use_count();
-		  
-		  channel_cb->ast_map_hook_struct(p, (void *)r);
-		  r->p = p;
-		  r->next = midcom_rule_head;
-		  midcom_rule_head = r;
+			}
+			} else {
+			ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(r->midbox_addr));
+			free(r);
+			return 0;
+			}
+			
+			r->firewall_done = 1;
+			midcom_disconnect(r->con, r->is_cached);
+			timer_setup_tick(r, sizeof(struct midcom_rule), r->lifetime, &r->timer_handle);
+
+			ast_mutex_lock(&usecnt_lock);
+			usecnt++;
+			ast_mutex_unlock(&usecnt_lock);
+			ast_update_use_count();
+			
+			channel_cb->ast_map_hook_struct(p, (void *)r);
+			r->p = p;
+			r->next = midcom_rule_head;
+			midcom_rule_head = r;
 		}
 	return 1;
 }
 
 static int midcom_transmit_reinvite_with_sdp_hook(void *p)
 {
-	char iabuf[INET_ADDRSTRLEN], iabuf1[INET_ADDRSTRLEN];
 	struct ast_channel *bridgepeer = NULL;
 	struct midcom_rule *r = NULL;
 	int res = -1;
@@ -931,16 +919,14 @@
 	char *username = NULL;
 
 	if (!midcom_enabled) {
-		ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
-		if (option_verbose > 1)
-		  ast_verbose("Midcom: Module currently disabled\n");
+		midcom_warning();
 		return 1;
 	}
 
 	if (!channel_cb) {
 		ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
 		if (option_verbose > 1)
-		  ast_verbose("Midcom: Error!! - Module not initialized\n");
+			ast_verbose("Midcom: Error!! - Module not initialized\n");
 		return 0;
 	}
 
@@ -949,7 +935,7 @@
 		username = channel_cb->ast_get_username(p);
 		ast_log(LOG_ERROR, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", username);
 		if (option_verbose > 1)
-		  ast_verbose("Midcom: Error!! - Unable to retrieve Midcom Rule for phone: %s\n", username);
+			ast_verbose("Midcom: Error!! - Unable to retrieve Midcom Rule for phone: %s\n", username);
 		return 0;
 	}
 
@@ -957,77 +943,77 @@
 
 	if (is_farend)
 		{
-		  if (!r->nat_done)
+			if (!r->nat_done)
 	{
-	  int first_phone = 0;
-
-	  if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
-	    
-	    timer_cancel_tick(r, sizeof(struct midcom_rule));
-	  
-	    midcom_delete_rule(r->con, r->ruleid);
-	    if (!r->novideo)
-	      midcom_delete_rule(r->con, r->vruleid);
-	    r->firewall_done = 0;
-
-	    r->channel = channel_cb->ast_channel_helper(p);
-	    bridgepeer = channel_cb->ast_bridged_channel_helper(p);
-	    first_phone = get_midbox_ip(bridgepeer, &r->midbox_addr, &r->remote_addr, &r->remote_vaddr);
-	    if (first_phone == -1) {
-	      return 0;
-	    }
-	    
-		        peer = get_peer_rule(r);
-		        if (peer == NULL)
+		int first_phone = 0;
+
+		if ((r->midbox_addr.s_addr) && (r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached)) != -1) {
+			
+			timer_cancel_tick(r, sizeof(struct midcom_rule));
+		
+			midcom_delete_rule(r->con, r->ruleid);
+			if (!r->novideo)
+				midcom_delete_rule(r->con, r->vruleid);
+			r->firewall_done = 0;
+
+			r->channel = channel_cb->ast_channel_helper(p);
+			bridgepeer = channel_cb->ast_bridged_channel_helper(p);
+			first_phone = get_midbox_ip(bridgepeer, &r->midbox_addr, &r->remote_addr, &r->remote_vaddr);
+			if (first_phone == -1) {
+				return 0;
+			}
+			
+						peer = get_peer_rule(r);
+						if (peer == NULL)
 		return 0;
 
-	    if (midcom_reserve_nat(r->con, &r->ruleid, &r->our_natted_addr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
-	      ast_log(LOG_NOTICE, "Failed to NAT user %s for audio\n", r->username);
-		          if (option_verbose > 1)
-	         ast_verbose("Midcom: Failed to acquire NAT IP for user %s for audio\n", r->username);
-	      return 0;
-	    }
-
-	    if ((!r->novideo) && (!peer->novideo)) {
-	      if (midcom_reserve_nat(r->con, &r->vruleid, &r->our_natted_vaddr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
+			if (midcom_reserve_nat(r->con, &r->ruleid, &r->our_natted_addr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
+				ast_log(LOG_NOTICE, "Failed to NAT user %s for audio\n", r->username);
+							if (option_verbose > 1)
+					 ast_verbose("Midcom: Failed to acquire NAT IP for user %s for audio\n", r->username);
+				return 0;
+			}
+
+			if ((!r->novideo) && (!peer->novideo)) {
+				if (midcom_reserve_nat(r->con, &r->vruleid, &r->our_natted_vaddr, /*r->enable_rtcp*/ 1, &r->lifetime) != 0) {
 		ast_log(LOG_NOTICE, "Failed to NAT user %s for video\n", r->username);
-		            if (option_verbose > 1)
-		  ast_verbose("Midcom: Failed to acquire NAT IP for user %s for video\n", r->username);
+								if (option_verbose > 1)
+			ast_verbose("Midcom: Failed to acquire NAT IP for user %s for video\n", r->username);
 		return 0;
-	      }
-	    }
-		        else
-		          /* if the peer does not support video, no need for video on our side too */
-		          r->novideo = 1; 
-	  } else {
-	    ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), r->midbox_addr));
-	    return 0;
-	  }
-
-	  r->nat_done = 1;
-
-		      if (option_verbose > 1)
-		        ast_verbose("Midcom: Acquired NAT IP: %s port: %d for phone %s audio stream with Originating IP: %s port: %d\n", ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_natted_addr.sin_addr),  ntohs(r->our_natted_addr.sin_port), r->username, ast_inet_ntoa(iabuf, sizeof(iabuf), r->our_internal_addr.sin_addr), ntohs(r->our_internal_addr.sin_port));
-
-	  if (!r->novideo) {
-		         if (option_verbose > 1)
-		           ast_verbose("Midcom: Acquired NAT IP: %s port: %d for phone %s video stream with Originating IP: %s port: %d\n", ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_natted_vaddr.sin_addr),  ntohs(r->our_natted_vaddr.sin_port), r->username, ast_inet_ntoa(iabuf, sizeof(iabuf), r->our_internal_vaddr.sin_addr), ntohs(r->our_internal_vaddr.sin_port));
-		      }
-	  if (first_phone)
-	    {
-	      /*
-	      bridgepeer->midbox = r->midbox_addr;
-	      bridgepeer->peer_internal_addr = r->our_natted_addr;
-	      bridgepeer->peer_internal_vaddr = r->our_natted_vaddr;
-	      */
-	      r->firewall_done = 1; /* no bridging for the first phone */
-	      midcom_disconnect(r->con, r->is_cached);
-	      timer_setup_tick(r, sizeof(struct midcom_rule), r->lifetime, &r->timer_handle);
-	    }
+				}
+			}
+						else
+							/* if the peer does not support video, no need for video on our side too */
+							r->novideo = 1; 
+		} else {
+			ast_log(LOG_NOTICE, "Failed to connect to %s\n", ast_inet_ntoa(r->midbox_addr));
+			return 0;
+		}
+
+		r->nat_done = 1;
+
+					if (option_verbose > 1)
+						ast_verbose("Midcom: Acquired NAT IP: %s port: %d for phone %s audio stream with Originating IP: %s port: %d\n", ast_inet_ntoa( r->our_natted_addr.sin_addr),	ntohs(r->our_natted_addr.sin_port), r->username, ast_inet_ntoa(r->our_internal_addr.sin_addr), ntohs(r->our_internal_addr.sin_port));
+
+		if (!r->novideo) {
+						 if (option_verbose > 1)
+							 ast_verbose("Midcom: Acquired NAT IP: %s port: %d for phone %s video stream with Originating IP: %s port: %d\n", ast_inet_ntoa(r->our_natted_vaddr.sin_addr),	ntohs(r->our_natted_vaddr.sin_port), r->username, ast_inet_ntoa(r->our_internal_vaddr.sin_addr), ntohs(r->our_internal_vaddr.sin_port));
+					}
+		if (first_phone)
+			{
+				/*
+				bridgepeer->midbox = r->midbox_addr;
+				bridgepeer->peer_internal_addr = r->our_natted_addr;
+				bridgepeer->peer_internal_vaddr = r->our_natted_vaddr;
+				*/
+				r->firewall_done = 1; /* no bridging for the first phone */
+				midcom_disconnect(r->con, r->is_cached);
+				timer_setup_tick(r, sizeof(struct midcom_rule), r->lifetime, &r->timer_handle);
+			}
 	} /* (!r->nat_done) */
 
-		  r->redirip_nat = r->our_natted_addr;
-		  r->vredirip_nat = r->our_natted_vaddr;
+			r->redirip_nat = r->our_natted_addr;
+			r->vredirip_nat = r->our_natted_vaddr;
 
 		}
 
@@ -1036,59 +1022,58 @@
 
 	if (!r->firewall_done)
 		{
-		  r->firewall_done = 1;
-
-		  if ((r->midbox_addr.s_addr) && (r->con != -1))
+			r->firewall_done = 1;
+
+			if ((r->midbox_addr.s_addr) && (r->con != -1))
 	{
-	  codec = channel_cb->ast_get_capability_helper(p);
-	  if (is_farend)
-	    res = midcom_bridge_firewall(r->con, r->ruleid, &r->our_natted_addr, &r->remote_addr, &r->lifetime, (codec & 0x0000FFFF));
-	  else
-	    res = midcom_add_firewall(r->con, r->ruleid, &r->redirip_nat, &r->our_internal_addr, &r->lifetime, (codec & 0x0000FFFF));
-
-	  if (res != 0)
-	    {
-	      /* free r */
-		          if (peer && is_farend) {
-		             if (option_verbose > 1)
-		                 ast_verbose("Midcom: Failed to Bridge Audio streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_natted_addr.sin_addr),  ntohs(r->our_natted_addr.sin_port), peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->our_natted_addr.sin_addr), ntohs(peer->our_natted_addr.sin_port));
-		          }
-	      return 0;
-	    }
-
-		      if (peer && is_farend) {
-		         if (option_verbose > 1)
-		             ast_verbose("Midcom: Bridging Audio streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_natted_addr.sin_addr),  ntohs(r->our_natted_addr.sin_port), peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->our_natted_addr.sin_addr), ntohs(peer->our_natted_addr.sin_port));
-		      }
-
-	  if (!r->novideo) 
-	    {
-	      if (is_farend)
+		codec = channel_cb->ast_get_capability_helper(p);
+		if (is_farend)
+			res = midcom_bridge_firewall(r->con, r->ruleid, &r->our_natted_addr, &r->remote_addr, &r->lifetime, (codec & 0x0000FFFF));
+		else
+			res = midcom_add_firewall(r->con, r->ruleid, &r->redirip_nat, &r->our_internal_addr, &r->lifetime, (codec & 0x0000FFFF));
+
+		if (res != 0) {
+			/* free r */
+			if (peer && is_farend) {
+				 if (option_verbose > 1)
+					 ast_verbose("Midcom: Failed to Bridge Audio streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(r->our_natted_addr.sin_addr),	ntohs(r->our_natted_addr.sin_port), peer->username, ast_inet_ntoa(peer->our_natted_addr.sin_addr), ntohs(peer->our_natted_addr.sin_port));
+			}
+			return 0;
+		}
+
+		if (peer && is_farend) {
+			 if (option_verbose > 1)
+				 ast_verbose("Midcom: Bridging Audio streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(r->our_natted_addr.sin_addr),	ntohs(r->our_natted_addr.sin_port), peer->username, ast_inet_ntoa(peer->our_natted_addr.sin_addr), ntohs(peer->our_natted_addr.sin_port));
+		}
+
+		if (!r->novideo) 
+			{
+				if (is_farend)
 		res = midcom_bridge_firewall(r->con, r->vruleid, &r->our_natted_vaddr, &r->remote_vaddr, &r->lifetime, (codec & 0xFFFF0000));
-	      else
+				else
 		res = midcom_add_firewall(r->con, r->vruleid, &r->vredirip_nat, &r->our_internal_vaddr, &r->lifetime, (codec & 0xFFFF0000));
 
-	      if (res != 0)
+				if (res != 0)
 		{
-		  /* free r */
-	          if (peer && is_farend) {
-		                 if (option_verbose > 1)
-		                    ast_verbose("Midcom: Failed to Bridge Video streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_natted_vaddr.sin_addr),  ntohs(r->our_natted_vaddr.sin_port), peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->our_natted_vaddr.sin_addr), ntohs(peer->our_natted_vaddr.sin_port));
-		              }
-		  return 0;
-		}
-	    }
-	  if (!r->novideo && peer && is_farend) {
-		         if (option_verbose > 1)
-		            ast_verbose("Midcom: Bridging Video streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(iabuf1, sizeof(iabuf1), r->our_natted_vaddr.sin_addr),  ntohs(r->our_natted_vaddr.sin_port), peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), peer->our_natted_vaddr.sin_addr), ntohs(peer->our_natted_vaddr.sin_port));
-		      }
-	  midcom_disconnect(r->con, r->is_cached);
-	  timer_setup_tick(r, sizeof(struct midcom_rule), r->lifetime, &r->timer_handle);
-	}
-		  else
+			/* free r */
+						if (peer && is_farend) {
+										 if (option_verbose > 1)
+												ast_verbose("Midcom: Failed to Bridge Video streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(r->our_natted_vaddr.sin_addr),	ntohs(r->our_natted_vaddr.sin_port), peer->username, ast_inet_ntoa(peer->our_natted_vaddr.sin_addr), ntohs(peer->our_natted_vaddr.sin_port));
+									}
+			return 0;
+		}
+			}
+		if (!r->novideo && peer && is_farend) {
+						 if (option_verbose > 1)
+								ast_verbose("Midcom: Bridging Video streams of phone %s with IP: %s port %d and Phone %s with IP; %s port %d\n", r->username, ast_inet_ntoa(r->our_natted_vaddr.sin_addr),	ntohs(r->our_natted_vaddr.sin_port), peer->username, ast_inet_ntoa(peer->our_natted_vaddr.sin_addr), ntohs(peer->our_natted_vaddr.sin_port));
+					}
+		midcom_disconnect(r->con, r->is_cached);
+		timer_setup_tick(r, sizeof(struct midcom_rule), r->lifetime, &r->timer_handle);
+	}
+			else
 	{
-	  /* free r */
-	  return 0;
+		/* free r */
+		return 0;
 	}
 		}
 	return 1;
@@ -1100,16 +1085,14 @@
 	char *username=NULL;
 
 	if (!midcom_enabled) {
-		ast_log(LOG_ERROR, "Midcom: Module not enabled\n");
-		if (option_verbose > 1)
-		  ast_verbose("Midcom: Module currently disabled\n");
+		midcom_warning();
 		return 1;
 	}
 
 	if (!channel_cb) {
 		ast_log(LOG_ERROR, "Midcom: Module not initialized properly\n");
 		if (option_verbose > 1)
-		  ast_verbose("Midcom: Error!! - Module not initialized\n");
+			ast_verbose("Midcom: Error!! - Module not initialized\n");
 		return 0;
 	}
 
@@ -1117,9 +1100,9 @@
 
 		username = channel_cb->ast_get_username(p);
 		if (username && username[0]) {
-		  ast_log(LOG_ERROR, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", username);
-		  if (option_verbose > 1)
-		    ast_verbose("Midcom: Error!! - Unable to retrieve Midcom Rule for phone: %s\n", username);
+			ast_log(LOG_ERROR, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", username);
+			if (option_verbose > 1)
+				ast_verbose("Midcom: Error!! - Unable to retrieve Midcom Rule for phone: %s\n", username);
 		}
 		return 1;
 	}
@@ -1140,19 +1123,19 @@
 
 	if ((!r->invalid) && (r->nat_done) && (!r->bye_done)) {
 		if (r->firewall_done) {
-		  timer_cancel_tick(r, sizeof(struct midcom_rule));
-		  r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached);
+			timer_cancel_tick(r, sizeof(struct midcom_rule));
+			r->con = midcom_connect(r->midbox_addr, &r->lifetime, &r->is_cached);
 		}
 		if (r->con != -1) {
-		  if (option_verbose > 1)
-		     ast_verbose("Midcom: Unbridging Audio media and destroying midcom rule for phone: %s\n", r->username);
-		  midcom_delete_rule(r->con, r->ruleid);
-		  if (!r->novideo) {
-		     if (option_verbose > 1)
-		        ast_verbose("Midcom: Unbridging Video media and destroying midcom rule for phone: %s\n", r->username);
+			if (option_verbose > 1)
+				 ast_verbose("Midcom: Unbridging Audio media and destroying midcom rule for phone: %s\n", r->username);
+			midcom_delete_rule(r->con, r->ruleid);
+			if (!r->novideo) {
+				 if (option_verbose > 1)
+						ast_verbose("Midcom: Unbridging Video media and destroying midcom rule for phone: %s\n", r->username);
 	 midcom_delete_rule(r->con, r->vruleid);
-		  }
-		  midcom_disconnect(r->con, r->is_cached);
+			}
+			midcom_disconnect(r->con, r->is_cached);
 		}
 		r->bye_done = 1;
 	}
@@ -1182,14 +1165,14 @@
 		ast_rtp_nat_us(rtp, &((struct midcom_rule*)r)->our_natted_vaddr);
 }
 
-static void  midcom_get_redirip_audio_hook(void *r, struct sockaddr_in *redirip)
+static void	midcom_get_redirip_audio_hook(void *r, struct sockaddr_in *redirip)
 {
 	if (!midcom_enabled)
 		return;
 	memcpy(redirip, &((struct midcom_rule*)r)->redirip_nat, sizeof(struct sockaddr_in));
 }
 
-static void  midcom_get_vredirip_video_hook(void *r, struct sockaddr_in *vredirip)
+static void	midcom_get_vredirip_video_hook(void *r, struct sockaddr_in *vredirip)
 {
 	if (!midcom_enabled)
 		return;
@@ -1215,20 +1198,19 @@
 static void midcom_connect_all()
 {
 	struct connection *conn;
-	char iabuf[INET_ADDRSTRLEN];
 
 	conn = connl;
 	while (conn) {
-		ast_inet_ntoa(iabuf, sizeof(iabuf), conn->ipaddress);
-		if ((conn->sock = mc_comm_connect(iabuf)) == -1)
-		  ast_log(LOG_WARNING, "Could not connect to middlebox %s\n", iabuf);
+		if ((conn->sock = mc_comm_connect(ast_inet_ntoa(conn->ipaddress)) == -1)
+			ast_log(LOG_WARNING, "MIDCOM Could not connect to middlebox %s\n", ast_inet_ntoa(conn->ipaddress));
 		else
-		  ast_log(LOG_NOTICE, "Connected to middlebox %s\n", iabuf);
+			if (option_verbose > 1)
+				ast_verbose("MIDCOM Connected to middlebox %s\n", iabuf);
 	 /*
 		if ((conn->pingsock = mc_comm_connect(iabuf)) == -1)
-		  timer_setup_tick(conn, sizeof(struct connection), DEFAULT_FREQ_NOTOK, &conn->timer_handle);
-		else      
-		  timer_setup_tick(conn, sizeof(struct connection), DEFAULT_FREQ_OK, &conn->timer_handle);
+			timer_setup_tick(conn, sizeof(struct connection), DEFAULT_FREQ_NOTOK, &conn->timer_handle);
+		else			
+			timer_setup_tick(conn, sizeof(struct connection), DEFAULT_FREQ_OK, &conn->timer_handle);
 	 */
 		conn = conn->next;
 	}
@@ -1239,7 +1221,6 @@
 static int midcom_connect(struct in_addr midbox, int *lifetime, int *cached)
 {
 	int con = -1;
-	char iabuf[INET_ADDRSTRLEN];
 	char *login = "root";
 	char *password = "ranchroot";
 	int res = -1;
@@ -1249,67 +1230,60 @@
 	curr = connl;
 	while (curr) {
 		if (midbox.s_addr == curr->ipaddress.s_addr)
-		  break;
-	 curr = curr->next;
+			break;
+		curr = curr->next;
 	}
 
 	if (curr && (curr->sock >= 0)) {
 		if ((ret = simco_se_b(curr->sock)) == 0) {
-		  if ((ret = simco_sa_b(curr->sock, curr->username, curr->password)) == 0) {
-		  *cached = 1;
-		  *lifetime = 600; /* to be removed */
-		  return curr->sock;
-		  }
-		else
-		  ast_log(LOG_WARNING, "Connection closed while authenticating session error=0x%x\n", ret);
-		}
-		else
-		  ast_log(LOG_WARNING, "Connection closed while establishing session error=0x%x\n", ret);
-	}
-	else
-	 ast_log(LOG_WARNING, "Connection stale \n");
-
-	ast_inet_ntoa(iabuf, sizeof(iabuf), midbox);
-	ast_log(LOG_NOTICE, "Re-opening new connection to %s!!!\n", iabuf);
+			if ((ret = simco_sa_b(curr->sock, curr->username, curr->password)) == 0) {
+				*cached = 1;
+				*lifetime = 600; /* to be removed */
+				return curr->sock;
+Ã			} else
+Ã				ast_log(LOG_WARNING, "Connection closed while authenticating session error=0x%x\n", ret);
+		} else
+			ast_log(LOG_WARNING, "Connection closed while establishing session error=0x%x\n", ret);
+	} else
+		ast_log(LOG_WARNING, "Connection stale \n");
+
+	if (option_verbose > 1)
+		ast_verbose("Re-opening new connection to %s!!!\n", ast_inet_ntoa(midbox));
 
 	if (curr)
 		curr->sock = -1;
 
 	if ((con = mc_comm_connect(iabuf)) == -1) {
-		ast_log(LOG_WARNING, "Midcom: Could not connect to middlebox %s\n", iabuf);
+		ast_log(LOG_ERROR, "Midcom: Could not connect to middlebox %s\n", ast_inet_ntoa(midbox));
 		*cached = 0;
 		return -1;
 	}
 
-	if (simco_se_b(con) != 0)
-		{
-		  ast_log(LOG_WARNING, "Midcom: Could not establish new session %s\n", iabuf);
-		  mc_comm_disconnect(con);
-		  *cached = 0;
-		  return -1;
-		}
-
-	if (curr) {
+	if (simco_se_b(con) != 0) {
+		ast_log(LOG_ERROR, "Midcom: Could not establish new session %s\n", ast_inet_ntoa(midbox));
+		mc_comm_disconnect(con);
+		*cached = 0;
+		return -1;
+	}
+
+	if (curr) 
 		res = simco_sa_b(con, curr->username, curr->password);
-	} else {
+	else 
 		res = simco_sa_b(con, login, password);
-	}
 		
-	if (res != 0)
-		{
-		  ast_log(LOG_WARNING, "Midcom: Could not authenticate on %s \n", iabuf);
-		  simco_st_b(con);
-		  mc_comm_disconnect(con);
-		  *cached = 0;
-		  return -1;
-		}
+	if (res != 0) {
+		ast_log(LOG_WARNING, "Midcom: Could not authenticate on %s \n", ast_inet_ntoa(midbox));
+		simco_st_b(con);
+		mc_comm_disconnect(con);
+		*cached = 0;
+		return -1;
+	}
 
 	if (curr) {
 		curr->sock = con;
 		*cached = 1;
-	} else {
+	} else
 		*cached = 0;
-	}
 
 	*lifetime = 600; /* to be removed */
 	return con;
@@ -1325,8 +1299,8 @@
 	spacket.lifetime = *lifetime;
 	if ((ret = simco_plc_b(con, &spacket)) != 0)
 		{
-		  ast_log(LOG_WARNING, "Midcom: Error - simco_plc_b: 0x%x\n", ret);
-		  return -1;
+			ast_log(LOG_WARNING, "Midcom: Error - simco_plc_b: 0x%x\n", ret);
+			return -1;
 		}
 	*lifetime = spacket.lifetime;
 	return 0;
@@ -1341,13 +1315,13 @@
 	spacket.lifetime = *lifetime;
 	/*if (enable_rtcp) */
 		spacket.nat_port_range = 2;
-	if ((ret = simco_prr_b(con, &spacket)) != 0)
-		{
-		  ast_log(LOG_WARNING, "Midcom: Error - simco_prr_b: 0x%x\n", ret);
-		  return -1;
-		}
-	ast_log(LOG_DEBUG, "Midcom: PRR: spacket.ruleId=%d, spacket.outside_ip=%s, spacket.outside_port=%d\n",
-	  spacket.ruleId, spacket.outside_ip, spacket.outside_port);
+	if ((ret = simco_prr_b(con, &spacket)) != 0) {

[... 388 lines stripped ...]


More information about the asterisk-commits mailing list