]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/tmplout.c
Cast char* argument to hh_to_c() to Byte*
[openldap] / libraries / libldap / tmplout.c
index 823b36a30c1b5f66e492bebf9f4cc48ed66286d4..e603e2009b14cb6b3f1c23c9d45794bb2bf2b404 100644 (file)
@@ -1,3 +1,7 @@
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * tmplout.c:  display template library output routines for LDAP clients
  * 12 April 1994 by Mark C Smith
@@ -8,9 +12,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <ac/socket.h>
-#include <ac/string.h>
 #include <ac/ctype.h>
+#include <ac/string.h>
 #include <ac/time.h>
 
 #ifdef HAVE_SYS_FILE_H
 
 #include "lber.h"
 #include "ldap.h"
+
+#include "ldap_log.h"
 #include "disptmpl.h"
 
+#include "ldap-int.h"
 #include "ldapconfig.h"
 
+/* local functions */
 static int do_entry2text LDAP_P((
        LDAP *ld, char *buf, char *base, LDAPMessage *entry,
        struct ldap_disptmpl *tmpl, char **defattrs, char ***defvals,
@@ -193,7 +200,7 @@ do_entry2text(
            sprintf( buf + strlen( buf ),
                    "%s\">Move Up To <EM>%s</EM></A>%s<BR>",
                    ( vals[ 1 ] == NULL ) ? "??one" : "",
-                   ( untagged != NULL ) ? untagged + 1 : vals[ 1 ], eol, eol );
+                   ( untagged != NULL ) ? untagged + 1 : vals[ 1 ], eol );
            (*writeproc)( writeparm, buf, strlen( buf ));
 
            /*
@@ -249,9 +256,7 @@ do_entry2text(
                freevals = 1;
            }
 
-           if ( islower( *attr )) {    /* cosmetic -- upcase attr. name */
-               *attr = toupper( *attr );
-           }
+           *attr = TOUPPER( (unsigned char) *attr );
 
            err = do_vals2text( ld, buf, vals, attr, labelwidth,
                    LDAP_SYN_CASEIGNORESTR, writeproc, writeparm, eol, 
@@ -260,6 +265,10 @@ do_entry2text(
                ldap_value_free( vals );
            }
        }
+
+       if( ber != NULL) {
+               ber_free( ber, 0 );
+       }
     } else {
        for ( rowp = ldap_first_tmplrow( tmpl );
                NONFATAL_LDAP_ERR( err ) && rowp != NULLTMPLITEM;
@@ -300,14 +309,14 @@ do_entry2text(
                if ( show && LDAP_GET_SYN_TYPE( colp->ti_syntaxid )
                        == LDAP_SYN_TYPE_BOOLEAN && LDAP_IS_TMPLITEM_OPTION_SET(
                        colp, LDAP_DITEM_OPT_HIDEIFFALSE ) &&
-                       toupper( vals[ 0 ][ 0 ] ) != 'T' ) {
+                       TOUPPER( (unsigned char) vals[ 0 ][ 0 ] ) != 'T' ) {
                    show = 0;
                }
 
                if ( colp->ti_syntaxid == LDAP_SYN_SEARCHACTION ) {
                    if (( opts & LDAP_DISP_OPT_DOSEARCHACTIONS ) != 0 ) {
                        if ( colp->ti_attrname == NULL || ( show &&
-                               toupper( vals[ 0 ][ 0 ] ) == 'T' )) {
+                               TOUPPER( (unsigned char) vals[ 0 ][ 0 ] ) == 'T' )) {
                            err = searchaction( ld, buf, base, entry, dn, colp,
                                    labelwidth, rdncount, writeproc,
                                    writeparm, eol, urlprefix );
@@ -671,7 +680,7 @@ do_vals2text(
            p = s = outval;
            while (( s = strchr( s, '$' )) != NULL ) {
                *s++ = '\0';
-               while ( isspace( *s )) {
+               while ( isspace( (unsigned char) *s )) {
                    ++s;
                }
                if ( html ) {
@@ -687,7 +696,7 @@ do_vals2text(
            break;
 
        case LDAP_SYN_BOOLEAN:
-           outval = toupper( outval[ 0 ] ) == 'T' ? "TRUE" : "FALSE";
+           outval = TOUPPER((unsigned char) outval[0]) == 'T' ? "TRUE" : "FALSE";
            ++writeoutval;
            break;
 
@@ -700,13 +709,13 @@ do_vals2text(
        case LDAP_SYN_LABELEDURL:
            if ( !notascii && ( p = strchr( outval, '$' )) != NULL ) {
                *p++ = '\0';
-               while ( isspace( *p )) {
+               while ( isspace( (unsigned char) *p )) {
                    ++p;
                }
                s = outval;
            } else if ( !notascii && ( s = strchr( outval, ' ' )) != NULL ) {
                *s++ = '\0';
-               while ( isspace( *s )) {
+               while ( isspace( (unsigned char) *s )) {
                    ++s;
                }
                p = outval;
@@ -873,20 +882,33 @@ time2text( char *ldtimestr, int dateonly )
     struct tm          t;
     char               *p, *timestr, zone, *fmterr = "badly formatted time";
     time_t             gmttime;
+    char               timebuf[32];
+       int ndigits;
 
-    memset( (char *)&t, 0, sizeof( struct tm ));
-    if ( (int) strlen( ldtimestr ) < 13 ) {
-       return( fmterr );
+       if (strlen( ldtimestr ) < 12 ) {
+               return( fmterr );
+       }
+
+    for ( ndigits=0; isdigit((unsigned char) ldtimestr[ndigits]); ndigits++) {
+               ; /* EMPTY */
     }
 
-    for ( p = ldtimestr; p - ldtimestr < 12; ++p ) {
-       if ( !isdigit( *p )) {
+       if ( ndigits != 12 && ndigits != 14) {
            return( fmterr );
        }
-    }
+       
+    memset( (char *)&t, 0, sizeof( struct tm ));
 
     p = ldtimestr;
+
+       if( ndigits == 14) {
+               /* came with a century */
+               /* POSIX says tm_year should be year - 1900 */
+       t.tm_year = 100 * GET2BYTENUM( p ) - 1900;
+               p += 2;
+       }
     t.tm_year = GET2BYTENUM( p ); p += 2;
+
     t.tm_mon = GET2BYTENUM( p ) - 1; p += 2;
     t.tm_mday = GET2BYTENUM( p ); p += 2;
     t.tm_hour = GET2BYTENUM( p ); p += 2;
@@ -898,11 +920,12 @@ time2text( char *ldtimestr, int dateonly )
     }
 
     gmttime = gtime( &t );
-    timestr = ctime( &gmttime );
 
+    timestr = ldap_pvt_ctime( &gmttime, timebuf );
+   
     timestr[ strlen( timestr ) - 1 ] = zone;   /* replace trailing newline */
     if ( dateonly ) {
-       strcpy( timestr + 11, timestr + 20 );
+       SAFEMEMCPY( timestr + 11, timestr + 20, strlen( timestr + 20 ) + 1 );
     }
 
     return( timestr );
@@ -922,7 +945,27 @@ static int dmsize[] = {
 #define        dysize(y)       \
        (((y) % 4) ? 365 : (((y) % 100) ? 366 : (((y) % 400) ? 365 : 366)))
 
-#define        YEAR(y)         ((y) >= 100 ? (y) : (y) + 1900)
+/*
+ * Y2K YEAR
+ */
+       /* per POSIX tm_year should be offset by 1900 */
+#define YEAR_POSIX(y)          ((y) + 1900)
+
+       /*
+        * year is < 1900, year is offset by 1900
+        */
+#define YEAR_CAREFUL(y)                ((y) < 1900 ? (y) + 1900 : (y))
+
+       /*
+       ** if year is < 1990 and < 70 must be offset by 2000 as Unix epoch
+       ** started in 1970.  if year is < 1990 but >= 70, offset by 1900.
+       ** if year is >= 1900, it must be the real year.
+       */ 
+#define YEAR_PEDANTIC(y)               ((y) < 1900 \
+                                               ? ((y) < 70 ? (y) + 2000 ? (y) + 1900) \
+                                               : (y))
+
+#define YEAR(y) YEAR_CAREFUL(y)
 
 /* \f */