untabify
This commit is contained in:
parent
0cf03bc158
commit
ef0cb39c1d
|
|
@ -27,7 +27,7 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
DCAtomicField::
|
||||
DCAtomicField(const string &name, DCClass *dclass,
|
||||
bool bogus_field) :
|
||||
bool bogus_field) :
|
||||
DCField(name, dclass)
|
||||
{
|
||||
_bogus_field = bogus_field;
|
||||
|
|
|
|||
|
|
@ -1248,15 +1248,15 @@ write(ostream &out, bool brief, int indent_level) const {
|
|||
|
||||
/*
|
||||
if (true || (*fi)->has_default_value()) {
|
||||
indent(out, indent_level + 2) << "// = ";
|
||||
DCPacker packer;
|
||||
packer.set_unpack_data((*fi)->get_default_value());
|
||||
packer.begin_unpack(*fi);
|
||||
packer.unpack_and_format(out, false);
|
||||
if (!packer.end_unpack()) {
|
||||
out << "<error>";
|
||||
}
|
||||
out << "\n";
|
||||
indent(out, indent_level + 2) << "// = ";
|
||||
DCPacker packer;
|
||||
packer.set_unpack_data((*fi)->get_default_value());
|
||||
packer.begin_unpack(*fi);
|
||||
packer.unpack_and_format(out, false);
|
||||
if (!packer.end_unpack()) {
|
||||
out << "<error>";
|
||||
}
|
||||
out << "\n";
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -986,7 +986,7 @@ describe_message(ostream &out, const string &prefix,
|
|||
nassertv(methodName != NULL);
|
||||
|
||||
PyObject *result = PyObject_CallMethodObjArgs(_python_repository, methodName,
|
||||
msgId, NULL);
|
||||
msgId, NULL);
|
||||
nassertv(result != NULL);
|
||||
|
||||
msgName += string(PyString_AsString(result));
|
||||
|
|
@ -1130,7 +1130,7 @@ bool CConnectionRepository::check_datagram_ai(PyObject *PycallBackFunction)
|
|||
endTime = ClockObject::get_global_clock()->get_real_time();
|
||||
if ( _time_warning < (endTime - startTime)) {
|
||||
nout << "msg " << _msg_type <<" from " << _msg_sender << " took "<< (endTime-startTime) << "secs to process\n";
|
||||
_dg.dump_hex(nout,2);
|
||||
_dg.dump_hex(nout,2);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -1146,7 +1146,7 @@ bool CConnectionRepository::check_datagram_ai(PyObject *PycallBackFunction)
|
|||
endTime = ClockObject::get_global_clock()->get_real_time();
|
||||
if ( _time_warning < (endTime - startTime)) {
|
||||
nout << "msg " << _msg_type <<" from " << _msg_sender << " took "<< (endTime-startTime) << "secs to process\n";
|
||||
_dg.dump_hex(nout,2);
|
||||
_dg.dump_hex(nout,2);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
@ -1157,7 +1157,7 @@ bool CConnectionRepository::check_datagram_ai(PyObject *PycallBackFunction)
|
|||
endTime = ClockObject::get_global_clock()->get_real_time();
|
||||
if ( _time_warning < (endTime - startTime)) {
|
||||
nout << "msg " << _msg_type <<" from " << _msg_sender << " took "<< (endTime-startTime) << "secs to process\n";
|
||||
_dg.dump_hex(nout,2);
|
||||
_dg.dump_hex(nout,2);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#define INCLUDED_SOURCES \
|
||||
config_http.cxx \
|
||||
http_connection.cxx \
|
||||
http_connection.cxx \
|
||||
parsedhttprequest.cxx \
|
||||
http_request.cxx
|
||||
|
||||
|
|
|
|||
|
|
@ -6,22 +6,22 @@
|
|||
|
||||
enum CloseState
|
||||
{
|
||||
ConnectionDoNotClose,
|
||||
ConnectionDoClose
|
||||
ConnectionDoNotClose,
|
||||
ConnectionDoClose
|
||||
};
|
||||
// RHH
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Template :BaseIncomingSet
|
||||
// Template :BaseIncomingSet
|
||||
//
|
||||
// Description : A base structre for a listening socket and a
|
||||
// set of connection that have been received with there read functions..
|
||||
// set of connection that have been received with there read functions..
|
||||
//
|
||||
// Think of this like a web server with 1 listening socket and 0-n open reacting conections..
|
||||
// Think of this like a web server with 1 listening socket and 0-n open reacting conections..
|
||||
//
|
||||
// The general operation if get connection..
|
||||
// do you have a message
|
||||
// process message
|
||||
// go back to do you have a message or close connection
|
||||
// The general operation if get connection..
|
||||
// do you have a message
|
||||
// process message
|
||||
// go back to do you have a message or close connection
|
||||
//
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -29,33 +29,33 @@ template < class _INCLASS1,class _IN_LISTEN, class MESSAGE_READER_BUF, class MES
|
|||
{
|
||||
typedef std::list<_INCLASS1 *> BaseClass;
|
||||
typedef TYPENAME BaseClass::iterator iterator;
|
||||
_IN_LISTEN _Listener;
|
||||
_IN_LISTEN _Listener;
|
||||
|
||||
inline void AddFromListener(void);
|
||||
inline int PumpReader(Time_Clock ¤tTime);
|
||||
inline void AddAConection(_INCLASS1 * newt);
|
||||
inline void AddFromListener(void);
|
||||
inline int PumpReader(Time_Clock ¤tTime);
|
||||
inline void AddAConection(_INCLASS1 * newt);
|
||||
|
||||
public:
|
||||
|
||||
// typedef typename BaseIncomingSet<_INCLASS1, _IN_LISTEN, MESSAGE_READER_BUF, MESSAGE_READER_UPPASS>::LinkNode LinkNode;
|
||||
// typedef typename BaseIncomingSet<_INCLASS1, _IN_LISTEN, MESSAGE_READER_BUF, MESSAGE_READER_UPPASS>::LinkNode LinkNode;
|
||||
|
||||
// typedef SentDblLinkListNode_Gm SentDblLinkListNode_Gm;
|
||||
inline BaseIncomingSet(void);
|
||||
inline BaseIncomingSet(BaseIncomingSet &in);
|
||||
virtual ~BaseIncomingSet();
|
||||
// typedef SentDblLinkListNode_Gm SentDblLinkListNode_Gm;
|
||||
inline BaseIncomingSet(void);
|
||||
inline BaseIncomingSet(BaseIncomingSet &in);
|
||||
virtual ~BaseIncomingSet();
|
||||
|
||||
inline _IN_LISTEN & GetListener(void);
|
||||
inline bool init(Socket_Address &WhereFrom);
|
||||
inline void PumpAll(Time_Clock ¤tTime);
|
||||
virtual CloseState ProcessNewConnection(SOCKET socket);
|
||||
inline void AddToFDSet(Socket_fdset &set);
|
||||
inline _IN_LISTEN & GetListener(void);
|
||||
inline bool init(Socket_Address &WhereFrom);
|
||||
inline void PumpAll(Time_Clock ¤tTime);
|
||||
virtual CloseState ProcessNewConnection(SOCKET socket);
|
||||
inline void AddToFDSet(Socket_fdset &set);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// inline LinkNode * GetRoot(void) { return &this->sentenal; };
|
||||
BaseIncomingSet &operator=( BaseIncomingSet &inval);
|
||||
// inline LinkNode * GetRoot(void) { return &this->sentenal; };
|
||||
BaseIncomingSet &operator=( BaseIncomingSet &inval);
|
||||
void Reset();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,88 +1,88 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddFromListener
|
||||
// Description : Read incoming connections off the listener
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddFromListener
|
||||
// Description : Read incoming connections off the listener
|
||||
//
|
||||
// Return type : inline void
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline void BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddFromListener(void)
|
||||
{
|
||||
Socket_Address Addr1;
|
||||
SOCKET newsck;
|
||||
|
||||
|
||||
while(_Listener.GetIncomingConnection(newsck,Addr1) == true)
|
||||
{
|
||||
CloseState cl= ProcessNewConnection(newsck);
|
||||
if(cl == ConnectionDoNotClose)
|
||||
{
|
||||
_INCLASS1 * newt = new _INCLASS1(newsck,Addr1);
|
||||
AddAConection(newt);
|
||||
}
|
||||
else
|
||||
DO_CLOSE(newsck);
|
||||
}
|
||||
|
||||
Socket_Address Addr1;
|
||||
SOCKET newsck;
|
||||
|
||||
|
||||
while(_Listener.GetIncomingConnection(newsck,Addr1) == true)
|
||||
{
|
||||
CloseState cl= ProcessNewConnection(newsck);
|
||||
if(cl == ConnectionDoNotClose)
|
||||
{
|
||||
_INCLASS1 * newt = new _INCLASS1(newsck,Addr1);
|
||||
AddAConection(newt);
|
||||
}
|
||||
else
|
||||
DO_CLOSE(newsck);
|
||||
}
|
||||
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::PumpReader
|
||||
// Description : Tries to read a record off the incoming socket
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::PumpReader
|
||||
// Description : Tries to read a record off the incoming socket
|
||||
//
|
||||
// Return type : inline void
|
||||
// Return type : inline void
|
||||
// Argument : Time_Clock currentTime
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline int BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::PumpReader(Time_Clock ¤tTime)
|
||||
{
|
||||
MESSAGE_READER_BUF message;
|
||||
|
||||
iterator lpNext, lp;
|
||||
for (lpNext = lp = BaseClass::begin(); lp != BaseClass::end() ; lp = lpNext)
|
||||
{
|
||||
lpNext++;
|
||||
|
||||
int ans = (*lp)->ReadIt(message, sizeof(message),currentTime);
|
||||
if(ans < 0)
|
||||
{
|
||||
delete *lp;
|
||||
erase(lp);
|
||||
}
|
||||
if(ans > 0)
|
||||
{
|
||||
CloseState cs = (*lp)->ProcessMessage(message,currentTime);
|
||||
if( cs == ConnectionDoClose)
|
||||
{
|
||||
delete *lp;
|
||||
erase(lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
{
|
||||
MESSAGE_READER_BUF message;
|
||||
|
||||
iterator lpNext, lp;
|
||||
for (lpNext = lp = BaseClass::begin(); lp != BaseClass::end() ; lp = lpNext)
|
||||
{
|
||||
lpNext++;
|
||||
|
||||
int ans = (*lp)->ReadIt(message, sizeof(message),currentTime);
|
||||
if(ans < 0)
|
||||
{
|
||||
delete *lp;
|
||||
erase(lp);
|
||||
}
|
||||
if(ans > 0)
|
||||
{
|
||||
CloseState cs = (*lp)->ProcessMessage(message,currentTime);
|
||||
if( cs == ConnectionDoClose)
|
||||
{
|
||||
delete *lp;
|
||||
erase(lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddAConection
|
||||
// Description : Adds a member to the base container
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddAConection
|
||||
// Description : Adds a member to the base container
|
||||
//
|
||||
// Return type : inline void
|
||||
// Return type : inline void
|
||||
// Argument : _INCLASS1 * newt
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline void BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddAConection(_INCLASS1 * newt)
|
||||
{
|
||||
push_back(newt);
|
||||
push_back(newt);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::BaseIncomingSet
|
||||
// Description : core constructor
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::BaseIncomingSet
|
||||
// Description : core constructor
|
||||
//
|
||||
// Return type : inline
|
||||
// Return type : inline
|
||||
// Argument : void
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::BaseIncomingSet(void)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
|
|
@ -91,10 +91,10 @@ BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::
|
|||
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::~BaseIncomingSet
|
||||
// Description : The Destructot .. will delete all members.. ??
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::~BaseIncomingSet
|
||||
// Description : The Destructot .. will delete all members.. ??
|
||||
//
|
||||
// Return type :
|
||||
// Return type :
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::~BaseIncomingSet()
|
||||
|
|
@ -103,99 +103,99 @@ BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::
|
|||
delete *ii;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : & BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::GetListener
|
||||
// Description : Retyurns a pointer to the listener in this class
|
||||
// Function name : & BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::GetListener
|
||||
// Description : Retyurns a pointer to the listener in this class
|
||||
//
|
||||
// Return type : inline _IN_LISTEN
|
||||
// Return type : inline _IN_LISTEN
|
||||
// Argument : void
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline _IN_LISTEN & BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::GetListener(void)
|
||||
{
|
||||
return this->Listener;
|
||||
return this->Listener;
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::init
|
||||
// Description : the second part of the 2 phase power up.. Opends the listener
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::init
|
||||
// Description : the second part of the 2 phase power up.. Opends the listener
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Return type : inline bool
|
||||
// Argument : Socket_Address &WhereFrom
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline bool BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::init(Socket_Address &WhereFrom)
|
||||
{
|
||||
if(_Listener.OpenForListen(WhereFrom,true) != true)
|
||||
return false;
|
||||
_Listener.SetNonBlocking();
|
||||
return true;
|
||||
if(_Listener.OpenForListen(WhereFrom,true) != true)
|
||||
return false;
|
||||
_Listener.SetNonBlocking();
|
||||
return true;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::PumpAll
|
||||
// Description : THis is the polled interface to this class
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::PumpAll
|
||||
// Description : THis is the polled interface to this class
|
||||
//
|
||||
// Return type : inline void
|
||||
// Return type : inline void
|
||||
// Argument : Time_Clock ¤tTime
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline void BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::PumpAll(Time_Clock ¤tTime)
|
||||
{
|
||||
PumpReader(currentTime); // I MOVED ORDER TO FINE TUNE THE READ OPERATIONS
|
||||
AddFromListener();
|
||||
PumpReader(currentTime); // I MOVED ORDER TO FINE TUNE THE READ OPERATIONS
|
||||
AddFromListener();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::ProcessNewConnection
|
||||
// Description : this is the vertual function call when a new connection is created
|
||||
// manly here for loging if needed...
|
||||
// Function name : BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::ProcessNewConnection
|
||||
// Description : this is the vertual function call when a new connection is created
|
||||
// manly here for loging if needed...
|
||||
//
|
||||
// Return type : CloseState
|
||||
// Return type : CloseState
|
||||
// Argument : SOCKET socket
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
CloseState BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::ProcessNewConnection(SOCKET socket)
|
||||
{
|
||||
return ConnectionDoNotClose;
|
||||
return ConnectionDoNotClose;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : void BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddToFDSet
|
||||
// Description : Add LIstener and Client to the FD set for polled reading
|
||||
// Function name : void BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddToFDSet
|
||||
// Description : Add LIstener and Client to the FD set for polled reading
|
||||
//
|
||||
// Return type : inline
|
||||
// Return type : inline
|
||||
// Argument : Socket_Selector &set
|
||||
////////////////////////////////////////////////////////////////////
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline void BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::AddToFDSet(Socket_fdset &set1)
|
||||
{
|
||||
if(_Listener.Active())
|
||||
set1.setForSocket(_Listener);
|
||||
iterator lp;
|
||||
|
||||
for (lp = BaseClass::begin(); lp != BaseClass::end(); lp = lp++)
|
||||
set1.setForSocket((*lp)->val);
|
||||
{
|
||||
if(_Listener.Active())
|
||||
set1.setForSocket(_Listener);
|
||||
iterator lp;
|
||||
|
||||
for (lp = BaseClass::begin(); lp != BaseClass::end(); lp = lp++)
|
||||
set1.setForSocket((*lp)->val);
|
||||
}
|
||||
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS> &BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::operator=
|
||||
(BaseIncomingSet &inval)
|
||||
(BaseIncomingSet &inval)
|
||||
{
|
||||
if (&inval == this) return *this;
|
||||
_Listener = inval._Listener;
|
||||
return *this;
|
||||
if (&inval == this) return *this;
|
||||
_Listener = inval._Listener;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <class _INCLASS1,class _IN_LISTEN,typename MESSAGE_READER_BUF, typename MESSAGE_READER_UPPASS>
|
||||
inline void BaseIncomingSet<_INCLASS1,_IN_LISTEN,MESSAGE_READER_BUF,MESSAGE_READER_UPPASS>::Reset()
|
||||
{
|
||||
_Listener.Close();
|
||||
iterator lpNext, lp;
|
||||
for (lpNext = lp = BaseClass::begin(); lp != BaseClass::end() ; lp = lpNext)
|
||||
{
|
||||
lpNext++;
|
||||
(*lp)->Reset();
|
||||
delete *lp;
|
||||
erase(lp);
|
||||
}
|
||||
_Listener.Close();
|
||||
iterator lpNext, lp;
|
||||
for (lpNext = lp = BaseClass::begin(); lp != BaseClass::end() ; lp = lpNext)
|
||||
{
|
||||
lpNext++;
|
||||
(*lp)->Reset();
|
||||
delete *lp;
|
||||
erase(lp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,35 +9,35 @@
|
|||
|
||||
class BufferedWriter_Growable : public std::string
|
||||
{
|
||||
int _write_offset;
|
||||
int _write_offset;
|
||||
public:
|
||||
|
||||
BufferedWriter_Growable(void);
|
||||
~BufferedWriter_Growable(void);
|
||||
int AmountBuffered(void);
|
||||
void AppendData(const char * buf, int len);
|
||||
BufferedWriter_Growable(void);
|
||||
~BufferedWriter_Growable(void);
|
||||
int AmountBuffered(void);
|
||||
void AppendData(const char * buf, int len);
|
||||
void Reset() { clear(); _write_offset = 0; };
|
||||
const char * GetMessageHead(void);
|
||||
int Flush(Socket_TCP &sck) ; // this is the ugly part
|
||||
const char * GetMessageHead(void);
|
||||
int Flush(Socket_TCP &sck) ; // this is the ugly part
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Function name : BufferedWriter_Growable::BufferedWriter_Growable
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Function name : BufferedWriter_Growable::BufferedWriter_Growable
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////////
|
||||
inline BufferedWriter_Growable::BufferedWriter_Growable(void)
|
||||
{
|
||||
_write_offset = 0;
|
||||
_write_offset = 0;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Function name : ~BufferedWriter_Growable::BufferedWriter_Growable
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Function name : ~BufferedWriter_Growable::BufferedWriter_Growable
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////////
|
||||
inline BufferedWriter_Growable::~BufferedWriter_Growable(void)
|
||||
|
|
@ -46,69 +46,69 @@ inline BufferedWriter_Growable::~BufferedWriter_Growable(void)
|
|||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Function name : BufferedWriter_Growable::AmountBuffered
|
||||
// Description :
|
||||
// Return type : inline int
|
||||
// Function name : BufferedWriter_Growable::AmountBuffered
|
||||
// Description :
|
||||
// Return type : inline int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////////
|
||||
inline int BufferedWriter_Growable::AmountBuffered(void)
|
||||
{
|
||||
return (int) (size() - _write_offset);
|
||||
return (int) (size() - _write_offset);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Function name : BufferedWriter_Growable::AppendData
|
||||
// Description :
|
||||
// Return type : inline void
|
||||
// Function name : BufferedWriter_Growable::AppendData
|
||||
// Description :
|
||||
// Return type : inline void
|
||||
// Argument : const char * buf
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////////
|
||||
inline void BufferedWriter_Growable::AppendData(const char * buf, int len)
|
||||
{
|
||||
append(buf, len);
|
||||
append(buf, len);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Function name : char * BufferedWriter_Growable::GetMessageHead
|
||||
// Description :
|
||||
// Return type : inline const
|
||||
// Function name : char * BufferedWriter_Growable::GetMessageHead
|
||||
// Description :
|
||||
// Return type : inline const
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////////
|
||||
inline const char * BufferedWriter_Growable::GetMessageHead(void)
|
||||
{
|
||||
return data() + _write_offset;
|
||||
return data() + _write_offset;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////
|
||||
// Function name : BufferedWriter_Growable::Flush
|
||||
// Description :
|
||||
// Return type : inline int
|
||||
// Function name : BufferedWriter_Growable::Flush
|
||||
// Description :
|
||||
// Return type : inline int
|
||||
// Argument : SocketTCP_Gm &sck
|
||||
//////////////////////////////////////////////////////////////
|
||||
inline int BufferedWriter_Growable::Flush(Socket_TCP &sck) // this is the ugly part
|
||||
{
|
||||
int answer = 0;
|
||||
int Writesize = AmountBuffered();
|
||||
|
||||
if(Writesize > 0)
|
||||
{
|
||||
const char * out1 = GetMessageHead();
|
||||
int Writen = sck.SendData(out1,Writesize);
|
||||
if(Writen > 0)
|
||||
{
|
||||
_write_offset += Writen;
|
||||
answer = 1;
|
||||
}
|
||||
else if(Writen < 0)
|
||||
{
|
||||
if(GETERROR() != LOCAL_BLOCKING_ERROR)
|
||||
answer = -1;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
{
|
||||
int answer = 0;
|
||||
int Writesize = AmountBuffered();
|
||||
|
||||
if(Writesize > 0)
|
||||
{
|
||||
const char * out1 = GetMessageHead();
|
||||
int Writen = sck.SendData(out1,Writesize);
|
||||
if(Writen > 0)
|
||||
{
|
||||
_write_offset += Writen;
|
||||
answer = 1;
|
||||
}
|
||||
else if(Writen < 0)
|
||||
{
|
||||
if(GETERROR() != LOCAL_BLOCKING_ERROR)
|
||||
answer = -1;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,29 +10,29 @@
|
|||
|
||||
class Http_BufferedReader : protected RingBuffer_Slide
|
||||
{
|
||||
inline bool GetTermedString(char * outdata, size_t maxlen,char termchar1, char termchar2);
|
||||
inline bool GetDoubleTermedString(char * outdata, int maxlen,char termchar1, char termchar2);
|
||||
inline bool GetTermedStringInPLace(char ** outdata,char termchars);
|
||||
inline bool GetTermedString(char * outdata, int maxlen,char * termchars);
|
||||
inline bool GetSizeString(StrTargetBuffer & outdata);
|
||||
inline bool GetTermedString(char * outdata, size_t maxlen,char termchar1, char termchar2);
|
||||
inline bool GetDoubleTermedString(char * outdata, int maxlen,char termchar1, char termchar2);
|
||||
inline bool GetTermedStringInPLace(char ** outdata,char termchars);
|
||||
inline bool GetTermedString(char * outdata, int maxlen,char * termchars);
|
||||
inline bool GetSizeString(StrTargetBuffer & outdata);
|
||||
public:
|
||||
inline Http_BufferedReader(int in_size = 8192) ;
|
||||
inline Http_BufferedReader(int in_size = 8192) ;
|
||||
//
|
||||
// The Read Message Interface
|
||||
//
|
||||
inline void ReSet(void);
|
||||
inline int PumpCRRead(char * data, int maxdata, Socket_TCP &sck);
|
||||
inline int PumpHTTPHeaderRead(char * data, int maxdata, Socket_TCP &sck);
|
||||
inline void ReSet(void);
|
||||
inline int PumpCRRead(char * data, int maxdata, Socket_TCP &sck);
|
||||
inline int PumpHTTPHeaderRead(char * data, int maxdata, Socket_TCP &sck);
|
||||
inline int PumpSizeRead(StrTargetBuffer & outdata,Socket_TCP &sck);
|
||||
inline int PumpEofRead(StrTargetBuffer & outdata,Socket_TCP &sck);
|
||||
//inline int PumpMessageReader(CoreMessage &inmsg, Socket_TCP &sck);
|
||||
//inline int PumpMessageReader(CoreMessage &inmsg, Socket_TCP &sck);
|
||||
|
||||
|
||||
template < class SOCK_TYPE>
|
||||
inline int ReadPump(SOCK_TYPE &sck)
|
||||
{
|
||||
int answer = 0;
|
||||
size_t readsize = BufferAvailabe();
|
||||
{
|
||||
int answer = 0;
|
||||
size_t readsize = BufferAvailabe();
|
||||
|
||||
if(readsize < 1)
|
||||
{
|
||||
|
|
@ -64,7 +64,7 @@ public:
|
|||
else if(gotbytes > 0) // ok got some lets process it
|
||||
{
|
||||
|
||||
_EndPos += gotbytes;
|
||||
_EndPos += gotbytes;
|
||||
answer = 1;
|
||||
}
|
||||
else // 0 mean other end disconect arggggg
|
||||
|
|
@ -72,7 +72,7 @@ public:
|
|||
answer = -1;
|
||||
LOGWARNING("Http_BufferedReader::ReadPump->Other End Closed Normal [%s]",sck.GetPeerName().get_ip_port().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string addstr = sck.GetPeerName().get_ip_port();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::GetTermedString
|
||||
// Description : a function that will peal a terminated string from the buffer
|
||||
// Function name : Http_BufferedReader::GetTermedString
|
||||
// Description : a function that will peal a terminated string from the buffer
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Return type : inline bool
|
||||
// Argument : char * outdata
|
||||
// Argument : int maxlen
|
||||
// Argument : char termchar1
|
||||
|
|
@ -10,34 +10,34 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
inline bool Http_BufferedReader::GetTermedString(char * outdata, size_t maxlen,char termchar1, char termchar2)
|
||||
{
|
||||
bool answer = false;
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = maxlen;
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=0; x< MaxRead; x++)
|
||||
{
|
||||
if(wrk[x] == termchar1 || wrk[x] == termchar2)
|
||||
{
|
||||
memcpy(outdata,wrk,x);
|
||||
outdata[x] = '\0';
|
||||
_StartPos += x+1;
|
||||
Compress();
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
bool answer = false;
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = maxlen;
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=0; x< MaxRead; x++)
|
||||
{
|
||||
if(wrk[x] == termchar1 || wrk[x] == termchar2)
|
||||
{
|
||||
memcpy(outdata,wrk,x);
|
||||
outdata[x] = '\0';
|
||||
_StartPos += x+1;
|
||||
Compress();
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::GetDoubleTermedString
|
||||
// Description : a function that will peal a terminated string from the buffer
|
||||
// Function name : Http_BufferedReader::GetDoubleTermedString
|
||||
// Description : a function that will peal a terminated string from the buffer
|
||||
//
|
||||
// This is the interface for a web request....
|
||||
// This is the interface for a web request....
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Return type : inline bool
|
||||
// Argument : char * outdata
|
||||
// Argument : int maxlen
|
||||
// Argument : char termchar1
|
||||
|
|
@ -45,252 +45,252 @@ inline bool Http_BufferedReader::GetTermedString(char * outdata, size_t maxlen,c
|
|||
////////////////////////////////////////////////////////////////////
|
||||
inline bool Http_BufferedReader::GetDoubleTermedString(char * outdata, int maxlen,char termchar1, char termchar2)
|
||||
{
|
||||
bool answer = false;
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = maxlen;
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=1; x< MaxRead; x++)
|
||||
{
|
||||
if(
|
||||
(wrk[x] == termchar1 && wrk[x-1] == termchar1) ||
|
||||
(wrk[x] == termchar2 && wrk[x-1] == termchar2) ||
|
||||
( x >= 3 && wrk[x] == termchar1 && wrk[x-2] == termchar1 && wrk[x-1] == termchar2 && wrk[x-3] == termchar2 ) ||
|
||||
( x >= 3 && wrk[x] == termchar2 && wrk[x-2] == termchar2 && wrk[x-1] == termchar1 && wrk[x-3] == termchar1 )
|
||||
)
|
||||
{
|
||||
memcpy(outdata,wrk,x);
|
||||
outdata[x] = '\0';
|
||||
_StartPos += x+1;
|
||||
Compress();
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
bool answer = false;
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = maxlen;
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=1; x< MaxRead; x++)
|
||||
{
|
||||
if(
|
||||
(wrk[x] == termchar1 && wrk[x-1] == termchar1) ||
|
||||
(wrk[x] == termchar2 && wrk[x-1] == termchar2) ||
|
||||
( x >= 3 && wrk[x] == termchar1 && wrk[x-2] == termchar1 && wrk[x-1] == termchar2 && wrk[x-3] == termchar2 ) ||
|
||||
( x >= 3 && wrk[x] == termchar2 && wrk[x-2] == termchar2 && wrk[x-1] == termchar1 && wrk[x-3] == termchar1 )
|
||||
)
|
||||
{
|
||||
memcpy(outdata,wrk,x);
|
||||
outdata[x] = '\0';
|
||||
_StartPos += x+1;
|
||||
Compress();
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::GetTermedStringInPLace
|
||||
// Description : Will peal a string inplace for reading
|
||||
// Function name : Http_BufferedReader::GetTermedStringInPLace
|
||||
// Description : Will peal a string inplace for reading
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Return type : inline bool
|
||||
// Argument : char ** outdata
|
||||
// Argument : char termchars
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline bool Http_BufferedReader::GetTermedStringInPLace(char ** outdata,char termchars)
|
||||
{
|
||||
bool answer = false;
|
||||
Compress();
|
||||
size_t MaxRead = FastAmountBeffered();
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=0; x< MaxRead; x++)
|
||||
{
|
||||
if(wrk[x] == termchars)
|
||||
{
|
||||
*outdata = wrk;
|
||||
wrk[x] = '\0';
|
||||
_StartPos += x+1;
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
bool answer = false;
|
||||
Compress();
|
||||
size_t MaxRead = FastAmountBeffered();
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=0; x< MaxRead; x++)
|
||||
{
|
||||
if(wrk[x] == termchars)
|
||||
{
|
||||
*outdata = wrk;
|
||||
wrk[x] = '\0';
|
||||
_StartPos += x+1;
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::GetTermedString
|
||||
// Description : do a read of a termed string not in place
|
||||
// Function name : Http_BufferedReader::GetTermedString
|
||||
// Description : do a read of a termed string not in place
|
||||
//
|
||||
// Return type : bool
|
||||
// Return type : bool
|
||||
// Argument : char * outdata
|
||||
// Argument : int maxlen
|
||||
// Argument : char * termchars
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool Http_BufferedReader::GetTermedString(char * outdata, int maxlen,char * termchars)
|
||||
{
|
||||
bool answer = false;
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = maxlen;
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
int tstrsize = (int)strlen(termchars);
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=0; x< MaxRead; x++)
|
||||
{
|
||||
if(memcmp(&wrk[x],termchars,tstrsize) == 0)
|
||||
{
|
||||
memcpy(outdata,wrk,x);
|
||||
outdata[x] = '\0';
|
||||
_StartPos += x+tstrsize;
|
||||
Compress();
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
bool answer = false;
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = maxlen;
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
int tstrsize = (int)strlen(termchars);
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
for(size_t x=0; x< MaxRead; x++)
|
||||
{
|
||||
if(memcmp(&wrk[x],termchars,tstrsize) == 0)
|
||||
{
|
||||
memcpy(outdata,wrk,x);
|
||||
outdata[x] = '\0';
|
||||
_StartPos += x+tstrsize;
|
||||
Compress();
|
||||
answer = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::Http_BufferedReader
|
||||
// Description : constructore .. passes size up to ring buffer
|
||||
// Function name : Http_BufferedReader::Http_BufferedReader
|
||||
// Description : constructore .. passes size up to ring buffer
|
||||
//
|
||||
// Return type : inline
|
||||
// Return type : inline
|
||||
// Argument : int in_size
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline Http_BufferedReader::Http_BufferedReader(int in_size) : RingBuffer_Slide(in_size)
|
||||
{
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::ReSet
|
||||
// Description : Reaset all read content.. IE zero's out buffer...
|
||||
// Function name : Http_BufferedReader::ReSet
|
||||
// Description : Reaset all read content.. IE zero's out buffer...
|
||||
//
|
||||
// If you lose framing this will not help
|
||||
// If you lose framing this will not help
|
||||
//
|
||||
// Return type : inline void
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline void Http_BufferedReader::ReSet(void)
|
||||
{
|
||||
ResetContent();
|
||||
ResetContent();
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::PumpCRRead
|
||||
// Description : a upcall function to read a CR object off buffer
|
||||
// Function name : Http_BufferedReader::PumpCRRead
|
||||
// Description : a upcall function to read a CR object off buffer
|
||||
//
|
||||
// Return type : inline int
|
||||
// Return type : inline int
|
||||
// Argument : char * data
|
||||
// Argument : int maxdata
|
||||
// Argument : Socket_TCP &sck
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline int Http_BufferedReader::PumpCRRead(char * data, int maxdata, Socket_TCP &sck)
|
||||
{
|
||||
if(GetTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
if(GetTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
|
||||
return 0;
|
||||
{
|
||||
if(GetTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
if(GetTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : Http_BufferedReader::PumpHTTPHeaderRead
|
||||
// Description : Will read a HTTP head ,, GET ..... or response from web server
|
||||
// Function name : Http_BufferedReader::PumpHTTPHeaderRead
|
||||
// Description : Will read a HTTP head ,, GET ..... or response from web server
|
||||
//
|
||||
// Return type : inline int
|
||||
// Return type : inline int
|
||||
// Argument : char * data
|
||||
// Argument : int maxdata
|
||||
// Argument : Socket_TCP &sck
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline int Http_BufferedReader::PumpHTTPHeaderRead(char * data, int maxdata, Socket_TCP &sck)
|
||||
{
|
||||
|
||||
if(GetDoubleTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
if(GetDoubleTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
||||
if(GetDoubleTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
if(GetDoubleTermedString(data,maxdata,'\r','\n') == true)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int Http_BufferedReader::PumpSizeRead(StrTargetBuffer & outdata,Socket_TCP &sck)
|
||||
{
|
||||
if(GetSizeString(outdata) == true)
|
||||
return 1;
|
||||
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
if(GetSizeString(outdata) == true)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
if(GetSizeString(outdata) == true)
|
||||
return 1;
|
||||
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
if(GetSizeString(outdata) == true)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int Http_BufferedReader::PumpEofRead(StrTargetBuffer & outdata,Socket_TCP &sck)
|
||||
{
|
||||
{
|
||||
// do a quick read
|
||||
{
|
||||
size_t MaxRead = FastAmountBeffered();
|
||||
if(MaxRead > 0)
|
||||
{
|
||||
char *ff = FastGetMessageHead();
|
||||
outdata.append(ff,MaxRead);
|
||||
_StartPos += MaxRead;
|
||||
Compress();
|
||||
}
|
||||
}
|
||||
|
||||
// pump the reader
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp== -1) // eof
|
||||
{
|
||||
// if eof clean the mess
|
||||
{
|
||||
size_t MaxRead = FastAmountBeffered();
|
||||
if(MaxRead > 0)
|
||||
{
|
||||
char *ff = FastGetMessageHead();
|
||||
outdata.append(ff,MaxRead);
|
||||
_StartPos += MaxRead;
|
||||
Compress();
|
||||
char *ff = FastGetMessageHead();
|
||||
outdata.append(ff,MaxRead);
|
||||
_StartPos += MaxRead;
|
||||
Compress();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// pump the reader
|
||||
int rp = ReadPump(sck);
|
||||
if(rp == 0)
|
||||
return 0;
|
||||
|
||||
if(rp== -1) // eof
|
||||
{
|
||||
// if eof clean the mess
|
||||
size_t MaxRead = FastAmountBeffered();
|
||||
if(MaxRead > 0)
|
||||
{
|
||||
char *ff = FastGetMessageHead();
|
||||
outdata.append(ff,MaxRead);
|
||||
_StartPos += MaxRead;
|
||||
Compress();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if(rp < 1)
|
||||
return -1;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
inline bool Http_BufferedReader::GetSizeString(StrTargetBuffer & outdata)
|
||||
{
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = outdata.left_to_fill();
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
if(MaxRead > 0)
|
||||
{
|
||||
|
||||
char *ff = FastGetMessageHead();
|
||||
outdata.append(ff,MaxRead);
|
||||
_StartPos += MaxRead;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
size_t DataAvail = FastAmountBeffered();
|
||||
size_t MaxRead = outdata.left_to_fill();
|
||||
if(MaxRead > DataAvail)
|
||||
MaxRead = DataAvail;
|
||||
|
||||
char * wrk = FastGetMessageHead();
|
||||
if(MaxRead > 0)
|
||||
{
|
||||
|
||||
char *ff = FastGetMessageHead();
|
||||
outdata.append(ff,MaxRead);
|
||||
_StartPos += MaxRead;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ int HttpConnection::DoReadHeader(char * message, int buffersize,Time_Clock &cur
|
|||
|
||||
if(_Timer.Expired(currentTime) == true)
|
||||
{
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -59,7 +59,7 @@ int HttpConnection::DoReadBody(char * message1, int buffersize,Time_Clock &curr
|
|||
|
||||
if(_Timer.Expired(currentTime) == true)
|
||||
{
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ok lets process this thing..
|
||||
|
|
@ -69,7 +69,7 @@ int HttpConnection::DoReadBody(char * message1, int buffersize,Time_Clock &curr
|
|||
}
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int HttpConnection::ReadIt(char * message, int buffersize,Time_Clock ¤tTime)
|
||||
{
|
||||
{
|
||||
switch (_state)
|
||||
{
|
||||
case(READING_HEADER):
|
||||
|
|
@ -144,17 +144,17 @@ CloseState HttpConnection::ProcessMessage(char * message,Time_Clock ¤tTime
|
|||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
int HttpConnection::CloseStateWriter(Time_Clock ¤tTime)
|
||||
{
|
||||
int fans = _writer.Flush(*this); // write error
|
||||
int fans = _writer.Flush(*this); // write error
|
||||
if(fans < 0)
|
||||
return -1;
|
||||
return -1;
|
||||
|
||||
if(_writer.AmountBuffered() <= 0) // all done
|
||||
return -1;
|
||||
if(_writer.AmountBuffered() <= 0) // all done
|
||||
return -1;
|
||||
|
||||
if(_Timer.Expired(currentTime) == true) // too long
|
||||
if(_Timer.Expired(currentTime) == true) // too long
|
||||
return -1;
|
||||
|
||||
return 0; // keep trying
|
||||
return 0; // keep trying
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@
|
|||
class HttpConnection : public Socket_TCP
|
||||
{
|
||||
protected:
|
||||
Http_BufferedReader _Reader;
|
||||
Http_BufferedReader _Reader;
|
||||
BufferedWriter_Growable _writer;
|
||||
Socket_Address _MyAddress;
|
||||
Socket_Address _MyAddress;
|
||||
|
||||
Time_Out _Timer;
|
||||
Time_Out _Timer;
|
||||
|
||||
enum STATE_CONNECTIONS {
|
||||
READING_HEADER =1,
|
||||
|
|
@ -40,12 +40,12 @@ protected:
|
|||
public:
|
||||
virtual ~HttpConnection(void);
|
||||
const Socket_Address & GetMyAddress(void);
|
||||
virtual bool BuildPage( BufferedWriter_Growable &_writer, ParsedHttpRequest &parser) = 0;
|
||||
virtual bool BuildPage( BufferedWriter_Growable &_writer, ParsedHttpRequest &parser) = 0;
|
||||
HttpConnection(SOCKET sck,Socket_Address &inaddr) ;
|
||||
|
||||
CloseState ProcessMessage(char * message,Time_Clock ¤tTime);
|
||||
int DoReadHeader(char * message, int buffersize,Time_Clock ¤tTime);
|
||||
int DoReadBody(char * message, int buffersize,Time_Clock ¤tTime);
|
||||
int DoReadHeader(char * message, int buffersize,Time_Clock ¤tTime);
|
||||
int DoReadBody(char * message, int buffersize,Time_Clock ¤tTime);
|
||||
int ReadIt(char * message, int buffersize,Time_Clock ¤tTime);
|
||||
void Reset();
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ public:
|
|||
{
|
||||
Global_WebRequests_pendingNotify.erase(this);
|
||||
};
|
||||
bool BuildPage( BufferedWriter_Growable &_writer, ParsedHttpRequest &parser)
|
||||
bool BuildPage( BufferedWriter_Growable &_writer, ParsedHttpRequest &parser)
|
||||
{
|
||||
Global_WebRequests_pendingNotify.insert((Http_Request *)this);
|
||||
|
||||
|
|
@ -78,7 +78,7 @@ PUBLISHED:
|
|||
{
|
||||
const std::string * answer = _parser.GetOption(in);
|
||||
if(answer != NULL)
|
||||
return true;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +86,7 @@ PUBLISHED:
|
|||
{
|
||||
const std::string * answer = _parser.GetOption(in);
|
||||
if(answer != NULL)
|
||||
return answer->c_str();
|
||||
return answer->c_str();
|
||||
return "";
|
||||
}
|
||||
std::string GetRequestOptionString()
|
||||
|
|
|
|||
|
|
@ -23,112 +23,112 @@ s.refresh() # If you need to refresh the dynamic data
|
|||
"""
|
||||
|
||||
class SystemInformation:
|
||||
def __init__(self):
|
||||
def __init__(self):
|
||||
|
||||
# Just in case sombody called this class by accident, we should
|
||||
# check to make sure the OS is Linux before continuing
|
||||
# Just in case sombody called this class by accident, we should
|
||||
# check to make sure the OS is Linux before continuing
|
||||
|
||||
assert sys.platform == 'linux2', "Not a Linux based system. This class should not be called"
|
||||
assert sys.platform == 'linux2', "Not a Linux based system. This class should not be called"
|
||||
|
||||
self.os = self.__getOS()
|
||||
self.cpu = self.__getCPU()
|
||||
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
||||
self.loadAvg = self.__getLoadAvg()
|
||||
self.os = self.__getOS()
|
||||
self.cpu = self.__getCPU()
|
||||
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
||||
self.loadAvg = self.__getLoadAvg()
|
||||
|
||||
def refresh(self):
|
||||
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
||||
self.loadAvg = self.__getLoadAvg()
|
||||
def refresh(self):
|
||||
self.totalRAM, self.availableRAM, self.totalVM, self.availableVM = self.__getMemory()
|
||||
self.loadAvg = self.__getLoadAvg()
|
||||
|
||||
def __getloadAvg(self):
|
||||
loadAvg = open('/proc/loadavg')
|
||||
procloadAvg = loadAvg.read()
|
||||
loadAvg.close()
|
||||
# Lets remove the \n from the raw string
|
||||
procloadAvg = procloadAvg.replace('\n','')
|
||||
return procloadAvg
|
||||
def __getloadAvg(self):
|
||||
loadAvg = open('/proc/loadavg')
|
||||
procloadAvg = loadAvg.read()
|
||||
loadAvg.close()
|
||||
# Lets remove the \n from the raw string
|
||||
procloadAvg = procloadAvg.replace('\n','')
|
||||
return procloadAvg
|
||||
|
||||
def __getOS(self):
|
||||
procOS = open('/proc/version')
|
||||
procOSRaw = procOS.read()
|
||||
procOS.close()
|
||||
# Lets remove the \n before returning the version string
|
||||
procOSRaw = procOSRaw.replace('\n', '')
|
||||
return procOSRaw
|
||||
def __getOS(self):
|
||||
procOS = open('/proc/version')
|
||||
procOSRaw = procOS.read()
|
||||
procOS.close()
|
||||
# Lets remove the \n before returning the version string
|
||||
procOSRaw = procOSRaw.replace('\n', '')
|
||||
return procOSRaw
|
||||
|
||||
def __getCPU(self):
|
||||
procCPU = open('/proc/cpuinfo')
|
||||
procCPURaw = procCPU.read()
|
||||
procCPU.close()
|
||||
del procCPU
|
||||
procCPURaw = procCPURaw.split('\n')
|
||||
# Lets first figure out how many CPUs are in the system
|
||||
cpuCount = 0
|
||||
modelName = ''
|
||||
cpuMHz = ''
|
||||
for element in procCPURaw:
|
||||
if element.find('processor') != -1:
|
||||
cpuCount += 1
|
||||
# cpuCount now has the total number of CPUs
|
||||
def __getCPU(self):
|
||||
procCPU = open('/proc/cpuinfo')
|
||||
procCPURaw = procCPU.read()
|
||||
procCPU.close()
|
||||
del procCPU
|
||||
procCPURaw = procCPURaw.split('\n')
|
||||
# Lets first figure out how many CPUs are in the system
|
||||
cpuCount = 0
|
||||
modelName = ''
|
||||
cpuMHz = ''
|
||||
for element in procCPURaw:
|
||||
if element.find('processor') != -1:
|
||||
cpuCount += 1
|
||||
# cpuCount now has the total number of CPUs
|
||||
|
||||
# Next, on to the Model of the Processor
|
||||
for element in procCPURaw:
|
||||
if element.find('model name') != -1:
|
||||
modelName = element[element.find(':')+2:]
|
||||
break
|
||||
# Next, on to the Model of the Processor
|
||||
for element in procCPURaw:
|
||||
if element.find('model name') != -1:
|
||||
modelName = element[element.find(':')+2:]
|
||||
break
|
||||
|
||||
# Next, on to the clock speed
|
||||
for element in procCPURaw:
|
||||
if element.find('cpu MHz') != -1:
|
||||
cpuMHz = element[element.find(':')+2:]
|
||||
break
|
||||
# Now that we have the info, time to return a string
|
||||
# Next, on to the clock speed
|
||||
for element in procCPURaw:
|
||||
if element.find('cpu MHz') != -1:
|
||||
cpuMHz = element[element.find(':')+2:]
|
||||
break
|
||||
# Now that we have the info, time to return a string
|
||||
|
||||
return "%s\t%d @ %s MHz" % (modelName, cpuCount, cpuMHz)
|
||||
return "%s\t%d @ %s MHz" % (modelName, cpuCount, cpuMHz)
|
||||
|
||||
|
||||
def __getMemory(self):
|
||||
procMemory = open('/proc/meminfo')
|
||||
procMemoryRaw = procMemory.read()
|
||||
procMemory.close()
|
||||
del procMemory
|
||||
procMemoryRaw = procMemoryRaw.split('\n')
|
||||
# We are looking for the following:
|
||||
# MemTotal, MemFree, SwapTotal, SwapFree
|
||||
def __getMemory(self):
|
||||
procMemory = open('/proc/meminfo')
|
||||
procMemoryRaw = procMemory.read()
|
||||
procMemory.close()
|
||||
del procMemory
|
||||
procMemoryRaw = procMemoryRaw.split('\n')
|
||||
# We are looking for the following:
|
||||
# MemTotal, MemFree, SwapTotal, SwapFree
|
||||
|
||||
# Lets start with MemTotal first
|
||||
# Lets start with MemTotal first
|
||||
|
||||
memTotal = ''
|
||||
for element in procMemoryRaw:
|
||||
if element.find('MemTotal:') != -1:
|
||||
memTotal = element.split(':')[1].replace(' ','')
|
||||
break
|
||||
# Next MemFree:
|
||||
memTotal = ''
|
||||
for element in procMemoryRaw:
|
||||
if element.find('MemTotal:') != -1:
|
||||
memTotal = element.split(':')[1].replace(' ','')
|
||||
break
|
||||
# Next MemFree:
|
||||
|
||||
memFree = ''
|
||||
for element in procMemoryRaw:
|
||||
if element.find('MemFree:') != -1:
|
||||
memFree = element.split(':')[1].replace(' ','')
|
||||
memFree = ''
|
||||
for element in procMemoryRaw:
|
||||
if element.find('MemFree:') != -1:
|
||||
memFree = element.split(':')[1].replace(' ','')
|
||||
break
|
||||
|
||||
# SwapTotal:
|
||||
# SwapTotal:
|
||||
|
||||
swapTotal = ''
|
||||
for element in procMemoryRaw:
|
||||
if element.find('SwapTotal:') != -1:
|
||||
memFree = element.split(':')[1].replace(' ','')
|
||||
swapTotal = ''
|
||||
for element in procMemoryRaw:
|
||||
if element.find('SwapTotal:') != -1:
|
||||
memFree = element.split(':')[1].replace(' ','')
|
||||
break
|
||||
|
||||
# SwapFree:
|
||||
# SwapFree:
|
||||
|
||||
swapFree = ''
|
||||
for element in procMemoryRaw:
|
||||
swapFree = ''
|
||||
for element in procMemoryRaw:
|
||||
if element.find('SwapFree:') != -1:
|
||||
memFree = element.split(':')[1].replace(' ','')
|
||||
break
|
||||
return memTotal, memFree, swapTotal, swapFree
|
||||
return memTotal, memFree, swapTotal, swapFree
|
||||
|
||||
if __name__ == "__main__":
|
||||
s = SystemInformation()
|
||||
print s.cpu
|
||||
print s.totalRAM
|
||||
print s.os
|
||||
s = SystemInformation()
|
||||
print s.cpu
|
||||
print s.totalRAM
|
||||
print s.os
|
||||
|
|
|
|||
|
|
@ -6,41 +6,41 @@
|
|||
////////////////////////////////////////////////////////////////////
|
||||
inline std::string & trimleft_inplace(std::string & s)
|
||||
{
|
||||
s.erase(0, s.find_first_not_of(" \t\n\r"));
|
||||
return s;
|
||||
s.erase(0, s.find_first_not_of(" \t\n\r"));
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline std::string & trimright_inplace(std::string & s)
|
||||
{
|
||||
size_t idx = s.find_last_not_of(" \t\n\r");
|
||||
size_t idx = s.find_last_not_of(" \t\n\r");
|
||||
|
||||
if (std::string::npos == idx)
|
||||
{
|
||||
s.erase();
|
||||
}
|
||||
else
|
||||
{
|
||||
char c = s.at(idx);
|
||||
s.erase(idx, std::string::npos);
|
||||
s.append(1, c);
|
||||
}
|
||||
if (std::string::npos == idx)
|
||||
{
|
||||
s.erase();
|
||||
}
|
||||
else
|
||||
{
|
||||
char c = s.at(idx);
|
||||
s.erase(idx, std::string::npos);
|
||||
s.append(1, c);
|
||||
}
|
||||
|
||||
return s;
|
||||
return s;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline std::string & trim_inplace(std::string & s)
|
||||
{
|
||||
trimleft_inplace(s);
|
||||
trimright_inplace(s);
|
||||
return s;
|
||||
trimleft_inplace(s);
|
||||
trimright_inplace(s);
|
||||
return s;
|
||||
}
|
||||
|
||||
inline std::string trim_tonew(const std::string &in)
|
||||
{
|
||||
std::string ss = in;
|
||||
return trim_inplace(ss);
|
||||
std::string ss = in;
|
||||
return trim_inplace(ss);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -48,81 +48,81 @@ inline std::string trim_tonew(const std::string &in)
|
|||
|
||||
std::string ParsedHttpRequest::deCanonicalize(std::string &inval)
|
||||
{
|
||||
std::string work("");
|
||||
unsigned int x=0;
|
||||
while (x < inval.size())
|
||||
{
|
||||
switch(inval[x])
|
||||
{
|
||||
case('+'):
|
||||
work+=' ';
|
||||
x++;
|
||||
break;
|
||||
|
||||
case('%'):
|
||||
if(x+2 < inval.size())
|
||||
{
|
||||
x++;
|
||||
char aa[5];
|
||||
char * end;
|
||||
aa[0] = inval[x++];
|
||||
aa[1] = inval[x++];
|
||||
aa[2] = '\0';
|
||||
char c = ( char ) strtoul(aa,&end,16);
|
||||
work+=c;
|
||||
}
|
||||
else
|
||||
x+=3;
|
||||
break;
|
||||
|
||||
default:
|
||||
work+=inval[x++];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return work;
|
||||
std::string work("");
|
||||
unsigned int x=0;
|
||||
while (x < inval.size())
|
||||
{
|
||||
switch(inval[x])
|
||||
{
|
||||
case('+'):
|
||||
work+=' ';
|
||||
x++;
|
||||
break;
|
||||
|
||||
case('%'):
|
||||
if(x+2 < inval.size())
|
||||
{
|
||||
x++;
|
||||
char aa[5];
|
||||
char * end;
|
||||
aa[0] = inval[x++];
|
||||
aa[1] = inval[x++];
|
||||
aa[2] = '\0';
|
||||
char c = ( char ) strtoul(aa,&end,16);
|
||||
work+=c;
|
||||
}
|
||||
else
|
||||
x+=3;
|
||||
break;
|
||||
|
||||
default:
|
||||
work+=inval[x++];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return work;
|
||||
}
|
||||
|
||||
size_t ParsedHttpRequest::PullCR(std::string &src, std::string &dst)
|
||||
{
|
||||
size_t offset = src.find(' ');
|
||||
if(offset >= 0 )
|
||||
{
|
||||
dst = src.substr(0,offset);
|
||||
src = src.substr(offset+1);
|
||||
}
|
||||
return offset;
|
||||
size_t offset = src.find(' ');
|
||||
if(offset >= 0 )
|
||||
{
|
||||
dst = src.substr(0,offset);
|
||||
src = src.substr(offset+1);
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
void ParsedHttpRequest::clear(void)
|
||||
{
|
||||
_RequestType = "";
|
||||
_parameters.clear();
|
||||
_RequestType = "";
|
||||
_parameters.clear();
|
||||
}
|
||||
|
||||
const std::string * ParsedHttpRequest::GetOption(const std::string & query)
|
||||
{
|
||||
std::map<std::string,std::string>::iterator ii;
|
||||
ii = _parameters.find(query);
|
||||
if(ii == _parameters.end())
|
||||
return NULL;
|
||||
|
||||
return &ii->second;
|
||||
std::map<std::string,std::string>::iterator ii;
|
||||
ii = _parameters.find(query);
|
||||
if(ii == _parameters.end())
|
||||
return NULL;
|
||||
|
||||
return &ii->second;
|
||||
}
|
||||
|
||||
|
||||
bool ParsedHttpRequest::GetOption(const std::string & query, std::string & out_value)
|
||||
{
|
||||
std::map<std::string,std::string>::iterator ii;
|
||||
ii = _parameters.find(query);
|
||||
if(ii == _parameters.end())
|
||||
{
|
||||
out_value = "";
|
||||
return false;
|
||||
}
|
||||
out_value = ii->second;
|
||||
return true;
|
||||
std::map<std::string,std::string>::iterator ii;
|
||||
ii = _parameters.find(query);
|
||||
if(ii == _parameters.end())
|
||||
{
|
||||
out_value = "";
|
||||
return false;
|
||||
}
|
||||
out_value = ii->second;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ParsedHttpRequest::ParseThis(char * request)
|
||||
|
|
@ -155,59 +155,59 @@ bool ParsedHttpRequest::ParseThis(char * request)
|
|||
//
|
||||
// Get the url for the request ..
|
||||
//
|
||||
std::string work(request);
|
||||
std::string line1 = work.substr(0,work.find_first_of("\n\r\0"));
|
||||
if(line1.size() < 4)
|
||||
return false;
|
||||
|
||||
if(PullCR(line1,_RequestType) < 3)
|
||||
return false;
|
||||
|
||||
if(PullCR(line1,_RequestText) < 1)
|
||||
return false;
|
||||
|
||||
size_t loc = (int)_RequestText.find('?');
|
||||
std::string work(request);
|
||||
std::string line1 = work.substr(0,work.find_first_of("\n\r\0"));
|
||||
if(line1.size() < 4)
|
||||
return false;
|
||||
|
||||
if(PullCR(line1,_RequestType) < 3)
|
||||
return false;
|
||||
|
||||
if(PullCR(line1,_RequestText) < 1)
|
||||
return false;
|
||||
|
||||
size_t loc = (int)_RequestText.find('?');
|
||||
if(loc != std::string::npos)
|
||||
{
|
||||
_Requestoptions = _RequestText.substr(loc+1);
|
||||
_RequestText = _RequestText.substr(0,loc);
|
||||
}
|
||||
|
||||
return ProcessOptionString(_Requestoptions);
|
||||
{
|
||||
_Requestoptions = _RequestText.substr(loc+1);
|
||||
_RequestText = _RequestText.substr(0,loc);
|
||||
}
|
||||
|
||||
return ProcessOptionString(_Requestoptions);
|
||||
}
|
||||
|
||||
std::string & ParsedHttpRequest::GetRequestURL(void)
|
||||
{
|
||||
return _RequestText;
|
||||
return _RequestText;
|
||||
};
|
||||
|
||||
bool ParsedHttpRequest::ProcessOptionString(std::string str)
|
||||
{
|
||||
size_t loc;
|
||||
size_t loc;
|
||||
for(loc = str.find('&'); loc != std::string::npos; loc = str.find('&'))
|
||||
{
|
||||
std::string valset = str.substr(0,loc);
|
||||
str = str.substr(loc+1);
|
||||
if(ProcessParamSet(valset) != true)
|
||||
return false;
|
||||
}
|
||||
return ProcessParamSet(str);
|
||||
{
|
||||
std::string valset = str.substr(0,loc);
|
||||
str = str.substr(loc+1);
|
||||
if(ProcessParamSet(valset) != true)
|
||||
return false;
|
||||
}
|
||||
return ProcessParamSet(str);
|
||||
};
|
||||
|
||||
bool ParsedHttpRequest::ProcessParamSet(std::string &str)
|
||||
{
|
||||
std::string val("");
|
||||
size_t loc = str.find('=');
|
||||
|
||||
std::string val("");
|
||||
size_t loc = str.find('=');
|
||||
|
||||
if(loc != std::string::npos)
|
||||
{
|
||||
val = str.substr(loc+1);
|
||||
str = str.substr(0,loc);
|
||||
|
||||
std::string ind1 = deCanonicalize(str);
|
||||
_parameters[ind1] = deCanonicalize(val);
|
||||
}
|
||||
return true;
|
||||
{
|
||||
val = str.substr(loc+1);
|
||||
str = str.substr(0,loc);
|
||||
|
||||
std::string ind1 = deCanonicalize(str);
|
||||
_parameters[ind1] = deCanonicalize(val);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -10,29 +10,29 @@ class ParsedHttpRequest
|
|||
{
|
||||
protected:
|
||||
std::string _Raw_Text;
|
||||
std::string _RequestType;
|
||||
std::string _RequestText;
|
||||
std::string _Requestoptions;
|
||||
std::string _RequestType;
|
||||
std::string _RequestText;
|
||||
std::string _Requestoptions;
|
||||
std::string _BodyText;
|
||||
|
||||
|
||||
std::map<std::string,std::string> _parameters;
|
||||
std::map<std::string,std::string> _parameters;
|
||||
std::map<std::string,std::string> _header_Lines;
|
||||
|
||||
std::string deCanonicalize(std::string &inval);
|
||||
size_t PullCR(std::string &src, std::string &dst);
|
||||
std::string deCanonicalize(std::string &inval);
|
||||
size_t PullCR(std::string &src, std::string &dst);
|
||||
|
||||
public:
|
||||
void clear(void);
|
||||
void clear(void);
|
||||
const std::string GetRequestOptionString() { return _Requestoptions; };
|
||||
const std::string * GetOption(const std::string & query);
|
||||
bool GetOption(const std::string & query, std::string & out_value);
|
||||
bool ParseThis(char * request);
|
||||
std::string & GetRequestURL(void);
|
||||
const std::string * GetOption(const std::string & query);
|
||||
bool GetOption(const std::string & query, std::string & out_value);
|
||||
bool ParseThis(char * request);
|
||||
std::string & GetRequestURL(void);
|
||||
const std::string & GetRawRequest(void) const { return _Raw_Text; };
|
||||
const std::string & GetRequestType(void) const { return _RequestType; };
|
||||
bool ProcessOptionString(std::string str);
|
||||
bool ProcessParamSet(std::string &str);
|
||||
bool ProcessOptionString(std::string str);
|
||||
bool ProcessParamSet(std::string &str);
|
||||
|
||||
|
||||
void SetBodyText(const std::string & text)
|
||||
|
|
|
|||
|
|
@ -4,41 +4,41 @@
|
|||
|
||||
// RHH
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : GmRingBuffer
|
||||
// Description : This is an implemention of the membuffer with ring
|
||||
// buffer interface on it....
|
||||
//
|
||||
// Main target right know is base class for network
|
||||
// stream buffering both input and output
|
||||
//
|
||||
// see BufferedReader_Gm
|
||||
// BufferedWriter_Gm
|
||||
// Class : GmRingBuffer
|
||||
// Description : This is an implemention of the membuffer with ring
|
||||
// buffer interface on it....
|
||||
//
|
||||
// Main target right know is base class for network
|
||||
// stream buffering both input and output
|
||||
//
|
||||
// see BufferedReader_Gm
|
||||
// BufferedWriter_Gm
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "membuffer.h"
|
||||
class RingBuffer_Slide : protected MemBuffer
|
||||
{
|
||||
protected:
|
||||
size_t _StartPos;
|
||||
size_t _EndPos;
|
||||
inline char * GetMessageHead(void);
|
||||
inline char * GetBufferOpen(void);
|
||||
inline void ForceWindowSlide(void);
|
||||
size_t _StartPos;
|
||||
size_t _EndPos;
|
||||
inline char * GetMessageHead(void);
|
||||
inline char * GetBufferOpen(void);
|
||||
inline void ForceWindowSlide(void);
|
||||
#define FastGetMessageHead() (_Buffer+_StartPos)
|
||||
#define FastAmountBeffered() (_EndPos - _StartPos)
|
||||
|
||||
inline bool PutFast(const char * data, size_t len);
|
||||
|
||||
public:
|
||||
inline size_t AmountBuffered(void);
|
||||
inline size_t BufferAvailabe(void);
|
||||
inline void ResetContent(void);
|
||||
inline size_t AmountBuffered(void);
|
||||
inline size_t BufferAvailabe(void);
|
||||
inline void ResetContent(void);
|
||||
|
||||
inline RingBuffer_Slide(size_t in_size = 4096);
|
||||
inline void FullCompress(void);
|
||||
inline void Compress(void);
|
||||
inline bool Put(const char * data, size_t len);
|
||||
inline bool Get(char * data, size_t len);
|
||||
inline RingBuffer_Slide(size_t in_size = 4096);
|
||||
inline void FullCompress(void);
|
||||
inline void Compress(void);
|
||||
inline bool Put(const char * data, size_t len);
|
||||
inline bool Get(char * data, size_t len);
|
||||
};
|
||||
|
||||
#include "ringbuffer_slide.i"
|
||||
|
|
|
|||
|
|
@ -1,187 +1,187 @@
|
|||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::GetMessageHead
|
||||
// Description : This will get a pointer to the fist undelivered data in buffer
|
||||
// Return type : char *
|
||||
// Function name : RingBuffer_Slide::GetMessageHead
|
||||
// Description : This will get a pointer to the fist undelivered data in buffer
|
||||
// Return type : char *
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * RingBuffer_Slide::GetMessageHead(void)
|
||||
inline char * RingBuffer_Slide::GetMessageHead(void)
|
||||
{
|
||||
return _Buffer+_StartPos;
|
||||
return _Buffer+_StartPos;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::GetBufferOpen
|
||||
// Description : This will get the first writabe section of the buffer space
|
||||
// Return type :
|
||||
// Function name : RingBuffer_Slide::GetBufferOpen
|
||||
// Description : This will get the first writabe section of the buffer space
|
||||
// Return type :
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline char * RingBuffer_Slide::GetBufferOpen(void)
|
||||
inline char * RingBuffer_Slide::GetBufferOpen(void)
|
||||
{
|
||||
return _Buffer+_EndPos;
|
||||
return _Buffer+_EndPos;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::ForceWindowSlide
|
||||
// Description : Will force a compression of data // shift left to start position
|
||||
// Return type : inline void
|
||||
// Function name : RingBuffer_Slide::ForceWindowSlide
|
||||
// Description : Will force a compression of data // shift left to start position
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer_Slide::ForceWindowSlide(void)
|
||||
{
|
||||
size_t len = AmountBuffered();
|
||||
if(len > 0 && _StartPos != 0) // basic flush left..
|
||||
{
|
||||
memmove(_Buffer,GetMessageHead(),len);
|
||||
_StartPos = 0;
|
||||
_EndPos = len;
|
||||
}
|
||||
size_t len = AmountBuffered();
|
||||
if(len > 0 && _StartPos != 0) // basic flush left..
|
||||
{
|
||||
memmove(_Buffer,GetMessageHead(),len);
|
||||
_StartPos = 0;
|
||||
_EndPos = len;
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::AmountBuffered
|
||||
// Description : Will report the number of unread chars in buffer
|
||||
// Return type : int
|
||||
// Function name : RingBuffer_Slide::AmountBuffered
|
||||
// Description : Will report the number of unread chars in buffer
|
||||
// Return type : int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t RingBuffer_Slide::AmountBuffered(void)
|
||||
inline size_t RingBuffer_Slide::AmountBuffered(void)
|
||||
{
|
||||
return _EndPos - _StartPos;
|
||||
return _EndPos - _StartPos;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::BufferAvailabe
|
||||
// Description : Will report amount of data that is contiguas that can be writen at
|
||||
// the location returned by GetBufferOpen
|
||||
// Return type : inline int
|
||||
// Function name : RingBuffer_Slide::BufferAvailabe
|
||||
// Description : Will report amount of data that is contiguas that can be writen at
|
||||
// the location returned by GetBufferOpen
|
||||
// Return type : inline int
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline size_t RingBuffer_Slide::BufferAvailabe(void)
|
||||
{
|
||||
return GetBufferSize() - _EndPos;
|
||||
return GetBufferSize() - _EndPos;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::ResetContent
|
||||
// Description : Throw away all inread information
|
||||
// Return type : void
|
||||
// Function name : RingBuffer_Slide::ResetContent
|
||||
// Description : Throw away all inread information
|
||||
// Return type : void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
void RingBuffer_Slide::ResetContent(void)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::RingBuffer_Slide
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Function name : RingBuffer_Slide::RingBuffer_Slide
|
||||
// Description :
|
||||
// Return type : inline
|
||||
// Argument : int in_size
|
||||
//////////////////////////////////////////////////////////
|
||||
inline RingBuffer_Slide::RingBuffer_Slide(size_t in_size) : MemBuffer(in_size)
|
||||
{
|
||||
_EndPos = 0;
|
||||
_StartPos = 0;
|
||||
{
|
||||
_EndPos = 0;
|
||||
_StartPos = 0;
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::FullCompress
|
||||
// Description : Force a compress of the data
|
||||
// Return type : inline void
|
||||
// Function name : RingBuffer_Slide::FullCompress
|
||||
// Description : Force a compress of the data
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer_Slide::FullCompress(void)
|
||||
{
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::Compress
|
||||
// Description : Try and do a intelegent compress of the data space
|
||||
// the algorithem is really stupid right know.. just say if i have
|
||||
// read past 1/2 my space do a compress...Im open for sugestions
|
||||
//
|
||||
// Function name : RingBuffer_Slide::Compress
|
||||
// Description : Try and do a intelegent compress of the data space
|
||||
// the algorithem is really stupid right know.. just say if i have
|
||||
// read past 1/2 my space do a compress...Im open for sugestions
|
||||
//
|
||||
//
|
||||
// Return type : inline void
|
||||
// Return type : inline void
|
||||
// Argument : void
|
||||
//////////////////////////////////////////////////////////
|
||||
inline void RingBuffer_Slide::Compress(void)
|
||||
{
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else if(_StartPos >= GetBufferSize() / 2)
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
if(_StartPos == _EndPos)
|
||||
{
|
||||
_StartPos = 0;
|
||||
_EndPos = 0;
|
||||
}
|
||||
else if(_StartPos >= GetBufferSize() / 2)
|
||||
{
|
||||
ForceWindowSlide();
|
||||
}
|
||||
}
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::Put
|
||||
// Description : Adds Data to a ring Buffer
|
||||
// Will do a compress if needed so pointers suplied by Get Call are no longer valide
|
||||
// Function name : RingBuffer_Slide::Put
|
||||
// Description : Adds Data to a ring Buffer
|
||||
// Will do a compress if needed so pointers suplied by Get Call are no longer valide
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Return type : inline bool
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer_Slide::Put(const char * data, size_t len)
|
||||
{
|
||||
bool answer = false;
|
||||
|
||||
if(len > BufferAvailabe() )
|
||||
Compress();
|
||||
|
||||
if(len <= BufferAvailabe() )
|
||||
{
|
||||
memcpy(GetBufferOpen(),data,len);
|
||||
_EndPos += len;
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
bool answer = false;
|
||||
|
||||
if(len > BufferAvailabe() )
|
||||
Compress();
|
||||
|
||||
if(len <= BufferAvailabe() )
|
||||
{
|
||||
memcpy(GetBufferOpen(),data,len);
|
||||
_EndPos += len;
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::PutFast
|
||||
// Description :
|
||||
// Function name : RingBuffer_Slide::PutFast
|
||||
// Description :
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Return type : inline bool
|
||||
// Argument : const char * data
|
||||
// Argument : int len
|
||||
////////////////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer_Slide::PutFast(const char * data, size_t len)
|
||||
{
|
||||
// no checking be carefull
|
||||
memcpy(GetBufferOpen(),data,len); // should i be using memcopy..
|
||||
_EndPos += len;
|
||||
return true;
|
||||
// no checking be carefull
|
||||
memcpy(GetBufferOpen(),data,len); // should i be using memcopy..
|
||||
_EndPos += len;
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// Function name : RingBuffer_Slide::Get
|
||||
// Description : will copy the data ..
|
||||
// false indicates not enogh data to read .. sorry...
|
||||
// Function name : RingBuffer_Slide::Get
|
||||
// Description : will copy the data ..
|
||||
// false indicates not enogh data to read .. sorry...
|
||||
//
|
||||
// Return type : inline bool
|
||||
// Return type : inline bool
|
||||
// Argument : char * data
|
||||
// Argument : int len
|
||||
//////////////////////////////////////////////////////////
|
||||
inline bool RingBuffer_Slide::Get(char * data, size_t len)
|
||||
{
|
||||
bool answer = false;
|
||||
|
||||
if(len <= AmountBuffered() )
|
||||
{
|
||||
memcpy(data,GetMessageHead(),len);
|
||||
_StartPos += len;
|
||||
Compress();
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
bool answer = false;
|
||||
|
||||
if(len <= AmountBuffered() )
|
||||
{
|
||||
memcpy(data,GetMessageHead(),len);
|
||||
_StartPos += len;
|
||||
Compress();
|
||||
answer = true;
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -158,7 +158,7 @@ fill_xml(TiXmlElement *xvalue, P3DSession *session) {
|
|||
// list.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
P3D_object **P3DConcreteSequence::
|
||||
get_object_array() {
|
||||
get_object_array() {
|
||||
if (_elements.empty()) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ public:
|
|||
// Overrides
|
||||
public:
|
||||
virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
|
||||
virtual void OnClose( DWORD dwSaveOption );
|
||||
virtual void OnClose( DWORD dwSaveOption );
|
||||
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
|
||||
virtual void DoPropExchange(CPropExchange* pPX);
|
||||
virtual void OnResetState();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ class PPDownloadCallback : public IBindStatusCallback
|
|||
{
|
||||
public:
|
||||
PPDownloadCallback( PPDownloadCallbackSync& downloadSync );
|
||||
virtual ~PPDownloadCallback();
|
||||
virtual ~PPDownloadCallback();
|
||||
|
||||
// IUnknown methods
|
||||
STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ public:
|
|||
static void unref_plugin();
|
||||
|
||||
int Start( const std::string& p3dFileName );
|
||||
int Stop( );
|
||||
int Stop( );
|
||||
|
||||
std::string GetHostUrl( );
|
||||
std::string GetP3DFilename( );
|
||||
|
|
@ -57,7 +57,7 @@ public:
|
|||
|
||||
HWND m_parentWnd;
|
||||
CEvent m_eventStop;
|
||||
CEvent m_eventDownloadStopped;
|
||||
CEvent m_eventDownloadStopped;
|
||||
|
||||
P3D_object* m_p3dObject;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue