]> git.sur5r.net Git - openldap/blobdiff - libraries/liblunicode/ure/ure.c
Full implementation of server identity checking per RFC2830 section 3.6
[openldap] / libraries / liblunicode / ure / ure.c
index 21750349660319cc23bf115de160a17134a110c2..90cea614073b1d21c50079f3fd510c9c0ee18bdc 100644 (file)
@@ -1,3 +1,8 @@
+/* $OpenLDAP$ */
+/*
+ * Copyright 2000 The OpenLDAP Foundation, All Rights Reserved.
+ * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+ */
 /*
  * Copyright 1997, 1998, 1999 Computing Research Labs,
  * New Mexico State University
  * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  */
-#ifndef lint
-static char rcsid[] = "$Id: ure.c,v 1.2 1999/09/21 15:47:43 mleisher Exp $";
-#endif
+/* $Id: ure.c,v 1.2 1999/09/21 15:47:43 mleisher Exp $" */
+
+#include "portable.h"
 
 #include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
+#include <ac/unistd.h>
+#include <ac/string.h>
+
 #include "ure.h"
 
 /*
@@ -251,13 +257,7 @@ typedef struct _ure_dfa_t {
  *************************************************************************/
 
 static void
-#if NeedFunctionPrototypes
 _ure_memmove(char *dest, char *src, unsigned long bytes)
-#else
-_ure_memmove(dest, src, bytes)
-char *dest, *src;
-unsigned long bytes;
-#endif
 {
     long i, j;
 
@@ -301,13 +301,7 @@ unsigned long bytes;
 }
 
 static void
-#ifdef __STDC__
 _ure_push(ucs2_t v, _ure_buffer_t *b)
-#else
-_ure_push(v, b)
-ucs2_t v;
-_ure_buffer_t *b;
-#endif
 {
     _ure_stlist_t *s;
 
@@ -341,12 +335,7 @@ _ure_buffer_t *b;
 }
 
 static ucs2_t
-#ifdef __STDC__
 _ure_peek(_ure_buffer_t *b)
-#else
-_ure_peek(b)
-_ure_buffer_t *b;
-#endif
 {
     if (b == 0 || b->stack.slist_used == 0)
       return _URE_NOOP;
@@ -355,12 +344,7 @@ _ure_buffer_t *b;
 }
 
 static ucs2_t
-#ifdef __STDC__
 _ure_pop(_ure_buffer_t *b)
-#else
-_ure_pop(b)
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t v;
 
@@ -386,15 +370,8 @@ _ure_buffer_t *b;
  * variable, and return the number of characters consumed.
  */
 static unsigned long
-#ifdef __STDC__
 _ure_prop_list(ucs2_t *pp, unsigned long limit, unsigned long *mask,
                _ure_buffer_t *b)
