Change date encoding to use struct tm

This is more flexible, also add decode function.

Signed-off-by: Karsten Keil <kkeil@linux-pingi.de>
This commit is contained in:
Karsten Keil 2011-06-15 14:00:24 +02:00
parent 29b5b2d8d0
commit 05aaa6b832
2 changed files with 36 additions and 9 deletions

View File

@ -20,6 +20,8 @@
#ifndef _Q931_H
#define _Q931_H
#include <time.h>
/*
* Q931 protocol discriminator
*/
@ -282,7 +284,7 @@ extern int mi_encode_redir_nr(struct l3_msg *, char *, int, unsigned int, unsign
extern int mi_encode_useruser(struct l3_msg *, int, int, char *);
extern int mi_encode_cause(struct l3_msg *l, int cause, int, int, unsigned char *);
extern int mi_encode_progress(struct l3_msg *, struct misdn_progress_info *);
extern int mi_encode_date(struct l3_msg *, time_t);
extern int mi_encode_date(struct l3_msg *, struct tm *);
extern int mi_encode_restart_ind(struct l3_msg *, unsigned char);
/* Common IE decode helpers */
@ -297,6 +299,7 @@ extern int mi_decode_called_nr(struct l3_msg *, int *, int *, char *);
extern int mi_decode_redir_nr(struct l3_msg *, int *, int *, int *, int *, int *, char *);
extern int mi_decode_display(struct l3_msg *, char *, int);
extern int mi_decode_useruser(struct l3_msg *, int *, int *, char *, int);
extern int mi_decode_date(struct l3_msg *, struct tm *);
extern int mi_decode_restart_ind(struct l3_msg *, unsigned char *);
/* some print helpers */

View File

@ -568,17 +568,15 @@ mi_encode_progress(struct l3_msg *l3m, struct misdn_progress_info *prg)
}
int
mi_encode_date(struct l3_msg *l3m, time_t ti)
mi_encode_date(struct l3_msg *l3m, struct tm *tm)
{
unsigned char ie[5];
struct tm tm;
localtime_r(&ti, &tm);
ie[0] = tm.tm_year % 100;
ie[1] = tm.tm_mon + 1;
ie[2] = tm.tm_mday;
ie[3] = tm.tm_hour;
ie[4] = tm.tm_min;
ie[0] = tm->tm_year % 100;
ie[1] = tm->tm_mon + 1;
ie[2] = tm->tm_mday;
ie[3] = tm->tm_hour;
ie[4] = tm->tm_min;
return add_layer3_ie(l3m, IE_DATE, 5, ie);
}
@ -933,6 +931,32 @@ mi_decode_useruser(struct l3_msg *l3m, int *pd, int *uulen, char *uu, int maxlen
return 0;
}
int
mi_decode_date(struct l3_msg *l3m, struct tm *dat)
{
struct tm tm;
if (!dat)
return 0;
if (l3m == NULL || !l3m->date)
return 0;
if (*l3m->date < 5)
return 0;
memset(&tm, 0, sizeof(tm));
tm.tm_year = l3m->date[1];
if (tm.tm_year < 70)
tm.tm_year += 100;
tm.tm_mon = l3m->date[2] - 1;
tm.tm_mday = l3m->date[3];
tm.tm_hour = l3m->date[4];
tm.tm_min = l3m->date[5];
_ASSIGN_PVAL(dat, tm);
return 0;
}
int
mi_decode_restart_ind(struct l3_msg *l3m, unsigned char *_class)
{