httpParser.h 2.9 KB
Newer Older
S
TD-1311  
Shengliang Guan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

S
TD-1311  
Shengliang Guan 已提交
16 17
#ifndef HTTP_PARSER_H
#define HTTP_PARSER_H
S
Shengliang Guan 已提交
18
#include "httpGzip.h"
F
freemine 已提交
19

S
TD-1311  
Shengliang Guan 已提交
20
#define HTTP_MAX_URL 5  // http url stack size
F
freemine 已提交
21

S
TD-1311  
Shengliang Guan 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
typedef enum HTTP_PARSER_STATE {
  HTTP_PARSER_BEGIN,
  HTTP_PARSER_REQUEST_OR_RESPONSE,
  HTTP_PARSER_METHOD,
  HTTP_PARSER_TARGET,
  HTTP_PARSER_HTTP_VERSION,
  HTTP_PARSER_SP,
  HTTP_PARSER_STATUS_CODE,
  HTTP_PARSER_REASON_PHRASE,
  HTTP_PARSER_CRLF,
  HTTP_PARSER_HEADER,
  HTTP_PARSER_HEADER_KEY,
  HTTP_PARSER_HEADER_VAL,
  HTTP_PARSER_CHUNK_SIZE,
  HTTP_PARSER_CHUNK,
  HTTP_PARSER_END,
  HTTP_PARSER_ERROR,
} HTTP_PARSER_STATE;

S
TD-1311  
Shengliang Guan 已提交
41 42 43 44 45
typedef enum HTTP_AUTH_TYPE {
  HTTP_INVALID_AUTH,
  HTTP_BASIC_AUTH,
  HTTP_TAOSD_AUTH
} HTTP_AUTH_TYPE;
S
TD-1311  
Shengliang Guan 已提交
46

S
TD-1311  
Shengliang Guan 已提交
47 48 49 50 51 52
typedef enum HTTP_VERSION {
  HTTP_VERSION_10 = 0,
  HTTP_VERSION_11 = 1,
  HTTP_VERSION_12 = 2,
  HTTP_INVALID_VERSION
} HTTP_VERSION;
S
TD-1311  
Shengliang Guan 已提交
53

S
TD-1311  
Shengliang Guan 已提交
54 55 56 57 58
typedef enum HTTP_KEEPALIVE {
  HTTP_KEEPALIVE_NO_INPUT = 0,
  HTTP_KEEPALIVE_ENABLE = 1,
  HTTP_KEEPALIVE_DISABLE = 2
} HTTP_KEEPALIVE;
F
freemine 已提交
59

S
TD-1311  
Shengliang Guan 已提交
60 61 62 63 64
typedef struct HttpString {
  char *  str;
  int32_t pos;
  int32_t size;
} HttpString;
F
freemine 已提交
65

S
TD-1311  
Shengliang Guan 已提交
66 67 68 69
typedef struct HttpStatus {
  int32_t code;
  char *  desc;
} HttpStatus;
S
TD-1311  
Shengliang Guan 已提交
70

S
TD-1311  
Shengliang Guan 已提交
71 72 73 74 75
typedef struct HttpStack{
  int8_t *stacks;
  int32_t pos;
  int32_t size;
} HttpStack;
S
Shengliang Guan 已提交
76

S
TD-1311  
Shengliang Guan 已提交
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
struct HttpContext;
typedef struct HttpParser {
  struct HttpContext *pContext;
  ehttp_gzip_t *gzip;
  HttpStack     stacks;
  HttpString    str;
  HttpString    body;
  HttpString    path[HTTP_MAX_URL];
  char *  method;
  char *  target;
  char *  target_raw;
  char *  version;
  char *  reasonPhrase;
  char *  key;
  char *  val;
  char *  authContent;
  int8_t  httpVersion;
  int8_t  acceptEncodingGzip;
  int8_t  acceptEncodingChunked;
  int8_t  contentLengthSpecified;
  int8_t  contentChunked;
  int8_t  transferGzip;
  int8_t  transferChunked;
  int8_t  keepAlive;
  int8_t  authType;
  int32_t contentLength;
  int32_t chunkSize;
  int32_t receivedChunkSize;
  int32_t receivedSize;
  int32_t statusCode;
  int8_t  inited;
  int8_t  parsed;
  int16_t httpCode;
  int32_t parseCode;
} HttpParser;
S
Shengliang Guan 已提交
112

S
TD-1311  
Shengliang Guan 已提交
113 114 115 116 117
void        httpInitParser(HttpParser *parser);
HttpParser *httpCreateParser(struct HttpContext *pContext);
void        httpDestroyParser(HttpParser *parser);
int32_t     httpParseBuf(HttpParser *parser, const char *buf, int32_t len);
char *      httpGetStatusDesc(int32_t statusCode);
F
freemine 已提交
118

S
TD-1311  
Shengliang Guan 已提交
119
#endif