Skip to content

Commit

Permalink
emergency -- last test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
evillaron committed Sep 7, 2015
1 parent 7781342 commit 579a82b
Show file tree
Hide file tree
Showing 19 changed files with 283 additions and 203 deletions.
219 changes: 140 additions & 79 deletions modules/emergency/emergency_methods.c

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions modules/emergency/emergency_methods.h
Expand Up @@ -17,7 +17,7 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
Expand All @@ -27,6 +27,7 @@
* 2015-05-20 change callcell identity
* 2015-06-08 change from list to hash (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/

#include <string.h>
Expand All @@ -41,6 +42,7 @@
#include "../../mod_fix.h"
#include "../../socket_info.h"
#include "../../route_struct.h"
#include "../../route.c"
#include "../rr/api.h"
#include "../../ip_addr.h"
#include "../../parser/msg_parser.h"
Expand All @@ -67,17 +69,9 @@
//str str_source;
//char *char_dest;


#define CP_STR_CHAR(str_source, char_dest)\
do{ \
char_dest = (char *)pkg_malloc( str_source.len + 1);\
if (!char_dest) {\
LM_ERR("no more shm\n");\
goto error;\
}\
memcpy(char_dest, str_source.s, str_source.len);\
char_dest[str_source.len] = 0;\
} while(0)
#define FREE_BUF(buf)\
if(buf != empty)\
pkg_free(buf);


#define MAXNUMBERLEN 31
Expand All @@ -91,6 +85,8 @@
#define ACK_TIME 3
#define BYE_TIME 10

#define EXPIRES_SUBSCRIBE 300

const char *BLANK_SPACE = " ";

struct code_number {
Expand Down Expand Up @@ -174,7 +170,7 @@ int check_myself(struct sip_msg *msg);
int contingency(struct sip_msg *msg, ESCT *call_cell);
int fill_blank_space(void);
int fill_parm_with_BS(char** var);
unsigned long get_xml_size(char* lie, char* formated_time, char* callidHeader, char* cbn);
unsigned long get_xml_size(char* lie, char* formated_time, char* callidHeader, char* cbn, char* call_origin);
char* formatted_xml(struct sip_msg *msg, char* lie, char* callidHeader, char* cbn);
int routing_by_ert( struct sip_msg *msg, ESCT *call_cell, int failure);
int treat_routing(struct sip_msg* msg, struct esct *call_cell, char* callidHeader, str cbn);
Expand Down
20 changes: 11 additions & 9 deletions modules/emergency/hash.c
Expand Up @@ -17,12 +17,13 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2015-06-08 change from list to hash (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -491,19 +492,20 @@ struct sm_subscriber* search_shtable(sbtable_t htable, str* callid, str* from_ta

LM_DBG("******************************METODO %.*s\n", method->len, method->s);

if (memcmp(method->s,"BYE", method->len) == 0) {
dlg_id = s->call_dlg_id;
}else{
dlg_id = s->dlg_id;
}
while(s)
{
if (memcmp(method->s,"BYE", method->len) == 0) {
dlg_id = s->call_dlg_id;
}else{
dlg_id = s->dlg_id;
}

LM_DBG(" --------------------CALLID M%.*s\n", callid->len, callid->s);
LM_DBG(" --------------------FROM TAG M%.*s\n", from_tag->len, from_tag->s);
LM_DBG(" --------------------CALLID T%.*s\n",dlg_id->callid.len,dlg_id->callid.s);
LM_DBG(" --------------------FROM TAG T%.*s\n",dlg_id->rem_tag.len,dlg_id->rem_tag.s);
LM_DBG(" --------------------FROM TAG T%.*s\n",dlg_id->rem_tag.len,dlg_id->rem_tag.s);


while(s)
{
if(dlg_id->callid.len == callid->len &&
strncmp(dlg_id->callid.s, callid->s, callid->len)==0 &&
dlg_id->rem_tag.len == from_tag->len &&
Expand Down
13 changes: 9 additions & 4 deletions modules/emergency/hash.h
Expand Up @@ -17,12 +17,13 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2015-06-08 change from list to hash (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/
#include "../../lock_ops.h"
#include "xml_parser.h"
Expand All @@ -31,9 +32,13 @@
#define SHARE_MEM "share"

#define CONT_COPY(buf, dest, source)\
if(source){ dest= (char*)buf+ size;\
memcpy(dest, source, strlen(source));\
size+= strlen(source) + 1;\
if(source){dest= (char*)buf+ size;\
if(source == empty){\
dest = empty;\
}else{\
memcpy(dest, source, strlen(source));\
}\
size+= strlen(source) + 1;\
}

#define CONT_COPY_STR(buf, dest, source)\
Expand Down
32 changes: 7 additions & 25 deletions modules/emergency/http_emergency.c
Expand Up @@ -17,7 +17,7 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
Expand All @@ -27,6 +27,7 @@
* 2015-05-20 change callcell identity
* 2015-06-08 change from list to hash (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/

#include <stdio.h>
Expand All @@ -47,7 +48,6 @@ int send_esct(struct sip_msg *msg, str callid_ori, str from_tag){
int resp;
char* callidHeader;
char* ftag;
str vsp_addr;
unsigned int hash_code;
str callid;

Expand All @@ -72,12 +72,6 @@ int send_esct(struct sip_msg *msg, str callid_ori, str from_tag){
// extract call cell with same callid from list linked eme_calls
LM_DBG(" --- BYE callid=%s \n", callidHeader);



vsp_addr.s = ip_addr2a(&msg->rcv.src_ip);
vsp_addr.len = strlen(vsp_addr.s);
LM_DBG("********************************************IP DE ORIGEM%.*s\n", vsp_addr.len, vsp_addr.s);

callid.s = callidHeader,
callid.len = strlen(callidHeader);

Expand Down Expand Up @@ -328,8 +322,7 @@ int treat_parse_esrResponse(struct sip_msg *msg, ESCT *call_cell, PARSED *parsed
memcpy(call_cell->lro, pt_lro.s, pt_lro.len);
call_cell->lro[pt_lro.len] = 0;
pkg_free(lro_aux);
pkg_free(parsed->lro);

pkg_free(parsed->lro);
}

end:
Expand Down Expand Up @@ -360,9 +353,9 @@ int get_lro_in_contact(char *contact_lro, ESCT *call_cell) {
pt_contact_lro.s = contact_lro_aux;
pt_contact_lro.len = len_contact_lro;

pattern_contact_lro.s = "(sips?:)*+?1?-?([0-9]+)@";
pattern_contact_lro.s = "sips?:[+]*1?-?([0-9]+)@";
pattern_contact_lro.len = strlen(pattern_contact_lro.s);
replacement_contact_lro.s = "\\2";
replacement_contact_lro.s = "\\1";
replacement_contact_lro.len = strlen(replacement_contact_lro.s);

if (reg_replace(pattern_contact_lro.s, replacement_contact_lro.s, contact_lro, &pt_contact_lro) != 1) {
Expand Down Expand Up @@ -417,12 +410,7 @@ int get_esqk_in_contact(char *contact_esgwri, ESCT *call_cell){
LM_ERR("****** PATTERN ESQK NAO OK \n");
pkg_free(contact_esqk_aux);
pkg_free(contact_esgwri);

if (strlen(call_cell->lro) <= 1){
pkg_free(call_cell->callid);
pkg_free(call_cell);
}
return -1;
return 0;
}
pt_contact_esqk.len = strlen(pt_contact_esqk.s);

Expand Down Expand Up @@ -501,13 +489,7 @@ int get_esgwri_ert_in_contact(char *contact_esgwri, ESCT *call_cell){
LM_ERR("****** PATTERN ERT NAO OK \n");
pkg_free(contact_routing_aux);
pkg_free(contact_routing);

if (strlen(call_cell->lro) <= 1){
pkg_free(call_cell->callid);
pkg_free(call_cell->esqk);
pkg_free(call_cell);
}
return -1;
return 0;
}

LM_DBG ("CONTEUDO TRANS REPLY ERT %.*s \n", pt_contact_routing.len, pt_contact_routing.s);
Expand Down
4 changes: 2 additions & 2 deletions modules/emergency/http_emergency.h
Expand Up @@ -17,7 +17,7 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
Expand All @@ -27,6 +27,7 @@
* 2015-05-20 change callcell identity
* 2015-06-08 change from list to hash (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/

#include "../../sr_module.h"
Expand Down Expand Up @@ -69,7 +70,6 @@ int emet_size;
int subst_size;

int send_esct(struct sip_msg *msg, str callid_ori, str from_tag);
int range_result(int result);
int treat_parse_esrResponse(struct sip_msg *msg, ESCT *call_cell, PARSED *parsed, int proxy_role);
int get_lro_in_contact(char *contact_lro, ESCT *call_cell);
int get_esqk_in_contact(char *contact_lro, ESCT *call_cell);
Expand Down
3 changes: 2 additions & 1 deletion modules/emergency/model.h
Expand Up @@ -17,14 +17,15 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2014-10-14 initial version (Villaron/Tesini)
* 2015-03-21 implementing subscriber function (Villaron/Tesini)
* 2015-04-29 implementing notifier function (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/

const char *MODEL = "<esrRequest xmlns=\"urn:nena:xml:ns:es:v2\" \n \
Expand Down
22 changes: 11 additions & 11 deletions modules/emergency/notifier_emergency.c
Expand Up @@ -17,7 +17,7 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
Expand All @@ -26,6 +26,7 @@
* 2015-04-29 implementing notifier function (Villaron/Tesini)
* 2015-06-08 change from list to hash (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/

#include <stdio.h>
Expand Down Expand Up @@ -65,6 +66,7 @@ struct sm_subscriber* build_notify_cell(struct sip_msg *msg, int expires){
unsigned int hash_code;
static str msg489={"Bad Event",sizeof("Bad Event")-1};


// get data from SUBSCRIBE request
// get callid from Subscribe
if( msg->callid==NULL || msg->callid->body.s==NULL){
Expand Down Expand Up @@ -99,10 +101,7 @@ struct sm_subscriber* build_notify_cell(struct sip_msg *msg, int expires){
LM_ERR("failed to parse TO header\n");
return NULL;
}
if( pto->tag_value.s ==NULL || pto->tag_value.len == 0){
LM_ERR("subscribe without to_tag value \n");
//return 0;
}

LM_DBG("PTO: %.*s \n ", pto->uri.len, pto->uri.s );
LM_DBG("PTO_TAG: %.*s \n ", pto->tag_value.len, pto->tag_value.s );

Expand Down Expand Up @@ -230,7 +229,7 @@ int treat_subscribe(struct sip_msg *msg) {
int expires= 0;
char *subs_callid, *subs_fromtag;
str callid_event;
unsigned int hash_code;
unsigned int hash_code;

if(!check_event_header(msg)){
LM_ERR("event header type not allow\n");
Expand Down Expand Up @@ -258,7 +257,7 @@ int treat_subscribe(struct sip_msg *msg) {
}
}

if (expires == 0){
if (expires == 0){

if(get_event_header(msg, &subs_callid, &subs_fromtag) == 1){
callid_event.s = subs_callid;
Expand Down Expand Up @@ -290,13 +289,14 @@ int treat_subscribe(struct sip_msg *msg) {
}

}else{

notify_cell = build_notify_cell(msg, expires);
if (notify_cell == NULL){
LM_ERR("**** error in build notify cell");
if(!eme_tm.t_reply(msg,489,&msg489)){
LM_ERR("t_reply (489)\n");
}
return 0;
}

/* Reply OK to Notify*/
if(!eme_tm.t_reply(msg,200,&msg200)){
LM_DBG("t_reply (200)\n");
Expand Down Expand Up @@ -416,7 +416,7 @@ void notif_cback_func(struct cell *t, int cb_type, struct tmcb_params *params){
LM_DBG("CODE: %d \n ", code);

// verify if response is OK
if (code < 300){
if (code >= 200 && code < 300){
// response OK(2XX)
if (params_notify->expires > 0){
LM_DBG("REPLY OK timeout %d \n", params_notify->timeout);
Expand All @@ -429,7 +429,7 @@ void notif_cback_func(struct cell *t, int cb_type, struct tmcb_params *params){

// update timeout
params_notify->timeout = params_notify->expires + time_now;
LM_DBG("TIMEOUT: %d \n ", params_notify->timeout);
LM_DBG("TIMEOUT_NOTIFY: %d \n ", params_notify->timeout);
return;
}
if (params_notify->dlg_id->status == TERMINATED){
Expand Down
5 changes: 3 additions & 2 deletions modules/emergency/notifier_emergency.h
Expand Up @@ -17,15 +17,16 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2014-10-14 initial version (Villaron/Tesini)
* 2015-03-21 implementing subscriber function (Villaron/Tesini)
* 2015-04-29 implementing notifier function (Villaron/Tesini)
* 2015-06-08 change from list to hash (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/


Expand Down
5 changes: 3 additions & 2 deletions modules/emergency/post_curl.c
Expand Up @@ -17,14 +17,15 @@
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2014-10-14 initial version (Villaron/Tesini)
* 2015-03-21 implementing subscriber function (Villaron/Tesini)
* 2015-04-29 implementing notifier function (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-08-05 code review (Villaron/Tesini)
* 2015-09-07 final test cases (Villaron/Tesini)
*/


Expand Down

0 comments on commit 579a82b

Please sign in to comment.