EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyAddress Class Reference

#include "PyPacket.h"

Collaboration diagram for PyAddress:

Public Types

enum  AddrType {
  Node = 1, Client = 2, Broadcast = 4, Any = 8,
  Invalid = 'I'
}
 

Public Member Functions

 PyAddress ()
 
void Dump (FILE *into, const char *pfx) const
 
void Dump (LogType type, const char *pfx) const
 
bool Decode (PyRep *&object)
 
PyRepEncode ()
 
void operator= (const PyAddress &right)
 

Public Attributes

AddrType type
 
int64 objectID
 
int64 callID
 
std::string service
 
std::string bcast_idtype
 

Protected Member Functions

bool _DecodeService (PyRep *rep)
 
bool _DecodeCallID (PyRep *rep)
 
bool _DecodeObjectID (PyRep *rep)
 

Detailed Description

Definition at line 36 of file PyPacket.h.

Member Enumeration Documentation

Enumerator
Node 
Client 
Broadcast 
Any 
Invalid 

Definition at line 57 of file PyPacket.h.

57  {
58  Node = 1,
59  /*
60  * [0] addressType
61  * [1] nodeID
62  * [2] service
63  * [3] callID
64  */
65  Client = 2,
66  /* "because it's ID doesn't match"
67  * [0] addressType
68  * [1] clientID
69  * [2] callID
70  * [3] service
71  */
72  Broadcast = 4,
73  /*
74  * [0] addressType
75  * [1] broadcastID
76  * [2] narrowcast // this part is not understood yet... something about specific nodes for bcast types
77  * [3] idtype
78  */
79  Any = 8,
80  /*
81  * [0] addressType
82  * [1] service
83  * [2] callID
84  */
85  Invalid = 'I' //not real
86  } AddrType;
Definition: Client.h:66

Constructor & Destructor Documentation

PyAddress::PyAddress ( )

Definition at line 275 of file PyPacket.cpp.

276 : type(Invalid),
277 objectID(0),
278 callID(0),
279 service("")
280 {
281 
282 }
int64 callID
Definition: PyPacket.h:90
int64 objectID
Definition: PyPacket.h:89
AddrType type
Definition: PyPacket.h:88
std::string service
Definition: PyPacket.h:92

Member Function Documentation

bool PyAddress::_DecodeCallID ( PyRep rep)
protected

Definition at line 542 of file PyPacket.cpp.

References callID, and PyRep::IntegerValue().

Referenced by Decode().

542  {
544  return true;
545 }
int64 callID
Definition: PyPacket.h:90
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118

Here is the call graph for this function:

Here is the caller graph for this function:

bool PyAddress::_DecodeObjectID ( PyRep rep)
protected

Definition at line 547 of file PyPacket.cpp.

References PyRep::IntegerValue(), and objectID.

Referenced by Decode().

547  {
549  return true;
550 }
int64 objectID
Definition: PyPacket.h:89
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118

Here is the call graph for this function:

Here is the caller graph for this function:

bool PyAddress::_DecodeService ( PyRep rep)
protected

Definition at line 537 of file PyPacket.cpp.

References service, and PyRep::StringContent().

Referenced by Decode().

537  {
539  return true;
540 }
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
std::string service
Definition: PyPacket.h:92

Here is the call graph for this function:

Here is the caller graph for this function:

bool PyAddress::Decode ( PyRep *&  object)

Definition at line 332 of file PyPacket.cpp.

References _DecodeCallID(), _DecodeObjectID(), _DecodeService(), Any, PyObject::arguments(), PyRep::AsObject(), PyRep::AsTuple(), bcast_idtype, Broadcast, Client, codelog, PyRep::Dump(), PyRep::IntegerValue(), PyRep::IsObject(), PyTuple::items, Node, PyDecRef, PySafeDecRef, service, PyRep::StringContent(), type, and PyRep::TypeString().

Referenced by PyPacket::Decode().

