summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Duedal <hd@onlinecity.dk>2011-09-06 17:41:16 +0200
committerHans Duedal <hd@onlinecity.dk>2011-09-06 17:41:16 +0200
commited096f8690810189f9026a0b34e4e7d10488e6af (patch)
tree711646e2aabfbe907b45474b6e385636bf5557c2
parent30cf1e1727be3f1dcc356b07f7de86c4aac2f4f2 (diff)
parenta3e5e7f474231f28769f96d653a91a7a1a061291 (diff)
downloadphp-smpp-ed096f8690810189f9026a0b34e4e7d10488e6af.zip
php-smpp-ed096f8690810189f9026a0b34e4e7d10488e6af.tar.gz
php-smpp-ed096f8690810189f9026a0b34e4e7d10488e6af.tar.bz2
Merged PHP5.2 compat and Logica/Generic_NACK fixes from develop
-rw-r--r--smppclient.class.php28
-rw-r--r--sockettransport.class.php2
2 files changed, 18 insertions, 12 deletions
diff --git a/smppclient.class.php b/smppclient.class.php
index 1b7fc11..1d6fd53 100644
--- a/smppclient.class.php
+++ b/smppclient.class.php
@@ -83,7 +83,7 @@ class SmppClient
$this->pdu_queue=array();
$this->transport = $transport;
- $this->debugHandler = $debugHandler ?: 'error_log';
+ $this->debugHandler = $debugHandler ? $debugHandler : 'error_log';
$this->mode = null;
}
@@ -550,6 +550,9 @@ class SmppClient
/**
* Waits for SMSC response on specific PDU.
+ * If a GENERIC_NACK with a matching sequence number, or null sequence is received instead it's also accepted.
+ * Some SMPP servers, ie. logica returns GENERIC_NACK on errors.
+ *
* @param integer $seq_number - PDU sequence number
* @param integer $command_id - PDU command ID
* @return SmppPdu
@@ -564,22 +567,25 @@ class SmppClient
$ql = count($this->pdu_queue);
for($i=0;$i<$ql;$i++) {
$pdu=$this->pdu_queue[$i];
- if($pdu->sequence==$seq_number && $pdu->id==$command_id) {
+ if (
+ ($pdu->sequence == $seq_number && ($pdu->id == $command_id || $pdu->id == SMPP::GENERIC_NACK)) ||
+ ($pdu->sequence == null && $pdu->id == SMPP::GENERIC_NACK)
+ ) {
// remove response pdu from queue
array_splice($this->pdu_queue, $i, 1);
return $pdu;
}
}
- // Read pdu until ours show up
+
+ // Read PDUs until the one we are looking for shows up, or a generic nack pdu with matching sequence or null sequence
do{
$pdu=$this->readPDU();
- if($pdu) array_push($this->pdu_queue, $pdu);
- } while($pdu && ($pdu->sequence!=$seq_number || $pdu->id!=$command_id));
- // Remove response from queue
- if($pdu){
- array_pop($this->pdu_queue);
- return $pdu;
- }
+ if ($pdu) {
+ if ($pdu->sequence == $seq_number && ($pdu->id == $command_id || $pdu->id == SMPP::GENERIC_NACK)) return $pdu;
+ if ($pdu->sequence == null && $pdu->id == SMPP::GENERIC_NACK) return $pdu;
+ array_push($this->pdu_queue, $pdu); // unknown PDU push to queue
+ }
+ } while($pdu);
return false;
}
@@ -1148,6 +1154,6 @@ class SmppTag
*/
public function getBinary()
{
- return pack('nn'.$this->type, $this->id, ($this->length ?: strlen($this->value)), $this->value);
+ return pack('nn'.$this->type, $this->id, ($this->length ? $this->length : strlen($this->value)), $this->value);
}
} \ No newline at end of file
diff --git a/sockettransport.class.php b/sockettransport.class.php
index d6bce99..a2773de 100644
--- a/sockettransport.class.php
+++ b/sockettransport.class.php
@@ -37,7 +37,7 @@ class SocketTransport
public function __construct(array $hosts,$ports,$persist=false,$debugHandler=null)
{
$this->debug = self::$defaultDebug;
- $this->debugHandler = $debugHandler ?: 'error_log';
+ $this->debugHandler = $debugHandler ? $debugHandler : 'error_log';
// Deal with optional port
$h = array();