Author |
Post |
|
#1 Wed May 11, 2016 19:55, 101 months ago.
|
Member
Registered: Mar 2016
Location: Voronezh, Russian Federation
|
Operating system name and version: Centos 7 x86_64 Version of smsd: 3.1.15 Smsd installed from: sources Name and model of a modem / phone: MTS 423s (Huawei E3531s) Interface: USB
How to run eventhander after every part of long multipart message is sent? Now it is executed after last part is sent.
|
|
#2 Fri May 13, 2016 15:07, 101 months ago.
|
Administrator
Registered: May 2009
Location: Jyväskylä, Finland
|
Why do you need that? Smsd does not run eventhandler because there is no message file for each part. The 3.1.16 is coming, and I have to think if some enhancement can be done. But there must be a good reason for it. ![;)](./templates/default/smilies/wink.gif) Currently you could create multiple message files, one file for each part, with proper User Data Header and taking care of length of each part by yourself. This is slightly complicated, but works. See UDH.
|
|
#3 Fri May 13, 2016 21:07, 101 months ago.
|
Member
Registered: Mar 2016
Location: Voronezh, Russian Federation
Topic owner
|
I have thought about UDH too, I'll try to write here my sample code about it if I can win it, maybe somebody needs it.
|
|
#4 Tue May 24, 2016 09:06, 100 months ago.
|
Member
Registered: Mar 2016
Location: Voronezh, Russian Federation
Topic owner
|
Keke, i made multipart processing on php, but have no time to beautify sample source and put it here. Maybe in couple of days , i'll try.
|
|
#5 Wed Jun 08, 2016 15:31, 100 months ago.
|
Member
Registered: Mar 2016
Location: Voronezh, Russian Federation
Topic owner
|
Hello, as promised - here is code part for handle multipart messages and get delivery report for each part in /var/spool/sms/reports. Maybe somebody finds it useful. //input data: //mysql table sms_turn contains sms message with record id ("id_turn" field), phone and body. //mysql table sms_state_final contains splitted sms message (split algoritm is made on 3rd party, not here): 1 part = 1 record //records here are linked thru id: sms_turn.id_turn links to sms_state_final.id_sms //$spoolpath is set to /var/spool/sms/queue //directory /var/spool/sms/queue contains dirs GSM1 GSM2 GSM3... - the same as modem names in smsd.conf //(c) Dmitry L, Alexander Sh.
//sms-file template: //To: +79092345555 //Modem: GSM2 //UDH: true //UDH-DATA: 05 00 03 5F 02 01 //IMSI: 250202101644965
//Menya zovut E-Type! Na zdorovye!!!
//main program started
function RandomString() { //sms-filename generator $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randstring = ''; for ($i = 0; $i < 20; $i++) { $randstring = $randstring . $characters[rand(0, strlen($characters) - 1)]; } return $randstring; } //!sms-filename generator
//for multi-modem station you need to write sub-routine here which chooses modem for sending. //Pay attention, that if you have multipart message - all parts must go thru the same modem. //as a result, $selectedroute must have value with modem name from smsd.conf
echo " Modem chosen:" . $selectedroute . "\n";
echo "Found " . $partscount . " parts of message with id_turn=" . $currentsmsid . "\n"; //sms-file forming 1 $ipart = 1; $udhstringwspaces = "";
// we decided not to set MSG indicator more than FF, because len of UDH must be 5, not more (for russian operators) //so 1 multi-part sms must have the same ID (4th byte in UDH header) as all its children parts $udhpartid = strtoupper(dechex(rand(1, 255)));
while ($row = $resultpc->fetch_assoc()) { //ipart if ($partscount > 1) { $filename = $queuerootpath . "/" . $selectedroute . "/" . RandomString(); } else { //Hindussian code on $filename = $spoolpath . "/" . RandomString(); $filename = $queuerootpath . "/" . $selectedroute . "/" . RandomString(); //Hindussian code off } echo " Writing sms-file" . $filename . " for record with id_state=" . $row["id_state"] . "\n"; echo " Modem chosen:" . $selectedroute . "\n"; $fp = fopen($filename, "wt"); fwrite($fp, "To: +" . $currentphone . "\n"); fwrite($fp, "Report: yes\n"); fwrite($fp, "X-turn-msgid: " . $currentsmsid . "\n"); fwrite($fp, "X-state-partid: " . $row["id_state"] . "\n"); if ($partscount > 1) { //do not put UDH if we process 1-segment (not multisegment) sms echo " As it is multi-segment sms - we put UDH.\n"; fwrite($fp, "UDH: true\n"); //UDH forming //UDH forming //$udhpartid=strtoupper(dechex($row["id_sms"])); $udhpartscount = strtoupper(dechex($partscount)); $udhipart = strtoupper(dechex($row["part_no"])); if ((strlen($udhpartid) % 2 != 0) || (strlen($udhpartid) == 1)) { $udhpartid = '0' . $udhpartid; } if ((strlen($udhpartscount) % 2 != 0) || (strlen($udhpartscount) == 1)) { $udhpartscount = '0' . $udhpartscount; } if ((strlen($udhipart) % 2 != 0) || (strlen($udhipart) == 1)) { $udhipart = '0' . $udhipart; } $len2 = dechex(intval(strlen($udhpartid . $udhpartscount . $udhipart) / 2)); if ((strlen($len2) % 2 != 0) || (strlen($len2) == 1)) { $len2 = '0' . $len2; } $lentot = dechex(intval(strlen("00" . $len2 . $udhpartid . $udhpartscount . $udhipart) / 2)); if ((strlen($lentot) % 2 != 0) || (strlen($lentot) == 1)) { $lentot = '0' . $lentot; } $udhstring = $lentot . "00" . $len2 . $udhpartid . $udhpartscount . $udhipart; echo " Unformatted UDH string is " . $udhstring; for ($i2 = 0; $i2 < strlen($udhstring); $i2++) { //formatting UDH with spaces $udhstringwspaces = $udhstringwspaces . $udhstring[$i2]; if (($i2 + 1) % 2 == 0) { $udhstringwspaces = $udhstringwspaces . " "; } } //!formatting UDH with spaces, needed practically echo ", or human-readable " . $udhstringwspaces . "\n"; fwrite($fp, "UDH-DATA: " . $udhstringwspaces . "\n"); //!UDH forming //!UDH forming } //for non-latin sms, you have to write routine which finds out encoding and puts in into sms-file //for example, you can use standard php mb_detect_encoding() function //as a result, you must have in $msgenc variable a value of obtained encoding, UCS or Latin
echo " Writing into SMS file header Alphabet: " . $msgenc . "\n"; fwrite($fp, "Alphabet: " . $msgenc . "\n\n");
//write encoded in appropriate encoding text into sms-file fwrite($fp, $text); //!write encoded in appropriate encoding text into sms-file
if (!fclose($fp)) { echo "!!! ERROR during save sms-file, exiting"; exit; } $ipart++; $udhstringwspaces = ""; } //while ipart //! sms-file forming } //of WHILE of Processing 1 line from array echo "Done genetaring sms-files.\n"; //don't forget to clear all file and query handles and close all unused connctions //main program stops 'php' Syntax Highlight powered by GeSHi
|