--- lmtp2nntp_msg.c 2002/04/18 15:38:59 1.7
+++ lmtp2nntp_msg.c 2002/04/23 14:26:32 1.8
@@ -30,6 +30,7 @@
#include "lmtp2nntp_msg.h"
#include "lmtp2nntp_argz.h"
#include "fixme.h" //FIMXE logbook only
+#include "tai.h"
#include "str.h"
@@ -564,6 +565,75 @@
return rc;
}
+static void canonifydate(const char *pVal, const char *pArg)
+{
+ /* RFC0822
+ 5. DATE AND TIME SPECIFICATION
+ 5.1. SYNTAX
+
+ date-time = [ day "," ] date time ; "dd mm yy" or "hh:mm:ss zzz"
+ day = "Mon" / "Tue" / "Wed" / "Thu" / "Fri" / "Sat" / "Sun"
+ date = 1*2DIGIT month 2DIGIT ; day month year e.g. 20 Jun 82
+ month = "Jan" / "Feb"/ "Mar" / "Apr"/ "May" / "Jun"/ "Jul" / "Aug"/ "Sep" / "Oct"/ "Nov" / "Dec"
+ time = hour zone ; ANSI and Military
+ hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT] ; 00:00:00 - 23:59:59
+ zone = "UT" / "GMT" ; Universal Time, North American : UT
+ / "EST" / "EDT" ; Eastern: - 5/ - 4
+ / "CST" / "CDT" ; Central: - 6/ - 5
+ / "MST" / "MDT" ; Mountain: - 7/ - 6
+ / "PST" / "PDT" ; Pacific: - 8/ - 7
+ / 1ALPHA ; Military: Z = UT; A:-1; (J not used); M:-12; N:+1; Y:+12
+ / ( ("+" / "-") 4DIGIT ) ; Local differential hours+min. (HHMM)
+ */
+ tai_t *tm;
+ tai_rc_t rv;
+ char out[32];
+ int i;
+ time_t tim;
+ const struct tm *sttm;
+ int ok;
+ char *fmt[] = {
+ "%a, %d %b %Y %H:%M:%S %z", /* RFC0822 but four digit year */
+ "%a, %d %b %y %H:%M:%S %z", /* RFC0822 strict */
+ "%a, %d %b %Y %H:%M %z", /* RFC0822 but four digit year */
+ "%a, %d %b %y %H:%M %z", /* RFC0822 strict */
+ "%d %b %Y %H:%M:%S %z", /* RFC0822 but four digit year */
+ "%d %b %y %H:%M:%S %z", /* RFC0822 strict */
+ "%d %b %Y %H:%M %z", /* RFC0822 but four digit year */
+ "%d %b %y %H:%M %z", /* RFC0822 strict */
+ "%a %b %d %H:%M:%S %Y", /* strange Mon Jan 27 12:34:56 2001 */
+ NULL };
+
+ printf("DEBUG: pVal=\"%41s\", pArg=\"%s\" ", pVal, pArg);
+ tai_create(&tm);
+ tim = time(NULL);
+ sttm = localtime(&tim);
+ ok = 0;
+ for (i = 0; !ok && (fmt[i] != NULL); i++) {
+ //printf("DEBUG: date=%s, fmt[%d]=%30s ", pArg, i, fmt[i]);
+ if ((rv = tai_parse(tm, pVal, strlen(pVal), fmt[i])) != TAI_OK)
+ ;//printf("FAILED tai_parse() returned %d", rv);
+ else
+ ok = 1;
+#if 0
+ else {
+ if ((rv = tai_format(tm, out, sizeof(out), fmt[i])) != TAI_OK)
+ printf("#%d: tai_format() returned %d", i, rv);
+ if (strcmp(pArg, out) != 0)
+ printf("#%d: output \"%s\", expected \"%s\" (input)", i, out, pArg);
+ }
+#endif
+ //printf("\n");
+ }
+ if (ok) {
+ rv = tai_format(tm, out, sizeof(out), "%a, %d %b %Y %H:%M:%S %z");
+ printf("OK[%d], %s (%d)\n", ok, out, rv);
+ }
+ else
+ printf("FAILED\n");
+ tai_destroy(tm);
+}
+
static var_rc_t operate_cb(
var_t *var, void *ctx,
const char *op_ptr, size_t op_len,
@@ -573,7 +643,6 @@
{
int i;
-fprintf(stderr, "DEBUG: #1 HALLO\n");
if (val_ptr == NULL) {
*out_ptr = "";
*out_len = 0;
@@ -595,10 +664,11 @@
(*out_ptr)[i] = (char)toupper((int)(val_ptr[i]));
return VAR_OK;
}
- else if (op_len == 5 && strncmp(op_ptr, "lower", 5) == 0) {
+ else if (op_len == 12 && strncmp(op_ptr, "canonifydate", 12) == 0) {
*out_ptr = malloc(val_len);
*out_len = val_len;
*out_size = val_len;
+ canonifydate(val_ptr, arg_ptr);
for (i = 0; i < val_len; i++)
(*out_ptr)[i] = (char)tolower((int)(val_ptr[i]));
return VAR_OK;
|