Annotation of parser3/src/include/pa_sapi.h, revision 1.43
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.43 ! moko 11: #define IDENT_PA_SAPI_H "$Id: pa_sapi.h,v 1.42 2026/04/25 13:38:46 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.43 ! moko 40: /// interrupt the request in the given number of seconds from now, 0 cancels the timer
! 41: static void set_response_timeout(SAPI_Info& info, int seconds);
1.35 moko 42:
1.30 moko 43: class Env {
44: public:
45: /// entire environment
46: static const char* const* get(SAPI_Info& ainfo);
47: /// single environment string
48: static char* get(SAPI_Info& ainfo, const char* name);
1.36 moko 49: static bool set(SAPI_Info& ainfo, const char* name, const char* value);
1.30 moko 50:
51: class Iterator {
52: private:
53: const char* const* pairs;
54: const char* pair;
55: const char* eq_at;
56: public:
1.32 moko 57: Iterator(SAPI_Info& asapi_info) : pair(NULL), eq_at(NULL){
1.30 moko 58: if(pairs=SAPI::Env::get(asapi_info))
59: next();
60: }
61: operator bool () {
62: return pair!=0;
63: }
64: void next() {
65: while(pair=*pairs++)
66: if(eq_at=strchr(pair, '=')) // valid pair (key=value)
67: if(eq_at[1]) // value is not empty
68: break;
69: }
70: char* key(){
71: return pa_strdup(pair, eq_at-pair);
72: }
73: char* value(){
74: return pa_strdup(eq_at+1);
75: }
76: };
77: };
1.1 paf 78: };
79:
80: #endif
E-mail: