blob: 7ebc72d400954d8266beeac64911473987ea9d56 [file] [log] [blame]
akmhoque59980a52012-08-09 12:36:09 -05001#include<stdio.h>
2#include<string.h>
3#include<stdlib.h>
4#include <unistd.h>
5#include <getopt.h>
6#include <sys/time.h>
akmhoque0476dc42012-08-13 09:59:08 -05007#include <time.h>
akmhoque59980a52012-08-09 12:36:09 -05008#include <assert.h>
9#ifdef HAVE_CONFIG_H
10#include <config.h>
11#endif
12
akmhoque53f64222012-09-05 13:57:51 -050013#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
akmhoque59980a52012-08-09 12:36:09 -050020#include "utility.h"
21
22
23char * 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(&ltime);
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
akmhoquec9286692012-08-16 09:57:58 -050037char * 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(&gtime);
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
akmhoque59980a52012-08-09 12:36:09 -050052char *
53nth_named_component(const char *name_prefix, int n)
54{
55
56 int i;
57 char * seps="/";
58 char *rem=NULL;
59 char *component;
60
61 char *prefix=(char *)malloc(strlen(name_prefix)+1);
62 memcpy(prefix,name_prefix,strlen(name_prefix)+1);
63
64 component=strtok_r(prefix,seps,&rem);
65
66 for(i=1;i<n;i++)
67 component=strtok_r(NULL,seps,&rem);
68
69 return component;
70
akmhoquef71d9082012-08-22 12:51:53 -040071}
akmhoque59980a52012-08-09 12:36:09 -050072
akmhoquef71d9082012-08-22 12:51:53 -040073long int
74get_current_time_sec(void)
75{
76 struct timeval now;
77 gettimeofday(&now,NULL);
78 return now.tv_sec;
akmhoque59980a52012-08-09 12:36:09 -050079}
akmhoqued79438d2012-08-27 13:31:42 -050080
81
82long int
83get_current_time_microsec(void)
84{
85 struct timeval now;
86 gettimeofday(&now, NULL);
87 long int microSec=1000000*now.tv_sec+now.tv_usec;
88 return microSec;
89
90}
akmhoque53f64222012-09-05 13:57:51 -050091
92char *
93get_current_timestamp_micro(void)
94{
95 struct timeval now;
96 gettimeofday(&now, NULL);
97
98 char *microSec=(char *)malloc(20);
99 sprintf(microSec,"%ld%06ld",now.tv_sec,(long int)now.tv_usec);
100 microSec[strlen(microSec)]='\0';
101
102 return microSec;
103
104}
105