update.
[chise/xemacs-chise.git.1] / src / eldap.c
index 99c5d53..16756e5 100644 (file)
@@ -40,7 +40,7 @@ Boston, MA 02111-1307, USA.  */
 
 #include "eldap.h"
 
-static int ldap_default_port;
+static Fixnum ldap_default_port;
 static Lisp_Object Vldap_default_base;
 
 /* Needed by the lrecord definition */
@@ -120,7 +120,7 @@ print_ldap (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
   print_internal (ldap->host, printcharfun, 1);
   if (!ldap->ld)
     write_c_string ("(dead) ",printcharfun);
-  sprintf (buf, " 0x%x>", (unsigned int)ldap);
+  sprintf (buf, " 0x%lx>", (long)ldap);
   write_c_string (buf, printcharfun);
 }
 
@@ -218,77 +218,73 @@ the LDAP library XEmacs was compiled with: `simple', `krbv41' and `krbv42'.
   int  ldap_sizelimit = 0;
   int  err;
 
-  Lisp_Object list, keyword, value;
-
   CHECK_STRING (host);
 
-  EXTERNAL_PROPERTY_LIST_LOOP (list, keyword, value, plist)
-    {
-      /* TCP Port */
-      if (EQ (keyword, Qport))
-        {
-          CHECK_INT (value);
-          ldap_port = XINT (value);
-        }
-      /* Authentication method */
-      if (EQ (keyword, Qauth))
-        {
-          if (EQ (value, Qsimple))
-            ldap_auth = LDAP_AUTH_SIMPLE;
+  {
+    EXTERNAL_PROPERTY_LIST_LOOP_3 (keyword, value, plist)
+      {
+       /* TCP Port */
+       if (EQ (keyword, Qport))
+         {
+           CHECK_INT (value);
+           ldap_port = XINT (value);
+         }
+       /* Authentication method */
+       if (EQ (keyword, Qauth))
+         {
+           if (EQ (value, Qsimple))
+             ldap_auth = LDAP_AUTH_SIMPLE;
 #ifdef LDAP_AUTH_KRBV41
-          else if (EQ (value, Qkrbv41))
-            ldap_auth = LDAP_AUTH_KRBV41;
+           else if (EQ (value, Qkrbv41))
+             ldap_auth = LDAP_AUTH_KRBV41;
 #endif
 #ifdef LDAP_AUTH_KRBV42
-          else if (EQ (value, Qkrbv42))
-            ldap_auth = LDAP_AUTH_KRBV42;
+           else if (EQ (value, Qkrbv42))
+             ldap_auth = LDAP_AUTH_KRBV42;
 #endif
-          else
-            signal_simple_error ("Invalid authentication method", value);
-        }
-      /* Bind DN */
-      else if (EQ (keyword, Qbinddn))
-        {
-          CHECK_STRING (value);
-         TO_EXTERNAL_FORMAT (LISP_STRING, value,
-                             C_STRING_ALLOCA, ldap_binddn,
-                             Qnative);
-        }
-      /* Password */
-      else if (EQ (keyword, Qpasswd))
-        {
-          CHECK_STRING (value);
-         TO_EXTERNAL_FORMAT (LISP_STRING, value,
-                             C_STRING_ALLOCA, ldap_passwd,
-                             Qnative);
-        }
-      /* Deref */
-      else if (EQ (keyword, Qderef))
-        {
-          if (EQ (value, Qnever))
-            ldap_deref = LDAP_DEREF_NEVER;
-          else if (EQ (value, Qsearch))
-            ldap_deref = LDAP_DEREF_SEARCHING;
-          else if (EQ (value, Qfind))
-            ldap_deref = LDAP_DEREF_FINDING;
-          else if (EQ (value, Qalways))
-            ldap_deref = LDAP_DEREF_ALWAYS;
-          else
-            signal_simple_error ("Invalid deref value", value);
-        }
-      /* Timelimit */
-      else if (EQ (keyword, Qtimelimit))
-        {
-          CHECK_INT (value);
-          ldap_timelimit = XINT (value);
-        }
-      /* Sizelimit */
-      else if (EQ (keyword, Qsizelimit))
-        {
-          CHECK_INT (value);
-          ldap_sizelimit = XINT (value);
-        }
-    }
+           else
+             signal_simple_error ("Invalid authentication method", value);
+         }
+       /* Bind DN */
+       else if (EQ (keyword, Qbinddn))
+         {
+           CHECK_STRING (value);
+           LISP_STRING_TO_EXTERNAL (value, ldap_binddn, Qnative);
+         }
+       /* Password */
+       else if (EQ (keyword, Qpasswd))
+         {
+           CHECK_STRING (value);
+           LISP_STRING_TO_EXTERNAL (value, ldap_passwd, Qnative);
+         }
+       /* Deref */
+       else if (EQ (keyword, Qderef))
+         {
+           if (EQ (value, Qnever))
+             ldap_deref = LDAP_DEREF_NEVER;
+           else if (EQ (value, Qsearch))
+             ldap_deref = LDAP_DEREF_SEARCHING;
+           else if (EQ (value, Qfind))
+             ldap_deref = LDAP_DEREF_FINDING;
+           else if (EQ (value, Qalways))
+             ldap_deref = LDAP_DEREF_ALWAYS;
+           else
+             signal_simple_error ("Invalid deref value", value);
+         }
+       /* Timelimit */
+       else if (EQ (keyword, Qtimelimit))
+         {
+           CHECK_INT (value);
+           ldap_timelimit = XINT (value);
+         }
+       /* Sizelimit */
+       else if (EQ (keyword, Qsizelimit))
+         {
+           CHECK_INT (value);
+           ldap_sizelimit = XINT (value);
+         }
+      }
+  }
 
   if (ldap_port == 0)
     {
@@ -297,7 +293,7 @@ the LDAP library XEmacs was compiled with: `simple', `krbv41' and `krbv42'.
 
   /* Connect to the server and bind */
   slow_down_interrupts ();
-  ld = ldap_open ((char *)XSTRING_DATA (host), ldap_port);
+  ld = ldap_open ((char *) XSTRING_DATA (host), ldap_port);
   speed_up_interrupts ();
 
   if (ld == NULL )
@@ -417,7 +413,7 @@ entry according to the value of WITHDN.
   LDAPMessage *e;
   BerElement *ptr;
   char *a, *dn;
-  int i, rc, rc2;
+  int i, rc;
   int  matches;
   struct ldap_unwind_struct unwind;
 
@@ -426,10 +422,11 @@ entry according to the value of WITHDN.
 
   int speccount = specpdl_depth ();
 
-  Lisp_Object list, entry, result;
+  Lisp_Object list   = Qnil;
+  Lisp_Object entry  = Qnil;
+  Lisp_Object result = Qnil;
   struct gcpro gcpro1, gcpro2, gcpro3;
 
-  list = entry = result = Qnil;
   GCPRO3 (list, entry, result);
 
   unwind.res = NULL;
@@ -476,9 +473,7 @@ entry according to the value of WITHDN.
        {
          Lisp_Object current = XCAR (attrs);
          CHECK_STRING (current);
-         TO_EXTERNAL_FORMAT (LISP_STRING, current,
-                             C_STRING_ALLOCA, ldap_attributes[i],
-                             Qnative);
+         LISP_STRING_TO_EXTERNAL (current, ldap_attributes[i], Qnative);
          ++i;
        }
       ldap_attributes[i] = NULL;
@@ -489,9 +484,9 @@ entry according to the value of WITHDN.
 
   /* Perform the search */
   if (ldap_search (ld,
-                   NILP (base) ? "" : (char *) XSTRING_DATA (base),
+                   NILP (base) ? (char *) "" : (char *) XSTRING_DATA (base),
                    ldap_scope,
-                   NILP (filter) ? "" : (char *) XSTRING_DATA (filter),
+                   NILP (filter) ? (char *) "" : (char *) XSTRING_DATA (filter),
                    ldap_attributes,
                    NILP (attrsonly) ? 0 : 1)
       == -1)
@@ -538,7 +533,7 @@ entry according to the value of WITHDN.
             {
               for (i = 0; unwind.vals[i] != NULL; i++)
                 {
-                  list = Fcons (make_ext_string (unwind.vals[i]->bv_val,
+                  list = Fcons (make_ext_string ((Extbyte *) unwind.vals[i]->bv_val,
                                                  unwind.vals[i]->bv_len,
                                                  Qnative),
                                 list);
@@ -558,11 +553,13 @@ entry according to the value of WITHDN.
     }
 
 #if defined HAVE_LDAP_PARSE_RESULT
-  rc2 = ldap_parse_result (ld, unwind.res,
-                           &rc,
-                           NULL, NULL, NULL, NULL, 0);
-  if (rc2 != LDAP_SUCCESS)
-    rc = rc2;
+  {
+    int rc2 = ldap_parse_result (ld, unwind.res,
+                                &rc,
+                                NULL, NULL, NULL, NULL, 0);
+    if (rc2 != LDAP_SUCCESS)
+      rc = rc2;
+  }
 #else
   if (rc == 0)
     signal_ldap_error (ld, NULL, LDAP_TIMELIMIT_EXCEEDED);
@@ -604,9 +601,12 @@ containing attribute/value string pairs.
   struct berval *bervals;
   int rc;
   int i, j;
+  size_t len;
 
-  Lisp_Object current, values;
+  Lisp_Object current = Qnil;
+  Lisp_Object values  = Qnil;
   struct gcpro gcpro1, gcpro2;
+
   GCPRO2 (current, values);
 
   /* Do all the parameter checking  */
@@ -622,8 +622,9 @@ containing attribute/value string pairs.
     signal_simple_error ("Cannot add void entry", entry);
 
   /* Build the ldap_mods array */
-  ldap_mods = alloca_array (LDAPMod, XINT (Flength (entry)));
-  ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + XINT (Flength (entry)));
+  len = XINT (Flength (entry));
+  ldap_mods = alloca_array (LDAPMod, len);
+  ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
   i = 0;
   EXTERNAL_LIST_LOOP (entry, entry)
     {
@@ -631,17 +632,15 @@ containing attribute/value string pairs.
       CHECK_CONS (current);
       CHECK_STRING (XCAR (current));
       ldap_mods_ptrs[i] = &(ldap_mods[i]);
-      TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (current),
-                         C_STRING_ALLOCA, ldap_mods[i].mod_type,
-                         Qnative);
+      LISP_STRING_TO_EXTERNAL (XCAR (current), ldap_mods[i].mod_type, Qnative);
       ldap_mods[i].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
       values = XCDR (current);
       if (CONSP (values))
         {
-          bervals =
-            alloca_array (struct berval, XINT (Flength (values)));
+         len = XINT (Flength (values));
+          bervals = alloca_array (struct berval, len);
           ldap_mods[i].mod_vals.modv_bvals =
-            alloca_array (struct berval *, 1 + XINT (Flength (values)));
+            alloca_array (struct berval *, 1 + len);
           j = 0;
           EXTERNAL_LIST_LOOP (values, values)
             {
@@ -676,6 +675,7 @@ containing attribute/value string pairs.
     signal_ldap_error (ld, NULL, rc);
 
   UNGCPRO;
+  return Qnil;
 }
 
 DEFUN ("ldap-modify", Fldap_modify, 3, 3, 0, /*
@@ -686,7 +686,7 @@ MODS is a list of modifications to apply.
 A modification is a list of the form (MOD-OP ATTR VALUE1 VALUE2 ...)
 MOD-OP and ATTR are mandatory, VALUEs are optional depending on MOD-OP.
 MOD-OP is the type of modification, one of the symbols `add', `delete'
-or `replace'. ATTR is the LDAP attribute type to modify
+or `replace'. ATTR is the LDAP attribute type to modify.
 */
        (ldap, dn, mods))
 {
@@ -694,12 +694,13 @@ or `replace'. ATTR is the LDAP attribute type to modify
   LDAPMod *ldap_mods, **ldap_mods_ptrs;
   struct berval *bervals;
   int i, j, rc;
+  Lisp_Object mod_op;
+  size_t len;
 
-  Lisp_Object current, mod_op, values;
+  Lisp_Object current = Qnil;
+  Lisp_Object values  = Qnil;
   struct gcpro gcpro1, gcpro2;
 
-  GCPRO2 (current, values);
-
   /* Do all the parameter checking  */
   CHECK_LIVE_LDAP (ldap);
   ld = XLDAP (ldap)->ld;
@@ -713,9 +714,12 @@ or `replace'. ATTR is the LDAP attribute type to modify
     return Qnil;
 
   /* Build the ldap_mods array */
-  ldap_mods = alloca_array (LDAPMod, XINT (Flength (mods)));
-  ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + XINT (Flength (mods)));
+  len = XINT (Flength (mods));
+  ldap_mods = alloca_array (LDAPMod, len);
+  ldap_mods_ptrs = alloca_array (LDAPMod *, 1 + len);
   i = 0;
+
+  GCPRO2 (current, values);
   EXTERNAL_LIST_LOOP (mods, mods)
     {
       current = XCAR (mods);
@@ -734,13 +738,12 @@ or `replace'. ATTR is the LDAP attribute type to modify
         signal_simple_error ("Invalid LDAP modification type", mod_op);
       current = XCDR (current);
       CHECK_STRING (XCAR (current));
-      TO_EXTERNAL_FORMAT (LISP_STRING, XCAR (current),
-                         C_STRING_ALLOCA, ldap_mods[i].mod_type,
-                         Qnative);
+      LISP_STRING_TO_EXTERNAL (XCAR (current), ldap_mods[i].mod_type, Qnative);
       values = XCDR (current);
-      bervals = alloca_array (struct berval, XINT (Flength (values)));
+      len = XINT (Flength (values));
+      bervals = alloca_array (struct berval, len);
       ldap_mods[i].mod_vals.modv_bvals =
-        alloca_array (struct berval *, 1 + XINT (Flength (values)));
+        alloca_array (struct berval *, 1 + len);
       j = 0;
       EXTERNAL_LIST_LOOP (values, values)
         {
@@ -762,6 +765,7 @@ or `replace'. ATTR is the LDAP attribute type to modify
     signal_ldap_error (ld, NULL, rc);
 
   UNGCPRO;
+  return Qnil;
 }
 
 
@@ -783,6 +787,8 @@ DN is the distinguished name of the entry to delete.
   rc = ldap_delete_s (ld, (char *) XSTRING_DATA (dn));
   if (rc != LDAP_SUCCESS)
     signal_ldap_error (ld, NULL, rc);
+
+  return Qnil;
 }
 
 void