]> git.sur5r.net Git - openldap/blobdiff - clients/rcpt500/query.c
Add configure tests for ssize_t and caddr_t and remove NT preamble
[openldap] / clients / rcpt500 / query.c
index fe9c7e88e8954e5b89cfdf09a374ffc4a5aff261..157b5a4bafc7eb7467fe51e7a89b12b805894f39 100644 (file)
@@ -1,3 +1,4 @@
+/* $OpenLDAP$ */
 /*
  * query.c: for rcpt500 (X.500 email query responder)
  *
@@ -8,49 +9,38 @@
 
 #include "portable.h"
 
-#include <stdio.h>
-#include <ctype.h>
+#include <ac/stdlib.h>
 
+#include <ac/ctype.h>
 #include <ac/string.h>
 #include <ac/syslog.h>
 #include <ac/time.h>
 
-#include "lber.h"
-#include "ldap.h"
+#include <stdio.h>
 
-#include "disptmpl.h"
+#include <ldap.h>
+#include <disptmpl.h>
 
 #include "rcpt500.h"
-#include "ldapconfig.h"
-
-extern int dosyslog;
-extern int do_cldap;
-extern int rdncount;
-extern int derefaliases;
-extern int sizelimit;
-extern int ldapport;
-extern char *ldaphost;
-extern char *searchbase;
-extern char *dapuser;
-extern char *filterfile;
-extern char *templatefile;
+#include "ldap_defaults.h"
 
 static char buf[ MAXSIZE ];
 static char *errpreface = "Your query failed: ";
 
-extern int      strcasecmp();
-
-void close_ldap();
+static void close_ldap(LDAP *ld);
+static void append_entry_list(char *rep, char *qu, LDAP *ld, LDAPMessage *msg);
+static int  append_text(void *reply, char *text, ber_len_t len);
+static int  do_read (LDAP *ld, char *dn, char *rep, struct ldap_disptmpl *tmp);
+static void report_ldap_err (LDAP *ldp, char *reply);
+static void remove_trailing_space (char *s);
 
 
 int
-query_cmd( msgp, reply )
-    struct msginfo     *msgp;
-    char               *reply;
+query_cmd( struct msginfo *msgp, char *reply )
 {
     LDAP                       *ldp;
     LDAPMessage                        *ldmsgp, *entry;
-    char                       *s, *dn;
+    char                       *dn;
     int                                matches, rc, ld_errno, ufn;
     LDAPFiltDesc               *lfdp;
     LDAPFiltInfo               *lfi;
@@ -86,7 +76,7 @@ query_cmd( msgp, reply )
        ldp = cldap_open( ldaphost, ldapport );
     else
 #endif /* LDAP_CONNECTIONLESS */
-       ldp = ldap_open( ldaphost, ldapport );
+       ldp = ldap_init( ldaphost, ldapport );
 
     if ( ldp == NULL ) {
        strcat( reply, errpreface );
@@ -224,7 +214,7 @@ query_cmd( msgp, reply )
 }
 
 
-void
+static void
 close_ldap( LDAP *ld )
 {
 #ifdef LDAP_CONNECTIONLESS
@@ -236,11 +226,8 @@ close_ldap( LDAP *ld )
 }
 
 
-append_entry_list( reply, query, ldp, ldmsgp )
-    char       *reply;
-    char       *query;
-    LDAP       *ldp;
-    LDAPMessage        *ldmsgp;
+static void
+append_entry_list( char *reply, char *query, LDAP *ldp, LDAPMessage *ldmsgp )
 {
     LDAPMessage        *e;
     char       *dn, *rdn, *s, **title;
@@ -276,7 +263,7 @@ append_entry_list( reply, query, ldp, ldmsgp )
 
            if (( cn = ldap_get_values( ldp, e, "cn" )) != NULL ) {
                for ( i = 0; cn[i] != NULL; i++ ) {
-                   if ( isdigit( *( cn[i] + strlen( cn[i] ) - 1 ))) {
+                   if ( isdigit((unsigned char) cn[i][strlen( cn[i] ) - 1])) {
                        rdn = strdup( cn[i] );
                        free_rdn = 1;
                        break;
@@ -301,23 +288,16 @@ append_entry_list( reply, query, ldp, ldmsgp )
 }
 
 
-int
-append_text( reply, text, len )
-    char       *reply;
-    char       *text;
-    int                len;
+static int
+append_text( void *reply, char *text, ber_len_t len )
 {
-    strcat( reply, text );
+    strcat( (char *) reply, text );
     return( len );
 }
     
 
-int
-do_read( ldp, dn, reply, tmpll )
-    LDAP                       *ldp;
-    char                       *dn;
-    char                       *reply;
-    struct ldap_disptmpl       *tmpll;
+static int
+do_read( LDAP *ldp, char *dn, char *reply, struct ldap_disptmpl *tmpll )
 {
     int                                rc;
     static char        *maildefvals[] = { "None registered in this service", NULL };
@@ -325,7 +305,7 @@ do_read( ldp, dn, reply, tmpll )
     static char        **defvals[] = { maildefvals, NULL };
 
 
-    rc = ldap_entry2text_search( ldp, dn, searchbase, NULLMSG, tmpll,
+    rc = ldap_entry2text_search( ldp, dn, searchbase, NULL, tmpll,
            defattrs, defvals, append_text, (void *)reply, "\n",
            rdncount, LDAP_DISP_OPT_DOSEARCHACTIONS );
 
@@ -333,9 +313,8 @@ do_read( ldp, dn, reply, tmpll )
 }
 
 
-report_ldap_err( ldp, reply )
-    LDAP       *ldp;
-    char       *reply;
+static void
+report_ldap_err( LDAP *ldp, char *reply )
 {
        int ld_errno = 0;
        ldap_get_option(ldp, LDAP_OPT_ERROR_NUMBER, &ld_errno);
@@ -346,12 +325,12 @@ report_ldap_err( ldp, reply )
 }
 
 
-remove_trailing_space( s )
-    char       *s;
+static void
+remove_trailing_space( char *s )
 {
     char       *p = s + strlen( s ) - 1;
 
-    while ( isspace( *p ) && p > s ) {
+    while ( isspace( (unsigned char) *p ) && p > s ) {
        --p;
     }
     *(++p) = '\0';