From e015ebe064c6f5120ef2af2b73ce52796a06f790 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Thu, 14 Sep 2006 16:07:49 +0000 Subject: Added pjsip_transport_register_type() API to register new transport type. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@720 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/include/pjsip/sip_transport.h | 24 ++++++++++++++++++++++ pjsip/include/pjsip/sip_types.h | 5 ++++- pjsip/src/pjsip/sip_transport.c | 41 +++++++++++++++++++++++++++++++++++-- 3 files changed, 67 insertions(+), 3 deletions(-) (limited to 'pjsip') diff --git a/pjsip/include/pjsip/sip_transport.h b/pjsip/include/pjsip/sip_transport.h index 69a9f624..ec371f0f 100644 --- a/pjsip/include/pjsip/sip_transport.h +++ b/pjsip/include/pjsip/sip_transport.h @@ -79,6 +79,30 @@ enum pjsip_transport_flags_e #define PJSIP_TRANSPORT_IS_SECURE(tp) \ ((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. * diff --git a/pjsip/include/pjsip/sip_types.h b/pjsip/include/pjsip/sip_types.h index d50fdba0..38525453 100644 --- a/pjsip/include/pjsip/sip_types.h +++ b/pjsip/include/pjsip/sip_types.h @@ -79,7 +79,10 @@ typedef enum pjsip_transport_type_e 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 e18a9048..909632e8 100644 --- a/pjsip/src/pjsip/sip_transport.c +++ b/pjsip/src/pjsip/sip_transport.c @@ -97,13 +97,14 @@ struct transport_key /* * 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}, @@ -115,6 +116,42 @@ const struct }; +/* + * 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