diff --git a/README.md b/README.md index a5ae9e2..6926545 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,16 @@ [![Build Status](https://travis-ci.org/staskobzar/sippak.svg?branch=master)](https://travis-ci.org/staskobzar/sippak) [![codecov](https://codecov.io/gh/staskobzar/sippak/branch/master/graph/badge.svg)](https://codecov.io/gh/staskobzar/sippak) +[![CodeFactor](https://www.codefactor.io/repository/github/staskobzar/sippak/badge/master)](https://www.codefactor.io/repository/github/staskobzar/sippak/overview/master) +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/3c43374de75b492e9e0be3d97612e643)](https://www.codacy.com/app/staskobzar/sippak?utm_source=github.com&utm_medium=referral&utm_content=staskobzar/sippak&utm_campaign=Badge_Grade) ![GPL3](https://img.shields.io/badge/license-GPL_3-green.svg "License") -Simple command line utility for SIP protocol based on PJPROJECT. +Simple command line utility for SIP protocol based on [PJPROJECT](http://www.pjsip.org/). +Can be useful for SIP administrators and developers. + +
+ +
### Install @@ -16,6 +23,8 @@ make sudo make install ``` +Also, packages (rpm, deb and tgz) are available in "[dist](https://github.com/staskobzar/sippak/tree/master/dist)" directory. + ### Usage ``` diff --git a/sippak.png b/sippak.png new file mode 100644 index 0000000..d49be4f Binary files /dev/null and b/sippak.png differ diff --git a/src/app/sip_helper.c b/src/app/sip_helper.c index 68a2179..047e6e1 100644 --- a/src/app/sip_helper.c +++ b/src/app/sip_helper.c @@ -202,3 +202,27 @@ PJ_DEF(void) sippak_add_sip_headers (pjsip_tx_data *tdata, struct sippak_app *ap } } } + +PJ_DEF(pj_bool_t) sippak_set_proxies_list(struct sippak_app *app, pjsip_route_hdr **rset) +{ + pjsip_route_hdr *route_set = pj_pool_alloc(app->pool, sizeof(pjsip_route_hdr)); + int i; + const pj_str_t hname = { "Route", 5 }; + + if (app->cfg.proxy.cnt == 0) { + return PJ_FALSE; + } + + pj_list_init(route_set); + + for(i = 0; i < app->cfg.proxy.cnt; i++) { + pjsip_route_hdr *route = pjsip_parse_hdr(app->pool, &hname, + app->cfg.proxy.p[i], pj_ansi_strlen(app->cfg.proxy.p[i]), + NULL); + if (route) { + pj_list_push_back(route_set, route); + } + } + *rset = route_set; + return PJ_TRUE; +} diff --git a/src/include/sippak.h.in b/src/include/sippak.h.in index 7d82c58..ed07a04 100644 --- a/src/include/sippak.h.in +++ b/src/include/sippak.h.in @@ -279,4 +279,13 @@ PJ_DEF(pj_status_t) sippak_set_media_sdp(struct sippak_app *app, pjmedia_sdp_ses */ PJ_DEF(void) sippak_add_sip_headers (pjsip_tx_data *tdata, struct sippak_app *app); +/** + * Set proxies list. + * + * @param dlg PJSIP dialog instance + * @param list Route set + * @return PJ_TRUE if set + */ +PJ_DEF(pj_bool_t) sippak_set_proxies_list(struct sippak_app *app, pjsip_route_hdr **route_set); + #endif diff --git a/src/mod/invite.c b/src/mod/invite.c index a708b4b..2ef4432 100644 --- a/src/mod/invite.c +++ b/src/mod/invite.c @@ -36,7 +36,6 @@ static pj_bool_t on_rx_response (pjsip_rx_data *rdata); static void call_on_state_changed( pjsip_inv_session *inv, pjsip_event *e); static void call_on_forked(pjsip_inv_session *inv, pjsip_event *e); static void call_tsx_state_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e); -static void set_dlg_outbound_proxy(pjsip_dialog *dlg, struct sippak_app *app); static pj_bool_t early_cancel; static pjsip_inv_session *inv; @@ -129,29 +128,6 @@ static void call_on_forked(pjsip_inv_session *inv, pjsip_event *e) PJ_UNUSED_ARG(inv); } -static void set_dlg_outbound_proxy(pjsip_dialog *dlg, struct sippak_app *app) -{ - pjsip_route_hdr route_set; - int i; - const pj_str_t hname = { "Route", 5 }; - - if (app->cfg.proxy.cnt == 0) { - return; - } - - pj_list_init(&route_set); - - for(i = 0; i < app->cfg.proxy.cnt; i++) { - pjsip_route_hdr *route = pjsip_parse_hdr(dlg->pool, &hname, - app->cfg.proxy.p[i], pj_ansi_strlen(app->cfg.proxy.p[i]), - NULL); - if (route) { - pj_list_push_back(&route_set, route); - } - } - pjsip_dlg_set_route_set(dlg, &route_set); -} - /* Ping */ PJ_DEF(pj_status_t) sippak_cmd_invite (struct sippak_app *app) { @@ -164,6 +140,7 @@ PJ_DEF(pj_status_t) sippak_cmd_invite (struct sippak_app *app) pjsip_inv_callback inv_cb; pjsip_cred_info cred[1]; pjmedia_sdp_session *sdp_sess; + pjsip_route_hdr *route_set; early_cancel = app->cfg.cancel; @@ -213,7 +190,9 @@ PJ_DEF(pj_status_t) sippak_cmd_invite (struct sippak_app *app) SIPPAK_ASSERT_SUCC(status, "Failed to create invite UAC."); /* outbound proxy */ - set_dlg_outbound_proxy(dlg, app); + if (sippak_set_proxies_list(app, &route_set) == PJ_TRUE) { + pjsip_dlg_set_route_set(dlg, route_set); + } /* create invite request */ status = pjsip_inv_invite(inv, &tdata); diff --git a/src/mod/publish.c b/src/mod/publish.c index 04c848a..1f4531e 100644 --- a/src/mod/publish.c +++ b/src/mod/publish.c @@ -34,7 +34,6 @@ static pj_bool_t on_rx_response (pjsip_rx_data *rdata); static short unsigned auth_tries = 0; static int pj_str_toi(pj_str_t val); -static void set_pubc_outbound_proxy(pjsip_publishc *pubc, struct sippak_app *app); static pjsip_module mod_publish = { @@ -84,29 +83,6 @@ static void publish_cb(struct pjsip_publishc_cbparam *param) sippak_loop_cancel(); } -static void set_pubc_outbound_proxy(pjsip_publishc *pubc, struct sippak_app *app) -{ - pjsip_route_hdr route_set; - int i; - const pj_str_t hname = { "Route", 5 }; - - if (app->cfg.proxy.cnt == 0) { - return; - } - - pj_list_init(&route_set); - - for(i = 0; i < app->cfg.proxy.cnt; i++) { - pjsip_route_hdr *route = pjsip_parse_hdr(app->pool, &hname, - app->cfg.proxy.p[i], pj_ansi_strlen(app->cfg.proxy.p[i]), - NULL); - if (route) { - pj_list_push_back(&route_set, route); - } - } - pjsip_publishc_set_route_set (pubc, &route_set); -} - PJ_DEF(pj_status_t) sippak_cmd_publish (struct sippak_app *app) { pj_status_t status; @@ -119,6 +95,7 @@ PJ_DEF(pj_status_t) sippak_cmd_publish (struct sippak_app *app) pjsip_publishc *publish_sess = NULL; pjsip_publishc_opt publish_opt; pjsip_tx_data *tdata; + pjsip_route_hdr *route_set; pjsip_pres_status pres_status; pjsip_cred_info cred[1]; pj_str_t event; @@ -161,7 +138,9 @@ PJ_DEF(pj_status_t) sippak_cmd_publish (struct sippak_app *app) sippak_set_cred(app, cred); - set_pubc_outbound_proxy(publish_sess, app); + if (sippak_set_proxies_list(app, &route_set) == PJ_TRUE) { + pjsip_publishc_set_route_set (publish_sess, route_set); + } status = pjsip_publishc_set_credentials(publish_sess, 1, cred); SIPPAK_ASSERT_SUCC(status, "Failed to set auth credentials."); diff --git a/src/mod/register.c b/src/mod/register.c index 9e0e124..0d832d8 100644 --- a/src/mod/register.c +++ b/src/mod/register.c @@ -31,7 +31,6 @@ static void reg_callback(struct pjsip_regc_cbparam *param); static void print_reg_success(struct pjsip_regc_cbparam *regp); -static void set_regc_outbound_proxy(pjsip_regc *regc, struct sippak_app *app); static pjsip_module mod_register = { @@ -89,29 +88,6 @@ static void reg_callback(struct pjsip_regc_cbparam *regp) sippak_loop_cancel(); } -static void set_regc_outbound_proxy(pjsip_regc *regc, struct sippak_app *app) -{ - pjsip_route_hdr route_set; - int i; - const pj_str_t hname = { "Route", 5 }; - - if (app->cfg.proxy.cnt == 0) { - return; - } - - pj_list_init(&route_set); - - for(i = 0; i < app->cfg.proxy.cnt; i++) { - pjsip_route_hdr *route = pjsip_parse_hdr(app->pool, &hname, - app->cfg.proxy.p[i], pj_ansi_strlen(app->cfg.proxy.p[i]), - NULL); - if (route) { - pj_list_push_back(&route_set, route); - } - } - pjsip_regc_set_route_set(regc, &route_set); -} - /* Register */ PJ_DEF(pj_status_t) sippak_cmd_register (struct sippak_app *app) { @@ -121,6 +97,7 @@ PJ_DEF(pj_status_t) sippak_cmd_register (struct sippak_app *app) pjsip_tx_data *tdata; pjsip_regc *regc; pjsip_cred_info cred[1]; + pjsip_route_hdr *route_set; pj_str_t srv_url, from_uri, to_uri; pj_str_t contacts[1]; @@ -154,7 +131,9 @@ PJ_DEF(pj_status_t) sippak_cmd_register (struct sippak_app *app) status = pjsip_regc_set_credentials(regc, 1, cred); SIPPAK_ASSERT_SUCC(status, "Failed to set auth credentials."); - set_regc_outbound_proxy(regc, app); + if (sippak_set_proxies_list(app, &route_set) == PJ_TRUE) { + pjsip_regc_set_route_set(regc, route_set); + } if (app->cfg.cancel_all_reg == PJ_TRUE) { status = pjsip_regc_unregister_all(regc, &tdata); diff --git a/src/mod/subscribe.c b/src/mod/subscribe.c index 86e774d..d9f2ed3 100644 --- a/src/mod/subscribe.c +++ b/src/mod/subscribe.c @@ -40,7 +40,6 @@ static void on_rx_notify(pjsip_evsub *sub, pjsip_rx_data *rdata, int *p_st_code, pj_str_t **p_st_text, pjsip_hdr *res_hdr, pjsip_msg_body **p_body); static void on_tsx_state(pjsip_evsub *sub, pjsip_transaction *tsx, pjsip_event *event); static sippak_evtype_e set_sub_evtype(struct sippak_app *app); -static void set_dlg_outbound_proxy(pjsip_dialog *dlg, struct sippak_app *app); static short unsigned auth_tries = 0; static pjsip_module mod_subscribe = @@ -148,29 +147,6 @@ static sippak_evtype_e set_sub_evtype(struct sippak_app *app) return app->cfg.pres_ev; } -static void set_dlg_outbound_proxy(pjsip_dialog *dlg, struct sippak_app *app) -{ - pjsip_route_hdr route_set; - int i; - const pj_str_t hname = { "Route", 5 }; - - if (app->cfg.proxy.cnt == 0) { - return; - } - - pj_list_init(&route_set); - - for(i = 0; i < app->cfg.proxy.cnt; i++) { - pjsip_route_hdr *route = pjsip_parse_hdr(dlg->pool, &hname, - app->cfg.proxy.p[i], pj_ansi_strlen(app->cfg.proxy.p[i]), - NULL); - if (route) { - pj_list_push_back(&route_set, route); - } - } - pjsip_dlg_set_route_set(dlg, &route_set); -} - PJ_DEF(pj_status_t) sippak_cmd_subscribe (struct sippak_app *app) { pj_status_t status; @@ -200,7 +176,7 @@ PJ_DEF(pj_status_t) sippak_cmd_subscribe (struct sippak_app *app) SIPPAK_ASSERT_SUCC(status, "Failed to create dialog uac."); // TODO: set routes for subscribe - // set_dlg_outbound_proxy(dlg, app); + // sippak_set_dlg_outbound_proxy(dlg, app); sippak_set_cred(app, cred); status = pjsip_auth_clt_set_credentials(&dlg->auth_sess, 1, cred);