#include <unistd.h>#include <ctype.h>#include <string.h>#include "gwlib.h"Include dependency graph for date.c:

Go to the source code of this file.
Defines | |
| #define | MINUTE 60 |
| #define | HOUR (60 * MINUTE) |
| #define | DAY (24 * HOUR) |
Functions | |
| Octstr * | date_format_http (unsigned long unixtime) |
| long | date_convert_universal (struct universaltime *t) |
| long | date_parse_http (Octstr *date) |
| int | date_parse_iso (struct universaltime *ut, Octstr *os) |
| Octstr * | date_create_iso (time_t unixtime) |
| long | date_universal_now (void) |
Variables | |
| unsigned char * | wkday [7] |
| unsigned char * | monthname [12] |
| int | monthstart [12] |
|
|
|
|
|
|
|
|
|
|
|
Definition at line 118 of file date.c. References universaltime::day, universaltime::hour, universaltime::minute, universaltime::month, monthstart, universaltime::second, and universaltime::year. Referenced by at2_pdu_decode_deliver_sm(), date_parse_http(), handle_operation(), main(), soap_parse_mo(), and soap_read_date(). 00119 {
00120 long date;
00121 int leapyears;
00122 long year;
00123
00124 date = (t->year - 1970) * (365 * DAY);
00125
00126 /* If we haven't had this year's leap day yet, pretend it's
00127 * the previous year. */
00128 year = t->year;
00129 if (t->month <= 1)
00130 year--;
00131
00132 /* Add leap years since 1970. The magic number 477 is the value
00133 * this formula would give for 1970 itself. Notice the extra
00134 * effort we make to keep it correct for the year 2100. */
00135 leapyears = (year / 4) - (year / 100) + (year / 400) - 477;
00136 date += leapyears * DAY;
00137
00138 date += monthstart[t->month] * DAY;
00139 date += (t->day - 1) * DAY;
00140 date += t->hour * HOUR;
00141 date += t->minute * MINUTE;
00142 date += t->second;
00143
00144 return date;
00145 }
|
|
|
Definition at line 278 of file date.c. References gw_gmtime(), and octstr_format(). Referenced by soap_mobitai_date_attribute(), and soap_mobitai_validity_date_attribute(). 00279 {
00280 struct tm tm;
00281
00282 tm = gw_gmtime(unixtime);
00283
00284 return octstr_format("%d-%02d-%02dT%02d:%02d:%02dZ",
00285 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
00286 }
|
Here is the call graph for this function:

|
|
Definition at line 89 of file date.c. References gw_gmtime(), monthname, octstr_create, warning(), and wkday. Referenced by add_x_wap_tod(), check_reversible(), http_send_reply(), soap_server(), and wsp_unpack_date_value(). 00090 {
00091 struct tm tm;
00092 unsigned char buffer[30];
00093
00094 tm = gw_gmtime((time_t) unixtime);
00095
00096 /* Make sure gmtime gave us a good date. We check this to
00097 * protect the sprintf call below, which might overflow its
00098 * buffer if the field values are bad. */
00099 if (tm.tm_wday < 0 || tm.tm_wday > 6 ||
00100 tm.tm_mday < 0 || tm.tm_mday > 31 ||
00101 tm.tm_mon < 0 || tm.tm_mon > 11 ||
00102 tm.tm_year < 0 ||
00103 tm.tm_hour < 0 || tm.tm_hour > 23 ||
00104 tm.tm_min < 0 || tm.tm_min > 59 ||
00105 tm.tm_sec < 0 || tm.tm_sec > 61) {
00106 warning(0, "Bad date for timestamp %lu, cannot format.",
00107 unixtime);
00108 return NULL;
00109 }
00110
00111 sprintf(buffer, "%s, %02d %s %04d %02d:%02d:%02d GMT",
00112 wkday[tm.tm_wday], tm.tm_mday, monthname[tm.tm_mon],
00113 tm.tm_year + 1900, tm.tm_hour, tm.tm_min, tm.tm_sec);
00114
00115 return octstr_create(buffer);
00116 }
|
Here is the call graph for this function:

|
|
Definition at line 147 of file date.c. References date_convert_universal(), universaltime::day, error(), universaltime::hour, universaltime::minute, universaltime::month, monthname, octstr_copy, octstr_destroy(), octstr_get_char(), octstr_len(), octstr_parse_long(), octstr_search_char(), octstr_str_compare(), universaltime::second, and universaltime::year. Referenced by check_reversible(), and wsp_pack_date(). 00148 {
00149 long pos;
00150 struct universaltime t;
00151 Octstr *monthstr = NULL;
00152
00153 /* First, skip the leading day-of-week string. */
00154 pos = octstr_search_char(date, ' ', 0);
00155 if (pos < 0 || pos == octstr_len(date) - 1)
00156 return -1;
00157 pos++; /* Skip the space */
00158
00159 /* Distinguish between the three acceptable formats */
00160 if (isdigit(octstr_get_char(date, pos)) &&
00161 octstr_get_char(date, pos + 2) == ' ') {
00162 if (octstr_len(date) - pos < (long)strlen("06 Nov 1994 08:49:37 GMT"))
00163 goto error;
00164 if (octstr_parse_long(&t.day, date, pos, 10) != pos + 2)
00165 goto error;
00166 monthstr = octstr_copy(date, pos + 3, 3);
00167 if (octstr_parse_long(&t.year, date, pos + 7, 10) != pos + 11)
00168 goto error;
00169 if (octstr_parse_long(&t.hour, date, pos + 12, 10) != pos + 14)
00170 goto error;
00171 if (octstr_parse_long(&t.minute, date, pos + 15, 10) != pos + 17)
00172 goto error;
00173 if (octstr_parse_long(&t.second, date, pos + 18, 10) != pos + 20)
00174 goto error;
00175 /* Take the GMT part on faith. */
00176 } else if (isdigit(octstr_get_char(date, pos)) &&
00177 octstr_get_char(date, pos + 2) == '-') {
00178 if (octstr_len(date) - pos < (long)strlen("06-Nov-94 08:49:37 GMT"))
00179 goto error;
00180 if (octstr_parse_long(&t.day, date, pos, 10) != pos + 2)
00181 goto error;
00182 monthstr = octstr_copy(date, pos + 3, 3);
00183 if (octstr_parse_long(&t.year, date, pos + 7, 10) != pos + 9)
00184 goto error;
00185 if (t.year > 60)
00186 t.year += 1900;
00187 else
00188 t.year += 2000;
00189 if (octstr_parse_long(&t.hour, date, pos + 10, 10) != pos + 12)
00190 goto error;
00191 if (octstr_parse_long(&t.minute, date, pos + 13, 10) != pos + 15)
00192 goto error;
00193 if (octstr_parse_long(&t.second, date, pos + 16, 10) != pos + 18)
00194 goto error;
00195 /* Take the GMT part on faith. */
00196 } else {
00197 if (octstr_len(date) - pos < (long)strlen(" 6 08:49:37 1994"))
00198 goto error;
00199 monthstr = octstr_copy(date, pos, 3);
00200 if (octstr_parse_long(&t.day, date, pos + 4, 10) != pos + 6)
00201 goto error;
00202 if (octstr_parse_long(&t.hour, date, pos + 7, 10) != pos + 9)
00203 goto error;
00204 if (octstr_parse_long(&t.minute, date, pos + 10, 10) != pos + 12)
00205 goto error;
00206 if (octstr_parse_long(&t.second, date, pos + 13, 10) != pos + 15)
00207 goto error;
00208 if (octstr_parse_long(&t.year, date, pos + 16, 10) != pos + 20)
00209 goto error;
00210 }
00211
00212 for (t.month = 0; t.month < 12; t.month++) {
00213 if (octstr_str_compare(monthstr, monthname[t.month]) == 0)
00214 break;
00215 }
00216 if (t.month == 12)
00217 goto error;
00218
00219 octstr_destroy(monthstr);
00220 return date_convert_universal(&t);
00221
00222 error:
00223 octstr_destroy(monthstr);
00224 return -1;
00225 }
|
Here is the call graph for this function:

|
||||||||||||
|
Definition at line 227 of file date.c. References universaltime::day, gw_isdigit(), universaltime::hour, universaltime::minute, universaltime::month, octstr_get_char(), octstr_parse_long(), universaltime::second, and universaltime::year. Referenced by soap_parse_mo(). 00228 {
00229 long pos = 0;
00230 int c;
00231
00232 /* assign defaults */
00233 ut->month = 0;
00234 ut->day = 1;
00235 ut->hour = 0;
00236 ut->minute = 0;
00237 ut->second = 0;
00238
00239 if ((pos = octstr_parse_long(&(ut->year), os, pos, 10)) < 0)
00240 return -1;
00241 if (ut->year < 70)
00242 ut->year += 2000;
00243 else if (ut->year < 100)
00244 ut->year += 1900;
00245
00246 while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
00247 pos++;
00248 if ((pos = octstr_parse_long(&(ut->month), os, pos, 10)) < 0)
00249 return 0;
00250
00251 /* 0-based months */
00252 if (ut->month > 0)
00253 ut->month--;
00254
00255 while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
00256 pos++;
00257 if ((pos = octstr_parse_long(&(ut->day), os, pos, 10)) < 0)
00258 return 0;
00259
00260 while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
00261 pos++;
00262 if ((pos = octstr_parse_long(&(ut->hour), os, pos, 10)) < 0)
00263 return 0;
00264
00265 while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
00266 pos++;
00267 if ((pos = octstr_parse_long(&(ut->minute), os, pos, 10)) < 0)
00268 return 0;
00269
00270 while ((c = octstr_get_char(os, pos)) != -1 && !gw_isdigit(c))
00271 pos++;
00272 if ((pos = octstr_parse_long(&(ut->second), os, pos, 10)) < 0)
00273 return 0;
00274
00275 return 0;
00276 }
|
Here is the call graph for this function:

|
|
Definition at line 290 of file date.c. Referenced by eq_create_event(), eq_round_trip_time(), io_thread(), send_enquire_link(), smasi_thread(), and smpp_emu_writer(). 00291 {
00292 return (long) time(NULL);
00293 }
|
|
|
Initial value: {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}
Definition at line 72 of file date.c. Referenced by date_format_http(), and date_parse_http(). |
|
|
Initial value: {
0, 31, 59, 90, 120, 151,
181, 212, 243, 273, 304, 334
}
Definition at line 79 of file date.c. Referenced by date_convert_universal(). |
|
|
Initial value: {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
}
Definition at line 68 of file date.c. Referenced by date_format_http(). |