A clone of btpd with my configuration changes.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

138 lignes
3.5 KiB

  1. /*
  2. * Copyright 2001 Niels Provos <provos@citi.umich.edu>
  3. * All rights reserved.
  4. *
  5. * This header file contains definitions for dealing with HTTP requests
  6. * that are internal to libevent. As user of the library, you should not
  7. * need to know about these.
  8. */
  9. #ifndef _HTTP_H_
  10. #define _HTTP_H_
  11. #define HTTP_CONNECT_TIMEOUT 45
  12. #define HTTP_WRITE_TIMEOUT 50
  13. #define HTTP_READ_TIMEOUT 50
  14. #define HTTP_PREFIX "http://"
  15. #define HTTP_DEFAULTPORT 80
  16. struct evbuffer;
  17. struct addrinfo;
  18. struct evhttp_request;
  19. /* A stupid connection object - maybe make this a bufferevent later */
  20. enum evhttp_connection_state {
  21. EVCON_DISCONNECTED, /* not currently connected not trying either */
  22. EVCON_CONNECTING, /* tries to currently connect */
  23. EVCON_CONNECTED /* connection is established */
  24. };
  25. struct evhttp_connection {
  26. int fd;
  27. struct event ev;
  28. struct evbuffer *input_buffer;
  29. struct evbuffer *output_buffer;
  30. char *address;
  31. u_short port;
  32. int flags;
  33. #define EVHTTP_CON_INCOMING 0x0001 /* only one request on it ever */
  34. #define EVHTTP_CON_OUTGOING 0x0002 /* multiple requests possible */
  35. enum evhttp_connection_state state;
  36. TAILQ_HEAD(evcon_requestq, evhttp_request) requests;
  37. void (*cb)(struct evhttp_connection *, void *);
  38. void *cb_arg;
  39. };
  40. enum evhttp_request_kind { EVHTTP_REQUEST, EVHTTP_RESPONSE };
  41. struct evhttp_request {
  42. TAILQ_ENTRY(evhttp_request) next;
  43. /* the connection object that this request belongs to */
  44. struct evhttp_connection *evcon;
  45. int flags;
  46. #define EVHTTP_REQ_OWN_CONNECTION 0x0001
  47. struct evkeyvalq *input_headers;
  48. struct evkeyvalq *output_headers;
  49. /* xxx: do we still need these? */
  50. char *remote_host;
  51. u_short remote_port;
  52. enum evhttp_request_kind kind;
  53. enum evhttp_cmd_type type;
  54. char *uri; /* uri after HTTP request was parsed */
  55. char major; /* HTTP Major number */
  56. char minor; /* HTTP Minor number */
  57. int got_firstline;
  58. int response_code; /* HTTP Response code */
  59. char *response_code_line; /* Readable response */
  60. struct evbuffer *input_buffer; /* read data */
  61. int ntoread;
  62. struct evbuffer *output_buffer; /* outgoing post or data */
  63. /* Callback */
  64. void (*cb)(struct evhttp_request *, void *);
  65. void *cb_arg;
  66. };
  67. struct evhttp_cb {
  68. TAILQ_ENTRY(evhttp_cb) next;
  69. char *what;
  70. void (*cb)(struct evhttp_request *req, void *);
  71. void *cbarg;
  72. };
  73. struct evhttp {
  74. struct event bind_ev;
  75. TAILQ_HEAD(httpcbq, evhttp_cb) callbacks;
  76. void (*gencb)(struct evhttp_request *req, void *);
  77. void *gencbarg;
  78. };
  79. /* resets the connection; can be reused for more requests */
  80. void evhttp_connection_reset(struct evhttp_connection *);
  81. /* connects if necessary */
  82. int evhttp_connection_connect(struct evhttp_connection *);
  83. /* notifies the current request that it failed; resets connection */
  84. void evhttp_connection_fail(struct evhttp_connection *);
  85. void evhttp_get_request(int, struct sockaddr *, socklen_t,
  86. void (*)(struct evhttp_request *, void *), void *);
  87. int evhttp_hostportfile(char *, char **, u_short *, char **);
  88. int evhttp_parse_lines(struct evhttp_request *, struct evbuffer*);
  89. void evhttp_start_read(struct evhttp_connection *);
  90. void evhttp_read_header(int, short, void *);
  91. void evhttp_make_header(struct evhttp_connection *, struct evhttp_request *);
  92. void evhttp_write_buffer(struct evhttp_connection *,
  93. void (*)(struct evhttp_connection *, void *), void *);
  94. /* response sending HTML the data in the buffer */
  95. void evhttp_response_code(struct evhttp_request *, int, const char *);
  96. void evhttp_send_page(struct evhttp_request *, struct evbuffer *);
  97. #endif /* _HTTP_H */