http-parser.c

Small C library to parse HTTP requests
Log | Files | Refs | README | LICENSE

http-parser.h (2546B)


      1 #ifndef _HTTP_PARSER_H_
      2 #define _HTTP_PARSER_H_
      3 
      4 #ifdef __cplusplus
      5 extern "C" {
      6 #endif
      7 
      8 #include "finwo/mindex.h"
      9 #include "tidwall/buf.h"
     10 
     11 struct http_parser_event {
     12   struct http_parser_message *request;
     13   struct http_parser_message *response;
     14   struct http_parser_pair *pair;
     15   struct buf *chunk;
     16   void *udata;
     17 };
     18 
     19 struct http_parser_message {
     20   int ready;
     21   int status;
     22   char *statusMessage;
     23   char *method;
     24   char *path;
     25   char *query;
     26   char *version;
     27   struct mindex_t *meta;
     28   struct buf *body;
     29   struct buf *buf;
     30   int chunksize;
     31   int _state;
     32   void (*onChunk)(struct http_parser_event*);
     33   void *udata;
     34 };
     35 
     36 struct http_parser_pair {
     37   struct http_parser_message *request;
     38   struct http_parser_message *response;
     39   void *udata;
     40   void (*onRequest)(struct http_parser_event*);
     41   void (*onResponse)(struct http_parser_event*);
     42 };
     43 
     44 // Meta management
     45 const char * http_parser_meta_get(struct http_parser_message *subject, const char *key);
     46 void http_parser_meta_set(struct http_parser_message *subject, const char *key, const char *value);
     47 void http_parser_meta_del(struct http_parser_message *subject, const char *key);
     48 
     49 // Header management
     50 const char * http_parser_header_get(struct http_parser_message *subject, const char *key);
     51 void http_parser_header_set(struct http_parser_message *subject ,const char *key, const char *value);
     52 void http_parser_header_del(struct http_parser_message *subject, const char *key);
     53 
     54 struct http_parser_pair    * http_parser_pair_init(void *udata);
     55 struct http_parser_message * http_parser_request_init();
     56 struct http_parser_message * http_parser_response_init();
     57 
     58 void http_parser_request_data(struct http_parser_message *request, const struct buf *data);
     59 void http_parser_response_data(struct http_parser_message *response, const struct buf *data);
     60 
     61 void http_parser_pair_request_data(struct http_parser_pair *pair, const struct buf *data);
     62 void http_parser_pair_response_data(struct http_parser_pair *pair, const struct buf *data);
     63 
     64 void http_parser_pair_free(struct http_parser_pair *pair);
     65 void http_parser_message_free(struct http_parser_message *subject);
     66 
     67 const char * http_parser_status_message(int status);
     68 struct buf * http_parser_sprint_pair_response(struct http_parser_pair *pair);
     69 struct buf * http_parser_sprint_pair_request(struct http_parser_pair *pair);
     70 struct buf * http_parser_sprint_response(struct http_parser_message *response);
     71 struct buf * http_parser_sprint_request(struct http_parser_message *request);
     72 
     73 #ifdef __cplusplus
     74 } // extern "C"
     75 #endif
     76 
     77 #endif // _HTTP_PARSER_H_