Main Page   Class Hierarchy   Compound List   File List   Compound Members  

C_SCTPDataDecode.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017  *
00018  */
00019 #include "C_SCTPDataDecode.hpp"
00020 #include "Utils.hpp"
00021 
00022 #include <cstring>
00023 
00024 #define SOCKET_ERROR(l,m) iostream_error << m << iostream_endl << iostream_flush
00025 #ifdef DEBUG_MODE
00026 #define SOCKET_DEBUG(l,m) iostream_error << m << iostream_endl << iostream_flush
00027 #else
00028 #define SOCKET_DEBUG(l,m)
00029 #endif
00030 
00031 C_SCTPDataDecode::C_SCTPDataDecode(size_t P_buf_size) {
00032   SOCKET_DEBUG(0, "C_SCTPDataDecode::C_SCTPDataDecode (" 
00033             << P_buf_size << ")");
00034   m_segm_size = 0 ;
00035   m_buf_size = P_buf_size;
00036   ALLOC_TABLE(m_buffer,
00037               unsigned char*,
00038               sizeof(unsigned char),
00039               m_buf_size);
00040 }
00041 
00042 C_SCTPDataDecode::~C_SCTPDataDecode() {
00043   SOCKET_DEBUG(0, "C_SCTPDataDecode::~C_SCTPDataDecode ()");
00044   m_segm_size = 0 ;
00045   FREE_TABLE(m_buffer);
00046   m_buf_size = 0 ;
00047 }
00048 
00049 void C_SCTPDataDecode::init () {
00050   SOCKET_DEBUG(0, "C_SCTPDataDecode::init ()");
00051   m_segm_size = 0 ;
00052 }
00053 
00054 void C_SCTPDataDecode::reset_buffer() {
00055   SOCKET_DEBUG(0, "C_SCTPDataDecode::reset_buffer ()");
00056   m_segm_size = 0 ;
00057 }
00058 
00059 unsigned char *C_SCTPDataDecode::get_buffer (unsigned char* P_buf, 
00060                                          size_t       * P_pSize) {
00061 
00062   size_t L_final_size = (*P_pSize) ;
00063 
00064   SOCKET_DEBUG(0, "C_SCTPDataDecode::get_buffer (" 
00065             << (void*)&P_buf[0] << "," << *P_pSize << ")");
00066 
00067   SOCKET_DEBUG(0, "C_SCTPDataDecode::get_buffer() segment = " << m_segm_size);
00068 
00069   
00070   L_final_size += m_segm_size;
00071   if (L_final_size <= m_buf_size) {
00072     memcpy (m_buffer+m_segm_size, P_buf, *P_pSize);
00073     m_segm_size = 0 ;
00074     *P_pSize = L_final_size ;
00075   } else {
00076     // error
00077     *P_pSize = 0 ;
00078   }
00079 
00080   SOCKET_DEBUG(0, "C_SCTPDataDecode::get_buffer () return " 
00081             << &m_buffer);
00082 
00083   return (m_buffer);
00084 }
00085 
00086 int           C_SCTPDataDecode::set_buffer (unsigned char* P_buf, 
00087                                          size_t         P_size) {
00088   int L_ret = 0 ;
00089   SOCKET_DEBUG(0, "C_SCTPDataDecode::set_buffer (" 
00090             << &P_buf[0] << "," << P_size << ")");
00091 
00092   if (P_size <= m_buf_size) {
00093     memmove(m_buffer, P_buf, P_size);
00094     m_segm_size = P_size ;
00095   } else {
00096     SOCKET_ERROR(E_GEN_FATAL_ERROR, "session maximum size buffer=" << m_buf_size << " data=" << P_size);
00097     L_ret = -1 ;
00098   }
00099   return (L_ret);
00100 }

Generated on Wed Mar 7 14:44:58 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002