/**
 * File:	include/ldap/routines.ycp
 * Package:	Configuration of LDAP
 * Summary:	Helper routines for string manupulations
 * Authors:	Jiri Suchomel <jsuchome@suse.cz>
 *
 * $Id: routines.ycp 20550 2004-12-14 13:30:31Z jsuchome $
 *
 */

{

textdomain "ldap-client";

import "Ldap";

/**
 * Get RDN (relative distinguished name) from dn
 */
define string get_rdn (string dn) ``{

    list dn_list = splitstring (dn, ",");
    return dn_list[0]:dn;
}

/**
 * Get first value from dn (don't have to be "cn")
 */
define string get_cn (string dn) ``{

    string rdn	= get_rdn (dn);
    return substring (rdn, find (rdn, "=") + 1);
}

/**
 * Create DN from cn by adding base config DN
 * (Can't work in general cases!)
 */
define string get_dn (string cn) ``{

    return sformat ("cn=%1,%2", cn, Ldap::base_config_dn);
}

/**
 * Create new DN from DN by changing leading cn value
 * (Can't work in general cases!)
 */
define string get_new_dn (string cn, string dn) ``{

    return tolower (sformat ("cn=%1%2", cn, substring (dn, find (dn, ","))));
}

/**
 * Get string value of attribute from map.
 * (Generaly, it is supposed to be list or string.)
 */
define string get_string (map object, string attr) ``{

    if (is (object [attr]:nil, list))
	return object [attr,0]:"";
    return (string) (object [attr]:"");
}

}
