summaryrefslogtreecommitdiff
path: root/pjnath
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-10-16 01:34:14 +0000
committerBenny Prijono <bennylp@teluu.com>2007-10-16 01:34:14 +0000
commit5aea96f9de3908f2fc85c16001adc6c3f82d4705 (patch)
treee838b8a6077af937b2e834822540839c4e2515b2 /pjnath
parent4b289329774686a3e261fac70fbd902942cb9b1f (diff)
More ticket #399: added callback to report NAT detection result, and sends NAT type in SDP
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1501 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjnath')
-rw-r--r--pjnath/include/pjnath/errno.h5
-rw-r--r--pjnath/include/pjnath/nat_detect.h18
-rw-r--r--pjnath/src/pjnath/errno.c1
-rw-r--r--pjnath/src/pjnath/nat_detect.c28
4 files changed, 43 insertions, 9 deletions
diff --git a/pjnath/include/pjnath/errno.h b/pjnath/include/pjnath/errno.h
index 403f191d..1f763fc1 100644
--- a/pjnath/include/pjnath/errno.h
+++ b/pjnath/include/pjnath/errno.h
@@ -110,6 +110,11 @@
*/
#define PJNATH_ESTUNIPV6NOTSUPP (PJNATH_ERRNO_START+41) /* 370041 */
+/**
+ * @hideinitializer
+ * Invalid STUN server or server not configured.
+ */
+#define PJNATH_ESTUNINSERVER (PJNATH_ERRNO_START+42) /* 370042 */
diff --git a/pjnath/include/pjnath/nat_detect.h b/pjnath/include/pjnath/nat_detect.h
index e79ffb14..a4bc5fec 100644
--- a/pjnath/include/pjnath/nat_detect.h
+++ b/pjnath/include/pjnath/nat_detect.h
@@ -48,11 +48,17 @@ PJ_BEGIN_DECL
typedef enum pj_stun_nat_type
{
/**
- * NAT type is unknown, because the detection has failed.
+ * NAT type is unknown because the detection has not been performed.
*/
PJ_STUN_NAT_TYPE_UNKNOWN,
/**
+ * NAT type is unknown because there is failure in the detection
+ * process, possibly because server does not support RFC 3489.
+ */
+ PJ_STUN_NAT_TYPE_ERR_UNKNOWN,
+
+ /**
* This specifies that the client has open access to Internet (or
* at least, its behind a firewall that behaves like a full-cone NAT,
* but without the translation)
@@ -152,6 +158,16 @@ typedef void pj_stun_nat_detect_cb(void *user_data,
/**
+ * Get the NAT name from the specified NAT type.
+ *
+ * @param type NAT type.
+ *
+ * @return NAT name.
+ */
+PJ_DECL(const char*) pj_stun_get_nat_name(pj_stun_nat_type type);
+
+
+/**
* Perform NAT classification function according to the procedures
* specified in RFC 3489. Once this function returns successfully,
* the procedure will run in the "background" and will complete
diff --git a/pjnath/src/pjnath/errno.c b/pjnath/src/pjnath/errno.c
index 21a42d4e..af636fcd 100644
--- a/pjnath/src/pjnath/errno.c
+++ b/pjnath/src/pjnath/errno.c
@@ -49,6 +49,7 @@ static const struct
PJ_BUILD_ERR( PJNATH_ESTUNNOMAPPEDADDR, "STUN (XOR-)MAPPED-ADDRESS attribute not found"),
PJ_BUILD_ERR( PJNATH_ESTUNIPV6NOTSUPP, "STUN IPv6 attribute not supported"),
+ PJ_BUILD_ERR( PJNATH_ESTUNINSERVER, "Invalid STUN server or server not configured"),
/* ICE related errors */
PJ_BUILD_ERR( PJNATH_ENOICE, "ICE session not available"),
diff --git a/pjnath/src/pjnath/nat_detect.c b/pjnath/src/pjnath/nat_detect.c
index cf3ceed4..368c86fb 100644
--- a/pjnath/src/pjnath/nat_detect.c
+++ b/pjnath/src/pjnath/nat_detect.c
@@ -32,7 +32,8 @@
static const char *nat_type_names[] =
{
"Unknown",
- "Open Internet",
+ "ErrUnknown",
+ "Open",
"Blocked",
"Symmetric UDP",
"Full Cone",
@@ -129,6 +130,17 @@ static void on_sess_timer(pj_timer_heap_t *th,
static void sess_destroy(nat_detect_session *sess);
+/*
+ * Get the NAT name from the specified NAT type.
+ */
+PJ_DEF(const char*) pj_stun_get_nat_name(pj_stun_nat_type type)
+{
+ PJ_ASSERT_RETURN(type >= 0 && type <= PJ_STUN_NAT_TYPE_PORT_RESTRICTED,
+ "*Invalid*");
+
+ return nat_type_names[type];
+}
+
static int test_executed(nat_detect_session *sess)
{
unsigned i, count;
@@ -387,7 +399,7 @@ static void on_read_complete(pj_ioqueue_key_t *key,
-bytes_read != PJ_STATUS_FROM_OS(OSERR_ECONNRESET))
{
/* Permanent error */
- end_session(sess, -bytes_read, PJ_STUN_NAT_TYPE_UNKNOWN);
+ end_session(sess, -bytes_read, PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
goto on_return;
}
@@ -406,7 +418,7 @@ static void on_read_complete(pj_ioqueue_key_t *key,
if (status != PJ_EPENDING) {
pj_assert(status != PJ_SUCCESS);
- end_session(sess, status, PJ_STUN_NAT_TYPE_UNKNOWN);
+ end_session(sess, status, PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
}
on_return:
@@ -627,7 +639,7 @@ static void on_request_complete(pj_stun_session *stun_sess,
* We've got other error with Test 2.
*/
end_session(sess, sess->result[ST_TEST_2].status,
- PJ_STUN_NAT_TYPE_UNKNOWN);
+ PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
break;
}
} else {
@@ -690,7 +702,7 @@ static void on_request_complete(pj_stun_session *stun_sess,
* Got other error with test 3.
*/
end_session(sess, sess->result[ST_TEST_3].status,
- PJ_STUN_NAT_TYPE_UNKNOWN);
+ PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
break;
}
}
@@ -707,7 +719,7 @@ static void on_request_complete(pj_stun_session *stun_sess,
* Got other error with test 1B.
*/
end_session(sess, sess->result[ST_TEST_1B].status,
- PJ_STUN_NAT_TYPE_UNKNOWN);
+ PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
break;
}
break;
@@ -716,7 +728,7 @@ static void on_request_complete(pj_stun_session *stun_sess,
* We've got other error with Test 2.
*/
end_session(sess, sess->result[ST_TEST_2].status,
- PJ_STUN_NAT_TYPE_UNKNOWN);
+ PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
break;
}
}
@@ -726,7 +738,7 @@ static void on_request_complete(pj_stun_session *stun_sess,
* We've got other error with Test 1.
*/
end_session(sess, sess->result[ST_TEST_1].status,
- PJ_STUN_NAT_TYPE_UNKNOWN);
+ PJ_STUN_NAT_TYPE_ERR_UNKNOWN);
break;
}