summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_fastcgi_source.h
blob: 979e962ba4170b9749c00a613f7c8b4b06a003bb (plain) (blame)
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

/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) NGINX, Inc.
 */

#ifndef _NXT_FASTCGI_SOURCE_H_INCLUDED_
#define _NXT_FASTCGI_SOURCE_H_INCLUDED_


#define NXT_FASTCGI_BEGIN_REQUEST        1
#define NXT_FASTCGI_ABORT_REQUEST        2
#define NXT_FASTCGI_END_REQUEST          3
#define NXT_FASTCGI_PARAMS               4
#define NXT_FASTCGI_STDIN                5
#define NXT_FASTCGI_STDOUT               6
#define NXT_FASTCGI_STDERR               7
#define NXT_FASTCGI_DATA                 8


typedef struct nxt_fastcgi_parse_s       nxt_fastcgi_parse_t;

struct nxt_fastcgi_parse_s {
    u_char                               *pos;

    uint16_t                             length;         /* 16 bits */
    uint8_t                              padding;
    uint8_t                              type;

    uint8_t                              state;
    uint8_t                              fastcgi_error;  /* 1 bit */
    uint8_t                              error;          /* 1 bit */
    uint8_t                              done;           /* 1 bit */

    /* FastCGI stdout and stderr buffer chains. */
    nxt_buf_t                            *out[2];

    nxt_buf_t                            *(*last_buf)(nxt_fastcgi_parse_t *fp);
    void                                 *data;
    nxt_mp_t                             *mem_pool;
};


typedef struct {
    nxt_fastcgi_parse_t                  parse;
    nxt_source_hook_t                    next;
} nxt_fastcgi_source_record_t;


typedef struct {
    nxt_str_t                            name;
    nxt_str_t                            value;
    uintptr_t                            data[3];
} nxt_fastcgi_source_request_t;


typedef struct nxt_fastcgi_source_s  nxt_fastcgi_source_t;
typedef nxt_int_t (*nxt_fastcgi_source_request_create_t)(
    nxt_fastcgi_source_t *fs);


struct nxt_fastcgi_source_s {
    nxt_source_hook_t                    query;
    nxt_source_hook_t                    *next;

    nxt_upstream_source_t                *upstream;

    nxt_fastcgi_source_request_create_t  request_create;

    nxt_upstream_header_in_t             header_in;

    nxt_buf_t                            *rest;

    uint32_t                             state;  /* 2 bits */

    nxt_fastcgi_source_record_t          record;

    union {
        nxt_fastcgi_source_request_t     request;
    } u;
};


NXT_EXPORT void nxt_fastcgi_source_handler(nxt_task_t *task,
    nxt_upstream_source_t *us,
    nxt_fastcgi_source_request_create_t request_create);
NXT_EXPORT nxt_int_t nxt_fastcgi_source_hash_create(nxt_mp_t *mp,
    nxt_lvlhsh_t *lh);
void nxt_fastcgi_record_parse(nxt_task_t *task, nxt_fastcgi_parse_t *fp,
    nxt_buf_t *in);


#endif /* _NXT_FASTCGI_SOURCE_H_INCLUDED_ */