Skip to content

Commit

Permalink
Merge pull request #22 from rtckit/v0.7.1
Browse files Browse the repository at this point in the history
v0.7.1
  • Loading branch information
cdosoftei committed May 22, 2023
2 parents f7bb13b + 171763f commit 7e93187
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 122 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
53 changes: 53 additions & 0 deletions .github/workflows/ci.yaml
@@ -0,0 +1,53 @@
name: CI

on:
push:
pull_request:

jobs:
StaticAnalysis:
name: StaticAnalysis (PHP ${{ matrix.php }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-20.04
php:
- 7.4
- 8.0
- 8.1
- 8.2
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install
- run: composer phpstan
- run: composer psalm -- --output-format=github --shepherd

Coverage:
name: Coverage (PHP ${{ matrix.php }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- ubuntu-20.04
php:
- 7.4
- 8.0
- 8.1
- 8.2
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- run: composer install
- uses: paambaati/codeclimate-action@v4.0.0
env:
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
with:
coverageCommand: php -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist --coverage-clover clover.xml
coverageLocations: clover.xml:clover
debug: true
40 changes: 0 additions & 40 deletions Makefile

This file was deleted.

6 changes: 4 additions & 2 deletions README.md
Expand Up @@ -6,8 +6,10 @@

[RFC 3261](https://tools.ietf.org/html/rfc3261) compliant SIP parsing and rendering library for PHP 7.4.

[![Build Status](https://travis-ci.com/rtckit/php-sip.svg?branch=main)](https://travis-ci.com/rtckit/php-sip)
[![CI Status](https://github.com/rtckit/php-sip/workflows/CI/badge.svg)](https://github.com/rtckit/php-sip/actions/workflows/ci.yaml)
[![Psalm Type Coverage](https://shepherd.dev/github/rtckit/php-sip/coverage.svg)](https://shepherd.dev/github/rtckit/php-sip)
[![Latest Stable Version](https://poser.pugx.org/rtckit/sip/v/stable.png)](https://packagist.org/packages/rtckit/sip)
[![Installs on Packagist](https://img.shields.io/packagist/dt/rtckit/sip?color=blue&label=Installs%20on%20Packagist)](https://packagist.org/packages/rtckit/sip)
[![Test Coverage](https://api.codeclimate.com/v1/badges/aff5ee8e8ef3b51689c2/test_coverage)](https://codeclimate.com/github/rtckit/php-sip/test_coverage)
[![Maintainability](https://api.codeclimate.com/v1/badges/aff5ee8e8ef3b51689c2/maintainability)](https://codeclimate.com/github/rtckit/php-sip/maintainability)
[![License](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
Expand Down Expand Up @@ -193,7 +195,7 @@ In order to ensure high code quality, **RTCKit\SIP** uses [PHPStan](https://gith

```sh
php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src
php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml --show-info=true
php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml
```

## License
Expand Down
19 changes: 16 additions & 3 deletions composer.json
@@ -1,7 +1,7 @@
{
"name": "rtckit/sip",
"description": "SIP protocol implementation written in PHP",
"version": "0.7.0",
"version": "0.7.1",
"type": "library",
"keywords": [
"sip",
Expand All @@ -27,10 +27,10 @@
"ext-ctype": "*"
},
"require-dev": {
"phpstan/phpstan": "^0.12",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "^9.5",
"symfony/yaml": "^5.3",
"vimeo/psalm": "^4.10"
"vimeo/psalm": "^5.11"
},
"suggest": {
"ext-hash": "Enables RFC 8760 authentication via SHA(-512)-256 hashing"
Expand All @@ -44,5 +44,18 @@
"psr-4": {
"RTCKit\\SIP\\": "tests/"
}
},
"config": {
"allow-plugins": false,
"platform": {
"php": "7.4"
}
},
"scripts": {
"phpstan": "php -d memory_limit=-1 ./vendor/bin/phpstan analyse -c ./etc/phpstan.neon -n -vvv --ansi --level=max src",
"psalm": "php -d memory_limit=-1 ./vendor/bin/psalm --config=./etc/psalm.xml",
"test": "php -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist --debug",
"coverage": "php -d extension=pcov -d memory_limit=-1 ./vendor/bin/phpunit -c ./etc/phpunit.xml.dist --coverage-text --coverage-html=reports/coverage",
"profile": "php -d memory_limit=-1 ./examples/99-crude-benchmark.php"
}
}
36 changes: 0 additions & 36 deletions etc/Dockerfile

This file was deleted.

29 changes: 0 additions & 29 deletions etc/Dockerfile.xdebug

This file was deleted.

3 changes: 2 additions & 1 deletion etc/psalm.xml
@@ -1,9 +1,10 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedCode="false"
findUnusedBaselineEntry="false"
>
<projectFiles>
<directory name="../src" />
Expand Down
6 changes: 4 additions & 2 deletions src/Auth/Digest/AbstractParams.php
Expand Up @@ -142,7 +142,8 @@ public static function parse(string $input): ParamsInterface

default:
if ($challenge) {
/** @var ChallengeParams $params */
assert($params instanceof ChallengeParams);

switch ($pk) {
case 'domain':
$params->domain = $pv;
Expand All @@ -165,7 +166,8 @@ public static function parse(string $input): ParamsInterface
break 2;
}
} else {
/** @var ResponseParams $params */
assert($params instanceof ResponseParams);

switch ($pk) {
case 'username':
$params->username = $pv;
Expand Down
31 changes: 28 additions & 3 deletions src/Header/ContactHeader.php
Expand Up @@ -37,6 +37,31 @@ public static function parse(array $hbody): ContactHeader
{
$ret = new static;

$input = $hbody;
$hbody = [];

foreach ($input as $hline) {
$segments = explode(',', $hline);
$buffer = $comma = '';

foreach ($segments as $segment) {
$buffer .= $comma . $segment;

if (!(substr_count($segment, '"') % 2) && (substr_count($segment, '<') === substr_count($segment, '>'))) {
$hbody[] = $buffer;
$buffer = $comma = '';

continue;
}

$comma = ',';
}

if (isset($buffer[0])) {
$hbody[] = $buffer;
}
}

foreach ($hbody as $hline) {
$val = new ContactValue;

Expand All @@ -47,7 +72,7 @@ public static function parse(array $hbody): ContactHeader
$qfrom = null;
$afrom = null;
$base = 0;
$addr = null;
$addr = false;

for ($i = 0; $i <= $len; $i++) {
if (!$quoted) {
Expand Down Expand Up @@ -174,7 +199,7 @@ public static function parse(array $hbody): ContactHeader
}
}

if (!is_null($addr)) {
if (is_string($addr)) {
$val->uri = URI::parse($addr);
$ret->values[] = $val;
$addr = null;
Expand All @@ -200,7 +225,7 @@ public static function parse(array $hbody): ContactHeader
}
}

if (!is_null($addr)) {
if (is_string($addr)) {
$val->uri = URI::parse($addr);
$ret->values[] = $val;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Header/NameAddrHeader.php
Expand Up @@ -175,7 +175,7 @@ public static function parse(array $hbody): NameAddrHeader
}
}

if (is_null($addr)) {
if (!is_string($addr)) {
throw new InvalidHeaderLineException('Invalid name-addr line, missing addr-spec', Response::BAD_REQUEST);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Message.php
Expand Up @@ -174,7 +174,7 @@ public static function parse(string $text, bool $ignoreBody = false): Message

$hvalue .= $lines[$i];
} else {
if (isset($hname, $hvalue)) {
if (isset($hname, $hvalue) && strlen($hvalue)) {
$headers[$hname][] = $hvalue;
}

Expand All @@ -199,7 +199,7 @@ public static function parse(string $text, bool $ignoreBody = false): Message
}
}

if (isset($hname, $hvalue[0])) {
if (isset($hname, $hvalue) && strlen($hvalue)) {
$headers[$hname][] = $hvalue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Response.php
Expand Up @@ -373,7 +373,7 @@ public function __construct(?string $startLine = null)

$sttsLine = explode(' ', $startLine, 3);

if (!isset($sttsLine[2])) {
if (count($sttsLine) !== 3) {
throw new InvalidMessageStartLineException('Malformed Status-Line: ' . $startLine, self::BAD_REQUEST);
}

Expand Down
4 changes: 3 additions & 1 deletion src/StreamParser.php
Expand Up @@ -59,6 +59,8 @@ public function process(string $chunk, ?array &$messages): int
break;
}

assert(count($blocks) === 2);

$this->message = Message::parse($this->buffer, true);
$this->buffer = $blocks[1];
} else {
Expand Down Expand Up @@ -91,7 +93,7 @@ public function process(string $chunk, ?array &$messages): int
unset($this->message);

$status = self::SUCCESS;
} while ($status === self::SUCCESS);
} while (true);

return (isset($messages[0]))
? self::SUCCESS
Expand Down
2 changes: 1 addition & 1 deletion tests/RFC4475/S31101Test.php
Expand Up @@ -33,7 +33,7 @@ public function testShouldParseProperly()
$this->assertEquals('Quoted string \\"\\"', $msg->contact->values[0]->name);

/* an empty subject */
$this->assertEquals('', $msg->subject->values[0]);
$this->assertCount(0, $msg->subject->values);

/* both comma separated and separately listed header field values */
/* a mix of short and long form for the same header field name */
Expand Down
13 changes: 13 additions & 0 deletions tests/fixtures/misc/gh-21.yaml
@@ -0,0 +1,13 @@
# https://github.com/rtckit/php-sip/issues/21
- |+
SIP/2.0 200 OK
Via: SIP/2.0/TCP 192.0.2.15;branch=z9hG4bKnuiqisi
From: Bob <sip:bob@example.com>;tag=7F94778B653B
To: Bob <sip:bob@example.com>;tag=6AF99445E44A
Call-ID: 16CB75F21C70
CSeq: 1 REGISTER
Supported: path, outbound
Require: outbound
Contact: <sip:e52@78.102.16.243:55497;transport=tls>;expires=111;received="sip:e52@78.102.16.243:55497";reg-id=1;+sip.instance="<d79966b435633699badcf12507380d51d4e97eab>",<sip:e52@78.102.16.243:17127;transport=tls>;expires=258;received="sip:e52@78.102.16.243:17127";reg-id=2;+sip.instance="<65be01c100f2ccd762df61057569f037bd46a367>"
Path: <sip:VskztcQ/S8p4WPbOnHbuyh5iJvJIW3ib@ep1.example.com;lr;ob>
Content-Length: 0

0 comments on commit 7e93187

Please sign in to comment.