string.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  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. /* string.c - common string syntax routines */
  42. #include <stdio.h>
  43. #include <string.h>
  44. #include <sys/types.h>
  45. #include "syntax.h"
  46. #if defined(IRIX)
  47. #include <unistd.h>
  48. #endif
  49. static int string_filter_approx( struct berval *bvfilter,
  50. Slapi_Value **bvals, Slapi_Value **retVal );
  51. static void substring_comp_keys( Slapi_Value ***ivals, int *nsubs, char *str,
  52. int prepost, int syntax );
  53. int
  54. string_filter_ava( struct berval *bvfilter, Slapi_Value **bvals, int syntax,
  55. int ftype, Slapi_Value **retVal )
  56. {
  57. int i, rc;
  58. struct berval bvfilter_norm;
  59. if(retVal) {
  60. *retVal = NULL;
  61. }
  62. if ( ftype == LDAP_FILTER_APPROX ) {
  63. return( string_filter_approx( bvfilter, bvals, retVal ) );
  64. }
  65. bvfilter_norm.bv_val = slapi_ch_malloc( bvfilter->bv_len + 1 );
  66. SAFEMEMCPY( bvfilter_norm.bv_val, bvfilter->bv_val, bvfilter->bv_len );
  67. bvfilter_norm.bv_val[bvfilter->bv_len] = '\0';
  68. value_normalize( bvfilter_norm.bv_val, syntax, 1 /* trim leading blanks */ );
  69. for ( i = 0; bvals[i] != NULL; i++ ) {
  70. rc = value_cmp( (struct berval*)slapi_value_get_berval(bvals[i]), &bvfilter_norm, syntax, 1/* Normalise the first value only */ );
  71. switch ( ftype ) {
  72. case LDAP_FILTER_GE:
  73. if ( rc >= 0 ) {
  74. if(retVal) {
  75. *retVal = bvals[i];
  76. }
  77. slapi_ch_free ((void**)&bvfilter_norm.bv_val);
  78. return( 0 );
  79. }
  80. break;
  81. case LDAP_FILTER_LE:
  82. if ( rc <= 0 ) {
  83. if(retVal) {
  84. *retVal = bvals[i];
  85. }
  86. slapi_ch_free ((void**)&bvfilter_norm.bv_val);
  87. return( 0 );
  88. }
  89. break;
  90. case LDAP_FILTER_EQUALITY:
  91. if ( rc == 0 ) {
  92. if(retVal) {
  93. *retVal = bvals[i];
  94. }
  95. slapi_ch_free ((void**)&bvfilter_norm.bv_val);
  96. return( 0 );
  97. }
  98. break;
  99. }
  100. }
  101. slapi_ch_free ((void**)&bvfilter_norm.bv_val);
  102. return( -1 );
  103. }
  104. static int
  105. string_filter_approx( struct berval *bvfilter, Slapi_Value **bvals,
  106. Slapi_Value **retVal)
  107. {
  108. int i, rc;
  109. int ava_wordcount;
  110. char *w1, *w2, *c1, *c2;
  111. /*
  112. * try to match words in each filter value in order
  113. * in the attribute value.
  114. * XXX should do this once for the filter and save it XXX
  115. */
  116. rc = -1;
  117. if(retVal) {
  118. *retVal = NULL;
  119. }
  120. for ( i = 0; bvals[i] != NULL; i++ ) {
  121. w2 = (char*)slapi_value_get_string(bvals[i]); /* JCM cast */
  122. ava_wordcount = 0;
  123. /* for each word in the filter value */
  124. for ( w1 = first_word( bvfilter->bv_val ); w1 != NULL;
  125. w1 = next_word( w1 ) ) {
  126. ++ava_wordcount;
  127. if ( (c1 = phonetic( w1 )) == NULL ) {
  128. break;
  129. }
  130. /*
  131. * for each word in the attribute value from
  132. * where we left off...
  133. */
  134. for ( w2 = first_word( w2 ); w2 != NULL;
  135. w2 = next_word( w2 ) ) {
  136. c2 = phonetic( w2 );
  137. rc = strcmp( c1, c2 );
  138. slapi_ch_free((void**)&c2 );
  139. if ( rc == 0 ) {
  140. if(retVal) {
  141. *retVal = bvals[i];
  142. }
  143. break;
  144. }
  145. }
  146. slapi_ch_free((void**)&c1 );
  147. /*
  148. * if we stopped because we ran out of words
  149. * before making a match, go on to the next
  150. * value. otherwise try to keep matching
  151. * words in this value from where we left off.
  152. */
  153. if ( w2 == NULL ) {
  154. break;
  155. } else {
  156. w2 = next_word( w2 );
  157. }
  158. }
  159. /*
  160. * if we stopped because we ran out of words and
  161. * we found at leasy one word, we have a match.
  162. */
  163. if ( w1 == NULL && ava_wordcount > 0 ) {
  164. rc = 0;
  165. break;
  166. }
  167. }
  168. LDAPDebug( LDAP_DEBUG_TRACE, "<= string_filter_approx %d\n",
  169. rc, 0, 0 );
  170. return( rc );
  171. }
  172. int
  173. string_filter_sub( Slapi_PBlock *pb, char *initial, char **any, char *final,
  174. Slapi_Value **bvals, int syntax )
  175. {
  176. int i, j, rc;
  177. char *p, *end, *realval, *tmpbuf;
  178. size_t tmpbufsize;
  179. char pat[BUFSIZ];
  180. char buf[BUFSIZ];
  181. char ebuf[BUFSIZ];
  182. LDAPDebug( LDAP_DEBUG_FILTER, "=> string_filter_sub\n",
  183. 0, 0, 0 );
  184. /*
  185. * construct a regular expression corresponding to the
  186. * filter and let regex do the work for each value
  187. * XXX should do this once and save it somewhere XXX
  188. */
  189. pat[0] = '\0';
  190. p = pat;
  191. end = pat + sizeof(pat) - 2; /* leave room for null */
  192. if ( initial != NULL ) {
  193. value_normalize( initial, syntax, 1 /* trim leading blanks */ );
  194. strcpy( p, "^" );
  195. p = strchr( p, '\0' );
  196. /* 2 * in case every char is special */
  197. if ( p + 2 * strlen( initial ) > end ) {
  198. LDAPDebug( LDAP_DEBUG_ANY, "not enough pattern space\n",
  199. 0, 0, 0 );
  200. return( -1 );
  201. }
  202. filter_strcpy_special( p, initial );
  203. p = strchr( p, '\0' );
  204. }
  205. if ( any != NULL ) {
  206. for ( i = 0; any[i] != NULL; i++ ) {
  207. value_normalize( any[i], syntax, 0 /* DO NOT trim leading blanks */ );
  208. /* ".*" + value */
  209. if ( p + 2 * strlen( any[i] ) + 2 > end ) {
  210. LDAPDebug( LDAP_DEBUG_ANY,
  211. "not enough pattern space\n", 0, 0, 0 );
  212. return( -1 );
  213. }
  214. strcpy( p, ".*" );
  215. p = strchr( p, '\0' );
  216. filter_strcpy_special( p, any[i] );
  217. p = strchr( p, '\0' );
  218. }
  219. }
  220. if ( final != NULL ) {
  221. value_normalize( final, syntax, 0 /* DO NOT trim leading blanks */ );
  222. /* ".*" + value */
  223. if ( p + 2 * strlen( final ) + 2 > end ) {
  224. LDAPDebug( LDAP_DEBUG_ANY, "not enough pattern space\n",
  225. 0, 0, 0 );
  226. return( -1 );
  227. }
  228. strcpy( p, ".*" );
  229. p = strchr( p, '\0' );
  230. filter_strcpy_special( p, final );
  231. p = strchr( p, '\0' );
  232. strcpy( p, "$" );
  233. }
  234. /* compile the regex */
  235. slapd_re_lock();
  236. if ( (p = slapd_re_comp( pat )) != 0 ) {
  237. LDAPDebug( LDAP_DEBUG_ANY, "re_comp (%s) failed (%s)\n",
  238. pat, p, 0 );
  239. slapd_re_unlock();
  240. return( -1 );
  241. } else {
  242. LDAPDebug( LDAP_DEBUG_TRACE, "re_comp (%s)\n",
  243. escape_string( pat, ebuf ), 0, 0 );
  244. }
  245. /*
  246. * test the regex against each value
  247. */
  248. rc = -1;
  249. tmpbuf = NULL;
  250. tmpbufsize = 0;
  251. for ( j = 0; bvals[j] != NULL; j++ ) {
  252. int tmprc;
  253. size_t len;
  254. const struct berval *bvp = slapi_value_get_berval(bvals[j]);
  255. len = bvp->bv_len;
  256. if ( len < sizeof(buf) ) {
  257. strcpy( buf, bvp->bv_val );
  258. realval = buf;
  259. } else if ( len < tmpbufsize ) {
  260. strcpy( buf, bvp->bv_val );
  261. realval = tmpbuf;
  262. } else {
  263. tmpbuf = (char *) slapi_ch_realloc( tmpbuf, len + 1 );
  264. strcpy( tmpbuf, bvp->bv_val );
  265. realval = tmpbuf;
  266. }
  267. value_normalize( realval, syntax, 1 /* trim leading blanks */ );
  268. tmprc = slapd_re_exec( realval );
  269. LDAPDebug( LDAP_DEBUG_TRACE, "re_exec (%s) %i\n",
  270. escape_string( realval, ebuf ), tmprc, 0 );
  271. if ( tmprc != 0 ) {
  272. rc = 0;
  273. break;
  274. }
  275. }
  276. slapd_re_unlock();
  277. if ( tmpbuf != NULL ) {
  278. slapi_ch_free((void**)&tmpbuf );
  279. }
  280. LDAPDebug( LDAP_DEBUG_FILTER, "<= string_filter_sub %d\n",
  281. rc, 0, 0 );
  282. return( rc );
  283. }
  284. int
  285. string_values2keys( Slapi_PBlock *pb, Slapi_Value **bvals,
  286. Slapi_Value ***ivals, int syntax, int ftype )
  287. {
  288. int nsubs, numbvals, i, n, j;
  289. Slapi_Value **nbvals;
  290. char *w, *c, *p;
  291. char buf[SUBLEN+1];
  292. switch ( ftype ) {
  293. case LDAP_FILTER_EQUALITY:
  294. /* allocate a new array for the normalized values */
  295. for ( numbvals = 0; bvals[numbvals] != NULL; numbvals++ ) {
  296. /* NULL */
  297. }
  298. nbvals = (Slapi_Value **) slapi_ch_malloc( (numbvals+1) * sizeof(Slapi_Value *));
  299. for ( i = 0; i < numbvals; i++ )
  300. {
  301. c = slapi_ch_strdup(slapi_value_get_string(bvals[i]));
  302. /* if the NORMALIZED flag is set, skip normalizing */
  303. if (!(slapi_value_get_flags(bvals[i]) & SLAPI_ATTR_FLAG_NORMALIZED))
  304. value_normalize( c, syntax, 1 /* trim leading blanks */ );
  305. nbvals[i] = slapi_value_new_string_passin(c);
  306. }
  307. nbvals[i] = NULL;
  308. *ivals = nbvals;
  309. break;
  310. case LDAP_FILTER_APPROX:
  311. /* XXX should not do this twice! XXX */
  312. /* get an upper bound on the number of ivals */
  313. numbvals = 0;
  314. for ( i = 0; bvals[i] != NULL; i++ ) {
  315. for ( w = first_word( (char*)slapi_value_get_string(bvals[i]) ); w != NULL;
  316. w = next_word( w ) ) {
  317. numbvals++;
  318. }
  319. }
  320. nbvals = (Slapi_Value **) slapi_ch_malloc( (numbvals + 1) * sizeof(Slapi_Value *) );
  321. n = 0;
  322. for ( i = 0; bvals[i] != NULL; i++ ) {
  323. for ( w = first_word( (char*)slapi_value_get_string(bvals[i]) ); w != NULL;
  324. w = next_word( w ) ) {
  325. if ( (c = phonetic( w )) != NULL ) {
  326. nbvals[n] = slapi_value_new_string_passin(c);
  327. n++;
  328. }
  329. }
  330. }
  331. nbvals[n] = NULL;
  332. if ( n == 0 ) {
  333. slapi_ch_free((void**)ivals );
  334. return( 0 );
  335. }
  336. *ivals = nbvals;
  337. break;
  338. case LDAP_FILTER_SUBSTRINGS:
  339. {
  340. /* XXX should remove duplicates! XXX */
  341. Slapi_Value *bvdup;
  342. const struct berval *bvp;
  343. nsubs = 0;
  344. for ( i = 0; bvals[i] != NULL; i++ ) {
  345. /*
  346. * Note: this calculation may err on the high side,
  347. * because value_normalize(), which is called below
  348. * before we actually create the substring keys, may
  349. * reduce the length of the value in some cases. For
  350. * example, spaces are removed when space insensitive
  351. * strings are normalized. But it's okay for nsubs to
  352. * be too big. Since the ivals array is NULL terminated,
  353. * the only downside is that we allocate more space than
  354. * we really need.
  355. */
  356. nsubs += slapi_value_get_length(bvals[i]) - SUBLEN + 3;
  357. }
  358. *ivals = (Slapi_Value **) slapi_ch_malloc( (nsubs + 1) * sizeof(Slapi_Value *) );
  359. buf[SUBLEN] = '\0';
  360. n = 0;
  361. bvdup= slapi_value_new();
  362. for ( i = 0; bvals[i] != NULL; i++ )
  363. {
  364. c = slapi_ch_strdup(slapi_value_get_string(bvals[i]));
  365. value_normalize( c, syntax, 1 /* trim leading blanks */ );
  366. slapi_value_set_string_passin(bvdup, c);
  367. bvp = slapi_value_get_berval(bvdup);
  368. /* leading */
  369. if ( bvp->bv_len > SUBLEN - 2 ) {
  370. buf[0] = '^';
  371. for ( j = 0; j < SUBLEN - 1; j++ ) {
  372. buf[j + 1] = bvp->bv_val[j];
  373. }
  374. (*ivals)[n] = slapi_value_new_string(buf);
  375. n++;
  376. }
  377. /* any */
  378. for ( p = bvp->bv_val;
  379. p < (bvp->bv_val + bvp->bv_len - SUBLEN + 1);
  380. p++ ) {
  381. for ( j = 0; j < SUBLEN; j++ ) {
  382. buf[j] = p[j];
  383. }
  384. buf[SUBLEN] = '\0';
  385. (*ivals)[n] = slapi_value_new_string(buf);
  386. n++;
  387. }
  388. /* trailing */
  389. if ( bvp->bv_len > SUBLEN - 2 ) {
  390. p = bvp->bv_val + bvp->bv_len - SUBLEN + 1;
  391. for ( j = 0; j < SUBLEN - 1; j++ ) {
  392. buf[j] = p[j];
  393. }
  394. buf[SUBLEN - 1] = '$';
  395. (*ivals)[n] = slapi_value_new_string(buf);
  396. n++;
  397. }
  398. }
  399. slapi_value_free(&bvdup);
  400. (*ivals)[n] = NULL;
  401. }
  402. break;
  403. }
  404. return( 0 );
  405. }
  406. /* we've added code to make our equality filter processing faster */
  407. int
  408. string_assertion2keys_ava(
  409. Slapi_PBlock *pb,
  410. Slapi_Value *val,
  411. Slapi_Value ***ivals,
  412. int syntax,
  413. int ftype
  414. )
  415. {
  416. int i, numbvals;
  417. size_t len;
  418. char *w, *c;
  419. Slapi_Value *tmpval=NULL;
  420. switch ( ftype ) {
  421. case LDAP_FILTER_EQUALITY_FAST:
  422. /* this code is trying to avoid multiple malloc/frees */
  423. len=slapi_value_get_length(val);
  424. tmpval=(*ivals)[0];
  425. if (len >= tmpval->bv.bv_len) {
  426. tmpval->bv.bv_val=(char *)slapi_ch_malloc(len+1);
  427. }
  428. memcpy(tmpval->bv.bv_val,slapi_value_get_string(val),len);
  429. tmpval->bv.bv_val[len]='\0';
  430. value_normalize(tmpval->bv.bv_val, syntax, 1 /* trim leading blanks */ );
  431. tmpval->bv.bv_len=strlen(tmpval->bv.bv_val);
  432. break;
  433. case LDAP_FILTER_EQUALITY:
  434. (*ivals) = (Slapi_Value **) slapi_ch_malloc( 2 * sizeof(Slapi_Value *) );
  435. (*ivals)[0] = slapi_value_dup( val );
  436. value_normalize( (*ivals)[0]->bv.bv_val, syntax, 1 /* trim leading blanks */ );
  437. (*ivals)[0]->bv.bv_len = strlen( (*ivals)[0]->bv.bv_val );
  438. (*ivals)[1] = NULL;
  439. break;
  440. case LDAP_FILTER_APPROX:
  441. /* XXX should not do this twice! XXX */
  442. /* get an upper bound on the number of ivals */
  443. numbvals = 0;
  444. for ( w = first_word( (char*)slapi_value_get_string(val) ); w != NULL;
  445. w = next_word( w ) ) {
  446. numbvals++;
  447. }
  448. (*ivals) = (Slapi_Value **) slapi_ch_malloc( (numbvals + 1) *
  449. sizeof(Slapi_Value *) );
  450. i = 0;
  451. for ( w = first_word( (char*)slapi_value_get_string(val) ); w != NULL;
  452. w = next_word( w ) ) {
  453. if ( (c = phonetic( w )) != NULL ) {
  454. (*ivals)[i] = slapi_value_new_string_passin(c);
  455. i++;
  456. }
  457. }
  458. (*ivals)[i] = NULL;
  459. if ( i == 0 ) {
  460. slapi_ch_free((void**)ivals );
  461. return( 0 );
  462. }
  463. break;
  464. default:
  465. LDAPDebug( LDAP_DEBUG_ANY,
  466. "string_assertion2keys_ava: unknown ftype 0x%x\n",
  467. ftype, 0, 0 );
  468. break;
  469. }
  470. return( 0 );
  471. }
  472. int
  473. string_assertion2keys_sub(
  474. Slapi_PBlock *pb,
  475. char *initial,
  476. char **any,
  477. char *final,
  478. Slapi_Value ***ivals,
  479. int syntax
  480. )
  481. {
  482. int nsubs, i, len;
  483. *ivals = NULL;
  484. /*
  485. * First figure out how many keys we will return. The answer is based
  486. * on the length of each assertion value. Since normalization may
  487. * reduce the length (such as when spaces are removed from space
  488. * insensitive strings), we call value_normalize() before checking
  489. * the length.
  490. */
  491. nsubs = 0;
  492. if ( initial != NULL ) {
  493. value_normalize( initial, syntax, 0 /* do not trim leading blanks */ );
  494. if ( strlen( initial ) > SUBLEN - 2 ) {
  495. nsubs += strlen( initial ) - SUBLEN + 2;
  496. } else {
  497. initial = NULL; /* save some work later */
  498. }
  499. }
  500. for ( i = 0; any != NULL && any[i] != NULL; i++ ) {
  501. value_normalize( any[i], syntax, 0 /* do not trim leading blanks */ );
  502. len = strlen( any[i] );
  503. if ( len >= SUBLEN ) {
  504. nsubs += len - SUBLEN + 1;
  505. }
  506. }
  507. if ( final != NULL ) {
  508. value_normalize( final, syntax, 0 /* do not trim leading blanks */ );
  509. if ( strlen( final ) > SUBLEN - 2 ) {
  510. nsubs += strlen( final ) - SUBLEN + 2;
  511. } else {
  512. final = NULL; /* save some work later */
  513. }
  514. }
  515. if ( nsubs == 0 ) { /* no keys to return */
  516. return( 0 );
  517. }
  518. /*
  519. * Next, allocated the ivals array and fill it in with the actual
  520. * keys. *ivals is a NULL terminated array of Slapi_Value pointers.
  521. */
  522. *ivals = (Slapi_Value **) slapi_ch_malloc( (nsubs + 1) * sizeof(Slapi_Value *) );
  523. nsubs = 0;
  524. if ( initial != NULL ) {
  525. substring_comp_keys( ivals, &nsubs, initial, '^', syntax );
  526. }
  527. for ( i = 0; any != NULL && any[i] != NULL; i++ ) {
  528. if ( strlen( any[i] ) < SUBLEN ) {
  529. continue;
  530. }
  531. substring_comp_keys( ivals, &nsubs, any[i], 0, syntax );
  532. }
  533. if ( final != NULL ) {
  534. substring_comp_keys( ivals, &nsubs, final, '$', syntax );
  535. }
  536. (*ivals)[nsubs] = NULL;
  537. return( 0 );
  538. }
  539. static void
  540. substring_comp_keys(
  541. Slapi_Value ***ivals,
  542. int *nsubs,
  543. char *str,
  544. int prepost,
  545. int syntax
  546. )
  547. {
  548. int i, len;
  549. char *p;
  550. char buf[SUBLEN + 1];
  551. LDAPDebug( LDAP_DEBUG_TRACE, "=> substring_comp_keys (%s) %d\n",
  552. str, prepost, 0 );
  553. len = strlen( str );
  554. /* prepend ^ for initial substring */
  555. if ( prepost == '^' )
  556. {
  557. buf[0] = '^';
  558. for ( i = 0; i < SUBLEN - 1; i++ )
  559. {
  560. buf[i + 1] = str[i];
  561. }
  562. buf[SUBLEN] = '\0';
  563. (*ivals)[*nsubs] = slapi_value_new_string(buf);
  564. (*nsubs)++;
  565. }
  566. for ( p = str; p < (str + len - SUBLEN + 1); p++ )
  567. {
  568. for ( i = 0; i < SUBLEN; i++ )
  569. {
  570. buf[i] = p[i];
  571. }
  572. buf[SUBLEN] = '\0';
  573. (*ivals)[*nsubs] = slapi_value_new_string(buf);
  574. (*nsubs)++;
  575. }
  576. if ( prepost == '$' )
  577. {
  578. p = str + len - SUBLEN + 1;
  579. for ( i = 0; i < SUBLEN - 1; i++ )
  580. {
  581. buf[i] = p[i];
  582. }
  583. buf[SUBLEN - 1] = '$';
  584. buf[SUBLEN] = '\0';
  585. (*ivals)[*nsubs] = slapi_value_new_string(buf);
  586. (*nsubs)++;
  587. }
  588. LDAPDebug( LDAP_DEBUG_TRACE, "<= substring_comp_keys\n", 0, 0, 0 );
  589. }