plugin_syntax.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  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. /*
  42. * plugin_syntax.c - routines for calling syntax plugins
  43. */
  44. #include "slap.h"
  45. struct slapdplugin *
  46. plugin_syntax_find( const char *nameoroid )
  47. {
  48. struct slapdplugin *pi;
  49. /* LDAPDebug( LDAP_DEBUG_FILTER, "=> plugin_syntax_find (%s)\n", nameoroid, 0, 0 ); */
  50. for ( pi = get_plugin_list(PLUGIN_LIST_SYNTAX); pi != NULL; pi = pi->plg_next ) {
  51. if ( charray_inlist( pi->plg_syntax_names, (char *)nameoroid ) ) {
  52. break;
  53. }
  54. }
  55. /* LDAPDebug( LDAP_DEBUG_FILTER, "<= plugin_syntax_find %d\n", pi, 0, 0 ); */
  56. return ( pi );
  57. }
  58. /*
  59. * Enumerate all the syntax plugins, calling (*sef)() for each one.
  60. */
  61. void
  62. plugin_syntax_enumerate( SyntaxEnumFunc sef, void *arg )
  63. {
  64. struct slapdplugin *pi;
  65. for ( pi = get_plugin_list(PLUGIN_LIST_SYNTAX); pi != NULL;
  66. pi = pi->plg_next ) {
  67. (*sef)( pi->plg_syntax_names, &pi->plg_desc, arg );
  68. }
  69. }
  70. struct slapdplugin *
  71. slapi_get_global_syntax_plugins()
  72. {
  73. return get_plugin_list(PLUGIN_LIST_SYNTAX);
  74. }
  75. char *
  76. plugin_syntax2oid( struct slapdplugin *pi )
  77. {
  78. return( pi->plg_syntax_oid );
  79. }
  80. int
  81. plugin_call_syntax_get_compare_fn(
  82. void *vpi,
  83. value_compare_fn_type *compare_fn
  84. )
  85. {
  86. struct slapdplugin *pi = vpi;
  87. *compare_fn = NULL;
  88. LDAPDebug( LDAP_DEBUG_TRACE,
  89. "=> plugin_call_syntax_get_compare_fn\n",0,0, 0 );
  90. if ( pi == NULL ) {
  91. LDAPDebug( LDAP_DEBUG_TRACE,
  92. "<= plugin_syntax no plugin for attribute type\n",
  93. 0, 0, 0 );
  94. return( LDAP_PROTOCOL_ERROR ); /* syntax unkonwn */
  95. }
  96. if ( (pi->plg_syntax_flags & SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING) == 0 ) {
  97. return( LDAP_PROTOCOL_ERROR );
  98. }
  99. if (pi->plg_syntax_filter_ava == NULL) {
  100. LDAPDebug( LDAP_DEBUG_ANY, "<= plugin_call_syntax_get_compare_fn: "
  101. "no filter_ava found for attribute type\n", 0, 0, 0 );
  102. return( LDAP_PROTOCOL_ERROR );
  103. }
  104. if (pi->plg_syntax_compare == NULL) {
  105. return( LDAP_PROTOCOL_ERROR );
  106. }
  107. *compare_fn = (value_compare_fn_type) pi->plg_syntax_compare;
  108. LDAPDebug( LDAP_DEBUG_TRACE,
  109. "<= plugin_call_syntax_get_compare_fn \n", 0, 0, 0 );
  110. return( 0 );
  111. }
  112. int
  113. plugin_call_syntax_filter_ava(
  114. const Slapi_Attr *a,
  115. int ftype,
  116. struct ava *ava
  117. )
  118. {
  119. return(plugin_call_syntax_filter_ava_sv(a,ftype,ava,NULL,0 /*Present*/));
  120. }
  121. int
  122. plugin_call_syntax_filter_ava_sv(
  123. const Slapi_Attr *a,
  124. int ftype,
  125. struct ava *ava,
  126. Slapi_Value **retVal,
  127. int useDeletedValues
  128. )
  129. {
  130. int rc;
  131. Slapi_PBlock pipb;
  132. LDAPDebug( LDAP_DEBUG_FILTER,
  133. "=> plugin_call_syntax_filter_ava %s=%s\n", ava->ava_type,
  134. ava->ava_value.bv_val, 0 );
  135. if ( a->a_plugin == NULL ) {
  136. LDAPDebug( LDAP_DEBUG_FILTER,
  137. "<= plugin_syntax no plugin for attr (%s)\n",
  138. a->a_type, 0, 0 );
  139. return( LDAP_PROTOCOL_ERROR ); /* syntax unkonwn */
  140. }
  141. pblock_init( &pipb );
  142. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
  143. rc = -1; /* does not match by default */
  144. switch ( ftype ) {
  145. case LDAP_FILTER_GE:
  146. case LDAP_FILTER_LE:
  147. if ( (a->a_plugin->plg_syntax_flags &
  148. SLAPI_PLUGIN_SYNTAX_FLAG_ORDERING) == 0 ) {
  149. rc = LDAP_PROTOCOL_ERROR;
  150. break;
  151. }
  152. /* FALL */
  153. case LDAP_FILTER_EQUALITY:
  154. case LDAP_FILTER_APPROX:
  155. if ( a->a_plugin->plg_syntax_filter_ava != NULL )
  156. {
  157. /* JCM - Maybe the plugin should use the attr value iterator too... */
  158. Slapi_Value **va;
  159. if(useDeletedValues)
  160. va= valueset_get_valuearray(&a->a_deleted_values);
  161. else
  162. va= valueset_get_valuearray(&a->a_present_values);
  163. if(va!=NULL)
  164. {
  165. rc = a->a_plugin->plg_syntax_filter_ava( &pipb,
  166. &ava->ava_value,
  167. va,
  168. ftype, retVal );
  169. }
  170. }
  171. break;
  172. default:
  173. LDAPDebug( LDAP_DEBUG_ANY, "plugin_call_syntax_filter: "
  174. "unknown filter type %d\n", ftype, 0, 0 );
  175. rc = LDAP_PROTOCOL_ERROR;
  176. break;
  177. }
  178. LDAPDebug( LDAP_DEBUG_FILTER,
  179. "<= plugin_call_syntax_filter_ava %d\n", rc, 0, 0 );
  180. return( rc );
  181. }
  182. int
  183. plugin_call_syntax_filter_sub(
  184. Slapi_PBlock *pb,
  185. Slapi_Attr *a,
  186. struct subfilt *fsub
  187. )
  188. {
  189. return(plugin_call_syntax_filter_sub_sv(pb,a,fsub));
  190. }
  191. int
  192. plugin_call_syntax_filter_sub_sv(
  193. Slapi_PBlock *pb,
  194. Slapi_Attr *a,
  195. struct subfilt *fsub
  196. )
  197. {
  198. Slapi_PBlock pipb;
  199. int rc;
  200. LDAPDebug( LDAP_DEBUG_FILTER,
  201. "=> plugin_call_syntax_filter_sub\n", 0, 0, 0 );
  202. if ( a->a_plugin == NULL ) {
  203. LDAPDebug( LDAP_DEBUG_FILTER,
  204. "<= plugin_call_syntax_filter no plugin\n", 0, 0, 0 );
  205. return( -1 ); /* syntax unkonwn - does not match */
  206. }
  207. if ( a->a_plugin->plg_syntax_filter_sub != NULL )
  208. {
  209. Slapi_Value **va= valueset_get_valuearray(&a->a_present_values);
  210. pblock_init( &pipb );
  211. if (pb)
  212. {
  213. Operation *op = NULL;
  214. /* to pass SLAPI_SEARCH_TIMELIMIT & SLAPI_OPINITATED_TIME */
  215. slapi_pblock_get( pb, SLAPI_OPERATION, &op );
  216. slapi_pblock_set( &pipb, SLAPI_OPERATION, op );
  217. }
  218. slapi_pblock_set( &pipb, SLAPI_PLUGIN, (void *) a->a_plugin );
  219. rc = a->a_plugin->plg_syntax_filter_sub( &pipb,
  220. fsub->sf_initial, fsub->sf_any, fsub->sf_final, va);
  221. } else {
  222. rc = -1;
  223. }
  224. LDAPDebug( LDAP_DEBUG_FILTER, "<= plugin_call_syntax_filter_sub_sv %d\n",
  225. rc, 0, 0 );
  226. return( rc );
  227. }
  228. SLAPI_DEPRECATED int
  229. slapi_call_syntax_values2keys( /* JCM SLOW FUNCTION */
  230. void *vpi,
  231. struct berval **vals,
  232. struct berval ***ivals,
  233. int ftype
  234. )
  235. {
  236. int rc;
  237. Slapi_Value **svin= NULL;
  238. Slapi_Value **svout= NULL;
  239. valuearray_init_bervalarray(vals,&svin); /* JCM SLOW FUNCTION */
  240. rc= slapi_call_syntax_values2keys_sv(vpi,svin,&svout,ftype);
  241. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  242. valuearray_free(&svout);
  243. valuearray_free(&svin);
  244. return rc;
  245. }
  246. int
  247. slapi_call_syntax_values2keys_sv(
  248. void *vpi,
  249. Slapi_Value **vals,
  250. Slapi_Value ***ivals,
  251. int ftype
  252. )
  253. {
  254. int rc;
  255. Slapi_PBlock pipb;
  256. struct slapdplugin *pi = vpi;
  257. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_call_syntax_values2keys\n",
  258. 0, 0, 0 );
  259. pblock_init( &pipb );
  260. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  261. *ivals = NULL;
  262. rc = -1; /* means no values2keys function */
  263. if ( pi != NULL && pi->plg_syntax_values2keys != NULL ) {
  264. rc = pi->plg_syntax_values2keys( &pipb, vals, ivals, ftype );
  265. }
  266. LDAPDebug( LDAP_DEBUG_FILTER,
  267. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  268. return( rc );
  269. }
  270. /*
  271. * almost identical to slapi_call_syntax_values2keys_sv except accepting
  272. * pblock to pass some info such as substrlen.
  273. */
  274. int
  275. slapi_call_syntax_values2keys_sv_pb(
  276. void *vpi,
  277. Slapi_Value **vals,
  278. Slapi_Value ***ivals,
  279. int ftype,
  280. Slapi_PBlock *pb
  281. )
  282. {
  283. int rc;
  284. struct slapdplugin *pi = vpi;
  285. LDAPDebug( LDAP_DEBUG_FILTER, "=> slapi_call_syntax_values2keys\n",
  286. 0, 0, 0 );
  287. slapi_pblock_set( pb, SLAPI_PLUGIN, vpi );
  288. *ivals = NULL;
  289. rc = -1; /* means no values2keys function */
  290. if ( pi != NULL && pi->plg_syntax_values2keys != NULL ) {
  291. rc = pi->plg_syntax_values2keys( pb, vals, ivals, ftype );
  292. }
  293. LDAPDebug( LDAP_DEBUG_FILTER,
  294. "<= slapi_call_syntax_values2keys %d\n", rc, 0, 0 );
  295. return( rc );
  296. }
  297. SLAPI_DEPRECATED int
  298. slapi_call_syntax_assertion2keys_ava( /* JCM SLOW FUNCTION */
  299. void *vpi,
  300. struct berval *val,
  301. struct berval ***ivals,
  302. int ftype
  303. )
  304. {
  305. int rc;
  306. Slapi_Value svin;
  307. Slapi_Value **svout= NULL;
  308. slapi_value_init_berval(&svin, val);
  309. rc= slapi_call_syntax_assertion2keys_ava_sv(vpi,&svin,&svout,ftype);
  310. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  311. valuearray_free(&svout);
  312. value_done(&svin);
  313. return rc;
  314. }
  315. SLAPI_DEPRECATED int
  316. slapi_call_syntax_assertion2keys_ava_sv(
  317. void *vpi,
  318. Slapi_Value *val,
  319. Slapi_Value ***ivals,
  320. int ftype
  321. )
  322. {
  323. int rc;
  324. Slapi_PBlock pipb;
  325. struct slapdplugin *pi = vpi;
  326. LDAPDebug( LDAP_DEBUG_FILTER,
  327. "=> slapi_call_syntax_assertion2keys_ava\n", 0, 0, 0 );
  328. pblock_init( &pipb );
  329. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  330. rc = -1; /* means no assertion2keys function */
  331. if ( pi->plg_syntax_assertion2keys_ava != NULL ) {
  332. rc = pi->plg_syntax_assertion2keys_ava( &pipb, val, ivals, ftype );
  333. }
  334. LDAPDebug( LDAP_DEBUG_FILTER,
  335. "<= slapi_call_syntax_assertion2keys_ava %d\n", rc, 0, 0 );
  336. return( rc );
  337. }
  338. SLAPI_DEPRECATED int
  339. slapi_call_syntax_assertion2keys_sub( /* JCM SLOW FUNCTION */
  340. void *vpi,
  341. char *initial,
  342. char **any,
  343. char *final,
  344. struct berval ***ivals
  345. )
  346. {
  347. int rc;
  348. Slapi_Value **svout= NULL;
  349. rc= slapi_call_syntax_assertion2keys_sub_sv(vpi,initial,any,final,&svout);
  350. valuearray_get_bervalarray(svout,ivals); /* JCM SLOW FUNCTION */
  351. valuearray_free(&svout);
  352. return rc;
  353. }
  354. int
  355. slapi_call_syntax_assertion2keys_sub_sv(
  356. void *vpi,
  357. char *initial,
  358. char **any,
  359. char *final,
  360. Slapi_Value ***ivals
  361. )
  362. {
  363. int rc;
  364. Slapi_PBlock pipb;
  365. struct slapdplugin *pi = vpi;
  366. LDAPDebug( LDAP_DEBUG_FILTER,
  367. "=> slapi_call_syntax_assertion2keys_sub\n", 0, 0, 0 );
  368. pblock_init( &pipb );
  369. slapi_pblock_set( &pipb, SLAPI_PLUGIN, vpi );
  370. rc = -1; /* means no assertion2keys function */
  371. *ivals = NULL;
  372. if ( pi->plg_syntax_assertion2keys_sub != NULL ) {
  373. rc = pi->plg_syntax_assertion2keys_sub( &pipb, initial, any,
  374. final, ivals );
  375. }
  376. LDAPDebug( LDAP_DEBUG_FILTER,
  377. "<= slapi_call_syntax_assertion2keys_sub %d\n", rc, 0, 0 );
  378. return( rc );
  379. }