diff options
author | Stefan Sperling <ssperling@sysmocom.de> | 2018-12-07 12:30:21 +0100 |
---|---|---|
committer | Stefan Sperling <stsp@stsp.name> | 2018-12-10 16:12:06 +0000 |
commit | 5c14c9ccca83563d07670eb8e9ed5867ca957112 (patch) | |
tree | b36b740fa2a3f8b49cf42baa49eee7c6911e1a08 /src/hlr_vty_subscr.c | |
parent | 705b61bcb795490e265027d0b45499b87dd65e12 (diff) |
display last location update timestamp in vty
Read the subscriber's last location update timestamp from the
database and display it in the output of 'show subscriber'.
For example:
OsmoHLR> show subscriber id 1
ID: 1
IMSI: 123456789000000
MSISDN: 543210123456789
VLR number: 712
SGSN number: 5952
last LU seen: Fri Dec 7 11:30:51 2018 UTC
While the database stores the timestamp as a string, we
convert the timestamp into time_t for internal use.
This allows for flexible potential use of the timestamp
in contexts other than the VTY in the future.
The timestamp displayed in the VTY is created with ctime_r(3).
It does not match the format of the raw string in the database:
sqlite> select id,last_lu_seen from subscriber;
1|2018-12-07 11:30:51
Related: OS#2838
Change-Id: Ie180c434f02ffec0d4b2f651a73258a8126b2e1a
Diffstat (limited to 'src/hlr_vty_subscr.c')
-rw-r--r-- | src/hlr_vty_subscr.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/hlr_vty_subscr.c b/src/hlr_vty_subscr.c index bc6f6a5..92cfa2a 100644 --- a/src/hlr_vty_subscr.c +++ b/src/hlr_vty_subscr.c @@ -20,6 +20,8 @@ #include <inttypes.h> #include <string.h> #include <errno.h> +#include <sys/types.h> +#include <time.h> #include <osmocom/gsm/gsm23003.h> #include <osmocom/vty/vty.h> @@ -33,11 +35,24 @@ struct vty; #define hexdump_buf(buf) osmo_hexdump_nospc((void*)buf, sizeof(buf)) +static char * +get_datestr(const time_t *t, char *datebuf) +{ + char *p, *s = ctime_r(t, datebuf); + + /* Strip trailing newline. */ + p = strchr(s, '\n'); + if (p) + *p = '\0'; + return s; +} + static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr) { int rc; struct osmo_sub_auth_data aud2g; struct osmo_sub_auth_data aud3g; + char datebuf[26]; /* for ctime_r(3) */ vty_out(vty, " ID: %"PRIu64"%s", subscr->id, VTY_NEWLINE); @@ -63,6 +78,8 @@ static void subscr_dump_full_vty(struct vty *vty, struct hlr_subscriber *subscr) vty_out(vty, " PS disabled%s", VTY_NEWLINE); if (subscr->ms_purged_ps) vty_out(vty, " PS purged%s", VTY_NEWLINE); + if (subscr->last_lu_seen) + vty_out(vty, " last LU seen: %s UTC%s", get_datestr(&subscr->last_lu_seen, datebuf), VTY_NEWLINE); if (!*subscr->imsi) return; |