collate.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* collate.c - implementation of indexing, using a Collation */
  42. #include "collate.h"
  43. #include <string.h> /* memcpy */
  44. #include <unicode/ucol.h> /* Collation */
  45. #include <unicode/ucnv.h> /* Conversion */
  46. #include <unicode/ustring.h> /* UTF8 conversion */
  47. #include <ldap.h> /* LDAP_UTF8LEN */
  48. #include <slap.h> /* for strcasecmp on non-UNIX platforms and correct debug macro */
  49. void
  50. collation_init( char *configpath )
  51. /* Called once per process, to initialize globals. */
  52. {
  53. /* ICU needs no initialization? */
  54. }
  55. typedef struct coll_profile_t { /* Collator characteristics */
  56. const char* language;
  57. const char* country;
  58. const char* variant;
  59. UColAttributeValue strength; /* one of UCOL_PRIMARY = 0, UCOL_SECONDARY = 1, UCOL_TERTIARY = 2, UCOL_QUATERNARY = 3, UCOL_IDENTICAL = 4 */
  60. UColAttributeValue decomposition; /* one of UCOL_OFF = 0, UCOL_DEFAULT = 1, UCOL_ON = 2 */
  61. } coll_profile_t;
  62. typedef struct coll_id_t { /* associates an OID with a coll_profile_t */
  63. char* oid;
  64. coll_profile_t* profile;
  65. } coll_id_t;
  66. /* A list of all OIDs that identify collator profiles: */
  67. static const coll_id_t** collation_id = NULL;
  68. static size_t collation_ids = 0;
  69. int
  70. collation_config (size_t cargc, char** cargv,
  71. const char* fname, size_t lineno)
  72. /* Process one line from a configuration file.
  73. Return 0 if it's OK, -1 if it's not recognized.
  74. Any other return value is a process exit code.
  75. */
  76. {
  77. if (cargc <= 0) { /* Bizarre. Oh, well... */
  78. } else if (!strcasecmp (cargv[0], "NLS")) {
  79. /* ignore - not needed anymore with ICU - was used to get path for NLS_Initialize */
  80. } else if (!strcasecmp (cargv[0], "collation")) {
  81. if ( cargc < 7 ) {
  82. LDAPDebug (LDAP_DEBUG_ANY,
  83. "%s: line %lu ignored: only %lu arguments (expected "
  84. "collation language country variant strength decomposition oid ...)\n",
  85. fname, (unsigned long)lineno, (unsigned long)cargc );
  86. } else {
  87. auto size_t arg;
  88. auto coll_profile_t* profile = (coll_profile_t*) slapi_ch_calloc (1, sizeof (coll_profile_t));
  89. if (*cargv[1]) profile->language = slapi_ch_strdup (cargv[1]);
  90. if (*cargv[2]) profile->country = slapi_ch_strdup (cargv[2]);
  91. if (*cargv[3]) profile->variant = slapi_ch_strdup (cargv[3]);
  92. switch (atoi(cargv[4])) {
  93. case 1: profile->strength = UCOL_PRIMARY; break;
  94. case 2: profile->strength = UCOL_SECONDARY; /* no break here? fall through? wtf? */
  95. case 3: profile->strength = UCOL_TERTIARY; break;
  96. case 4: profile->strength = UCOL_IDENTICAL; break;
  97. default: profile->strength = UCOL_SECONDARY;
  98. LDAPDebug (LDAP_DEBUG_ANY,
  99. "%s: line %lu: strength \"%s\" not supported (will use 2)\n",
  100. fname, (unsigned long)lineno, cargv[4]);
  101. break;
  102. }
  103. switch (atoi(cargv[5])) {
  104. case 1: profile->decomposition = UCOL_OFF; break;
  105. case 2: profile->decomposition = UCOL_DEFAULT; /* no break here? fall through? wtf? */
  106. case 3: profile->decomposition = UCOL_ON; break;
  107. default: profile->decomposition = UCOL_DEFAULT;
  108. LDAPDebug (LDAP_DEBUG_ANY,
  109. "%s: line %lu: decomposition \"%s\" not supported (will use 2)\n",
  110. fname, (unsigned long)lineno, cargv[5]);
  111. break;
  112. }
  113. {
  114. char descStr[256];
  115. char nameOrder[256];
  116. char nameSubstring[256];
  117. char oidString[256];
  118. char *tmpStr=NULL;
  119. Slapi_MatchingRuleEntry *mrentry=slapi_matchingrule_new();
  120. if(UCOL_PRIMARY == profile->strength) {
  121. strcpy(nameOrder,"caseIgnoreOrderingMatch");
  122. strcpy(nameSubstring,"caseIgnoreSubstringMatch");
  123. }
  124. else {
  125. strcpy(nameOrder,"caseExactOrderingMatch");
  126. strcpy(nameSubstring,"caseExactSubstringMatch");
  127. }
  128. /* PAR: this looks broken
  129. the "extra" text based oids that are actually used
  130. to form the name and description are always derived
  131. from the language and country fields so there should
  132. be no need to have two separate code paths to
  133. set the name and description fields of the schema
  134. as language is always available, and if country is
  135. not, it is not in the name anyway.
  136. Is it safe to assume all matching rules will follow
  137. this convention? The answer, or lack of it, probably
  138. explains the reasoning for doing things the way they
  139. are currently.
  140. */
  141. if(cargc > 7) {
  142. PL_strcatn(nameOrder,sizeof(nameOrder),"-");
  143. PL_strcatn(nameOrder,sizeof(nameOrder),cargv[7]);
  144. PL_strcatn(nameSubstring,sizeof(nameSubstring),"-");
  145. PL_strcatn(nameSubstring,sizeof(nameSubstring),cargv[7]);
  146. slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_NAME,
  147. (void *)slapi_ch_strdup(nameOrder));
  148. }
  149. else {
  150. if(0 != cargv[1][0]) {
  151. PL_strcatn(nameOrder,sizeof(nameOrder),"-");
  152. PL_strcatn(nameSubstring,sizeof(nameSubstring),"-");
  153. } else {
  154. nameOrder[0] = 0;
  155. nameSubstring[0] = 0;
  156. }
  157. PL_strcatn(nameOrder,sizeof(nameOrder),cargv[1]);
  158. PL_strcatn(nameSubstring,sizeof(nameSubstring),cargv[1]);
  159. slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_NAME,
  160. (void *)slapi_ch_strdup(nameOrder));
  161. }
  162. PL_strncpyz(oidString,cargv[6], sizeof(oidString));
  163. slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_OID,
  164. (void *)slapi_ch_strdup(oidString));
  165. if(0 != cargv[2][0]) {
  166. PR_snprintf(descStr, sizeof(descStr), "%s-%s",cargv[1],cargv[2]);
  167. }
  168. else {
  169. PL_strncpyz(descStr,cargv[1], sizeof(descStr));
  170. }
  171. slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_DESC,
  172. (void *)slapi_ch_strdup(descStr));
  173. slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_SYNTAX,
  174. (void *)slapi_ch_strdup(DIRSTRING_SYNTAX_OID));
  175. slapi_matchingrule_register(mrentry);
  176. slapi_matchingrule_get(mrentry,SLAPI_MATCHINGRULE_NAME,
  177. (void *)&tmpStr);
  178. slapi_ch_free((void **)&tmpStr);
  179. slapi_matchingrule_get(mrentry,SLAPI_MATCHINGRULE_OID,
  180. (void *)&tmpStr);
  181. slapi_ch_free((void **)&tmpStr);
  182. slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_NAME,
  183. (void *)slapi_ch_strdup(nameSubstring));
  184. PL_strcatn(oidString,sizeof(oidString),".6");
  185. slapi_matchingrule_set(mrentry,SLAPI_MATCHINGRULE_OID,
  186. (void *)slapi_ch_strdup(oidString));
  187. slapi_matchingrule_register(mrentry);
  188. slapi_matchingrule_free(&mrentry,1);
  189. }
  190. for (arg = 6; arg < cargc; ++arg) {
  191. auto coll_id_t* id = (coll_id_t*) slapi_ch_malloc (sizeof (coll_id_t));
  192. id->oid = slapi_ch_strdup (cargv[arg]);
  193. id->profile = profile;
  194. if (collation_ids <= 0) {
  195. collation_id = (const coll_id_t**) slapi_ch_malloc (2 * sizeof (coll_id_t*));
  196. } else {
  197. collation_id = (const coll_id_t**) slapi_ch_realloc
  198. ((void*)collation_id, (collation_ids + 2) * sizeof (coll_id_t*));
  199. }
  200. collation_id [collation_ids++] = id;
  201. collation_id [collation_ids] = NULL;
  202. }
  203. }
  204. } else {
  205. return -1; /* unrecognized */
  206. }
  207. return 0; /* success */
  208. }
  209. typedef struct collation_indexer_t
  210. /* A kind of indexer, implemented using an ICU Collator */
  211. {
  212. UCollator* collator;
  213. UConverter* converter;
  214. struct berval** ix_keys;
  215. } collation_indexer_t;
  216. /*
  217. Caller must ensure that U == NULL and Ulen == 0 the first time called
  218. */
  219. static UErrorCode
  220. SetUnicodeStringFromUTF_8 (UChar** U, int32_t* Ulen, int *isAlloced, const struct berval* bv)
  221. /* Copy the UTF-8 string bv into the UnicodeString U,
  222. but remove leading and trailing whitespace, and
  223. convert consecutive whitespaces into a single space.
  224. Ulen is set to the number of UChars in the array (not necessarily the number of bytes!)
  225. */
  226. {
  227. size_t n;
  228. int32_t len = 0; /* length of non-space string */
  229. UErrorCode err = U_ZERO_ERROR;
  230. const char* s = bv->bv_val;
  231. const char* begin = NULL; /* will point to beginning of non-space in val */
  232. const char* end = NULL; /* will point to the first space after the last non-space char in val */
  233. int32_t nUchars = 0;
  234. if (!bv->bv_len) { /* no value? */
  235. return U_INVALID_FORMAT_ERROR; /* don't know what else to use here */
  236. }
  237. /* first, set s to the first non-space char in bv->bv_val */
  238. for (n = 0; (n < bv->bv_len) && ldap_utf8isspace((char *)s); ) { /* cast away const */
  239. const char *next = LDAP_UTF8NEXT((char *)s); /* cast away const */
  240. n += (next - s); /* count bytes, not chars */
  241. s = next;
  242. }
  243. begin = s; /* begin points to first non-space char in val */
  244. if (n >= bv->bv_len) { /* value is all spaces? */
  245. return U_INVALID_FORMAT_ERROR; /* don't know what else to use here */
  246. }
  247. s = bv->bv_val + (bv->bv_len-1); /* move s to last char of bv_val */
  248. end = s; /* end points at last char of bv_val - may change below */
  249. /* find the last non-null and non-space char of val */
  250. for (n = bv->bv_len; (n > 0) && (!*s || ldap_utf8isspace((char *)s));) {
  251. const char *prev = LDAP_UTF8PREV((char *)s);
  252. end = prev;
  253. n -= (s - prev); /* count bytes, not chars */
  254. s = prev;
  255. }
  256. /* end now points at last non-null/non-space of val */
  257. if (n == 0) { /* bogus */
  258. return U_INVALID_FORMAT_ERROR; /* don't know what else to use here */
  259. }
  260. len = LDAP_UTF8NEXT((char *)end) - begin;
  261. u_strFromUTF8(*U, *Ulen, &nUchars, begin, len, &err);
  262. if (nUchars > *Ulen) { /* need more space */
  263. if (*isAlloced) { /* realloc space */
  264. *U = (UChar *)slapi_ch_realloc((char *)*U, sizeof(UChar) * nUchars);
  265. } else { /* must use malloc */
  266. *U = (UChar *)slapi_ch_malloc(sizeof(UChar) * nUchars);
  267. *isAlloced = 1; /* no longer using fixed buffer */
  268. }
  269. *Ulen = nUchars;
  270. err = U_ZERO_ERROR; /* reset */
  271. u_strFromUTF8(*U, *Ulen, NULL, begin, len, &err);
  272. } else {
  273. *Ulen = nUchars;
  274. }
  275. return err;
  276. }
  277. static struct berval**
  278. collation_index (indexer_t* ix, struct berval** bvec, struct berval** prefixes)
  279. {
  280. collation_indexer_t* etc = (collation_indexer_t*) ix->ix_etc;
  281. struct berval** keys = NULL;
  282. if (bvec) {
  283. char keyBuffer[128]; /* try to use static space buffer to avoid malloc */
  284. int32_t keyLen = sizeof(keyBuffer);
  285. char* key = keyBuffer; /* but key can grow if necessary */
  286. size_t keyn = 0;
  287. struct berval** bv;
  288. UChar charBuffer[128]; /* try to use static space buffer */
  289. int32_t nChars = sizeof(charBuffer)/sizeof(UChar); /* but grow if necessary */
  290. UChar *chars = charBuffer; /* try to reuse this */
  291. int isAlloced = 0; /* using fixed buffer */
  292. for (bv = bvec; *bv; ++bv) {
  293. /* if chars is allocated, nChars will be the capacity and the number of chars in chars */
  294. /* otherwise, nChars will be the number of chars, which may be less than the capacity */
  295. if (!isAlloced) {
  296. nChars = sizeof(charBuffer)/sizeof(UChar); /* reset */
  297. }
  298. if (U_ZERO_ERROR == SetUnicodeStringFromUTF_8 (&chars, &nChars, &isAlloced, *bv)) {
  299. /* nChars is now the number of UChar in chars, which may be less than the
  300. capacity of charBuffer if not allocated */
  301. struct berval* prefix = prefixes ? prefixes[bv-bvec] : NULL;
  302. const size_t prefixLen = prefix ? prefix->bv_len : 0;
  303. struct berval* bk = NULL;
  304. int32_t realLen; /* real length of key, not keyLen which is buffer size */
  305. /* try to get the sort key using key and keyLen; only grow key
  306. if we need to */
  307. /* can use -1 for char len since the conversion from UTF8
  308. null terminates the string */
  309. realLen = ucol_getSortKey(etc->collator, chars, nChars, (uint8_t *)key, keyLen);
  310. if (realLen > keyLen) { /* need more space */
  311. if (key == keyBuffer) {
  312. key = (char*)slapi_ch_malloc(sizeof(char) * realLen);
  313. } else {
  314. key = (char*)slapi_ch_realloc(key, sizeof(char) * realLen);
  315. }
  316. keyLen = ucol_getSortKey(etc->collator, chars, nChars, (uint8_t *)key, realLen);
  317. }
  318. if (realLen > 0) {
  319. bk = (struct berval*) slapi_ch_malloc (sizeof(struct berval));
  320. bk->bv_len = prefixLen + realLen;
  321. bk->bv_val = slapi_ch_malloc (bk->bv_len + 1);
  322. if (prefixLen) {
  323. memcpy(bk->bv_val, prefix->bv_val, prefixLen);
  324. }
  325. memcpy(bk->bv_val + prefixLen, key, realLen);
  326. bk->bv_val[bk->bv_len] = '\0';
  327. LDAPDebug (LDAP_DEBUG_FILTER, "collation_index(%.*s) %lu bytes\n",
  328. bk->bv_len, bk->bv_val, (unsigned long)bk->bv_len);
  329. keys = (struct berval**)
  330. slapi_ch_realloc ((void*)keys, sizeof(struct berval*) * (keyn + 2));
  331. keys[keyn++] = bk;
  332. keys[keyn] = NULL;
  333. }
  334. }
  335. }
  336. if (chars != charBuffer) { /* realloc'ed, need to free */
  337. slapi_ch_free((void **)&chars);
  338. }
  339. if (key != keyBuffer) { /* realloc'ed, need to free */
  340. slapi_ch_free_string(&key);
  341. }
  342. }
  343. if (etc->ix_keys != NULL) ber_bvecfree (etc->ix_keys);
  344. etc->ix_keys = keys;
  345. return keys;
  346. }
  347. static void
  348. collation_indexer_destroy (indexer_t* ix)
  349. /* The destructor function for a collation-based indexer. */
  350. {
  351. collation_indexer_t* etc = (collation_indexer_t*) ix->ix_etc;
  352. if (etc->converter) {
  353. ucnv_close(etc->converter);
  354. etc->converter = NULL;
  355. }
  356. if (etc->collator) {
  357. ucol_close(etc->collator);
  358. etc->collator = NULL;
  359. }
  360. if (etc->ix_keys != NULL) {
  361. ber_bvecfree (etc->ix_keys);
  362. etc->ix_keys = NULL;
  363. }
  364. slapi_ch_free((void**)&ix->ix_etc);
  365. ix->ix_etc = NULL; /* just for hygiene */
  366. }
  367. static UErrorCode
  368. s_newNamedLocaleFromComponents(char **locale, const char *lang, const char *country, const char *variant)
  369. {
  370. UErrorCode err = U_ZERO_ERROR;
  371. int hasLang = (lang && *lang);
  372. int hasC = (country && *country);
  373. int hasVar = (variant && *variant);
  374. *locale = NULL;
  375. if (hasLang) {
  376. *locale = PR_smprintf("%s%s%s%s%s", lang, (hasC ? "_" : ""), (hasC ? country : ""),
  377. (hasVar ? "_" : ""), (hasVar ? variant : ""));
  378. } else {
  379. err = U_INVALID_FORMAT_ERROR; /* don't know what else to use here */
  380. }
  381. return err;
  382. }
  383. indexer_t*
  384. collation_indexer_create (const char* oid)
  385. /* Return a new indexer, based on the collation identified by oid.
  386. Return NULL if this can't be done.
  387. */
  388. {
  389. indexer_t* ix = NULL;
  390. const coll_id_t** id = collation_id;
  391. char* locale = NULL; /* NULL == default locale */
  392. UCollator* coll = NULL;
  393. collation_indexer_t* etc = NULL;
  394. if (id) for (; *id; ++id) {
  395. if (!strcasecmp (oid, (*id)->oid)) {
  396. const coll_profile_t* profile = (*id)->profile;
  397. const int is_default = (profile->language == NULL &&
  398. profile->country == NULL &&
  399. profile->variant == NULL);
  400. UErrorCode err = U_ZERO_ERROR;
  401. if ( ! is_default) {
  402. err = s_newNamedLocaleFromComponents(&locale,
  403. profile->language,
  404. profile->country,
  405. profile->variant);
  406. }
  407. if (err == U_ZERO_ERROR) {
  408. coll = ucol_open(locale, &err);
  409. /*
  410. * If we found exactly the right collator for this locale,
  411. * or if we found a fallback one, or if we are happy with
  412. * the default, use it.
  413. */
  414. if (err == U_ZERO_ERROR || err == U_USING_FALLBACK_WARNING ||
  415. (err == U_USING_DEFAULT_WARNING && is_default)) {
  416. etc = (collation_indexer_t*) slapi_ch_calloc (1, sizeof (collation_indexer_t));
  417. ix = (indexer_t*) slapi_ch_calloc (1, sizeof (indexer_t));
  418. ucol_setAttribute (coll, UCOL_STRENGTH, profile->strength, &err);
  419. if (err != U_ZERO_ERROR && err != U_USING_FALLBACK_WARNING
  420. && (err != U_USING_DEFAULT_WARNING || !is_default)) {
  421. LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
  422. "set the collator strength for oid %s to %d: err %d\n",
  423. oid, profile->strength, err);
  424. }
  425. ucol_setAttribute (coll, UCOL_DECOMPOSITION_MODE, profile->decomposition, &err);
  426. if (err != U_ZERO_ERROR && err != U_USING_FALLBACK_WARNING
  427. && (err != U_USING_DEFAULT_WARNING || !is_default)) {
  428. LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: could not "
  429. "set the collator decomposition mode for oid %s to %d: err %d\n",
  430. oid, profile->decomposition, err);
  431. }
  432. etc->collator = coll;
  433. for (id = collation_id; *id; ++id) {
  434. if ((*id)->profile == profile) {
  435. break; /* found the 'official' id */
  436. }
  437. }
  438. if (!*id) {
  439. LDAPDebug (LDAP_DEBUG_ANY, "collation_indexer_create: id not found\n", 0, 0, 0);
  440. goto error;
  441. }
  442. ix->ix_etc = etc;
  443. ix->ix_oid = (*id)->oid;
  444. ix->ix_index = collation_index;
  445. ix->ix_destroy = collation_indexer_destroy;
  446. break; /* return */
  447. /* free (etc); */
  448. /* free (ix); */
  449. } else if (err == U_USING_DEFAULT_WARNING) {
  450. LDAPDebug (LDAP_DEBUG_FILTER, "collation_indexer_create: could not "
  451. "create an indexer for OID %s for locale %s and could not "
  452. "use default locale\n",
  453. oid, (locale ? locale : "(default)"), NULL);
  454. } else { /* error */
  455. LDAPDebug (LDAP_DEBUG_FILTER, "collation_indexer_create: could not "
  456. "create an indexer for OID %s for locale %s: err = %d\n",
  457. oid, (locale ? locale : "(default)"), err);
  458. }
  459. if (coll) {
  460. ucol_close (coll);
  461. coll = NULL;
  462. }
  463. }
  464. break; /* failed to create the specified collator */
  465. }
  466. }
  467. goto done;
  468. error:
  469. slapi_ch_free((void **)&etc);
  470. slapi_ch_free((void **)&ix);
  471. if (coll) {
  472. ucol_close (coll);
  473. coll = NULL;
  474. }
  475. done:
  476. if (locale) {
  477. PR_smprintf_free(locale);
  478. locale = NULL;
  479. }
  480. return ix;
  481. }