-#else
-_ure_prop_list(pp, limit, mask, b)
-ucs2_t *pp;
-unsigned long limit, *mask;
-_ure_buffer_t *b;
-#endif
 {
     unsigned long n, m;
     ucs2_t *sp, *ep;
@@ -450,14 +427,7 @@ _ure_buffer_t *b;
  * of characters used.
  */
 static unsigned long
-#ifdef __STDC__
 _ure_hex(ucs2_t *np, unsigned long limit, ucs4_t *n)
-#else
-_ure_hex(np, limit, n)
-ucs2_t *np;
-unsigned long limit;
-ucs4_t *n;
-#endif
 {
     ucs2_t i;
     ucs2_t *sp, *ep;
@@ -494,14 +464,7 @@ ucs4_t *n;
  * them in increasing range-start order.
  */
 static void
-#ifdef __STDC__
 _ure_add_range(_ure_ccl_t *ccl, _ure_range_t *r, _ure_buffer_t *b)
-#else
-_ure_add_range(ccl, r, b)
-_ure_ccl_t *ccl;
-_ure_range_t *r;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t i;
     ucs4_t tmp;
@@ -567,11 +530,9 @@ _URE_MATHSYM|_URE_CURRENCYSYM|_URE_OTHERSYM)
 #define _URE_SPACE_MASK  (_URE_SPACESEP|_URE_LINESEP|_URE_PARASEP)
 
 typedef void (*_ure_cclsetup_t)(
-#ifdef __STDC__
     _ure_symtab_t *sym,
     unsigned long mask,
     _ure_buffer_t *b
-#endif
 );
 
 typedef struct {
@@ -583,27 +544,13 @@ typedef struct {
 } _ure_trie_t;
 
 static void
-#ifdef __STDC__
 _ure_ccl_setup(_ure_symtab_t *sym, unsigned long mask, _ure_buffer_t *b)
-#else
-_ure_ccl_setup(sym, mask, b)
-_ure_symtab_t *sym;
-unsigned long mask;
-_ure_buffer_t *b;
-#endif
 {
     sym->props |= mask;
 }
 
 static void
-#ifdef __STDC__
 _ure_space_setup(_ure_symtab_t *sym, unsigned long mask, _ure_buffer_t *b)
-#else
-_ure_space_setup(sym, mask, *b)
-_ure_symtab_t *sym;
-unsigned long mask;
-_ure_buffer_t b;
-#endif
 {
     _ure_range_t range;
 
@@ -625,14 +572,7 @@ _ure_buffer_t b;
 }
 
 static void
-#ifdef __STDC__
 _ure_xdigit_setup(_ure_symtab_t *sym, unsigned long mask, _ure_buffer_t *b)
-#else
-_ure_xdigit_setup(sym, mask, b)
-_ure_symtab_t *sym;
-unsigned long mask;
-_ure_buffer_t *b;
-#endif
 {
     _ure_range_t range;
 
@@ -723,16 +663,8 @@ static _ure_trie_t cclass_trie[] = {
  * trie.
  */
 static unsigned long
-#ifdef __STDC__
 _ure_posix_ccl(ucs2_t *cp, unsigned long limit, _ure_symtab_t *sym,
                _ure_buffer_t *b)
-#else
-_ure_posix_ccl(cp, limit, sym, b)
-ucs2_t *cp;
-unsigned long limit;
-_ure_symtab_t *sym;
-_ure_buffer_t *b;
-#endif
 {
     int i;
     unsigned long n;
@@ -776,16 +708,8 @@ _ure_buffer_t *b;
  * Construct a list of ranges and return the number of characters consumed.
  */
 static unsigned long
-#ifdef __STDC__
 _ure_cclass(ucs2_t *cp, unsigned long limit, _ure_symtab_t *symp,
             _ure_buffer_t *b)
-#else
-_ure_cclass(cp, limit, symp, b)
-ucs2_t *cp;
-unsigned long limit;
-_ure_symtab_t *symp;
-_ure_buffer_t *b;
-#endif
 {
     int range_end;
     unsigned long n;
@@ -954,14 +878,7 @@ _ure_buffer_t *b;
  * Probe for a low surrogate hex code.
  */
 static unsigned long
-#ifdef __STDC__
 _ure_probe_ls(ucs2_t *ls, unsigned long limit, ucs4_t *c)
-#else
-_ure_probe_ls(ls, limit, c)
-ucs2_t *ls;
-unsigned long limit;
-ucs4_t *c;
-#endif
 {
     ucs4_t i, code;
     ucs2_t *sp, *ep;
@@ -982,16 +899,8 @@ ucs4_t *c;
 }
 
 static unsigned long
-#ifdef __STDC__
 _ure_compile_symbol(ucs2_t *sym, unsigned long limit, _ure_symtab_t *symp,
                     _ure_buffer_t *b)
-#else
-_ure_compile_symbol(sym, limit, symp, b)
-ucs2_t *sym;
-unsigned long limit;
-_ure_symtab_t *symp;
-_ure_buffer_t *b;
-#endif
 {
     ucs4_t c;
     ucs2_t *sp, *ep;
@@ -1135,12 +1044,7 @@ _ure_buffer_t *b;
 }
 
 static int
-#ifdef __STDC__
 _ure_sym_neq(_ure_symtab_t *a, _ure_symtab_t *b)
-#else
-_ure_sym_neq(a, b)
-_ure_symtab_t *a, *b;
-#endif
 {
     if (a->type != b->type || a->mods != b->mods || a->props != b->props)
       return 1;
@@ -1161,15 +1065,8 @@ _ure_symtab_t *a, *b;
  * Construct a symbol, but only keep unique symbols.
  */
 static ucs2_t
-#ifdef __stdc__
 _ure_make_symbol(ucs2_t *sym, unsigned long limit, unsigned long *consumed,
                  _ure_buffer_t *b)
-#else
-_ure_make_symbol(sym, limit, consumed, b)
-ucs2_t *sym;
-unsigned long limit, *consumed;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t i;
     _ure_symtab_t *sp, symbol;
@@ -1178,7 +1075,7 @@ _ure_buffer_t *b;
      * Build the next symbol so we can test to see if it is already in the
      * symbol table.
      */
-    (void) memset((char *) &symbol, 0, sizeof(_ure_symtab_t));
+    (void) memset((char *) &symbol, '\0', sizeof(_ure_symtab_t));
     *consumed = _ure_compile_symbol(sym, limit, &symbol, b);
 
     /*
@@ -1209,12 +1106,12 @@ _ure_buffer_t *b;
               realloc((char *) b->symtab,
                       sizeof(_ure_symtab_t) * (b->symtab_size + 8));
         sp = b->symtab + b->symtab_size;
-        (void) memset((char *) sp, 0, sizeof(_ure_symtab_t) << 3);
+        (void) memset((char *) sp, '\0', sizeof(_ure_symtab_t) << 3);
         b->symtab_size += 8;
     }
 
     symbol.id = b->symtab_used++;
-    (void) memcpy((char *) &b->symtab[symbol.id], (char *) &symbol,
+    (void) AC_MEMCPY((char *) &b->symtab[symbol.id], (char *) &symbol,
                   sizeof(_ure_symtab_t));
 
     return symbol.id;
@@ -1227,13 +1124,7 @@ _ure_buffer_t *b;
  *************************************************************************/
 
 static ucs2_t
-#ifdef __stdc__
 _ure_make_expr(ucs2_t type, ucs2_t lhs, ucs2_t rhs, _ure_buffer_t *b)
-#else
-_ure_make_expr(type, lhs, rhs, b)
-ucs2_t type, lhs, rhs;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t i;
 
@@ -1286,14 +1177,7 @@ static unsigned char spmap[] = {
  * reduce to a DFA.  The starting state for the reduction will be returned.
  */
 static ucs2_t
-#ifdef __STDC__
 _ure_re2nfa(ucs2_t *re, unsigned long relen, _ure_buffer_t *b)
-#else
-_ure_re2nfa(re, relen, b)
-ucs2_t *re;
-unsigned long relen;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t c, state, top, sym, *sp, *ep;
     unsigned long used;
@@ -1377,13 +1261,7 @@ _ure_buffer_t *b;
 }
 
 static void
-#ifdef __STDC__
 _ure_add_symstate(ucs2_t sym, ucs2_t state, _ure_buffer_t *b)
-#else
-_ure_add_symstate(sym, state, b)
-ucs2_t sym, state;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t i, *stp;
     _ure_symtab_t *sp;
@@ -1424,13 +1302,7 @@ _ure_buffer_t *b;
 }
 
 static ucs2_t
-#ifdef __STDC__
 _ure_add_state(ucs2_t nstates, ucs2_t *states, _ure_buffer_t *b)
-#else
-_ure_add_state(nstates, states, b)
-ucs2_t nstates, *states;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t i;
     _ure_state_t *sp;
@@ -1455,7 +1327,7 @@ _ure_buffer_t *b;
                   realloc((char *) b->states.states,
                           sizeof(_ure_state_t) * (b->states.states_size + 8));
             sp = b->states.states + b->states.states_size;
-            (void) memset((char *) sp, 0, sizeof(_ure_state_t) << 3);
+            (void) memset((char *) sp, '\0', sizeof(_ure_state_t) << 3);
             b->states.states_size += 8;
         }
 
@@ -1473,7 +1345,7 @@ _ure_buffer_t *b;
             sp->st.slist_size = sp->st.slist_used + nstates;
         }
         sp->st.slist_used = nstates;
-        (void) memcpy((char *) sp->st.slist, (char *) states,
+        (void) AC_MEMCPY((char *) sp->st.slist, (char *) states,
                       sizeof(ucs2_t) * nstates);
     }
 
@@ -1484,13 +1356,7 @@ _ure_buffer_t *b;
 }
 
 static void
-#ifdef __STDC__
 _ure_reduce(ucs2_t start, _ure_buffer_t *b)
-#else
-_ure_reduce(start, b)
-ucs2_t start;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t i, j, state, eval, syms, rhs;
     ucs2_t s1, s2, ns1, ns2;
@@ -1665,13 +1531,7 @@ _ure_buffer_t *b;
 }
 
 static void
-#ifdef __STDC__
 _ure_add_equiv(ucs2_t l, ucs2_t r, _ure_buffer_t *b)
-#else
-_ure_add_equiv(l, r, b)
-ucs2_t l, r;
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t tmp;
 
@@ -1715,12 +1575,7 @@ _ure_buffer_t *b;
  * Merge the DFA states that are equivalent.
  */
 static void
-#ifdef __STDC__
 _ure_merge_equiv(_ure_buffer_t *b)
-#else
-_ure_merge_equiv(b)
-_ure_buffer_t *b;
-#endif
 {
     ucs2_t i, j, k, eq, done;
     _ure_state_t *sp1, *sp2, *ls, *rs;
@@ -1776,11 +1631,7 @@ _ure_buffer_t *b;
  *************************************************************************/
 
 ure_buffer_t
-#ifdef __STDC__
 ure_buffer_create(void)
-#else
-ure_buffer_create()
-#endif
 {
     ure_buffer_t b;
 
@@ -1790,12 +1641,7 @@ ure_buffer_create()
 }
 
 void
-#ifdef __STDC__
 ure_buffer_free(ure_buffer_t buf)
-#else
-ure_buffer_free(buf)
-ure_buffer_t buf;
-#endif
 {
     unsigned long i;
 
@@ -1833,15 +1679,7 @@ ure_buffer_t buf;
 }
 
 ure_dfa_t
-#ifdef __STDC__
 ure_compile(ucs2_t *re, unsigned long relen, int casefold, ure_buffer_t buf)
-#else
-ure_compile(re, relen, casefold, buf)
-ucs2_t *re;
-unsigned long relen;
-int casefold;
-ure_buffer_t buf;
-#endif
 {
     ucs2_t i, j, state;
     _ure_state_t *sp;
@@ -1894,7 +1732,7 @@ ure_buffer_t buf;
      * Construct the minimal DFA.
      */
     dfa = (ure_dfa_t) malloc(sizeof(_ure_dfa_t));
-    (void) memset((char *) dfa, 0, sizeof(_ure_dfa_t));
+    (void) memset((char *) dfa, '\0', sizeof(_ure_dfa_t));
 
     dfa->flags = buf->flags & (_URE_DFA_CASEFOLD|_URE_DFA_BLANKLINE);
 
@@ -1959,12 +1797,7 @@ ure_buffer_t buf;
 }
 
 void
-#ifdef __STDC__
 ure_dfa_free(ure_dfa_t dfa)
-#else
-ure_dfa_free(dfa)
-ure_dfa_t dfa;
-#endif
 {
     ucs2_t i;
 
@@ -1988,13 +1821,7 @@ ure_dfa_t dfa;
 }
 
 void
-#ifdef __STDC__
 ure_write_dfa(ure_dfa_t dfa, FILE *out)
-#else
-ure_write_dfa(dfa, out)
-ure_dfa_t dfa;
-FILE *out;
-#endif
 {
     ucs2_t i, j, k, h, l;
     _ure_dstate_t *sp;
@@ -2039,8 +1866,8 @@ FILE *out;
                  */
                 if (0x10000 <= rp->min_code &&
                     rp->min_code <= 0x10ffff) {
-                    h = ((rp->min_code - 0x10000) >> 10) + 0xd800;
-                    l = ((rp->min_code - 0x10000) & 1023) + 0xdc00;
+                    h = (ucs2_t) (((rp->min_code - 0x10000) >> 10) + 0xd800);
+                    l = (ucs2_t) (((rp->min_code - 0x10000) & 1023) + 0xdc00);
                     fprintf(out, "\\x%04hX\\x%04hX", h, l);
                 } else
                   fprintf(out, "\\x%04lX", rp->min_code & 0xffff);
@@ -2048,8 +1875,8 @@ FILE *out;
                     putc('-', out);
                     if (rp->max_code >= 0x10000 &&
                         rp->max_code <= 0x10ffff) {
-                        h = ((rp->max_code - 0x10000) >> 10) + 0xd800;
-                        l = ((rp->max_code - 0x10000) & 1023) + 0xdc00;
+                        h = (ucs2_t) (((rp->max_code - 0x10000) >> 10) + 0xd800);
+                        l = (ucs2_t) (((rp->max_code - 0x10000) & 1023) + 0xdc00);
                         fprintf(out, "\\x%04hX\\x%04hX", h, l);
                     } else
                       fprintf(out, "\\x%04lX", rp->max_code & 0xffff);
@@ -2079,8 +1906,8 @@ FILE *out;
                     /*
                      * Take care of UTF16 characters.
                      */
-                    h = ((sym->sym.chr - 0x10000) >> 10) + 0xd800;
-                    l = ((sym->sym.chr - 0x10000) & 1023) + 0xdc00;
+                    h = (ucs2_t) (((sym->sym.chr - 0x10000) >> 10) + 0xd800);
+                    l = (ucs2_t) (((sym->sym.chr - 0x10000) & 1023) + 0xdc00);
                     fprintf(out, "\\x%04hX\\x%04hX ", h, l);
                 } else
                   fprintf(out, "\\x%04lX ", sym->sym.chr & 0xffff);
@@ -2111,16 +1938,8 @@ FILE *out;
                         (cc) == 0x2029)
 
 int
-#ifdef __STDC__
 ure_exec(ure_dfa_t dfa, int flags, ucs2_t *text, unsigned long textlen,
          unsigned long *match_start, unsigned long *match_end)
-#else
-ure_exec(dfa, flags, text, textlen, match_start, match_end)
-ure_dfa_t dfa;
-int flags;
-ucs2_t *text;
-unsigned long textlen, *match_start,  *match_end;
-#endif
 {
     int i, j, matched, found, skip;
     unsigned long ms, me;