Annotation of parser3/src/include/pa_http.h, revision 1.32

1.1       paf         1: /** @file
                      2:        Parser: commonly used functions.
                      3: 
1.29      moko        4:        Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com)
1.1       paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
                      6: */
                      7: 
                      8: #ifndef PA_HTTP_H
                      9: #define PA_HTTP_H
                     10: 
1.32    ! moko       11: #define IDENT_PA_HTTP_H "$Id: pa_http.h,v 1.31 2020/12/16 15:04:47 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.1       paf        23: #ifndef DOXYGEN
                     24: struct File_read_http_result {
                     25:        char *str; size_t length;
                     26:        HashStringValue* headers;
                     27: }; 
                     28: #endif
                     29: 
1.21      moko       30: class HTTP_Headers {
1.15      moko       31: public:
                     32:        class Header {
                     33:        public:
                     34:                String::Body name;
                     35:                String::Body value;
                     36: 
                     37:                Header(String::Body aname, String::Body avalue) : name(aname), value(avalue) {}
                     38: 
                     39:                void transcode(Charset &charset, Charset &source){
                     40:                        name=Charset::transcode(name, charset, source);
                     41:                        value=Charset::transcode(value, charset, source);
                     42:                }
                     43: 
                     44:        };
                     45: 
                     46:        Array<Header> headers;
                     47: 
                     48:        String::Body content_type;
1.18      moko       49:        uint64_t content_length;
1.15      moko       50: 
1.21      moko       51:        HTTP_Headers() : content_type(""), content_length(0){}
1.15      moko       52: 
1.18      moko       53:        bool add_header(const char *line);
1.15      moko       54: 
1.17      moko       55:        void clear(){
                     56:                headers.clear();
                     57:                content_type="";
1.18      moko       58:                content_length=0;
1.17      moko       59:        }
                     60: 
1.15      moko       61: };
                     62: 
1.20      moko       63: /*** http part ***/
                     64: 
1.9       misha      65: Table* parse_cookies(Request& r, Table *cookies);
1.16      moko       66: void tables_update(HashStringValue& tables, const String::Body name, const String& value);
1.9       misha      67: 
1.6       moko       68: char *pa_http_safe_header_name(const char *name);
                     69: 
1.15      moko       70: 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        71: 
1.20      moko       72: /*** httpd part ***/
                     73: 
1.31      moko       74: //#define HTTPD_DEBUG
                     75: 
1.20      moko       76: class HTTPD_request;
                     77: 
                     78: class HTTPD_Connection : public PA_Allocated {
                     79: public:
                     80:        int sock;
                     81:        const char *remote_addr;
                     82:        HTTPD_request *request;
                     83: 
1.26      moko       84:        HTTPD_Connection() : sock(-1), remote_addr(NULL), request(NULL){}
                     85:        ~HTTPD_Connection();
1.20      moko       86: 
1.21      moko       87:        Array<HTTP_Headers::Header> &headers();
1.20      moko       88: 
                     89:        const char *method();
                     90:        const char *uri();
                     91:        const char *content_type();
                     92:        uint64_t content_length();
                     93: 
1.22      moko       94:        const char *query(){
                     95:                if(uri()){
                     96:                        const char *result=strchr(uri(), '?');
                     97:                        if(result++ && *result)
                     98:                                return result;
                     99:                }
                    100:                return NULL;
                    101:        }
                    102: 
1.26      moko      103:        bool accept(int, int);
1.30      moko      104:        bool read_header();
1.20      moko      105:        size_t read_post(char *, size_t);
1.24      moko      106:        size_t send_body(const void *, size_t);
1.20      moko      107: };
                    108: 
                    109: class HTTPD_Server : public PA_Allocated {
                    110: public:
1.27      moko      111:        enum HTTPD_MODE {
                    112:                SEQUENTIAL,
                    113:                PARALLEL,
                    114:                MULTITHREADED
                    115:        } static mode;
1.32    ! moko      116:        static const char *port;
1.27      moko      117: 
1.28      moko      118:        static void set_mode(const String&);
1.26      moko      119:        static int bind(const char *);
1.20      moko      120: };
                    121: 
1.1       paf       122: #endif

E-mail: