gsm: Implement the size checking of the hello packet
[lcr.git] / endpoint.cpp
index 1dce9f1..cda79c2 100644 (file)
@@ -23,8 +23,7 @@ class Endpoint *find_epoint_id(unsigned int epoint_id)
 {
        class Endpoint *epoint = epoint_first;
 
-       while(epoint)
-       {
+       while(epoint) {
 //printf("comparing: '%s' with '%s'\n", name, epoint->name);
                if (epoint->ep_serial == epoint_id)
                        return(epoint);
@@ -34,6 +33,7 @@ class Endpoint *find_epoint_id(unsigned int epoint_id)
        return(NULL);
 }
 
+int delete_endpoint(struct lcr_work *work, void *instance, int index);
 
 /*
  * endpoint constructor (link with either port or join id)
@@ -49,6 +49,8 @@ Endpoint::Endpoint(unsigned int port_id, unsigned int join_id)
 
         ep_portlist = NULL;
        ep_app = NULL;
+       memset(&ep_delete, 0, sizeof(ep_delete));
+       add_work(&ep_delete, delete_endpoint, this, 0);
        ep_use = 1;
 
        /* add endpoint to chain */
@@ -62,12 +64,10 @@ Endpoint::Endpoint(unsigned int port_id, unsigned int join_id)
        ep_serial = epoint_serial++;
 
        /* link to join or port */
-       if (port_id)
-       {
+       if (port_id) {
                port = find_port_id(port_id);
-               if (port)
-               {
-                       if ((port->p_type&PORT_CLASS_mISDN_MASK) == PORT_CLASS_mISDN_DSS1)
+               if (port) {
+                       if ((port->p_type&PORT_CLASS_MASK) == PORT_CLASS_mISDN)
                                earlyb = ((class PmISDN *)port)->p_m_mISDNport->earlyb;
                        if (!portlist_new(port_id, port->p_type, earlyb))
                                FATAL("No memory for portlist.\n");
@@ -97,17 +97,14 @@ Endpoint::~Endpoint(void)
                delete ep_app;
        
        /* free relations */
-       if (ep_join_id)
-       {
+       if (ep_join_id) {
                PERROR("warning: still relation to join.\n");
        }
 
        /* free portlist */
        portlist = ep_portlist;
-       while(portlist)
-       {
-               if (portlist->port_id)
-               {
+       while(portlist) {
+               if (portlist->port_id) {
                        PERROR("warning: still relation to port (portlist list)\n");
                }
                mtemp = portlist;
@@ -120,8 +117,7 @@ Endpoint::~Endpoint(void)
        /* detach */
        temp =epoint_first;
        tempp = &epoint_first;
-       while(temp)
-       {
+       while(temp) {
                if (temp == this)
                        break;
 
@@ -132,6 +128,8 @@ Endpoint::~Endpoint(void)
                FATAL("Endpoint not in Endpoint's list.\n");
        *tempp = next;
 
+       del_work(&ep_delete);
+
        /* free */
        PDEBUG(DEBUG_EPOINT, "removed endpoint %d.\n", ep_serial);
 }
@@ -171,8 +169,7 @@ void Endpoint::free_portlist(struct port_list *portlist)
 
        temp = ep_portlist;
        tempp = &ep_portlist;
-       while(temp)
-       {
+       while(temp) {
                if (temp == portlist)
                        break;
 
@@ -191,18 +188,13 @@ void Endpoint::free_portlist(struct port_list *portlist)
 }
 
 
-/* handler for endpoint
- */
-int Endpoint::handler(void)
+int delete_endpoint(struct lcr_work *work, void *instance, int index)
 {
-       if (ep_use <= 0)
-       {
-               delete this;
-               return(-1);
-       }
+       class Endpoint *ep = (class Endpoint *)instance;
 
-       /* call application handler */
-       if (ep_app)
-               return(ep_app->handler());
-       return(0);
+       if (ep->ep_use <= 0)
+               delete ep;
+
+       return 0;
 }
+