rpc_struct.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_INCLUDED_
  28. #define EVENT2_RPC_STRUCT_H_INCLUDED_
  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. /* Fix so that people don't have to run with <sys/queue.h> */
  37. #ifndef TAILQ_ENTRY
  38. #define EVENT_DEFINED_TQENTRY_
  39. #define TAILQ_ENTRY(type) \
  40. struct { \
  41. struct type *tqe_next; /* next element */ \
  42. struct type **tqe_prev; /* address of previous next element */ \
  43. }
  44. #endif /* !TAILQ_ENTRY */
  45. /**
  46. * provides information about the completed RPC request.
  47. */
  48. struct evrpc_status {
  49. #define EVRPC_STATUS_ERR_NONE 0
  50. #define EVRPC_STATUS_ERR_TIMEOUT 1
  51. #define EVRPC_STATUS_ERR_BADPAYLOAD 2
  52. #define EVRPC_STATUS_ERR_UNSTARTED 3
  53. #define EVRPC_STATUS_ERR_HOOKABORTED 4
  54. int error;
  55. /* for looking at headers or other information */
  56. struct evhttp_request *http_req;
  57. };
  58. /* the structure below needs to be synchronized with evrpc_req_generic */
  59. /* Encapsulates a request */
  60. struct evrpc {
  61. TAILQ_ENTRY(evrpc) next;
  62. /* the URI at which the request handler lives */
  63. const char* uri;
  64. /* creates a new request structure */
  65. void *(*request_new)(void *);
  66. void *request_new_arg;
  67. /* frees the request structure */
  68. void (*request_free)(void *);
  69. /* unmarshals the buffer into the proper request structure */
  70. int (*request_unmarshal)(void *, struct evbuffer *);
  71. /* creates a new reply structure */
  72. void *(*reply_new)(void *);
  73. void *reply_new_arg;
  74. /* frees the reply structure */
  75. void (*reply_free)(void *);
  76. /* verifies that the reply is valid */
  77. int (*reply_complete)(void *);
  78. /* marshals the reply into a buffer */
  79. void (*reply_marshal)(struct evbuffer*, void *);
  80. /* the callback invoked for each received rpc */
  81. void (*cb)(struct evrpc_req_generic *, void *);
  82. void *cb_arg;
  83. /* reference for further configuration */
  84. struct evrpc_base *base;
  85. };
  86. #ifdef EVENT_DEFINED_TQENTRY_
  87. #undef TAILQ_ENTRY
  88. #endif
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* EVENT2_RPC_STRUCT_H_INCLUDED_ */