From efc550418c0b107c07818809a3d8e779e476dcd4 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Tue, 4 Nov 2008 09:31:09 +0100 Subject: [PATCH] Added processing of second caller id. New routing macht rule to filter second caller id. Fixed extensions directory path. "make clean" now cleans ".po" files. Fixed unititialized variable bugs and compiler warnings. modified: Makefile.am modified: Makefile.in modified: action.cpp modified: apppbx.cpp modified: callerid.c modified: chan_lcr.c modified: dss1.cpp modified: dss1.h modified: extension.c modified: gentones.c modified: ie.cpp modified: mISDN.cpp modified: message.h modified: port.cpp modified: route.c modified: route.h modified: socket_server.c modified: tones.c modified: trace.c --- Makefile.am | 5 +- Makefile.in | 7 ++- action.cpp | 2 +- apppbx.cpp | 42 +++++++++++-- callerid.c | 3 + chan_lcr.c | 6 +- dss1.cpp | 190 +++++++++++++++++++++++++++++++++++++++----------------- dss1.h | 4 +- extension.c | 1 + gentones.c | 6 +- ie.cpp | 108 +++++++++++++++++++++++++++++++- mISDN.cpp | 2 +- message.h | 12 ++-- port.cpp | 7 +-- route.c | 13 +++- route.h | 1 + socket_server.c | 1 + tones.c | 4 +- trace.c | 18 +----- 19 files changed, 325 insertions(+), 107 deletions(-) diff --git a/Makefile.am b/Makefile.am index 844c2d8..7f1b577 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,7 +41,7 @@ INSTALLATION_DEFINES = \ -DCONFIG_DATA="\"$(CONFIGdir)\"" \ -DSHARE_DATA="\"$(SHAREdir)\"" \ -DLOG_DIR="\"$(LOGdir)\"" \ - -DEXTENSION_DATA="\"$(EXTENSIONdir)/extensions\"" + -DEXTENSION_DATA="\"$(EXTENSIONdir)\"" INCLUDES = $(all_includes) -I/usr/include/mISDNuser $(INSTALLATION_DEFINES) @@ -134,6 +134,9 @@ install-data-hook: echo "NOTE: special efi tones already exists, not overwritten." ; else \ cp -a tones_efi $(SHAREdir) ; fi +clean-generic: + rm -f *.po + # test rule, nothing important #echo: # -echo $(all_libraries) >&2 diff --git a/Makefile.in b/Makefile.in index 929550d..9a94335 100644 --- a/Makefile.in +++ b/Makefile.in @@ -222,7 +222,7 @@ INSTALLATION_DEFINES = \ -DCONFIG_DATA="\"$(CONFIGdir)\"" \ -DSHARE_DATA="\"$(SHAREdir)\"" \ -DLOG_DIR="\"$(LOGdir)\"" \ - -DEXTENSION_DATA="\"$(EXTENSIONdir)/extensions\"" + -DEXTENSION_DATA="\"$(EXTENSIONdir)\"" INCLUDES = $(all_includes) -I/usr/include/mISDNuser $(INSTALLATION_DEFINES) @ENABLE_ASTERISK_CHANNEL_DRIVER_TRUE@chan_lcr_so_SOURCES = @@ -641,8 +641,6 @@ install-strip: echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install mostlyclean-generic: -clean-generic: - distclean-generic: -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) @@ -788,6 +786,9 @@ install-data-hook: @if test -a $(SHAREdir)/tones_efi ; then \ echo "NOTE: special efi tones already exists, not overwritten." ; else \ cp -a tones_efi $(SHAREdir) ; fi + +clean-generic: + rm -f *.po # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/action.cpp b/action.cpp index d0a1c9f..5819670 100644 --- a/action.cpp +++ b/action.cpp @@ -1503,7 +1503,7 @@ void EndpointAppPBX::action_dialing_calculator(void) struct port_list *portlist = ea_endpoint->ep_portlist; struct lcr_msg *message; double value1, value2, v, sign1; - int komma1, komma2, k, state, mode, first; + int komma1, komma2, k, state, mode = 0, first; char *p; portlist = ea_endpoint->ep_portlist; diff --git a/apppbx.cpp b/apppbx.cpp index 3132417..88694e0 100644 --- a/apppbx.cpp +++ b/apppbx.cpp @@ -386,7 +386,7 @@ char *EndpointAppPBX::apply_callerid_display(const char *id, int itype, int ntyp } /* display if callerid is anonymouse but available due anon-ignore */ - if (e_ext.display_fake && screen==INFO_SCREEN_USER && present!=INFO_PRESENT_NULL) + if (e_ext.display_fake && screen==INFO_SCREEN_USER && ntype!=INFO_NTYPE_NOTPRESENT) { if (!display[0]) { @@ -1023,6 +1023,7 @@ void EndpointAppPBX::out_setup(void) //terminal SCPY(message->param.setup.to_terminal, e_dialinginfo.id); /* handle restricted caller ids */ apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id, &message->param.setup.callerinfo.ntype, &message->param.setup.callerinfo.present, &message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name); + apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id2, &message->param.setup.callerinfo.ntype2, &message->param.setup.callerinfo.present2, &message->param.setup.callerinfo.screen2, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name); apply_callerid_restriction(&e_ext, message->param.setup.redirinfo.id, &message->param.setup.redirinfo.ntype, &message->param.setup.redirinfo.present, 0, message->param.setup.redirinfo.extension, NULL); /* display callerid if desired for extension */ SCPY(message->param.setup.callerinfo.display, apply_callerid_display(message->param.setup.callerinfo.id, message->param.setup.callerinfo.itype, message->param.setup.callerinfo.ntype, message->param.setup.callerinfo.present, message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name)); @@ -1037,11 +1038,18 @@ void EndpointAppPBX::out_setup(void) SCAT(message->param.setup.callerinfo.id, numberrize_callerinfo(e_callerinfo.id,e_callerinfo.ntype, options.national, options.international)); message->param.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN; } + if (message->param.setup.callerinfo.id2[0] && e_ext.clip_prefix[0]) + { + SCPY(message->param.setup.callerinfo.id2, e_ext.clip_prefix); + SCAT(message->param.setup.callerinfo.id2, numberrize_callerinfo(e_callerinfo.id2,e_callerinfo.ntype2, options.national, options.international)); + message->param.setup.callerinfo.ntype2 = INFO_NTYPE_UNKNOWN; + } /* use internal caller id */ if (e_callerinfo.extension[0] && (message->param.setup.callerinfo.present!=INFO_PRESENT_RESTRICTED || e_ext.anon_ignore)) { SCPY(message->param.setup.callerinfo.id, e_callerinfo.extension); message->param.setup.callerinfo.ntype = INFO_NTYPE_UNKNOWN; + message->param.setup.callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT; } message_put(message); logmessage(message->type, &message->param, portlist->port_id, DIRECTION_OUT); @@ -1055,6 +1063,7 @@ void EndpointAppPBX::out_setup(void) if (e_ext.anon_ignore && e_callerinfo.id[0]) { e_callerinfo.present = INFO_PRESENT_ALLOWED; + e_callerinfo.present2 = INFO_PRESENT_ALLOWED; } } @@ -1135,6 +1144,7 @@ void EndpointAppPBX::out_setup(void) SCPY(message->param.setup.callerinfo.extension, e_ext.number); message->param.setup.callerinfo.ntype = e_ext.callerid_type; message->param.setup.callerinfo.present = e_ext.callerid_present; + message->param.setup.callerinfo.ntype = INFO_NTYPE_NOTPRESENT; } memcpy(&message->param.setup.capainfo, &e_capainfo, sizeof(struct capa_info)); //terminal SCPY(message->param.setup.from_terminal, e_ext.number); @@ -1142,6 +1152,7 @@ void EndpointAppPBX::out_setup(void) //terminal SCPY(message->param.setup.to_terminal, e_dialinginfo.id); /* handle restricted caller ids */ apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id, &message->param.setup.callerinfo.ntype, &message->param.setup.callerinfo.present, &message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name); + apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id2, &message->param.setup.callerinfo.ntype2, &message->param.setup.callerinfo.present2, &message->param.setup.callerinfo.screen2, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name); apply_callerid_restriction(&e_ext, message->param.setup.redirinfo.id, &message->param.setup.redirinfo.ntype, &message->param.setup.redirinfo.present, 0, message->param.setup.redirinfo.extension, NULL); /* display callerid if desired for extension */ SCPY(message->param.setup.callerinfo.display, apply_callerid_display(message->param.setup.callerinfo.id, message->param.setup.callerinfo.itype, message->param.setup.callerinfo.ntype, message->param.setup.callerinfo.present, message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name)); @@ -1217,6 +1228,7 @@ void EndpointAppPBX::out_setup(void) //terminal SCPY(message->param.setup.to_terminal, e_dialinginfo.id); /* handle restricted caller ids */ apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id, &message->param.setup.callerinfo.ntype, &message->param.setup.callerinfo.present, &message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name); + apply_callerid_restriction(&e_ext, message->param.setup.callerinfo.id2, &message->param.setup.callerinfo.ntype2, &message->param.setup.callerinfo.present2, &message->param.setup.callerinfo.screen2, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name); apply_callerid_restriction(&e_ext, message->param.setup.redirinfo.id, &message->param.setup.redirinfo.ntype, &message->param.setup.redirinfo.present, 0, message->param.setup.redirinfo.extension, NULL); /* display callerid if desired for extension */ SCPY(message->param.setup.callerinfo.display, apply_callerid_display(message->param.setup.callerinfo.id, message->param.setup.callerinfo.itype, message->param.setup.callerinfo.ntype, message->param.setup.callerinfo.present, message->param.setup.callerinfo.screen, message->param.setup.callerinfo.extension, message->param.setup.callerinfo.name)); @@ -1493,8 +1505,10 @@ void EndpointAppPBX::port_setup(struct port_list *portlist, int message_type, un } interface = interface->next; } - if (interface) + if (interface) { do_screen(0, e_callerinfo.id, sizeof(e_callerinfo.id), &e_callerinfo.ntype, &e_callerinfo.present, interface); + do_screen(0, e_callerinfo.id2, sizeof(e_callerinfo.id2), &e_callerinfo.ntype2, &e_callerinfo.present2, interface); + } /* process extension */ if (e_callerinfo.itype == INFO_ITYPE_ISDN_EXTENSION) @@ -1565,6 +1579,7 @@ void EndpointAppPBX::port_setup(struct port_list *portlist, int message_type, un else e_callerinfo.present = e_ext.callerid_present; e_callerinfo.ntype = e_ext.callerid_type; } + e_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT; /* extension is written */ if (writeext) @@ -2087,7 +2102,7 @@ void EndpointAppPBX::port_connect(struct port_list *portlist, int message_type, /* other calls with no caller id (or not available for the extension) and force colp */ if ((e_connectinfo.id[0]=='\0' || (e_connectinfo.present==INFO_PRESENT_RESTRICTED && !e_ext.anon_ignore))&& e_ext.colp==COLP_FORCE) { - e_connectinfo.present = INFO_PRESENT_NOTAVAIL; + e_connectinfo.ntype = INFO_NTYPE_NOTPRESENT; if (portlist->port_type==PORT_TYPE_DSS1_TE_OUT || portlist->port_type==PORT_TYPE_DSS1_NT_OUT) /* external extension answered */ { port = find_port_id(portlist->port_id); @@ -2151,6 +2166,7 @@ void EndpointAppPBX::port_connect(struct port_list *portlist, int message_type, e_callerinfo.present = e_ext.callerid_present; e_callerinfo.ntype = e_ext.callerid_type; } + e_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT; e_connectedmode = 1; /* dtmf-hangup & disconnect prevention */ e_dtmf = 1; @@ -2607,7 +2623,6 @@ void EndpointAppPBX::port_resume(struct port_list *portlist, int message_type, u void EndpointAppPBX::ea_message_port(unsigned int port_id, int message_type, union parameter *param) { struct port_list *portlist; - struct lcr_msg *message; portlist = ea_endpoint->ep_portlist; while(portlist) @@ -2797,7 +2812,7 @@ void EndpointAppPBX::ea_message_port(unsigned int port_id, int message_type, uni default: - PDEBUG(DEBUG_EPOINT, "EPOINT(%d) epoint with terminal '%s' (caller id '%s') received a wrong message: %d\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, message); + PDEBUG(DEBUG_EPOINT, "EPOINT(%d) epoint with terminal '%s' (caller id '%s') received a wrong message: %d\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, message_type); } /* Note: this endpoint may be destroyed, so we MUST return */ @@ -3535,7 +3550,7 @@ void EndpointAppPBX::ea_message_join(unsigned int join_id, int message_type, uni break; default: - PDEBUG(DEBUG_EPOINT, "EPOINT(%d) epoint with terminal '%s' (caller id '%s') received a wrong message: #%d\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, message); + PDEBUG(DEBUG_EPOINT, "EPOINT(%d) epoint with terminal '%s' (caller id '%s') received a wrong message: #%d\n", ea_endpoint->ep_serial, e_ext.number, e_callerinfo.id, message_type); } } @@ -4094,6 +4109,21 @@ void EndpointAppPBX::logmessage(int message_type, union parameter *param, unsign default: add_trace("caller id", "present", "not available"); } + if (param->setup.callerinfo.ntype2) + { + add_trace("caller id2", "number", "%s", numberrize_callerinfo(param->setup.callerinfo.id2, param->setup.callerinfo.ntype2, options.national, options.international)); + switch(param->setup.callerinfo.present) + { + case INFO_PRESENT_RESTRICTED: + add_trace("caller id2", "present", "restricted"); + break; + case INFO_PRESENT_ALLOWED: + add_trace("caller id2", "present", "allowed"); + break; + default: + add_trace("caller id2", "present", "not available"); + } + } if (param->setup.redirinfo.id[0]) { add_trace("redir'ing", "number", "%s", numberrize_callerinfo(param->setup.redirinfo.id, param->setup.redirinfo.ntype, options.national, options.international)); diff --git a/callerid.c b/callerid.c index a60c451..c12e908 100644 --- a/callerid.c +++ b/callerid.c @@ -43,6 +43,9 @@ const char *numberrize_callerinfo(const char *string, int ntype, const char *nat switch(ntype) { + case INFO_NTYPE_NOTPRESENT: + return(""); + case INFO_NTYPE_INTERNATIONAL: strcpy(result, international); strncat(result, string, sizeof(result)-strlen(result)-1); diff --git a/chan_lcr.c b/chan_lcr.c index 3573e27..acc485d 100644 --- a/chan_lcr.c +++ b/chan_lcr.c @@ -543,17 +543,15 @@ static void send_setup_to_lcr(struct chan_call *call) } switch(ast->cid.cid_pres & AST_PRES_RESTRICTION) { - case AST_PRES_ALLOWED: - newparam.setup.callerinfo.present = INFO_PRESENT_ALLOWED; - break; case AST_PRES_RESTRICTED: newparam.setup.callerinfo.present = INFO_PRESENT_RESTRICTED; break; case AST_PRES_UNAVAILABLE: newparam.setup.callerinfo.present = INFO_PRESENT_NOTAVAIL; break; + case AST_PRES_ALLOWED: default: - newparam.setup.callerinfo.present = INFO_PRESENT_NULL; + newparam.setup.callerinfo.present = INFO_PRESENT_ALLOWED; } switch(ast->cid.cid_ton) { diff --git a/dss1.cpp b/dss1.cpp index bb32c41..3b14332 100644 --- a/dss1.cpp +++ b/dss1.cpp @@ -428,6 +428,7 @@ use_channel: void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) { int calling_type, calling_plan, calling_present, calling_screen; + int calling_type2, calling_plan2, calling_present2, calling_screen2; int called_type, called_plan; int redir_type, redir_plan, redir_present, redir_screen, redir_reason; int hlc_coding, hlc_presentation, hlc_interpretation, hlc_hlc, hlc_exthlc; @@ -463,7 +464,7 @@ void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) end_trace(); l1l2l3_trace_header(p_m_mISDNport, this, L3_SETUP_IND, DIRECTION_IN); - dec_ie_calling_pn(l3m, &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id)); + dec_ie_calling_pn(l3m, &calling_type, &calling_plan, &calling_present, &calling_screen, (unsigned char *)p_callerinfo.id, sizeof(p_callerinfo.id), &calling_type2, &calling_plan2, &calling_present2, &calling_screen2, (unsigned char *)p_callerinfo.id2, sizeof(p_callerinfo.id2)); dec_ie_called_pn(l3m, &called_type, &called_plan, (unsigned char *)p_dialinginfo.id, sizeof(p_dialinginfo.id)); dec_ie_keypad(l3m, (unsigned char *)keypad, sizeof(keypad)); /* te-mode: CNIP (calling name identification presentation) */ @@ -516,9 +517,10 @@ void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) switch (calling_type) { case -1: + p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT; + break; + case 0x0: p_callerinfo.ntype = INFO_NTYPE_UNKNOWN; - p_callerinfo.present = INFO_PRESENT_NOTAVAIL; - p_callerinfo.screen = INFO_SCREEN_NETWORK; break; case 0x1: p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL; @@ -536,6 +538,50 @@ void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) p_callerinfo.isdn_port = p_m_portnum; SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name); + /* caller info2 */ + switch (calling_present2) + { + case 1: + p_callerinfo.present2 = INFO_PRESENT_RESTRICTED; + break; + case 2: + p_callerinfo.present2 = INFO_PRESENT_NOTAVAIL; + break; + default: + p_callerinfo.present2 = INFO_PRESENT_ALLOWED; + break; + } + switch (calling_screen2) + { + case 0: + p_callerinfo.screen2 = INFO_SCREEN_USER; + break; + default: + p_callerinfo.screen2 = INFO_SCREEN_NETWORK; + break; + } + switch (calling_type2) + { + case -1: + p_callerinfo.ntype2 = INFO_NTYPE_NOTPRESENT; + break; + case 0x0: + p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN; + break; + case 0x1: + p_callerinfo.ntype2 = INFO_NTYPE_INTERNATIONAL; + break; + case 0x2: + p_callerinfo.ntype2 = INFO_NTYPE_NATIONAL; + break; + case 0x4: + p_callerinfo.ntype2 = INFO_NTYPE_SUBSCRIBER; + break; + default: + p_callerinfo.ntype2 = INFO_NTYPE_UNKNOWN; + break; + } + /* dialing information */ SCAT(p_dialinginfo.id, (char *)keypad); switch (called_type) @@ -600,9 +646,10 @@ void Pdss1::setup_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) switch (redir_type) { case -1: + p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT; + break; + case 0x0: p_redirinfo.ntype = INFO_NTYPE_UNKNOWN; - p_redirinfo.present = INFO_PRESENT_NULL; /* not redirecting */ - p_redirinfo.reason = INFO_REDIR_UNKNOWN; break; case 0x1: p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL; @@ -859,8 +906,7 @@ void Pdss1::proceeding_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3 switch (type) { case -1: - message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN; - message->param.notifyinfo.present = INFO_PRESENT_NULL; + message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT; break; case 1: message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL; @@ -940,8 +986,7 @@ void Pdss1::alerting_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) switch (type) { case -1: - message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN; - message->param.notifyinfo.present = INFO_PRESENT_NULL; + message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT; break; case 1: message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL; @@ -1016,9 +1061,8 @@ void Pdss1::connect_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) } switch (type) { - case 0x0: - p_connectinfo.present = INFO_PRESENT_NULL; /* no COLP info */ - p_connectinfo.ntype = INFO_NTYPE_UNKNOWN; + case -1: + p_connectinfo.ntype = INFO_NTYPE_NOTPRESENT; break; case 0x1: p_connectinfo.ntype = INFO_NTYPE_INTERNATIONAL; @@ -1280,8 +1324,7 @@ void Pdss1::notify_ind(unsigned int cmd, unsigned int pid, struct l3_msg *l3m) switch (type) { case -1: - message->param.notifyinfo.ntype = INFO_NTYPE_UNKNOWN; - message->param.notifyinfo.present = INFO_PRESENT_NULL; + message->param.notifyinfo.ntype = INFO_NTYPE_NOTPRESENT; break; case 1: message->param.notifyinfo.ntype = INFO_NTYPE_INTERNATIONAL; @@ -1907,6 +1950,7 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete l3_msg *l3m; int ret; int plan, type, screen, present, reason; + int plan2, type2, screen2, present2; int capability, mode, rate, coding, user, presentation, interpretation, hlc, exthlc; int channel, exclusive; struct epoint_list *epointlist; @@ -1933,6 +1977,7 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir); /* screen outgoing caller id */ do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface); + do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_m_mISDNport->ifport->interface); /* only display at connect state: this case happens if endpoint is in connected mode */ if (p_state==PORT_STATE_CONNECT) @@ -2012,6 +2057,9 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete plan = 1; switch (p_callerinfo.ntype) { + case INFO_NTYPE_UNKNOWN: + type = 0x0; + break; case INFO_NTYPE_INTERNATIONAL: type = 0x1; break; @@ -2021,8 +2069,8 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete case INFO_NTYPE_SUBSCRIBER: type = 0x4; break; - default: /* INFO_NTYPE_UNKNOWN */ - type = 0x0; + default: /* INFO_NTYPE_NOTPRESENT */ + type = -1; break; } switch (p_callerinfo.screen) @@ -2036,18 +2084,59 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete } switch (p_callerinfo.present) { + case INFO_PRESENT_ALLOWED: + present = 0; + break; case INFO_PRESENT_RESTRICTED: present = 1; break; - case INFO_PRESENT_NOTAVAIL: + default: /* INFO_PRESENT_NOTAVAIL */ present = 2; break; - default: /* INFO_PRESENT_ALLOWED */ - present = 0; + } + /* caller information 2 */ + plan2 = 1; + switch (p_callerinfo.ntype2) + { + case INFO_NTYPE_UNKNOWN: + type2 = 0x0; + break; + case INFO_NTYPE_INTERNATIONAL: + type2 = 0x1; + break; + case INFO_NTYPE_NATIONAL: + type2 = 0x2; + break; + case INFO_NTYPE_SUBSCRIBER: + type2 = 0x4; + break; + default: /* INFO_NTYPE_NOTPRESENT */ + type2 = -1; + break; + } + switch (p_callerinfo.screen2) + { + case INFO_SCREEN_USER: + screen2 = 0; + break; + default: /* INFO_SCREEN_NETWORK */ + screen2 = 3; + break; + } + switch (p_callerinfo.present2) + { + case INFO_PRESENT_ALLOWED: + present2 = 0; + break; + case INFO_PRESENT_RESTRICTED: + present2 = 1; + break; + default: /* INFO_PRESENT_NOTAVAIL */ + present2 = 2; break; } if (type >= 0) - enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id); + enc_ie_calling_pn(l3m, type, plan, present, screen, (unsigned char *)p_callerinfo.id, type2, plan2, present2, screen2, (unsigned char *)p_callerinfo.id2); /* dialing information */ if (p_dialinginfo.id[0]) /* only if we have something to dial */ { @@ -2065,6 +2154,9 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete plan = 1; switch (p_redirinfo.ntype) { + case INFO_NTYPE_UNKNOWN: + type = 0x0; + break; case INFO_NTYPE_INTERNATIONAL: type = 0x1; break; @@ -2074,8 +2166,8 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete case INFO_NTYPE_SUBSCRIBER: type = 0x4; break; - default: /* INFO_NTYPE_UNKNOWN */ - type = 0x0; + default: /* INFO_NTYPE_NOTPRESENT */ + type = -1; break; } switch (p_redirinfo.screen) @@ -2110,22 +2202,15 @@ void Pdss1::message_setup(unsigned int epoint_id, int message_id, union paramete } switch (p_redirinfo.present) { - case INFO_PRESENT_NULL: /* no redir at all */ - present = -1; - screen = -1; - reason = -1; - plan = -1; - type = -1; + case INFO_PRESENT_ALLOWED: + present = 0; break; case INFO_PRESENT_RESTRICTED: present = 1; break; - case INFO_PRESENT_NOTAVAIL: + default: /* INFO_PRESENT_NOTAVAIL */ present = 2; break; - default: /* INFO_PRESENT_ALLOWED */ - present = 0; - break; } /* sending redirecting number only in ntmode */ if (type >= 0 && (p_m_d_ntmode || p_m_d_tespecial)) @@ -2195,7 +2280,7 @@ void Pdss1::message_notify(unsigned int epoint_id, int message_id, union paramet { l3_msg *l3m; int notify; - int plan, type = -1, present; + int plan = 0, type = -1, present = 0; if (param->notifyinfo.notify>INFO_NOTIFY_NONE) notify = param->notifyinfo.notify & 0x7f; @@ -2211,6 +2296,9 @@ void Pdss1::message_notify(unsigned int epoint_id, int message_id, union paramet plan = 1; switch (param->notifyinfo.ntype) { + case INFO_NTYPE_UNKNOWN: + type = 0; + break; case INFO_NTYPE_INTERNATIONAL: type = 1; break; @@ -2221,25 +2309,20 @@ void Pdss1::message_notify(unsigned int epoint_id, int message_id, union paramet type = 4; break; default: /* INFO_NTYPE_UNKNOWN */ - type = 0; + type = -1; break; } switch (param->notifyinfo.present) { - case INFO_PRESENT_NULL: /* no redir at all */ - present = -1; - plan = -1; - type = -1; + case INFO_PRESENT_ALLOWED: + present = 0; break; case INFO_PRESENT_RESTRICTED: present = 1; break; - case INFO_PRESENT_NOTAVAIL: + default: /* INFO_PRESENT_NOTAVAIL */ present = 2; break; - default: /* INFO_PRESENT_ALLOWED */ - present = 0; - break; } } @@ -2431,6 +2514,9 @@ void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parame plan = 1; switch (p_connectinfo.ntype) { + case INFO_NTYPE_UNKNOWN: + type = 0x0; + break; case INFO_NTYPE_INTERNATIONAL: type = 0x1; break; @@ -2440,8 +2526,8 @@ void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parame case INFO_NTYPE_SUBSCRIBER: type = 0x4; break; - default: /* INFO_NTYPE_UNKNOWN */ - type = 0x0; + default: /* INFO_NTYPE_NOTPRESENT */ + type = -1; break; } switch (param->connectinfo.screen) @@ -2455,21 +2541,15 @@ void Pdss1::message_connect(unsigned int epoint_id, int message_id, union parame } switch (p_connectinfo.present) { - case INFO_PRESENT_NULL: /* no colp at all */ - present = -1; - screen = -1; - plan = -1; - type = -1; + case INFO_PRESENT_ALLOWED: + present = 0; break; case INFO_PRESENT_RESTRICTED: present = 1; break; - case INFO_PRESENT_NOTAVAIL: + default: /* INFO_PRESENT_NOTAVAIL */ present = 2; break; - default: /* INFO_PRESENT_ALLOWED */ - present = 0; - break; } if (type >= 0) enc_ie_connected_pn(l3m, type, plan, present, screen, (unsigned char *)p_connectinfo.id); @@ -2675,8 +2755,6 @@ wirklich erst proceeding?: */ int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union parameter *param) { - struct lcr_msg *message; - if (PmISDN::message_epoint(epoint_id, message_id, param)) return(1); @@ -2800,7 +2878,7 @@ int Pdss1::message_epoint(unsigned int epoint_id, int message_id, union paramete break; default: - PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message); + PERROR("Pdss1(%s) isdn port with (caller id %s) received a wrong message: %d\n", p_name, p_callerinfo.id, message_id); } return(1); diff --git a/dss1.h b/dss1.h index 821c587..cb31b3b 100644 --- a/dss1.h +++ b/dss1.h @@ -71,8 +71,8 @@ class Pdss1 : public PmISDN void dec_ie_call_id(struct l3_msg *l3m, unsigned char *callid, int *callid_len); void enc_ie_called_pn(struct l3_msg *l3m, int type, int plan, unsigned char *number); void dec_ie_called_pn(struct l3_msg *l3m, int *type, int *plan, unsigned char *number, int number_len); - void enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number); - void dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len); + void enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number, int type2, int plan2, int present2, int screen2, unsigned char *number2); + void dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len, int *type2, int *plan2, int *present2, int *screen2, unsigned char *number2, int number_len2); void enc_ie_connected_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number); void dec_ie_connected_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len); void enc_ie_cause(struct l3_msg *l3m, int location, int cause); diff --git a/extension.c b/extension.c index 973aa85..46cb2cf 100644 --- a/extension.c +++ b/extension.c @@ -55,6 +55,7 @@ int read_extension(struct extension *ext, char *num) if (!(fp = fopen(filename, "r"))) { + printf("the given extension doesn't exist: \"%s\"\n", filename); PDEBUG(DEBUG_CONFIG, "the given extension doesn't exist: \"%s\"\n", filename); return(0); } diff --git a/gentones.c b/gentones.c index bf91e26..daaf9cb 100644 --- a/gentones.c +++ b/gentones.c @@ -86,9 +86,9 @@ static short isdn_audio_alaw_to_s16[] = unsigned char encode_isdn(short sample, char law) { - int best=-1; + int best = -1; int i,diff; - int best_diff; + int best_diff = 9999; i=0; while(i<256) @@ -149,7 +149,7 @@ void write_wav(FILE *fp, char *wav, char law) struct fmt *fmt; FILE *wfp; signed int i; - int channels, bytes; + int channels = 0, bytes = 0; short sample, sample2; signed int size, chunk; int gotfmt = 0, gotdata = 0; diff --git a/ie.cpp b/ie.cpp index 31e6a35..c4033c4 100644 --- a/ie.cpp +++ b/ie.cpp @@ -373,7 +373,7 @@ void Pdss1::dec_ie_called_pn(struct l3_msg *l3m, int *type, int *plan, unsigned /* IE_CALLING_PN */ -void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number) +void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int present, int screen, unsigned char *number, int type2, int plan2, int present2, int screen2, unsigned char *number2) { unsigned char p[256]; int l; @@ -425,15 +425,74 @@ void Pdss1::enc_ie_calling_pn(struct l3_msg *l3m, int type, int plan, int presen UNCPY((char *)p+3, (char *)number, strlen((char *)number)); } add_layer3_ie(l3m, p[0], p[1], p+2); + + /* second calling party number */ + if (type2 < 0) + return; + + if (type2>7) + { + PERROR("type2(%d) is out of range.\n", type2); + return; + } + if (plan2<0 || plan2>15) + { + PERROR("plan2(%d) is out of range.\n", plan2); + return; + } + if (present2>3) + { + PERROR("present2(%d) is out of range.\n", present2); + return; + } + if (present2 >= 0) if (screen2<0 || screen2>3) + { + PERROR("screen2(%d) is out of range.\n", screen2); + return; + } + + add_trace("call_pn 2", "type", "%d", type2); + add_trace("call_pn 2", "plan", "%d", plan2); + add_trace("call_pn 2", "present", "%d", present2); + add_trace("call_pn 2", "screen", "%d", screen2); + add_trace("call_pn 2", "number", "%s", number2); + + l = 1; + if (number2) if (number2[0]) + l += strlen((char *)number2); + if (present2 >= 0) + l += 1; + p[0] = IE_CALLING_PN; + p[1] = l; + if (present2 >= 0) + { + p[2] = 0x00 + (type2<<4) + plan2; + p[3] = 0x80 + (present2<<5) + screen2; + if (number2) if (number2[0]) + UNCPY((char *)p+4, (char *)number2, strlen((char *)number2)); + } else + { + p[2] = 0x80 + (type2<<4) + plan2; + if (number2) if (number2[0]) + UNCPY((char *)p+3, (char *)number2, strlen((char *)number2)); + } + add_layer3_ie(l3m, p[0], p[1], p+2); } -void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len) +void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *present, int *screen, unsigned char *number, int number_len, int *type2, int *plan2, int *present2, int *screen2, unsigned char *number2, int number_len2) { *type = -1; *plan = -1; *present = -1; *screen = -1; *number = '\0'; + *type2 = -1; + *plan2 = -1; + *present2 = -1; + *screen2 = -1; + *number2 = '\0'; + unsigned int numextra = sizeof(l3m->extra) / sizeof(struct m_extie); + unsigned int i; unsigned char *p = l3m->calling_nr; if (!p) @@ -466,6 +525,51 @@ void Pdss1::dec_ie_calling_pn(struct l3_msg *l3m, int *type, int *plan, int *pre add_trace("calling_pn", "present", "%d", *present); add_trace("calling_pn", "screen", "%d", *screen); add_trace("calling_pn", "number", "%s", number); + + /* second calling party number */ + p = NULL; + i = 0; + while(i < numextra) + { + if (!l3m->extra[i].val) + break; + if (l3m->extra[i].ie == IE_CALLING_PN) + { + p = l3m->extra[i].val; + break; + } + i++; + } + if (!p) + return; + if (p[0] < 1) + { + add_trace("calling_pn2", "error", "IE too short (len=%d)", p[0]); + return; + } + + *type2 = (p[1]&0x70) >> 4; + *plan2 = p[1] & 0xf; + if (!(p[1] & 0x80)) + { + if (p[0] < 2) + { + add_trace("calling_pn2", "error", "IE too short (len=%d)", p[0]); + return; + } + *present2 = (p[2]&0x60) >> 5; + *screen2 = p[2] & 0x3; + strnncpy(number2, p+3, p[0]-2, number_len2); + } else + { + strnncpy(number2, p+2, p[0]-1, number_len2); + } + + add_trace("call_pn 2", "type", "%d", *type2); + add_trace("call_pn 2", "plan", "%d", *plan2); + add_trace("call_pn 2", "present", "%d", *present2); + add_trace("call_pn 2", "screen", "%d", *screen2); + add_trace("call_pn 2", "number", "%s", number2); } diff --git a/mISDN.cpp b/mISDN.cpp index 3e1d0e4..f228906 100644 --- a/mISDN.cpp +++ b/mISDN.cpp @@ -1534,7 +1534,7 @@ void PmISDN::set_echotest(int echo) */ void PmISDN::set_tone(const char *dir, const char *tone) { - int id; + int id = TONE_OFF; if (!tone) tone = ""; diff --git a/message.h b/message.h index 8fb7021..7ac4a84 100644 --- a/message.h +++ b/message.h @@ -19,17 +19,17 @@ enum { /* interface types */ }; enum { /* number types */ - INFO_NTYPE_UNKNOWN = 0, + INFO_NTYPE_NOTPRESENT = 0, + INFO_NTYPE_UNKNOWN, INFO_NTYPE_SUBSCRIBER, INFO_NTYPE_NATIONAL, INFO_NTYPE_INTERNATIONAL }; enum { /* number presentation */ - INFO_PRESENT_NULL = 0, + INFO_PRESENT_NOTAVAIL, INFO_PRESENT_ALLOWED, - INFO_PRESENT_RESTRICTED, - INFO_PRESENT_NOTAVAIL + INFO_PRESENT_RESTRICTED }; enum { /* number presentation */ @@ -161,6 +161,10 @@ struct caller_info { int present; /* presentation */ int screen; /* who provided the number */ char display[84]; /* display information */ + char id2[32]; /* second callerid */ + int ntype2; /* second type of number */ + int present2; /* second presentation */ + int screen2; /* second who provided the number */ }; /* call-info structure DIALING */ diff --git a/port.cpp b/port.cpp index 934a4cc..3867464 100644 --- a/port.cpp +++ b/port.cpp @@ -450,7 +450,6 @@ void Port::set_vbox_tone(const char *dir, const char *name) */ void Port::set_vbox_play(const char *name, int offset) { - signed int size; struct lcr_msg *message; /* use ser_box_tone() */ @@ -469,7 +468,7 @@ void Port::set_vbox_play(const char *name, int offset) { message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_TONE_COUNTER); message->param.counter.current = offset; - message->param.counter.max = size; + message->param.counter.max = p_tone_size; message_put(message); } } @@ -491,7 +490,7 @@ void Port::set_vbox_speed(int speed) */ int Port::read_audio(unsigned char *buffer, int length) { - int l,len; + int l = 0,len; int nodata=0; /* to detect 0-length files and avoid endless reopen */ char filename[128]; int tone_left_before; /* temp variable to determine the change in p_tone_left */ @@ -794,7 +793,7 @@ int Port::open_record(int type, int vbox, int skip, char *extension, int anon_ig void Port::close_record(int beep, int mute) { static signed short beep_mono[256]; - unsigned int size, wsize; + unsigned int size = 0, wsize = 0; struct fmt fmt; char filename[512], indexname[512]; FILE *fp; diff --git a/route.c b/route.c index 29381c2..2abc0f6 100644 --- a/route.c +++ b/route.c @@ -26,6 +26,8 @@ struct cond_defs cond_defs[] = { "interface=[,...]", "Matches if call is received from given interface(s). NOT PORTS!"}, { "callerid", MATCH_CALLERID, COND_TYPE_STRING, "callerid=[-][,...]", "Matches if caller ID matches or begins with the given (range(s) of) prefixes(s)."}, + { "callerid2", MATCH_CALLERID2,COND_TYPE_STRING, + "callerid2=[-][,...]", "Matches the second caller ID (network provided)."}, { "extension", MATCH_EXTENSION,COND_TYPE_STRING, "extension=[-][,...]", "Matches if caller calls from given (range(s) of) extension(s)."}, { "dialing", MATCH_DIALING, COND_TYPE_STRING, @@ -1956,7 +1958,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) struct route_action *action = NULL; unsigned long comp_len; int j, jj; - char callerid[64], redirid[64]; + char callerid[64], callerid2[64], redirid[64]; int integer; char *string; FILE *tfp; @@ -1969,6 +1971,7 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) e_match_to_action = NULL; SCPY(callerid, numberrize_callerinfo(e_callerinfo.id, e_callerinfo.ntype, options.national, options.international)); + SCPY(callerid2, numberrize_callerinfo(e_callerinfo.id2, e_callerinfo.ntype2, options.national, options.international)); SCPY(redirid, numberrize_callerinfo(e_redirinfo.id, e_redirinfo.ntype, options.national, options.international)); PDEBUG(DEBUG_ROUTE, "parsing ruleset '%s'\n", ruleset->name); @@ -2014,6 +2017,10 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) string = callerid; goto match_string_prefix; + case MATCH_CALLERID2: + string = callerid2; + goto match_string_prefix; + case MATCH_EXTENSION: string = e_ext.name; goto match_string; @@ -2063,12 +2070,12 @@ struct route_action *EndpointAppPBX::route(struct route_ruleset *ruleset) break; case MATCH_REDIRECTED: - if (e_redirinfo.present != INFO_PRESENT_NULL) + if (e_redirinfo.ntype != INFO_NTYPE_NOTPRESENT) istrue = 1; break; case MATCH_DIRECT: - if (e_redirinfo.present == INFO_PRESENT_NULL) + if (e_redirinfo.ntype == INFO_NTYPE_NOTPRESENT) istrue = 1; break; diff --git a/route.h b/route.h index a2d9d3b..06fb54f 100644 --- a/route.h +++ b/route.h @@ -41,6 +41,7 @@ enum { /* what to check during runtime */ MATCH_PORT, MATCH_INTERFACE, MATCH_CALLERID, + MATCH_CALLERID2, MATCH_EXTENSION, MATCH_DIALING, MATCH_ENBLOCK, diff --git a/socket_server.c b/socket_server.c index d4f8ae1..7f6e7ec 100644 --- a/socket_server.c +++ b/socket_server.c @@ -415,6 +415,7 @@ int admin_block(struct admin_queue **responsep, int portnum, int block) response->am[0].u.x.portnum = portnum; /* search for port */ + ifport = NULL; interface = interface_first; while(interface) { diff --git a/tones.c b/tones.c index e24e9c3..4f8a40f 100644 --- a/tones.c +++ b/tones.c @@ -41,7 +41,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) char linkname[256]; unsigned char buffer[256]; struct fmt *fmt; - int channels, bytes; + int channels = 0, bytes = 0; unsigned int size, chunk; int gotfmt = 0; struct stat _stat; @@ -272,7 +272,7 @@ int open_tone(char *file, int *codec, signed int *length, signed int *left) */ int read_tone(int fh, unsigned char *buffer, int codec, int len, signed int size, signed int *left, int speed) { - int l; + int l = 0; int offset; signed short buffer16[len], *buf16 = buffer16; signed short buffer32[len<<1], *buf32 = buffer32; diff --git a/trace.c b/trace.c index 8242a7c..2050a2d 100644 --- a/trace.c +++ b/trace.c @@ -14,19 +14,7 @@ struct trace trace; char trace_string[MAX_TRACE_ELEMENTS * 100 + 400]; -static const char *spaces[11] = { - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - " ", - "", -}; +static const char *spaces = " "; /* * initializes a new trace @@ -252,12 +240,12 @@ static char *print_trace(int detail, int port, char *interface, char *caller, ch i = 0; while(i < trace.elements) { - SPRINT(buffer, " %s%s", trace.element[i].name, spaces[strlen(trace.element[i].name)]); + SPRINT(buffer, " %s%s", trace.element[i].name, &spaces[strlen(trace.element[i].name)]); if (i) if (!strcmp(trace.element[i].name, trace.element[i-1].name)) SPRINT(buffer, " "); SCAT(trace_string, buffer); if (trace.element[i].sub[0]) - SPRINT(buffer, " : %s%s = ", trace.element[i].sub, spaces[strlen(trace.element[i].sub)]); + SPRINT(buffer, " : %s%s = ", trace.element[i].sub, &spaces[strlen(trace.element[i].sub)]); else SPRINT(buffer, " : "); SCAT(trace_string, buffer); -- 2.13.6