[svn-commits] oej: branch oej/midcom-0.5.3.2 r53575 - /team/oej/midcom-0.5.3.2/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Thu Feb 8 09:31:20 MST 2007


Author: oej
Date: Thu Feb  8 10:31:19 2007
New Revision: 53575

URL: http://svn.digium.com/view/asterisk?view=rev&rev=53575
Log:
Update

Modified:
    team/oej/midcom-0.5.3.2/res_netsec.c
    team/oej/midcom-0.5.3.2/res_netsec.h

Modified: team/oej/midcom-0.5.3.2/res_netsec.c
URL: http://svn.digium.com/view/asterisk/team/oej/midcom-0.5.3.2/res_netsec.c?view=diff&rev=53575&r1=53574&r2=53575
==============================================================================
--- team/oej/midcom-0.5.3.2/res_netsec.c (original)
+++ team/oej/midcom-0.5.3.2/res_netsec.c Thu Feb  8 10:31:19 2007
@@ -24,6 +24,26 @@
  *
  */
 
+/*! \file
+ * res_netsec.c -- Provides the MIDCOM services to Asterisk
+ *
+ * \author Srivatsa Chivukula <srivatsa at ranchnetworks.com>
+ *
+ * \todo
+ *  - Create registration in rtp.c for a remote RTP handler
+ *  - Make interface less SIP-specific (this can be used for
+ *    all RTP based channels - H.323, jingle, mgcp)
+ *  - Make source code follow coding guidelines
+ *  - Check licensing
+ *  - Fix proper reload function
+        - How does this affect midcom connections to a device?
+ *  - fix autoconfigure to set MIDCOM_EXISTS flag if libmidcom is installed
+ */
+
+/*** MODULEINFO
+	<depend>libmidcom</depend>
+***/
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -67,12 +87,13 @@
 #define MIDCOM_MAX_SIMCO_RETRY_CNT 1
 
 static const char version[] = "Libmidcom version 0.5.3.2";
-static const char desc[] = "MiddleBox Communication Module (MIDCOM)";
+static const char desc[] = "MiddleBox Communication Module (MIDCOM/SIMCO)";
 static unsigned int midcomnat = FAREND;
 static char cert[512];
 static char* config = "midcom.conf";
 static int midcom_enabled = 1;
 static int midcom_err_state = 0;
+static int told_them_that_midcom_is_not_enabled = 0;
 
 #define MIDCOM_NO_CONFIG 0x1
 #define MIDCOM_NO_INIT   0x2
@@ -110,60 +131,68 @@
 static timer_task_context_t *timer_context_create(void);
 static void timer_context_delete(timer_task_context_t *ttc);
 
+*! Midcom ruleset, one per session (pvt)
+       \note this structure needs a pointer in the channel's
+               pvt structure
+*/
+
 static struct midcom_rule {
-  char username[256];
-  unsigned int nat_done:1,
+	char username[256];
+	unsigned int nat_done:1,
                firewall_done:1,
                bridge_done:1,
                bye_done:1,
                novideo:1,
                enable_rtcp:1,
-               bridged_node:1,             /* bridged_node = 1 - bridging done throught this rule */
+               bridged_node:1,             /*!< bridged_node = 1 - bridging done throught this rule */
                tls:1,
                invalid:1,
                audio_to_asterisk:1,
                video_to_asterisk:1,
-               may_xfer_call:1,          /* call may be transferred to another extension */
+               may_xfer_call:1,          /*!< call may be transferred to another extension */
                unused:20;
-  struct connection *conn;               /* midbox to which we are talking to for this rule */
+  struct connection *conn;               /*!< midbox to which we are talking to for this rule */
   int ruleid;
   int vruleid;
   int aux_ruleid;
   int aux_vruleid;
-  struct sockaddr_in our_internal_addr;   /* audio - internal address of the endpoint (pre NAT) */
-  struct sockaddr_in our_external_addr;   /* audio - external address of the endpoint (post NAT) */
-  struct sockaddr_in our_natted_addr;     /* audio - address assigned to endpoint by Midbox */
-  struct sockaddr_in our_internal_vaddr;  /* video - internal address of the endpoint (pre NAT) */
-  struct sockaddr_in our_external_vaddr;  /* video - external address of the endpoint (post NAT) */
-  struct sockaddr_in our_natted_vaddr;    /* video - address assigned to endpoint by Midbox */
+  struct sockaddr_in our_internal_addr;   /*!< audio - internal address of the endpoint (pre NAT) */
+  struct sockaddr_in our_external_addr;   /*!< audio - external address of the endpoint (post NAT) */
+  struct sockaddr_in our_natted_addr;     /*!< audio - address assigned to endpoint by Midbox */
+  struct sockaddr_in our_internal_vaddr;  /*!< video - internal address of the endpoint (pre NAT) */
+  struct sockaddr_in our_external_vaddr;  /*!< video - external address of the endpoint (post NAT) */
+  struct sockaddr_in our_natted_vaddr;    /*!< video - address assigned to endpoint by Midbox */
+				/* XXX For Asterisk 1.6, we need text RTP.  */
   int lifetime;
   timer_id_t timer_handle;
-  void *p;                                /* handle to tech pvt data structure */
-  struct midcom_rule *pr;                 /* peer MIDCOM rule for the other leg of a bridged call. */
+  void *p;                                /*!< handle to tech pvt data structure */
+  struct midcom_rule *pr;                 /*!< peer MIDCOM rule for the other leg of a bridged call. */
   struct midcom_rule *next;
 } *midcom_rule_head = NULL;
 
 
