syntax_common.c 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2010 Red Hat, Inc.
  3. * All rights reserved.
  4. *
  5. * License: GPL (version 3 or any later version).
  6. * See LICENSE for details.
  7. * END COPYRIGHT BLOCK **/
  8. #ifdef HAVE_CONFIG_H
  9. #include <config.h>
  10. #endif
  11. #include "syntax.h"
  12. int
  13. syntax_register_matching_rule_plugins(
  14. struct mr_plugin_def mr_plugin_table[],
  15. size_t mr_plugin_table_size,
  16. int32_t (*matching_rule_plugin_init)(Slapi_PBlock *))
  17. {
  18. int rc = -1;
  19. size_t ii;
  20. for (ii = 0; ii < mr_plugin_table_size; ++ii) {
  21. char *argv[2];
  22. argv[0] = mr_plugin_table[ii].mr_def_entry.mr_name;
  23. argv[1] = NULL;
  24. rc = slapi_register_plugin_ext("matchingrule", 1 /* enabled */,
  25. "matching_rule_plugin_init",
  26. matching_rule_plugin_init,
  27. mr_plugin_table[ii].mr_def_entry.mr_name,
  28. argv, NULL, PLUGIN_DEFAULT_PRECEDENCE);
  29. }
  30. return rc;
  31. }
  32. int
  33. syntax_matching_rule_plugin_init(
  34. Slapi_PBlock *pb,
  35. struct mr_plugin_def mr_plugin_table[],
  36. size_t mr_plugin_table_size)
  37. {
  38. size_t ii;
  39. char **argv = NULL;
  40. int rc = -1;
  41. struct mr_plugin_def *mrpd = NULL;
  42. slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
  43. if (!argv || !argv[0]) {
  44. slapi_log_err(SLAPI_LOG_ERR, SYNTAX_PLUGIN_SUBSYSTEM,
  45. "syntax_matching_rule_plugin_init - "
  46. "Error: matching rule plugin name not specified\n");
  47. return rc;
  48. }
  49. for (ii = 0; ii < mr_plugin_table_size; ++ii) {
  50. /* get the arguments - argv[0] is our plugin name */
  51. /* find the plugin name in the table */
  52. if (!strcmp(mr_plugin_table[ii].mr_def_entry.mr_name, argv[0])) {
  53. mrpd = &mr_plugin_table[ii];
  54. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01);
  55. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &mrpd->mr_plg_desc);
  56. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_CREATE_FN, mrpd->mr_filter_create);
  57. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, mrpd->mr_indexer_create);
  58. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_AVA, mrpd->mr_filter_ava);
  59. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_SUB, mrpd->mr_filter_sub);
  60. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_VALUES2KEYS, mrpd->mr_values2keys);
  61. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_ASSERTION2KEYS_AVA, mrpd->mr_assertion2keys_ava);
  62. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_ASSERTION2KEYS_SUB, mrpd->mr_assertion2keys_sub);
  63. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_NAMES, mrpd->mr_names);
  64. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_COMPARE, mrpd->mr_compare);
  65. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_NORMALIZE, mrpd->mr_normalize);
  66. break;
  67. }
  68. }
  69. if (!mrpd) {
  70. slapi_log_err(SLAPI_LOG_ERR, SYNTAX_PLUGIN_SUBSYSTEM,
  71. "syntax_matching_rule_plugin_init - "
  72. "Error: matching rule plugin name [%s] not found\n",
  73. argv[0]);
  74. } else {
  75. rc = slapi_matchingrule_register(&mrpd->mr_def_entry);
  76. }
  77. return rc;
  78. }