Annotation of parser3/src/include/pa_http.h, revision 1.34
1.1 paf 1: /** @file
2: Parser: commonly used functions.
3:
1.34 ! moko 4: Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com)
! 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_HTTP_H
9: #define PA_HTTP_H
10:
1.34 ! moko 11: #define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.33 2021/12/22 21:52:49 moko Exp $"
1.1 paf 12:
13: #include "pa_vstring.h"
14: #include "pa_vint.h"
15: #include "pa_vhash.h"
16: #include "pa_vtable.h"
17: #include "pa_socks.h"
1.15 moko 18: #include "pa_charset.h"
1.10 misha 19: #include "pa_request.h"
1.1 paf 20:
1.11 misha 21: #define HTTP_COOKIES_NAME "cookies"
1.12 moko 22:
1.33 moko 23: #ifdef _MSC_VER
24: #include <windows.h>
25: #define socklen_t int
26: #else
27: #define closesocket close
28: #define INVALID_SOCKET -1
29: typedef int SOCKET;
30: #endif
31:
1.1 paf 32: #ifndef DOXYGEN
33: struct File_read_http_result {
34: char *str; size_t length;
35: HashStringValue* headers;
36: };
37: #endif
38:
1.21 moko 39: class HTTP_Headers {
1.15 moko 40: public:
41: class Header {
42: public:
43: String::Body name;
44: String::Body value;
45:
46: Header(String::Body aname, String::Body avalue) : name(aname), value(avalue) {}
47:
48: void transcode(Charset &charset, Charset &source){
49: name=Charset::transcode(name, charset, source);
50: value=Charset::transcode(value, charset, source);
51: }
52:
53: };
54:
55: Array<Header> headers;
56:
57: String::Body content_type;
1.18 moko 58: uint64_t content_length;
1.15 moko 59:
1.21 moko 60: HTTP_Headers() : content_type(""), content_length(0){}
1.15 moko 61:
1.18 moko 62: bool add_header(const char *line);
1.15 moko 63:
1.17 moko 64: void clear(){
65: headers.clear();
66: content_type="";
1.18 moko 67: content_length=0;
1.17 moko 68: }
69:
1.15 moko 70: };
71:
1.20 moko 72: /*** http part ***/
73:
1.9 misha 74: Table* parse_cookies(Request& r, Table *cookies);
1.16 moko 75: void tables_update(HashStringValue& tables, const String::Body name, const String& value);
1.9 misha 76:
1.6 moko 77: char *pa_http_safe_header_name(const char *name);
78:
1.15 moko 79: File_read_http_result pa_internal_file_read_http(Request& r, const String& file_spec, bool as_text, HashStringValue *options=0, bool transcode_text_result=true);
1.1 paf 80:
1.20 moko 81: /*** httpd part ***/
82:
1.31 moko 83: //#define HTTPD_DEBUG
84:
1.20 moko 85: class HTTPD_request;
86:
87: class HTTPD_Connection : public PA_Allocated {
88: public:
1.33 moko 89: SOCKET sock;
1.20 moko 90: const char *remote_addr;
91: HTTPD_request *request;
92:
1.33 moko 93: HTTPD_Connection() : sock(INVALID_SOCKET), remote_addr(NULL), request(NULL){}
1.26 moko 94: ~HTTPD_Connection();
1.20 moko 95:
1.21 moko 96: Array<HTTP_Headers::Header> &headers();
1.20 moko 97:
98: const char *method();
99: const char *uri();
100: const char *content_type();
101: uint64_t content_length();
102:
1.22 moko 103: const char *query(){
104: if(uri()){
105: const char *result=strchr(uri(), '?');
106: if(result++ && *result)
107: return result;
108: }
109: return NULL;
110: }
111:
1.33 moko 112: bool accept(SOCKET, int);
1.30 moko 113: bool read_header();
1.20 moko 114: size_t read_post(char *, size_t);
1.24 moko 115: size_t send_body(const void *, size_t);
1.20 moko 116: };
117:
118: class HTTPD_Server : public PA_Allocated {
119: public:
1.27 moko 120: enum HTTPD_MODE {
121: SEQUENTIAL,
122: PARALLEL,
123: MULTITHREADED
124: } static mode;
1.32 moko 125: static const char *port;
1.27 moko 126:
1.28 moko 127: static void set_mode(const String&);
1.33 moko 128: static SOCKET bind(const char *);
1.20 moko 129: };
130:
1.1 paf 131: #endif
E-mail: