diff options
author | Benny Prijono <bennylp@teluu.com> | 2006-05-16 13:20:00 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2006-05-16 13:20:00 +0000 |
commit | 11e0aa7dac9feb0b09155a73eabc161e9db1d55f (patch) | |
tree | 6b07f893c52dbef12144c079faf2caf3874ba768 | |
parent | ca05e325d99bde3c74889348aacc77571f21a0b9 (diff) |
Rearrange transaction statefull stuffs in SIP so that it will not be linked when transaction is disabled
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@448 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r-- | pjsip-apps/build/Samples-vc.mak | 14 | ||||
-rw-r--r-- | pjsip-apps/build/Samples.mak | 13 | ||||
-rw-r--r-- | pjsip-apps/build/samples.dsp | 4 | ||||
-rw-r--r-- | pjsip-apps/src/samples/sipstateless.c | 157 | ||||
-rw-r--r-- | pjsip-apps/src/samples/streamutil.c | 8 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_endpoint.c | 7 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_transaction.c | 10 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_util.c | 67 | ||||
-rw-r--r-- | pjsip/src/pjsip/sip_util_statefull.c | 72 |
9 files changed, 272 insertions, 80 deletions
diff --git a/pjsip-apps/build/Samples-vc.mak b/pjsip-apps/build/Samples-vc.mak index 12f1684c..3293ad50 100644 --- a/pjsip-apps/build/Samples-vc.mak +++ b/pjsip-apps/build/Samples-vc.mak @@ -35,10 +35,16 @@ OBJDIR = .\output\samples-$(TARGET) BINDIR = ..\bin\samples -SAMPLES = $(BINDIR)\simpleua.exe $(BINDIR)\playfile.exe $(BINDIR)\playsine.exe\ - $(BINDIR)\confsample.exe $(BINDIR)\sndinfo.exe \ - $(BINDIR)\level.exe $(BINDIR)\recfile.exe \ - $(BINDIR)\resampleplay.exe $(BINDIR)\siprtp.exe \ +SAMPLES = $(BINDIR)\confsample.exe \ + $(BINDIR)\level.exe \ + $(BINDIR)\playfile.exe \ + $(BINDIR)\playsine.exe\ + $(BINDIR)\recfile.exe \ + $(BINDIR)\resampleplay.exe \ + $(BINDIR)\simpleua.exe \ + $(BINDIR)\siprtp.exe \ + $(BINDIR)\sipstateless.exe \ + $(BINDIR)\sndinfo.exe \ $(BINDIR)\streamutil.exe diff --git a/pjsip-apps/build/Samples.mak b/pjsip-apps/build/Samples.mak index db945109..2e6d01b6 100644 --- a/pjsip-apps/build/Samples.mak +++ b/pjsip-apps/build/Samples.mak @@ -38,8 +38,17 @@ SRCDIR := ../src/samples OBJDIR := ./output/samples-$(TARGET) BINDIR := ../bin/samples -SAMPLES := simpleua playfile playsine confsample sndinfo level recfile resampleplay \ - siprtp streamutil +SAMPLES := confsample \ + level \ + playfile \ + playsine \ + recfile \ + resampleplay \ + simpleua \ + siprtp \ + sipstateless \ + sndinfo \ + streamutil EXES := $(foreach file, $(SAMPLES), $(BINDIR)/$(file)-$(TARGET)$(HOST_EXE)) diff --git a/pjsip-apps/build/samples.dsp b/pjsip-apps/build/samples.dsp index 189f5468..e0c374dd 100644 --- a/pjsip-apps/build/samples.dsp +++ b/pjsip-apps/build/samples.dsp @@ -122,6 +122,10 @@ SOURCE=..\src\samples\siprtp_report.c # End Source File # Begin Source File +SOURCE=..\src\samples\sipstateless.c +# End Source File +# Begin Source File + SOURCE=..\src\samples\sndinfo.c # End Source File # Begin Source File diff --git a/pjsip-apps/src/samples/sipstateless.c b/pjsip-apps/src/samples/sipstateless.c new file mode 100644 index 00000000..c3cfe071 --- /dev/null +++ b/pjsip-apps/src/samples/sipstateless.c @@ -0,0 +1,157 @@ +/* $Id$ */ +/* + * Copyright (C) 2003-2006 Benny Prijono <benny@prijono.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/** + * sipcore.c + * + * This program is only used to measure the footprint of the SIP core. + * When UDP transport is included (with HAS_UDP_TRANSPORT macro), the + * executable will respond any incoming requests with 501 (Not Implemented) + * response statelessly. + */ + + +/* Include all headers. */ +#include <pjsip.h> +#include <pjlib-util.h> +#include <pjlib.h> + + +/* If this macro is set, UDP transport will be initialized at port 5060 */ +#define HAS_UDP_TRANSPORT + + +/* Log identification */ +#define THIS_FILE "sipstateless.c" + + +/* Global SIP endpoint */ +static pjsip_endpoint *sip_endpt; + + +/* Callback to handle incoming requests. */ +static pj_bool_t on_rx_request( pjsip_rx_data *rdata ) +{ + /* Respond (statelessly) all incoming requests (except ACK!) + * with 501 (Not Implemented) + */ + if (rdata->msg_info.msg->line.req.method.id != PJSIP_ACK_METHOD) { + pjsip_endpt_respond_stateless( sip_endpt, rdata, + PJSIP_SC_NOT_IMPLEMENTED, NULL, + NULL, NULL); + } + return PJ_TRUE; +} + + + +/* + * main() + * + */ +int main() +{ + pj_caching_pool cp; + pjsip_module mod_app = + { + NULL, NULL, /* prev, next. */ + { "mod-app", 7 }, /* Name. */ + -1, /* Id */ + PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */ + NULL, /* load() */ + NULL, /* start() */ + NULL, /* stop() */ + NULL, /* unload() */ + &on_rx_request, /* on_rx_request() */ + NULL, /* on_rx_response() */ + NULL, /* on_tx_request. */ + NULL, /* on_tx_response() */ + NULL, /* on_tsx_state() */ + }; + + + pj_status_t status; + + /* Must init PJLIB first: */ + status = pj_init(); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); + + + /* Then init PJLIB-UTIL: */ + status = pjlib_util_init(); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); + + /* Must create a pool factory before we can allocate any memory. */ + pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); + + + /* Create global endpoint: */ + { + const pj_str_t *hostname; + const char *endpt_name; + + /* Endpoint MUST be assigned a globally unique name. + * The name will be used as the hostname in Warning header. + */ + + /* For this implementation, we'll use hostname for simplicity */ + hostname = pj_gethostname(); + endpt_name = hostname->ptr; + + /* Create the endpoint: */ + + status = pjsip_endpt_create(&cp.factory, endpt_name, + &sip_endpt); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); + } + + /* + * Add UDP transport, with hard-coded port + */ +#ifdef HAS_UDP_TRANSPORT + { + pj_sockaddr_in addr; + + addr.sin_family = PJ_AF_INET; + addr.sin_addr.s_addr = 0; + addr.sin_port = pj_htons(5060); + + status = pjsip_udp_transport_start( sip_endpt, &addr, NULL, 1, NULL); + if (status != PJ_SUCCESS) { + PJ_LOG(3,(THIS_FILE, + "Error starting UDP transport (port in use?)")); + return 1; + } + } +#endif + + /* + * Register our module to receive incoming requests. + */ + status = pjsip_endpt_register_module( sip_endpt, &mod_app); + PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1); + + + /* Done. Loop forever to handle incoming events. */ + PJ_LOG(3,(THIS_FILE, "Press Ctrl-C to quit..")); + + for (;;) { + pjsip_endpt_handle_events(sip_endpt, NULL); + } +} diff --git a/pjsip-apps/src/samples/streamutil.c b/pjsip-apps/src/samples/streamutil.c index 686a2efe..d87dae74 100644 --- a/pjsip-apps/src/samples/streamutil.c +++ b/pjsip-apps/src/samples/streamutil.c @@ -74,17 +74,25 @@ static pj_status_t init_codecs(pjmedia_endpt *med_endpt) { pj_status_t status; +#if defined(PJMEDIA_HAS_G711_CODEC) && PJMEDIA_HAS_G711_CODEC!=0 status = pjmedia_codec_g711_init(med_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); +#endif +#if defined(PJMEDIA_HAS_GSM_CODEC) && PJMEDIA_HAS_GSM_CODEC!=0 status = pjmedia_codec_gsm_init(med_endpt); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); +#endif +#if defined(PJMEDIA_HAS_SPEEX_CODEC) && PJMEDIA_HAS_SPEEX_CODEC!=0 status = pjmedia_codec_speex_init(med_endpt, 0, -1, -1); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); +#endif +#if defined(PJMEDIA_HAS_L16_CODEC) && PJMEDIA_HAS_L16_CODEC!=0 status = pjmedia_codec_l16_init(med_endpt, 0); PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); +#endif return PJ_SUCCESS; } diff --git a/pjsip/src/pjsip/sip_endpoint.c b/pjsip/src/pjsip/sip_endpoint.c index c4aeb742..3ede0102 100644 --- a/pjsip/src/pjsip/sip_endpoint.c +++ b/pjsip/src/pjsip/sip_endpoint.c @@ -103,9 +103,6 @@ void init_sip_parser(void); /* Defined in sip_tel_uri.c */ pj_status_t pjsip_tel_uri_subsys_init(void); -/* Defined in sip_util_statefull.c */ -extern pjsip_module mod_stateful_util; - /* Specifies whether error subsystem has been registered to pjlib. */ static int error_subsys_initialized; @@ -486,10 +483,6 @@ PJ_DEF(pj_status_t) pjsip_endpt_create(pj_pool_factory *pf, /* Initialize capability header list. */ pj_list_init(&endpt->cap_hdr); - /* Register mod_stateful_util module (sip_util_statefull.c) */ - status = pjsip_endpt_register_module(endpt, &mod_stateful_util); - if (status != PJ_SUCCESS) - goto on_error; /* Done. */ *p_endpt = endpt; diff --git a/pjsip/src/pjsip/sip_transaction.c b/pjsip/src/pjsip/sip_transaction.c index 8b20d8c2..b3c0609b 100644 --- a/pjsip/src/pjsip/sip_transaction.c +++ b/pjsip/src/pjsip/sip_transaction.c @@ -39,6 +39,10 @@ #endif +/* Defined in sip_util_statefull.c */ +extern pjsip_module mod_stateful_util; + + /***************************************************************************** ** ** Declarations and static variable definitions section. @@ -465,6 +469,12 @@ PJ_DEF(pj_status_t) pjsip_tsx_layer_init_module(pjsip_endpoint *endpt) return status; } + /* Register mod_stateful_util module (sip_util_statefull.c) */ + status = pjsip_endpt_register_module(endpt, &mod_stateful_util); + if (status != PJ_SUCCESS) { + return status; + } + return PJ_SUCCESS; } diff --git a/pjsip/src/pjsip/sip_util.c b/pjsip/src/pjsip/sip_util.c index 60f48681..d4f2dbac 100644 --- a/pjsip/src/pjsip/sip_util.c +++ b/pjsip/src/pjsip/sip_util.c @@ -1257,73 +1257,6 @@ PJ_DEF(pj_status_t) pjsip_endpt_respond_stateless( pjsip_endpoint *endpt, /* - * Send response statefully. - */ -PJ_DEF(pj_status_t) pjsip_endpt_respond( pjsip_endpoint *endpt, - pjsip_module *tsx_user, - pjsip_rx_data *rdata, - int st_code, - const pj_str_t *st_text, - const pjsip_hdr *hdr_list, - const pjsip_msg_body *body, - pjsip_transaction **p_tsx ) -{ - pj_status_t status; - pjsip_tx_data *tdata; - pjsip_transaction *tsx; - - /* Validate arguments. */ - PJ_ASSERT_RETURN(endpt && rdata, PJ_EINVAL); - - if (p_tsx) *p_tsx = NULL; - - /* Create response message */ - status = pjsip_endpt_create_response( endpt, rdata, st_code, st_text, - &tdata); - if (status != PJ_SUCCESS) - return status; - - /* Add the message headers, if any */ - if (hdr_list) { - const pjsip_hdr *hdr = hdr_list->next; - while (hdr != hdr_list) { - pjsip_msg_add_hdr( tdata->msg, pjsip_hdr_clone(tdata->pool, hdr) ); - hdr = hdr->next; - } - } - - /* Add the message body, if any. */ - if (body) { - tdata->msg->body = pjsip_msg_body_clone( tdata->pool, body ); - if (tdata->msg->body == NULL) { - pjsip_tx_data_dec_ref(tdata); - return status; - } - } - - /* Create UAS transaction. */ - status = pjsip_tsx_create_uas(tsx_user, rdata, &tsx); - if (status != PJ_SUCCESS) { - pjsip_tx_data_dec_ref(tdata); - return status; - } - - /* Feed the request to the transaction. */ - pjsip_tsx_recv_msg(tsx, rdata); - - /* Send the message. */ - status = pjsip_tsx_send_msg(tsx, tdata); - if (status != PJ_SUCCESS) { - pjsip_tx_data_dec_ref(tdata); - } else if (p_tsx) { - *p_tsx = tsx; - } - - return status; -} - - -/* * Get the event string from the event ID. */ PJ_DEF(const char *) pjsip_event_str(pjsip_event_id_e e) diff --git a/pjsip/src/pjsip/sip_util_statefull.c b/pjsip/src/pjsip/sip_util_statefull.c index c0427653..d211af93 100644 --- a/pjsip/src/pjsip/sip_util_statefull.c +++ b/pjsip/src/pjsip/sip_util_statefull.c @@ -89,6 +89,10 @@ PJ_DEF(pj_status_t) pjsip_endpt_send_request( pjsip_endpoint *endpt, PJ_ASSERT_RETURN(endpt && tdata && (timeout==-1 || timeout>0), PJ_EINVAL); + /* Check that transaction layer module is registered to endpoint */ + PJ_ASSERT_RETURN(mod_stateful_util.id != -1, PJ_EINVALIDOP); + + status = pjsip_tsx_create_uac(&mod_stateful_util, tdata, &tsx); if (status != PJ_SUCCESS) { pjsip_tx_data_dec_ref(tdata); @@ -105,3 +109,71 @@ PJ_DEF(pj_status_t) pjsip_endpt_send_request( pjsip_endpoint *endpt, return pjsip_tsx_send_msg(tsx, NULL); } + +/* + * Send response statefully. + */ +PJ_DEF(pj_status_t) pjsip_endpt_respond( pjsip_endpoint *endpt, + pjsip_module *tsx_user, + pjsip_rx_data *rdata, + int st_code, + const pj_str_t *st_text, + const pjsip_hdr *hdr_list, + const pjsip_msg_body *body, + pjsip_transaction **p_tsx ) +{ + pj_status_t status; + pjsip_tx_data *tdata; + pjsip_transaction *tsx; + + /* Validate arguments. */ + PJ_ASSERT_RETURN(endpt && rdata, PJ_EINVAL); + + if (p_tsx) *p_tsx = NULL; + + /* Create response message */ + status = pjsip_endpt_create_response( endpt, rdata, st_code, st_text, + &tdata); + if (status != PJ_SUCCESS) + return status; + + /* Add the message headers, if any */ + if (hdr_list) { + const pjsip_hdr *hdr = hdr_list->next; + while (hdr != hdr_list) { + pjsip_msg_add_hdr( tdata->msg, pjsip_hdr_clone(tdata->pool, hdr) ); + hdr = hdr->next; + } + } + + /* Add the message body, if any. */ + if (body) { + tdata->msg->body = pjsip_msg_body_clone( tdata->pool, body ); + if (tdata->msg->body == NULL) { + pjsip_tx_data_dec_ref(tdata); + return status; + } + } + + /* Create UAS transaction. */ + status = pjsip_tsx_create_uas(tsx_user, rdata, &tsx); + if (status != PJ_SUCCESS) { + pjsip_tx_data_dec_ref(tdata); + return status; + } + + /* Feed the request to the transaction. */ + pjsip_tsx_recv_msg(tsx, rdata); + + /* Send the message. */ + status = pjsip_tsx_send_msg(tsx, tdata); + if (status != PJ_SUCCESS) { + pjsip_tx_data_dec_ref(tdata); + } else if (p_tsx) { + *p_tsx = tsx; + } + + return status; +} + + |