Kannel: Open Source WAP and SMS gateway  svn-r5335
check_date.c File Reference
#include <string.h>
#include "gwlib/gwlib.h"

Go to the source code of this file.

Functions

static void check_reversible (void)
 
int main (void)
 

Function Documentation

◆ check_reversible()

static void check_reversible ( void  )
static

Definition at line 71 of file check_date.c.

References date(), date_format_http(), date_parse_http(), octstr_compare(), octstr_copy, octstr_destroy(), octstr_duplicate, octstr_get_cstr, octstr_read_file(), octstr_search_char(), and warning().

Referenced by main().

72 {
73  Octstr *dates;
74  long pos, endpos, tabpos;
75  Octstr *date, *canondate;
76  long timeval;
77 
78  dates = octstr_read_file("checks/test_dates");
79  if (dates == NULL)
80  return;
81 
82  for (pos = 0; ; pos = endpos + 1) {
83  endpos = octstr_search_char(dates, '\n', pos);
84  if (endpos < 0)
85  break;
86 
87  tabpos = octstr_search_char(dates, '\t', pos);
88 
89  if (tabpos >= 0 && tabpos < endpos) {
90  date = octstr_copy(dates, pos, tabpos - pos);
91  canondate = octstr_copy(dates, tabpos + 1, endpos - tabpos - 1);
92  } else {
93  date = octstr_copy(dates, pos, endpos - pos);
94  canondate = octstr_duplicate(date);
95  }
96 
97  timeval = date_parse_http(date);
98  if (timeval == -1)
99  warning(0, "Could not parse date \"%s\"", octstr_get_cstr(date));
100  else {
101  Octstr *newdate;
102  newdate = date_format_http((unsigned long) timeval);
103  if (octstr_compare(newdate, canondate) != 0) {
104  warning(0, "Date not reversible: \"%s\" becomes \"%s\"",
106  }
107  octstr_destroy(newdate);
108  }
109 
111  octstr_destroy(canondate);
112  }
113 
114  octstr_destroy(dates);
115 }
long date_parse_http(Octstr *date)
Definition: date.c:148
#define octstr_get_cstr(ostr)
Definition: octstr.h:233
#define octstr_copy(ostr, from, len)
Definition: octstr.h:178
long octstr_search_char(const Octstr *ostr, int ch, long pos)
Definition: octstr.c:1012
#define octstr_duplicate(ostr)
Definition: octstr.h:187
void warning(int err, const char *fmt,...)
Definition: log.c:660
void octstr_destroy(Octstr *ostr)
Definition: octstr.c:324
Octstr * octstr_read_file(const char *filename)
Definition: octstr.c:1548
Definition: octstr.c:118
Octstr * date_format_http(unsigned long unixtime)
Definition: date.c:89
static int date(int hex)
int octstr_compare(const Octstr *ostr1, const Octstr *ostr2)
Definition: octstr.c:871

◆ main()

int main ( void  )

Definition at line 118 of file check_date.c.

References check_reversible(), GW_INFO, gwlib_init(), gwlib_shutdown(), and log_set_output_level().

119 {
120  gwlib_init();
123  gwlib_shutdown();
124  return 0;
125 }
void log_set_output_level(enum output_level level)
Definition: log.c:253
static void check_reversible(void)
Definition: check_date.c:71
Definition: log.h:69
void gwlib_shutdown(void)
Definition: gwlib.c:94
void gwlib_init(void)
Definition: gwlib.c:78
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.