332  {
333  PyRep *base = in_object;
334  in_object = nullptr;
335 
336  if (base == nullptr) {
337  codelog(NET__PACKET_ERROR, "PyAddress::Decode() - base is null.");
338  return false;
339  }
340 
341  if (!base->IsObject()) {
342  codelog(NET__PACKET_ERROR, "Invalid element type, expected object but got %s", base->TypeString());
343  PyDecRef(base);
344  return false;
345  }
346 
347  PyTuple *tuple = base->AsObject()->arguments()->AsTuple();
348  if (tuple == nullptr) {
349  codelog(NET__PACKET_ERROR, "PyAddress::Decode() - tuple is null.");
350  return false;
351  }
352 
353  if (tuple->items.size() < 3) {
354  codelog(NET__PACKET_ERROR, "Not enough elements in address tuple: %u", tuple->items.size());
355  tuple->Dump(NET__PACKET_ERROR, " ");
356  PyDecRef(base);
357  PyDecRef(tuple);
358  return false;
359  }
360 
361  //decode the address type.
362  if (!tuple->items[0]->IsInt()) {
363  codelog(NET__PACKET_ERROR, "Wrong type on address element (0)");
364  tuple->items[0]->Dump(NET__PACKET_ERROR, " ");
365  PyDecRef(base);
366  PySafeDecRef(tuple);
367  return false;
368  }
369 
370  switch(PyRep::IntegerValue(tuple->items[0])) {
371  case Any: {
372  if (tuple->items.size() != 3) {
373  codelog(NET__PACKET_ERROR, "Invalid number of elements in Any address tuple: %lu", tuple->items.size());
374  PyDecRef(base);
375  PySafeDecRef(tuple);
376  return false;
377  }
378  type = Any;
379 
380  if (!_DecodeService(tuple->items[1])
381  or !_DecodeCallID(tuple->items[2])) {
382  PyDecRef(base);
383  PySafeDecRef(tuple);
384  return false;
385  }
386  } break;
387  case Node: {
388  if (tuple->items.size() != 4) {
389  codelog(NET__PACKET_ERROR, "Invalid number of elements in Node address tuple: %lu", tuple->items.size());
390  PyDecRef(base);
391  PySafeDecRef(tuple);
392  return false;
393  }
394  type = Node;
395 
396  if (!_DecodeObjectID(tuple->items[1])
397  or !_DecodeService(tuple->items[2])
398  or !_DecodeCallID(tuple->items[3])) {
399  PyDecRef(base);
400  PySafeDecRef(tuple);
401  return false;
402  }
403  } break;
404  case Client: {
405  if (tuple->items.size() != 4) {
406  codelog(NET__PACKET_ERROR, "Invalid number of elements in Client address tuple: %lu", tuple->items.size());
407  PyDecRef(base);
408  PySafeDecRef(tuple);
409  return false;
410  }
411  type = Client;
412 
413  if (!_DecodeObjectID(tuple->items[1])
414  or !_DecodeCallID(tuple->items[2])
415  or !_DecodeService(tuple->items[3])) {
416  PyDecRef(base);
417  PySafeDecRef(tuple);
418  return false;
419  }
420  } break;
421  case Broadcast: {
422  if (tuple->items.size() != 4) {
423  codelog(NET__PACKET_ERROR, "Invalid number of elements in Broadcast address tuple: %lu", tuple->items.size());
424  PyDecRef(base);
425  PySafeDecRef(tuple);
426  return false;
427  }
428  type = Broadcast;
429 
430  if (!tuple->items[1]->IsString()) {
431  codelog(NET__PACKET_ERROR, "Invalid type %s for brodcastID", tuple->items[1]->TypeString());
432  PyDecRef(base);
433  PySafeDecRef(tuple);
434  return false;
435  }
436  if (!tuple->items[3]->IsString()) {
437  codelog(NET__PACKET_ERROR, "Invalid type %s for idtype", tuple->items[3]->TypeString());
438  PyDecRef(base);
439  PySafeDecRef(tuple);
440  return false;
441  }
442 
443  service = PyRep::StringContent(tuple->items[1]); //assign op
444  bcast_idtype = PyRep::StringContent(tuple->items[3]); //assign op
445 
446  //items[2] is either a list or a tuple.
447  /*
448  //PyList *nclist = (PyList *) tuple->items[2];
449  if (!nclist->items.empty()) {
450  printf("Not decoding narrowcast list:");
451  nclist->Dump(NET__PACKET_ERROR, " ");
452  }*/
453  } break;
454  default: {
455  codelog(NET__PACKET_ERROR, "Unknown address type: %i", PyRep::IntegerValue(tuple->items[0]));
456  PyDecRef(base);
457  PySafeDecRef(tuple);
458  return false;
459  }
460  }
461 
462  PyDecRef(base);
463  PySafeDecRef(tuple);
464  return true;
465 }
Base Python wire object.
Definition: PyRep.h:66
PyTuple * AsTuple()
Definition: PyRep.h:138
static std::string StringContent(PyRep *pRep)
Definition: PyRep.cpp:103
PyObject * AsObject()
Definition: PyRep.h:152
bool IsObject() const
Definition: PyRep.h:115
Python tuple.
Definition: PyRep.h:567
void Dump(FILE *into, const char *pfx) const
Dumps object to file.
Definition: PyRep.cpp:84
PyRep * arguments() const
Definition: PyRep.h:845
AddrType type
Definition: PyPacket.h:88
#define codelog(type, fmt,...)
Definition: logsys.h:128
#define PyDecRef(op)
Definition: PyRep.h:57
Definition: Client.h:66
std::string bcast_idtype
Definition: PyPacket.h:93
bool _DecodeObjectID(PyRep *rep)
Definition: PyPacket.cpp:547
std::string service
Definition: PyPacket.h:92
#define PySafeDecRef(op)
Definition: PyRep.h:61
storage_type items
Definition: PyRep.h:628
bool _DecodeCallID(PyRep *rep)
Definition: PyPacket.cpp:542
static int64 IntegerValue(PyRep *pRep)
Definition: PyRep.cpp:118
const char * TypeString() const
Definition: PyRep.cpp:76
bool _DecodeService(PyRep *rep)
Definition: PyPacket.cpp:537