+/*! \brief midcom connection to the remote device */
 static struct connection {
-  struct in_addr ipaddress;
-  char name[256];
-  char username[256];
-  char password[256];
-  int tls;
-  int location;
-  int role;
-  int sock;
-  int pingsock;
-  mbox_state_t state;
-  ast_mutex_t lock;
-  unsigned int thread;		/* thread currently holding lock */
-  timer_id_t timer_handle;
-  struct connection *next;
+	struct in_addr ipaddress;
+	char name[256];
+	char username[256];
+	char password[256];
+	int tls;
+	int location;
+	int role;
+	int sock;
+	int pingsock;
+	mbox_state_t state;
+	ast_mutex_t lock;
+	unsigned int thread;		/* thread currently holding lock */
+	timer_id_t timer_handle;
+	struct connection *next;
 } *connl = NULL;
    
-/* Protect the midcom rule list */
+/*! \brief Protect the midcom rule list */
 AST_MUTEX_DEFINE_STATIC(netsec_lock);
 
+/*! Forward declarations */
 static int midcom_config_reload(void);
 
 static struct connection * get_primary_midbox(void);
@@ -213,7 +242,7 @@
 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);
@@ -225,7 +254,7 @@
 static int midcom_mutex_lock(ast_mutex_t *mutex);
 static int midcom_mutex_unlock(ast_mutex_t *mutex);
 
-static struct ast_sip_helper_cb *sip_cb = NULL;
+static struct ast_rtp_helper_cb *channel_cb = NULL;
 
 struct ast_sip_hook_cb *m_cb = NULL; /*move this to the core asterisk files */
 
@@ -280,18 +309,18 @@
   ast_get_vredirip_video_hook: midcom_get_vredirip_video_hook,
   ast_rtp_get_their_nat_audio_hook: midcom_rtp_get_their_nat_audio_hook,
   ast_rtp_get_their_nat_video_hook: midcom_rtp_get_their_nat_video_hook,
-  ast_sip_helper_register: midcom_sip_helper_register,
-  ast_sip_helper_unregister: midcom_sip_helper_unregister,
+  ast_rtp_helper_cb: midcom_sip_helper_register,
+  ast_rtp_helper_cb: midcom_sip_helper_unregister,
 };
 
