SMS Server Tools 3
 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. The forum is currently read-only, but will open soon. Fri Mar 14, 2025 10:44
SMSTools3 Community » Search Bottom

Page:  1

Keywords:
Mode: All keywords (AND)
yjh: 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--- If You will this patch must be added with 'config-enabled' options
yjh: That was promised :). There are changed patch for 'ps': the your old code is working if USE_LINUX_PS_TRICK is not defined in makefile. diff -Pur base/smsd.c src/smsd.c --- base/smsd.c 2009-06-25 00:30:18.000000000 +0400 +++ src2/smsd.c 2009-06-29 07:21:01.000000000 +0400 @@ -5797,10 +5797,12 @@ if (!(*communicate) && keep_messages) writelogfile(LOG_CRIT, 0, "This is a test run: messages are kept and smsd will stop after reading."); +#ifdef USE_LINUX_PS_TRICK // Make readable process name for(i = 0; i < argc; i++) memset(argv, 0, strlen(argv)); strcpy(argv[0], "smsd: MAINPROCESS"); +#endif // Start sub-processes for each modem for (i = 0; i < NUMBER_OF_MODEMS; i++) @@ -5818,8 +5820,29 @@ if (pid == 0) { // 3.1.4: +#ifndef USE_LINUX_PS_TRICK + int idx; + + for (idx = 0; idx < argc; idx++) + { + if (strncmp(argv[idx], "MAINPROCESS", 11) == 0) + { + size_t l = strlen(devices.name); + + if (l > strlen(argv[idx])) + l = strlen(argv[idx]); + + strncpy(argv[idx], devices.name, l); + while (argv[idx][l]) + argv[idx][l++] = '_'; + + break; + } + } +#else memset(argv[0] + sizeof("smsd: ")-1, 0, sizeof("MAINPROCESS")-1); strcpy(argv[0] + sizeof("smsd: ")-1, devices.name); +#endif // ------ time(&process_start_time); ----------------------------- Next is ucs2<=>utf8 converter. All changes are under #ifdef USE_ICONV (i.e. if is is not defined in makefile all work in old manner). If USE_ICONV is defined than "logical changes" are: 1. If define Alphabet: UTF-8 in output file, than: 1.1. If message contains only ASCII symbols that math GSM coding, that only change is Alphabet replacing to GSM (this is needed for "automating" of scripts and E-mail redirector). 1.2. If 1.1 is not true, the message is recoding from UTF8 to UCS2 and Alphabet is changed to UCS2. 2. If decode_unicode_text=yes is defined in configuration, than: 2.1. The message is recoding from UCS2 to UTF8 (and ISO=>UTF recoding is automatically disabled). 2.2. The Alphabet:UTF-8 is placed in output file. 3. NOTE (unexpected addonce :)). If the USSD command is defined in regular_run_cmd and if this command receive replay in HEX-UCS2, this string is automatically converted to UTF8. This is necessary for receiving "balance" (payment information). There are many GSM-modems that permit the USSD request only in format '1,"....",15' (i.e. with "default" language). The many GSM-providers in this case are send replay in "local" language. And if language is not LatinX, the replays are some sort of: OK +CUSD 2,"045b04230023.....",72 which is... not readable for user :). diff -Pur base/charset.c src/charset.c --- base/charset.c 2009-06-24 05:11:08.000000000 +0400 +++ src/charset.c 2009-06-29 06:39:03.000000000 +0400 @@ -18,6 +18,10 @@ #include <string.h> #include <stdarg.h> #include <syslog.h> +#ifdef USE_ICONV +#include <iconv.h> +#include <errno.h> +#endif #include "charset.h" #include "logging.h" #include "smsd_cfg.h" @@ -292,6 +296,11 @@ 0 , 0 }; +#ifdef USE_ICONV +static iconv_t iconv4ucs; // UCS2->UTF8 descriptor +static iconv_t iconv2ucs; // UTF8->UCS2 descriptor +#endif + int special_char2gsm(char ch, char *newch) { int table_row = 0; @@ -717,6 +726,7 @@ return dest_count; } +#ifndef USE_ICONV int decode_ucs2(char *buffer, int len) { int i; @@ -741,6 +751,7 @@ *(buffer +i) = '\0'; return i; } +#endif // ****************************************************************************** // Collect character conversion log, flush it if called with format==NULL. @@ -802,3 +813,87 @@ // ****************************************************************************** +#ifdef USE_ICONV +int iconv_init(void) +{ + // do noy use 'UTF8' alias - it not supported in cygwin/mingw + return (iconv4ucs = iconv_open("UTF-8", "UCS-2BE")) != (iconv_t)-1 + && (iconv2ucs = iconv_open("UCS-2BE", "UTF-8")) != (iconv_t)-1; +} + +static size_t iconv_convert(iconv_t cd, char *buf, size_t* ilen, size_t maxlen) +{ + char tmp[MAXTEXT], *out, *in; + size_t olen, rc; + const char* err; + + if (!maxlen || !ilen || !*ilen || !buf) + return 0; + + // reset conversion descriptor + iconv(cd, NULL, NULL, NULL, NULL); + err = NULL; + in = buf; + out = tmp; + olen = sizeof(tmp); + rc = iconv(cd, &in, ilen, &out, &olen); + if (rc == (size_t)-1) + { + switch (errno) + { + case E2BIG: + err = "Buffer to small"; + break; + case EILSEQ: + err = "Invalid sequnce"; + break; + case EINVAL: + err = "Incomplete sequence"; + break; + default: + err = strerror(errno); + break; + } + } + olen = sizeof(tmp) - olen; + if (olen >= maxlen) + { + err = "output buffer too small"; + olen = maxlen; + } + memcpy(buf, tmp, olen); + if (err != NULL) + writelogfile(LOG_NOTICE, 0, "Unicode conversion error: %s", err); + return olen; +} + +size_t iconv_utf2ucs(char *buf, size_t len, size_t maxlen) +{ + return iconv_convert(iconv2ucs, buf, &len, maxlen); +} + +size_t iconv_ucs2utf(char *buf, size_t len, size_t maxlen) +{ + return iconv_convert(iconv4ucs, buf, &len, maxlen); +} + +size_t iconv_ucs2utf_chk(char *buf, size_t len, size_t maxlen) +{ + size_t olen, ilen = len; + olen = iconv_convert(iconv4ucs, buf, &ilen, maxlen); + buf[olen] = 0; + if (ilen != 0) + ilen = (len - ilen + 1) / 2; + return ilen; +} + +int is_ascii_gsm(char* buf, size_t len) +{ + char tmp; + size_t i; + for (i = 0; i < len; i++) + if (buf < ' ' || char2gsm(buf, &tmp) != 1) + return 0; + return 1; +} +#endif // USE_ICONV diff -Pur base/charset.h src/charset.h --- base/charset.h 2009-05-05 20:30:25.000000000 +0400 +++ src/charset.h 2009-06-29 06:01:42.000000000 +0400 @@ -37,6 +37,14 @@ //int iso2gsm(char* source, int size, char* destination, int max); //int unicode2sms(char* source, int size, char* destination, int max); +#ifndef USE_ICONV int decode_ucs2(char *buffer, int len); +#else +int iconv_init(void); +size_t iconv_utf2ucs(char* buf, size_t len, size_t maxlen); +size_t iconv_ucs2utf(char* buf, size_t len, size_t maxlen); +size_t iconv_ucs2utf_chk(char *buf, size_t len, size_t maxlen); +int is_ascii_gsm(char* buf, size_t len); +#endif #endif diff -Pur base/pdu.c src/pdu.c --- base/pdu.c 2009-06-24 05:11:08.000000000 +0400 +++ src/pdu.c 2009-06-29 05:45:46.000000000 +0400 @@ -1590,8 +1590,12 @@ else { memcpy(ascii, message, message_length); +#ifndef USE_ICONV ascii[message_length] = 0; i = decode_ucs2(ascii, message_length); +#else + i = (int)iconv_ucs2utf(ascii, message_length, sizeof(ascii)); +#endif expected_length /= 2; } diff -Pur base/smsd.c src/smsd.c --- base/smsd.c 2009-06-25 00:30:18.000000000 +0400 +++ src/smsd.c 2009-06-29 06:02:06.000000000 +0400 @@ -927,7 +927,7 @@ // output variables are: char* to, /* destination number */ char* from, /* sender name or number */ - int* alphabet, /* -1=GSM 0=ISO 1=binary 2=UCS2 3=unknown */ + int* alphabet, /* -1=GSM 0=ISO 1=binary 2=UCS2 3=UTF8 4=unknown */ int* with_udh, /* UDH flag */ char* udh_data, /* UDH data in hex dump format. Only used in alphabet<=0 */ char* queue, /* Name of Queue */ @@ -1116,8 +1116,10 @@ *alphabet=2; else if (strncasecmp(line,"uni",3)==0) *alphabet=2; - else + else if (strncasecmp(line,"utf",3)==0) *alphabet=3; + else + *alphabet=4; } else if (strncmp(line, HDR_UDHDATA, hlen = strlen(HDR_UDHDATA)) == 0) @@ -1646,7 +1648,11 @@ fail_text = "Destination is not whitelisted"; } // Is the alphabet setting valid? +#ifdef USE_ICONV + else if (alphabet>3) +#else else if (alphabet>2) +#endif { writelogfile(LOG_NOTICE, 0, tb_sprintf("Invalid alphabet in file %s", filename)); alarm_handler(LOG_NOTICE, tb); @@ -2744,9 +2750,14 @@ } } +#ifndef USE_ICONV // 3.1beta7, 3.0.9: decoding is always done: userdatalength = decode_ucs2(ascii, userdatalength); alphabet = 0; +#else + userdatalength = iconv_ucs2utf(ascii, userdatalength, sizeof(ascii)); + alphabet = 4; +#endif } #ifdef DEBUGMSG @@ -2755,7 +2766,7 @@ printf("!! sendr=%s\n",sendr); printf("!! date=%s\n",date); printf("!! Time=%s\n",Time); - if ((alphabet==-1 && DEVICE.cs_convert==1)||(alphabet==0)) + if ((alphabet==-1 && DEVICE.cs_convert==1)||(alphabet==0)||(alphabet==4)) printf("!! ascii=%s\n",ascii); printf("!! smsc=%s\n",smsc); printf("!! with_udh=%i\n",with_udh); @@ -2926,8 +2937,14 @@ udlen=gsm2iso(ascii +userdatalength,udlen,ascii +userdatalength,sizeof(ascii) -userdatalength); else if (alphabet == 2 && do_decode_unicode_text == 1) { +#ifndef USE_ICONV udlen = decode_ucs2(ascii +userdatalength, udlen); alphabet = 0; +#else + udlen = iconv_ucs2utf(ascii +userdatalength, udlen, + sizeof(ascii) -userdatalength); + alphabet = 4; +#endif } userdatalength += udlen; break; @@ -3092,6 +3109,8 @@ p = "binary"; else if (alphabet == 2) p = "UCS2"; + else if (alphabet == 4) + p = "UTF-8"; else if (alphabet == 3) p = "reserved"; @@ -3879,7 +3898,11 @@ fail_text = "No destination"; success = -2; } +#ifdef USE_ICONV + else if (alphabet>3) +#else else if (alphabet>2) +#endif { writelogfile0(LOG_NOTICE, 0, tb_sprintf("Invalid alphabet in file %s",filename)); alarm_handler0(LOG_NOTICE, tb); @@ -3941,12 +3964,12 @@ printf("!! to=%s, from=%s, alphabet=%i, with_udh=%i, udh_data=%s, provider=%s, flash=%i, smsc=%s, report=%i, split=%i\n",to,from,alphabet,with_udh,udh_data,provider,flash,smsc,report,split); #endif // If this is a text message, then read also the text - if (alphabet<1 || alphabet == 2) + if (alphabet<1 || alphabet >= 2) { #ifdef DEBUGMSG - printf("!! This is %stext message\n", (alphabet == 2)? "unicode " : ""); + printf("!! This is %stext message\n", (alphabet >= 2)? "unicode " : ""); #endif - maxpartlen = (alphabet == 2)? maxsms_ucs2 : maxsms_pdu; // ucs2 = 140, pdu = 160 + maxpartlen = (alphabet >= 2)? maxsms_ucs2 : maxsms_pdu; // ucs2 = 140, pdu = 160 readSMStext(filename, 0, DEVICE.cs_convert && (alphabet==0), text, &textlen, macros); // Is the message empty? if (textlen==0) @@ -3971,6 +3994,18 @@ } // ------ +#ifdef USE_ICONV + if (alphabet == 3) + { + if (is_ascii_gsm(text, textlen)) + alphabet = -1; + else + { + alphabet = 2; + textlen = (int)iconv_utf2ucs(text, textlen, sizeof(text)); + } + } +#endif // In how many parts do we need to split the text? if (split>0) { @@ -4813,6 +4848,9 @@ char *p; char answer[500]; char buffer[600]; +#ifdef USE_ICONV + int is_ussd = 0; +#endif int fd; int log_retry = 3; int i; @@ -4830,7 +4868,12 @@ // 3.1.5: Special case: AT+CUSD, wait USSD message: //put_command(*modem, device, cmd, answer, sizeof(answer), 1, "(OK)|(ERROR)"); if (!strncasecmp(command, "AT+CUSD", 7) && strlen(command) > 9) + { put_command(cmd, answer, sizeof(answer), 3, "(\\+CUSD:)|(ERROR)"); +#ifdef USE_ICONV + ++is_ussd; // = 1; +#endif + } else put_command(cmd, answer, sizeof(answer), 1, "(OK)|(ERROR)"); @@ -4850,7 +4893,35 @@ strcpy(p, p +1); if (*answer == ' ') strcpy(answer, answer +1); - + p = answer + strlen(answer); + while (p > answer && p[-1] == ' ') + --p; + *p = 0; +#ifdef USE_ICONV + // If answer of USSD received in unicode format, convert it to utf8 +#define USSDOK "OK +CUSD: 2,\"" + i = 0; + if (is_ussd != 0 && !strncasecmp(answer, USSDOK, sizeof(USSDOK)-1) + && sscanf(p = answer + sizeof(USSDOK)-1, + "%[0-9A-Fa-f]\",72%n", buffer, &i) == 1 + && !p && i > 4 && ((i -= 4) & 3) == 0) +#undef USSDOK + { + for (i = 0; buffer[i*2]; i++) + { + unsigned v; + sscanf(&buffer[i*2], "%2X", &v); + buffer = (char)v; + } + i = (int)iconv_ucs2utf(buffer, i, sizeof(answer)-2 - (p-answer)); + if (i != 0) + { + memcpy(p, buffer, i); + p = '"'; + p[i+1] = 0; + } + } +#endif if (DEVICE.dev_rr_logfile[0]) { while (log_retry-- > 0) @@ -5756,6 +5827,14 @@ } } +#ifdef USE_ICONV + if (!iconv_init()) + { + writelogfile(LOG_CRIT, 0, "Smsd mainprocess terminated because of the iconv_open() failure."); + exit(EXIT_FAILURE); + } +#endif + time(&process_start_time); if (write_pid(pidfile) == 0) ATT: If build after this patch in cyrwin/mingw environment makefile must add '-liconv' option (in linux all included in libc). NOTE: Yet NOT tested: Errors (i.e. replay with errors :)); code auto-detection (I don't know how to reach this situation); and finally, all tested only with Russian providers (but for different languages, including European :). ----------------------------- Next small patch (must use after "converter") needed, for example, for "balance" requests. If regular_run_cmd is defined for modem (and use USSD command), and the MODEM eventhandler are defined, after executing regular_run_cmd modem eventhandler is called with arguments: <modem_handler> USSD <modem_name> "answer_string" And the quotes(") in answer_string are processed correctly (escaped for shell). diff -Pur base/smsd.c src/smsd.c --- base/smsd.c 2009-06-29 07:27:52.000000000 +0400 +++ src/smsd.c 2009-06-29 08:14:09.000000000 +0400 @@ -4947,6 +4947,26 @@ else writelogfile(DEVICE.dev_rr_loglevel, 0, "CMD: %s: %s", command, answer); + if (is_ussd && DEVICE.eventhandler[0]) + { + size_t n, i; + n = snprintf(buffer, sizeof(buffer), "%s USSD %s \"", DEVICE.eventhandler, DEVICE.name); + for (i = 0; answer != '\0' && n < sizeof(buffer)-2; n++, i++) + { + if (answer == '"') + buffer[n++] = '\\'; + buffer[n] = answer; + } + if (n < sizeof(buffer)-2) + { + buffer[n] = '"'; + buffer[n+1] = '\0'; + exec_system(buffer, EXEC_EVENTHANDLER); + } + else + writelogfile(LOG_WARNING, 0, "Buffer too small for execute USSD eventhadler for %s", DEVICE.name); + } + // 3.1.5: If signal quality was checked, explain it to the log: if (!strcasecmp(cmd, "AT+CSQ\r")) explain_csq(DEVICE.dev_rr_loglevel, 0, answer); NOTE: I'm not make separate options for enable this call - I'm think that it will be only more complicate. If you think that 'enable option' is needed - I have't any questions :)
yjh: Have you double-checked that there surely is enough space available while running on GNU/Linux? Many time in many programs :). But only on x86/x64. Your changes can be included in the code, but it should be users choice to use it or not. Thanks. I'm post new version of patch tomorrow (or today later) Because of some activities I'm little bit busy currently, but after a while this repository can be created. Code of an upcoming version should be used as a base, not 3.1.5. New code is already reformatted and reorganized and there are also changes to allow SQL database based spooling. My patch is practically done - I'm will post it tomorrow. But this patch based on 3.1.5. If You will receive patch to other version (checked it in my environment), please send my e-mail with 'base-source'. A new header can override System_message header. I do not change System_message header usage because of backward compatibility. I think that backward compatibility present in my variant also (yes/no/0/1/etc values interpret in old manner), but if You will change header - make header part as You need right and get functionality from patch.
yjh: Perhaps you have something more to tell, e.g. what changes you been thinking on sms3 script? How about backward compatibility with watchdog systems, and probably for systems running more than one daemon... No problem. I'm can place this in #ifdef USE_SHORT_PS_NAMES (defined on make) or (if You will) move this patch to addition branch (when my environment in headers present). What variant is perfectly to You? (I'm replace patch after Your answer). I have to check this issue later. Ok, I'm wait :) Generally taken, it has been problematic to test some cyrillic environments, because I do not understand the language :(. But if you can help this project with your knowledge, I and many users too would appreciate it very much. This problem present not only in cyrillic environment (e.g. in chinese, japanese, tai... :)), but I'm can check only in cyrillic. I'm will make variant for english/russian combianation in any case, but... I can't test European languages (diasterics, etc). After You answer we can start 'iterated' process - e.g. I'm make build that correct work for cyrillic SMS (without checking of 'invalid-configuration-combination'), send it to You, You check this build in european environment, and that we can resolve check's of configuration. Ok? :) If yes - maybe I (or You) create (temporary) svn-repository for this process? Message-board is not optimal place for it. Those messages were using LOG_INFO in previous versions, but now (with smart_logging) LOG_NOTICE is a good level for logging and those messages was changed because they were needed in some kind of systems. Because those are startup messages only, not much additional lines are produced. First three - yes (Ok, I'm remove patch), and 4? "Moved file %s to %s" not needed for send/receive log-analizers, and present of any outed message :( You will get your feature as a new header, I just have to check how this works and if there is any side effects. :) Not good idea. If make new header (e.g. SStoSIM) need check that this header not present in combination with System_message. And in this situation (conflict) we have many variants - drop message, select one of options, etc.
yjh: Before go to problem with non-english messages :) last one small patch. This patch is very 'special' - for communicate with SIM-applications. It permit send SMS as SS,- it not show, not stored in ME and always stored (sended to) SIM. I'm not add new parameters - use one of Your's :) - SMS-file header for this behavior is: System_message: toSIM diff -Pur base/pdu.c src/pdu.c --- base/pdu.c 2009-06-24 05:11:08.000000000 +0400 +++ src/pdu.c 2009-06-24 06:13:20.000000000 +0400 @@ -365,12 +365,24 @@ sprintf(pdu,"%02X00%02X%02X%s00%02X%02X",flags,numberlength,numberformat,tmp,coding,messagelen); else { + int proto = 0; if (validity < 0 || validity > 255) validity = validity_period; + if (system_msg) + { + proto = 0x40; + coding = 0xF4; // binary + if (system_msg==2) + { + proto += (0x7F - 0x40); // SS (no show) + coding += 2; // store to sim + } + } + else if (replace_msg >= 1 && replace_msg <= 7) + proto = 0x40 + replace_msg; sprintf(pdu, "00%02X00%02X%02X%s%02X%02X%02X%02X", - flags, numberlength, numberformat, tmp, - (system_msg)? 0x40 : (replace_msg >= 1 && replace_msg <= 7)? 0x40 +replace_msg : 0, - (system_msg)? 0xF4 : coding, validity, messagelen); + flags, numberlength, numberformat, tmp, proto, coding, + validity, messagelen); } /* concatenate the text to the PDU string */ strcat(pdu,tmp2); Currently this message always sended as binary,- I'm can't yet test others case :). Do You intend to include this patch included in Your package, or I'm must make it in separate branch and merge after new versions?
yjh: Big thanks (detail below). For argv/argc - this is 'standard trick' :) for linux used in many (old) programs. 1. Argv's pointed to single memory buffer (e.g argv[n+1] == argv[n] + strlen(argv[n]). 2. Than go to /usr/src/linux/fs open file exec.c and find procedure copy_strings (it copies arguments from parent process to current). You can see that allocation have 'page' granularity (e.g. minimum allocation size for x86 is 4kB :). ----- Next (apply after previoused) trivial patch change log levels for 4 messages - it described as information (in comment's), but outed as notice :) and 'expand' logfile to unneeded details: diff -Pur base/modeminit.c src/modeminit.c --- base/modeminit.c 2009-06-24 05:11:08.000000000 +0400 +++ src/modeminit.c 2009-06-25 18:00:37.000000000 +0400 @@ -1197,7 +1197,7 @@ *p = 0; cut_ctrl(answer); cutspaces(answer); - writelogfile(LOG_NOTICE, 0, "CGSN: %s", answer); + writelogfile(LOG_INFO, 0, "CGSN: %s", answer); } if (!strstr(DEVICE.identity, "ERROR")) @@ -1206,10 +1206,10 @@ *p = 0; cut_ctrl(DEVICE.identity); cutspaces(DEVICE.identity); - writelogfile(LOG_NOTICE, 0, "IMSI: %s", DEVICE.identity); + writelogfile(LOG_INFO, 0, "IMSI: %s", DEVICE.identity); } else - writelogfile(LOG_NOTICE, 1, "IMSI/CGSN not supported"); + writelogfile(LOG_INFO, 1, "IMSI/CGSN not supported"); } // ----------------------------------------------------------------------------------------------- diff -Pur base/smsd.c src/smsd.c --- base/smsd.c 2009-06-25 00:30:18.000000000 +0400 +++ src/smsd.c 2009-06-25 18:05:57.000000000 +0400 @@ -1698,7 +1698,7 @@ } stop_if_file_exists("Cannot move", filename, "to", directory); - writelogfile(LOG_NOTICE, 0, "Moved file %s to %s", filename, (keep_filename)? directory : newfilename); + writelogfile(LOG_INFO, 0, "Moved file %s to %s", filename, (keep_filename)? directory : newfilename); success = 1; sendsignal2devices(SIGCONT); } ------ That go to complex problem :). Your realization of ucs2 conversion ( to/from utf8 ) is not correct (if messages contain symbols not in Latin-5). 1. You use wctomb without setlocale. In this case wctomb use default ('C') locale. And locale 'C'... is analogue of Latin1 :). 2. You use 'internal' tables for conversion (e.g. not support others languages). The simplest (but not fully correct) workaround is insert at begin of main() setlocale(LC_CTYPE, "en_US.UTF-8"); (or setlocale(LC_CTYPE, ""); if user environment is utf8 :). With this change 'decode_unicode_text=yes' work correctly for inputed mesages, but... only if 'incoming_utf8=yes' is NOT set. I think that 'ut8-conversion' would be unneeded, but this must be tested in environment for which it developed. But this method doesn't resolve problem of conversion output messages from utf8 to ucs2. The second (not so trivial) variant is add 'UTF8' alphabet and convert it (with iconv() call) to ucs2 on output if SMS-file set it. Also can use iconv instead of wctomb (and not change locale). But in this case 'Alphabet: UTF8' must be set it in inputed UCS2 messages when it converted and... for ISO-converted messages (if this needed) - for unification. But in this variant I also don't known must your utf8-conversion procedures removed or not. And if this procedures must remain we have situation with potentially conflicting configuration parameters. Please, tell me Your suggestions of this problem :) and I try to make patch (check it in my - russian - environment) and sent it to You. ----- Sorry, but my english is very poor :(
yjh: As You wish :). First patch remove compiler warnings when build in 64bit system (x64). Build with -W -Wall and possible -O2 diff -Pur base/cfgfile.c src/cfgfile.c --- base/cfgfile.c 2009-05-05 20:29:32.000000000 +0400 +++ src/cfgfile.c 2009-06-24 03:37:00.000000000 +0400 @@ -51,6 +51,7 @@ char* cp2; int size; + (void)size_subparam; cp=(char*)parameter; subparam[0]=0; for (j=1; j<n; j++) diff -Pur base/charset.c src/charset.c --- base/charset.c 2009-05-18 22:32:34.000000000 +0400 +++ src/charset.c 2009-06-24 03:42:58.000000000 +0400 @@ -644,7 +644,7 @@ logch("%s ", logtmp); } - if (fwrite(tmp, 1, len, fp) != len) + if (fwrite(tmp, 1, len, fp) != (size_t)len) { if (log_charconv) logch(NULL); diff -Pur base/logging.c src/logging.c --- base/logging.c 2009-05-29 13:12:49.000000000 +0400 +++ src/logging.c 2009-06-24 03:37:47.000000000 +0400 @@ -76,7 +76,7 @@ int error = 0; int i; - if (snprintf(filename2, sizeof(filename2), "%s", filename) >= sizeof(filename2)) + if ((size_t)snprintf(filename2, sizeof(filename2), "%s", filename) >= sizeof(filename2)) error = 1; else { diff -Pur base/modeminit.c src/modeminit.c --- base/modeminit.c 2009-05-30 20:06:23.000000000 +0400 +++ src/modeminit.c 2009-06-24 03:46:21.000000000 +0400 @@ -358,7 +358,7 @@ // 3.1.5: if (DEVICE.send_delay < 1) { - if (write(modem_handle, command, strlen(command)) != strlen(command)) + if ((size_t)write(modem_handle, command, strlen(command)) != strlen(command)) { writelogfile0(LOG_ERR, 1, tb_sprintf("Could not send string, cause: %s", strerror(errno))); alarm_handler0(LOG_ERR, tb); @@ -370,7 +370,7 @@ } else { - for(x=0;x<strlen(command);x++) + for(x=0;(size_t)x<strlen(command);x++) { if (write(modem_handle, command +x, 1) < 1) { @@ -547,7 +547,7 @@ writelogfile(LOG_DEBUG, 0, "Sending acknowledgement"); if (write_to_modem("AT+CNMA\r", 30, 1, 0) == 0) - ; + {} *loganswer = 0; read_from_modem(loganswer, sizeof(loganswer), 2); diff -Pur base/pdu.c src/pdu.c --- base/pdu.c 2009-05-24 15:24:30.000000000 +0400 +++ src/pdu.c 2009-06-24 04:01:42.000000000 +0400 @@ -169,7 +169,7 @@ if (length>maxsms_pdu-udh_size_septets) length=maxsms_pdu-udh_size_septets; //clear the tmp buffer - for (character=0;character<sizeof(tmp);character++) + for (character=0;(size_t)character<sizeof(tmp);character++) tmp[character]=0; // Convert 8bit text stream to 7bit stream for (character=0;character<length;character++) @@ -535,7 +535,7 @@ if ((udh_length = octet2bin_check(buffer)) < 0) return -1; udh_length++; - if (udh_length *2 > strlen(buffer)) + if ((size_t)(udh_length *2) > strlen(buffer)) return -1; sprintf(udh_type, "Length=%i", udh_length); idx = 1; @@ -612,7 +612,7 @@ // Next octet is length of data: if ((i = octet2bin_check(Src_Pointer +2)) < 0) return -1; - if (i *2 > strlen(Src_Pointer +4)) + if ((size_t)(i *2) > strlen(Src_Pointer +4)) return -1; idx += i +2; if (idx > udh_length) @@ -641,7 +641,7 @@ int octetcounter; int skip_characters = 0; char c; - char binary; + char binary = 0; int i; int result; @@ -973,7 +973,7 @@ Src_Pointer += 2; if ((i & 112) == 80) { // Sender is alphanumeric - if (strlen(Src_Pointer) < Length +padding) + if (strlen(Src_Pointer) < (size_t)(Length +padding)) pdu_error(err_str, 0, Src_Pointer -full_pdu, Length +padding, "While trying to read sender address (alphanumeric, length %i): %s", Length +padding, err_too_short); @@ -987,7 +987,7 @@ } else { // sender is numeric - if (strlen(Src_Pointer) < Length +padding) + if (strlen(Src_Pointer) < (size_t)(Length +padding)) pdu_error(err_str, 0, Src_Pointer -full_pdu, Length +padding, "While trying to read sender address (numeric, length %i): %s", Length +padding, err_too_short); @@ -1196,7 +1196,7 @@ Src_Pointer += 2; if ((i & 112) == 80) { // Sender is alphanumeric - if (strlen(Src_Pointer) < Length +padding) + if (strlen(Src_Pointer) < (size_t)(Length +padding)) pdu_error(err_str, 0, Src_Pointer -full_pdu, Length +padding, "While trying to read recipient address (alphanumeric, length %i): %s", Length +padding, err_too_short); @@ -1210,7 +1210,7 @@ } else { // sender is numeric - if (strlen(Src_Pointer) < Length +padding) + if (strlen(Src_Pointer) < (size_t)(Length +padding)) pdu_error(err_str, 0, Src_Pointer -full_pdu, Length +padding, "While trying to read recipient address (numeric, length %i): %s", Length +padding, err_too_short); @@ -1492,7 +1492,7 @@ { Length = Length *2 -2; // No padding because the given value is number of octets. - if (strlen(Pointer) < Length +4) + if (strlen(Pointer) < (size_t)(Length +4)) pdu_error(&err_str, 0, Pointer -pdu, Length +4, "While trying to read sender SMSC address (length %i): %s", Length, err_too_short); else @@ -1674,7 +1674,7 @@ return result; } -int get_pdu_details(char *dest, int size_dest, char *pdu, int mnumber) +int get_pdu_details(char *dest, size_t size_dest, char *pdu, int mnumber) { int result = 0; int udlen; @@ -1696,7 +1696,7 @@ int flash; int bin_udh = 1; int m_id = 999; // real id for concatenated messages only, others use this. - int length_sender = 32; + size_t length_sender = 32; int p_count = 1; int p_number = 1; char buffer[51]; diff -Pur base/pdu.h src/pdu.h --- base/pdu.h 2009-05-21 11:01:53.000000000 +0400 +++ src/pdu.h 2009-06-24 03:59:37.000000000 +0400 @@ -73,7 +73,7 @@ int explain_toa(char *dest, char *octet_char, int octet_int); -int get_pdu_details(char *dest, int size_dest, char *pdu, int mnumber); +int get_pdu_details(char *dest, size_t size_dest, char *pdu, int mnumber); void sort_pdu_details(char *dest); #endif diff -Pur base/smsd.c src/smsd.c --- base/smsd.c 2009-05-31 20:21:18.000000000 +0400 +++ src/smsd.c 2009-06-24 04:13:17.000000000 +0400 @@ -533,7 +533,7 @@ return 0; } -int prepare_remove_headers(char *remove_headers, int size) +int prepare_remove_headers(char *remove_headers, size_t size) { char *p; @@ -545,7 +545,7 @@ HDR_Number, HDR_Sent, HDR_MessageId, - HDR_Result) >= size) + HDR_Result) >= (ssize_t)size) return 0; if ((p = get_header(NULL, HDR_FailReason2))) @@ -708,7 +708,7 @@ i = setting_length; //filename_preview; if (strlen(filename) +2 +i > PATH_MAX) i = PATH_MAX - strlen(filename) -2; - if (strlen(text) > i) + if (strlen(text) > (size_t)i) text = 0; for (i = 0; text != 0; i++) if (!isalnum(text) && !strchr(allowed_chars, text)) @@ -1169,7 +1169,7 @@ p = macros; while (*p) p = strchr(p, 0) +1; - if (strlen(line) <= SIZE_MACROS -2 -(p - macros)) + if ((ssize_t)strlen(line) <= SIZE_MACROS -2 -(p - macros)) { strcpy(p, line); *(p +strlen(line) +1) = 0; @@ -1312,7 +1312,7 @@ int in_headers = 1; char *p; int h; - int i; + int i = 0; char *p_length = NULL; int too_long = 0; int hlen; @@ -1828,7 +1828,7 @@ ======================================================================= */ // Return value: 1 = OK, 0 = check failed. -int check_memory(int *used_memory, int *max_memory, char *memory_list, int memory_list_size, +int check_memory(int *used_memory, int *max_memory, char *memory_list, size_t memory_list_size, char *delete_list, int delete_list_size) { // 3.1.5: GMGL list needs much more space: using global buffer. @@ -1842,6 +1842,7 @@ char *pos; int i; + (void)delete_list_size; // Set default values in case that the modem does not support the +CPMS command *used_memory=1; *max_memory=10; @@ -3251,7 +3252,7 @@ int found; int foundsomething=0; int statusreport; - int sim; + int sim=0; char line1[1024]; char line2[1024]; char filename[PATH_MAX]; @@ -3262,7 +3263,7 @@ char *p2; char memory_list[1024]; char delete_list[1024]; - int i; + size_t i; flush_smart_logging(); @@ -3403,7 +3404,7 @@ p++; if ((p2 = strchr(p, '\r'))) { - i = (int)(p2 -p); + i = p2 -p; if (i < sizeof(line2)) { strncpy(line2, p, i); @@ -4072,7 +4073,7 @@ int bytes = (strlen(udh_data) +1) / 3; int i; - if (textlen <= sizeof(text) -bytes) + if (textlen <= (ssize_t)sizeof(text) -bytes) { memmove(text +bytes, text, textlen); for (i = 0; i < bytes; i++) @@ -4747,6 +4748,7 @@ char buffer[256]; int textlen; + (void)errorcounter; if (DEVICE.admin_to[0]) to = DEVICE.admin_to; else if (admin_to[0]) @@ -4796,7 +4798,7 @@ -1 /*validity*/, 0, 1, 0, 0, -1 /*to_type*/, 0)) - ; + {} } } @@ -5028,7 +5030,7 @@ if (i == 5 || i == 6) { p = (i == 5)? line +18 : line +21; - if (p -line < strlen(line)) + if ((size_t)(p -line) < strlen(line)) { *buffer = 0; i = get_pdu_details(buffer, sizeof(buffer), p, 0); @@ -5470,6 +5472,7 @@ void soft_termination_handler (int signum) { + (void)signum; if (process_id==-1) { signal(SIGTERM,SIG_IGN); @@ -5815,7 +5818,7 @@ { if (strncmp(argv[idx], "MAINPROCESS", 11) == 0) { - int l = strlen(devices.name); + size_t l = strlen(devices.name); if (l > strlen(argv[idx])) l = strlen(argv[idx]); diff -Pur base/smsd_cfg.c src/smsd_cfg.c --- base/smsd_cfg.c 2009-06-01 14:58:10.000000000 +0400 +++ src/smsd_cfg.c 2009-06-24 03:42:16.000000000 +0400 @@ -79,7 +79,7 @@ } // Helper function for copying to prevent buffer overflows: -char *copyvalue(char *dest, int maxlen, char *value, char *keyword) +char *copyvalue(char *dest, size_t maxlen, char *value, char *keyword) { if (strlen(value) > maxlen) { @@ -701,7 +701,7 @@ p = priviledged_numbers; while (*p) p = strchr(p, 0) +1; - if (strlen(tmp) <= SIZE_PRIVILEDGED_NUMBERS -2 -(p - priviledged_numbers)) + if ((ssize_t)strlen(tmp) <= SIZE_PRIVILEDGED_NUMBERS -2 -(p - priviledged_numbers)) { strcpy(p, tmp); *(p +strlen(tmp) +1) = 0; @@ -1154,7 +1154,7 @@ p = NEWDEVICE.dev_rr_cmd; while (*p) p = strchr(p, 0) +1; - if (strlen(value) <= SIZE_RR_CMD -2 -(p - NEWDEVICE.dev_rr_cmd)) + if ((ssize_t)strlen(value) <= SIZE_RR_CMD -2 -(p - NEWDEVICE.dev_rr_cmd)) { strcpy(p, value); *(p +strlen(value) +1) = 0; @@ -1226,7 +1226,7 @@ p = NEWDEVICE.priviledged_numbers; while (*p) p = strchr(p, 0) +1; - if (strlen(tmp) <= SIZE_PRIVILEDGED_NUMBERS -2 -(p - NEWDEVICE.priviledged_numbers)) + if ((ssize_t)strlen(tmp) <= SIZE_PRIVILEDGED_NUMBERS -2 -(p - NEWDEVICE.priviledged_numbers)) { strcpy(p, tmp); *(p +strlen(tmp) +1) = 0; @@ -2010,7 +2010,7 @@ else { snprintf(tmp, sizeof(tmp), "#!%s\necho OK > \"$1\"\nexit 0\n", shell); - if (write(fd, tmp, strlen(tmp)) < strlen(tmp)) + if (write(fd, tmp, strlen(tmp)) < (ssize_t)strlen(tmp)) error = "Cannot write to test script file."; close(fd); diff -Pur base/whitelist.c src/whitelist.c --- base/whitelist.c 2009-05-18 23:06:52.000000000 +0400 +++ src/whitelist.c 2009-06-24 03:44:14.000000000 +0400 @@ -50,7 +50,7 @@ i = strlen(line); if (i > 0) { - if (line[0] == '[' && line[i -1] == ']' && i -2 < sizeof(current_queue)) + if (line[0] == '[' && line[i -1] == ']' && (size_t)(i -2) < sizeof(current_queue)) { line[i -1] = 0; strcpy(current_queue, line +1); The second patch (apply after first) 'cenralize' all datetime formats used for logging as #defines in header. Also define default config file pathname to header and correct help out. When this defines placed in header it may be trivial changed before compilation (needed for pseudo-localized output - e.g. in russian environment datetimestamp in all log is d-m-Y). diff -Pur base/alarm.c src/alarm.c --- base/alarm.c 2009-05-05 20:29:22.000000000 +0400 +++ src/alarm.c 2009-06-24 23:41:02.000000000 +0400 @@ -54,7 +54,7 @@ if (severity<=_alarmlevel) { time(&now); - strftime(timestamp,sizeof(timestamp),"%Y-%m-%d %H:%M:%S",localtime(&now)); + strftime(timestamp,sizeof(timestamp),logtime_format,localtime(&now)); snprintf(cmdline,sizeof(cmdline),"%s ALARM %s %i %s \"%s\"",_alarmhandler,timestamp,severity, process_title, text); my_system(cmdline, "alarmhandler"); } diff -Pur base/logging.c src/logging.c --- base/logging.c 2009-06-24 05:11:08.000000000 +0400 +++ src/logging.c 2009-06-24 23:41:35.000000000 +0400 @@ -167,7 +167,7 @@ else { time(&now); - strftime(timestamp,sizeof(timestamp),"%Y-%m-%d %H:%M:%S",localtime(&now)); + strftime(timestamp,sizeof(timestamp),logtime_format,localtime(&now)); snprintf(text2, sizeof(text2),"%s,%i, %s: %s\n", timestamp, severity, process_title, text); // 3.1.5: @@ -194,7 +194,7 @@ // Any message is stored: time(&now); - strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", localtime(&now)); + strftime(timestamp, sizeof(timestamp), logtime_format, localtime(&now)); snprintf(text2, sizeof(text2),"%s,%i, %s: %s\n", timestamp, severity, process_title, text); if (text2[strlen(text2) -1] != '\n') diff -Pur base/smsd.c src/smsd.c --- base/smsd.c 2009-06-24 05:11:08.000000000 +0400 +++ src/smsd.c 2009-06-25 00:04:49.000000000 +0400 @@ -2999,7 +2999,7 @@ time_t rawtime; time(&rawtime); - strftime(timestamp, sizeof(timestamp), "%Y-%m-%d", localtime(&rawtime)); + strftime(timestamp, sizeof(timestamp), STATFILE_FORMAT, localtime(&rawtime)); if (date_filename == 1) sprintf(filename, "%s/%s.%s.XXXXXX", (is_statusreport && *d_report)? d_report : d_incoming, timestamp, DEVICE.name); else if (date_filename == 2) @@ -4840,7 +4840,7 @@ time_t now; time(&now); - strftime(timestamp, sizeof(timestamp), "%Y-%m-%d %H:%M:%S", localtime(&now)); + strftime(timestamp, sizeof(timestamp), logtime_format, localtime(&now)); while ((p = strchr(answer, '\r'))) *p = ' '; @@ -5600,6 +5600,7 @@ terminate = 0; strcpy(process_title, "smsd"); + strcpy(logtime_format, LOGTIME_DEFAULT); signal(SIGTERM,soft_termination_handler); signal(SIGINT,soft_termination_handler); signal(SIGHUP,soft_termination_handler); diff -Pur base/smsd_cfg.c src/smsd_cfg.c --- base/smsd_cfg.c 2009-06-24 05:11:08.000000000 +0400 +++ src/smsd_cfg.c 2009-06-25 00:11:16.000000000 +0400 @@ -1449,7 +1449,7 @@ printf(" -t run smsd in terminal\n"); printf(" -C Communicate with device\n\n"); printf(" -V print copyright and version\n\n"); - printf("All other options are set by the file /etc/smsd.conf.\n\n"); + printf("All other options are set by the file %s.\n\n", configfile); printf("Output is written to stdout, errors are written to stderr.\n\n"); exit(0); } @@ -1459,7 +1459,7 @@ int result; int i; - strcpy(configfile,"/etc/smsd.conf"); + strcpy(configfile,DEFAULT_CONFIGFILE); printstatus=0; arg_infofile[0] = 0; arg_pidfile[0] = 0; diff -Pur base/smsd_cfg.h src/smsd_cfg.h --- base/smsd_cfg.h 2009-05-31 20:01:14.000000000 +0400 +++ src/smsd_cfg.h 2009-06-25 00:11:38.000000000 +0400 @@ -20,6 +20,10 @@ #include <sys/types.h> #include <time.h> +#define DEFAULT_CONFIGFILE "/etc/smsd.conf" + +#define STATFILE_FORMAT "%Y-%m-%d" +#define LOGTIME_DEFAULT "%Y-%m-%d %H:%M:%S" #define DATETIME_DEFAULT "%y-%m-%d %H:%M:%S" #define CONCATENATED_DIR_FNAME "%s/%s-concatenated" @@ -288,6 +292,7 @@ char yes_word[SIZE_HEADER]; // "yes" printed as an output. char no_word[SIZE_HEADER]; // "no" char datetime_format[SIZE_HEADER]; // strftime format string for time stamps (not inside status reports). +char logtime_format[SIZE_HEADER]; // strftime forrmat string for time staps in any log's int translate_incoming; // 0 if incoming message headers are NOT transtaled. // Next two are ffor debugging purposes: The third patch (apply after second) make very readable process names (for 'ps') and permitts to simplify sms3 script :). Also source is slightly shorter :) diff -Pur base/smsd.c src/smsd.c --- base/smsd.c 2009-06-25 00:04:49.000000000 +0400 +++ src/smsd.c 2009-06-25 00:30:18.000000000 +0400 @@ -5797,6 +5797,11 @@ if (!(*communicate) && keep_messages) writelogfile(LOG_CRIT, 0, "This is a test run: messages are kept and smsd will stop after reading."); + // Make readable process name + for(i = 0; i < argc; i++) + memset(argv, 0, strlen(argv)); + strcpy(argv[0], "smsd: MAINPROCESS"); + // Start sub-processes for each modem for (i = 0; i < NUMBER_OF_MODEMS; i++) { @@ -5813,24 +5818,8 @@ if (pid == 0) { // 3.1.4: - int idx; - - for (idx = 0; idx < argc; idx++) - { - if (strncmp(argv[idx], "MAINPROCESS", 11) == 0) - { - size_t l = strlen(devices.name); - - if (l > strlen(argv[idx])) - l = strlen(argv[idx]); - - strncpy(argv[idx], devices.name, l); - while (argv[idx][l]) - argv[idx][l++] = '_'; - - break; - } - } + memset(argv[0] + sizeof("smsd: ")-1, 0, sizeof("MAINPROCESS")-1); + strcpy(argv[0] + sizeof("smsd: ")-1, devices.name); // ------ time(&process_start_time); I want to now which patches are accepted (or not) to decide to make other patches (e.g. correct ucsc2 conversation in non 8859-15 environment :) and more extension).
yjh: I'm make some patches to sms3 (e.g. remove compilation warnings in 64bit build, 'localize' datime format in log, etc), but... When I can sent this patches to it? I can't find any e-mail on site (and in package :), and Your forum's does not support 'attach file'. Regards

Page:  1

SMSTools3 Community » Search Top

 
Time in this board is UTC.  

Privacy Policy   SMS Server Tools 3 Copyright © Keijo Kasvi.