Here is the call graph for this function:

Here is the caller graph for this function:

void PyAddress::Dump ( FILE *  into,
const char *  pfx 
) const

Definition at line 284 of file PyPacket.cpp.

References Any, bcast_idtype, Broadcast, callID, Invalid, Node, objectID, service, and type.

Referenced by PyPacket::Dump(), EVECollectDispatcher::Handle_CallReq(), Client::Handle_CallReq(), EVECollectDispatcher::Handle_CallRsp(), EVECollectDispatcher::Handle_Notify(), and EVECollectDispatcher::Handle_Other().

284  {
285  switch(type) {
286  case Any:
287  fprintf(into, "%sAny: service='%s' callID=%li", pfx, service.c_str(), callID);
288  break;
289  case Node:
290  fprintf(into, "%sNode: nodeID=%li service='%s' callID=%li", pfx, objectID, service.c_str(), callID);
291  break;
292  case Client:
293  fprintf(into, "%sClient: clientID=%li service='%s' callID=%li", pfx, objectID, service.c_str(), callID);
294  break;
295  case Broadcast:
296  fprintf(into, "%sBroadcast: broadcastID='%s' narrowcast=(not implemented) idtype='%s'", pfx, service.c_str(), bcast_idtype.c_str());
297  break;
298  case Invalid:
299  break;
300  //no default on purpose
301  }
302 }
int64 callID
Definition: PyPacket.h:90
int64 objectID
Definition: PyPacket.h:89
AddrType type
Definition: PyPacket.h:88
Definition: Client.h:66
std::string bcast_idtype
Definition: PyPacket.h:93
std::string service
Definition: PyPacket.h:92

Here is the caller graph for this function:

void PyAddress::Dump ( LogType  type,
const char *  pfx 
) const

Definition at line 304 of file PyPacket.cpp.

References _log, Any, bcast_idtype, Broadcast, callID, Invalid, Node, objectID, service, and type.

304  {
305  switch(type) {
306  case Any:
307  _log(ltype, "%sAny: service='%s' callID=%li", pfx, service.c_str(), callID);
308  break;
309  case Node:
310  _log(ltype, "%sNode: nodeID=%li service='%s' callID=%li", pfx, objectID, service.c_str(), callID);
311  break;
312  case Client:
313  _log(ltype, "%sClient: clientID=%li callID=%li service='%s'", pfx, objectID, callID, service.c_str());
314  break;
315  case Broadcast:
316  _log(ltype, "%sBroadcast: broadcastID='%s' narrowcast=(not implemented) idtype='%s'", pfx, service.c_str(), bcast_idtype.c_str());
317  break;
318  case Invalid:
319  break;
320  //no default on purpose
321  }
322 }
int64 callID
Definition: PyPacket.h:90
#define _log(type, fmt,...)
Definition: logsys.h:124
int64 objectID
Definition: PyPacket.h:89
AddrType type
Definition: PyPacket.h:88
Definition: Client.h:66
std::string bcast_idtype
Definition: PyPacket.h:93
std::string service
Definition: PyPacket.h:92
PyRep * PyAddress::Encode ( )