-static void midcom_sip_helper_register(struct ast_sip_helper_cb *cb)
-{
-  sip_cb = cb;
+static void midcom_sip_helper_register(struct ast_rtp_helper_cb *cb)
+{
+  channel_cb = cb;
 }
 
 static void midcom_sip_helper_unregister(void)
 {
-  sip_cb = NULL;
+  channel_cb = NULL;
 }
 
 
@@ -338,8 +367,8 @@
      if (!ast_mutex_lock(&netsec_lock)) {
        /* Hangup all interfaces if they have an owner */
        while (r) {
-         if (sip_cb)
-           sip_cb->ast_softhangup_helper(r->p);
+         if (channel_cb)
+           channel_cb->ast_softhangup_helper(r->p);
          r = r->next;
        }
        midcom_rule_head = NULL;
@@ -775,12 +804,12 @@
     return NULL;
   }
   memset(r, 0, sizeof(struct midcom_rule));
-  r->novideo = (sip_cb->ast_get_flag_novideo(p)) ? 1 : 0;
-  sip_cb->ast_rtp_get_peer_audio_helper(p, &r->our_internal_addr);
+  r->novideo = (channel_cb->ast_get_flag_novideo(p)) ? 1 : 0;
+  channel_cb->ast_rtp_get_peer_audio_helper(p, &r->our_internal_addr);
   if (!r->novideo) {
-    sip_cb->ast_rtp_get_peer_video_helper(p, &r->our_internal_vaddr);
-  }
-  strncpy(r->username, sip_cb->ast_get_username(p), 256);
+    channel_cb->ast_rtp_get_peer_video_helper(p, &r->our_internal_vaddr);
+  }
+  strncpy(r->username, channel_cb->ast_get_username(p), 256);
   r->ruleid = -1;
   r->vruleid = -1;
   r->aux_ruleid = -1;
@@ -807,14 +836,14 @@
     return 1;
   }
 
-  if (!sip_cb) {
+  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");
     return 0;
   }
 
-  if ((r = sip_cb->ast_get_hook_struct(p)))
+  if ((r = channel_cb->ast_get_hook_struct(p)))
     return 1;
 
   r = midcom_rule_alloc(p);
@@ -848,7 +877,7 @@
   }
   if (debug_midbox)
       ast_log(LOG_DEBUG, "Acquired netsec_lock in the context of thread id 0x%x\n", (unsigned) pthread_self());
-  sip_cb->ast_map_hook_struct(p, (void *)r);
+  channel_cb->ast_map_hook_struct(p, (void *)r);
   r->next = midcom_rule_head;
   midcom_rule_head = r;
   ast_mutex_unlock(&netsec_lock); 
@@ -869,14 +898,14 @@
     return 1;
   }
 
-  if (!sip_cb) {
+  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");
     return 0;
   }
 
-  if ((r = sip_cb->ast_get_hook_struct(p)))
+  if ((r = channel_cb->ast_get_hook_struct(p)))
     return 1;
 
   r = midcom_rule_alloc(p);
@@ -885,7 +914,7 @@
       
   if (option_verbose > 1)
         ast_verbose("Midcom: Allocating new rule for phone: %s\n", r->username);
-      /* sip_cb->ast_get_recv_addr(p, &r->midbox_addr); */
+      /* channel_cb->ast_get_recv_addr(p, &r->midbox_addr); */
   if ( (r->conn = get_primary_midbox()) == NULL)
         return 0;
   if(midcom_open_firewall(r, MIDCOM_ALLOW_AUDIO, MIDCOM_ALLOW_VIDEO) != 0)
@@ -909,7 +938,7 @@
   }
   if (debug_midbox)
       ast_log(LOG_DEBUG, "Acquired netsec_lock in the context of thread id 0x%x\n", (unsigned) pthread_self());
-  sip_cb->ast_map_hook_struct(p, (void *)r);
+  channel_cb->ast_map_hook_struct(p, (void *)r);
   r->next = midcom_rule_head;
   midcom_rule_head = r;
   ast_mutex_unlock(&netsec_lock);
@@ -931,18 +960,18 @@
     return 1;
   }
 
-  if (!sip_cb) {
+  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");
     return 0;
   }
 
