Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Issue119 #139

Merged
merged 3 commits into from

1 participant

@JonTheNiceGuy

No description provided.

JonTheNiceGuy added some commits
@JonTheNiceGuy JonTheNiceGuy Better debugging in exception throwing :) 1ace09f
@JonTheNiceGuy JonTheNiceGuy Correct naming for the PHPDoc 4bd0a49
@JonTheNiceGuy JonTheNiceGuy A few patches around Issue #119.
* Created unit tests for Gammu
* Fixed the interface name for Gammu messages - it's not
Glue_Gammu-Generic_Glue-Gammu-Provider or something like that any more!!
* Fixed some insert statements to match the database schema.
* Corrected issue where the UDH for longer SMS messages was creating a random
value for each chunk, rather than for each long message.
* Split longer messages into two insertion arrays, rather than one.
* Fixed the installer so it uses the same name for the interface throughout.
* Fixed the installer so it writes the Gammu Config file to the correct file
path.
* Added the generated Gammu config file to the .gitignore.
0800bc3
@JonTheNiceGuy JonTheNiceGuy merged commit 89b82fb into from
@JonTheNiceGuy JonTheNiceGuy deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 21, 2012
  1. @JonTheNiceGuy
  2. @JonTheNiceGuy
Commits on Jan 7, 2013
  1. @JonTheNiceGuy

    A few patches around Issue #119.

    JonTheNiceGuy authored
    * Created unit tests for Gammu
    * Fixed the interface name for Gammu messages - it's not
    Glue_Gammu-Generic_Glue-Gammu-Provider or something like that any more!!
    * Fixed some insert statements to match the database schema.
    * Corrected issue where the UDH for longer SMS messages was creating a random
    value for each chunk, rather than for each long message.
    * Split longer messages into two insertion arrays, rather than one.
    * Fixed the installer so it uses the same name for the interface throughout.
    * Fixed the installer so it writes the Gammu Config file to the correct file
    path.
    * Added the generated Gammu config file to the .gitignore.
