Annotation of parser3/src/include/pa_sapi.h, revision 1.34

1.1       paf         1: /** @file
                      2:        Parser: web server api interface object decl.
                      3: 
1.33      moko        4:        Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)
1.18      paf         5:        Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
1.1       paf         6: */
                      7: 
                      8: #ifndef PA_SAPI_H
                      9: #define PA_SAPI_H
1.20      paf        10: 
1.34    ! moko       11: #define IDENT_PA_SAPI_H "$Id: pa_sapi.h,v 1.33 2017/02/07 22:00:36 moko Exp $"
1.23      paf        12: 
                     13: // includes
                     14: 
1.1       paf        15: 
                     16: #include "pa_types.h"
1.23      paf        17: #include "pa_array.h"
1.1       paf        18: 
1.23      paf        19: // forwards
                     20: class SAPI_Info;
1.5       paf        21: 
1.4       paf        22: /// target web-Server API
1.1       paf        23: struct SAPI {
1.5       paf        24:        /// log error message
1.23      paf        25:        static void log(SAPI_Info& info, const char* fmt, ...);
                     26:        /// log error message & exit
                     27:        static void die(const char* fmt, ...);
1.1       paf        28:        /// read POST request bytes
1.23      paf        29:        static size_t read_post(SAPI_Info& info, char *buf, size_t max_bytes);
1.12      parser     30:        /// add response header attribute [but do not send it to client]
1.28      misha      31:        static void add_header_attribute(SAPI_Info& info, const char* dont_store_key, const char* dont_store_value);
1.12      parser     32:        /// send collected header attributes to client
1.23      paf        33:        static void send_header(SAPI_Info& info);
1.1       paf        34:        /// output body bytes
1.26      paf        35:        static size_t send_body(SAPI_Info& info, const void *buf, size_t size);
1.30      moko       36: 
                     37:        class Env {
                     38:        public:
                     39:                /// entire environment
                     40:                static const char* const* get(SAPI_Info& ainfo);
                     41:                /// single environment string
                     42:                static char* get(SAPI_Info& ainfo, const char* name);
                     43: 
                     44:                class Iterator {
                     45:                private:
                     46:                        const char* const* pairs;
                     47:                        const char* pair;
                     48:                        const char* eq_at;
                     49:                public:
1.32      moko       50:                        Iterator(SAPI_Info& asapi_info) : pair(NULL), eq_at(NULL){
1.30      moko       51:                                if(pairs=SAPI::Env::get(asapi_info))
                     52:                                        next();
                     53:                        }
                     54:                        operator bool () {
                     55:                                return pair!=0;
                     56:                        }
                     57:                        void next() {
                     58:                                while(pair=*pairs++)
                     59:                                        if(eq_at=strchr(pair, '=')) // valid pair (key=value)
                     60:                                                if(eq_at[1]) // value is not empty
                     61:                                                        break;
                     62:                        }
                     63:                        char* key(){
                     64:                                return pa_strdup(pair, eq_at-pair);
                     65:                        }
                     66:                        char* value(){
                     67:                                return pa_strdup(eq_at+1);
                     68:                        }
                     69:                };
                     70:        };
1.1       paf        71: };
                     72: 
                     73: #endif

E-mail: