From 09ec7ee043042526b778cb264504a899b7032b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Wed, 3 Jul 2024 14:28:49 +0000 Subject: [PATCH] Fix FLEXIAPI-175 and FLEXISIP-231 Rewrite the Redis contacts parser to handle... --- CHANGELOG.md | 4 ++++ flexiapi/app/Device.php | 25 ++++++++----------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a29b01c..4a50a8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ v1.5 ---- +v1.4.7 +------ +- Fix FLEXIAPI-175 and FLEXISIP-231 Rewrite the Redis contacts parser to handle properly SIP uris (thanks @thibault.lemaire !) + v1.4.6 ------ - Fix FLEXIAPI-142 PUT /accounts endpoint doesn't allow overiding values anymore diff --git a/flexiapi/app/Device.php b/flexiapi/app/Device.php index ba15fe7..a76aaa0 100644 --- a/flexiapi/app/Device.php +++ b/flexiapi/app/Device.php @@ -26,25 +26,16 @@ class Device extends Model { public function fromRedisContact(string $contact) { - // Ugly :'( - $result = []; - $exploded = explode(';', urldecode($contact)); + preg_match("/<(.*)>;(.*)/", $contact, $matches); - foreach ($exploded as $line) { - $line = explode('=', $line); + $parsed = parse_url($matches[1]); + parse_str($parsed["query"], $query); - if (count($line) == 2) { - $result[trim($line[0])] = $line[1]; - } + parse_str(str_replace(";", "&", $parsed["path"]), $sipParams); + parse_str(str_replace(";", "&", $matches[2]), $sipHeaders); - // User agent - if (count($line) == 4) { - $result['userAgent'] = substr($line[3], 0, -1); - } - } - - $this->uuid = \substr($result['sip.instance'], 2, -2); - $this->update_time = Carbon::createFromTimestamp($result['updatedAt']); - $this->user_agent = $result['userAgent']; + $this->uuid = substr($sipHeaders['sip_instance'], 2, -2); + $this->update_time = Carbon::createFromTimestamp($sipParams['updatedAt']); + $this->user_agent = $query["user-agent"]; } }