rpc_struct.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright (c) 2006-2007 Niels Provos <provos@citi.umich.edu>
  3. * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  18. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  19. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  22. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  23. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  25. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef _EVENT2_RPC_STRUCT_H_
  28. #define _EVENT2_RPC_STRUCT_H_
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /** @file event2/rpc_struct.h
  33. Structures used by rpc.h. Using these structures directly may harm
  34. forward compatibility: be careful!
  35. */
  36. /**
  37. * provides information about the completed RPC request.
  38. */
  39. struct evrpc_status {
  40. #define EVRPC_STATUS_ERR_NONE 0
  41. #define EVRPC_STATUS_ERR_TIMEOUT 1
  42. #define EVRPC_STATUS_ERR_BADPAYLOAD 2
  43. #define EVRPC_STATUS_ERR_UNSTARTED 3
  44. #define EVRPC_STATUS_ERR_HOOKABORTED 4
  45. int error;
  46. /* for looking at headers or other information */
  47. struct evhttp_request *http_req;
  48. };
  49. /* the structure below needs to be synchronized with evrpc_req_generic */
  50. /* Encapsulates a request */
  51. struct evrpc {
  52. TAILQ_ENTRY(evrpc) next;
  53. /* the URI at which the request handler lives */
  54. const char* uri;
  55. /* creates a new request structure */
  56. void *(*request_new)(void *);
  57. void *request_new_arg;
  58. /* frees the request structure */
  59. void (*request_free)(void *);
  60. /* unmarshals the buffer into the proper request structure */
  61. int (*request_unmarshal)(void *, struct evbuffer *);
  62. /* creates a new reply structure */
  63. void *(*reply_new)(void *);
  64. void *reply_new_arg;
  65. /* frees the reply structure */
  66. void (*reply_free)(void *);
  67. /* verifies that the reply is valid */
  68. int (*reply_complete)(void *);
  69. /* marshals the reply into a buffer */
  70. void (*reply_marshal)(struct evbuffer*, void *);
  71. /* the callback invoked for each received rpc */
  72. void (*cb)(struct evrpc_req_generic *, void *);
  73. void *cb_arg;
  74. /* reference for further configuration */
  75. struct evrpc_base *base;
  76. };
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /* _EVENT2_RPC_STRUCT_H_ */