EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyVisitor.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Zhur, mmcs
24  Rewrite: Allan
25 */
26 
27 #include "../eve-common.h"
28 
30 #include "python/PyVisitor.h"
31 //#include "python/PyRep.h"
32 
33 /************************************************************************/
34 /* PyVisitor */
35 /************************************************************************/
37 {
38  PyTuple::const_iterator itr = rep->begin(), end = rep->end();
39  for (; itr != end; ++itr) {
40  // if/when segfault here and (*itr) == 0x0 then tuple count != tuple->SetItem()
41  if (!(*itr)->visit(*this))
42  return false;
43  }
44  return true;
45 }
46 
47 bool PyVisitor::VisitList(const PyList* rep)
48 {
49  PyList::const_iterator itr = rep->begin(), end = rep->end();
50  for (; itr != end; ++itr)
51  if (!(*itr)->visit(*this))
52  return false;
53 
54  return true;
55 }
56 
57 bool PyVisitor::VisitDict(const PyDict* rep)
58 {
59  PyDict::const_iterator itr = rep->begin(), end = rep->end();
60  for (; itr != end; ++itr) {
61  if (!itr->first->visit(*this))
62  return false;
63  if (!itr->second->visit(*this))
64  return false;
65  }
66  return true;
67 }
68 
70 {
71  if (!rep->type()->visit(*this))
72  return false;
73  if (!rep->arguments()->visit(*this))
74  return false;
75  return true;
76 }
77 
79 {
80  if (!rep->header()->visit(*this))
81  return false;
82 
83  PyObjectEx::const_list_iterator lItr = rep->list().begin(), lEnd = rep->list().end();
84  for (; lItr != lEnd; ++lItr) {
85  if (!(*lItr)->visit(*this))
86  return false;
87  }
88  PyObjectEx::const_dict_iterator dItr = rep->dict().begin(), dEnd = rep->dict().end();
89  for (; dItr != dEnd; ++dItr) {
90  if (!dItr->first->visit(*this))
91  return false;
92  if (!dItr->second->visit(*this))
93  return false;
94  }
95 
96  return true;
97 }
98 
100 {
101  if (!rep->header()->visit(*this))
102  return false;
103 
104  PyPackedRow::const_iterator itr = rep->begin(), end = rep->end();
105  for (; itr != end; ++itr)
106  if (!(*itr)->visit(*this))
107  return false;
108 
109  return true;
110 }
111 
113 {
114  if (!rep->sub()->visit(*this))
115  return false;
116  return true;
117 }
118 
120 {
121  if (rep->decoded() == nullptr) {
122  if (rep->data() == nullptr)
123  return false;
124  rep->DecodeData();
125  if (rep->decoded() == nullptr)
126  return false;
127  }
128  if (!rep->decoded()->visit(*this))
129  return false;
130  return true;
131 }
132 
134 {
135  if (!rep->stream()->visit(*this))
136  return false;
137  return true;
138 }
139 
140 /************************************************************************/
141 /* PyPfxVisitor */
142 /************************************************************************/
144 {
145  mPfxStack.push(pfx);
146 }
147 
148 void PyPfxVisitor::_pfxExtend(const char* fmt, ...)
149 {
150  va_list ap;
151  va_start(ap, fmt);
152 
153  char* res;
154  vasprintf(&res, fmt, ap);
155 
156  va_end(ap);
157 
158  std::string p(_pfx());
159  p += res;
160  mPfxStack.push(p);
161 
162  SafeFree(res);
163 }
list_type & list()
Definition: PyRep.h:889
list_type::const_iterator const_list_iterator
Definition: PyRep.h:866
virtual bool VisitTuple(const PyTuple *rep)
the nested types Visitor
Definition: PyVisitor.cpp:36
void _pfxExtend(const char *fmt,...)
Definition: PyVisitor.cpp:148
bool visit(PyVisitor &v) const
Visits object.
Definition: PyRep.cpp:804
virtual bool VisitSubStream(const PySubStream *rep)
Definition: PyVisitor.cpp:119
Python's dictionary.
Definition: PyRep.h:719
DBRowDescriptor * header() const
Definition: PyRep.h:983
virtual bool VisitDict(const PyDict *rep)
Definition: PyVisitor.cpp:57
virtual bool VisitPackedRow(const PyPackedRow *rep)
PackedRow type visitor.
Definition: PyVisitor.cpp:99
PyBuffer * data() const
Definition: PyRep.h:1047
storage_type::const_iterator const_iterator
Definition: PyRep.h:572
const_iterator begin() const
Definition: PyRep.h:660
storage_type::const_iterator const_iterator
Definition: PyRep.h:644
bool visit(PyVisitor &v) const
Visits object.
Definition: PyRep.cpp:455
Python tuple.
Definition: PyRep.h:567
std::stack< std::string > mPfxStack
Definition: PyVisitor.h:93
PyRep * arguments() const
Definition: PyRep.h:845
PyRep * decoded() const
Definition: PyRep.h:1048
int vasprintf(char **strp, const char *fmt, va_list ap)
Definition: eve-compat.cpp:70
void SafeFree(T *&p)
Frees and nullifies an array pointer.
Definition: SafeMem.h:111
virtual bool VisitObjectEx(const PyObjectEx *rep)
Definition: PyVisitor.cpp:78
Python extended object.
Definition: PyRep.h:861
void DecodeData() const
Definition: PyRep.cpp:1125
Python object.
Definition: PyRep.h:826
storage_type::const_iterator const_iterator
Definition: PyRep.h:966
dict_type::const_iterator const_dict_iterator
Definition: PyRep.h:870
virtual bool VisitSubStruct(const PySubStruct *rep)
wrapper types Visitor
Definition: PyVisitor.cpp:112
dict_type & dict()
Definition: PyRep.h:892
const_iterator begin() const
Definition: PyRep.h:986
PyString * type() const
Definition: PyRep.h:844
const_iterator begin() const
Definition: PyRep.h:766
PyPfxVisitor(const char *pfx="")
Definition: PyVisitor.cpp:143
virtual bool VisitObject(const PyObject *rep)
Object type visitor.
Definition: PyVisitor.cpp:69
const_iterator end() const
Definition: PyRep.h:661
storage_type::const_iterator const_iterator
Definition: PyRep.h:750
const_iterator end() const
Definition: PyRep.h:987
PyRep * header() const
Definition: PyRep.h:886
const_iterator end() const
Definition: PyRep.h:767
Packed row.
Definition: PyRep.h:961
const_iterator end() const
Definition: PyRep.h:589
const_iterator begin() const
Definition: PyRep.h:588
const char * _pfx() const
Definition: PyVisitor.h:89
PyRep * sub() const
Definition: PyRep.h:1021
virtual bool VisitList(const PyList *rep)
Definition: PyVisitor.cpp:47
Python list.
Definition: PyRep.h:639
virtual bool visit(PyVisitor &v) const =0
Visits object.
PyRep * stream() const
Definition: PyRep.h:1081
virtual bool VisitChecksumedStream(const PyChecksumedStream *rep)
Definition: PyVisitor.cpp:133