This page is out of date. Refresh to see the latest.
View
1  .gitignore
@@ -14,3 +14,4 @@
/Media/images/
/Media/sketchdock-*/
/config/default.php
+/config/gammu.php
View
14 SETUP/install.php
@@ -98,7 +98,7 @@
'gammuport' => '',
'gammudatabase' => 'gammu',
'gammudevice' => '/dev/ttyUSB0',
- 'gammuservice' => 'Generic',
+ 'gammuservice' => 'SMSD',
'twitterenable' => '1',
'twitterconsumerkey' => '',
'twitterconsumersecret' => '',
@@ -553,7 +553,7 @@
'Connection = at',
'',
'[smsd]',
- 'PhoneID = phone' . $arrConfig['gammuservice'],
+ 'PhoneID = Glue_Gammu-' . $arrConfig['gammuservice'],
'CommTimeout = 30',
'DeliveryReport = sms',
'',
@@ -568,7 +568,9 @@
'debuglevel = 3',
';";'
);
- file_put_contents($_SERVER['HOME'].'/phone'.$id.'.gammu', implode("\n", $contents));
+ if(file_put_contents(dirname(__FILE__) . '/../config/gammu.php', implode("\n", $contents)) === false) {
+ echo "Unable to write the config file to the file system. Please create the following file:\r\n\r\n" . implode("\n", $contents);
+ }
$sql = 'INSERT INTO secureconfig (`key`, `value`) VALUES '
. "('Glue_Gammu-{$arrConfig['gammuservice']}_DBType', '{$arrConfig['gammutype']}'), "
. "('Glue_Gammu-{$arrConfig['gammuservice']}_DBHost', '{$arrConfig['gammuhost']}'), "
@@ -578,8 +580,10 @@
. "('Glue_Gammu-{$arrConfig['gammuservice']}_DBBase', '{$arrConfig['gammudatabase']}')";
mysql_query($sql, $coredb);
}
+ echo "Done (to: " . dirname(__FILE__).'/../config/gammu.php' . ")\r\n";
+} else {
+ echo "Skipped";
}
-echo "Done\r\n";
echo "\r\n(8/9) Configuring Twitter API access: ";
if ($arrConfig['twitterenable'] == 1
@@ -650,6 +654,8 @@ function force_readline_reverse($string) {
$arrConfig['forceyes'] = 1;
$return = force_readline($string);
$arrConfig['forceyes'] = -1;
+ } else {
+ $return = force_readline($string);
}
return $return;
}
View
148 Tests/classes/Glue/GammuTest.php
@@ -49,7 +49,7 @@ public function testMessageInjectionWorks()
$this->assertTrue(count($result) == 1);
$this->assertTrue($result[0]['SenderNumber'] == "+447777777777");
$this->assertTrue($result[0]['TextDecoded'] == "testing");
- $this->assertTrue($result[0]['RecipientID'] == "Glue-Gammu-Provider");
+ $this->assertTrue($result[0]['RecipientID'] == "Glue_Gammu-SMSD");
$this->assertTrue($result[0]['Processed'] == "false");
Glue_GammuTestable::injectInboxItem($this->objGlueGammu, '+447777777777', 'testing 2');
$qry2 = $this->objDbGammu->prepare("SELECT * FROM inbox");
@@ -76,8 +76,105 @@ public function testProcessInbox()
$this->assertTrue(is_object($arrInput[1]));
$this->assertTrue($arrInput[1]->getKey('textMessage') == 'testing');
$this->assertTrue($arrInput[1]->getKey('strSender') == '+447777777777');
- $this->assertTrue($arrInput[1]->getKey('strInterface') == 'Gammu-private_Glue-Gammu-Provider');
+ $this->assertTrue($arrInput[1]->getKey('strInterface') == 'Glue_Gammu-SMSD');
}
+
+ public function testReplyToInbox()
+ {
+ $arrOutbox = Glue_GammuTestable::checkOutboxItem($this->objGlueGammu);
+ $this->assertTrue(count($arrOutbox) == 0);
+ Glue_GammuTestable::injectInboxItem($this->objGlueGammu, '+447777777777', 'testing');
+ $this->objGlueGammu->read_private();
+ $arrInput = Object_Input::brokerAll();
+ $this->assertTrue(count($arrInput) == 1);
+ $this->assertTrue(is_object($arrInput[1]));
+ Object_Output::replyToInput($arrInput[1], "Test Succeeded");
+ $system_state = Object_User::isSystem();
+ Object_User::isSystem(true);
+ $arrGlue = Glue_GammuTestable::brokerAllGlues();
+ foreach ($arrGlue as $objGlue) {
+ $objGlue->send();
+ }
+ Object_User::isSystem($system_state);
+ $arrOutbox2 = Glue_GammuTestable::checkOutboxItem($this->objGlueGammu);
+ $this->assertTrue(count($arrOutbox2) == 1);
+ $this->assertTrue($arrOutbox2[0]['DestinationNumber'] == "+447777777777");
+ $this->assertTrue($arrOutbox2[0]['TextDecoded'] == "Test Succeeded");
+ $this->assertTrue($arrOutbox2[0]['SenderID'] == "Glue_Gammu-SMSD");
+ }
+
+
+ public function testSendMessage()
+ {
+ $arrOutbox = Glue_GammuTestable::checkOutboxItem($this->objGlueGammu);
+ $this->assertTrue(count($arrOutbox) == 0);
+ $system_state = Object_User::isSystem();
+ Object_User::isSystem(true);
+ $arrGlue = Glue_GammuTestable::brokerAllGlues();
+ foreach ($arrGlue as $objGlue) {
+ $this->assertTrue($objGlue->getGlue() == "Glue_Gammu-SMSD");
+ $strInterface = $objGlue->canSendPrivateMessage();
+ if ($strInterface != false) {
+ $output = new Object_Output();
+ $output->setKey('textMessage', "Testing 123");
+ $output->setKey('strInterface', $strInterface);
+ $output->setKey('strReceiver', '+447777777777');
+ $output->create();
+ $objGlue->send();
+ }
+ }
+ Object_User::isSystem($system_state);
+ $arrOutbox2 = Glue_GammuTestable::checkOutboxItem($this->objGlueGammu);
+ $this->assertTrue(count($arrOutbox2) == 1);
+ $this->assertTrue($arrOutbox2[0]['DestinationNumber'] == "+447777777777");
+ $this->assertTrue($arrOutbox2[0]['TextDecoded'] == "Testing 123");
+ $this->assertTrue($arrOutbox2[0]['SenderID'] == "Glue_Gammu-SMSD");
+ }
+
+ public function testSendLongerMessage()
+ {
+ $arrOutbox = Glue_GammuTestable::checkOutboxItem($this->objGlueGammu);
+ $this->assertTrue(count($arrOutbox) == 0);
+ $system_state = Object_User::isSystem();
+ Object_User::isSystem(true);
+ $arrGlue = Glue_GammuTestable::brokerAllGlues();
+ foreach ($arrGlue as $objGlue) {
+ $this->assertTrue($objGlue->getGlue() == "Glue_Gammu-SMSD");
+ $strInterface = $objGlue->canSendPrivateMessage();
+ if ($strInterface != false) {
+ $output = new Object_Output();
+ $output->setKey('textMessage', "123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."123456789012345678901234567890");
+ $output->setKey('strInterface', $strInterface);
+ $output->setKey('strReceiver', '+447777777777');
+ $output->create();
+ $objGlue->send();
+ }
+ }
+ Object_User::isSystem($system_state);
+
+ $arrOutbox2 = Glue_GammuTestable::checkOutboxItem($this->objGlueGammu);
+ $arrOutbox3 = Glue_GammuTestable::checkOutboxMultipart($this->objGlueGammu);
+ $this->assertTrue(count($arrOutbox2) == 1);
+ $this->assertTrue($arrOutbox2[0]['DestinationNumber'] == "+447777777777");
+ $this->assertTrue($arrOutbox2[0]['TextDecoded'] == "123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."123456789012345678901234567890"
+ ."1234567890");
+ $this->assertTrue($arrOutbox2[0]['SenderID'] == "Glue_Gammu-SMSD");
+ $this->assertTrue(substr($arrOutbox2[0]['UDH'], -4) === '2010');
+ $this->assertTrue(substr($arrOutbox2[0]['UDH'], 0, 10) === substr($arrOutbox3[0]['UDH'], 0, 10));
+ $this->assertTrue(substr($arrOutbox3[0]['UDH'], -4) === '2020');
+ $this->assertTrue($arrOutbox3[0]['TextDecoded'] == "12345678901234567890");
+ $this->assertTrue(substr($arrOutbox2[0]['UDH'], 0, 10) === substr($arrOutbox3[0]['UDH'], 0, 10));
+ }
+
}
class Glue_GammuTestable extends Glue_Gammu
@@ -109,10 +206,40 @@ public static function injectInboxItem(
}
$inject = $self->objDbGammu->prepare("INSERT INTO `inbox` (`UpdatedInDB`, `ReceivingDateTime`, `Text`, `SenderNumber`, `Coding`, `UDH`, `SMSCNumber`, `Class`, `TextDecoded`, `ID`, `RecipientID`, `Processed`) VALUES
(:datereceived, :dateinserted, '', :number, 'Default_No_Compression', '',
- '+447771234567', -1, :message, NULL, 'Glue-Gammu-Provider', :actioned)");
+ '+447771234567', -1, :message, NULL, 'Glue_Gammu-SMSD', :actioned)");
$inject->execute(array('datereceived' => $datereceived, 'dateinserted' => $dateinserted, 'number' => $number, 'message' => $message, 'actioned' => $actioned));
return $self;
}
+
+ /**
+ * Gets a collection of data from the Outbox storage
+ *
+ * @param Glue_Gammu $self
+ *
+ * @return array
+ */
+ public static function checkOutboxItem($self)
+ {
+ $read = $self->objDbGammu->prepare("SELECT * FROM `outbox`");
+ $read->execute();
+ $result = $read->fetchAll(PDO::FETCH_ASSOC);
+ return $result;
+ }
+
+ /**
+ * Gets a collection of data from the Outbox storage
+ *
+ * @param Glue_Gammu $self
+ *
+ * @return array
+ */
+ public static function checkOutboxMultipart($self)
+ {
+ $read = $self->objDbGammu->prepare("SELECT * FROM `outbox_multipart`");
+ $read->execute();
+ $result = $read->fetchAll(PDO::FETCH_ASSOC);
+ return $result;
+ }
/**
* Return the DB object
@@ -139,7 +266,7 @@ public static function initialize($path = '')
$path = dirname(__FILE__) . '/../../../config/unittest_gammu.sqlite';
}
$arrConfigValues = array();
- $arrConfigValues['GluePrefix'] = "Gammu";
+ $arrConfigValues['GluePrefix'] = "Glue_Gammu-SMSD";
$arrConfigValues['DBType'] = "sqlite";
$arrConfigValues['DBHost'] = $path;
if (file_exists($path)) {
@@ -214,7 +341,18 @@ public static function initialize($path = '')
Received INTEGER NOT NULL DEFAULT 0
);
");
- $self->objDbGammu->exec("INSERT INTO `phones` (`ID`, `UpdatedInDB`, `InsertIntoDB`, `TimeOut`, `Send`, `Receive`, `IMEI`, `Client`, `Battery`, `Signal`, `Sent`, `Received`) VALUES ('Glue-Gammu-Provider', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "', 'yes', 'yes', '123456789012345', 'Dummy Client String', 0, 100, 0, 5);");
+ $self->objDbGammu->exec("INSERT INTO `phones` (`ID`, `UpdatedInDB`, `InsertIntoDB`, `TimeOut`, `Send`, `Receive`, `IMEI`, `Client`, `Battery`, `Signal`, `Sent`, `Received`) VALUES ('Glue_Gammu-SMSD', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "', '" . date("Y-m-d H:i:s") . "', 'yes', 'yes', '123456789012345', 'Dummy Client String', 0, 100, 0, 5);");
return $self;
}
+
+ public static function brokerAllGlues($path = '') {
+ if ($path == '') {
+ $path = dirname(__FILE__) . '/../../../config/unittest_gammu.sqlite';
+ }
+ $arrConfigValues = array();
+ $arrConfigValues['GluePrefix'] = "Glue_Gammu-SMSD";
+ $arrConfigValues['DBType'] = "sqlite";
+ $arrConfigValues['DBHost'] = $path;
+ return array(new Glue_Gammu($arrConfigValues));
+ }
}
View
82 classes/Glue/Gammu.php
@@ -125,7 +125,44 @@ public function __construct($arrConfigValues = array())
|| ($DBType != 'sqlite' && $DBPass == null)
|| ($DBType != 'sqlite' && $DBBase == null)
) {
- throw new InvalidArgumentException("Insufficient detail to connect to Gammu Database");
+ $value = "\r\nDBType: $DBType (";
+ if ($DBType == null) {
+ $value .= "False";
+ } else {
+ $value .= "True";
+ }
+ $value .= ")\r\nDBHost: $DBHost (";
+ if ($DBHost == null) {
+ $value .= "False";
+ } else {
+ $value .= "True";
+ }
+ $value .= ")\r\nDBPort: $DBPort (";
+ if ($DBPort == null) {
+ $value .= "False";
+ } else {
+ $value .= "True";
+ }
+ $value .= ")\r\nDBUser: $DBUser (";
+ if ($DBUser == null) {
+ $value .= "False";
+ } else {
+ $value .= "True";
+ }
+ $value .= ")\r\nDBPass: $DBPass (";
+ if ($DBPass == null) {
+ $value .= "False";
+ } else {
+ $value .= "True";
+ }
+ $value .= ")\r\nDBBase: $DBBase (";
+ if ($DBBase == null) {
+ $value .= "False";
+ } else {
+ $value .= "True";
+ }
+ $value .= ")";
+ throw new InvalidArgumentException("Insufficient detail to connect to Gammu Database : $value");
}
$this->strInterface = $GluePrefix;
@@ -209,11 +246,10 @@ public function read_private()
foreach($UDH[$uniq] as $textPart) {
$text .= $textPart;
}
- $strInterface = $this->strInterface . '-private_' . $message['RecipientID'];
$strSender = $message['SenderNumber'];
$textMessage = $text;
$intNativeID = $message['ID'];
- Object_Input::import($strSender, $strInterface, $textMessage, $intNativeID);
+ Object_Input::import($strSender, $this->strInterface, $textMessage, $intNativeID);
$sqlUpdateInbox = "UPDATE inbox SET processed = 'true' WHERE UDH = ?";
$qryUpdateInbox = $this->objDbGammu->prepare($sqlUpdateInbox);
$qryUpdateInbox->execute(array('050003' . $uniq . '%'));
@@ -227,11 +263,10 @@ public function read_private()
$this->objDaemon->setKey('intUniqueCounter', $this->objDaemon->getKey('intUniqueCounter') + 1);
}
- $strInterface = $this->strInterface . '-private_' . $message['RecipientID'];
$strSender = $message['SenderNumber'];
$textMessage = $message['TextDecoded'];
$intNativeID = $message['ID'];
- Object_Input::import($strSender, $strInterface, $textMessage, $intNativeID);
+ Object_Input::import($strSender, $this->strInterface, $textMessage, $intNativeID);
$sqlUpdateInbox = "UPDATE inbox SET processed = 'true' WHERE ID = ?";
$qryUpdateInbox = $this->objDbGammu->prepare($sqlUpdateInbox);
$qryUpdateInbox->execute(array($message['ID']));
@@ -286,12 +321,10 @@ public function send()
. '(:SequencePosition, :UDH, :TextDecoded, :ID, :Coding);';
$qryInsertLarge = $this->objDbGammu->prepare($sqlInsertLarge);
- $messages = Object_Output::brokerByColumnSearch('isActioned', 0);
+ $messages = Object_Output::brokerByColumnSearch('isActioned', false);
foreach ($messages as $message) {
- if (preg_match('/^([^-]+)/', $message->getKey('strInterface'), $matches) == 1) {
- if ($matches[1] != $this->strInterface) {
- continue;
- }
+ if ($message->getKey('strInterface') != $this->strInterface) {
+ continue;
}
if ($message->getKey('strReceiver') == null || $message->getKey('strReceiver') == '') {
$message->setKey('strError', 'No recipient');
@@ -303,10 +336,10 @@ public function send()
// Reset the insert data
$data = array(
'CreatorID' => 'CFM2',
- 'MultiPart' => null,
+ 'MultiPart' => false,
'DestinationNumber' => $message->getKey('strReceiver'),
'UDH' => null,
- 'TextDecoded' => null,
+ 'TextDecoded' => '',
'Coding' => 'Default_No_Compression',
'SenderID' => null
);
@@ -319,11 +352,12 @@ public function send()
// know which is which... which is where the SenderID comes into
// play.
- if (preg_match('/^([^-]+)-([^_]+)_(.*)$/', $message->getKey('strInterface'), $matches) == 1) {
+ if (preg_match('/^Glue_Gammu-([^_]+)$/', $message->getKey('strInterface'), $matches) == 1) {
$data['CreatorID'] .= '_' . $matches[1];
- $data['SenderID'] = $matches[3];
- } elseif (preg_match('/^([^-]+)$/', $message->getKey('strInterface'), $matches) == 1) {
+ $data['SenderID'] = 'Glue_Gammu-' . $matches[1];
+ } elseif (preg_match('/^Glue_Gammu-([^_]+)_(.*)$/', $message->getKey('strInterface'), $matches) == 1) {
$data['CreatorID'] .= '_' . $matches[1];
+ $data['SenderID'] = 'Glue_Gammu-' . $matches[1];
}
// So, now we've got our defaults set up - let's check whether this
@@ -333,19 +367,23 @@ public function send()
$data['TextDecoded'] = $message->getKey('textMessage');
$qryInsert->execute($data);
} else {
+ $uniq = str_pad(dechex(rand(0, 255)), 2, "0");
+ $size = str_pad(dechex(count($arrMessageChunks)), 2, "0");
foreach ($arrMessageChunks as $intChunkID => $strChunk) {
$intChunkID++;
- $uniq = str_pad(dechex(rand(0, 255)), 2, "0");
- $size = str_pad(dechex(count($arrMessageChunks)), 2, "0");
$mNum = str_pad(dechex($intChunkID), 2, "0");
$data['UDH'] = '050003' . $uniq . $size . $mNum;
- $data['TextDecoded'] = $strChunk;
if ($intChunkID == 1) {
+ $data['TextDecoded'] = $strChunk;
$qryInsert->execute($data);
- $data['ID'] = $this->objDbGammu->lastInsertId();
+ $LargeData['ID'] = $this->objDbGammu->lastInsertId();
} else {
- $data['SequencePosition'] = $intChunkID;
- $qryInsertLarge->execute($data);
+ //(:SequencePosition, :UDH, :TextDecoded, :ID, :Coding)
+ $LargeData['UDH'] = $data['UDH'];
+ $LargeData['SequencePosition'] = $intChunkID;
+ $LargeData['TextDecoded'] = $strChunk;
+ $LargeData['Coding'] = $data['Coding'];
+ $qryInsertLarge->execute($LargeData);
}
}
}
@@ -355,7 +393,7 @@ public function send()
$this->objDaemon->setKey('lastUsedSuccessfully', date('Y-m-d H:i:s'));
$this->objDaemon->write();
} catch (Exception $e) {
- error_log('Error moving data from CFM2 Outbox to Gammu Outbox: ' . $e->getMessage());
+ error_log('Error moving data from CFM2 Outbox to Gammu Outbox at ' . $e->getLine() . ': ' . $e->getMessage());
}
}
}
View
2  classes/Plugin/GlueBroadcaster/hook_loader.php
@@ -15,7 +15,7 @@
/**
* This plugin is used to broadcast to twitter when talks are about to start.
*
- * @category Plugin_Twitter
+ * @category Plugin_GlueBroadcaster
* @package CampFireManager2
* @author Jon Spriggs <jon@sprig.gs>
* @license http://www.gnu.org/licenses/agpl.html AGPLv3
Something went wrong with that request. Please try again.