1
0

syntax_common.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_FATAL, "syntax_matching_rule_plugin_init",
  47. "Error: matching rule plugin name not specified\n");
  48. return rc;
  49. }
  50. for (ii = 0; ii < mr_plugin_table_size; ++ii) {
  51. /* get the arguments - argv[0] is our plugin name */
  52. /* find the plugin name in the table */
  53. if (!strcmp(mr_plugin_table[ii].mr_def_entry.mr_name, argv[0])) {
  54. mrpd = &mr_plugin_table[ii];
  55. rc = slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01);
  56. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &mrpd->mr_plg_desc);
  57. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_CREATE_FN, mrpd->mr_filter_create);
  58. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_INDEXER_CREATE_FN, mrpd->mr_indexer_create);
  59. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_AVA, mrpd->mr_filter_ava);
  60. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_FILTER_SUB, mrpd->mr_filter_sub);
  61. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_VALUES2KEYS, mrpd->mr_values2keys);
  62. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_ASSERTION2KEYS_AVA, mrpd->mr_assertion2keys_ava);
  63. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_ASSERTION2KEYS_SUB, mrpd->mr_assertion2keys_sub);
  64. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_NAMES, mrpd->mr_names);
  65. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_COMPARE, mrpd->mr_compare);
  66. rc |= slapi_pblock_set(pb, SLAPI_PLUGIN_MR_NORMALIZE, mrpd->mr_normalize);
  67. break;
  68. }
  69. }
  70. if (!mrpd) {
  71. slapi_log_error(SLAPI_LOG_FATAL, "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. }