comparison libfdproto/dictionary_functions.c @ 1225:ce8bc8227ef4

Print times in localtime, not UTC.
author Thomas Klausner <tk@giga.or.at>
date Tue, 16 Jul 2013 19:23:33 +0200
parents 1020da0ea4bc
children d51fa7231f73
comparison
equal deleted inserted replaced
1224:7769172b877c 1225:ce8bc8227ef4
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * 32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF *
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * 33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
34 *********************************************************************************************************/ 34 *********************************************************************************************************/
35 35
36 #include "fdproto-internal.h" 36 #include "fdproto-internal.h"
37 #include <time.h>
37 38
38 /* This file contains helpers functions to be reused as callbacks in the struct dict_type_data structure. 39 /* This file contains helpers functions to be reused as callbacks in the struct dict_type_data structure.
39 There are three callbacks there: 40 There are three callbacks there:
40 41
41 - type_encode : 42 - type_encode :
303 CHECK_PARAMS( avp_value && interpreted ); 304 CHECK_PARAMS( avp_value && interpreted );
304 305
305 return diameter_string_to_time_t((const char *)avp_value->os.data, avp_value->os.len, interpreted); 306 return diameter_string_to_time_t((const char *)avp_value->os.data, avp_value->os.len, interpreted);
306 } 307 }
307 308
309 static void _format_offs (long offset, char *buf) {
310 int offs_hours, offs_minutes, sgn = 1;
311 if (offset < 0) {
312 offset = -offset;
313 sgn = 1;
314 }
315 offs_hours = (int)(offset/3600);
316 offs_minutes = (offset%3600)/60;
317
318 char* s = buf;
319
320 *(s++) = sgn == 1 ? '+' : '-';
321 *(s++) = (char)(offs_hours/10) + '0';
322 *(s++) = offs_hours%10 + '0';
323
324 if (offs_minutes == 0) {
325 *(s++) = '\0';
326 } else {
327 *(s++) = (char)(offs_minutes/10) + '0';
328 *(s++) = offs_minutes%10 + '0';
329 *(s++) = '\0';
330 }
331 }
332
308 DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Time_dump, union avp_value * avp_value) 333 DECLARE_FD_DUMP_PROTOTYPE(fd_dictfct_Time_dump, union avp_value * avp_value)
309 { 334 {
310 time_t val; 335 time_t val;
311 struct tm conv; 336 struct tm conv;
337 char tz_buf[7];
312 338
313 FD_DUMP_HANDLE_OFFSET(); 339 FD_DUMP_HANDLE_OFFSET();
314 340
315 if (avp_value->os.len != 4) { 341 if (avp_value->os.len != 4) {
316 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[invalid length: %zd]", avp_value->os.len), return NULL); 342 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[invalid length: %zd]", avp_value->os.len), return NULL);
320 if (diameter_string_to_time_t((char *)avp_value->os.data, avp_value->os.len, &val) != 0) { 346 if (diameter_string_to_time_t((char *)avp_value->os.data, avp_value->os.len, &val) != 0) {
321 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[time conversion error]"), return NULL); 347 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "[time conversion error]"), return NULL);
322 return *buf; 348 return *buf;
323 } 349 }
324 350
325 CHECK_MALLOC_DO ( gmtime_r(&val, &conv), return NULL); 351 CHECK_MALLOC_DO( localtime_r(&val, &conv), return NULL);
326 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "%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), return NULL); 352 _format_offs(conv.tm_gmtoff, tz_buf);
353 CHECK_MALLOC_DO( fd_dump_extend(FD_DUMP_STD_PARAMS, "%d%02d%02dT%02d%02d%02d%s", conv.tm_year+1900, conv.tm_mon+1, conv.tm_mday, conv.tm_hour, conv.tm_min, conv.tm_sec, tz_buf), return NULL);
327 return *buf; 354 return *buf;
328 } 355 }
329 356
"Welcome to our mercurial repository"