Re: [patch] opensmppbox validiti periode passtrought fix

Alexander Malysh <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
commited to repository...

Thanks,
Alexander Malysh

Am 27.10.2010 um 16:52 schrieb XEN-Housing s.r.o.:

> Thank you Alex.
> 
> implemented and new patch with validity_periode and schedule_delivery_time attached.
> 
> Slavoj.
> 
> Dňa 27. 10. 2010 15:04, Alexander Malysh wrote / napísal(a):
>> Hi,
>> 
>> your code doesn't handle relation and relative in the timestamp. Below is function that I use for this, then just write:
>> 
>>     if (pdu->u.submit_sm.validity_period)
>>         msg->sms.validity = timestamp_to_minutes(pdu->u.submit_sm.validity_period);
>> 
>> ditto fo deferred...
>> 
>> Alex
>> 
>> 
>> /*
>>  * Converting SMPP timestamp to minutes relative
>>  * to our localtime.
>>  * Return -1 if error detected
>> */
>> static int timestamp_to_minutes(Octstr *timestamp)
>> {
>>     struct tm tm, local;
>>     time_t valutc, utc;
>>     int rc, diff, dummy, localdiff;
>>     char relation;
>> 
>>     if (octstr_len(timestamp) == 0)
>>         return 0;
>> 
>>     if (octstr_len(timestamp) != 16)
>>         return -1;
>> 
>>     /*
>>     * Timestamp format:
>>     * YYMMDDhhmmsstnn[+-R]
>>     * t - tenths of second (not used by us)
>>     * nn - Time difference in quarter hours between local and UTC time
>>     */
>>     rc = sscanf(octstr_get_cstr(timestamp),
>>             "%02d%02d%02d%02d%02d%02d%1d%02d%1c",
>>             &tm.tm_year,&tm.tm_mon,&tm.tm_mday,
>>             &tm.tm_hour,&tm.tm_min,&tm.tm_sec,
>>             &dummy,&diff,&relation);
>>     if (rc != 9)
>>        return -1;
>> 
>>     utc = time(NULL);
>>     if (utc == ((time_t)-1))
>>         return 0;
>> 
>>     if (relation == '+' || relation == '-') {
>>         tm.tm_year += 100; /* number of years since 1900 */
>>         tm.tm_mon--; /* month 0-11 */
>>         tm.tm_isdst = -1;
>>         /* convert to sec. since 1970 */
>>         valutc = gw_mktime(&tm);
>>         if (valutc == ((time_t)-1))
>>             return -1;
>> 
>>         /* work out local time, because gw_mktime assume local time */
>>         local = gw_localtime(utc);
>>         tm = gw_gmtime(utc);
>>         local.tm_isdst = tm.tm_isdst = -1;
>>         localdiff = difftime(gw_mktime(&local), gw_mktime(&tm));
>>         valutc += localdiff;
>> 
>>         debug("sms.smpp",0, "diff between utc and localtime (%d)", localdiff);
>>         diff = diff*15*60;
>>         switch(relation) {
>>             case '+':
>>                 valutc -= diff;
>>                 break;
>>             case '-':
>>                 valutc += diff;
>>                 break;
>>         }
>>     } else if (relation == 'R') { /* relative to SMSC localtime */
>>         local = gw_localtime(utc);
>>         local.tm_year += tm.tm_year;
>>         local.tm_mon += tm.tm_mon;
>>         local.tm_mday += tm.tm_mday;
>>         local.tm_hour += tm.tm_hour;
>>         local.tm_min += tm.tm_min;
>>         local.tm_sec += tm.tm_sec;
>>         valutc = gw_mktime(&local);
>>         if (valutc == ((time_t)-1))
>>            return -1;
>>     } else {
>>         return -1;
>>     }
>>     tm = gw_gmtime(valutc);
>>     debug("sms.smpp",0,"Requested UTC timestamp: %02d-%02d-%02d %02d:%02d:%02d",
>>             tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
>> 
>>     debug("sms.smpp", 0, "requested timestamp in min. (%ld)", (valutc - utc)/60);
>> 
>>     return ceil(difftime(valutc, utc) / 60);
>> }
>> 
>> 
>> Am 27.10.2010 um 14:04 schrieb XEN-Housing s.r.o.:
>> 
>>> Hello folks,
>>> 
>>> at opensmppbox i found that it not support validity periode handling when from pdu makes msg for bb.
>>> 
>>> attached patch solve that. i am not well C++ coder, so please make an review, if there are no left some memory leaks. or may be there is an nicer way to make it.
>>> 
>>> But it's tested and working ;)
>>> 
>>> PS: acording this, deffered parameter have same problem, is not passing trought. and handling of DLR need some improvement too, coz from smsc i will get EXPIRED msg, but opensmpp client is sending UNDELIV with err:000. I will try to prepare next patches to handle it, but if someone is working on it, it would be twice made ;)
>>> 
>>> Slavoj.
>>> 
>>> <validity_period.diff>
> 
> <validity_period2.diff>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.