]> git.sur5r.net Git - openldap/blobdiff - clients/ud/print.c
Don't depend error handling on exact resultCode.
[openldap] / clients / ud / print.c
index 4185bdaef367e3580a1911e73831b05d6a4f7331..5d4414ee550ca141591cd7a2d6c19a4fb0ce3046 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright (c) 1991, 1993 
  * Regents of the University of Michigan.  All rights reserved.
  * is provided ``as is'' without express or implied warranty.
  */
 
+#include "portable.h"
+
 #include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-#ifndef __STDC__
-#include <memory.h>
-#endif
-#include <time.h>
+
+#include <ac/ctype.h>
+#include <ac/string.h>
+#include <ac/time.h>
+
 #include <lber.h>
 #include <ldap.h>
-#include "ud.h"
 
-#ifdef DEBUG
-extern int debug;
-#endif
+#include "ud.h"
 
 struct entry Entry;
-extern LDAP *ld;
 
-extern void * Malloc();
-extern void Free();
-extern char * my_ldap_dn2ufn();
+static char *time2text(char *ldtimestr, int dateonly);
+static long            gtime(struct tm *tm);
 
 /*
  *  When displaying entries, display only these attributes, and in this
@@ -55,6 +56,8 @@ static char *person_attr_print_order[] = {
        "memberOfGroup",
        "lastModifiedBy",
        "lastModifiedTime",
+       "modifiersname",
+       "modifytimestamp",
        NULL
 };
 
@@ -77,18 +80,21 @@ static char *group_attr_print_order[] = {
        "labeledURL",
        "lastModifiedBy",
        "lastModifiedTime",
+       "modifiersname",
+       "modifytimestamp",
+       "creatorsname",
+       "createtimestamp",
        NULL
 };
 
-parse_answer(s)
-LDAPMessage *s;
+
+void
+parse_answer( LDAPMessage *s )
 {
        int idx;
        char **rdns;
-       BerElement *cookie;
        register LDAPMessage *ep;
        register char *ap;
-       void clear_entry();
 
 #ifdef DEBUG
        if (debug & D_TRACE)
@@ -102,6 +108,7 @@ LDAPMessage *s;
                printf(" Done clearing entry\n");
 #endif
        for (ep = ldap_first_entry(ld, s); ep != NULL; ep = ldap_next_entry(ld, ep)) {
+               BerElement *cookie = NULL;
 #ifdef DEBUG
                if (debug & D_PARSE)
                        printf(" Determining DN and name\n");
@@ -130,6 +137,10 @@ LDAPMessage *s;
                        }
                        add_value(&(Entry.attrs[idx]), ep, ap);
                }
+
+               if( cookie != NULL ) {
+                       ber_free( cookie, 0 );
+               }
        }
 #ifdef DEBUG
        if (debug & D_PARSE)
@@ -137,10 +148,8 @@ LDAPMessage *s;
 #endif
 }
 
-add_value(attr, ep, ap)
-struct attribute *attr;
-LDAPMessage *ep;
-char *ap;
+void
+add_value( struct attribute *attr, LDAPMessage *ep, char *ap )
 {
        register int i = 0;
        char **vp, **tp, **avp;
@@ -185,18 +194,23 @@ char *ap;
        ldap_value_free(vp);
 }
 
-print_an_entry()
+void
+print_an_entry( void )
 {
        int n = 0, i, idx;
        char is_a_group, **order;
        char *sub_list[MAX_VALUES], buf[SMALL_BUF_SIZE];
-       extern int col_size, isaurl(), isadn();
-       static char *time2text();
 
 #ifdef DEBUG
        if (debug & D_TRACE)
                printf("->print_an_entry()\n");
 #endif
+
+       if( Entry.name == NULL ) {
+               printf(" No Entry found.\n");
+               return;
+       }
+
        printf(" \"%s\"\n", Entry.name);
        
        /*
@@ -277,8 +291,8 @@ print_an_entry()
 #define OUT_LABEL_LEN  20
 
 /* prints the values associated with an attribute */
-print_values(A)
-struct attribute A;
+void
+print_values( struct attribute A )
 {
        register int i, k;
        register char *cp, **vp;
@@ -348,7 +362,7 @@ struct attribute A;
                                        putchar('\n');
                                        for (k = lead; k > 0; k--)
                                                putchar(' ');
-                                       while (isspace(*(cp + 1)))
+                                       while (isspace((unsigned char) cp[1]))
                                                cp++;
                                }
                                else
@@ -370,13 +384,12 @@ struct attribute A;
 }
 
 /* prints the DN's associated with an attribute */
-print_DN(A)
-struct attribute A;
+void
+print_DN( struct attribute A )
 {
        int i, lead;
        register char **vp;
        char out_buf[MED_BUF_SIZE], *padding = NULL;
-       extern int col_size;
 
 #ifdef DEBUG
        if (debug & D_TRACE)
@@ -407,10 +420,10 @@ struct attribute A;
        return;
 }
 
