Added pjsip_transport_register_type() API to register new transport type.



git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@720 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/pjsip/include/pjsip/sip_transport.h b/pjsip/include/pjsip/sip_transport.h
index 69a9f62..ec371f0 100644
--- a/pjsip/include/pjsip/sip_transport.h
+++ b/pjsip/include/pjsip/sip_transport.h
@@ -80,6 +80,30 @@
 	    ((tp)->flag & PJSIP_TRANSPORT_SECURE)
 
 /**
+ * Register new transport type to PJSIP. The PJSIP transport framework
+ * contains the info for some standard transports, as declared by
+ * #pjsip_transport_type_e. Application may use non-standard transport
+ * with PJSIP, but before it does so, it must register the information
+ * about the new transport type to PJSIP by calling this function.
+ *
+ * @param tp_flag   The flags describing characteristics of this
+ *		    transport type.
+ * @param tp_name   Transport type name.
+ * @param def_port  Default port to be used for the transport.
+ * @param p_tp_type On successful registration, it will be filled with
+ *		    the registered type. This argument is optional.
+ *
+ * @return	    PJ_SUCCESS if registration is successful, or
+ *		    PJSIP_ETYPEEXISTS if the same transport type has
+ *		    already been registered.
+ */
+PJ_DECL(pj_status_t) pjsip_transport_register_type(unsigned tp_flag,
+						   const char *tp_name,
+						   int def_port,
+						   int *p_tp_type);
+
+
+/**
  * Get the transport type from the transport name.
  *
  * @param name	    Transport name, such as "TCP", or "UDP".
diff --git a/pjsip/include/pjsip/sip_types.h b/pjsip/include/pjsip/sip_types.h
index d50fdba..3852545 100644
--- a/pjsip/include/pjsip/sip_types.h
+++ b/pjsip/include/pjsip/sip_types.h
@@ -79,7 +79,10 @@
     PJSIP_TRANSPORT_LOOP,
 
     /** Loopback (datagram, unreliable) */
-    PJSIP_TRANSPORT_LOOP_DGRAM
+    PJSIP_TRANSPORT_LOOP_DGRAM,
+
+    /** Start of user defined transport */
+    PJSIP_TRANSPORT_START_OTHER
 
 } pjsip_transport_type_e;
 
diff --git a/pjsip/src/pjsip/sip_transport.c b/pjsip/src/pjsip/sip_transport.c
index e18a904..909632e 100644
--- a/pjsip/src/pjsip/sip_transport.c
+++ b/pjsip/src/pjsip/sip_transport.c
@@ -97,13 +97,14 @@
 /*
  * Transport names.
  */
-const struct
+struct
 {
     pjsip_transport_type_e type;
     pj_uint16_t		   port;
     pj_str_t		   name;
     unsigned		   flag;
-} transport_names[] = 
+    char		   name_buf[16];
+} transport_names[16] = 
 {
     { PJSIP_TRANSPORT_UNSPECIFIED, 0, {"Unspecified", 11}, 0},
     { PJSIP_TRANSPORT_UDP, 5060, {"UDP", 3}, PJSIP_TRANSPORT_DATAGRAM},
@@ -116,6 +117,42 @@
 
 
 /*
+ * Register new transport type to PJSIP.
+ */
+PJ_DECL(pj_status_t) pjsip_transport_register_type(unsigned tp_flag,
+						   const char *tp_name,
+						   int def_port,
+						   int *p_tp_type)
+{
+    unsigned i;
+
+    PJ_ASSERT_RETURN(tp_flag && tp_name && def_port, PJ_EINVAL);
+    PJ_ASSERT_RETURN(pj_ansi_strlen(tp_name) < 
+			PJ_ARRAY_SIZE(transport_names[0].name_buf), 
+		     PJ_ENAMETOOLONG);
+
+    for (i=1; i<PJ_ARRAY_SIZE(transport_names); ++i) {
+	if (transport_names[i].type == 0)
+	    break;
+    }
+
+    if (i == PJ_ARRAY_SIZE(transport_names))
+	return PJ_ETOOMANY;
+
+    transport_names[i].type = (pjsip_transport_type_e)i;
+    transport_names[i].port = (pj_uint16_t)def_port;
+    pj_ansi_strcpy(transport_names[i].name_buf, tp_name);
+    transport_names[i].name = pj_str(transport_names[i].name_buf);
+    transport_names[i].flag = tp_flag;
+
+    if (p_tp_type)
+	*p_tp_type = i;
+
+    return PJ_SUCCESS;
+}
+
+
+/*
  * Get transport type from name.
  */
 PJ_DEF(pjsip_transport_type_e)