akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 1 | #include<stdio.h> |
| 2 | #include<string.h> |
| 3 | #include<stdlib.h> |
| 4 | #include <unistd.h> |
| 5 | #include <getopt.h> |
| 6 | #include <sys/time.h> |
akmhoque | 0476dc4 | 2012-08-13 09:59:08 -0500 | [diff] [blame] | 7 | #include <time.h> |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 8 | #include <assert.h> |
| 9 | #ifdef HAVE_CONFIG_H |
| 10 | #include <config.h> |
| 11 | #endif |
| 12 | |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 13 | #include <ccn/ccn.h> |
| 14 | #include <ccn/uri.h> |
| 15 | #include <ccn/keystore.h> |
| 16 | #include <ccn/signing.h> |
| 17 | #include <ccn/schedule.h> |
| 18 | #include <ccn/hashtb.h> |
| 19 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 20 | #include "utility.h" |
| 21 | |
| 22 | |
| 23 | char * getLocalTimeStamp(void) |
| 24 | { |
| 25 | char *timestamp = (char *)malloc(sizeof(char) * 16); |
| 26 | time_t ltime; |
| 27 | ltime=time(NULL); |
| 28 | struct tm *tm; |
| 29 | tm=localtime(<ime); |
| 30 | |
| 31 | sprintf(timestamp, "%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon+1, |
| 32 | tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 33 | |
| 34 | return timestamp; |
| 35 | } |
| 36 | |
akmhoque | c928669 | 2012-08-16 09:57:58 -0500 | [diff] [blame] | 37 | char * getGmTimeStamp(void) |
| 38 | { |
| 39 | char *timestamp = (char *)malloc(sizeof(char) * 16); |
| 40 | time_t gtime; |
| 41 | gtime=time(NULL); |
| 42 | struct tm *tm; |
| 43 | tm=gmtime(>ime); |
| 44 | |
| 45 | sprintf(timestamp, "%04d%02d%02d%02d%02d%02d", tm->tm_year+1900, tm->tm_mon+1, |
| 46 | tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); |
| 47 | |
| 48 | return timestamp; |
| 49 | } |
| 50 | |
| 51 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 52 | |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 53 | |
akmhoque | f71d908 | 2012-08-22 12:51:53 -0400 | [diff] [blame] | 54 | long int |
| 55 | get_current_time_sec(void) |
| 56 | { |
| 57 | struct timeval now; |
| 58 | gettimeofday(&now,NULL); |
| 59 | return now.tv_sec; |
akmhoque | 59980a5 | 2012-08-09 12:36:09 -0500 | [diff] [blame] | 60 | } |
akmhoque | d79438d | 2012-08-27 13:31:42 -0500 | [diff] [blame] | 61 | |
| 62 | |
akmhoque | 03004e6 | 2012-09-06 01:12:28 -0500 | [diff] [blame] | 63 | void |
| 64 | get_current_timestamp_micro(char * microSec) |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 65 | { |
| 66 | struct timeval now; |
| 67 | gettimeofday(&now, NULL); |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 68 | sprintf(microSec,"%ld%06ld",now.tv_sec,(long int)now.tv_usec); |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 69 | } |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 70 | |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 71 | |
| 72 | long int |
akmhoque | da5b683 | 2012-09-13 22:33:55 -0500 | [diff] [blame] | 73 | get_time_diff(const char *time1, const char *time2) |
akmhoque | ffacaa8 | 2012-09-13 17:48:30 -0500 | [diff] [blame] | 74 | { |
| 75 | long int diff_secs; |
| 76 | |
| 77 | long int time1_in_sec, time2_in_sec; |
| 78 | |
| 79 | char *time1_sec=(char *)malloc(strlen(time1)-6+1); |
| 80 | memset(time1_sec,0,strlen(time1)-6+1); |
| 81 | memcpy(time1_sec,time1,strlen(time1)-6); |
| 82 | |
| 83 | char *time2_sec=(char *)malloc(strlen(time2)-6+1); |
| 84 | memset(time2_sec,0,strlen(time2)-6+1); |
| 85 | memcpy(time2_sec,time2,strlen(time2)-6); |
| 86 | |
| 87 | time1_in_sec=strtol(time1_sec,NULL,10); |
| 88 | time2_in_sec=strtol(time2_sec,NULL,10); |
| 89 | |
| 90 | diff_secs=time1_in_sec-time2_in_sec; |
| 91 | |
| 92 | free(time1_sec); |
| 93 | free(time2_sec); |
| 94 | |
| 95 | return diff_secs; |
akmhoque | 53f6422 | 2012-09-05 13:57:51 -0500 | [diff] [blame] | 96 | } |
| 97 | |