-void clear_entry()
+void
+clear_entry( void )
 {
        register int i;
-       extern struct attribute attrlist[];
 
 #ifdef DEBUG
        if (debug & D_TRACE)
@@ -419,7 +432,7 @@ void clear_entry()
                printf(" Clearing entry \"%s\"\n", Entry.name);
 #endif
        if (Entry.DN != NULL)
-               Free(Entry.DN);
+               ldap_memfree(Entry.DN);
        if (Entry.name != NULL)
                Free(Entry.name);
        Entry.may_join = FALSE;
@@ -456,11 +469,10 @@ void clear_entry()
        }
 }
 
-attr_to_index(s)
-char *s;
+int
+attr_to_index( char *s )
 {
        register int i;
-       extern struct attribute attrlist[];
 
        for (i = 0; attrlist[i].quipu_name != NULL; i++)
                if (!strcasecmp(s, attrlist[i].quipu_name))
@@ -468,11 +480,10 @@ char *s;
        return(-1);
 }
 
-void initialize_attribute_strings()
+void
+initialize_attribute_strings( void )
 {
        register int i;
-       extern struct entry Entry;
-       extern struct attribute attrlist[];
 
        for (i = 0; attrlist[i].quipu_name != NULL; i++)
                Entry.attrs[i].quipu_name = attrlist[i].quipu_name;
@@ -481,8 +492,8 @@ void initialize_attribute_strings()
 }
 
 /* prints the URL/label pairs associated with an attribute */
-print_URL(A)
-struct attribute A;
+void
+print_URL( struct attribute A )
 {
        int i, lead;
        register char **vp;
@@ -516,25 +527,20 @@ struct attribute A;
        return;
 }
 
-print_one_URL(s, label_lead, tag, url_lead)
-char *s;
-int label_lead;
-char *tag;
-int url_lead;
+void
+print_one_URL( char *s, int label_lead, char *tag, int url_lead )
 {
        register int i;
        char c, *cp, *url;
-       extern int col_size;
-       extern void Free();
 
-       for (cp = s; !isspace(*cp) && (*cp != '\0'); cp++)
+       for (cp = s; !isspace((unsigned char)*cp) && (*cp != '\0'); cp++)
                ;
        c = *cp;
        *cp = '\0';
        url = strdup(s);
        *cp = c;
        if (*cp != '\0') {
-               for (cp++; isspace(*cp); cp++)
+               for (cp++; isspace((unsigned char)*cp); cp++)
                        ;
        }
        else
@@ -547,7 +553,7 @@ int url_lead;
 }
 
 
-#define GET2BYTENUM( p )       (( *p - '0' ) * 10 + ( *(p+1) - '0' ))
+#define GET2BYTENUM( p )       (( *(p) - '0' ) * 10 + ( *((p)+1) - '0' ))
 
 static char *
 time2text( char *ldtimestr, int dateonly )
@@ -555,21 +561,34 @@ time2text( char *ldtimestr, int dateonly )
     struct tm          t;
     char               *p, *timestr, zone, *fmterr = "badly formatted time";
     time_t             gmttime;
-    static long                gtime();
+       int ndigits;
 
-    memset( (char *)&t, 0, sizeof( struct tm ));
-    if ( 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;
-    t.tm_year = GET2BYTENUM( p ); p += 2;
+
+       if( ndigits == 14) {
+               /* came with a century */
+               /* POSIX says tm_year should be year - 1900 */
+       t.tm_year = 100 * GET2BYTENUM( p ) - 1900;
+               p += 2;
+       } else {
+       t.tm_year = 0;
+       }
+    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;
@@ -585,19 +604,16 @@ time2text( char *ldtimestr, int dateonly )
 
     timestr[ strlen( timestr ) - 1 ] = zone;   /* replace trailing newline */
     if ( dateonly ) {
-       strcpy( timestr + 11, timestr + 20 );
+       SAFEMEMCPY( timestr + 11, timestr + 20, strlen( timestr + 20 ) + 1 );
     }
 
-    Free ( ldtimestr );
     return( strdup( timestr ) );
 }
 
 
 /* gtime.c - inverse gmtime */
 
-#if !defined( MACOS ) && !defined( _WIN32 ) && !defined( DOS )
-#include <sys/time.h>
-#endif /* !MACOS */
+#include <ac/time.h>
 
 /* gtime(): the inverse of localtime().
        This routine was supplied by Mike Accetta at CMU many years ago.
@@ -610,11 +626,24 @@ 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 STDC & 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))
+
+#define YEAR(y) YEAR_CAREFUL(y)
+
 
 /* \f */
 
-static long    gtime ( struct tm *tm )
+static long
+gtime( struct tm *tm )
 {
     register int    i,
                     sec,