- * get_next_substring(), rdn_attr_type(), rdn_attr_value(), and
- * build_new_dn().
- *
- * Copyright 1999, Juan C. Gomez, All rights reserved.
- * This software is not subject to any license of Silicon Graphics
- * Inc. or Purdue University.
- *
- * Redistribution and use in source and binary forms are permitted
- * without restriction or fee of any kind as long as this notice
- * is preserved.
- *
- */
-
-/* get_next_substring:
- *
- * Gets next substring in s, using d (or the end of the string '\0') as a
- * string delimiter, and places it in a duplicated memory space. Leading
- * spaces are ignored. String s **must** be null-terminated.
- */
-
-static char *
-get_next_substring( const char * s, char d )
-{
-
- char *str, *r;
-
- r = str = ch_malloc( strlen(s) + 1 );
-
- /* Skip leading spaces */
-
- while ( *s && ASCII_SPACE(*s) ) {
- s++;
- }
-
- /* Copy word */
-
- while ( *s && (*s != d) ) {
-
- /* Don't stop when you see trailing spaces may be a multi-word
- * string, i.e. name=John Doe!
- */
-
- *str++ = *s++;
- }
-
- *str = '\0';
-
- return r;
-
-}
-
-
-/* rdn_attr_type:
- *
- * Given a string (i.e. an rdn) of the form:
- * "attribute_type = attribute_value"
- * this function returns the type of an attribute, that is the
- * string "attribute_type" which is placed in newly allocated
- * memory. The returned string will be null-terminated.
- */
-
-char * rdn_attr_type( const char * s )
-{
- return get_next_substring( s, '=' );
-}
-
-
-/* rdn_attr_value:
- *
- * Given a string (i.e. an rdn) of the form:
- * "attribute_type = attribute_value"
- * this function returns "attribute_type" which is placed in newly allocated
- * memory. The returned string will be null-terminated and may contain
- * spaces (i.e. "John Doe\0").
- */
-
-char *
-rdn_attr_value( const char * rdn )
-{
-
- const char *str;
-
- if ( (str = strchr( rdn, '=' )) != NULL ) {
- return get_next_substring(++str, '\0');
- }
-
- return NULL;
-
-}
-
-
-/* rdn_attrs:
- *
- * Given a string (i.e. an rdn) of the form:
- * "attribute_type=attribute_value[+attribute_type=attribute_value[...]]"
- * this function stores the types of the attributes in ptypes, that is the
- * array of strings "attribute_type" which is placed in newly allocated
- * memory, and the values of the attributes in pvalues, that is the
- * array of strings "attribute_value" which is placed in newly allocated
- * memory. Returns 0 on success, -1 on failure.
- *
- * note: got part of the code from dn_validate
- */
-
-int
-rdn_attrs( const char * rdn_in, char ***ptypes, char ***pvalues)
-{
- char **parts, **p;
-
- *ptypes = NULL;
- *pvalues = NULL;
-
- /*
- * explode the rdn in parts
- */
- parts = ldap_explode_rdn( rdn_in, 0 );
-
- if ( parts == NULL ) {
- return( -1 );
- }
-
- for ( p = parts; p[0]; p++ ) {
- char *s, *e, *d;
-
- /* split each rdn part in type value */
- s = strchr( p[0], '=' );
- if ( s == NULL ) {
- charray_free( *ptypes );
- charray_free( *pvalues );
- charray_free( parts );
- return( -1 );
- }
-
- /* type should be fine */
- charray_add_n( ptypes, p[0], ( s-p[0] ) );
-
- /* value needs to be unescaped
- * (maybe this should be moved to ldap_explode_rdn?) */
- for ( e = d = s + 1; e[0]; e++ ) {
- if ( *e != '\\' ) {
- *d++ = *e;
- }
- }
- d[0] = '\0';
- charray_add( pvalues, s + 1 );
- }
-
- /* free array */
- charray_free( parts );
-
- return( 0 );
-}
-
-
-/* rdn_validate:
- *
- * 1 if rdn is a legal rdn;
- * 0 otherwise (including a sequence of rdns)
- *
- * note: got it from dn_rdn; it should be rewritten
- * according to dn_validate