janssonrpc_request.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /**
  2. * Copyright (C) 2013 Flowroute LLC (flowroute.com)
  3. *
  4. * This file is part of Kamailio, a free SIP server.
  5. *
  6. * This file 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. *
  12. * This file is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. *
  21. */
  22. #ifndef _JANSSONRPC_REQUEST_H_
  23. #define _JANSSONRPC_REQUEST_H_
  24. #include "janssonrpc_io.h"
  25. #include "janssonrpc_server.h"
  26. #define JSONRPC_DEFAULT_HTABLE_SIZE 500
  27. #define JSONRPC_MAX_ID 1000000
  28. #define RETRY_MAX_TIME 60000 /* milliseconds */
  29. typedef enum {
  30. RPC_REQUEST,
  31. RPC_NOTIFICATION
  32. } rpc_type;
  33. typedef struct jsonrpc_request jsonrpc_request_t;
  34. struct jsonrpc_request {
  35. rpc_type type;
  36. int id;
  37. jsonrpc_request_t *next; /* pkg */
  38. jsonrpc_server_t* server; /* shm */
  39. jsonrpc_req_cmd_t* cmd; /* shm */
  40. json_t* payload;
  41. struct event* timeout_ev; /* pkg */
  42. struct event* retry_ev; /* pkg */
  43. int retry;
  44. unsigned int ntries;
  45. unsigned int timeout;
  46. };
  47. jsonrpc_request_t* request_table[JSONRPC_DEFAULT_HTABLE_SIZE];
  48. jsonrpc_request_t* create_request(jsonrpc_req_cmd_t* cmd);
  49. void print_request(jsonrpc_request_t* req);
  50. jsonrpc_request_t* pop_request(int id);
  51. unsigned int requests_using_server(jsonrpc_server_t* server);
  52. void free_request(jsonrpc_request_t* req);
  53. int schedule_retry(jsonrpc_request_t* req);
  54. int jsonrpc_send(str conn, jsonrpc_request_t* req, bool notify_only);
  55. void fail_request(int code, jsonrpc_request_t* req, char* error_str);
  56. #endif /* _JSONRPC_H_ */