Annotation of parser3/src/include/pa_sapi.h, revision 1.42
1.1 paf 1: /** @file
2: Parser: web server api interface object decl.
3:
1.42 ! moko 4: Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
1.38 moko 5: Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
1.1 paf 6: */
7:
8: #ifndef PA_SAPI_H
9: #define PA_SAPI_H
1.20 paf 10:
1.42 ! moko 11: #define IDENT_PA_SAPI_H "$Id: pa_sapi.h,v 1.41 2024/11/10 00:28:42 moko Exp $"
1.23 paf 12:
13: // includes
14:
1.35 moko 15: #include "pa_common.h"
1.23 paf 16: #include "pa_array.h"
1.35 moko 17: #include "pa_exception.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.41 moko 33: static void send_headers(SAPI_Info& info);
34: /// clear collected header attributes
35: static void clear_headers(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.40 moko 38: // send error to client
39: static void send_error(SAPI_Info& info, const char *exception_cstr, const char *status = "500");
1.35 moko 40:
1.30 moko 41: class Env {
42: public:
43: /// entire environment
44: static const char* const* get(SAPI_Info& ainfo);
45: /// single environment string
46: static char* get(SAPI_Info& ainfo, const char* name);
1.36 moko 47: static bool set(SAPI_Info& ainfo, const char* name, const char* value);
1.30 moko 48:
49: class Iterator {
50: private:
51: const char* const* pairs;
52: const char* pair;
53: const char* eq_at;
54: public:
1.32 moko 55: Iterator(SAPI_Info& asapi_info) : pair(NULL), eq_at(NULL){
1.30 moko 56: if(pairs=SAPI::Env::get(asapi_info))
57: next();
58: }
59: operator bool () {
60: return pair!=0;
61: }
62: void next() {
63: while(pair=*pairs++)
64: if(eq_at=strchr(pair, '=')) // valid pair (key=value)
65: if(eq_at[1]) // value is not empty
66: break;
67: }
68: char* key(){
69: return pa_strdup(pair, eq_at-pair);
70: }
71: char* value(){
72: return pa_strdup(eq_at+1);
73: }
74: };
75: };
1.1 paf 76: };
77:
78: #endif
E-mail: