Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please merge #63

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions smppclient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ protected function parseSMS(SmppPdu $pdu)
$dataCoding = next($ar);
next($ar); // sm_default_msg_id
$sm_length = next($ar);
$message = $this->getString($ar,$sm_length);
if ($sm_length > 0) { // getString is doing "next()" on $ar
$message = $this->getString($ar, $sm_length); // but it shouldn't for 0-length,not-null-terminated value
} else {
$message = null;
}

// Check for optional params, and parse them
if (current($ar) !== false) {
Expand Down Expand Up @@ -1062,18 +1066,37 @@ class SmppDeliveryReceipt extends SmppSms
*/
public function parseDeliveryReceipt()
{
$numMatches = preg_match('/^id:([^ ]+) sub:(\d{1,3}) dlvrd:(\d{3}) submit date:(\d{10,12}) done date:(\d{10,12}) stat:([A-Z ]{7}) err:(\d{2,3}) text:(.*)$/si', $this->message, $matches);
$id = "id:(?<id>[^ ]+) ";
$sub = "sub:(?<sub>\d{1,3}) ";
$dlvrd = "dlvrd:(?<dlvrd>\d{3}) ";
$submitDate = "submit date:(?<submitDate>\d{10,12}) ";
$doneDate = "done date:(?<doneDate>\d{10,12}) ";
$stat = "stat:(?<stat>[A-Z ]{7}) ";
$err = "(err:(?<err>\d{2,3}) )?";
$text = "text:(?<text>.*)";
$numMatches = preg_match("/^{$id}{$sub}{$dlvrd}{$submitDate}{$doneDate}{$stat}{$err}{$text}$/si", $this->message, $matches);
if ($numMatches == 0) {
throw new InvalidArgumentException('Could not parse delivery receipt: '.$this->message."\n".bin2hex($this->body));
throw new InvalidArgumentException('Could not parse delivery receipt: '.$this->message."\n".bin2hex($this->body));
}
list($matched, $this->id, $this->sub, $this->dlvrd, $this->submitDate, $this->doneDate, $this->stat, $this->err, $this->text) = $matches;

$this->id = $this->getArrayValue($matches, 'id');
$this->sub = $this->getArrayValue($matches, 'sub');
$this->dlvrd = $this->getArrayValue($matches, 'dlvrd');
$this->submitDate = $this->getArrayValue($matches, 'submitDate');
$this->doneDate = $this->getArrayValue($matches, 'doneDate');
$this->stat = $this->getArrayValue($matches, 'stat');
$this->err = $this->getArrayValue($matches, 'err');
$this->text = $this->getArrayValue($matches, 'text');

// Convert dates
$dp = str_split($this->submitDate,2);
$this->submitDate = gmmktime($dp[3],$dp[4],isset($dp[5]) ? $dp[5] : 0,$dp[1],$dp[2],$dp[0]);
$dp = str_split($this->doneDate,2);
$this->doneDate = gmmktime($dp[3],$dp[4],isset($dp[5]) ? $dp[5] : 0,$dp[1],$dp[2],$dp[0]);
}

private function getArrayValue($array, $key, $default = null){
return isset($array[$key]) ? $array[$key] : $default;
}
}

/**
Expand Down