api.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * $Id$
  3. *
  4. * Kamailio LDAP Module
  5. *
  6. * Copyright (C) 2007 University of North Carolina
  7. *
  8. * Original author: Christian Schlatter, [email protected]
  9. *
  10. *
  11. * This file is part of Kamailio, a free SIP server.
  12. *
  13. * Kamailio is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version
  17. *
  18. * Kamailio is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  26. *
  27. * History:
  28. * --------
  29. * 2007-02-18: Initial version
  30. */
  31. #ifndef LDAP_API_H
  32. #define LDAP_API_H
  33. #include <ldap.h>
  34. #include "../../str.h"
  35. #include "../../sr_module.h"
  36. /*
  37. * LDAP API function types
  38. */
  39. typedef int (*ldap_params_search_t)(
  40. int* _ld_result_count,
  41. char* _lds_name,
  42. char* _dn,
  43. int _scope,
  44. char** _attrs,
  45. char* _filter,
  46. ...);
  47. typedef int (*ldap_url_search_t)(
  48. char* _ldap_url,
  49. int* _result_count);
  50. typedef int (*ldap_result_attr_vals_t)(
  51. str* _attr_name,
  52. struct berval ***_vals);
  53. typedef void (*ldap_value_free_len_t)(struct berval **_vals);
  54. typedef int (*ldap_result_next_t)(void);
  55. typedef int (*ldap_str2scope_t)(char* scope_str);
  56. typedef int (*get_ldap_handle_t)(char* _lds_name, LDAP** _ldap_handle);
  57. typedef void (*get_last_ldap_result_t)(
  58. LDAP** _last_ldap_handle,
  59. LDAPMessage** _last_ldap_result);
  60. typedef int (*ldap_rfc4515_escape_t)(str *sin, str *sout, int url_encode);
  61. /*
  62. * LDAP module API
  63. */
  64. typedef struct ldap_api {
  65. ldap_params_search_t ldap_params_search;
  66. ldap_url_search_t ldap_url_search;
  67. ldap_result_attr_vals_t ldap_result_attr_vals;
  68. ldap_value_free_len_t ldap_value_free_len;
  69. ldap_result_next_t ldap_result_next;
  70. ldap_str2scope_t ldap_str2scope;
  71. ldap_rfc4515_escape_t ldap_rfc4515_escape;
  72. get_ldap_handle_t get_ldap_handle;
  73. get_last_ldap_result_t get_last_ldap_result;
  74. } ldap_api_t;
  75. typedef int (*load_ldap_t)(ldap_api_t *api);
  76. int load_ldap(ldap_api_t *api);
  77. static inline int load_ldap_api(ldap_api_t *api)
  78. {
  79. load_ldap_t load_ldap;
  80. if (!(load_ldap = (load_ldap_t) find_export("load_ldap", 0, 0)))
  81. {
  82. LM_ERR("can't import load_ldap\n");
  83. return -1;
  84. }
  85. if (load_ldap(api) == -1)
  86. {
  87. return -1;
  88. }
  89. return 0;
  90. }
  91. #endif /* LDAP_API_H */