Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_ingress.cxx

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library is distributed in the hope that it will be useful,        */
00014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of         */
00015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 
00034 
00035 #include "pana_ingress.h"
00036 #include "pana_exceptions.h"
00037 
00038 int PANA_IngressMsgDelivery::Serve()
00039 {
00040     try {
00041        (*m_MsgHandler)(m_Message);
00042     }
00043     catch (PANA_Exception &e) {
00044        ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, DELIVERY] Exception, code=%d, description=%s\n",
00045                   e.code(), e.description().data()));
00046     }
00047     catch (...) {
00048        ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, DELIVERY] Unknown error\n"));
00049     }
00050     Release(2);
00051     return (0);
00052 }
00053 
00054 int PANA_IngressMsgParser::Serve()
00055 {
00056     AAAMessageBlock *aBuffer = reinterpret_cast<AAAMessageBlock*>(&m_Message);
00057     try {
00058 
00059        PANA_Message *parsedMsg;
00060        ACE_NEW_NORETURN(parsedMsg, PANA_Message);
00061 
00062        if (parsedMsg == NULL) {
00063           ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] App message\n"));
00064           throw (0);
00065        }
00066 
00067        PANA_HeaderParser hp;
00068        AAADictionaryOption opt(PARSE_STRICT, PANA_DICT_PROTOCOL_ID);
00069        hp.setRawData(aBuffer);
00070        hp.setAppData(static_cast<PANA_MsgHeader*>(parsedMsg));
00071        hp.setDictData(&opt);
00072 
00073        hp.parseRawToApp(); // may throw exception
00074 
00075        PANA_PayloadParser pp;
00076        pp.setRawData(aBuffer);
00077        pp.setAppData(&(parsedMsg->avpList()));
00078        pp.setDictData(parsedMsg->getDictHandle());
00079 
00080        pp.parseRawToApp(); // may throw exception
00081 
00082        // migrate deivice id and port info
00083        parsedMsg->srcDevices().move(m_SrcDevices);
00084        parsedMsg->srcPort(m_SrcPort);
00085 
00086        PANA_IngressMsgDelivery *delivery;
00087        ACE_NEW_NORETURN(delivery,
00088                         PANA_IngressMsgDelivery(m_Group, 
00089                                                 *parsedMsg));
00090        if (delivery) {
00091            delivery->RegisterHandler(*m_MsgHandler);
00092            if (Schedule(delivery) < 0) {
00093               ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, SCHEDULE] delivery job\n"));
00094               delete parsedMsg;
00095               throw (0);
00096            }
00097        }
00098        else {
00099            ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] delivery job\n"));
00100            delete parsedMsg;
00101            throw (0);
00102        }
00103     }
00104     catch (AAAErrorStatus st) {
00105        ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, PARSING] parsing error\n"));
00106     }
00107     catch (...) {
00108     }
00109 
00110     // release the raw buffer and device id containers
00111     PANA_MESSAGE_POOL()->free(&m_Message);
00112     delete &m_SrcDevices;
00113     
00114     Release(2);
00115     return (0);
00116 }
00117 
00118 int PANA_IngressReceiver::Serve()
00119 {
00120         m_Signalled = true;
00121     ACE_UINT32 srcPort;
00122     PANA_MessageBuffer *msg_buffer = NULL;
00123     try {
00124         PANA_DeviceIdContainer *srcDevices;
00125         ACE_NEW_NORETURN(srcDevices, PANA_DeviceIdContainer);
00126         if (srcDevices == NULL) {
00127             ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] device id on %s\n",
00128                        m_Name.data()));
00129             throw (0);
00130         }
00131 
00132         msg_buffer = PANA_MESSAGE_POOL()->malloc();
00133         ssize_t bytes = m_IO.recv(msg_buffer->wr_ptr(), msg_buffer->size(), 
00134                                   srcPort, *srcDevices);
00135         if (bytes > 0) {
00136             if (m_MsgHandler == NULL) {
00137                 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, RECV] handler absent on %s\n",
00138                            m_Name.data()));
00139                 throw (1);
00140             }
00141 
00142             PANA_IngressMsgParser *parser;
00143             ACE_NEW_NORETURN(parser, 
00144                              PANA_IngressMsgParser(m_Group,
00145                                                    *msg_buffer,
00146                                                    srcPort,
00147                                                    *srcDevices));
00148             if (parser) {
00149                 msg_buffer->size(bytes);
00150                 parser->RegisterHandler(*m_MsgHandler);
00151                 if (Schedule(parser) < 0) {
00152                    delete parser;
00153                    ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, SCHEDULE] delivery job on %s\n",
00154                               m_Name.data()));
00155                    throw (0);
00156                 }
00157             }
00158             else {
00159                 ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, ALLOC] message parser job on %s\n",
00160                            m_Name.data()));
00161                 throw (0);
00162             }
00163             Schedule();
00164         } 
00165         else if (bytes == 0) {
00166             throw (1);
00167         } else if ((errno != EAGAIN) &&
00168                    (errno != ETIME) &&
00169                    (errno != ECONNREFUSED)) {
00170             ACE_DEBUG((LM_ERROR, "(%P|%t) [INGRESS, RECV] receive error on %s : %s\n",
00171                        m_Name.data(), strerror(errno)));
00172             if (m_ErrHandler) {
00173                (*m_ErrHandler)(errno);
00174             }
00175             throw (0);
00176         }
00177         else {
00178             // timeout
00179             throw (1);
00180         }
00181     }
00182     catch (int rc) {
00183         PANA_MESSAGE_POOL()->free(msg_buffer);
00184         if (rc) {
00185             // manually re-schedule myself
00186             Schedule();
00187         }
00188                 else {
00189                         m_Signalled = false;
00190                 }
00191     }
00192     return (0);
00193 }
00194 

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5