1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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
|
#pragma once
#include <stdlib.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include <bits/types/struct_iovec.h>
#include "stellar/stellar.h"
#include "stellar/utils.h"
#include "stellar/session.h"
#include "llhttp.h"
#ifndef UNUSED
#define UNUSED __attribute__((unused))
#endif
char *http_safe_dup(const char *str, size_t len);
int http_strncasecmp_safe(const char *fix_s1, const char *dyn_s2, size_t fix_n1, size_t dyn_n2);
void httpd_url_decode(const char *string, size_t length, char *ostring, size_t *olen);
int httpd_url_is_encoded(const char *url, size_t len);
/******************************************************************************
* Logger
******************************************************************************/
enum http_decoder_log_level
{
DEBUG = 0x11,
WARN = 0x12,
INFO = 0x13,
ERROR = 0x14,
};
#ifndef http_decoder_log
#define http_decoder_log(level, format, ...) \
{ \
switch (level) \
{ \
case DEBUG: \
fprintf(stdout, "HTTP_DECODER [DEBUG] " format "\n", ##__VA_ARGS__); \
fflush(stdout); \
break; \
case WARN: \
fprintf(stdout, "HTTP_DECODER [WARN] " format "\n", ##__VA_ARGS__); \
fflush(stdout); \
break; \
case INFO: \
fprintf(stdout, "HTTP_DECODER [INFO] " format "\n", ##__VA_ARGS__); \
fflush(stdout); \
break; \
case ERROR: \
fprintf(stderr, "HTTP_DECODER [ERROR] " format "\n", ##__VA_ARGS__); \
fflush(stderr); \
break; \
} \
}
#endif
#include <netinet/in.h>
struct http_session_addr
{
uint8_t ipver; /* 4 or 6 */
uint16_t sport; /* network order */
uint16_t dport; /* network order */
union
{
uint32_t saddr4;
struct in6_addr saddr6;
};
union
{
uint32_t daddr4;
struct in6_addr daddr6;
};
};
/*
why not use libevent evbuffer?
1. evbuffer is a buffer chain, it is not suitable for http half flow cache;
2. http_half_flow_buffer is a whole continuous buffer;
*/
struct http_buffer
{
int reference; // used by other
char *buffer;
size_t buffer_size;
};
int http_protocol_identify(const char *data, size_t data_len);
void httpd_session_get_addr(const struct session *sess, struct http_session_addr *addr);
void http_session_addr_ntop(const struct http_session_addr *sesaddr, char *buf, size_t buflen);
struct http_buffer *http_buffer_new(void);
void http_buffer_free(struct http_buffer *buffer);
int http_buffer_add(struct http_buffer *buffer, const char *data, size_t data_len);
int http_buffer_read(struct http_buffer *buffer, char **data, size_t *data_len);
char *http_string_dup(const char *str, size_t len);
long long http_strtoll(const char *str, size_t strlen);
size_t http_line_header_completed(const char *data, size_t data_len);
void http_truncate_extract_headers(const char *raw_data, size_t raw_data_len, const char **headers_start, const char **headers_end);
#ifdef __cplusplus
}
#endif
|