OSSP CVS Repository

ossp - Difference in ossp-pkg/lmtp2nntp/lmtp2nntp_msg.c versions 1.8 and 1.9
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/lmtp2nntp/lmtp2nntp_msg.c 1.8 -> 1.9

--- lmtp2nntp_msg.c      2002/04/23 14:26:32     1.8
+++ lmtp2nntp_msg.c      2002/04/24 09:26:03     1.9
@@ -565,7 +565,11 @@
     return rc;
 }
 
-static void canonifydate(const char *pVal, const char *pArg)
+#define MAXOUT 32 /* strlen("Mon, 31 Jul 2002 12:34:56 +0123")+1 */
+static var_rc_t canonifydate(
+    const char  *cpArg,  size_t nArg,
+    const char  *cpVal,  size_t nVal,
+          char **cppOut, size_t *pnOut, size_t *pnOutsize)
 {
     /* RFC0822
      5.  DATE AND TIME SPECIFICATION
@@ -585,13 +589,9 @@
                  /  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;
+    int bOk;
     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 */
@@ -603,36 +603,96 @@
         "%d %b %y %H:%M %z",        /* RFC0822 strict */
         "%a %b %d %H:%M:%S %Y",     /* strange Mon Jan 27 12:34:56 2001 */
         NULL };
+    tai_t *now;
+    tai_t *pastrange;
+    tai_t *futurerange;
+    tai_t *value;
 
-    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);
+    tai_create(&now);   //FIXME ex
+    (void /*FIXME*/)tai_import(now, TAI_TYPE_UNIX);
+
+    /* parse argument ([past][,[future]])
+        () (,)     infinite range in the past, infinite range in the future => canonify only
+        (7), (7,)  seven days in the past, infinite range in the future
+        (,3)       infinite range in the past, three days in the future
+        (7,0)      seven days in the past, no point in future allowed
+        (0,3)      no point in past allowed, three days in the future => useless
+        (0,0)      now
+     */
+    pastrange   = NULL; /* infinite */
+    futurerange = NULL; /* infinite */
+    if (cpArg != NULL) {
+        char *cpP, *cpF;
+        cpP = strdupex(cpArg);
+        cpF = strchr(cpP, ',');
+        if (cpF == NULL)
+            cpF = "";
         else
-            ok = 1;
+            *cpF++ = NUL;
+        if (strlen(cpP) != 0) {
+            tai_create(&pastrange);   //FIXME ex
+            (void /*FIXME*/)tai_import(pastrange  , TAI_TYPE_SECONDS, 24*60*60*atoi(cpP));
+        }
+        if (strlen(cpF) != 0) {
+            tai_create(&futurerange); //FIXME ex
+            (void /*FIXME*/)tai_import(futurerange, TAI_TYPE_SECONDS, 24*60*60*atoi(cpF));
+        }
+        free(cpP);
+    }
+
+    printf("DEBUG: cpVal=\"%41s\", cpArg=\"%s\"\n", cpVal, cpArg);
+    if ((cpVal == NULL) || (strlen(cpVal) == 0)) {
+        *cppOut    = (char *)mallocex(MAXOUT);
+        *pnOutsize = MAXOUT;
+        (void /*FIXME*/)tai_format(now, *cppOut, MAXOUT, "%a, %d %b %Y %H:%M:%S %z");
+        *pnOut     = strlen(*cppOut);
+    }
+    else {
+        tai_create(&value);   //FIXME ex
+        bOk = FALSE;
+        for (i = 0; !bOk && (fmt[i] != NULL); i++) {
+            if ((rv = tai_parse(value, cpVal, strlen(cpVal), fmt[i])) == TAI_OK) 
+                bOk = TRUE;
+            //FIXME printf("DEBUG: checked against \"%41s\" returned %d\n", fmt[i], rv);
+        }
+        if (   bOk
 #if 0
+            tai_op is not yet implemented
+            && ((pastrange   != NULL) && (tai_op(value, TAI_OP_GT, pastrange  ) == TAI_OK))
+            && ((futurerange != NULL) && (tai_op(value, TAI_OP_LT, futurerange) == TAI_OK))
+#endif
+            ) {
+            *cppOut    = (char *)mallocex(MAXOUT);
+            *pnOutsize = MAXOUT;
+            (void /*FIXME*/)tai_format(value, *cppOut, MAXOUT, "%a, %d %b %Y %H:%M:%S %z");
+            *pnOut     = strlen(*cppOut);
+        }
         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);
+            /*FIXME interesting lib_var behaviour:
+            *cppOut    = NULL;                returning NULL with size/out=0 means not expandable and keeps the current value
+            *cppOut    = (char *)mallocex(0); returning any freeable pointer with size/out=0 means empty value
+            *pnOutsize = 0;
+            *pnOut     = 0;
+            */
+            *cppOut    = (char *)mallocex(0); //FIXME is this portable?
+            *pnOutsize = 0;
+            *pnOut     = 0;
         }
-#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);
+
+    /* cleanup */
+    if(now != NULL)
+        tai_destroy(now);
+    if(pastrange != NULL)
+        tai_destroy(pastrange);
+    if(futurerange != NULL)
+        tai_destroy(futurerange);
+    if(value != NULL)
+        tai_destroy(value);
+
+    return VAR_OK;
 }
+#undef MAXOUT //FIXME is there a better way to do it?
 
 static var_rc_t operate_cb(
     var_t *var, void *ctx,
@@ -665,13 +725,7 @@
         return VAR_OK;
     }
     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;
+        return canonifydate(arg_ptr, arg_len, val_ptr, val_len, out_ptr, out_len, out_size);
     }
     else 
         return VAR_ERR_UNDEFINED_OPERATION;

CVSTrac 2.0.1