Annotation of parser3/src/include/pa_sapi.h, revision 1.30
1.1 paf 1: /** @file
2: Parser: web server api interface object decl.
3:
1.29 moko 4: Copyright (c) 2001-2012 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.30 ! moko 11: #define IDENT_PA_SAPI_H "$Id: pa_sapi.h,v 1.29 2012/03/16 09:24:10 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, ...);
28: /// log error message & abort[write core]
29: static void abort(const char* fmt, ...);
1.1 paf 30: /// read POST request bytes
1.23 paf 31: static size_t read_post(SAPI_Info& info, char *buf, size_t max_bytes);
1.12 parser 32: /// add response header attribute [but do not send it to client]
1.28 misha 33: static void add_header_attribute(SAPI_Info& info, const char* dont_store_key, const char* dont_store_value);
1.12 parser 34: /// send collected header attributes to client
1.23 paf 35: static void send_header(SAPI_Info& info);
1.1 paf 36: /// output body bytes
1.26 paf 37: static size_t send_body(SAPI_Info& info, const void *buf, size_t size);
1.30 ! moko 38:
! 39: class Env {
! 40: public:
! 41: /// entire environment
! 42: static const char* const* get(SAPI_Info& ainfo);
! 43: /// single environment string
! 44: static char* get(SAPI_Info& ainfo, const char* name);
! 45:
! 46: class Iterator {
! 47: private:
! 48: const char* const* pairs;
! 49: const char* pair;
! 50: const char* eq_at;
! 51: public:
! 52: Iterator(SAPI_Info& asapi_info) {
! 53: if(pairs=SAPI::Env::get(asapi_info))
! 54: next();
! 55: }
! 56: operator bool () {
! 57: return pair!=0;
! 58: }
! 59: void next() {
! 60: while(pair=*pairs++)
! 61: if(eq_at=strchr(pair, '=')) // valid pair (key=value)
! 62: if(eq_at[1]) // value is not empty
! 63: break;
! 64: }
! 65: char* key(){
! 66: return pa_strdup(pair, eq_at-pair);
! 67: }
! 68: char* value(){
! 69: return pa_strdup(eq_at+1);
! 70: }
! 71: };
! 72: };
1.1 paf 73: };
74:
75: #endif
E-mail: