SMS Server Tools 3
This site is hosted by Kekekasvi.com
 Menu
Basic information:
Additional information:
Support:
Get SMS Server Tools 3:
Additional Options

 Sponsored links

 Search
Custom Search

 Visitor locations
 
 SMS Server Tools 3 Community
Welcome, Guest. Please login or register. Thu Apr 18, 2024 19:21
SMSTools3 Community » Feature requests Bottom

accept timezone in PDU

Login and Post Reply

Page:  1

Author Post
Member
Registered:
Jun 2009
Location: Moscow, Russian Federation
This patch (to 3.1.14) apply timezone from PDU, e.g. 'Received' filed in sms-header convert to localtime and user rec3eived the sms will see non-abstract ;) time in this field

-----cut---
--- src/pdu.c.orig      2010-09-07 17:42:05.000000000 +0400
+++ src/pdu.c   2011-06-09 07:03:25.000000000 +0400
@@ -1021,6 +1021,67 @@
   snprintf(dest, size_dest, "%s", p);
 }
 
+// Subroutine for convert SMSC timestamp
+char* get_timestamp(char* date, char* time, char** err_str, char* warning_headers,
+                    char* Src_Pointer, char* full_pdu, const char* dia)
+{
+  sprintf(date,"%c%c-%c%c-%c%c",Src_Pointer[1],Src_Pointer[0],Src_Pointer[3],Src_Pointer[2],Src_Pointer[5],Src_Pointer[4]);
+  if (!isdigitc(date[0]) || !isdigitc(date[1]) || !isdigitc(date[3]) || !isdigitc(date[4]) || !isdigitc(date[6]) || !isdigitc(date[7]))
+  {
+    pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid character(s) in date of %s Timestamp: \"%s\"", dia, date);
+    *date = 0;
+  }
+  else if ((unsigned)(atoi(date +3) -1) > (12 -1) || atoi(date +6) > 31)
+  {
+    // Not a fatal error (?)
+    //pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid value(s) in date of %s Timestamp: \"%s\"", dia, date);
+    // *date = 0;
+    add_warning(warning_headers, "Invalid value(s) in date of %s Timestamp.", dia);
+  }
+
+  Src_Pointer += 6;
+  sprintf(time,"%c%c:%c%c:%c%c",Src_Pointer[1],Src_Pointer[0],Src_Pointer[3],Src_Pointer[2],Src_Pointer[5],Src_Pointer[4]);
+  if (!isdigitc(time[0]) || !isdigitc(time[1]) || !isdigitc(time[3]) || !isdigitc(time[4]) || !isdigitc(time[6]) || !isdigitc(time[7]))
+  {
+    pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid character(s) in time of %s Timestamp: \"%s\"", dia, time);
+    *time = 0;
+  }
+  else if (atoi(time) > 23 || atoi(time +3) > 59 || atoi(time +6) > 59)
+  {
+    // Not a fatal error (?)
+    //pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid value(s) in time of %s Timestamp: \"%s\"", dia, time);
+    // *time = 0;
+    add_warning(warning_headers, "Invalid value(s) in time of %s Timestamp.", dia);
+  }
+
+  if (!(*err_str))
+  {
+    char tz[3];
+    Src_Pointer += 6;
+    // Time zone
+    sprintf(tz, "%c%c", Src_Pointer[1] & ~8, Src_Pointer[0]);
+    if (!isdigitc(tz[0]) || !isdigitc(tz[1]))
+    {
+      pdu_error(err_str, 0, Src_Pointer -full_pdu, 2,
+                "Invalid character(s) in Time Zone of %s Timestamp: \"%.2s\"", dia, Src_Pointer);
+    }
+    else
+    {
+      int dt, sign = (Src_Pointer[1] & 8) ? -1 : 1;
+      if((dt = atoi(tz)) > 12*60*60/4 || (!dt && sign))
+      {
+        // Not a fatal error (?)
+        //pdu_error(err_str, 0, Src_Pointer -full_pdu, 2, "Invalid value in Time Zone of %s Timestamp: \"%s\"", dia, time);
+        add_warning(warning_headers, "Invalid value in Time Zone of %s Timestamp: %c%u:%u", dia, sign > 0 ? '+' : '-', dt/4, (dt%4)*60);
+      }
+      smsctime2localtime(date, time, dt*sign*(60/4)*60);
+      Src_Pointer += 2;
+    }
+  }
+  return Src_Pointer;
+}
+
+
 // Subroutine for messages type 0 (SMS-Deliver)
 // Input:
 // Src_Pointer points to the PDU string
@@ -1166,45 +1227,8 @@
             if (!(*err_str))
             {
               Src_Pointer += 2;
-              sprintf(date,"%c%c-%c%c-%c%c",Src_Pointer[1],Src_Pointer[0],Src_Pointer[3],Src_Pointer[2],Src_Pointer[5],Src_Pointer[4]);
-              if (!isdigitc(date[0]) || !isdigitc(date[1]) || !isdigitc(date[3]) || !isdigitc(date[4]) || !isdigitc(date[6]) || !isdigitc(date[7]))
-              {
-                pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid character(s) in date of Service Centre Time Stamp: \"%s\"", date);
-                *date = 0;
-              }
-              else if (atoi(date +3) > 12 || atoi(date +6) > 31)
-              {
-                // Not a fatal error (?)
-                //pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid value(s) in date of Service Centre Time Stamp: \"%s\"", date);
-                // *date = 0;
-                add_warning(warning_headers, "Invalid values(s) in date of Service Centre Time Stamp.");
-              }
-
-              Src_Pointer += 6;
-              sprintf(time,"%c%c:%c%c:%c%c",Src_Pointer[1],Src_Pointer[0],Src_Pointer[3],Src_Pointer[2],Src_Pointer[5],Src_Pointer[4]);
-              if (!isdigitc(time[0]) || !isdigitc(time[1]) || !isdigitc(time[3]) || !isdigitc(time[4]) || !isdigitc(time[6]) || !isdigitc(time[7]))
-              {
-                pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid character(s) in time of Service Centre Time Stamp: \"%s\"", time);
-                *time = 0;
-              }
-              else if (atoi(time) > 23 || atoi(time +3) > 59 || atoi(time +6) > 59)
-              {
-                // Not a fatal error (?)
-                //pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid value(s) in time of Service Centre Time Stamp: \"%s\"", time);
-                // *time = 0;
-                add_warning(warning_headers, "Invalid values(s) in time of Service Centre Time Stamp.");
-              }
-
-              if (!(*err_str))
-              {
-                Src_Pointer += 6;
-                // Time zone is not used but bytes are checked:
-                if (octet2bin_check(Src_Pointer) < 0)
-                  pdu_error(err_str, 0, Src_Pointer -full_pdu, 2,
-                            "Invalid character(s) in Time Zone of Service Centre Time Stamp: \"%.2s\"", Src_Pointer);
-                else
-                  Src_Pointer += 2;
-              }
+              Src_Pointer = get_timestamp(date, time, err_str, warning_headers,
+                                          Src_Pointer, full_pdu, "Service Centre");
             }
           }
         }
@@ -1254,7 +1278,7 @@
   int Length;
   int padding;
   int status;
-  char temp[32];
+  char temp_date[9], temp_time[9];
   char tmpsender[100];
   int messageid;
   int i;
@@ -1352,48 +1376,8 @@
             if (strlen(Src_Pointer) < 14)
               pdu_error(err_str, 0, Src_Pointer -full_pdu, 14, "While trying to read SMSC Timestamp: %s", err_too_short);
             else
-            {
-              // get SMSC timestamp
-              sprintf(date,"%c%c-%c%c-%c%c",Src_Pointer[1],Src_Pointer[0],Src_Pointer[3],Src_Pointer[2],Src_Pointer[5],Src_Pointer[4]);
-              if (!isdigitc(date[0]) || !isdigitc(date[1]) || !isdigitc(date[3]) || !isdigitc(date[4]) || !isdigitc(date[6]) || !isdigitc(date[7]))
-              {
-                pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid character(s) in date of SMSC Timestamp: \"%s\"", date);
-                *date = 0;
-              }
-              else if (atoi(date +3) > 12 || atoi(date +6) > 31)
-              {
-                // Not a fatal error (?)
-                //pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid value(s) in date of SMSC Timestamp: \"%s\"", date);
-                // *date = 0;
-                add_warning(warning_headers, "Invalid value(s) in date of SMSC Timestamp.");
-              }
-
-              Src_Pointer += 6;
-              sprintf(time,"%c%c:%c%c:%c%c",Src_Pointer[1],Src_Pointer[0],Src_Pointer[3],Src_Pointer[2],Src_Pointer[5],Src_Pointer[4]);
-              if (!isdigitc(time[0]) || !isdigitc(time[1]) || !isdigitc(time[3]) || !isdigitc(time[4]) || !isdigitc(time[6]) || !isdigitc(time[7]))
-              {
-                pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid character(s) in time of SMSC Timestamp: \"%s\"", time);
-                *time = 0;
-              }
-              else if (atoi(time) > 23 || atoi(time +3) > 59 || atoi(time +6) > 59)
-              {
-                // Not a fatal error (?)
-                //pdu_error(err_str, 0, Src_Pointer -full_pdu, 6, "Invalid value(s) in time of SMSC Timestamp: \"%s\"", time);
-                // *time = 0;
-                add_warning(warning_headers, "Invalid value(s) in time of SMSC Timestamp.");
-              }
-
-              if (!(*err_str))
-              {
-                Src_Pointer += 6;
-                // Time zone is not used but bytes are checked:
-                if (octet2bin_check(Src_Pointer) < 0)
-                  pdu_error(err_str, 0, Src_Pointer -full_pdu, 2,
-                            "Invalid character(s) in Time Zone of SMSC Time Stamp: \"%.2s\"", Src_Pointer);
-                else
-                  Src_Pointer += 2;
-              }
-            }
+              Src_Pointer = get_timestamp(date, time, err_str, warning_headers,
+                                          Src_Pointer, full_pdu, "SMSC");
           }
 
           if (!(*err_str))
@@ -1401,34 +1385,17 @@
             if (strlen(Src_Pointer) < 14)
               pdu_error(err_str, 0, Src_Pointer -full_pdu, 14, "While trying to read Discharge Timestamp: %s", err_too_short);
             else
-            {
-              // get Discharge timestamp
-              sprintf(temp,"%c%c-%c%c-%c%c %c%c:%c%c:%c%c",Src_Pointer[1],Src_Pointer[0],Src_Pointer[3],Src_Pointer[2],Src_Pointer[5],Src_Pointer[4],Src_Pointer[7],Src_Pointer[6],Src_Pointer[9],Src_Pointer[8],Src_Pointer[11],Src_Pointer[10]);
-              if (!isdigitc(temp[0]) || !isdigitc(temp[1]) || !isdigitc(temp[3]) || !isdigitc(temp[4]) || !isdigitc(temp[6]) || !isdigitc(temp[7]) ||
-                  !isdigitc(temp[9]) || !isdigitc(temp[10]) || !isdigitc(temp[12]) || !isdigitc(temp[13]) || !isdigitc(temp[15]) || !isdigitc(temp[16]))
-                pdu_error(err_str, 0, Src_Pointer -full_pdu, 12, "Invalid character(s) in Discharge Timestamp: \"%s\"", temp);
-              else if (atoi(temp +3) > 12 || atoi(temp +6) > 31 || atoi(temp +9) > 24 || atoi(temp +12) > 59 || atoi(temp +16) > 59)
-              {
-                // Not a fatal error (?)
-                //pdu_error(err_str, 0, Src_Pointer -full_pdu, 12, "Invalid value(s) in Discharge Timestamp: \"%s\"", temp);
-                add_warning(warning_headers, "Invalid values(s) in Discharge Timestamp.");
-              }
-
-              if (!(*err_str))
-              {
-                Src_Pointer += 12;
-                // Time zone is not used but bytes are checked:
-                if (octet2bin_check(Src_Pointer) < 0)
-                  pdu_error(err_str, 0, Src_Pointer -full_pdu, 2,
-                            "Invalid character(s) in Time Zone of Discharge Time Stamp: \"%.2s\"", Src_Pointer);
-                else
-                  Src_Pointer += 2;
-              }
-            }
+              Src_Pointer = get_timestamp(temp_date, temp_time, err_str, warning_headers,
+                                          Src_Pointer, full_pdu, "Discharge");
 
             if (!(*err_str))
             {
-              sprintf(strchr(result, 0), "Discharge_timestamp: %s", temp);
+              strcat(result, "Discharge_timestamp: ");
+              {
+                char* pe = strchr(result, 0);
+                size_t len = pe - result;
+                make_datetime_string(pe, MAXTEXT - len, temp_date, temp_time, 0);
+              }
               if (strlen(Src_Pointer) < 2)
                 pdu_error(err_str, 0, Src_Pointer -full_pdu, 2, "While trying to read Status octet: %s", err_too_short);
               else
--- src/extras.h.orig   2010-09-11 15:21:25.000000000 +0400
+++ src/extras.h        2011-06-09 03:46:58.000000000 +0400
@@ -99,4 +99,6 @@
 
 void getfield(char* line, int field, char* result, int size);
 
+void smsctime2localtime(char* date, char* Time, int gmtoff);
+
 #endif
--- src/extras.c.orig   2010-09-21 13:15:45.000000000 +0400
+++ src/extras.c        2011-06-09 07:06:18.000000000 +0400
@@ -12,6 +12,7 @@
 the GNU General Public License as published by the Free Software Foundation.
 Either version 2 of the License, or (at your option) any later version.
 */
+#define _BSD_SOURCE
 
 #include <sys/time.h>
 #include <sys/types.h>
@@ -1593,3 +1594,28 @@
   printf("!! result=%s\n",result);
 #endif    
 }
+
+void smsctime2localtime(char* date, char* Time, int gmtoff)
+{
+  struct tm ti;
+  time_t    rc;
+
+  memset(&ti, 0, sizeof(ti));
+  ti.tm_year = atoi(date) + 100;
+  ti.tm_mon = atoi(date +3) - 1;
+  ti.tm_mday = atoi(date +6);
+  ti.tm_hour = atoi(Time);
+  ti.tm_min = atoi(Time +3);
+  ti.tm_sec = atoi(Time + 6);
+  rc = timegm(&ti);
+  if (rc != (time_t)-1)
+  {
+    rc -= gmtoff;
+    if (localtime_r(&rc, &ti))
+    {
+      sprintf(date, "%02u-%02u-%02u", ti.tm_year -100, ti.tm_mon +1, ti.tm_mday);
+      sprintf(Time, "%02u:%02u:%02u", ti.tm_hour, ti.tm_min, ti.tm_sec);
+    }
+  }
+}
+
-----end---
 
 
'diff' Syntax Highlight powered by GeSHi


If You will this patch must be added with 'config-enabled' options


« Last edit by keke on Fri May 01, 2020 00:19, 48 months ago. »
Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
Thanks for the patch. I likely will include it in the next release.

In the past there was some issues with time zone of SMSC, and therefore it was just checked but not handled. I do not remember for sure what was the issue, but probably some service centers provided incorrect values. Because of this, handling of time zone could be configurable, as you suggested.

You have used #define _BSD_SOURCE, why is that and is it mandatory? With googling I found that "If your program defines _BSD_SOURCE, you must give the option `-lbsd-compat' to the compiler or linker when linking the program, to tell it to find functions in this special compatibility library before looking for them in the normal C library. "

Is it sure that this definition has no any affect to previously used functions, and does this work on all environments where smsd can be compiled and run, including any Unix / any Linux and Cygwin and some rare platforms which I cannot name?

Member
Registered:
Apr 2020
Location: Aveiro, Portugal
Hi Keke,

Has this patch ever been applied?
If it did, in what version?

I'm trying to sort out some sent timestamp issues...

Thanks.

Administrator
Registered:
May 2009
Location: Jyväskylä, Finland
I think that the patch was never applied, but I cannot check it right now.

I moved the patch to public from the private block, so you can see if it will help with your issues. You also could describe what kind the issue is.

Login and Post Reply

Page:  1

SMSTools3 Community » Feature requests Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.