Definition at line 467 of file PyPacket.cpp.

References Any, bcast_idtype, Broadcast, callID, Invalid, PyTuple::items, new_tuple(), Node, objectID, PyStatic, service, and type.

Referenced by PyPacket::Encode().

467  {
468  PyTuple *t(nullptr);
469  switch(type) {
470  case Any: {
471  t = new PyTuple(3);
472  t->items[0] = new PyInt((int)type);
473 
474  if (service.empty())
475  t->items[1] = PyStatic.NewNone();
476  else
477  t->items[1] = new PyString(service.c_str());
478 
479  if (objectID == 0)
480  t->items[2] = PyStatic.NewNone();
481  else
482  t->items[2] = new PyLong(objectID);
483  } break;
484  case Node: {
485  t = new PyTuple(4);
486  t->items[0] = new PyInt((int)type);
487  t->items[1] = new PyLong(objectID);
488 
489  if (service.empty())
490  t->items[2] = PyStatic.NewNone();
491  else
492  t->items[2] = new PyString(service.c_str());
493 
494  if (callID == 0)
495  t->items[3] = PyStatic.NewNone();
496  else
497  t->items[3] = new PyLong(callID);
498  } break;
499  case Client: {
500  t = new PyTuple(4);
501  t->items[0] = new PyInt((int)type);
502  t->items[1] = new PyLong(objectID);
503 
504  if (callID == 0)
505  t->items[2] = PyStatic.NewNone();
506  else
507  t->items[2] = new PyLong(callID);
508 
509  if (service.empty())
510  t->items[3] = PyStatic.NewNone();
511  else
512  t->items[3] = new PyString(service.c_str());
513  } break;
514  case Broadcast: {
515  t = new PyTuple(4);
516  t->items[0] = new PyInt((int)type);
517  //broadcastID
518  if (service.empty())
519  t->items[1] = PyStatic.NewNone();
520  else
521  t->items[1] = new PyString(service.c_str());
522  //narrowcast
523  t->items[2] = new PyList(); // LSC uses tuple here, others None() or empty List()
524  //typeID
525  t->items[3] = new PyString(bcast_idtype.c_str());
526  } break;
527  case Invalid:
528  default: {
529  //this still needs to be something which will not crash us.
530  t = new_tuple(PyStatic.NewNone());
531  } break;
532  }
533 
534  return new PyObject( "macho.MachoAddress", t );
535 }
int64 callID
Definition: PyPacket.h:90
Python string.
Definition: PyRep.h:430
int64 objectID
Definition: PyPacket.h:89
Python tuple.
Definition: PyRep.h:567
Python object.
Definition: PyRep.h:826
PyTuple * new_tuple(int64 arg1)
Definition: PyRep.cpp:1160
AddrType type
Definition: PyPacket.h:88
Python integer.
Definition: PyRep.h:231
#define PyStatic
Definition: PyRep.h:1209
Definition: Client.h:66
std::string bcast_idtype
Definition: PyPacket.h:93
std::string service
Definition: PyPacket.h:92
Python list.
Definition: PyRep.h:639
Python long integer.
Definition: PyRep.h:261

Here is the call graph for this function:

Here is the caller graph for this function:

void PyAddress::operator= ( const PyAddress right)

Definition at line 324 of file PyPacket.cpp.

References bcast_idtype, callID, objectID, service, and type.

324  {
325  type = right.type;
326  objectID = right.objectID;
327  callID = right.callID;
328  service = right.service;
329  bcast_idtype = right.bcast_idtype;
330 }
int64 callID
Definition: PyPacket.h:90
int64 objectID
Definition: PyPacket.h:89
AddrType type
Definition: PyPacket.h:88
std::string bcast_idtype
Definition: PyPacket.h:93
std::string service
Definition: PyPacket.h:92

Member Data Documentation

std::string PyAddress::bcast_idtype

The documentation for this class was generated from the following files: