Changeset 1035:2f989d1a21e9 in freeDiameter
- Timestamp:
- Apr 17, 2013, 1:51:25 AM (11 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdproto/dictionary_functions.c
r1033 r1035 219 219 char * fd_dictfct_UTF8String_dump(union avp_value * avp_value) 220 220 { 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') { 224 229 /* We sanitize the returned string to avoid UTF8 boundary problem. 225 230 We do this whether the string is trucated at TRUNC_LEN or not, to avoid potential problem … … 227 232 228 233 char * end = strchr(ret, '\0'); 229 234 char * oldend = end; 230 235 while (end > ret) { 231 236 end--; … … 241 246 } 242 247 } 243 } 248 if (strlen((char *)avp_value->os.data) > strlen(ret+1)) 249 strcat(end, "..."); 250 strcat(end, "\""); 251 } else { 252 *ret = '\0'; 253 } 244 254 return ret; 245 255 } … … 320 330 { 321 331 char * ret; 332 time_t val; 333 struct tm conv; 322 334 CHECK_MALLOC_DO( ret = malloc(STR_LEN), return NULL ); 323 335 if (avp_value->os.len != 4) { … … 325 337 return ret; 326 338 } 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); 329 345 return ret; 330 346 }
Note: See TracChangeset
for help on using the changeset viewer.