Navigation


Changeset 1035:2f989d1a21e9 in freeDiameter


Ignore:
Timestamp:
Apr 17, 2013, 1:51:25 AM (11 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Phase:
public
Message:

Improve dumper for time, and print longer UTF8 strings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/dictionary_functions.c

    r1033 r1035  
    219219char * fd_dictfct_UTF8String_dump(union avp_value * avp_value)
    220220{
    221 #define TRUNC_LEN       42 /* avoid very long strings */
    222         char * ret = strndup((char *)avp_value->os.data, TRUNC_LEN);
    223         if (ret && (*ret != '\0')) {
     221#define TRUNC_LEN       1024 /* avoid very long strings */
     222        char * ret;
     223        CHECK_MALLOC_DO( ret = malloc(TRUNC_LEN+2+3+1), return NULL );
     224        *ret = '"';
     225        strncpy(ret+1, (char *)avp_value->os.data, TRUNC_LEN);
     226        /* be sure to have a nul-terminated string */
     227        ret[TRUNC_LEN+1] = '\0';
     228        if (ret[1] != '\0') {
    224229                /* We sanitize the returned string to avoid UTF8 boundary problem.
    225230                We do this whether the string is trucated at TRUNC_LEN or not, to avoid potential problem
     
    227232
    228233                char * end = strchr(ret, '\0');
    229                
     234                char * oldend = end;
    230235                while (end > ret) {
    231236                        end--;
     
    241246                        }
    242247                }
    243         }       
     248                if (strlen((char *)avp_value->os.data) > strlen(ret+1))
     249                        strcat(end, "...");
     250                strcat(end, "\"");
     251        } else {
     252                *ret = '\0';
     253        }
    244254        return ret;
    245255}
     
    320330{
    321331        char * ret;
     332        time_t val;
     333        struct tm conv;
    322334        CHECK_MALLOC_DO( ret = malloc(STR_LEN), return NULL );
    323335        if (avp_value->os.len != 4) {
     
    325337                return ret;
    326338        }
    327         /* TODO: display the time as human-readable */
    328         snprintf(ret, STR_LEN, "[TODO Time dump: 0x%02hhx%02hhx%02hhx%02hhx]", avp_value->os.data[0], avp_value->os.data[1], avp_value->os.data[2], avp_value->os.data[3]);
     339        if (diameter_string_to_time_t(avp_value->os.data, avp_value->os.len, &val) != 0) {
     340                snprintf(ret, STR_LEN, "[time conversion error]");
     341                return ret;
     342        }
     343        gmtime_r(&val, &conv);
     344        snprintf(ret, STR_LEN, "%d%02d%02dT%02d%02d%02d+00", conv.tm_year+1900, conv.tm_mon+1, conv.tm_mday, conv.tm_hour, conv.tm_min, conv.tm_sec);
    329345        return ret;
    330346}
Note: See TracChangeset for help on using the changeset viewer.