Add FXS support
[lcr.git] / appbridge.cpp
index b52e125..bc93a84 100644 (file)
@@ -114,6 +114,7 @@ fail:
                message->param.disconnectinfo.cause = cause;
                message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
                message_put(message);
+               ea_endpoint->free_portlist(portlist);
 
                /* destroy endpoint */
                ea_endpoint->ep_use = 0;
@@ -135,6 +136,24 @@ fail:
        /* create port for interface */
        SPRINT(portname, "%s-%d-out", interface_out->name, 0);
        memset(&port_settings, 0, sizeof(port_settings));
+#ifdef WITH_MISDN
+       if (interface_out->remote) {
+               struct admin_list       *admin;
+               admin = admin_first;
+               while(admin) {
+                       if (admin->remote_name[0] && !strcmp(admin->remote_name, interface_out->remote_app))
+                               break;
+                       admin = admin->next;
+               }
+               if (!admin) {
+                       trace_header("INTERFACE (remote not connected)", DIRECTION_NONE);
+                       add_trace("application", NULL, "%s", interface_out->remote_app);
+                       end_trace();
+                       goto fail;
+               }
+               port = new Premote(PORT_TYPE_REMOTE_OUT, portname, &port_settings, interface_out, admin->sock);
+       } else
+#endif
 #ifdef WITH_SIP
        if (interface_out->sip) {
                port = new Psip(PORT_TYPE_SIP_OUT, portname, &port_settings, interface_out);
@@ -147,15 +166,14 @@ fail:
 #endif
 #ifdef WITH_GSM_MS
        if (interface_out->gsm_ms) {
-               port = new Pgsm_bs(PORT_TYPE_GSM_MS_OUT, portname, &port_settings, interface_out);
+               port = new Pgsm_ms(PORT_TYPE_GSM_MS_OUT, portname, &port_settings, interface_out);
        } else
 #endif
        {
+               char *ifname = interface_out->name;
 #ifdef WITH_MISDN
                struct mISDNport *mISDNport;
-               char *ifname = interface_out->name;
                int channel = 0;
-               struct admin_list *admin;
                int earlyb;
                int mode = B_MODE_TRANSPARENT;
 
@@ -175,30 +193,19 @@ fail:
                        port = ss5_hunt_line(mISDNport);
                else
 #endif
-               if (mISDNport->ifport->remote) {
-                       admin = admin_first;
-                       while(admin) {
-                               if (admin->remote_name[0] && !strcmp(admin->remote_name, mISDNport->ifport->remote_app))
-                                       break;
-                               admin = admin->next;
-                       }
-                       if (!admin) {
-                               trace_header("INTERFACE (remote not connected)", DIRECTION_NONE);
-                               add_trace("application", NULL, "%s", mISDNport->ifport->remote_app);
-                               end_trace();
-                               cause = 27;
-                               goto fail;
-                       }
-                       port = new Premote(PORT_TYPE_REMOTE_OUT, mISDNport, portname, &port_settings, channel, mISDNport->ifport->channel_force, mode, admin->sock);
-               } else
-                       port = new Pdss1((mISDNport->ntmode)?PORT_TYPE_DSS1_NT_OUT:PORT_TYPE_DSS1_TE_OUT, mISDNport, portname, &port_settings, channel, mISDNport->ifport->channel_force, mode);
                earlyb = mISDNport->earlyb;
+#ifdef ISDN_P_FXS_POTS
+               if (mISDNport->pots)
+                       port = new Pfxs(PORT_TYPE_POTS_FXS_OUT, mISDNport, portname, &port_settings, mISDNport->ifport->interface, mode);
+               else
+#endif
+                       port = new Pdss1((mISDNport->ntmode)?PORT_TYPE_DSS1_NT_OUT:PORT_TYPE_DSS1_TE_OUT, mISDNport, portname, &port_settings, mISDNport->ifport->interface, channel, mISDNport->ifport->channel_force, mode);
 #else
                trace_header("INTERFACE (has no function)", DIRECTION_NONE);
                add_trace("interface", NULL, "%s", ifname);
                end_trace();
                cause = 31;
-               goto fail
+               goto fail;
 #endif
        }
        if (!port)
@@ -223,18 +230,22 @@ fail:
 /* port MESSAGE_RELEASE */
 void EndpointAppBridge::port_release(struct port_list *portlist, int message_type, union parameter *param)
 {
-       unsigned int remote;
+       struct port_list *remote;
 
        PDEBUG(DEBUG_EPOINT, "EPOINT(%d) epoint received release from port\n");
 
        if (!ea_endpoint->ep_portlist || !ea_endpoint->ep_portlist->next)
                goto out;
        if (ea_endpoint->ep_portlist->port_id == portlist->port_id)
-               remote = ea_endpoint->ep_portlist->next->port_id;
+               remote = ea_endpoint->ep_portlist->next;
        else
-               remote = ea_endpoint->ep_portlist->port_id;
+               remote = ea_endpoint->ep_portlist;
        /* forward release */
-       message_forward(ea_endpoint->ep_serial, remote, EPOINT_TO_PORT, param);  
+       message_forward(ea_endpoint->ep_serial, remote->port_id, EPOINT_TO_PORT, param);  
+
+       /* remove relations to in and out port */
+       ea_endpoint->free_portlist(portlist);
+       ea_endpoint->free_portlist(remote);
 
 out:
        /* destroy endpoint */