Annotation of parser3/src/include/pa_sapi.h, revision 1.38
1.1 paf 1: /** @file
2: Parser: web server api interface object decl.
3:
1.38 ! moko 4: Copyright (c) 2001-2023 Art. Lebedev Studio (http://www.artlebedev.com)
! 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.38 ! moko 11: #define IDENT_PA_SAPI_H "$Id: pa_sapi.h,v 1.37 2020/12/15 17:10:32 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.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:
1.35 moko 37: static void send_error(SAPI_Info& info, const char *exception_cstr, const char *status = "500"){
38: // capitalized headers passed for preventing malloc during capitalization
39: add_header_attribute(info, HTTP_STATUS_CAPITALIZED, status);
40: add_header_attribute(info, HTTP_CONTENT_TYPE_CAPITALIZED, "text/plain");
41: send_header(info);
42: send_body(info, exception_cstr, strlen(exception_cstr));
43: }
44:
1.30 moko 45: class Env {
46: public:
47: /// entire environment
48: static const char* const* get(SAPI_Info& ainfo);
49: /// single environment string
50: static char* get(SAPI_Info& ainfo, const char* name);
1.36 moko 51: static bool set(SAPI_Info& ainfo, const char* name, const char* value);
1.30 moko 52:
53: class Iterator {
54: private:
55: const char* const* pairs;
56: const char* pair;
57: const char* eq_at;
58: public:
1.32 moko 59: Iterator(SAPI_Info& asapi_info) : pair(NULL), eq_at(NULL){
1.30 moko 60: if(pairs=SAPI::Env::get(asapi_info))
61: next();
62: }
63: operator bool () {
64: return pair!=0;
65: }
66: void next() {
67: while(pair=*pairs++)
68: if(eq_at=strchr(pair, '=')) // valid pair (key=value)
69: if(eq_at[1]) // value is not empty
70: break;
71: }
72: char* key(){
73: return pa_strdup(pair, eq_at-pair);
74: }
75: char* value(){
76: return pa_strdup(eq_at+1);
77: }
78: };
79: };
1.1 paf 80: };
81:
82: #endif
E-mail: