Add screening of caller ID for remote (asterisk) connections
[lcr.git] / remote.cpp
index 81268b5..ceb3ebc 100644 (file)
@@ -16,14 +16,13 @@ unsigned int new_remote = 1000;
 /*
  * constructor
  */
-Premote::Premote(int type, char *portname, struct port_settings *settings, struct interface *interface, int remote_id) : Port(type, portname, settings)
+Premote::Premote(int type, char *portname, struct port_settings *settings, struct interface *interface, int remote_id) : Port(type, portname, settings, interface)
 {
        union parameter param;
 
        p_callerinfo.itype = (interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
        p_r_ref = new_remote++;
        SCPY(p_r_remote_app, interface->remote_app);
-       SCPY(p_r_interface_name, interface->name);
        p_r_tones = (interface->is_tones == IS_YES);
 
        /* send new ref to remote socket */
@@ -59,9 +58,9 @@ int Premote::message_epoint(unsigned int epoint_id, int message_type, union para
        switch (message_type) {
        case MESSAGE_SETUP:
                struct interface *interface;
-               interface = getinterfacebyname(p_r_interface_name);
+               interface = getinterfacebyname(p_interface_name);
                if (!interface) {
-                       PERROR("Cannot find interface %s.\n", p_r_interface_name);
+                       PERROR("Cannot find interface %s.\n", p_interface_name);
                        return 0;
                }
                /* attach only if not already */
@@ -81,6 +80,14 @@ int Premote::message_epoint(unsigned int epoint_id, int message_type, union para
                        else
                                SCPY(param->setup.dialinginfo.context, "lcr");
                }
+               /* screen */
+               memcpy(&p_callerinfo, &param->setup.callerinfo, sizeof(p_callerinfo));
+               memcpy(&p_redirinfo, &param->setup.redirinfo, sizeof(p_redirinfo));
+               do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_interface_name);
+               do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_interface_name);
+               do_screen(1, p_redirinfo.id, sizeof(p_redirinfo.id), &p_redirinfo.ntype, &p_redirinfo.present, p_interface_name);
+               memcpy(&param->setup.callerinfo, &p_callerinfo, sizeof(p_callerinfo));
+               memcpy(&param->setup.redirinfo, &p_redirinfo, sizeof(p_redirinfo));
 
                new_state(PORT_STATE_OUT_SETUP);
                break;
@@ -133,9 +140,9 @@ void Premote::message_remote(int message_type, union parameter *param)
                break;
 
        case MESSAGE_SETUP:
-               interface = getinterfacebyname(p_r_interface_name);
+               interface = getinterfacebyname(p_interface_name);
                if (!interface) {
-                       PERROR("Cannot find interface %s.\n", p_r_interface_name);
+                       PERROR("Cannot find interface %s.\n", p_interface_name);
                        return;
                }