syntax_common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. IFP matching_rule_plugin_init
  17. )
  18. {
  19. int rc = -1;
  20. size_t ii;
  21. for (ii = 0; ii < mr_plugin_table_size; ++ii) {
  22. char *argv[2];
  23. argv[0] = mr_plugin_table[ii].mr_def_entry.mr_name;
  24. argv[1] = NULL;
  25. rc = slapi_register_plugin_ext("matchingrule", 1 /* enabled */,
  26. "matching_rule_plugin_init",
  27. matching_rule_plugin_init,
  28. mr_plugin_table[ii].mr_def_entry.mr_name,
  29. argv, NULL, PLUGIN_DEFAULT_PRECEDENCE);
  30. }
  31. return rc;
  32. }
  33. int
  34. syntax_matching_rule_plugin_init(
  35. Slapi_PBlock *pb,
  36. struct mr_plugin_def mr_plugin_table[],
  37. size_t mr_plugin_table_size
  38. )
  39. {
  40. size_t ii;
  41. char **argv = NULL;
  42. int rc = -1;
  43. struct mr_plugin_def *mrpd = NULL;
  44. slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, &argv);
  45. if (!argv || !argv[0]) {
  46. slapi_log_error(SLAPI_LOG_ERR, SYNTAX_PLUGIN_SUBSYSTEM,
  47. "syntax_matching_rule_plugin_init - "
  48. "Error: matching rule plugin name not specified\n");
  49. return rc;
  50. }
  51. for (ii = 0; ii < mr_plugin_table_size; ++ii) {
  52. /* get the arguments - argv[0] is our plugin name */
  53. /* find the plugin name in the table */
  54. if (!strcmp(mr_plugin_table[ii].mr_def_entry.mr_name, argv[0])) {
  55. mrpd = &mr_plugin_table[ii];
  56. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01);
  57. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &mrpd->mr_plg_desc);
  58. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_CREATE_FN, mrpd->mr_filter_create);
  59. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, mrpd->mr_indexer_create);
  60. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_AVA, mrpd->mr_filter_ava);
  61. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_SUB, mrpd->mr_filter_sub);
  62. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_VALUES2KEYS, mrpd->mr_values2keys);
  63. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_ASSERTION2KEYS_AVA, mrpd->mr_assertion2keys_ava);
  64. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_ASSERTION2KEYS_SUB, mrpd->mr_assertion2keys_sub);
  65. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_NAMES, mrpd->mr_names);
  66. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_COMPARE, mrpd->mr_compare);
  67. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_NORMALIZE, mrpd->mr_normalize);
  68. break;
  69. }
  70. }
  71. if (!mrpd) {
  72. slapi_log_error(SLAPI_LOG_ERR, SYNTAX_PLUGIN_SUBSYSTEM,
  73. "syntax_matching_rule_plugin_init - "
  74. "Error: matching rule plugin name [%s] not found\n", argv[0]);
  75. } else {
  76. rc = slapi_matchingrule_register(&mrpd->mr_def_entry);
  77. }
  78. return rc;
  79. }