-  if (!(r = sip_cb->ast_get_hook_struct(p))) {
-
-    ast_log(LOG_ERROR, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", sip_cb->ast_get_username(p));
+  if (!(r = channel_cb->ast_get_hook_struct(p))) {
+
+    ast_log(LOG_ERROR, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", channel_cb->ast_get_username(p));
     if (option_verbose > 1)
-      ast_verbose("Midcom: Error!! - Unable to retrieve Midcom Rule for phone: %s\n", sip_cb->ast_get_username(p));
+      ast_verbose("Midcom: Error!! - Unable to retrieve Midcom Rule for phone: %s\n", channel_cb->ast_get_username(p));
     return 0;
   }
 
@@ -1131,7 +1160,7 @@
               ast_verbose("Midcom: Trying to rebridge audio between %s and %s\n", r->username, r->pr ? r->pr->username : '\0');
             midcom_delete_rule(rule->conn, rule->aux_ruleid, rule);
             rule->aux_ruleid = -1;
-            sip_cb->ast_get_capability_helper(r->p, &codec, 0);
+            channel_cb->ast_get_capability_helper(r->p, &codec, 0);
             res = midcom_bridge_firewall( r, pr, MIDCOM_BRIDGE_AUDIO, 0 );
 
             if (res != 0)
@@ -1166,7 +1195,7 @@
             midcom_delete_rule(r->conn, r->aux_vruleid, r);
             r->aux_vruleid = -1;
 
-            sip_cb->ast_get_capability_helper(r->p, &codec, 0);
+            channel_cb->ast_get_capability_helper(r->p, &codec, 0);
             res = midcom_bridge_firewall( r, pr, 0, MIDCOM_BRIDGE_VIDEO );
 
             if (res != 0)
@@ -1203,14 +1232,14 @@
   char *username=NULL;
   struct midcom_rule *peer=NULL;
 
-  if (!sip_cb) {
+  if (!channel_cb) {
     ast_log(LOG_DEBUG, "Midcom: Module not initialized properly\n");
     return 1;
   }
 
-  if (!(s = sip_cb->ast_get_hook_struct(p))) {
-
-    username = sip_cb->ast_get_username(p);
+  if (!(s = channel_cb->ast_get_hook_struct(p))) {
+
+    username = channel_cb->ast_get_username(p);
     if (midcom_enabled && username && username[0]) {
       ast_log(LOG_DEBUG, "Midcom: Unable to retrieve Midcom Rule for phone: %s\n", username);
     }
@@ -1707,8 +1736,8 @@
       ast_log(LOG_DEBUG, "Acquired connection lock in the context of thread id 0x%x\n", (unsigned) pthread_self());
     if( allow_audio )
     {
-        sip_cb->ast_rtp_get_us_audio_helper(r->p, &sin, 0);
-	sip_cb->ast_get_capability_helper(r->p, &acodec, 0);
+        channel_cb->ast_rtp_get_us_audio_helper(r->p, &sin, 0);
+	channel_cb->ast_get_capability_helper(r->p, &acodec, 0);
 
         memset((void*)&spacket, 0, sizeof(simcoPacket_t));
         ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr);
@@ -1743,10 +1772,10 @@
 
     if( allow_video && !r->novideo )
     {
-        sip_cb->ast_rtp_get_us_video_helper(r->p, &sin);
+        channel_cb->ast_rtp_get_us_video_helper(r->p, &sin);
 #if 0
         /* We need to get the actual video codec here */
-        vcodec = sip_cb->ast_get_capability_helper(r->p);
+        vcodec = channel_cb->ast_get_capability_helper(r->p);
 #endif
         memset((void*)&spacket, 0, sizeof(simcoPacket_t));
         ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr);
@@ -1868,11 +1897,11 @@
        ast_log(LOG_DEBUG, "Acquired connection lock in the context of thread id 0x%x\n", (unsigned) pthread_self());
     if( bridge_audio )
     {
-        sip_cb->ast_get_capability_helper(r->p, &acodec, &dtmf_payload0);
-        sip_cb->ast_get_capability_helper(peer->p, &acodec, &dtmf_payload1);
-
-        sip_cb->ast_rtp_get_us_audio_helper(r->p, &sin, &pbx_rtp0);
-        sip_cb->ast_rtp_get_us_audio_helper(peer->p, &sin, &pbx_rtp1);
+        channel_cb->ast_get_capability_helper(r->p, &acodec, &dtmf_payload0);
+        channel_cb->ast_get_capability_helper(peer->p, &acodec, &dtmf_payload1);
+
+        channel_cb->ast_rtp_get_us_audio_helper(r->p, &sin, &pbx_rtp0);
+        channel_cb->ast_rtp_get_us_audio_helper(peer->p, &sin, &pbx_rtp1);
 
         memset((void*)&spacket, 0, sizeof(simcoPacket_t));
         spacket.ruleId = r->ruleid;
@@ -1925,7 +1954,7 @@
     {
 #if 0
         /* Need to determine video codec here */
-        vcodec = sip_cb->ast_get_capability_helper(r->p);
+        vcodec = channel_cb->ast_get_capability_helper(r->p);
 #endif
         memset((void*)&spacket, 0, sizeof(simcoPacket_t));
         spacket.ruleId = r->vruleid;
@@ -2273,8 +2302,8 @@
   struct connection *conn= NULL;
   char *loc = "Master";
 
-  sip_cb->ast_get_recv_addr(rule->p, &my_endpoint);
-  sip_cb->ast_get_recv_addr(peer->p, &peer_endpoint);
+  channel_cb->ast_get_recv_addr(rule->p, &my_endpoint);
+  channel_cb->ast_get_recv_addr(peer->p, &peer_endpoint);
 
   if (option_verbose > 30)
    ast_verbose("Midcom: Phone: %s My endpoint: %s Peer Endpoint: %s, Midbox addr: %s\n", rule->username, ast_inet_ntoa(iabuf, sizeof(iabuf), my_endpoint), ast_inet_ntoa(iabuf1, sizeof(iabuf1), peer_endpoint), rule->conn ? (ast_inet_ntoa(iabuf2, sizeof(iabuf2), rule->conn->ipaddress)) : "");
@@ -2324,10 +2353,10 @@
 
   if (r && r->p) { /* pure paranoia */
 
-     my_chan = sip_cb->ast_channel_helper(r->p);
-     peer_chan = sip_cb->ast_bridged_channel_helper(r->p);
+     my_chan = channel_cb->ast_channel_helper(r->p);
+     peer_chan = channel_cb->ast_bridged_channel_helper(r->p);
      if (peer_chan && peer_chan->tech_pvt && (my_chan->tech == peer_chan->tech))
-          peer_rule = sip_cb->ast_get_hook_struct(peer_chan->tech_pvt);
+          peer_rule = channel_cb->ast_get_hook_struct(peer_chan->tech_pvt);
   }
   return peer_rule;
 }

Modified: team/oej/midcom-0.5.3.2/res_netsec.h
URL: http://svn.digium.com/view/asterisk/team/oej/midcom-0.5.3.2/res_netsec.h?view=diff&rev=53575&r1=53574&r2=53575
==============================================================================
--- team/oej/midcom-0.5.3.2/res_netsec.h (original)
+++ team/oej/midcom-0.5.3.2/res_netsec.h Thu Feb  8 10:31:19 2007
@@ -20,10 +20,16 @@
  *
  */
 
+/*! \file res_netsec.h
+        This file glues res_netsec to client channels
+ *
+ * \author Srivatsa Chivukula <srivatsa at ranchnetworks.com>
+*/
 extern int midcom_load_module(void);
 extern void midcom_unload_module(void);
 
-struct ast_sip_helper_cb {
+/* The RTP helper module */
+struct ast_rtp_helper_cb {
   void (* const ast_rtp_get_peer_audio_helper)(void *p, struct sockaddr_in *them);
   void (* const ast_rtp_get_peer_video_helper)(void *p, struct sockaddr_in *them);
   void (* const ast_rtp_get_us_audio_helper)(void *p, struct sockaddr_in *sin, struct sockaddr_in *pbx_rtp);
@@ -40,6 +46,15 @@
   void (* const ast_softhangup_helper)(void *p);
 };
 
+/*! Hooks into the SIP channel 
+        \note Can we make this more generic so it works for other channels
+                or do we need to have one per channel?
+                I think we can define various stages in the media setup process
+                instead or "transmit_response_with_sdp" etc - those are 
+                function calls and not states.
+                A good way would be to compare chan_jingle and chan_sip
+                to find these hooks.
+*/
 struct ast_sip_hook_cb {
   int (* const handle_request_invite_hook)(void *p);
   int (* const handle_response_invite_hook)(void *p);
@@ -52,7 +67,7 @@
   void (* const ast_get_vredirip_video_hook)(void *r, struct sockaddr_in *vredirip);
   void (* const ast_rtp_get_their_nat_audio_hook)(struct ast_rtp *rtp, void *r);
   void (* const ast_rtp_get_their_nat_video_hook)(struct ast_rtp *vrtp, void *r);
-  void (* const ast_sip_helper_register)(struct ast_sip_helper_cb *cb);
+  void (* const ast_sip_helper_register)(struct ast_rtp_helper_cb *cb);
   void (* const ast_sip_helper_unregister)(void);
 };
 



More information about the svn-commits mailing list