plugin_syntax.c 10 KB

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