mongodb_client.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * Copyright (C) 2014 Daniel-Constantin Mierla (asipto.com)
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * Kamailio is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version
  10. *
  11. * Kamailio is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. *
  20. */
  21. #ifndef _MONGODB_CLIENT_H_
  22. #define _MONGODB_CLIENT_H_
  23. #include <mongoc.h>
  24. #include <bson.h>
  25. #include "../../str.h"
  26. #include "../../parser/parse_param.h"
  27. #include "../../mod_fix.h"
  28. int mongodbc_init(void);
  29. int mongodbc_destroy(void);
  30. int mongodbc_add_server(char *spec);
  31. int mongodbc_exec_simple(str *srv, str *dname, str *cname, str *cmd, str *res);
  32. int mongodbc_exec(str *srv, str *dname, str *cname, str *cmd, str *res);
  33. int mongodbc_find(str *srv, str *dname, str *cname, str *cmd, str *res);
  34. int mongodbc_find_one(str *srv, str *dname, str *cname, str *cmd, str *res);
  35. typedef struct mongodbc_server {
  36. str *sname;
  37. str *uri;
  38. unsigned int hname;
  39. param_t *attrs;
  40. mongoc_client_t *client;
  41. struct mongodbc_server *next;
  42. } mongodbc_server_t;
  43. typedef struct mongodbc_reply {
  44. str rname;
  45. unsigned int hname;
  46. mongoc_collection_t *collection;
  47. mongoc_cursor_t *cursor;
  48. str jsonrpl;
  49. struct mongodbc_reply *next;
  50. } mongodbc_reply_t;
  51. typedef struct mongodbc_pv {
  52. str rname;
  53. mongodbc_reply_t *reply;
  54. str rkey;
  55. int rkeyid;
  56. } mongodbc_pv_t;
  57. /* Server related functions */
  58. mongodbc_server_t* mongodbc_get_server(str *name);
  59. int mongodbc_reconnect_server(mongodbc_server_t *rsrv);
  60. /* Command related functions */
  61. mongodbc_reply_t *mongodbc_get_reply(str *name);
  62. int mongodbc_free_reply(str *name);
  63. int mongodbc_next_reply(str *name);
  64. #endif