diff options
| author | Christian Weiske <cweiske@cweiske.de> | 2012-07-14 22:28:47 +0200 |
|---|---|---|
| committer | Christian Weiske <cweiske@cweiske.de> | 2012-07-14 22:28:47 +0200 |
| commit | 706ce1501a9ab1a33e4106774665c631a3ad3749 (patch) | |
| tree | 3193e52b2388831012806db6ad331afe73db173c /src/callnotifier/MessageHandler.php | |
| parent | 19e5e158f8a6e9dda406c2eb70ad035211613df8 (diff) | |
| download | auerswald-callnotifier-706ce1501a9ab1a33e4106774665c631a3ad3749.tar.gz auerswald-callnotifier-706ce1501a9ab1a33e4106774665c631a3ad3749.zip | |
dumping network data is possible now
Diffstat (limited to 'src/callnotifier/MessageHandler.php')
| -rw-r--r-- | src/callnotifier/MessageHandler.php | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/callnotifier/MessageHandler.php b/src/callnotifier/MessageHandler.php new file mode 100644 index 0000000..b4ed645 --- /dev/null +++ b/src/callnotifier/MessageHandler.php @@ -0,0 +1,61 @@ +<?php +namespace callnotifier; + +class MessageHandler +{ + protected $dumpHdl; + + + public function __construct($config) + { + $this->config = $config; + $this->prepareDump(); + } + + public function handle($msg) + { + if ($this->config->dumpFile !== null) { + $this->dump($msg); + } + if (substr($msg, 0, 9) != '[DKANPROT') { + //unknown message type + return; + } + $regex = '#^\\[DKANPROT-([^ ]+) ([0-9]+)\\] (.*)$#'; + if (!preg_match($regex, $msg, $matches)) { + //message should always be that way + return false; + } + list(, $type, $someid, $details) = $matches; + + if ($type != 'Info') { + //we only want info messages + var_dump($type . ': ' . $details); + return; + } + //Vegw/Ets-Cref:[0xffef]/[0x64] - VEGW_SETUP from upper layer to internal destination: CGPN[**22]->CDPN[41], + var_dump($details); + $regex = '#CGPN\\[([^\\]]+)\\]->CDPN\\[([^\\]]+)\\]#'; + if (preg_match($regex, $details, $matches)) { + var_dump('a call!', $matches); + } + } + + protected function prepareDump() + { + if ($this->config->dumpFile === null) { + return; + } + $this->dumpHdl = fopen($this->config->dumpFile, 'w'); + if (!$this->dumpHdl) { + throw new Exception('Cannot open replay file for reading'); + } + } + + protected function dump($msg) + { + fwrite($this->dumpHdl, $msg . "\n"); + } +} + +?> |
