A clone of btpd with my configuration changes.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

129 řádky
4.5 KiB

  1. /*
  2. * Copyright (c) 2000-2004 Niels Provos <provos@citi.umich.edu>
  3. * All rights reserved.
  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 _EVHTTP_H_
  28. #define _EVHTTP_H_
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. #ifdef WIN32
  33. #define WIN32_LEAN_AND_MEAN
  34. #include <windows.h>
  35. #undef WIN32_LEAN_AND_MEAN
  36. typedef unsigned char u_char;
  37. #endif
  38. /*
  39. * Basic support for HTTP serving.
  40. *
  41. * As libevent is a library for dealing with event notification and most
  42. * interesting applications are networked today, I have often found the
  43. * need to write HTTP code. The following prototypes and definitions provide
  44. * an application with a minimal interface for making HTTP requests and for
  45. * creating a very simple HTTP server.
  46. */
  47. /* Response codes */
  48. #define HTTP_OK 200
  49. #define HTTP_MOVEPERM 301
  50. #define HTTP_MOVETEMP 302
  51. #define HTTP_NOTFOUND 404
  52. struct evhttp;
  53. struct evhttp_request;
  54. struct evkeyvalq;
  55. /* Start an HTTP server on the specified address and port */
  56. struct evhttp *evhttp_start(const char *address, u_short port);
  57. /*
  58. * Free the previously create HTTP server. Works only if no requests are
  59. * currently being served.
  60. */
  61. void evhttp_free(struct evhttp* http);
  62. /* Set a callback for a specified URI */
  63. void evhttp_set_cb(struct evhttp *, const char *,
  64. void (*)(struct evhttp_request *, void *), void *);
  65. /* Set a callback for all requests that are not caught by specific callbacks */
  66. void evhttp_set_gencb(struct evhttp *,
  67. void (*)(struct evhttp_request *, void *), void *);
  68. void evhttp_send_error(struct evhttp_request *, int, const char *);
  69. void evhttp_send_reply(struct evhttp_request *, int, const char *,
  70. struct evbuffer *);
  71. /* Interfaces for making requests */
  72. enum evhttp_cmd_type { EVHTTP_REQ_GET, EVHTTP_REQ_POST, EVHTTP_REQ_HEAD };
  73. /*
  74. * Creates a new request object that needs to be filled in with the request
  75. * parameters. The callback is executed when the request completed or an
  76. * error occurred.
  77. */
  78. struct evhttp_request *evhttp_request_new(
  79. void (*cb)(struct evhttp_request *, void *), void *arg);
  80. /* Frees the request object and removes associated events. */
  81. void evhttp_request_free(struct evhttp_request *req);
  82. /*
  83. * A connection object that can be used to for making HTTP requests. The
  84. * connection object tries to establish the connection when it is given an
  85. * http request object.
  86. */
  87. struct evhttp_connection *evhttp_connection_new(
  88. const char *address, unsigned short port);
  89. /* Frees an http connection */
  90. void evhttp_connection_free(struct evhttp_connection *evcon);
  91. /* The connection gets ownership of the request */
  92. int evhttp_make_request(struct evhttp_connection *evcon,
  93. struct evhttp_request *req,
  94. enum evhttp_cmd_type type, const char *uri);
  95. const char *evhttp_request_uri(struct evhttp_request *req);
  96. /* Interfaces for dealing with HTTP headers */
  97. const char *evhttp_find_header(struct evkeyvalq *, const char *);
  98. int evhttp_remove_header(struct evkeyvalq *, const char *);
  99. int evhttp_add_header(struct evkeyvalq *, const char *, const char *);
  100. void evhttp_clear_headers(struct evkeyvalq *);
  101. /* Miscellaneous utility functions */
  102. void evhttp_parse_query(const char *uri, struct evkeyvalq *);
  103. char *evhttp_htmlescape(const char *html);
  104. #ifdef __cplusplus
  105. }
  106. #endif
  107. #endif /* _EVHTTP_H_ */