/client.h

http://github.com/nicolasff/webdis · C Header · 93 lines · 63 code · 26 blank · 4 comment · 0 complexity · 7878d33ae219aff96e1c64a86a6aeda2 MD5 · raw file

  1. #ifndef CLIENT_H
  2. #define CLIENT_H
  3. #include <event.h>
  4. #include <arpa/inet.h>
  5. #include "http_parser.h"
  6. #include "websocket.h"
  7. struct http_header;
  8. struct server;
  9. struct cmd;
  10. typedef enum {
  11. LAST_CB_NONE = 0,
  12. LAST_CB_KEY = 1,
  13. LAST_CB_VAL = 2} last_cb_t;
  14. typedef enum {
  15. CLIENT_DISCONNECTED = -1,
  16. CLIENT_OOM = -2} client_error_t;
  17. struct http_client {
  18. int fd;
  19. in_addr_t addr;
  20. struct event ev;
  21. struct worker *w;
  22. struct server *s;
  23. /* HTTP parsing */
  24. struct http_parser parser;
  25. struct http_parser_settings settings;
  26. char *buffer;
  27. size_t sz;
  28. size_t request_sz; /* accumulated so far. */
  29. last_cb_t last_cb;
  30. /* various flags. */
  31. char keep_alive;
  32. char broken;
  33. char is_websocket;
  34. char http_version;
  35. char failed_alloc;
  36. /* HTTP data */
  37. char *path;
  38. size_t path_sz;
  39. /* headers */
  40. struct http_header *headers;
  41. int header_count;
  42. char *body;
  43. size_t body_sz;
  44. char *type; /* forced output content-type */
  45. char *jsonp; /* jsonp wrapper */
  46. char *separator; /* list separator for raw lists */
  47. char *filename; /* content-disposition */
  48. struct cmd *pub_sub;
  49. struct ws_msg *frame; /* websocket frame */
  50. };
  51. struct http_client *
  52. http_client_new(struct worker *w, int fd, in_addr_t addr);
  53. void
  54. http_client_reset(struct http_client *c);
  55. void
  56. http_client_free(struct http_client *c);
  57. int
  58. http_client_read(struct http_client *c);
  59. int
  60. http_client_remove_data(struct http_client *c, size_t sz);
  61. int
  62. http_client_execute(struct http_client *c);
  63. int
  64. http_client_add_to_body(struct http_client *c, const char *at, size_t sz);
  65. const char *
  66. client_get_header(struct http_client *c, const char *key);
  67. #endif