├── .gitignore ├── .gitmodules ├── mrbgems └── mruby-ab-mruby-ext │ ├── mrbgem.rake │ └── mrblib │ └── test-ext.rb ├── test ├── ab-mruby-test.sh ├── ab-mruby.test.rb └── ab-mruby.conf.rb ├── Makefile ├── .travis.yml ├── Dockerfile ├── include ├── ap_compat.h ├── util_xml.h ├── heartbeat.h ├── mod_request.h ├── util_charset.h ├── util_ebcdic.h ├── util_md5.h ├── ap_config_layout.h ├── ap_release.h ├── util_cfgtree.h ├── http_main.h ├── mod_core.h ├── ap_provider.h ├── http_vhost.h ├── util_time.h ├── ap_listen.h ├── mod_auth.h ├── util_cookies.h ├── http_connection.h ├── ap_hooks.h ├── ap_config.h ├── ap_slotmem.h ├── util_varbuf.h ├── ap_config_auto.h ├── scoreboard.h ├── ap_regkey.h ├── util_mutex.h ├── ap_regex.h ├── ap_socache.h ├── util_script.h └── ap_mpm.h ├── README.md └── docker ├── ab-mruby.test.rb └── ab-mruby.conf.rb /.gitignore: -------------------------------------------------------------------------------- 1 | ab-mruby 2 | GPATH 3 | GRTAGS 4 | GTAGS 5 | mruby 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "mruby"] 2 | path = mruby 3 | url = git://github.com/mruby/mruby.git 4 | -------------------------------------------------------------------------------- /mrbgems/mruby-ab-mruby-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-ab-mruby-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'MATSUMOTO Ryosuke' 4 | spec.summary = 'ab-mruby ext class' 5 | end 6 | 7 | -------------------------------------------------------------------------------- /test/ab-mruby-test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | TARGET="http://localhost/index.html" 4 | AB_MRUBY="../ab-mruby" 5 | AB_MRUBY_CONFIG="./ab-mruby.conf.rb" 6 | AB_MRUBY_TEST="./ab-mruby.test.rb" 7 | 8 | for url in $TARGET 9 | do 10 | $AB_MRUBY -m $AB_MRUBY_CONFIG -M $AB_MRUBY_TEST $url 11 | done 12 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## Makefile -- Build procedure for ngx_mruby for nginx module 3 | ## MATSUMOTO, Ryosuke 4 | ## 5 | 6 | MAKE="make" 7 | 8 | HTTPD_SRC_ROOT=./httpd 9 | MRUBY_ROOT=./mruby 10 | LIBS=-lapr-1 -lssl -lcrypto -laprutil-1 -lm $(MRUBY_ROOT)/build/host/lib/libmruby.a 11 | CFLAGS=-I/usr/include/apr-1.0 -I/usr/include/apr-1 -I./include -I$(MRUBY_ROOT)/include 12 | 13 | # the default target 14 | all: 15 | cd mruby && cp -p ../build_config.rb . && rake && cd .. 16 | gcc ab-mruby.c -o ab-mruby $(CFLAGS) $(LIBS) 17 | 18 | # cleanup 19 | clean: 20 | -rm -rf ab-mruby 21 | cd mruby && rake clean 22 | 23 | clobber: clean 24 | cd mruby && rake deep_clean 25 | 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - clang 5 | before_install: 6 | - sudo apt-get -qq update 7 | install: 8 | - sudo apt-get -qq install rake bison libapr1-dev libaprutil1-dev apache2 9 | before_script: 10 | - make 11 | script: 12 | - cd test 13 | - sh ab-mruby-test.sh 14 | notifications: 15 | irc: 16 | channels: 17 | - "irc.freenode.org#hosting-ja" 18 | on_success: always 19 | on_failure: always 20 | use_notice: true 21 | skip_join: true 22 | template: 23 | - "[%{message}] %{repository} (%{commit}) by %{author}: See %{build_url}" 24 | webhooks: 25 | - secure: "WRiSNreWtI2ZxctRm80jNeHBgvxbDr7v2oKvb4w8OVi053VbTL1qESxmQ4F0YammrayNMqFRzxWe8TRP2BvkA2Ol7089fTdwFgAkGeYW8K5/7vzjQdFs8aGS7xdtEtdQ0REwI9yv8rWVv09eveneAiZNLt/bvE3861aLoKj7S5s=" 26 | 27 | -------------------------------------------------------------------------------- /mrbgems/mruby-ab-mruby-ext/mrblib/test-ext.rb: -------------------------------------------------------------------------------- 1 | class TestError < StandardError; end 2 | module Kernel 3 | def test_suite &blk 4 | @@r = get_config 5 | @@t = blk 6 | @@result = true 7 | end 8 | def bln_color val 9 | (val) ? "[\e[33m#{val}\e[m]" : "[\e[36m#{val}\e[m]" 10 | end 11 | def should_be val 12 | ret = @@r[self] == val 13 | puts "[TEST CASE] #{bln_color ret} #{self} (#{@@r[self]}) should be #{val}" 14 | @@result = ret if ret == false 15 | end 16 | def should_be_over val 17 | ret = @@r[self] >= val 18 | puts "[TEST CASE] #{bln_color ret} #{self} (#{@@r[self]}) should be over #{val}" 19 | @@result = ret if ret == false 20 | end 21 | def should_be_under val 22 | ret = @@r[self] <= val 23 | puts "[TEST CASE] #{bln_color ret} #{self} (#{@@r[self]}) should be under #{val}" 24 | @@result = ret if ret == false 25 | end 26 | def test_run 27 | @@t.call 28 | puts "\ntest suites: #{bln_color @@result}\n" 29 | raise TestError if @@result == false 30 | end 31 | end 32 | 33 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # Dockerfile for ab-mruby on ubuntu 14.04 64bit 3 | # 4 | 5 | # 6 | # Using Docker Image matsumotory/ab-mruby 7 | # 8 | # Pulling 9 | # docker pull matsumotory/ab-mruby 10 | # 11 | # Running 12 | # docker run -d matsumotory/ab-mruby http://example.com/ 13 | # 14 | 15 | # 16 | # Manual Build 17 | # 18 | # Building 19 | # docker build -t your_name:ab-mruby . 20 | # 21 | # Runing 22 | # docker run -d your_name:ab-mruby http://example.com/ 23 | # 24 | 25 | FROM ubuntu:14.04 26 | MAINTAINER matsumotory 27 | 28 | RUN apt-get -y update 29 | RUN apt-get -y install rake 30 | RUN apt-get -y install bison 31 | RUN apt-get -y install libapr1-dev 32 | RUN apt-get -y install libaprutil1-dev 33 | RUN apt-get -y install git 34 | RUN apt-get -y install make 35 | 36 | RUN cd /usr/local/src/ && git clone git://github.com/matsumoto-r/ab-mruby.git 37 | RUN cd /usr/local/src/ab-mruby && make && cp ab-mruby /usr/bin/. 38 | 39 | ADD docker/ab-mruby.conf.rb /etc/ab-mruby/ab-mruby.conf.rb 40 | ADD docker/ab-mruby.test.rb /etc/ab-mruby/ab-mruby.test.rb 41 | 42 | ENTRYPOINT ["/usr/bin/ab-mruby", "-m", "/etc/ab-mruby/ab-mruby.conf.rb", "-M", "/etc/ab-mruby/ab-mruby.test.rb"] 43 | -------------------------------------------------------------------------------- /include/ap_compat.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_compat.h 19 | * @brief Redefine Apache 1.3 symbols 20 | */ 21 | 22 | #ifndef AP_COMPAT_H 23 | #define AP_COMPAT_H 24 | 25 | /* redefine 1.3.x symbols to the new symbol names */ 26 | 27 | #define MODULE_VAR_EXPORT AP_MODULE_DECLARE_DATA 28 | #define ap_send_http_header(r) ; 29 | 30 | #endif /* AP_COMPAT_H */ 31 | -------------------------------------------------------------------------------- /include/util_xml.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_xml.h 19 | * @brief Apache XML library 20 | * 21 | * @defgroup APACHE_CORE_XML XML Library 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef UTIL_XML_H 27 | #define UTIL_XML_H 28 | 29 | #include "apr_xml.h" 30 | 31 | #include "httpd.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /** 38 | * Get XML post data and parse it 39 | * @param r The current request 40 | * @param pdoc The XML post data 41 | * @return HTTP status code 42 | * @fn int ap_xml_parse_input(request_rec *r, apr_xml_doc **pdoc) 43 | */ 44 | AP_DECLARE(int) ap_xml_parse_input(request_rec *r, apr_xml_doc **pdoc); 45 | 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif /* UTIL_XML_H */ 52 | /** @} */ 53 | -------------------------------------------------------------------------------- /include/heartbeat.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef HEARTBEAT_H 18 | #define HEARTBEAT_H 19 | 20 | /** 21 | * @file heartbeat.h 22 | * @brief commun structures for mod_heartmonitor.c and mod_lbmethod_heartbeat.c 23 | * 24 | * @defgroup HEARTBEAT mem 25 | * @ingroup APACHE_MODS 26 | * @{ 27 | */ 28 | 29 | #include "apr.h" 30 | #include "apr_time.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | /* 37 | * Worse Case: IPv4-Mapped IPv6 Address 38 | * 0000:0000:0000:0000:0000:FFFF:255.255.255.255 39 | */ 40 | #define MAXIPSIZE 46 41 | typedef struct hm_slot_server_t 42 | { 43 | char ip[MAXIPSIZE]; 44 | int busy; 45 | int ready; 46 | apr_time_t seen; 47 | int id; 48 | } hm_slot_server_t; 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | /** @} */ 56 | -------------------------------------------------------------------------------- /include/mod_request.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | /** 19 | * @file mod_request.h 20 | * @brief mod_request private header file 21 | * 22 | * @defgroup MOD_REQUEST mod_request 23 | * @ingroup APACHE_MODS 24 | * @{ 25 | */ 26 | 27 | #ifndef MOD_REQUEST_H 28 | #define MOD_REQUEST_H 29 | 30 | #include "apr.h" 31 | #include "apr_buckets.h" 32 | #include "apr_optional.h" 33 | 34 | #include "httpd.h" 35 | #include "util_filter.h" 36 | 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | extern module AP_MODULE_DECLARE_DATA request_module; 43 | 44 | #define KEEP_BODY_FILTER "KEEP_BODY" 45 | #define KEPT_BODY_FILTER "KEPT_BODY" 46 | 47 | /** 48 | * Core per-directory configuration. 49 | */ 50 | typedef struct { 51 | apr_off_t keep_body; 52 | int keep_body_set; 53 | } request_dir_conf; 54 | 55 | APR_DECLARE_OPTIONAL_FN(void, ap_request_insert_filter, (request_rec * r)); 56 | 57 | APR_DECLARE_OPTIONAL_FN(void, ap_request_remove_filter, (request_rec * r)); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* !MOD_REQUEST_H */ 64 | /** @} */ 65 | -------------------------------------------------------------------------------- /include/util_charset.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_charset.h 19 | * @brief charset conversion 20 | * 21 | * @defgroup APACHE_CORE_CHARSET Charset Conversion 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_UTIL_CHARSET_H 27 | #define APACHE_UTIL_CHARSET_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include "apr.h" 34 | 35 | #if APR_CHARSET_EBCDIC 36 | 37 | #include "apr_xlate.h" 38 | 39 | /** On EBCDIC machine this is a translation handle used to translate the 40 | * headers from the local machine format to ASCII for network transmission. 41 | * On an ASCII machine this is NULL */ 42 | extern apr_xlate_t *ap_hdrs_to_ascii; 43 | /** On EBCDIC machine this is a translation handle used to translate the 44 | * headers from ASCII to the local machine format after network transmission. 45 | * On an ASCII machine this is NULL */ 46 | extern apr_xlate_t *ap_hdrs_from_ascii; 47 | 48 | #endif /* APR_CHARSET_EBCDIC */ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif /* !APACHE_UTIL_CHARSET_H */ 55 | /** @} */ 56 | -------------------------------------------------------------------------------- /include/util_ebcdic.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_ebcdic.h 19 | * @brief Utilities for EBCDIC conversion 20 | * 21 | * @defgroup APACHE_CORE_EBCDIC Utilities for EBCDIC conversion 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_UTIL_EBCDIC_H 27 | #define APACHE_UTIL_EBCDIC_H 28 | 29 | 30 | #ifdef __cplusplus 31 | extern "C" { 32 | #endif 33 | 34 | #include "apr_xlate.h" 35 | #include "httpd.h" 36 | #include "util_charset.h" 37 | 38 | #if APR_CHARSET_EBCDIC 39 | 40 | /** 41 | * Setup all of the global translation handlers 42 | * @param pool pool to allocate out of 43 | */ 44 | apr_status_t ap_init_ebcdic(apr_pool_t *pool); 45 | 46 | /** 47 | * Convert protocol data from the implementation character 48 | * set to ASCII. 49 | * @param buffer buffer to translate 50 | * @param len number of bytes to translate 51 | */ 52 | void ap_xlate_proto_to_ascii(char *buffer, apr_size_t len); 53 | 54 | /** 55 | * Convert protocol data to the implementation character 56 | * set from ASCII. 57 | * @param buffer buffer to translate 58 | * @param len number of bytes to translate 59 | */ 60 | void ap_xlate_proto_from_ascii(char *buffer, apr_size_t len); 61 | 62 | /** 63 | * Convert protocol data from the implementation charater 64 | * set to ASCII, then send it. 65 | * @param r the current request 66 | * @param ... the strings to write, followed by a NULL pointer 67 | */ 68 | int ap_rvputs_proto_in_ascii(request_rec *r, ...); 69 | 70 | #else /* APR_CHARSET_EBCDIC */ 71 | 72 | #define ap_xlate_proto_to_ascii(x,y) /* NOOP */ 73 | #define ap_xlate_proto_from_ascii(x,y) /* NOOP */ 74 | 75 | #define ap_rvputs_proto_in_ascii ap_rvputs 76 | 77 | #endif /* APR_CHARSET_EBCDIC */ 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* !APACHE_UTIL_EBCDIC_H */ 84 | /** @} */ 85 | -------------------------------------------------------------------------------- /include/util_md5.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_md5.h 19 | * @brief Apache MD5 library 20 | * 21 | * @defgroup APACHE_CORE_MD5 MD5 Package Library 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_UTIL_MD5_H 27 | #define APACHE_UTIL_MD5_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | #include "apr_md5.h" 34 | 35 | /** 36 | * Create an MD5 checksum of a given string 37 | * @param a Pool to allocate out of 38 | * @param string String to get the checksum of 39 | * @return The checksum 40 | * @fn char *ap_md5(apr_pool_t *a, const unsigned char *string) 41 | */ 42 | AP_DECLARE(char *) ap_md5(apr_pool_t *a, const unsigned char *string); 43 | 44 | /** 45 | * Create an MD5 checksum of a string of binary data 46 | * @param a Pool to allocate out of 47 | * @param buf Buffer to generate checksum for 48 | * @param len The length of the buffer 49 | * @return The checksum 50 | * @fn char *ap_md5_binary(apr_pool_t *a, const unsigned char *buf, int len) 51 | */ 52 | AP_DECLARE(char *) ap_md5_binary(apr_pool_t *a, const unsigned char *buf, int len); 53 | 54 | /** 55 | * Convert an MD5 checksum into a base64 encoding 56 | * @param p The pool to allocate out of 57 | * @param context The context to convert 58 | * @return The converted encoding 59 | * @fn char *ap_md5contextTo64(apr_pool_t *p, apr_md5_ctx_t *context) 60 | */ 61 | AP_DECLARE(char *) ap_md5contextTo64(apr_pool_t *p, apr_md5_ctx_t *context); 62 | 63 | /** 64 | * Create an MD5 Digest for a given file 65 | * @param p The pool to allocate out of 66 | * @param infile The file to create the digest for 67 | * @fn char *ap_md5digest(apr_pool_t *p, apr_file_t *infile) 68 | */ 69 | AP_DECLARE(char *) ap_md5digest(apr_pool_t *p, apr_file_t *infile); 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif /* !APACHE_UTIL_MD5_H */ 76 | /** @} */ 77 | -------------------------------------------------------------------------------- /include/ap_config_layout.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_config_layout.h 19 | * @brief Apache Config Layout 20 | */ 21 | 22 | #ifndef AP_CONFIG_LAYOUT_H 23 | #define AP_CONFIG_LAYOUT_H 24 | 25 | /* Configured Apache directory layout */ 26 | #define DEFAULT_PREFIX "/usr/local/apache2" 27 | #define DEFAULT_EXP_EXEC_PREFIX "/usr/local/apache2" 28 | #define DEFAULT_REL_EXEC_PREFIX "" 29 | #define DEFAULT_EXP_BINDIR "/usr/local/apache2/bin" 30 | #define DEFAULT_REL_BINDIR "bin" 31 | #define DEFAULT_EXP_SBINDIR "/usr/local/apache2/bin" 32 | #define DEFAULT_REL_SBINDIR "bin" 33 | #define DEFAULT_EXP_LIBEXECDIR "/usr/local/apache2/modules" 34 | #define DEFAULT_REL_LIBEXECDIR "modules" 35 | #define DEFAULT_EXP_MANDIR "/usr/local/apache2/man" 36 | #define DEFAULT_REL_MANDIR "man" 37 | #define DEFAULT_EXP_SYSCONFDIR "/usr/local/apache2/conf" 38 | #define DEFAULT_REL_SYSCONFDIR "conf" 39 | #define DEFAULT_EXP_DATADIR "/usr/local/apache2" 40 | #define DEFAULT_REL_DATADIR "" 41 | #define DEFAULT_EXP_INSTALLBUILDDIR "/usr/local/apache2/build" 42 | #define DEFAULT_REL_INSTALLBUILDDIR "build" 43 | #define DEFAULT_EXP_ERRORDIR "/usr/local/apache2/error" 44 | #define DEFAULT_REL_ERRORDIR "error" 45 | #define DEFAULT_EXP_ICONSDIR "/usr/local/apache2/icons" 46 | #define DEFAULT_REL_ICONSDIR "icons" 47 | #define DEFAULT_EXP_HTDOCSDIR "/usr/local/apache2/htdocs" 48 | #define DEFAULT_REL_HTDOCSDIR "htdocs" 49 | #define DEFAULT_EXP_MANUALDIR "/usr/local/apache2/manual" 50 | #define DEFAULT_REL_MANUALDIR "manual" 51 | #define DEFAULT_EXP_CGIDIR "/usr/local/apache2/cgi-bin" 52 | #define DEFAULT_REL_CGIDIR "cgi-bin" 53 | #define DEFAULT_EXP_INCLUDEDIR "/usr/local/apache2/include" 54 | #define DEFAULT_REL_INCLUDEDIR "include" 55 | #define DEFAULT_EXP_LOCALSTATEDIR "/usr/local/apache2" 56 | #define DEFAULT_REL_LOCALSTATEDIR "" 57 | #define DEFAULT_EXP_RUNTIMEDIR "/usr/local/apache2/logs" 58 | #define DEFAULT_REL_RUNTIMEDIR "logs" 59 | #define DEFAULT_EXP_LOGFILEDIR "/usr/local/apache2/logs" 60 | #define DEFAULT_REL_LOGFILEDIR "logs" 61 | #define DEFAULT_EXP_PROXYCACHEDIR "/usr/local/apache2/proxy" 62 | #define DEFAULT_REL_PROXYCACHEDIR "proxy" 63 | 64 | #endif /* AP_CONFIG_LAYOUT_H */ 65 | -------------------------------------------------------------------------------- /include/ap_release.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_release.h 19 | * @brief Version Release defines 20 | */ 21 | 22 | #ifndef AP_RELEASE_H 23 | #define AP_RELEASE_H 24 | 25 | #include "apr_general.h" /* stringify */ 26 | 27 | #define AP_SERVER_COPYRIGHT \ 28 | "Copyright 2013 The Apache Software Foundation." 29 | 30 | /* 31 | * The below defines the base string of the Server: header. Additional 32 | * tokens can be added via the ap_add_version_component() API call. 33 | * 34 | * The tokens are listed in order of their significance for identifying the 35 | * application. 36 | * 37 | * "Product tokens should be short and to the point -- use of them for 38 | * advertizing or other non-essential information is explicitly forbidden." 39 | * 40 | * Example: "Apache/1.1.0 MrWidget/0.1-alpha" 41 | */ 42 | #define AP_SERVER_BASEVENDOR "Apache Software Foundation" 43 | #define AP_SERVER_BASEPROJECT "Apache HTTP Server" 44 | #define AP_SERVER_BASEPRODUCT "Apache" 45 | 46 | #define AP_SERVER_MAJORVERSION_NUMBER 2 47 | #define AP_SERVER_MINORVERSION_NUMBER 4 48 | #define AP_SERVER_PATCHLEVEL_NUMBER 4 49 | #define AP_SERVER_DEVBUILD_BOOLEAN 0 50 | #define AP_SERVER_ADD_STRING "-dev" 51 | 52 | /* Synchronize the above with docs/manual/style/version.ent */ 53 | 54 | #if !AP_SERVER_DEVBUILD_BOOLEAN 55 | #undef AP_SERVER_ADD_STRING 56 | #define AP_SERVER_ADD_STRING "" 57 | #endif 58 | 59 | /* keep old macros as well */ 60 | #define AP_SERVER_MAJORVERSION APR_STRINGIFY(AP_SERVER_MAJORVERSION_NUMBER) 61 | #define AP_SERVER_MINORVERSION APR_STRINGIFY(AP_SERVER_MINORVERSION_NUMBER) 62 | #define AP_SERVER_PATCHLEVEL APR_STRINGIFY(AP_SERVER_PATCHLEVEL_NUMBER) \ 63 | AP_SERVER_ADD_STRING 64 | 65 | #define AP_SERVER_MINORREVISION AP_SERVER_MAJORVERSION "." AP_SERVER_MINORVERSION 66 | #define AP_SERVER_BASEREVISION AP_SERVER_MINORREVISION "." AP_SERVER_PATCHLEVEL 67 | #define AP_SERVER_BASEVERSION AP_SERVER_BASEPRODUCT "/" AP_SERVER_BASEREVISION 68 | #define AP_SERVER_VERSION AP_SERVER_BASEVERSION 69 | 70 | /* macro for Win32 .rc files using numeric csv representation */ 71 | #define AP_SERVER_PATCHLEVEL_CSV AP_SERVER_MAJORVERSION_NUMBER, \ 72 | AP_SERVER_MINORVERSION_NUMBER, \ 73 | AP_SERVER_PATCHLEVEL_NUMBER 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /include/util_cfgtree.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_cfgtree.h 19 | * @brief Config Tree Package 20 | * 21 | * @defgroup APACHE_CORE_CONFIG_TREE Config Tree Package 22 | * @ingroup APACHE_CORE_CONFIG 23 | * @{ 24 | */ 25 | 26 | #ifndef AP_CONFTREE_H 27 | #define AP_CONFTREE_H 28 | 29 | #include "ap_config.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct ap_directive_t ap_directive_t; 36 | 37 | /** 38 | * @brief Structure used to build the config tree. 39 | * 40 | * The config tree only stores 41 | * the directives that will be active in the running server. Directives 42 | * that contain other directions, such as <Directory ...> cause a sub-level 43 | * to be created, where the included directives are stored. The closing 44 | * directive (</Directory>) is not stored in the tree. 45 | */ 46 | struct ap_directive_t { 47 | /** The current directive */ 48 | const char *directive; 49 | /** The arguments for the current directive, stored as a space 50 | * separated list */ 51 | const char *args; 52 | /** The next directive node in the tree */ 53 | struct ap_directive_t *next; 54 | /** The first child node of this directive */ 55 | struct ap_directive_t *first_child; 56 | /** The parent node of this directive */ 57 | struct ap_directive_t *parent; 58 | 59 | /** directive's module can store add'l data here */ 60 | void *data; 61 | 62 | /* ### these may go away in the future, but are needed for now */ 63 | /** The name of the file this directive was found in */ 64 | const char *filename; 65 | /** The line number the directive was on */ 66 | int line_num; 67 | 68 | /** A short-cut towards the last directive node in the tree. 69 | * The value may not always be up-to-date but it always points to 70 | * somewhere in the tree, nearer to the tail. 71 | * This value is only set in the first node 72 | */ 73 | struct ap_directive_t *last; 74 | }; 75 | 76 | /** 77 | * The root of the configuration tree 78 | */ 79 | AP_DECLARE_DATA extern ap_directive_t *ap_conftree; 80 | 81 | /** 82 | * Add a node to the configuration tree. 83 | * @param parent The current parent node. If the added node is a first_child, 84 | then this is changed to the current node 85 | * @param current The current node 86 | * @param toadd The node to add to the tree 87 | * @param child Is the node to add a child node 88 | * @return the added node 89 | */ 90 | ap_directive_t *ap_add_node(ap_directive_t **parent, ap_directive_t *current, 91 | ap_directive_t *toadd, int child); 92 | 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif 98 | /** @} */ 99 | -------------------------------------------------------------------------------- /include/http_main.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file http_main.h 19 | * @brief Command line options 20 | * 21 | * @defgroup APACHE_CORE_MAIN Command line options 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_HTTP_MAIN_H 27 | #define APACHE_HTTP_MAIN_H 28 | 29 | #include "httpd.h" 30 | #include "apr_optional.h" 31 | 32 | /** AP_SERVER_BASEARGS is the command argument list parsed by http_main.c 33 | * in apr_getopt() format. Use this for default'ing args that the MPM 34 | * can safely ignore and pass on from its rewrite_args() handler. 35 | */ 36 | #define AP_SERVER_BASEARGS "C:c:D:d:E:e:f:vVlLtTSMh?X" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | /** The name of the Apache executable */ 43 | AP_DECLARE_DATA extern const char *ap_server_argv0; 44 | /** The global server's ServerRoot */ 45 | AP_DECLARE_DATA extern const char *ap_server_root; 46 | /** The global server's DefaultRuntimeDir 47 | * This is not usable directly in the general case; use 48 | * ap_runtime_dir_relative() instead. 49 | */ 50 | AP_DECLARE_DATA extern const char *ap_runtime_dir; 51 | /** The global server's server_rec */ 52 | AP_DECLARE_DATA extern server_rec *ap_server_conf; 53 | /** global pool, for access prior to creation of server_rec */ 54 | AP_DECLARE_DATA extern apr_pool_t *ap_pglobal; 55 | /** state of the server (startup, exiting, ...) */ 56 | AP_DECLARE_DATA extern int ap_main_state; 57 | /** run mode (normal, config test, config dump, ...) */ 58 | AP_DECLARE_DATA extern int ap_run_mode; 59 | /** run mode (normal, config test, config dump, ...) */ 60 | AP_DECLARE_DATA extern int ap_config_generation; 61 | 62 | /* for -C, -c and -D switches */ 63 | /** An array of all -C directives. These are processed before the server's 64 | * config file */ 65 | AP_DECLARE_DATA extern apr_array_header_t *ap_server_pre_read_config; 66 | /** An array of all -c directives. These are processed after the server's 67 | * config file */ 68 | AP_DECLARE_DATA extern apr_array_header_t *ap_server_post_read_config; 69 | /** An array of all -D defines on the command line. This allows people to 70 | * effect the server based on command line options */ 71 | AP_DECLARE_DATA extern apr_array_header_t *ap_server_config_defines; 72 | /** Available integer for using the -T switch */ 73 | AP_DECLARE_DATA extern int ap_document_root_check; 74 | 75 | /** 76 | * An optional function to send signal to server on presence of '-k' 77 | * command line argument. 78 | * @param status The exit status after sending signal 79 | * @param pool Memory pool to allocate from 80 | */ 81 | APR_DECLARE_OPTIONAL_FN(int, ap_signal_server, (int *status, apr_pool_t *pool)); 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | 87 | #endif /* !APACHE_HTTP_MAIN_H */ 88 | /** @} */ 89 | -------------------------------------------------------------------------------- /include/mod_core.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | /** 19 | * @file mod_core.h 20 | * @brief mod_core private header file 21 | * 22 | * @defgroup MOD_CORE mod_core 23 | * @ingroup APACHE_MODS 24 | * @{ 25 | */ 26 | 27 | #ifndef MOD_CORE_H 28 | #define MOD_CORE_H 29 | 30 | #include "apr.h" 31 | #include "apr_buckets.h" 32 | 33 | #include "httpd.h" 34 | #include "util_filter.h" 35 | 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* Handles for core filters */ 42 | AP_DECLARE_DATA extern ap_filter_rec_t *ap_http_input_filter_handle; 43 | AP_DECLARE_DATA extern ap_filter_rec_t *ap_http_header_filter_handle; 44 | AP_DECLARE_DATA extern ap_filter_rec_t *ap_chunk_filter_handle; 45 | AP_DECLARE_DATA extern ap_filter_rec_t *ap_http_outerror_filter_handle; 46 | AP_DECLARE_DATA extern ap_filter_rec_t *ap_byterange_filter_handle; 47 | 48 | /* 49 | * These (input) filters are internal to the mod_core operation. 50 | */ 51 | apr_status_t ap_http_filter(ap_filter_t *f, apr_bucket_brigade *b, 52 | ap_input_mode_t mode, apr_read_type_e block, 53 | apr_off_t readbytes); 54 | 55 | /* HTTP/1.1 chunked transfer encoding filter. */ 56 | apr_status_t ap_http_chunk_filter(ap_filter_t *f, apr_bucket_brigade *b); 57 | 58 | /* Filter to handle any error buckets on output */ 59 | apr_status_t ap_http_outerror_filter(ap_filter_t *f, 60 | apr_bucket_brigade *b); 61 | 62 | char *ap_response_code_string(request_rec *r, int error_index); 63 | 64 | /** 65 | * Send the minimal part of an HTTP response header. 66 | * @param r The current request 67 | * @param bb The brigade to add the header to. 68 | * @warning Modules should be very careful about using this, and should 69 | * the default behavior. Much of the HTTP/1.1 implementation 70 | * correctness depends on the full headers. 71 | * @fn void ap_basic_http_header(request_rec *r, apr_bucket_brigade *bb) 72 | */ 73 | AP_DECLARE(void) ap_basic_http_header(request_rec *r, apr_bucket_brigade *bb); 74 | 75 | /** 76 | * Send an appropriate response to an http TRACE request. 77 | * @param r The current request 78 | * @note returns DONE or the HTTP status error if it handles the TRACE, 79 | * or DECLINED if the request was not for TRACE. 80 | * request method was not TRACE. 81 | */ 82 | AP_DECLARE_NONSTD(int) ap_send_http_trace(request_rec *r); 83 | 84 | /** 85 | * Send an appropriate response to an http OPTIONS request. 86 | * @param r The current request 87 | */ 88 | AP_DECLARE(int) ap_send_http_options(request_rec *r); 89 | 90 | /* Used for multipart/byteranges boundary string */ 91 | AP_DECLARE_DATA extern const char *ap_multipart_boundary; 92 | 93 | /* Init RNG at startup */ 94 | AP_CORE_DECLARE(void) ap_init_rng(apr_pool_t *p); 95 | /* Update RNG state in parent after fork */ 96 | AP_CORE_DECLARE(void) ap_random_parent_after_fork(void); 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* !MOD_CORE_H */ 103 | /** @} */ 104 | -------------------------------------------------------------------------------- /include/ap_provider.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_provider.h 19 | * @brief Apache Provider API 20 | * 21 | * @defgroup APACHE_CORE_PROVIDER Provider API 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef AP_PROVIDER_H 27 | #define AP_PROVIDER_H 28 | 29 | #include "ap_config.h" 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct { 36 | const char *provider_name; 37 | } ap_list_provider_names_t; 38 | 39 | typedef struct { 40 | const char *provider_group; 41 | const char *provider_version; 42 | } ap_list_provider_groups_t; 43 | 44 | /** 45 | * This function is used to register a provider with the global 46 | * provider pool. 47 | * @param pool The pool to create any storage from 48 | * @param provider_group The group to store the provider in 49 | * @param provider_name The name for this provider 50 | * @param provider_version The version for this provider 51 | * @param provider Opaque structure for this provider 52 | * @return APR_SUCCESS if all went well 53 | */ 54 | AP_DECLARE(apr_status_t) ap_register_provider(apr_pool_t *pool, 55 | const char *provider_group, 56 | const char *provider_name, 57 | const char *provider_version, 58 | const void *provider); 59 | 60 | /** 61 | * This function is used to retrieve a provider from the global 62 | * provider pool. 63 | * @param provider_group The group to look for this provider in 64 | * @param provider_name The name for the provider 65 | * @param provider_version The version for the provider 66 | * @return provider pointer to provider if found, NULL otherwise 67 | */ 68 | AP_DECLARE(void *) ap_lookup_provider(const char *provider_group, 69 | const char *provider_name, 70 | const char *provider_version); 71 | 72 | /** 73 | * This function is used to retrieve a list (array) of provider 74 | * names from the specified group with the specified version. 75 | * @param pool The pool to create any storage from 76 | * @param provider_group The group to look for this provider in 77 | * @param provider_version The version for the provider 78 | * @return pointer to array of ap_list_provider_names_t of provider names (could be empty) 79 | */ 80 | 81 | AP_DECLARE(apr_array_header_t *) ap_list_provider_names(apr_pool_t *pool, 82 | const char *provider_group, 83 | const char *provider_version); 84 | 85 | /** 86 | * This function is used to retrieve a list (array) of provider groups and versions 87 | * @param pool The pool to create any storage from 88 | * @return pointer to array of ap_list_provider_groups_t of provider groups 89 | * and versions (could be empty) 90 | */ 91 | 92 | AP_DECLARE(apr_array_header_t *) ap_list_provider_groups(apr_pool_t *pool); 93 | 94 | 95 | #ifdef __cplusplus 96 | } 97 | #endif 98 | 99 | #endif 100 | /** @} */ 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ab-mruby HTTP Benchmark and Test Tool [![Build Status](https://travis-ci.org/matsumotory/ab-mruby.svg?branch=master)](https://travis-ci.org/matsumotory/ab-mruby) 2 | 3 | ab-mruby is a HTTP Benchmark and Test Framework. 4 | 5 | ab-mruby embedded mruby into ab command by matsumoto_r. 6 | 7 | You can test and configure ab command options dynamically by mruby script. 8 | 9 | ## How to build 10 | 11 | - build 12 | 13 | ``` 14 | git clone --recursive https://github.com/matsumoto-r/ab-mruby.git 15 | cd ab-mruby 16 | make 17 | ``` 18 | 19 | - clean 20 | 21 | ``` 22 | make clean 23 | ``` 24 | 25 | - clean all (included mrbgems) 26 | 27 | ``` 28 | make clobber 29 | ``` 30 | 31 | ## How to use 32 | ### ab-mruby benchmark and test command 33 | 34 | ```bash 35 | ./ab-mruby -m ab-mruby.conf.rb -M ab-mruby.test.rb http://127.0.0.1/ 36 | ``` 37 | 38 | 39 | ### write config pattern for HTTP benchmark into ab-mruby.config.rb 40 | 41 | see also `test/ab-mruby.conf.rb` 42 | 43 | ```ruby 44 | add_config( 45 | "TotalRequests" => 100, # int 46 | "Concurrency" => 10, # int max 20000 47 | "KeepAlive" => true, # true or false or nil 48 | "VerboseLevel" => 1, # int 1 ~ 5 49 | "SilentMode" => true, 50 | ) 51 | ``` 52 | 53 | ### write test suite for HTTP benchmark into ab-mruby.test.rb 54 | 55 | see also `test/ab-mruby.test.rb` 56 | 57 | ```ruby 58 | test_suite do 59 | "FailedRequests".should_be 0 60 | "WriteErrors".should_be 0 61 | "CompleteRequests".should_be 100 62 | "TransferRate".should_be_over 500 63 | "RequestPerSecond".should_be_over 1000 64 | "TimePerRequest".should_be_under 100 65 | "TimePerConcurrentRequest".should_be_under 3000 66 | "ConnetcErrors".should_be 0 67 | "ReceiveErrors".should_be 0 68 | "LengthErrors".should_be 0 69 | "ExceptionsErrors".should_be 0 70 | "Non2xxResponses".should_be 0 71 | end 72 | 73 | test_run 74 | ``` 75 | 76 | ### ab-mruby benchmark and test start! 77 | 78 | ```bash 79 | $ ./ab-mruby -m test/ab-mruby.conf.rb -M test/ab-mruby.test.rb http://127.0.0.1/ 80 | ====================================================================== 81 | This is ab-mruby using ApacheBench Version 2.3 <$Revision: 1430300 $> 82 | Licensed to MATSUMOTO Ryosuke, https://github.com/matsumoto-r/ab-mruby 83 | 84 | CONFIG PHASE 85 | 86 | ====================================================================== 87 | Target Information URL: http://127.0.0.1/ 88 | Target Information HOST: 127.0.0.1 89 | Target Information PORT: 80 90 | Target Information PATH: / 91 | Target Information SSL: false 92 | ====================================================================== 93 | This is ab-mruby using ApacheBench Version 2.3 <$Revision: 1430300 $> 94 | Licensed to MATSUMOTO Ryosuke, https://github.com/matsumoto-r/ab-mruby 95 | 96 | TEST PHASE 97 | 98 | ====================================================================== 99 | [TEST CASE] [true] FailedRequests (0) should be 0 100 | [TEST CASE] [true] WriteErrors (0) should be 0 101 | [TEST CASE] [true] CompleteRequests (100) should be 100 102 | [TEST CASE] [true] TransferRate (2521.9284988877) should be over 500 103 | [TEST CASE] [true] RequestPerSecond (3224.0384305381) should be over 1000 104 | [TEST CASE] [true] TimePerRequest (0.31017) should be under 100 105 | [TEST CASE] [true] TimePerConcurrentRequest (3.1017) should be under 3000 106 | [TEST CASE] [true] ConnetcErrors (0) should be 0 107 | [TEST CASE] [true] ReceiveErrors (0) should be 0 108 | [TEST CASE] [true] LengthErrors (0) should be 0 109 | [TEST CASE] [true] ExceptionsErrors (0) should be 0 110 | [TEST CASE] [false] Non2xxResponses (100) should be 0 111 | 112 | test suites: [false] 113 | TestError: TestError 114 | ``` 115 | 116 | # License 117 | Licensed under the Apache License, Version 2.0 118 | 119 | http://www.apache.org/licenses/LICENSE-2.0 120 | -------------------------------------------------------------------------------- /include/http_vhost.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file http_vhost.h 19 | * @brief Virtual Host package 20 | * 21 | * @defgroup APACHE_CORE_VHOST Virtual Host Package 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_HTTP_VHOST_H 27 | #define APACHE_HTTP_VHOST_H 28 | 29 | #ifdef __cplusplus 30 | extern "C" { 31 | #endif 32 | 33 | /** 34 | * called before any config is read 35 | * @param p Pool to allocate out of 36 | */ 37 | AP_DECLARE(void) ap_init_vhost_config(apr_pool_t *p); 38 | 39 | /** 40 | * called after the config has been read to compile the tables needed to do 41 | * the run-time vhost lookups 42 | * @param p The pool to allocate out of 43 | * @param main_server The start of the virtual host list 44 | */ 45 | AP_DECLARE(void) ap_fini_vhost_config(apr_pool_t *p, server_rec *main_server); 46 | 47 | /** 48 | * handle addresses in "" statement 49 | * @param p The pool to allocate out of 50 | * @param hostname The hostname in the VirtualHost statement 51 | * @param s The list of Virtual Hosts. 52 | */ 53 | const char *ap_parse_vhost_addrs(apr_pool_t *p, const char *hostname, server_rec *s); 54 | 55 | /** 56 | * handle NameVirtualHost directive 57 | * @param cmd Command Parameters structure 58 | * @param dummy NOT USED 59 | * @param arg a host of the form "
[:port]" 60 | */ 61 | AP_DECLARE_NONSTD(const char *)ap_set_name_virtual_host(cmd_parms *cmd, 62 | void *dummy, 63 | const char *arg); 64 | 65 | /** 66 | * Callback function for every Name Based Virtual Host. 67 | * @param baton Opaque user object 68 | * @param conn The current Connection 69 | * @param s The current Server 70 | * @see ap_vhost_iterate_given_conn 71 | * @return 0 on success, any non-zero return will stop the iteration. 72 | */ 73 | typedef int(*ap_vhost_iterate_conn_cb)(void* baton, conn_rec* conn, server_rec* s); 74 | 75 | /** 76 | * For every virtual host on this connection, call func_cb. 77 | * @param conn The current connection 78 | * @param func_cb Function called for every Name Based Virtual Host for this 79 | * connection. 80 | * @param baton Opaque object passed to func_cb. 81 | * @return The return value from func_cb. 82 | * @note If func_cb returns non-zero, the function will return at this point, 83 | * and not continue iterating the virtual hosts. 84 | */ 85 | AP_DECLARE(int) ap_vhost_iterate_given_conn(conn_rec *conn, 86 | ap_vhost_iterate_conn_cb func_cb, 87 | void* baton); 88 | 89 | /** 90 | * given an ip address only, give our best guess as to what vhost it is 91 | * @param conn The current connection 92 | */ 93 | AP_DECLARE(void) ap_update_vhost_given_ip(conn_rec *conn); 94 | 95 | /** 96 | * ap_update_vhost_given_ip is never enough, and this is always called after 97 | * the headers have been read. It may change r->server. 98 | * @param r The current request 99 | */ 100 | AP_DECLARE(void) ap_update_vhost_from_headers(request_rec *r); 101 | 102 | /** 103 | * Match the host in the header with the hostname of the server for this 104 | * request. 105 | * @param r The current request 106 | * @param host The hostname in the headers 107 | * @param port The port from the headers 108 | * @return return 1 if the host:port matches any of the aliases of r->server, 109 | * return 0 otherwise 110 | */ 111 | AP_DECLARE(int) ap_matches_request_vhost(request_rec *r, const char *host, 112 | apr_port_t port); 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif /* !APACHE_HTTP_VHOST_H */ 119 | /** @} */ 120 | -------------------------------------------------------------------------------- /include/util_time.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_time.h 19 | * @brief Apache date-time handling functions 20 | * 21 | * @defgroup APACHE_CORE_TIME Date-time handling functions 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_UTIL_TIME_H 27 | #define APACHE_UTIL_TIME_H 28 | 29 | #include "apr.h" 30 | #include "apr_time.h" 31 | #include "httpd.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* Maximum delta from the current time, in seconds, for a past time 38 | * to qualify as "recent" for use in the ap_explode_recent_*() functions: 39 | * (Must be a power of two minus one!) 40 | */ 41 | #define AP_TIME_RECENT_THRESHOLD 15 42 | 43 | /* Options for ap_recent_ctime_ex */ 44 | /* No extension */ 45 | #define AP_CTIME_OPTION_NONE 0x0 46 | /* Add sub second timestamps with micro second resolution */ 47 | #define AP_CTIME_OPTION_USEC 0x1 48 | /* Use more compact ISO 8601 format */ 49 | #define AP_CTIME_OPTION_COMPACT 0x2 50 | 51 | 52 | /** 53 | * convert a recent time to its human readable components in local timezone 54 | * @param tm the exploded time 55 | * @param t the time to explode: MUST be within the last 56 | * AP_TIME_RECENT_THRESHOLD seconds 57 | * @note This is a faster alternative to apr_time_exp_lt that uses 58 | * a cache of pre-exploded time structures. It is useful for things 59 | * that need to explode the current time multiple times per second, 60 | * like loggers. 61 | * @return APR_SUCCESS iff successful 62 | */ 63 | AP_DECLARE(apr_status_t) ap_explode_recent_localtime(apr_time_exp_t *tm, 64 | apr_time_t t); 65 | 66 | /** 67 | * convert a recent time to its human readable components in GMT timezone 68 | * @param tm the exploded time 69 | * @param t the time to explode: MUST be within the last 70 | * AP_TIME_RECENT_THRESHOLD seconds 71 | * @note This is a faster alternative to apr_time_exp_gmt that uses 72 | * a cache of pre-exploded time structures. It is useful for things 73 | * that need to explode the current time multiple times per second, 74 | * like loggers. 75 | * @return APR_SUCCESS iff successful 76 | */ 77 | AP_DECLARE(apr_status_t) ap_explode_recent_gmt(apr_time_exp_t *tm, 78 | apr_time_t t); 79 | 80 | 81 | /** 82 | * format a recent timestamp in the ctime() format. 83 | * @param date_str String to write to. 84 | * @param t the time to convert 85 | * @note Consider using ap_recent_ctime_ex instead. 86 | * @return APR_SUCCESS iff successful 87 | */ 88 | AP_DECLARE(apr_status_t) ap_recent_ctime(char *date_str, apr_time_t t); 89 | 90 | 91 | /** 92 | * format a recent timestamp in an extended ctime() format. 93 | * @param date_str String to write to. 94 | * @param t the time to convert 95 | * @param option Additional formatting options (AP_CTIME_OPTION_*). 96 | * @param len Pointer to an int containing the length of the provided buffer. 97 | * On successful return it contains the number of bytes written to the 98 | * buffer. 99 | * @return APR_SUCCESS iff successful, APR_ENOMEM if buffer was to short. 100 | */ 101 | AP_DECLARE(apr_status_t) ap_recent_ctime_ex(char *date_str, apr_time_t t, 102 | int option, int *len); 103 | 104 | 105 | /** 106 | * format a recent timestamp in the RFC822 format 107 | * @param date_str String to write to (must have length >= APR_RFC822_DATE_LEN) 108 | * @param t the time to convert 109 | */ 110 | AP_DECLARE(apr_status_t) ap_recent_rfc822_date(char *date_str, apr_time_t t); 111 | 112 | #ifdef __cplusplus 113 | } 114 | #endif 115 | 116 | #endif /* !APACHE_UTIL_TIME_H */ 117 | /** @} */ 118 | -------------------------------------------------------------------------------- /include/ap_listen.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_listen.h 19 | * @brief Apache Listeners Library 20 | * 21 | * @defgroup APACHE_CORE_LISTEN Apache Listeners Library 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef AP_LISTEN_H 27 | #define AP_LISTEN_H 28 | 29 | #include "apr_network_io.h" 30 | #include "httpd.h" 31 | #include "http_config.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | typedef struct ap_slave_t ap_slave_t; 38 | typedef struct ap_listen_rec ap_listen_rec; 39 | typedef apr_status_t (*accept_function)(void **csd, ap_listen_rec *lr, apr_pool_t *ptrans); 40 | 41 | /** 42 | * @brief Apache's listeners record. 43 | * 44 | * These are used in the Multi-Processing Modules 45 | * to setup all of the sockets for the MPM to listen to and accept on. 46 | */ 47 | struct ap_listen_rec { 48 | /** 49 | * The next listener in the list 50 | */ 51 | ap_listen_rec *next; 52 | /** 53 | * The actual socket 54 | */ 55 | apr_socket_t *sd; 56 | /** 57 | * The sockaddr the socket should bind to 58 | */ 59 | apr_sockaddr_t *bind_addr; 60 | /** 61 | * The accept function for this socket 62 | */ 63 | accept_function accept_func; 64 | /** 65 | * Is this socket currently active 66 | */ 67 | int active; 68 | /** 69 | * The default protocol for this listening socket. 70 | */ 71 | const char* protocol; 72 | 73 | ap_slave_t *slave; 74 | }; 75 | 76 | /** 77 | * The global list of ap_listen_rec structures 78 | */ 79 | AP_DECLARE_DATA extern ap_listen_rec *ap_listeners; 80 | 81 | /** 82 | * Setup all of the defaults for the listener list 83 | */ 84 | AP_DECLARE(void) ap_listen_pre_config(void); 85 | 86 | /** 87 | * Loop through the global ap_listen_rec list and create all of the required 88 | * sockets. This executes the listen and bind on the sockets. 89 | * @param s The global server_rec 90 | * @return The number of open sockets. 91 | */ 92 | AP_DECLARE(int) ap_setup_listeners(server_rec *s); 93 | 94 | /** 95 | * Loop through the global ap_listen_rec list and close each of the sockets. 96 | */ 97 | AP_DECLARE_NONSTD(void) ap_close_listeners(void); 98 | 99 | /** 100 | * FIXMEDOC 101 | */ 102 | AP_DECLARE_NONSTD(int) ap_close_selected_listeners(ap_slave_t *); 103 | 104 | /* Although these functions are exported from libmain, they are not really 105 | * public functions. These functions are actually called while parsing the 106 | * config file, when one of the LISTEN_COMMANDS directives is read. These 107 | * should not ever be called by external modules. ALL MPMs should include 108 | * LISTEN_COMMANDS in their command_rec table so that these functions are 109 | * called. 110 | */ 111 | AP_DECLARE_NONSTD(const char *) ap_set_listenbacklog(cmd_parms *cmd, void *dummy, const char *arg); 112 | AP_DECLARE_NONSTD(const char *) ap_set_listener(cmd_parms *cmd, void *dummy, 113 | int argc, char *const argv[]); 114 | AP_DECLARE_NONSTD(const char *) ap_set_send_buffer_size(cmd_parms *cmd, void *dummy, 115 | const char *arg); 116 | AP_DECLARE_NONSTD(const char *) ap_set_receive_buffer_size(cmd_parms *cmd, 117 | void *dummy, 118 | const char *arg); 119 | 120 | #define LISTEN_COMMANDS \ 121 | AP_INIT_TAKE1("ListenBacklog", ap_set_listenbacklog, NULL, RSRC_CONF, \ 122 | "Maximum length of the queue of pending connections, as used by listen(2)"), \ 123 | AP_INIT_TAKE_ARGV("Listen", ap_set_listener, NULL, RSRC_CONF, \ 124 | "A port number or a numeric IP address and a port number, and an optional protocol"), \ 125 | AP_INIT_TAKE1("SendBufferSize", ap_set_send_buffer_size, NULL, RSRC_CONF, \ 126 | "Send buffer size in bytes"), \ 127 | AP_INIT_TAKE1("ReceiveBufferSize", ap_set_receive_buffer_size, NULL, \ 128 | RSRC_CONF, "Receive buffer size in bytes") 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | 134 | #endif 135 | /** @} */ 136 | -------------------------------------------------------------------------------- /include/mod_auth.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file mod_auth.h 19 | * @brief Authentication and Authorization Extension for Apache 20 | * 21 | * @defgroup MOD_AUTH mod_auth 22 | * @ingroup APACHE_MODS 23 | */ 24 | 25 | #ifndef APACHE_MOD_AUTH_H 26 | #define APACHE_MOD_AUTH_H 27 | 28 | #include "apr_pools.h" 29 | #include "apr_hash.h" 30 | #include "apr_optional.h" 31 | 32 | #include "httpd.h" 33 | #include "http_config.h" 34 | 35 | #ifdef __cplusplus 36 | extern "C" { 37 | #endif 38 | 39 | #define AUTHN_PROVIDER_GROUP "authn" 40 | #define AUTHZ_PROVIDER_GROUP "authz" 41 | #define AUTHN_PROVIDER_VERSION "0" 42 | #define AUTHZ_PROVIDER_VERSION "0" 43 | #define AUTHN_DEFAULT_PROVIDER "file" 44 | 45 | #define AUTHN_PROVIDER_NAME_NOTE "authn_provider_name" 46 | #define AUTHZ_PROVIDER_NAME_NOTE "authz_provider_name" 47 | 48 | #define AUTHN_PREFIX "AUTHENTICATE_" 49 | #define AUTHZ_PREFIX "AUTHORIZE_" 50 | 51 | /** all of the requirements must be met */ 52 | #ifndef SATISFY_ALL 53 | #define SATISFY_ALL 0 54 | #endif 55 | /** any of the requirements must be met */ 56 | #ifndef SATISFY_ANY 57 | #define SATISFY_ANY 1 58 | #endif 59 | /** There are no applicable satisfy lines */ 60 | #ifndef SATISFY_NOSPEC 61 | #define SATISFY_NOSPEC 2 62 | #endif 63 | 64 | typedef enum { 65 | AUTH_DENIED, 66 | AUTH_GRANTED, 67 | AUTH_USER_FOUND, 68 | AUTH_USER_NOT_FOUND, 69 | AUTH_GENERAL_ERROR 70 | } authn_status; 71 | 72 | typedef enum { 73 | AUTHZ_DENIED, 74 | AUTHZ_GRANTED, 75 | AUTHZ_NEUTRAL, 76 | AUTHZ_GENERAL_ERROR, 77 | AUTHZ_DENIED_NO_USER /* denied because r->user == NULL */ 78 | } authz_status; 79 | 80 | typedef struct { 81 | /* Given a username and password, expected to return AUTH_GRANTED 82 | * if we can validate this user/password combination. 83 | */ 84 | authn_status (*check_password)(request_rec *r, const char *user, 85 | const char *password); 86 | 87 | /* Given a user and realm, expected to return AUTH_USER_FOUND if we 88 | * can find a md5 hash of 'user:realm:password' 89 | */ 90 | authn_status (*get_realm_hash)(request_rec *r, const char *user, 91 | const char *realm, char **rethash); 92 | } authn_provider; 93 | 94 | /* A linked-list of authn providers. */ 95 | typedef struct authn_provider_list authn_provider_list; 96 | 97 | struct authn_provider_list { 98 | const char *provider_name; 99 | const authn_provider *provider; 100 | authn_provider_list *next; 101 | }; 102 | 103 | typedef struct { 104 | /* Given a request_rec, expected to return AUTHZ_GRANTED 105 | * if we can authorize user access. 106 | * @param r the request record 107 | * @param require_line the argument to the authz provider 108 | * @param parsed_require_line the value set by parse_require_line(), if any 109 | */ 110 | authz_status (*check_authorization)(request_rec *r, 111 | const char *require_line, 112 | const void *parsed_require_line); 113 | 114 | /** Check the syntax of a require line and optionally cache the parsed 115 | * line. This function may be NULL. 116 | * @param cmd the config directive 117 | * @param require_line the argument to the authz provider 118 | * @param parsed_require_line place to store parsed require_line for use by provider 119 | * @return Error message or NULL on success 120 | */ 121 | const char *(*parse_require_line)(cmd_parms *cmd, const char *require_line, 122 | const void **parsed_require_line); 123 | } authz_provider; 124 | 125 | /* ap_authn_cache_store: Optional function for authn providers 126 | * to enable cacheing their lookups with mod_authn_cache 127 | * @param r The request rec 128 | * @param module Module identifier 129 | * @param user User name to authenticate 130 | * @param realm Digest authn realm (NULL for basic authn) 131 | * @param data The value looked up by the authn provider, to cache 132 | */ 133 | APR_DECLARE_OPTIONAL_FN(void, ap_authn_cache_store, 134 | (request_rec*, const char*, const char*, 135 | const char*, const char*)); 136 | 137 | #ifdef __cplusplus 138 | } 139 | #endif 140 | 141 | #endif 142 | -------------------------------------------------------------------------------- /include/util_cookies.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_cookies.h 19 | * @brief Apache cookie library 20 | */ 21 | 22 | #ifndef UTIL_COOKIES_H 23 | #define UTIL_COOKIES_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * @defgroup APACHE_CORE_COOKIE Cookies 31 | * @ingroup APACHE_CORE 32 | * 33 | * RFC2109 and RFC2965 compliant HTTP cookies can be read from and written 34 | * to using this set of functions. 35 | * 36 | * @{ 37 | * 38 | */ 39 | 40 | #include "apr_errno.h" 41 | #include "httpd.h" 42 | 43 | #define SET_COOKIE "Set-Cookie" 44 | #define SET_COOKIE2 "Set-Cookie2" 45 | #define DEFAULT_ATTRS "HttpOnly;Secure;Version=1" 46 | #define CLEAR_ATTRS "Version=1" 47 | 48 | typedef struct { 49 | request_rec *r; 50 | const char *name; 51 | const char *encoded; 52 | apr_table_t *new_cookies; 53 | int duplicated; 54 | } ap_cookie_do; 55 | 56 | /** 57 | * Write an RFC2109 compliant cookie. 58 | * 59 | * @param r The request 60 | * @param name The name of the cookie. 61 | * @param val The value to place in the cookie. 62 | * @param attrs The string containing additional cookie attributes. If NULL, the 63 | * DEFAULT_ATTRS will be used. 64 | * @param maxage If non zero, a Max-Age header will be added to the cookie. 65 | * @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL 66 | * to which the cookies should be added. 67 | */ 68 | AP_DECLARE(apr_status_t) ap_cookie_write(request_rec * r, const char *name, 69 | const char *val, const char *attrs, 70 | long maxage, ...) 71 | AP_FN_ATTR_SENTINEL; 72 | 73 | /** 74 | * Write an RFC2965 compliant cookie. 75 | * 76 | * @param r The request 77 | * @param name2 The name of the cookie. 78 | * @param val The value to place in the cookie. 79 | * @param attrs2 The string containing additional cookie attributes. If NULL, the 80 | * DEFAULT_ATTRS will be used. 81 | * @param maxage If non zero, a Max-Age header will be added to the cookie. 82 | * @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL 83 | * to which the cookies should be added. 84 | */ 85 | AP_DECLARE(apr_status_t) ap_cookie_write2(request_rec * r, const char *name2, 86 | const char *val, const char *attrs2, 87 | long maxage, ...) 88 | AP_FN_ATTR_SENTINEL; 89 | 90 | /** 91 | * Remove an RFC2109 compliant cookie. 92 | * 93 | * @param r The request 94 | * @param name The name of the cookie. 95 | * @param attrs The string containing additional cookie attributes. If NULL, the 96 | * CLEAR_ATTRS will be used. 97 | * @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL 98 | * to which the cookies should be added. 99 | */ 100 | AP_DECLARE(apr_status_t) ap_cookie_remove(request_rec * r, const char *name, 101 | const char *attrs, ...) 102 | AP_FN_ATTR_SENTINEL; 103 | 104 | /** 105 | * Remove an RFC2965 compliant cookie. 106 | * 107 | * @param r The request 108 | * @param name2 The name of the cookie. 109 | * @param attrs2 The string containing additional cookie attributes. If NULL, the 110 | * CLEAR_ATTRS will be used. 111 | * @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL 112 | * to which the cookies should be added. 113 | */ 114 | AP_DECLARE(apr_status_t) ap_cookie_remove2(request_rec * r, const char *name2, 115 | const char *attrs2, ...) 116 | AP_FN_ATTR_SENTINEL; 117 | 118 | /** 119 | * Read a cookie called name, placing its value in val. 120 | * 121 | * Both the Cookie and Cookie2 headers are scanned for the cookie. 122 | * 123 | * If the cookie is duplicated, this function returns APR_EGENERAL. If found, 124 | * and if remove is non zero, the cookie will be removed from the headers, and 125 | * thus kept private from the backend. 126 | */ 127 | AP_DECLARE(apr_status_t) ap_cookie_read(request_rec * r, const char *name, const char **val, 128 | int remove); 129 | 130 | /** 131 | * Sanity check a given string that it exists, is not empty, 132 | * and does not contain the special characters '=', ';' and '&'. 133 | * 134 | * It is used to sanity check the cookie names. 135 | */ 136 | AP_DECLARE(apr_status_t) ap_cookie_check_string(const char *string); 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | #ifdef __cplusplus 143 | } 144 | #endif 145 | 146 | #endif /* !UTIL_COOKIES_H */ 147 | -------------------------------------------------------------------------------- /include/http_connection.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file http_connection.h 19 | * @brief Apache connection library 20 | * 21 | * @defgroup APACHE_CORE_CONNECTION Connection Library 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_HTTP_CONNECTION_H 27 | #define APACHE_HTTP_CONNECTION_H 28 | 29 | #include "apr_network_io.h" 30 | #include "apr_buckets.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | /** 36 | * @file http_connection.h 37 | * @brief Apache connection library 38 | */ 39 | 40 | /** 41 | * This is the protocol module driver. This calls all of the 42 | * pre-connection and connection hooks for all protocol modules. 43 | * @param c The connection on which the request is read 44 | * @param csd The mechanism on which this connection is to be read. 45 | * Most times this will be a socket, but it is up to the module 46 | * that accepts the request to determine the exact type. 47 | */ 48 | AP_CORE_DECLARE(void) ap_process_connection(conn_rec *c, void *csd); 49 | 50 | /** 51 | * Flushes all remain data in the client send buffer 52 | * @param c The connection to flush 53 | */ 54 | AP_CORE_DECLARE(void) ap_flush_conn(conn_rec *c); 55 | 56 | /** 57 | * This function is responsible for the following cases: 58 | *
 59 |  * we now proceed to read from the client until we get EOF, or until
 60 |  * MAX_SECS_TO_LINGER has passed.  the reasons for doing this are
 61 |  * documented in a draft:
 62 |  *
 63 |  * http://www.ics.uci.edu/pub/ietf/http/draft-ietf-http-connection-00.txt
 64 |  *
 65 |  * in a nutshell -- if we don't make this effort we risk causing
 66 |  * TCP RST packets to be sent which can tear down a connection before
 67 |  * all the response data has been sent to the client.
 68 |  * 
69 | * @param c The connection we are closing 70 | */ 71 | AP_DECLARE(void) ap_lingering_close(conn_rec *c); 72 | 73 | AP_DECLARE(int) ap_start_lingering_close(conn_rec *c); 74 | 75 | /* Hooks */ 76 | /** 77 | * create_connection is a RUN_FIRST hook which allows modules to create 78 | * connections. In general, you should not install filters with the 79 | * create_connection hook. If you require vhost configuration information 80 | * to make filter installation decisions, you must use the pre_connection 81 | * or install_network_transport hook. This hook should close the connection 82 | * if it encounters a fatal error condition. 83 | * 84 | * @param p The pool from which to allocate the connection record 85 | * @param server The server record to create the connection too. 86 | * @param csd The socket that has been accepted 87 | * @param conn_id A unique identifier for this connection. The ID only 88 | * needs to be unique at that time, not forever. 89 | * @param sbh A handle to scoreboard information for this connection. 90 | * @param alloc The bucket allocator to use for all bucket/brigade creations 91 | * @return An allocated connection record or NULL. 92 | */ 93 | AP_DECLARE_HOOK(conn_rec *, create_connection, 94 | (apr_pool_t *p, server_rec *server, apr_socket_t *csd, 95 | long conn_id, void *sbh, apr_bucket_alloc_t *alloc)) 96 | 97 | /** 98 | * This hook gives protocol modules an opportunity to set everything up 99 | * before calling the protocol handler. All pre-connection hooks are 100 | * run until one returns something other than ok or decline 101 | * @param c The connection on which the request has been received. 102 | * @param csd The mechanism on which this connection is to be read. 103 | * Most times this will be a socket, but it is up to the module 104 | * that accepts the request to determine the exact type. 105 | * @return OK or DECLINED 106 | */ 107 | AP_DECLARE_HOOK(int,pre_connection,(conn_rec *c, void *csd)) 108 | 109 | /** 110 | * This hook implements different protocols. After a connection has been 111 | * established, the protocol module must read and serve the request. This 112 | * function does that for each protocol module. The first protocol module 113 | * to handle the request is the last module run. 114 | * @param c The connection on which the request has been received. 115 | * @return OK or DECLINED 116 | */ 117 | AP_DECLARE_HOOK(int,process_connection,(conn_rec *c)) 118 | 119 | /** End Of Connection (EOC) bucket */ 120 | AP_DECLARE_DATA extern const apr_bucket_type_t ap_bucket_type_eoc; 121 | 122 | /** 123 | * Determine if a bucket is an End Of Connection (EOC) bucket 124 | * @param e The bucket to inspect 125 | * @return true or false 126 | */ 127 | #define AP_BUCKET_IS_EOC(e) (e->type == &ap_bucket_type_eoc) 128 | 129 | /** 130 | * Make the bucket passed in an End Of Connection (EOC) bucket 131 | * @param b The bucket to make into an EOC bucket 132 | * @return The new bucket, or NULL if allocation failed 133 | */ 134 | AP_DECLARE(apr_bucket *) ap_bucket_eoc_make(apr_bucket *b); 135 | 136 | /** 137 | * Create a bucket referring to an End Of Connection (EOC). This indicates 138 | * that the connection will be closed. 139 | * @param list The freelist from which this bucket should be allocated 140 | * @return The new bucket, or NULL if allocation failed 141 | */ 142 | AP_DECLARE(apr_bucket *) ap_bucket_eoc_create(apr_bucket_alloc_t *list); 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* !APACHE_HTTP_REQUEST_H */ 149 | /** @} */ 150 | -------------------------------------------------------------------------------- /test/ab-mruby.test.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Usage: ./ab-mruby -m ab-mruby.conf.rb -M ab-mruby.text.rb [http[s]://]hostname[:port]/path 3 | # 4 | # TEST PARAMETERS 5 | # 6 | # "TargetURL" 7 | # "TargetHost" 8 | # "TargetPort" 9 | # "TargetPath" 10 | # "TargetisSSL" 11 | # "TargetServerSoftware" 12 | # "TargetServerHost" 13 | # "TargetServerPort" 14 | # "TargetServerSSLInfo" # if use SSL 15 | # "TargetDocumentPath" 16 | # "TargetDocumentLength" 17 | # "TimeTakenforTests" 18 | # "CompleteRequests" 19 | # "FailedRequests" 20 | # "ConnetcErrors" # if FailedRequests > 0 21 | # "ReceiveErrors" # if FailedRequests > 0 22 | # "LengthErrors" # if FailedRequests > 0 23 | # "ExceptionsErrors" # if FailedRequests > 0 24 | # "WriteErrors" 25 | # "Non2xxResponses" # if Non2xxResponse > 0 26 | # "KeepAliveRequests" 27 | # "TotalTransferred" 28 | # "TotalBodySent" # if body send 29 | # "HTMLTransferred" 30 | # "RequestPerSecond" 31 | # "TimePerConcurrentRequest" 32 | # "TimePerRequest" 33 | # "TransferRate" 34 | # 35 | 36 | print < 39 | Licensed to MATSUMOTO Ryosuke, https://github.com/matsumoto-r/ab-mruby 40 | 41 | TEST PHASE 42 | 43 | ====================================================================== 44 | EOS 45 | 46 | if get_config["TargetHost"] == "blog.example.jp" 47 | 48 | test_suite do 49 | "TargetServerHost".should_be "blog.example.jp" 50 | "TargetServerPort".should_be 80 51 | "TargetDocumentPath".should_be "/" 52 | "TargetServerSoftware".should_be "nginx/1.4.1" 53 | "FailedRequests".should_be 0 54 | "KeepAliveRequests".should_be 0 55 | "WriteErrors".should_be 0 56 | "HTMLTransferred".should_be_over 0 57 | "TargetDocumentLength".should_be_over 0 58 | "TotalTransferred".should_be_over 0 59 | "CompleteRequests".should_be 100 60 | "TransferRate".should_be_over 4000 61 | "TimeTakenforTests".should_be_under 5 62 | "RequestPerSecond".should_be_over 40 63 | "TimePerRequest".should_be_under 20 64 | "TimePerConcurrentRequest".should_be_under 200 65 | "TotalBodySent".should_be 0 66 | "ConnetcErrors".should_be 0 67 | "ReceiveErrors".should_be 0 68 | "LengthErrors".should_be 0 69 | "ExceptionsErrors".should_be 0 70 | "Non2xxResponses".should_be 0 71 | end 72 | 73 | elsif get_config["TargetHost"] == "moblog.example.jp" 74 | 75 | test_suite do 76 | "TargetServerHost".should_be "moblog.example.jp" 77 | "TargetServerPort".should_be 80 78 | "TargetDocumentPath".should_be "/" 79 | "TargetServerSoftware".should_be "nginx/1.4.1" 80 | "FailedRequests".should_be 0 81 | "KeepAliveRequests".should_be 0 82 | "WriteErrors".should_be 0 83 | "HTMLTransferred".should_be_over 0 84 | "TargetDocumentLength".should_be_over 0 85 | "TotalTransferred".should_be_over 0 86 | "CompleteRequests".should_be 200 87 | "TransferRate".should_be_over 500 88 | "TimeTakenforTests".should_be_under 5 89 | "RequestPerSecond".should_be_over 40 90 | "TimePerRequest".should_be_under 30 91 | "TimePerConcurrentRequest".should_be_under 500 92 | "TotalBodySent".should_be 0 93 | "ConnetcErrors".should_be 0 94 | "ReceiveErrors".should_be 0 95 | "LengthErrors".should_be 0 96 | "ExceptionsErrors".should_be 0 97 | "Non2xxResponses".should_be 0 98 | end 99 | 100 | elsif get_config["TargetHost"] == "example.org" 101 | 102 | test_suite do 103 | "TargetServerHost".should_be "example.org" 104 | "TargetServerPort".should_be 443 105 | "TargetDocumentPath".should_be "/" 106 | "TargetServerSoftware".should_be "nginx/1.4.1" 107 | "FailedRequests".should_be 0 108 | "KeepAliveRequests".should_be 0 109 | "WriteErrors".should_be 0 110 | "HTMLTransferred".should_be_over 0 111 | "TargetDocumentLength".should_be_over 0 112 | "TotalTransferred".should_be_over 0 113 | "CompleteRequests".should_be 300 114 | "TransferRate".should_be_over 500 115 | "TimeTakenforTests".should_be_under 30 116 | "RequestPerSecond".should_be_over 10 117 | "TimePerRequest".should_be_under 100 118 | "TimePerConcurrentRequest".should_be_under 3000 119 | "TotalBodySent".should_be 0 120 | "ConnetcErrors".should_be 0 121 | "ReceiveErrors".should_be 0 122 | "LengthErrors".should_be 0 123 | "ExceptionsErrors".should_be 0 124 | "Non2xxResponses".should_be 0 125 | end 126 | 127 | else 128 | 129 | test_suite do 130 | "FailedRequests".should_be 0 131 | "WriteErrors".should_be 0 132 | "CompleteRequests".should_be 100 133 | "TransferRate".should_be_over 500 134 | "RequestPerSecond".should_be_over 1000 135 | "TimePerRequest".should_be_under 100 136 | "TimePerConcurrentRequest".should_be_under 3000 137 | "ConnetcErrors".should_be 0 138 | "ReceiveErrors".should_be 0 139 | "LengthErrors".should_be 0 140 | "ExceptionsErrors".should_be 0 141 | "Non2xxResponses".should_be 0 142 | end 143 | 144 | end 145 | 146 | test_run 147 | -------------------------------------------------------------------------------- /include/ap_hooks.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_hooks.h 19 | * @brief ap hook functions and macros 20 | */ 21 | 22 | #ifndef AP_HOOKS_H 23 | #define AP_HOOKS_H 24 | 25 | /* Although this file doesn't declare any hooks, declare the hook group here */ 26 | /** 27 | * @defgroup hooks Apache Hooks 28 | * @ingroup APACHE_CORE 29 | */ 30 | 31 | #if defined(AP_HOOK_PROBES_ENABLED) && !defined(APR_HOOK_PROBES_ENABLED) 32 | #define APR_HOOK_PROBES_ENABLED 1 33 | #endif 34 | 35 | #ifdef APR_HOOK_PROBES_ENABLED 36 | #include "ap_hook_probes.h" 37 | #endif 38 | 39 | #include "apr.h" 40 | #include "apr_hooks.h" 41 | #include "apr_optional_hooks.h" 42 | 43 | #ifdef DOXYGEN 44 | /* define these just so doxygen documents them */ 45 | 46 | /** 47 | * AP_DECLARE_STATIC is defined when including Apache's Core headers, 48 | * to provide static linkage when the dynamic library may be unavailable. 49 | * 50 | * @see AP_DECLARE_EXPORT 51 | * 52 | * AP_DECLARE_STATIC and AP_DECLARE_EXPORT are left undefined when 53 | * including Apache's Core headers, to import and link the symbols from the 54 | * dynamic Apache Core library and assure appropriate indirection and calling 55 | * conventions at compile time. 56 | */ 57 | # define AP_DECLARE_STATIC 58 | /** 59 | * AP_DECLARE_EXPORT is defined when building the Apache Core dynamic 60 | * library, so that all public symbols are exported. 61 | * 62 | * @see AP_DECLARE_STATIC 63 | */ 64 | # define AP_DECLARE_EXPORT 65 | 66 | #endif /* def DOXYGEN */ 67 | 68 | /** 69 | * Declare a hook function 70 | * @param ret The return type of the hook 71 | * @param name The hook's name (as a literal) 72 | * @param args The arguments the hook function takes, in brackets. 73 | */ 74 | #define AP_DECLARE_HOOK(ret,name,args) \ 75 | APR_DECLARE_EXTERNAL_HOOK(ap,AP,ret,name,args) 76 | 77 | /** @internal */ 78 | #define AP_IMPLEMENT_HOOK_BASE(name) \ 79 | APR_IMPLEMENT_EXTERNAL_HOOK_BASE(ap,AP,name) 80 | 81 | /** 82 | * Implement an Apache core hook that has no return code, and 83 | * therefore runs all of the registered functions. The implementation 84 | * is called ap_run_name. 85 | * 86 | * @param name The name of the hook 87 | * @param args_decl The declaration of the arguments for the hook, for example 88 | * "(int x,void *y)" 89 | * @param args_use The arguments for the hook as used in a call, for example 90 | * "(x,y)" 91 | * @note If IMPLEMENTing a hook that is not linked into the Apache core, 92 | * (e.g. within a dso) see APR_IMPLEMENT_EXTERNAL_HOOK_VOID. 93 | */ 94 | #define AP_IMPLEMENT_HOOK_VOID(name,args_decl,args_use) \ 95 | APR_IMPLEMENT_EXTERNAL_HOOK_VOID(ap,AP,name,args_decl,args_use) 96 | 97 | /** 98 | * Implement an Apache core hook that runs until one of the functions 99 | * returns something other than ok or decline. That return value is 100 | * then returned from the hook runner. If the hooks run to completion, 101 | * then ok is returned. Note that if no hook runs it would probably be 102 | * more correct to return decline, but this currently does not do 103 | * so. The implementation is called ap_run_name. 104 | * 105 | * @param ret The return type of the hook (and the hook runner) 106 | * @param name The name of the hook 107 | * @param args_decl The declaration of the arguments for the hook, for example 108 | * "(int x,void *y)" 109 | * @param args_use The arguments for the hook as used in a call, for example 110 | * "(x,y)" 111 | * @param ok The "ok" return value 112 | * @param decline The "decline" return value 113 | * @return ok, decline or an error. 114 | * @note If IMPLEMENTing a hook that is not linked into the Apache core, 115 | * (e.g. within a dso) see APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL. 116 | */ 117 | #define AP_IMPLEMENT_HOOK_RUN_ALL(ret,name,args_decl,args_use,ok,decline) \ 118 | APR_IMPLEMENT_EXTERNAL_HOOK_RUN_ALL(ap,AP,ret,name,args_decl, \ 119 | args_use,ok,decline) 120 | 121 | /** 122 | * Implement a hook that runs until a function returns something other than 123 | * decline. If all functions return decline, the hook runner returns decline. 124 | * The implementation is called ap_run_name. 125 | * 126 | * @param ret The return type of the hook (and the hook runner) 127 | * @param name The name of the hook 128 | * @param args_decl The declaration of the arguments for the hook, for example 129 | * "(int x,void *y)" 130 | * @param args_use The arguments for the hook as used in a call, for example 131 | * "(x,y)" 132 | * @param decline The "decline" return value 133 | * @return decline or an error. 134 | * @note If IMPLEMENTing a hook that is not linked into the Apache core 135 | * (e.g. within a dso) see APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST. 136 | */ 137 | #define AP_IMPLEMENT_HOOK_RUN_FIRST(ret,name,args_decl,args_use,decline) \ 138 | APR_IMPLEMENT_EXTERNAL_HOOK_RUN_FIRST(ap,AP,ret,name,args_decl, \ 139 | args_use,decline) 140 | 141 | /* Note that the other optional hook implementations are straightforward but 142 | * have not yet been needed 143 | */ 144 | 145 | /** 146 | * Implement an optional hook. This is exactly the same as a standard hook 147 | * implementation, except the hook is optional. 148 | * @see AP_IMPLEMENT_HOOK_RUN_ALL 149 | */ 150 | #define AP_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ret,name,args_decl,args_use,ok, \ 151 | decline) \ 152 | APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(ap,AP,ret,name,args_decl, \ 153 | args_use,ok,decline) 154 | 155 | /** 156 | * Hook an optional hook. Unlike static hooks, this uses a macro instead of a 157 | * function. 158 | */ 159 | #define AP_OPTIONAL_HOOK(name,fn,pre,succ,order) \ 160 | APR_OPTIONAL_HOOK(ap,name,fn,pre,succ,order) 161 | 162 | #endif /* AP_HOOKS_H */ 163 | -------------------------------------------------------------------------------- /docker/ab-mruby.test.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Usage: ./ab-mruby -m ab-mruby.conf.rb -M ab-mruby.text.rb [http[s]://]hostname[:port]/path 3 | # 4 | # BENCHMARK RESULT AND TEST PARAMETERS 5 | # 6 | # get_config "TargetURL" 7 | # get_config "TargetHost" 8 | # get_config "TargetPort" 9 | # get_config "TargetPath" 10 | # get_config "TargetisSSL" 11 | # get_config "TargetServerSoftware" 12 | # get_config "TargetServerHost" 13 | # get_config "TargetServerPort" 14 | # get_config "TargetServerSSLInfo" # if use SSL 15 | # get_config "TargetDocumentPath" 16 | # get_config "TargetDocumentLength" 17 | # get_config "TimeTakenforTests" 18 | # get_config "CompleteRequests" 19 | # get_config "FailedRequests" 20 | # get_config "ConnetcErrors" # if FailedRequests > 0 21 | # get_config "ReceiveErrors" # if FailedRequests > 0 22 | # get_config "LengthErrors" # if FailedRequests > 0 23 | # get_config "ExceptionsErrors" # if FailedRequests > 0 24 | # get_config "WriteErrors" 25 | # get_config "Non2xxResponses" # if Non2xxResponse > 0 26 | # get_config "KeepAliveRequests" 27 | # get_config "TotalTransferred" 28 | # get_config "TotalBodySent" # if body send 29 | # get_config "HTMLTransferred" 30 | # get_config "RequestPerSecond" 31 | # get_config "TimePerConcurrentRequest" 32 | # get_config "TimePerRequest" 33 | # get_config "TransferRate" 34 | # 35 | 36 | module Kernel 37 | def test_suite &blk 38 | @@r = get_config 39 | @@t = blk 40 | @@result = true 41 | end 42 | def bln_color val 43 | (val) ? "[\e[33m#{val}\e[m]" : "[\e[36m#{val}\e[m]" 44 | end 45 | def should_be val 46 | ret = @@r[self] == val 47 | puts "[TEST CASE] #{bln_color ret} #{self} (#{@@r[self]}) should be #{val}" 48 | @@result = ret if ret == false 49 | end 50 | def should_be_over val 51 | ret = @@r[self] > val 52 | puts "[TEST CASE] #{bln_color ret} #{self} (#{@@r[self]}) should be over #{val}" 53 | @@result = ret if ret == false 54 | end 55 | def should_be_under val 56 | ret = @@r[self] < val 57 | puts "[TEST CASE] #{bln_color ret} #{self} (#{@@r[self]}) should be under #{val}" 58 | @@result = ret if ret == false 59 | end 60 | def test_run 61 | @@t.call 62 | puts "\ntest suites: #{bln_color @@result}\n" 63 | end 64 | end 65 | 66 | print < 69 | Licensed to MATSUMOTO Ryosuke, https://github.com/matsumoto-r/ab-mruby 70 | 71 | TEST PHASE 72 | 73 | ====================================================================== 74 | EOS 75 | 76 | if get_config["TargetHost"] == "blog.example.jp" 77 | 78 | test_suite do 79 | "TargetServerHost".should_be "blog.example.jp" 80 | "TargetServerPort".should_be 80 81 | "TargetDocumentPath".should_be "/" 82 | "TargetServerSoftware".should_be "nginx/1.4.1" 83 | "FailedRequests".should_be 0 84 | "KeepAliveRequests".should_be 0 85 | "WriteErrors".should_be 0 86 | "HTMLTransferred".should_be_over 0 87 | "TargetDocumentLength".should_be_over 0 88 | "TotalTransferred".should_be_over 0 89 | "CompleteRequests".should_be 100 90 | "TransferRate".should_be_over 4000 91 | "TimeTakenforTests".should_be_under 5 92 | "RequestPerSecond".should_be_over 40 93 | "TimePerRequest".should_be_under 20 94 | "TimePerConcurrentRequest".should_be_under 200 95 | "TotalBodySent".should_be 0 96 | "ConnetcErrors".should_be 0 97 | "ReceiveErrors".should_be 0 98 | "LengthErrors".should_be 0 99 | "ExceptionsErrors".should_be 0 100 | "Non2xxResponses".should_be 0 101 | end 102 | 103 | elsif get_config["TargetHost"] == "moblog.example.jp" 104 | 105 | test_suite do 106 | "TargetServerHost".should_be "moblog.example.jp" 107 | "TargetServerPort".should_be 80 108 | "TargetDocumentPath".should_be "/" 109 | "TargetServerSoftware".should_be "nginx/1.4.1" 110 | "FailedRequests".should_be 0 111 | "KeepAliveRequests".should_be 0 112 | "WriteErrors".should_be 0 113 | "HTMLTransferred".should_be_over 0 114 | "TargetDocumentLength".should_be_over 0 115 | "TotalTransferred".should_be_over 0 116 | "CompleteRequests".should_be 200 117 | "TransferRate".should_be_over 500 118 | "TimeTakenforTests".should_be_under 5 119 | "RequestPerSecond".should_be_over 40 120 | "TimePerRequest".should_be_under 30 121 | "TimePerConcurrentRequest".should_be_under 500 122 | "TotalBodySent".should_be 0 123 | "ConnetcErrors".should_be 0 124 | "ReceiveErrors".should_be 0 125 | "LengthErrors".should_be 0 126 | "ExceptionsErrors".should_be 0 127 | "Non2xxResponses".should_be 0 128 | end 129 | 130 | elsif get_config["TargetHost"] == "example.org" 131 | 132 | test_suite do 133 | "TargetServerHost".should_be "example.org" 134 | "TargetServerPort".should_be 443 135 | "TargetDocumentPath".should_be "/" 136 | "TargetServerSoftware".should_be "nginx/1.4.1" 137 | "FailedRequests".should_be 0 138 | "KeepAliveRequests".should_be 0 139 | "WriteErrors".should_be 0 140 | "HTMLTransferred".should_be_over 0 141 | "TargetDocumentLength".should_be_over 0 142 | "TotalTransferred".should_be_over 0 143 | "CompleteRequests".should_be 300 144 | "TransferRate".should_be_over 500 145 | "TimeTakenforTests".should_be_under 30 146 | "RequestPerSecond".should_be_over 10 147 | "TimePerRequest".should_be_under 100 148 | "TimePerConcurrentRequest".should_be_under 3000 149 | "TotalBodySent".should_be 0 150 | "ConnetcErrors".should_be 0 151 | "ReceiveErrors".should_be 0 152 | "LengthErrors".should_be 0 153 | "ExceptionsErrors".should_be 0 154 | "Non2xxResponses".should_be 0 155 | end 156 | 157 | else 158 | 159 | test_suite do 160 | "FailedRequests".should_be 0 161 | "WriteErrors".should_be 0 162 | "CompleteRequests".should_be 100 163 | "TransferRate".should_be_over 500 164 | "RequestPerSecond".should_be_over 1000 165 | "TimePerRequest".should_be_under 100 166 | "TimePerConcurrentRequest".should_be_under 3000 167 | "ConnetcErrors".should_be 0 168 | "ReceiveErrors".should_be 0 169 | "LengthErrors".should_be 0 170 | "ExceptionsErrors".should_be 0 171 | "Non2xxResponses".should_be 0 172 | end 173 | 174 | end 175 | 176 | test_run 177 | -------------------------------------------------------------------------------- /include/ap_config.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_config.h 19 | * @brief Symbol export macros and hook functions 20 | */ 21 | 22 | #ifndef AP_CONFIG_H 23 | #define AP_CONFIG_H 24 | 25 | #include "ap_hooks.h" 26 | 27 | /* Although this file doesn't declare any hooks, declare the exports group here */ 28 | /** 29 | * @defgroup exports Apache exports 30 | * @ingroup APACHE_CORE 31 | */ 32 | 33 | #ifdef DOXYGEN 34 | /* define these just so doxygen documents them */ 35 | 36 | /** 37 | * AP_DECLARE_STATIC is defined when including Apache's Core headers, 38 | * to provide static linkage when the dynamic library may be unavailable. 39 | * 40 | * @see AP_DECLARE_EXPORT 41 | * 42 | * AP_DECLARE_STATIC and AP_DECLARE_EXPORT are left undefined when 43 | * including Apache's Core headers, to import and link the symbols from the 44 | * dynamic Apache Core library and assure appropriate indirection and calling 45 | * conventions at compile time. 46 | */ 47 | # define AP_DECLARE_STATIC 48 | /** 49 | * AP_DECLARE_EXPORT is defined when building the Apache Core dynamic 50 | * library, so that all public symbols are exported. 51 | * 52 | * @see AP_DECLARE_STATIC 53 | */ 54 | # define AP_DECLARE_EXPORT 55 | 56 | #endif /* def DOXYGEN */ 57 | 58 | #if !defined(WIN32) 59 | /** 60 | * Apache Core dso functions are declared with AP_DECLARE(), so they may 61 | * use the most appropriate calling convention. Hook functions and other 62 | * Core functions with variable arguments must use AP_DECLARE_NONSTD(). 63 | * @code 64 | * AP_DECLARE(rettype) ap_func(args) 65 | * @endcode 66 | */ 67 | #define AP_DECLARE(type) type 68 | 69 | /** 70 | * Apache Core dso variable argument and hook functions are declared with 71 | * AP_DECLARE_NONSTD(), as they must use the C language calling convention. 72 | * @see AP_DECLARE 73 | * @code 74 | * AP_DECLARE_NONSTD(rettype) ap_func(args [...]) 75 | * @endcode 76 | */ 77 | #define AP_DECLARE_NONSTD(type) type 78 | 79 | /** 80 | * Apache Core dso variables are declared with AP_MODULE_DECLARE_DATA. 81 | * This assures the appropriate indirection is invoked at compile time. 82 | * 83 | * @note AP_DECLARE_DATA extern type apr_variable; syntax is required for 84 | * declarations within headers to properly import the variable. 85 | * @code 86 | * AP_DECLARE_DATA type apr_variable 87 | * @endcode 88 | */ 89 | #define AP_DECLARE_DATA 90 | 91 | #elif defined(AP_DECLARE_STATIC) 92 | #define AP_DECLARE(type) type __stdcall 93 | #define AP_DECLARE_NONSTD(type) type 94 | #define AP_DECLARE_DATA 95 | #elif defined(AP_DECLARE_EXPORT) 96 | #define AP_DECLARE(type) __declspec(dllexport) type __stdcall 97 | #define AP_DECLARE_NONSTD(type) __declspec(dllexport) type 98 | #define AP_DECLARE_DATA __declspec(dllexport) 99 | #else 100 | #define AP_DECLARE(type) __declspec(dllimport) type __stdcall 101 | #define AP_DECLARE_NONSTD(type) __declspec(dllimport) type 102 | #define AP_DECLARE_DATA __declspec(dllimport) 103 | #endif 104 | 105 | #if !defined(WIN32) || defined(AP_MODULE_DECLARE_STATIC) 106 | /** 107 | * Declare a dso module's exported module structure as AP_MODULE_DECLARE_DATA. 108 | * 109 | * Unless AP_MODULE_DECLARE_STATIC is defined at compile time, symbols 110 | * declared with AP_MODULE_DECLARE_DATA are always exported. 111 | * @code 112 | * module AP_MODULE_DECLARE_DATA mod_tag 113 | * @endcode 114 | */ 115 | #if defined(WIN32) 116 | #define AP_MODULE_DECLARE(type) type __stdcall 117 | #else 118 | #define AP_MODULE_DECLARE(type) type 119 | #endif 120 | #define AP_MODULE_DECLARE_NONSTD(type) type 121 | #define AP_MODULE_DECLARE_DATA 122 | #else 123 | /** 124 | * AP_MODULE_DECLARE_EXPORT is a no-op. Unless contradicted by the 125 | * AP_MODULE_DECLARE_STATIC compile-time symbol, it is assumed and defined. 126 | * 127 | * The old SHARED_MODULE compile-time symbol is now the default behavior, 128 | * so it is no longer referenced anywhere with Apache 2.0. 129 | */ 130 | #define AP_MODULE_DECLARE_EXPORT 131 | #define AP_MODULE_DECLARE(type) __declspec(dllexport) type __stdcall 132 | #define AP_MODULE_DECLARE_NONSTD(type) __declspec(dllexport) type 133 | #define AP_MODULE_DECLARE_DATA __declspec(dllexport) 134 | #endif 135 | 136 | #include "os.h" 137 | #if (!defined(WIN32) && !defined(NETWARE)) || defined(__MINGW32__) 138 | #include "ap_config_auto.h" 139 | #endif 140 | #include "ap_config_layout.h" 141 | 142 | /* Where the main/parent process's pid is logged */ 143 | #ifndef DEFAULT_PIDLOG 144 | #define DEFAULT_PIDLOG DEFAULT_REL_RUNTIMEDIR "/httpd.pid" 145 | #endif 146 | 147 | #if defined(NETWARE) 148 | #define AP_NONBLOCK_WHEN_MULTI_LISTEN 1 149 | #endif 150 | 151 | #if defined(AP_ENABLE_DTRACE) && HAVE_SYS_SDT_H 152 | #include 153 | #else 154 | #undef _DTRACE_VERSION 155 | #endif 156 | 157 | #ifdef _DTRACE_VERSION 158 | #include "apache_probes.h" 159 | #else 160 | #include "apache_noprobes.h" 161 | #endif 162 | 163 | /* If APR has OTHER_CHILD logic, use reliable piped logs. */ 164 | #if APR_HAS_OTHER_CHILD 165 | #define AP_HAVE_RELIABLE_PIPED_LOGS TRUE 166 | #endif 167 | 168 | #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 169 | #define AP_HAVE_C99 170 | #endif 171 | 172 | /* Presume that the compiler supports C99-style designated 173 | * initializers if using GCC (but not G++), or for any other compiler 174 | * which claims C99 support. */ 175 | #if (defined(__GNUC__) && !defined(__cplusplus)) || defined(AP_HAVE_C99) 176 | #define AP_HAVE_DESIGNATED_INITIALIZER 177 | #endif 178 | 179 | #ifndef __has_attribute /* check for supported attributes on clang */ 180 | #define __has_attribute(x) 0 181 | #endif 182 | #if (defined(__GNUC__) && __GNUC__ >= 4) || __has_attribute(sentinel) 183 | #define AP_FN_ATTR_SENTINEL __attribute__((sentinel)) 184 | #else 185 | #define AP_FN_ATTR_SENTINEL 186 | #endif 187 | 188 | #if ( defined(__GNUC__) && \ 189 | (__GNUC__ >= 4 || ( __GNUC__ == 3 && __GNUC_MINOR__ >= 4))) \ 190 | || __has_attribute(warn_unused_result) 191 | #define AP_FN_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result)) 192 | #else 193 | #define AP_FN_ATTR_WARN_UNUSED_RESULT 194 | #endif 195 | 196 | #if ( defined(__GNUC__) && \ 197 | (__GNUC__ >= 4 && __GNUC_MINOR__ >= 3)) \ 198 | || __has_attribute(alloc_size) 199 | #define AP_FN_ATTR_ALLOC_SIZE(x) __attribute__((alloc_size(x))) 200 | #define AP_FN_ATTR_ALLOC_SIZE2(x,y) __attribute__((alloc_size(x,y))) 201 | #else 202 | #define AP_FN_ATTR_ALLOC_SIZE(x) 203 | #define AP_FN_ATTR_ALLOC_SIZE2(x,y) 204 | #endif 205 | 206 | #endif /* AP_CONFIG_H */ 207 | -------------------------------------------------------------------------------- /include/ap_slotmem.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef SLOTMEM_H 18 | #define SLOTMEM_H 19 | 20 | /* Memory handler for a shared memory divided in slot. 21 | */ 22 | /** 23 | * @file ap_slotmem.h 24 | * @brief Memory Slot Extension Storage Module for Apache 25 | * 26 | * @defgroup MEM mem 27 | * @ingroup APACHE_MODS 28 | * @{ 29 | */ 30 | 31 | #include "httpd.h" 32 | #include "http_config.h" 33 | #include "http_log.h" 34 | #include "ap_provider.h" 35 | 36 | #include "apr.h" 37 | #include "apr_strings.h" 38 | #include "apr_pools.h" 39 | #include "apr_shm.h" 40 | #include "apr_global_mutex.h" 41 | #include "apr_file_io.h" 42 | 43 | #if APR_HAVE_UNISTD_H 44 | #include /* for getpid() */ 45 | #endif 46 | 47 | #ifdef __cplusplus 48 | extern "C" { 49 | #endif 50 | 51 | #define AP_SLOTMEM_PROVIDER_GROUP "slotmem" 52 | #define AP_SLOTMEM_PROVIDER_VERSION "0" 53 | 54 | typedef unsigned int ap_slotmem_type_t; 55 | 56 | /* 57 | * Values for ap_slotmem_type_t:: 58 | * 59 | * AP_SLOTMEM_TYPE_PERSIST: For transitory providers, persist 60 | * the data on the file-system 61 | * 62 | * AP_SLOTMEM_TYPE_NOTMPSAFE: 63 | * 64 | * AP_SLOTMEM_TYPE_PREALLOC: Access to slots require they be grabbed 1st 65 | * 66 | * AP_SLOTMEM_TYPE_CLEARINUSE: If persisting, clear 'inuse' array before 67 | * storing 68 | */ 69 | #define AP_SLOTMEM_TYPE_PERSIST (1 << 0) 70 | #define AP_SLOTMEM_TYPE_NOTMPSAFE (1 << 1) 71 | #define AP_SLOTMEM_TYPE_PREGRAB (1 << 2) 72 | #define AP_SLOTMEM_TYPE_CLEARINUSE (1 << 3) 73 | 74 | typedef struct ap_slotmem_instance_t ap_slotmem_instance_t; 75 | 76 | /** 77 | * callback function used for slotmem doall. 78 | * @param mem is the memory associated with a worker. 79 | * @param data is what is passed to slotmem. 80 | * @param pool is pool used 81 | * @return APR_SUCCESS if all went well 82 | */ 83 | typedef apr_status_t ap_slotmem_callback_fn_t(void* mem, void *data, apr_pool_t *pool); 84 | 85 | struct ap_slotmem_provider_t { 86 | /* 87 | * Name of the provider method 88 | */ 89 | const char *name; 90 | /** 91 | * call the callback on all worker slots 92 | * @param s ap_slotmem_instance_t to use. 93 | * @param funct callback function to call for each element. 94 | * @param data parameter for the callback function. 95 | * @param pool is pool used 96 | * @return APR_SUCCESS if all went well 97 | */ 98 | apr_status_t (* doall)(ap_slotmem_instance_t *s, ap_slotmem_callback_fn_t *func, void *data, apr_pool_t *pool); 99 | /** 100 | * create a new slotmem with each item size is item_size. 101 | * This would create shared memory, basically. 102 | * @param inst where to store pointer to slotmem 103 | * @param name a key used for debugging and in mod_status output or allow another process to share this space. 104 | * @param item_size size of each item 105 | * @param item_num number of item to create. 106 | * @param type type of slotmem. 107 | * @param pool is pool used 108 | * @return APR_SUCCESS if all went well 109 | */ 110 | apr_status_t (* create)(ap_slotmem_instance_t **inst, const char *name, apr_size_t item_size, unsigned int item_num, ap_slotmem_type_t type, apr_pool_t *pool); 111 | /** 112 | * attach to an existing slotmem. 113 | * This would attach to shared memory, basically. 114 | * @param inst where to store pointer to slotmem 115 | * @param name a key used for debugging and in mod_status output or allow another process to share this space. 116 | * @param item_size size of each item 117 | * @param item_num max number of item. 118 | * @param pool is pool to memory allocate. 119 | * @return APR_SUCCESS if all went well 120 | */ 121 | apr_status_t (* attach)(ap_slotmem_instance_t **inst, const char *name, apr_size_t *item_size, unsigned int *item_num, apr_pool_t *pool); 122 | /** 123 | * get the memory ptr associated with this worker slot. 124 | * @param s ap_slotmem_instance_t to use. 125 | * @param item_id item to return for 0 to item_num 126 | * @param mem address to store the pointer to the slot 127 | * @return APR_SUCCESS if all went well 128 | */ 129 | apr_status_t (* dptr)(ap_slotmem_instance_t *s, unsigned int item_id, void**mem); 130 | /** 131 | * get/read the data associated with this worker slot. 132 | * @param s ap_slotmem_instance_t to use. 133 | * @param item_id item to return for 0 to item_num 134 | * @param dest address to store the data 135 | * @param dest_len length of dataset to retrieve 136 | * @return APR_SUCCESS if all went well 137 | */ 138 | apr_status_t (* get)(ap_slotmem_instance_t *s, unsigned int item_id, unsigned char *dest, apr_size_t dest_len); 139 | /** 140 | * put/write the data associated with this worker slot. 141 | * @param s ap_slotmem_instance_t to use. 142 | * @param item_id item to return for 0 to item_num 143 | * @param src address of the data to store in the slot 144 | * @param src_len length of dataset to store in the slot 145 | * @return APR_SUCCESS if all went well 146 | */ 147 | apr_status_t (* put)(ap_slotmem_instance_t *slot, unsigned int item_id, unsigned char *src, apr_size_t src_len); 148 | /** 149 | * return number of slots allocated for this entry. 150 | * @param s ap_slotmem_instance_t to use. 151 | * @return number of slots 152 | */ 153 | unsigned int (* num_slots)(ap_slotmem_instance_t *s); 154 | /** 155 | * return number of free (not used) slots allocated for this entry. 156 | * Valid for slots which are AP_SLOTMEM_TYPE_PREGRAB as well as 157 | * any which use get/release. 158 | * @param s ap_slotmem_instance_t to use. 159 | * @return number of slots 160 | */ 161 | unsigned int (* num_free_slots)(ap_slotmem_instance_t *s); 162 | /** 163 | * return slot size allocated for this entry. 164 | * @param s ap_slotmem_instance_t to use. 165 | * @return size of slot 166 | */ 167 | apr_size_t (* slot_size)(ap_slotmem_instance_t *s); 168 | /** 169 | * grab (or alloc) a free slot 170 | * @param s ap_slotmem_instance_t to use. 171 | * @param item_id ptr to the available slot id and marked as in-use 172 | * @return APR_SUCCESS if all went well 173 | */ 174 | apr_status_t (* grab)(ap_slotmem_instance_t *s, unsigned int *item_id); 175 | /** 176 | * release (or free) the slot associated with this item_id 177 | * @param s ap_slotmem_instance_t to use. 178 | * @param item_id slot id to free and mark as no longer in-use 179 | * @return APR_SUCCESS if all went well 180 | */ 181 | apr_status_t (* release)(ap_slotmem_instance_t *s, unsigned int item_id); 182 | /** 183 | * forced grab (or alloc) a slot associated with this item_id 184 | * @param s ap_slotmem_instance_t to use. 185 | * @param item_id to the specified slot id and marked as in-use 186 | * @return APR_SUCCESS if all went well 187 | */ 188 | apr_status_t (* fgrab)(ap_slotmem_instance_t *s, unsigned int item_id); 189 | }; 190 | 191 | typedef struct ap_slotmem_provider_t ap_slotmem_provider_t; 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | 197 | #endif 198 | /** @} */ 199 | -------------------------------------------------------------------------------- /include/util_varbuf.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_varbuf.h 19 | * @brief Apache resizable variable length buffer library 20 | * 21 | * This set of functions provides resizable buffers. While the primary 22 | * usage is with NUL-terminated strings, most functions also work with 23 | * arbitrary binary data. 24 | * 25 | * @defgroup APACHE_CORE_VARBUF 26 | * @ingroup APACHE_CORE 27 | * @{ 28 | */ 29 | 30 | #ifndef AP_VARBUF_H 31 | #define AP_VARBUF_H 32 | 33 | #include "apr.h" 34 | #include "apr_allocator.h" 35 | 36 | #include "httpd.h" 37 | 38 | #ifdef __cplusplus 39 | extern "C" { 40 | #endif 41 | 42 | #define AP_VARBUF_UNKNOWN APR_SIZE_MAX 43 | struct ap_varbuf_info; 44 | 45 | /** A resizable buffer */ 46 | struct ap_varbuf { 47 | /** the actual buffer; will point to a const '\0' if avail == 0 and 48 | * to memory of the same lifetime as the pool otherwise */ 49 | char *buf; 50 | 51 | /** allocated size of the buffer (minus one for the final \0); 52 | * must only be changed using ap_varbuf_grow() */ 53 | apr_size_t avail; 54 | 55 | /** length of string in buffer, or AP_VARBUF_UNKNOWN. This determines how 56 | * much memory is copied by ap_varbuf_grow() and where 57 | * ap_varbuf_strmemcat() will append to the buffer. */ 58 | apr_size_t strlen; 59 | 60 | /** the pool for memory allocations and for registering the cleanup; 61 | * the buffer memory will be released when this pool is cleared */ 62 | apr_pool_t *pool; 63 | 64 | /** opaque info for memory allocation */ 65 | struct ap_varbuf_info *info; 66 | }; 67 | 68 | /** initialize a resizable buffer. It is safe to re-initialize a prevously 69 | * used ap_varbuf. The old buffer will be released when the corresponding 70 | * pool is cleared. The buffer remains usable until the pool is cleared, 71 | * even if the ap_varbuf was located on the stack and has gone out of scope. 72 | * @param pool the pool to allocate small buffers from and to register the 73 | * cleanup with 74 | * @param vb pointer to the ap_varbuf struct 75 | * @param init_size the initial size of the buffer (see ap_varbuf_grow() for details) 76 | */ 77 | AP_DECLARE(void) ap_varbuf_init(apr_pool_t *pool, struct ap_varbuf *vb, 78 | apr_size_t init_size); 79 | 80 | /** grow a resizable buffer. If the vb->buf cannot be grown in place, it will 81 | * be reallocated and the first vb->strlen + 1 bytes of memory will be copied 82 | * to the new location. If vb->strlen == AP_VARBUF_UNKNOWN, the whole buffer 83 | * is copied. 84 | * @param vb pointer to the ap_varbuf struct 85 | * @param new_size the minimum new size of the buffer 86 | * @note ap_varbuf_grow() will usually at least double vb->buf's size with 87 | * every invocation in order to reduce reallications. 88 | * @note ap_varbuf_grow() will use pool memory for small and allocator 89 | * mem nodes for larger allocations. 90 | * @note ap_varbuf_grow() will call vb->pool's abort function if out of memory. 91 | */ 92 | AP_DECLARE(void) ap_varbuf_grow(struct ap_varbuf *vb, apr_size_t new_size); 93 | 94 | /** Release memory from a ap_varbuf immediately, if possible. 95 | * This allows to free large buffers before the corresponding pool is 96 | * cleared. Only larger allocations using mem nodes will be freed. 97 | * @param vb pointer to the ap_varbuf struct 98 | * @note After ap_varbuf_free(), vb must not be used unless ap_varbuf_init() 99 | * is called again. 100 | */ 101 | AP_DECLARE(void) ap_varbuf_free(struct ap_varbuf *vb); 102 | 103 | /** Concatenate a string to an ap_varbuf. vb->strlen determines where 104 | * the string is appended in the buffer. If vb->strlen == AP_VARBUF_UNKNOWN, 105 | * the string will be appended at the first NUL byte in the buffer. 106 | * If len == 0, ap_varbuf_strmemcat() does nothing. 107 | * @param vb pointer to the ap_varbuf struct 108 | * @param str the string to append; must be at least len bytes long 109 | * @param len the number of characters of *str to concatenate to the buf 110 | * @note vb->strlen will be set to the length of the new string 111 | * @note if len != 0, vb->buf will always be NUL-terminated 112 | */ 113 | AP_DECLARE(void) ap_varbuf_strmemcat(struct ap_varbuf *vb, const char *str, 114 | int len); 115 | 116 | /** Duplicate an ap_varbuf's content into pool memory 117 | * @param p the pool to allocate from 118 | * @param vb the ap_varbuf to copy from 119 | * @param prepend an optional buffer to prepend (may be NULL) 120 | * @param prepend_len length of prepend 121 | * @param append an optional buffer to append (may be NULL) 122 | * @param append_len length of append 123 | * @param new_len where to store the length of the resulting string 124 | * (may be NULL) 125 | * @return the new string 126 | * @note ap_varbuf_pdup() uses vb->strlen to determine how much memory to 127 | * copy. It works even if 0-bytes are embedded in vb->buf, prepend, or 128 | * append. 129 | * @note If vb->strlen equals AP_VARBUF_UNKNOWN, it will be set to 130 | * strlen(vb->buf). 131 | */ 132 | AP_DECLARE(char *) ap_varbuf_pdup(apr_pool_t *p, struct ap_varbuf *vb, 133 | const char *prepend, apr_size_t prepend_len, 134 | const char *append, apr_size_t append_len, 135 | apr_size_t *new_len); 136 | 137 | 138 | /** Concatenate a string to an ap_varbuf 139 | * @param vb pointer to the ap_varbuf struct 140 | * @param str the string to append 141 | * @note vb->strlen will be set to the length of the new string 142 | */ 143 | #define ap_varbuf_strcat(vb, str) ap_varbuf_strmemcat(vb, str, strlen(str)) 144 | 145 | /** Perform string substitutions based on regexp match, using an ap_varbuf. 146 | * This function behaves like ap_pregsub(), but appends to an ap_varbuf 147 | * instead of allocating the result from a pool. 148 | * @param vb The ap_varbuf to which the string will be appended 149 | * @param input An arbitrary string containing $1 through $9. These are 150 | * replaced with the corresponding matched sub-expressions 151 | * @param source The string that was originally matched to the regex 152 | * @param nmatch the nmatch returned from ap_pregex 153 | * @param pmatch the pmatch array returned from ap_pregex 154 | * @param maxlen the maximum string length to append to vb, 0 for unlimited 155 | * @return APR_SUCCESS if successful 156 | * @note Just like ap_pregsub(), this function does not copy the part of 157 | * *source before the matching part (i.e. the first pmatch[0].rm_so 158 | * characters). 159 | * @note If vb->strlen equals AP_VARBUF_UNKNOWN, it will be set to 160 | * strlen(vb->buf) first. 161 | */ 162 | AP_DECLARE(apr_status_t) ap_varbuf_regsub(struct ap_varbuf *vb, 163 | const char *input, 164 | const char *source, 165 | apr_size_t nmatch, 166 | ap_regmatch_t pmatch[], 167 | apr_size_t maxlen); 168 | 169 | /** Read a line from an ap_configfile_t and append it to an ap_varbuf. 170 | * @param vb pointer to the ap_varbuf struct 171 | * @param cfg pointer to the ap_configfile_t 172 | * @param max_len maximum line length, including leading/trailing whitespace 173 | * @return see ap_cfg_getline() 174 | * @note vb->strlen will be set to the length of the line 175 | * @note If vb->strlen equals AP_VARBUF_UNKNOWN, it will be set to 176 | * strlen(vb->buf) first. 177 | */ 178 | AP_DECLARE(apr_status_t) ap_varbuf_cfg_getline(struct ap_varbuf *vb, 179 | ap_configfile_t *cfp, 180 | apr_size_t max_len); 181 | 182 | #ifdef __cplusplus 183 | } 184 | #endif 185 | 186 | #endif /* !AP_VARBUF_H */ 187 | /** @} */ 188 | -------------------------------------------------------------------------------- /include/ap_config_auto.h: -------------------------------------------------------------------------------- 1 | /* include/ap_config_auto.h. Generated from ap_config_auto.h.in by configure. */ 2 | /* include/ap_config_auto.h.in. Generated from configure.in by autoheader. */ 3 | 4 | /* SuExec root directory */ 5 | /* #undef AP_DOC_ROOT */ 6 | 7 | /* Enable DTrace probes */ 8 | /* #undef AP_ENABLE_DTRACE */ 9 | 10 | /* Allow modules to run hook after a fatal exception */ 11 | /* #undef AP_ENABLE_EXCEPTION_HOOK */ 12 | 13 | /* Allow IPv4 connections on IPv6 listening sockets */ 14 | #define AP_ENABLE_V4_MAPPED 1 15 | 16 | /* Minimum allowed GID */ 17 | /* #undef AP_GID_MIN */ 18 | 19 | /* Enable the APR hook probes capability, reading from ap_hook_probes.h */ 20 | /* #undef AP_HOOK_PROBES_ENABLED */ 21 | 22 | /* User allowed to call SuExec */ 23 | /* #undef AP_HTTPD_USER */ 24 | 25 | /* SuExec log file */ 26 | /* #undef AP_LOG_EXEC */ 27 | 28 | /* Listening sockets are non-blocking when there are more than 1 */ 29 | #define AP_NONBLOCK_WHEN_MULTI_LISTEN 1 30 | 31 | /* safe shell path for SuExec */ 32 | /* #undef AP_SAFE_PATH */ 33 | 34 | /* umask for suexec'd process */ 35 | /* #undef AP_SUEXEC_UMASK */ 36 | 37 | /* Location of the MIME types config file, relative to the Apache root 38 | directory */ 39 | #define AP_TYPES_CONFIG_FILE "conf/mime.types" 40 | 41 | /* Minimum allowed UID */ 42 | /* #undef AP_UID_MIN */ 43 | 44 | /* User subdirectory */ 45 | /* #undef AP_USERDIR_SUFFIX */ 46 | 47 | /* Using autoconf to configure Apache */ 48 | #define AP_USING_AUTOCONF 1 49 | 50 | /* Define to 1 if you have the `bindprocessor' function. */ 51 | /* #undef HAVE_BINDPROCESSOR */ 52 | 53 | /* Define to 1 if you have the header file. */ 54 | /* #undef HAVE_BSTRING_H */ 55 | 56 | /* Define if distcache support is enabled */ 57 | /* #undef HAVE_DISTCACHE */ 58 | 59 | /* Define to 1 if you have the header file. */ 60 | /* #undef HAVE_DISTCACHE_DC_CLIENT_H */ 61 | 62 | /* Define to 1 if you have the `ENGINE_init' function. */ 63 | #define HAVE_ENGINE_INIT 1 64 | 65 | /* Define to 1 if you have the `ENGINE_load_builtin_engines' function. */ 66 | #define HAVE_ENGINE_LOAD_BUILTIN_ENGINES 1 67 | 68 | /* Define to 1 if you have the `epoll_create' function. */ 69 | #define HAVE_EPOLL_CREATE 1 70 | 71 | /* Define to 1 if you have the `fopen64' function. */ 72 | #define HAVE_FOPEN64 1 73 | 74 | /* Define to 1 if you have the `getgrnam' function. */ 75 | #define HAVE_GETGRNAM 1 76 | 77 | /* Define to 1 if you have the `getloadavg' function. */ 78 | #define HAVE_GETLOADAVG 1 79 | 80 | /* Define to 1 if you have the `getpgid' function. */ 81 | #define HAVE_GETPGID 1 82 | 83 | /* Define to 1 if you have the `getpwnam' function. */ 84 | #define HAVE_GETPWNAM 1 85 | 86 | /* Define if you have gettid() */ 87 | #define HAVE_GETTID 1 88 | 89 | /* Define if struct tm has a tm_gmtoff field */ 90 | #define HAVE_GMTOFF 1 91 | 92 | /* Define to 1 if you have the header file. */ 93 | #define HAVE_GRP_H 1 94 | 95 | /* Define to 1 if you have the `initgroups' function. */ 96 | #define HAVE_INITGROUPS 1 97 | 98 | /* Define to 1 if you have the header file. */ 99 | #define HAVE_INTTYPES_H 1 100 | 101 | /* Define to 1 if you have the `killpg' function. */ 102 | #define HAVE_KILLPG 1 103 | 104 | /* Define to 1 if you have the `kqueue' function. */ 105 | /* #undef HAVE_KQUEUE */ 106 | 107 | /* Define to 1 if you have the header file. */ 108 | #define HAVE_LIMITS_H 1 109 | 110 | /* Define to 1 if you have the header file. */ 111 | #define HAVE_MEMORY_H 1 112 | 113 | /* Define if OpenSSL is available */ 114 | #define HAVE_OPENSSL 1 115 | 116 | /* Define to 1 if you have the header file. */ 117 | #define HAVE_OPENSSL_ENGINE_H 1 118 | 119 | /* Define to 1 if you have the `port_create' function. */ 120 | /* #undef HAVE_PORT_CREATE */ 121 | 122 | /* Define to 1 if you have the `prctl' function. */ 123 | #define HAVE_PRCTL 1 124 | 125 | /* Define to 1 if you have the header file. */ 126 | /* #undef HAVE_PRIV_H */ 127 | 128 | /* Define to 1 if you have the `pthread_kill' function. */ 129 | #define HAVE_PTHREAD_KILL 1 130 | 131 | /* Define to 1 if you have the header file. */ 132 | #define HAVE_PWD_H 1 133 | 134 | /* Define to 1 if you have the `setsid' function. */ 135 | #define HAVE_SETSID 1 136 | 137 | /* Define to 1 if you have the `SSLeay_version' function. */ 138 | #define HAVE_SSLEAY_VERSION 1 139 | 140 | /* Define to 1 if you have the `SSL_CTX_new' function. */ 141 | #define HAVE_SSL_CTX_NEW 1 142 | 143 | /* Define to 1 if you have the header file. */ 144 | #define HAVE_STDINT_H 1 145 | 146 | /* Define to 1 if you have the header file. */ 147 | #define HAVE_STDLIB_H 1 148 | 149 | /* Define to 1 if you have the header file. */ 150 | #define HAVE_STRINGS_H 1 151 | 152 | /* Define to 1 if you have the header file. */ 153 | #define HAVE_STRING_H 1 154 | 155 | /* Define to 1 if you have the `syslog' function. */ 156 | #define HAVE_SYSLOG 1 157 | 158 | /* Define to 1 if you have the header file. */ 159 | #define HAVE_SYS_IPC_H 1 160 | 161 | /* Define to 1 if you have the header file. */ 162 | /* #undef HAVE_SYS_LOADAVG_H */ 163 | 164 | /* Define to 1 if you have the header file. */ 165 | #define HAVE_SYS_PRCTL_H 1 166 | 167 | /* Define to 1 if you have the header file. */ 168 | /* #undef HAVE_SYS_PROCESSOR_H */ 169 | 170 | /* Define to 1 if you have the header file. */ 171 | #define HAVE_SYS_RESOURCE_H 1 172 | 173 | /* Define to 1 if you have the header file. */ 174 | /* #undef HAVE_SYS_SDT_H */ 175 | 176 | /* Define to 1 if you have the header file. */ 177 | #define HAVE_SYS_SEM_H 1 178 | 179 | /* Define to 1 if you have the header file. */ 180 | #define HAVE_SYS_SOCKET_H 1 181 | 182 | /* Define to 1 if you have the header file. */ 183 | #define HAVE_SYS_STAT_H 1 184 | 185 | /* Define to 1 if you have the header file. */ 186 | #define HAVE_SYS_TIMES_H 1 187 | 188 | /* Define to 1 if you have the header file. */ 189 | #define HAVE_SYS_TIME_H 1 190 | 191 | /* Define to 1 if you have the header file. */ 192 | #define HAVE_SYS_TYPES_H 1 193 | 194 | /* Define to 1 if you have that is POSIX.1 compatible. */ 195 | #define HAVE_SYS_WAIT_H 1 196 | 197 | /* Define to 1 if you have the `timegm' function. */ 198 | #define HAVE_TIMEGM 1 199 | 200 | /* Define to 1 if you have the `times' function. */ 201 | #define HAVE_TIMES 1 202 | 203 | /* Define to 1 if you have the header file. */ 204 | #define HAVE_UNISTD_H 1 205 | 206 | /* Root directory of the Apache install area */ 207 | #define HTTPD_ROOT "/usr/local/apache2" 208 | 209 | /* Define to the address where bug reports for this package should be sent. */ 210 | #define PACKAGE_BUGREPORT "" 211 | 212 | /* Define to the full name of this package. */ 213 | #define PACKAGE_NAME "" 214 | 215 | /* Define to the full name and version of this package. */ 216 | #define PACKAGE_STRING "" 217 | 218 | /* Define to the one symbol short name of this package. */ 219 | #define PACKAGE_TARNAME "" 220 | 221 | /* Define to the home page for this package. */ 222 | #define PACKAGE_URL "" 223 | 224 | /* Define to the version of this package. */ 225 | #define PACKAGE_VERSION "" 226 | 227 | /* Location of the config file, relative to the Apache root directory */ 228 | #define SERVER_CONFIG_FILE "conf/httpd.conf" 229 | 230 | /* This platform doesn't suffer from the thundering herd problem */ 231 | /* #undef SINGLE_LISTEN_UNSERIALIZED_ACCEPT */ 232 | 233 | /* Define to 1 if you have the ANSI C header files. */ 234 | #define STDC_HEADERS 1 235 | 236 | /* Path to suexec binary */ 237 | /* #undef SUEXEC_BIN */ 238 | 239 | /* Enable extensions on AIX 3, Interix. */ 240 | #ifndef _ALL_SOURCE 241 | # define _ALL_SOURCE 1 242 | #endif 243 | /* Enable GNU extensions on systems that have them. */ 244 | #ifndef _GNU_SOURCE 245 | # define _GNU_SOURCE 1 246 | #endif 247 | /* Enable threading extensions on Solaris. */ 248 | #ifndef _POSIX_PTHREAD_SEMANTICS 249 | # define _POSIX_PTHREAD_SEMANTICS 1 250 | #endif 251 | /* Enable extensions on HP NonStop. */ 252 | #ifndef _TANDEM_SOURCE 253 | # define _TANDEM_SOURCE 1 254 | #endif 255 | /* Enable general extensions on Solaris. */ 256 | #ifndef __EXTENSIONS__ 257 | # define __EXTENSIONS__ 1 258 | #endif 259 | 260 | 261 | /* Define to 1 if on MINIX. */ 262 | /* #undef _MINIX */ 263 | 264 | /* Define to 2 if the system does not provide POSIX.1 features except with 265 | this defined. */ 266 | /* #undef _POSIX_1_SOURCE */ 267 | 268 | /* Define to 1 if you need to in order for `stat' and other things to work. */ 269 | /* #undef _POSIX_SOURCE */ 270 | 271 | /* Define to empty if `const' does not conform to ANSI C. */ 272 | /* #undef const */ 273 | 274 | /* Define to 'int' if doesn't define it for us */ 275 | /* #undef rlim_t */ 276 | -------------------------------------------------------------------------------- /include/scoreboard.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file scoreboard.h 19 | * @brief Apache scoreboard library 20 | */ 21 | 22 | #ifndef APACHE_SCOREBOARD_H 23 | #define APACHE_SCOREBOARD_H 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #ifdef HAVE_SYS_TIMES_H 30 | #include 31 | #include 32 | #endif 33 | 34 | #include "ap_config.h" 35 | #include "http_config.h" 36 | #include "apr_thread_proc.h" 37 | #include "apr_portable.h" 38 | #include "apr_shm.h" 39 | #include "apr_optional.h" 40 | 41 | /* Scoreboard file, if there is one */ 42 | #ifndef DEFAULT_SCOREBOARD 43 | #define DEFAULT_SCOREBOARD "logs/apache_runtime_status" 44 | #endif 45 | 46 | /* Scoreboard info on a process is, for now, kept very brief --- 47 | * just status value and pid (the latter so that the caretaker process 48 | * can properly update the scoreboard when a process dies). We may want 49 | * to eventually add a separate set of long_score structures which would 50 | * give, for each process, the number of requests serviced, and info on 51 | * the current, or most recent, request. 52 | * 53 | * Status values: 54 | */ 55 | 56 | #define SERVER_DEAD 0 57 | #define SERVER_STARTING 1 /* Server Starting up */ 58 | #define SERVER_READY 2 /* Waiting for connection (or accept() lock) */ 59 | #define SERVER_BUSY_READ 3 /* Reading a client request */ 60 | #define SERVER_BUSY_WRITE 4 /* Processing a client request */ 61 | #define SERVER_BUSY_KEEPALIVE 5 /* Waiting for more requests via keepalive */ 62 | #define SERVER_BUSY_LOG 6 /* Logging the request */ 63 | #define SERVER_BUSY_DNS 7 /* Looking up a hostname */ 64 | #define SERVER_CLOSING 8 /* Closing the connection */ 65 | #define SERVER_GRACEFUL 9 /* server is gracefully finishing request */ 66 | #define SERVER_IDLE_KILL 10 /* Server is cleaning up idle children. */ 67 | #define SERVER_NUM_STATUS 11 /* number of status settings */ 68 | 69 | /* Type used for generation indicies. Startup and every restart cause a 70 | * new generation of children to be spawned. Children within the same 71 | * generation share the same configuration information -- pointers to stuff 72 | * created at config time in the parent are valid across children. However, 73 | * this can't work effectively with non-forked architectures. So while the 74 | * arrays in the scoreboard never change between the parent and forked 75 | * children, so they do not require shm storage, the contents of the shm 76 | * may contain no pointers. 77 | */ 78 | typedef int ap_generation_t; 79 | 80 | /* Is the scoreboard shared between processes or not? 81 | * Set by the MPM when the scoreboard is created. 82 | */ 83 | typedef enum { 84 | SB_NOT_SHARED = 1, 85 | SB_SHARED = 2 86 | } ap_scoreboard_e; 87 | 88 | /* stuff which is worker specific */ 89 | typedef struct worker_score worker_score; 90 | struct worker_score { 91 | #if APR_HAS_THREADS 92 | apr_os_thread_t tid; 93 | #endif 94 | int thread_num; 95 | /* With some MPMs (e.g., worker), a worker_score can represent 96 | * a thread in a terminating process which is no longer 97 | * represented by the corresponding process_score. These MPMs 98 | * should set pid and generation fields in the worker_score. 99 | */ 100 | pid_t pid; 101 | ap_generation_t generation; 102 | unsigned char status; 103 | unsigned short conn_count; 104 | apr_off_t conn_bytes; 105 | unsigned long access_count; 106 | apr_off_t bytes_served; 107 | unsigned long my_access_count; 108 | apr_off_t my_bytes_served; 109 | apr_time_t start_time; 110 | apr_time_t stop_time; 111 | apr_time_t last_used; 112 | #ifdef HAVE_TIMES 113 | struct tms times; 114 | #endif 115 | char client[32]; /* Keep 'em small... */ 116 | char request[64]; /* We just want an idea... */ 117 | char vhost[32]; /* What virtual host is being accessed? */ 118 | }; 119 | 120 | typedef struct { 121 | int server_limit; 122 | int thread_limit; 123 | ap_generation_t running_generation; /* the generation of children which 124 | * should still be serving requests. 125 | */ 126 | apr_time_t restart_time; 127 | } global_score; 128 | 129 | /* stuff which the parent generally writes and the children rarely read */ 130 | typedef struct process_score process_score; 131 | struct process_score { 132 | pid_t pid; 133 | ap_generation_t generation; /* generation of this child */ 134 | char quiescing; /* the process whose pid is stored above is 135 | * going down gracefully 136 | */ 137 | char not_accepting; /* the process is busy and is not accepting more 138 | * connections (for async MPMs) 139 | */ 140 | apr_uint32_t connections; /* total connections (for async MPMs) */ 141 | apr_uint32_t write_completion; /* async connections doing write completion */ 142 | apr_uint32_t lingering_close; /* async connections in lingering close */ 143 | apr_uint32_t keep_alive; /* async connections in keep alive */ 144 | apr_uint32_t suspended; /* connections suspended by some module */ 145 | }; 146 | 147 | /* Scoreboard is now in 'local' memory, since it isn't updated once created, 148 | * even in forked architectures. Child created-processes (non-fork) will 149 | * set up these indicies into the (possibly relocated) shmem records. 150 | */ 151 | typedef struct { 152 | global_score *global; 153 | process_score *parent; 154 | worker_score **servers; 155 | } scoreboard; 156 | 157 | typedef struct ap_sb_handle_t ap_sb_handle_t; 158 | 159 | /* 160 | * Creation and deletion (internal) 161 | */ 162 | int ap_create_scoreboard(apr_pool_t *p, ap_scoreboard_e t); 163 | apr_status_t ap_cleanup_scoreboard(void *d); 164 | 165 | /* 166 | * APIs for MPMs and other modules 167 | */ 168 | AP_DECLARE(int) ap_exists_scoreboard_image(void); 169 | AP_DECLARE(void) ap_increment_counts(ap_sb_handle_t *sbh, request_rec *r); 170 | 171 | AP_DECLARE(apr_status_t) ap_reopen_scoreboard(apr_pool_t *p, apr_shm_t **shm, int detached); 172 | AP_DECLARE(void) ap_init_scoreboard(void *shared_score); 173 | AP_DECLARE(int) ap_calc_scoreboard_size(void); 174 | 175 | AP_DECLARE(void) ap_create_sb_handle(ap_sb_handle_t **new_sbh, apr_pool_t *p, 176 | int child_num, int thread_num); 177 | 178 | AP_DECLARE(int) ap_find_child_by_pid(apr_proc_t *pid); 179 | AP_DECLARE(int) ap_update_child_status(ap_sb_handle_t *sbh, int status, request_rec *r); 180 | AP_DECLARE(int) ap_update_child_status_from_indexes(int child_num, int thread_num, 181 | int status, request_rec *r); 182 | AP_DECLARE(int) ap_update_child_status_from_conn(ap_sb_handle_t *sbh, int status, conn_rec *c); 183 | AP_DECLARE(void) ap_time_process_request(ap_sb_handle_t *sbh, int status); 184 | 185 | AP_DECLARE(worker_score *) ap_get_scoreboard_worker(ap_sb_handle_t *sbh); 186 | AP_DECLARE(worker_score *) ap_get_scoreboard_worker_from_indexes(int child_num, 187 | int thread_num); 188 | AP_DECLARE(process_score *) ap_get_scoreboard_process(int x); 189 | AP_DECLARE(global_score *) ap_get_scoreboard_global(void); 190 | 191 | AP_DECLARE_DATA extern scoreboard *ap_scoreboard_image; 192 | AP_DECLARE_DATA extern const char *ap_scoreboard_fname; 193 | AP_DECLARE_DATA extern int ap_extended_status; 194 | AP_DECLARE_DATA extern int ap_mod_status_reqtail; 195 | 196 | /* 197 | * Command handlers [internal] 198 | */ 199 | const char *ap_set_scoreboard(cmd_parms *cmd, void *dummy, const char *arg); 200 | const char *ap_set_extended_status(cmd_parms *cmd, void *dummy, int arg); 201 | const char *ap_set_reqtail(cmd_parms *cmd, void *dummy, int arg); 202 | 203 | /* Hooks */ 204 | /** 205 | * Hook for post scoreboard creation, pre mpm. 206 | * @param p Apache pool to allocate from. 207 | * @param sb_type 208 | * @ingroup hooks 209 | * @return OK or DECLINE on success; anything else is a error 210 | */ 211 | AP_DECLARE_HOOK(int, pre_mpm, (apr_pool_t *p, ap_scoreboard_e sb_type)) 212 | 213 | /* for time_process_request() in http_main.c */ 214 | #define START_PREQUEST 1 215 | #define STOP_PREQUEST 2 216 | 217 | #ifdef __cplusplus 218 | } 219 | #endif 220 | 221 | #endif /* !APACHE_SCOREBOARD_H */ 222 | -------------------------------------------------------------------------------- /include/ap_regkey.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_regkey.h 19 | * @brief APR-style Win32 Registry Manipulation 20 | */ 21 | 22 | #ifndef AP_REGKEY_H 23 | #define AP_REGKEY_H 24 | 25 | #if defined(WIN32) || defined(DOXYGEN) 26 | 27 | #include "apr.h" 28 | #include "apr_pools.h" 29 | #include "ap_config.h" /* Just for AP_DECLARE */ 30 | 31 | #ifdef __cplusplus 32 | extern "C" { 33 | #endif 34 | 35 | typedef struct ap_regkey_t ap_regkey_t; 36 | 37 | /* Used to recover AP_REGKEY_* constants 38 | */ 39 | AP_DECLARE(const ap_regkey_t *) ap_regkey_const(int i); 40 | 41 | /** 42 | * Win32 Only: Constants for ap_regkey_open() 43 | */ 44 | #define AP_REGKEY_CLASSES_ROOT ap_regkey_const(0) 45 | #define AP_REGKEY_CURRENT_CONFIG ap_regkey_const(1) 46 | #define AP_REGKEY_CURRENT_USER ap_regkey_const(2) 47 | #define AP_REGKEY_LOCAL_MACHINE ap_regkey_const(3) 48 | #define AP_REGKEY_USERS ap_regkey_const(4) 49 | #define AP_REGKEY_PERFORMANCE_DATA ap_regkey_const(5) 50 | #define AP_REGKEY_DYN_DATA ap_regkey_const(6) 51 | 52 | /** 53 | * Win32 Only: Flags for ap_regkey_value_set() 54 | */ 55 | #define AP_REGKEY_EXPAND 0x0001 56 | 57 | /** 58 | * Win32 Only: Open the specified registry key. 59 | * @param newkey The opened registry key 60 | * @param parentkey The open registry key of the parent, or one of 61 | *
 62 |  *           AP_REGKEY_CLASSES_ROOT
 63 |  *           AP_REGKEY_CURRENT_CONFIG
 64 |  *           AP_REGKEY_CURRENT_USER
 65 |  *           AP_REGKEY_LOCAL_MACHINE
 66 |  *           AP_REGKEY_USERS
 67 |  *           AP_REGKEY_PERFORMANCE_DATA
 68 |  *           AP_REGKEY_DYN_DATA
 69 |  * 
70 | * @param keyname The path of the key relative to the parent key 71 | * @param flags Or'ed value of: 72 | *
 73 |  *           APR_READ             open key for reading
 74 |  *           APR_WRITE            open key for writing
 75 |  *           APR_CREATE           create the key if it doesn't exist
 76 |  *           APR_EXCL             return error if APR_CREATE and key exists
 77 |  * 
78 | * @param pool The pool in which newkey is allocated 79 | */ 80 | AP_DECLARE(apr_status_t) ap_regkey_open(ap_regkey_t **newkey, 81 | const ap_regkey_t *parentkey, 82 | const char *keyname, 83 | apr_int32_t flags, 84 | apr_pool_t *pool); 85 | 86 | /** 87 | * Win32 Only: Close the registry key opened or created by ap_regkey_open(). 88 | * @param key The registry key to close 89 | */ 90 | AP_DECLARE(apr_status_t) ap_regkey_close(ap_regkey_t *key); 91 | 92 | /** 93 | * Win32 Only: Remove the given registry key. 94 | * @param parent The open registry key of the parent, or one of 95 | *
 96 |  *           AP_REGKEY_CLASSES_ROOT
 97 |  *           AP_REGKEY_CURRENT_CONFIG
 98 |  *           AP_REGKEY_CURRENT_USER
 99 |  *           AP_REGKEY_LOCAL_MACHINE
100 |  *           AP_REGKEY_USERS
101 |  *           AP_REGKEY_PERFORMANCE_DATA
102 |  *           AP_REGKEY_DYN_DATA
103 |  * 
104 | * @param keyname The path of the key relative to the parent key 105 | * @param pool The pool used for temp allocations 106 | * @remark ap_regkey_remove() is not recursive, although it removes 107 | * all values within the given keyname, it will not remove a key 108 | * containing subkeys. 109 | */ 110 | AP_DECLARE(apr_status_t) ap_regkey_remove(const ap_regkey_t *parent, 111 | const char *keyname, 112 | apr_pool_t *pool); 113 | 114 | /** 115 | * Win32 Only: Retrieve a registry value string from an open key. 116 | * @param result The string value retrieved 117 | * @param key The registry key to retrieve the value from 118 | * @param valuename The named value to retrieve (pass "" for the default) 119 | * @param pool The pool used to store the result 120 | * @remark There is no toggle to prevent environment variable expansion 121 | * if the registry value is set with AP_REG_EXPAND (REG_EXPAND_SZ), such 122 | * expansions are always performed. 123 | */ 124 | AP_DECLARE(apr_status_t) ap_regkey_value_get(char **result, 125 | ap_regkey_t *key, 126 | const char *valuename, 127 | apr_pool_t *pool); 128 | 129 | /** 130 | * Win32 Only: Store a registry value string into an open key. 131 | * @param key The registry key to store the value into 132 | * @param valuename The named value to store (pass "" for the default) 133 | * @param value The string to store for the named value 134 | * @param flags The option AP_REGKEY_EXPAND or 0, where AP_REGKEY_EXPAND 135 | * values will find all %foo% variables expanded from the environment. 136 | * @param pool The pool used for temp allocations 137 | */ 138 | AP_DECLARE(apr_status_t) ap_regkey_value_set(ap_regkey_t *key, 139 | const char *valuename, 140 | const char *value, 141 | apr_int32_t flags, 142 | apr_pool_t *pool); 143 | 144 | /** 145 | * Win32 Only: Retrieve a raw byte value from an open key. 146 | * @param result The raw bytes value retrieved 147 | * @param resultsize Pointer to a variable to store the number raw bytes retrieved 148 | * @param resulttype Pointer to a variable to store the registry type of the value retrieved 149 | * @param key The registry key to retrieve the value from 150 | * @param valuename The named value to retrieve (pass "" for the default) 151 | * @param pool The pool used to store the result 152 | */ 153 | AP_DECLARE(apr_status_t) ap_regkey_value_raw_get(void **result, 154 | apr_size_t *resultsize, 155 | apr_int32_t *resulttype, 156 | ap_regkey_t *key, 157 | const char *valuename, 158 | apr_pool_t *pool); 159 | 160 | /** 161 | * Win32 Only: Store a raw bytes value into an open key. 162 | * @param key The registry key to store the value into 163 | * @param valuename The named value to store (pass "" for the default) 164 | * @param value The bytes to store for the named value 165 | * @param valuesize The number of bytes for value 166 | * @param valuetype The 167 | * values will find all %foo% variables expanded from the environment. 168 | * @param pool The pool used for temp allocations 169 | */ 170 | AP_DECLARE(apr_status_t) ap_regkey_value_raw_set(ap_regkey_t *key, 171 | const char *valuename, 172 | const void *value, 173 | apr_size_t valuesize, 174 | apr_int32_t valuetype, 175 | apr_pool_t *pool); 176 | 177 | /** 178 | * Win32 Only: Retrieve a registry value string from an open key. 179 | * @param result The string elements retrieved from a REG_MULTI_SZ string array 180 | * @param key The registry key to retrieve the value from 181 | * @param valuename The named value to retrieve (pass "" for the default) 182 | * @param pool The pool used to store the result 183 | */ 184 | AP_DECLARE(apr_status_t) ap_regkey_value_array_get(apr_array_header_t **result, 185 | ap_regkey_t *key, 186 | const char *valuename, 187 | apr_pool_t *pool); 188 | 189 | /** 190 | * Win32 Only: Store a registry value string array into an open key. 191 | * @param key The registry key to store the value into 192 | * @param valuename The named value to store (pass "" for the default) 193 | * @param nelts The string elements to store in a REG_MULTI_SZ string array 194 | * @param elts The number of elements in the elts string array 195 | * @param pool The pool used for temp allocations 196 | */ 197 | AP_DECLARE(apr_status_t) ap_regkey_value_array_set(ap_regkey_t *key, 198 | const char *valuename, 199 | int nelts, 200 | const char * const * elts, 201 | apr_pool_t *pool); 202 | 203 | /** 204 | * Win32 Only: Remove a registry value from an open key. 205 | * @param key The registry key to remove the value from 206 | * @param valuename The named value to remove (pass "" for the default) 207 | * @param pool The pool used for temp allocations 208 | */ 209 | AP_DECLARE(apr_status_t) ap_regkey_value_remove(const ap_regkey_t *key, 210 | const char *valuename, 211 | apr_pool_t *pool); 212 | 213 | #ifdef __cplusplus 214 | } 215 | #endif 216 | 217 | #endif /* def WIN32 || def DOXYGEN */ 218 | 219 | #endif /* AP_REGKEY_H */ 220 | -------------------------------------------------------------------------------- /include/util_mutex.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_mutex.h 19 | * @brief Apache Mutex support library 20 | * 21 | * @defgroup APACHE_CORE_MUTEX Mutex Library 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef UTIL_MUTEX_H 27 | #define UTIL_MUTEX_H 28 | 29 | #include "httpd.h" 30 | #include "http_config.h" 31 | #include "apr_global_mutex.h" 32 | 33 | #if APR_HAS_FLOCK_SERIALIZE 34 | # define AP_LIST_FLOCK_SERIALIZE ", 'flock:/path/to/file'" 35 | #else 36 | # define AP_LIST_FLOCK_SERIALIZE 37 | #endif 38 | #if APR_HAS_FCNTL_SERIALIZE 39 | # define AP_LIST_FCNTL_SERIALIZE ", 'fcntl:/path/to/file'" 40 | #else 41 | # define AP_LIST_FCNTL_SERIALIZE 42 | #endif 43 | #if APR_HAS_SYSVSEM_SERIALIZE 44 | # define AP_LIST_SYSVSEM_SERIALIZE ", 'sysvsem'" 45 | #else 46 | # define AP_LIST_SYSVSEM_SERIALIZE 47 | #endif 48 | #if APR_HAS_POSIXSEM_SERIALIZE 49 | # define AP_LIST_POSIXSEM_SERIALIZE ", 'posixsem'" 50 | #else 51 | # define AP_LIST_POSIXSEM_SERIALIZE 52 | #endif 53 | #if APR_HAS_PROC_PTHREAD_SERIALIZE 54 | # define AP_LIST_PTHREAD_SERIALIZE ", 'pthread'" 55 | #else 56 | # define AP_LIST_PTHREAD_SERIALIZE 57 | #endif 58 | #if APR_HAS_FLOCK_SERIALIZE || APR_HAS_FCNTL_SERIALIZE 59 | # define AP_LIST_FILE_SERIALIZE ", 'file:/path/to/file'" 60 | #else 61 | # define AP_LIST_FILE_SERIALIZE 62 | #endif 63 | #if APR_HAS_SYSVSEM_SERIALIZE || APR_HAS_POSIXSEM_SERIALIZE 64 | # define AP_LIST_SEM_SERIALIZE ", 'sem'" 65 | #else 66 | # define AP_LIST_SEM_SERIALIZE 67 | #endif 68 | 69 | #define AP_ALL_AVAILABLE_MUTEXES_STRING \ 70 | "Mutex mechanisms are: 'none', 'default'" \ 71 | AP_LIST_FLOCK_SERIALIZE AP_LIST_FCNTL_SERIALIZE \ 72 | AP_LIST_FILE_SERIALIZE AP_LIST_PTHREAD_SERIALIZE \ 73 | AP_LIST_SYSVSEM_SERIALIZE AP_LIST_POSIXSEM_SERIALIZE \ 74 | AP_LIST_SEM_SERIALIZE 75 | 76 | #define AP_AVAILABLE_MUTEXES_STRING \ 77 | "Mutex mechanisms are: 'default'" \ 78 | AP_LIST_FLOCK_SERIALIZE AP_LIST_FCNTL_SERIALIZE \ 79 | AP_LIST_FILE_SERIALIZE AP_LIST_PTHREAD_SERIALIZE \ 80 | AP_LIST_SYSVSEM_SERIALIZE AP_LIST_POSIXSEM_SERIALIZE \ 81 | AP_LIST_SEM_SERIALIZE 82 | 83 | #ifdef __cplusplus 84 | extern "C" { 85 | #endif 86 | 87 | /** 88 | * Get Mutex config data and parse it 89 | * @param arg The mutex config string 90 | * @param pool The allocation pool 91 | * @param mutexmech The APR mutex locking mechanism 92 | * @param mutexfile The lockfile to use as required 93 | * @return APR status code 94 | * @fn apr_status_t ap_parse_mutex(const char *arg, apr_pool_t *pool, 95 | apr_lockmech_e *mutexmech, 96 | const char **mutexfile) 97 | */ 98 | AP_DECLARE(apr_status_t) ap_parse_mutex(const char *arg, apr_pool_t *pool, 99 | apr_lockmech_e *mutexmech, 100 | const char **mutexfile); 101 | 102 | /* private function to process the Mutex directive */ 103 | AP_DECLARE_NONSTD(const char *) ap_set_mutex(cmd_parms *cmd, void *dummy, 104 | const char *arg); 105 | 106 | /* private function to initialize Mutex infrastructure */ 107 | AP_DECLARE_NONSTD(void) ap_mutex_init(apr_pool_t *p); 108 | 109 | /** 110 | * option flags for ap_mutex_register(), ap_global_mutex_create(), and 111 | * ap_proc_mutex_create() 112 | */ 113 | #define AP_MUTEX_ALLOW_NONE 1 /* allow "none" as mutex implementation; 114 | * respected only on ap_mutex_register() 115 | */ 116 | #define AP_MUTEX_DEFAULT_NONE 2 /* default to "none" for this mutex; 117 | * respected only on ap_mutex_register() 118 | */ 119 | 120 | /** 121 | * Register a module's mutex type with core to allow configuration 122 | * with the Mutex directive. This must be called in the pre_config 123 | * hook; otherwise, configuration directives referencing this mutex 124 | * type will be rejected. 125 | * 126 | * The default_dir and default_mech parameters allow a module to set 127 | * defaults for the lock file directory and mechanism. These could 128 | * be based on compile-time settings. These aren't required except 129 | * in special circumstances. 130 | * 131 | * The order of precedence for the choice of mechanism and lock file 132 | * directory is: 133 | * 134 | * 1. Mutex directive specifically for this mutex 135 | * e.g., Mutex mpm-default flock:/tmp/mpmlocks 136 | * 2. Mutex directive for global default 137 | * e.g., Mutex default flock:/tmp/httpdlocks 138 | * 3. Defaults for this mutex provided on the ap_mutex_register() 139 | * 4. Built-in defaults for all mutexes, which are 140 | * APR_LOCK_DEFAULT and DEFAULT_REL_RUNTIMEDIR. 141 | * 142 | * @param pconf The pconf pool 143 | * @param type The type name of the mutex, used as the basename of the 144 | * file associated with the mutex, if any. This must be unique among 145 | * all mutex types (mutex creation accommodates multi-instance mutex 146 | * types); mod_foo might have mutex types "foo-pipe" and "foo-shm" 147 | * @param default_dir Default dir for any lock file required for this 148 | * lock, to override built-in defaults; should be NULL for most 149 | * modules, to respect built-in defaults 150 | * @param default_mech Default mechanism for this lock, to override 151 | * built-in defaults; should be APR_LOCK_DEFAULT for most modules, to 152 | * respect built-in defaults 153 | * or NULL if there are no defaults for this mutex. 154 | * @param options combination of AP_MUTEX_* constants, or 0 for defaults 155 | */ 156 | AP_DECLARE(apr_status_t) ap_mutex_register(apr_pool_t *pconf, 157 | const char *type, 158 | const char *default_dir, 159 | apr_lockmech_e default_mech, 160 | apr_int32_t options); 161 | 162 | /** 163 | * Create an APR global mutex that has been registered previously with 164 | * ap_mutex_register(). Mutex files, permissions, and error logging will 165 | * be handled internally. 166 | * @param mutex The memory address where the newly created mutex will be 167 | * stored. If this mutex is disabled, mutex will be set to NULL on 168 | * output. (That is allowed only if the AP_MUTEX_ALLOW_NONE flag is 169 | * passed to ap_mutex_register().) 170 | * @param name The generated filename of the created mutex, or NULL if 171 | * no file was created. Pass NULL if this result is not needed. 172 | * @param type The type name of the mutex, matching the type name passed 173 | * to ap_mutex_register(). 174 | * @param instance_id A unique string to be used in the lock filename IFF 175 | * this mutex type is multi-instance, NULL otherwise. 176 | * @param server server_rec of main server 177 | * @param pool pool lifetime of the mutex 178 | * @param options combination of AP_MUTEX_* constants, or 0 for defaults 179 | * (currently none are defined for this function) 180 | */ 181 | AP_DECLARE(apr_status_t) ap_global_mutex_create(apr_global_mutex_t **mutex, 182 | const char **name, 183 | const char *type, 184 | const char *instance_id, 185 | server_rec *server, 186 | apr_pool_t *pool, 187 | apr_int32_t options); 188 | 189 | /** 190 | * Create an APR proc mutex that has been registered previously with 191 | * ap_mutex_register(). Mutex files, permissions, and error logging will 192 | * be handled internally. 193 | * @param mutex The memory address where the newly created mutex will be 194 | * stored. If this mutex is disabled, mutex will be set to NULL on 195 | * output. (That is allowed only if the AP_MUTEX_ALLOW_NONE flag is 196 | * passed to ap_mutex_register().) 197 | * @param name The generated filename of the created mutex, or NULL if 198 | * no file was created. Pass NULL if this result is not needed. 199 | * @param type The type name of the mutex, matching the type name passed 200 | * to ap_mutex_register(). 201 | * @param instance_id A unique string to be used in the lock filename IFF 202 | * this mutex type is multi-instance, NULL otherwise. 203 | * @param server server_rec of main server 204 | * @param pool pool lifetime of the mutex 205 | * @param options combination of AP_MUTEX_* constants, or 0 for defaults 206 | * (currently none are defined for this function) 207 | */ 208 | AP_DECLARE(apr_status_t) ap_proc_mutex_create(apr_proc_mutex_t **mutex, 209 | const char **name, 210 | const char *type, 211 | const char *instance_id, 212 | server_rec *server, 213 | apr_pool_t *pool, 214 | apr_int32_t options); 215 | 216 | AP_CORE_DECLARE(void) ap_dump_mutexes(apr_pool_t *p, server_rec *s, apr_file_t *out); 217 | 218 | #ifdef __cplusplus 219 | } 220 | #endif 221 | 222 | #endif /* UTIL_MUTEX_H */ 223 | /** @} */ 224 | -------------------------------------------------------------------------------- /docker/ab-mruby.conf.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Usage: ./ab-mruby -m ab-mruby.conf.rb -M ab-mruby.test.rb[http[s]://]hostname[:port]/path 3 | # 4 | # add_config( 5 | # "TotalRequests" => 100, # int 6 | # "Concurrency" => 10, # int max 20000 7 | # "KeepAlive" => true, # true or false or nil 8 | # "VerboseLevel" => 1, # int 1 ~ 5 9 | # "ShowProgress" => true, # true, false or nil 10 | # "ShowPercentile" => true, # true, false or nil 11 | # "ShowConfidence" => true, # true, false or nil 12 | # "WaitSocketError" => true, # true, false or nil 13 | # "RequestTimeOut" => 30000, # int msec 14 | # "BechmarkTimelimit" => 50000, # int sec 15 | # "WindowSize" => nil, # int byte 16 | # "HeadMethodOnly" => false, # true, false or nil 17 | # "Postfile" => nil, # './post.txt', 18 | # "Putfile" => nil, # './put.txt', 19 | # "ContentType" => nil, # 'application/x-www-form-urlencoded', 20 | # "OutputGnuplotFile" => nil, # './gnu.txt' 21 | # "OutputCSVFile" => nil, # './csv.txt' 22 | # "AddCookie" => nil, # 'Apache=1234' 23 | # "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 24 | # "BasicAuth" => nil, # 'user:pass' 25 | # "Proxy" => nil, # 'proxy[:port]' 26 | # "ProxyAuth" => nil, # 'user:pass' 27 | # "OutputHtml" => false, # true, false or nil 28 | # "SilentMode" => false, # true, false or nil 29 | # "BindAddress" => nil, # 'matsumoto-r.jp' 30 | # "SSLCipher" => 'DHE-RSA-AES128-SHA', # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 31 | # "SSLProtocol" => 'SSL3', # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 32 | # ) 33 | 34 | 35 | print < 38 | Licensed to MATSUMOTO Ryosuke, https://github.com/matsumoto-r/ab-mruby 39 | 40 | CONFIG PHASE 41 | 42 | ====================================================================== 43 | Target Information URL: #{get_config('TargetURL').to_s} 44 | Target Information HOST: #{get_config('TargetHost').to_s} 45 | Target Information PORT: #{get_config('TargetPort').to_s} 46 | Target Information PATH: #{get_config('TargetPath').to_s} 47 | Target Information SSL: #{get_config('TargetisSSL').to_s} 48 | EOS 49 | 50 | # defined ab config pattern 51 | if get_config("TargetHost").to_s == "blog.example.jp" 52 | 53 | add_config( 54 | "TotalRequests" => 100, # int 55 | "Concurrency" => 10, # int max 20000 56 | "KeepAlive" => true, # true or false or nil 57 | "VerboseLevel" => 1, # int 1 ~ 5 58 | "ShowProgress" => false, # true, false or nil 59 | "ShowPercentile" => false, # true, false or nil 60 | "ShowConfidence" => false, # true, false or nil 61 | "WaitSocketError" => true, # true, false or nil 62 | "RequestTimeOut" => 30000, # int msec 63 | "BechmarkTimelimit" => 50000, # int sec 64 | "WindowSize" => nil, # int byte 65 | "HeadMethodOnly" => false, # true, false or nil 66 | "Postfile" => nil, # './post.txt', 67 | "Putfile" => nil, # './put.txt', 68 | "ContentType" => nil, # 'application/x-www-form-urlencoded', 69 | "OutputGnuplotFile" => nil, # './gnu.txt' 70 | "OutputCSVFile" => nil, # './csv.txt' 71 | "AddCookie" => nil, # 'Apache=1234' 72 | "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 73 | "BasicAuth" => nil, # 'user:pass' 74 | "Proxy" => nil, # 'proxy[:port]' 75 | "ProxyAuth" => nil, # 'user:pass' 76 | "OutputHtml" => false, # true, false or nil 77 | "BindAddress" => nil, # 'example.jp' 78 | "SSLCipher" => nil, # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 79 | "SSLProtocol" => nil, # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 80 | "SilentMode" => true, 81 | ) 82 | 83 | elsif get_config("TargetHost").to_s == "moblog.example.jp" 84 | 85 | add_config( 86 | "TotalRequests" => 200, # int 87 | "Concurrency" => 20, # int max 20000 88 | "KeepAlive" => true, # true or false or nil 89 | "VerboseLevel" => 1, # int 1 ~ 5 90 | "ShowProgress" => false, # true, false or nil 91 | "ShowPercentile" => false, # true, false or nil 92 | "ShowConfidence" => false, # true, false or nil 93 | "WaitSocketError" => true, # true, false or nil 94 | "RequestTimeOut" => 30000, # int msec 95 | "BechmarkTimelimit" => 50000, # int sec 96 | "WindowSize" => nil, # int byte 97 | "HeadMethodOnly" => false, # true, false or nil 98 | "Postfile" => nil, # './post.txt', 99 | "Putfile" => nil, # './put.txt', 100 | "ContentType" => nil, # 'application/x-www-form-urlencoded', 101 | "OutputGnuplotFile" => nil, # './gnu.txt' 102 | "OutputCSVFile" => nil, # './csv.txt' 103 | "AddCookie" => nil, # 'Apache=1234' 104 | "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 105 | "BasicAuth" => nil, # 'user:pass' 106 | "Proxy" => nil, # 'proxy[:port]' 107 | "ProxyAuth" => nil, # 'user:pass' 108 | "OutputHtml" => false, # true, false or nil 109 | "BindAddress" => nil, # 'example.jp' 110 | "SSLCipher" => nil, # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 111 | "SSLProtocol" => nil, # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 112 | "SilentMode" => true, 113 | ) 114 | 115 | elsif get_config("TargetHost").to_s == "example.org" 116 | 117 | add_config( 118 | "TotalRequests" => 300, # int 119 | "Concurrency" => 30, # int max 20000 120 | "KeepAlive" => true, # true or false or nil 121 | "VerboseLevel" => 1, # int 1 ~ 5 122 | "ShowProgress" => false, # true, false or nil 123 | "ShowPercentile" => false, # true, false or nil 124 | "ShowConfidence" => false, # true, false or nil 125 | "WaitSocketError" => true, # true, false or nil 126 | "RequestTimeOut" => 30000, # int msec 127 | "BechmarkTimelimit" => 50000, # int sec 128 | "WindowSize" => nil, # int byte 129 | "HeadMethodOnly" => false, # true, false or nil 130 | "Postfile" => nil, # './post.txt', 131 | "Putfile" => nil, # './put.txt', 132 | "ContentType" => nil, # 'application/x-www-form-urlencoded', 133 | "OutputGnuplotFile" => nil, # './gnu.txt' 134 | "OutputCSVFile" => nil, # './csv.txt' 135 | "AddCookie" => nil, # 'Apache=1234' 136 | "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 137 | "BasicAuth" => nil, # 'user:pass' 138 | "Proxy" => nil, # 'proxy[:port]' 139 | "ProxyAuth" => nil, # 'user:pass' 140 | "OutputHtml" => false, # true, false or nil 141 | "BindAddress" => nil, # 'example.jp' 142 | "SSLCipher" => 'AES256-SHA', # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 143 | "SSLProtocol" => 'SSL3', # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 144 | "SilentMode" => true, 145 | ) 146 | else 147 | 148 | add_config( 149 | "TotalRequests" => 100, # int 150 | "Concurrency" => 10, # int max 20000 151 | "KeepAlive" => true, # true or false or nil 152 | "VerboseLevel" => 1, # int 1 ~ 5 153 | "SilentMode" => true, 154 | ) 155 | 156 | end 157 | 158 | -------------------------------------------------------------------------------- /test/ab-mruby.conf.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Usage: ./ab-mruby -m ab-mruby.conf.rb -M ab-mruby.test.rb[http[s]://]hostname[:port]/path 3 | # 4 | # add_config( 5 | # "TotalRequests" => 100, # int 6 | # "Concurrency" => 10, # int max 20000 7 | # "KeepAlive" => true, # true or false or nil 8 | # "VerboseLevel" => 1, # int 1 ~ 5 9 | # "ShowProgress" => true, # true, false or nil 10 | # "ShowPercentile" => true, # true, false or nil 11 | # "ShowConfidence" => true, # true, false or nil 12 | # "WaitSocketError" => true, # true, false or nil 13 | # "RequestTimeOut" => 30000, # int msec 14 | # "BechmarkTimelimit" => 50000, # int sec 15 | # "WindowSize" => nil, # int byte 16 | # "HeadMethodOnly" => false, # true, false or nil 17 | # "Postfile" => nil, # './post.txt', 18 | # "Putfile" => nil, # './put.txt', 19 | # "ContentType" => nil, # 'application/x-www-form-urlencoded', 20 | # "OutputGnuplotFile" => nil, # './gnu.txt' 21 | # "OutputCSVFile" => nil, # './csv.txt' 22 | # "AddCookie" => nil, # 'Apache=1234' 23 | # "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 24 | # "BasicAuth" => nil, # 'user:pass' 25 | # "Proxy" => nil, # 'proxy[:port]' 26 | # "ProxyAuth" => nil, # 'user:pass' 27 | # "OutputHtml" => false, # true, false or nil 28 | # "SilentMode" => false, # true, false or nil 29 | # "BindAddress" => nil, # 'matsumoto-r.jp' 30 | # "SSLCipher" => 'DHE-RSA-AES128-SHA', # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 31 | # "SSLProtocol" => 'SSL3', # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 32 | # ) 33 | 34 | 35 | print < 38 | Licensed to MATSUMOTO Ryosuke, https://github.com/matsumoto-r/ab-mruby 39 | 40 | CONFIG PHASE 41 | 42 | ====================================================================== 43 | Target Information URL: #{get_config('TargetURL').to_s} 44 | Target Information HOST: #{get_config('TargetHost').to_s} 45 | Target Information PORT: #{get_config('TargetPort').to_s} 46 | Target Information PATH: #{get_config('TargetPath').to_s} 47 | Target Information SSL: #{get_config('TargetisSSL').to_s} 48 | EOS 49 | 50 | # defined ab config pattern 51 | if get_config("TargetHost").to_s == "blog.example.jp" 52 | 53 | add_config( 54 | "TotalRequests" => 100, # int 55 | "Concurrency" => 10, # int max 20000 56 | "KeepAlive" => true, # true or false or nil 57 | "VerboseLevel" => 1, # int 1 ~ 5 58 | "ShowProgress" => false, # true, false or nil 59 | "ShowPercentile" => false, # true, false or nil 60 | "ShowConfidence" => false, # true, false or nil 61 | "WaitSocketError" => true, # true, false or nil 62 | "RequestTimeOut" => 30000, # int msec 63 | "BechmarkTimelimit" => 50000, # int sec 64 | "WindowSize" => nil, # int byte 65 | "HeadMethodOnly" => false, # true, false or nil 66 | "Postfile" => nil, # './post.txt', 67 | "Putfile" => nil, # './put.txt', 68 | "ContentType" => nil, # 'application/x-www-form-urlencoded', 69 | "OutputGnuplotFile" => nil, # './gnu.txt' 70 | "OutputCSVFile" => nil, # './csv.txt' 71 | "AddCookie" => nil, # 'Apache=1234' 72 | "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 73 | "BasicAuth" => nil, # 'user:pass' 74 | "Proxy" => nil, # 'proxy[:port]' 75 | "ProxyAuth" => nil, # 'user:pass' 76 | "OutputHtml" => false, # true, false or nil 77 | "BindAddress" => nil, # 'example.jp' 78 | "SSLCipher" => nil, # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 79 | "SSLProtocol" => nil, # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 80 | "SilentMode" => true, 81 | ) 82 | 83 | elsif get_config("TargetHost").to_s == "moblog.example.jp" 84 | 85 | add_config( 86 | "TotalRequests" => 200, # int 87 | "Concurrency" => 20, # int max 20000 88 | "KeepAlive" => true, # true or false or nil 89 | "VerboseLevel" => 1, # int 1 ~ 5 90 | "ShowProgress" => false, # true, false or nil 91 | "ShowPercentile" => false, # true, false or nil 92 | "ShowConfidence" => false, # true, false or nil 93 | "WaitSocketError" => true, # true, false or nil 94 | "RequestTimeOut" => 30000, # int msec 95 | "BechmarkTimelimit" => 50000, # int sec 96 | "WindowSize" => nil, # int byte 97 | "HeadMethodOnly" => false, # true, false or nil 98 | "Postfile" => nil, # './post.txt', 99 | "Putfile" => nil, # './put.txt', 100 | "ContentType" => nil, # 'application/x-www-form-urlencoded', 101 | "OutputGnuplotFile" => nil, # './gnu.txt' 102 | "OutputCSVFile" => nil, # './csv.txt' 103 | "AddCookie" => nil, # 'Apache=1234' 104 | "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 105 | "BasicAuth" => nil, # 'user:pass' 106 | "Proxy" => nil, # 'proxy[:port]' 107 | "ProxyAuth" => nil, # 'user:pass' 108 | "OutputHtml" => false, # true, false or nil 109 | "BindAddress" => nil, # 'example.jp' 110 | "SSLCipher" => nil, # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 111 | "SSLProtocol" => nil, # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 112 | "SilentMode" => true, 113 | ) 114 | 115 | elsif get_config("TargetHost").to_s == "example.org" 116 | 117 | add_config( 118 | "TotalRequests" => 300, # int 119 | "Concurrency" => 30, # int max 20000 120 | "KeepAlive" => true, # true or false or nil 121 | "VerboseLevel" => 1, # int 1 ~ 5 122 | "ShowProgress" => false, # true, false or nil 123 | "ShowPercentile" => false, # true, false or nil 124 | "ShowConfidence" => false, # true, false or nil 125 | "WaitSocketError" => true, # true, false or nil 126 | "RequestTimeOut" => 30000, # int msec 127 | "BechmarkTimelimit" => 50000, # int sec 128 | "WindowSize" => nil, # int byte 129 | "HeadMethodOnly" => false, # true, false or nil 130 | "Postfile" => nil, # './post.txt', 131 | "Putfile" => nil, # './put.txt', 132 | "ContentType" => nil, # 'application/x-www-form-urlencoded', 133 | "OutputGnuplotFile" => nil, # './gnu.txt' 134 | "OutputCSVFile" => nil, # './csv.txt' 135 | "AddCookie" => nil, # 'Apache=1234' 136 | "AddHeader" => 'User-Agent: ab-mruby', # 'User-Agent: test' 137 | "BasicAuth" => nil, # 'user:pass' 138 | "Proxy" => nil, # 'proxy[:port]' 139 | "ProxyAuth" => nil, # 'user:pass' 140 | "OutputHtml" => false, # true, false or nil 141 | "BindAddress" => nil, # 'example.jp' 142 | "SSLCipher" => 'AES256-SHA', # 'DHE-RSA-AES256-SHA' or get from [openssl ciphers -v] 143 | "SSLProtocol" => 'SSL3', # 'SSL2', 'SSL3', 'TLS1', 'TLS1.1', 'TLS1.2' or 'ALL' 144 | "SilentMode" => true, 145 | ) 146 | else 147 | 148 | add_config( 149 | "TotalRequests" => 100, # int 150 | "Concurrency" => 10, # int max 20000 151 | "KeepAlive" => true, # true or false or nil 152 | "VerboseLevel" => 1, # int 1 ~ 5 153 | "SilentMode" => true, 154 | ) 155 | 156 | end 157 | 158 | -------------------------------------------------------------------------------- /include/ap_regex.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Derived from PCRE's pcreposix.h. 18 | 19 | Copyright (c) 1997-2004 University of Cambridge 20 | 21 | ----------------------------------------------------------------------------- 22 | Redistribution and use in source and binary forms, with or without 23 | modification, are permitted provided that the following conditions are met: 24 | 25 | * Redistributions of source code must retain the above copyright notice, 26 | this list of conditions and the following disclaimer. 27 | 28 | * Redistributions in binary form must reproduce the above copyright 29 | notice, this list of conditions and the following disclaimer in the 30 | documentation and/or other materials provided with the distribution. 31 | 32 | * Neither the name of the University of Cambridge nor the names of its 33 | contributors may be used to endorse or promote products derived from 34 | this software without specific prior written permission. 35 | 36 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 37 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 39 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 40 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 41 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 42 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 43 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 44 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 45 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 46 | POSSIBILITY OF SUCH DAMAGE. 47 | ----------------------------------------------------------------------------- 48 | */ 49 | 50 | /** 51 | * @file ap_regex.h 52 | * @brief Apache Regex defines 53 | */ 54 | 55 | #ifndef AP_REGEX_H 56 | #define AP_REGEX_H 57 | 58 | #include "apr.h" 59 | 60 | /* Allow for C++ users */ 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | /* Options for ap_regcomp, ap_regexec, and ap_rxplus versions: */ 67 | 68 | #define AP_REG_ICASE 0x01 /** use a case-insensitive match */ 69 | #define AP_REG_NEWLINE 0x02 /** don't match newlines against '.' etc */ 70 | #define AP_REG_NOTBOL 0x04 /** ^ will not match against start-of-string */ 71 | #define AP_REG_NOTEOL 0x08 /** $ will not match against end-of-string */ 72 | 73 | #define AP_REG_EXTENDED (0) /** unused */ 74 | #define AP_REG_NOSUB (0) /** unused */ 75 | 76 | #define AP_REG_MULTI 0x10 /* perl's /g (needs fixing) */ 77 | #define AP_REG_NOMEM 0x20 /* nomem in our code */ 78 | #define AP_REG_DOTALL 0x40 /* perl's /s flag */ 79 | 80 | /* Error values: */ 81 | enum { 82 | AP_REG_ASSERT = 1, /** internal error ? */ 83 | AP_REG_ESPACE, /** failed to get memory */ 84 | AP_REG_INVARG, /** invalid argument */ 85 | AP_REG_NOMATCH /** match failed */ 86 | }; 87 | 88 | /* The structure representing a compiled regular expression. */ 89 | typedef struct { 90 | void *re_pcre; 91 | int re_nsub; 92 | apr_size_t re_erroffset; 93 | } ap_regex_t; 94 | 95 | /* The structure in which a captured offset is returned. */ 96 | typedef struct { 97 | int rm_so; 98 | int rm_eo; 99 | } ap_regmatch_t; 100 | 101 | /* The functions */ 102 | 103 | /** 104 | * Compile a regular expression. 105 | * @param preg Returned compiled regex 106 | * @param regex The regular expression string 107 | * @param cflags Bitwise OR of AP_REG_* flags (ICASE and NEWLINE supported, 108 | * other flags are ignored) 109 | * @return Zero on success or non-zero on error 110 | */ 111 | AP_DECLARE(int) ap_regcomp(ap_regex_t *preg, const char *regex, int cflags); 112 | 113 | /** 114 | * Match a NUL-terminated string against a pre-compiled regex. 115 | * @param preg The pre-compiled regex 116 | * @param string The string to match 117 | * @param nmatch Provide information regarding the location of any matches 118 | * @param pmatch Provide information regarding the location of any matches 119 | * @param eflags Bitwise OR of AP_REG_* flags (NOTBOL and NOTEOL supported, 120 | * other flags are ignored) 121 | * @return 0 for successful match, \p AP_REG_NOMATCH otherwise 122 | */ 123 | AP_DECLARE(int) ap_regexec(const ap_regex_t *preg, const char *string, 124 | apr_size_t nmatch, ap_regmatch_t *pmatch, int eflags); 125 | 126 | /** 127 | * Match a string with given length against a pre-compiled regex. The string 128 | * does not need to be NUL-terminated. 129 | * @param preg The pre-compiled regex 130 | * @param buff The string to match 131 | * @param len Length of the string to match 132 | * @param nmatch Provide information regarding the location of any matches 133 | * @param pmatch Provide information regarding the location of any matches 134 | * @param eflags Bitwise OR of AP_REG_* flags (NOTBOL and NOTEOL supported, 135 | * other flags are ignored) 136 | * @return 0 for successful match, AP_REG_NOMATCH otherwise 137 | */ 138 | AP_DECLARE(int) ap_regexec_len(const ap_regex_t *preg, const char *buff, 139 | apr_size_t len, apr_size_t nmatch, 140 | ap_regmatch_t *pmatch, int eflags); 141 | 142 | /** 143 | * Return the error code returned by regcomp or regexec into error messages 144 | * @param errcode the error code returned by regexec or regcomp 145 | * @param preg The precompiled regex 146 | * @param errbuf A buffer to store the error in 147 | * @param errbuf_size The size of the buffer 148 | */ 149 | AP_DECLARE(apr_size_t) ap_regerror(int errcode, const ap_regex_t *preg, 150 | char *errbuf, apr_size_t errbuf_size); 151 | 152 | /** Destroy a pre-compiled regex. 153 | * @param preg The pre-compiled regex to free. 154 | */ 155 | AP_DECLARE(void) ap_regfree(ap_regex_t *preg); 156 | 157 | /* ap_rxplus: higher-level regexps */ 158 | 159 | typedef struct { 160 | ap_regex_t rx; 161 | apr_uint32_t flags; 162 | const char *subs; 163 | const char *match; 164 | apr_size_t nmatch; 165 | ap_regmatch_t *pmatch; 166 | } ap_rxplus_t; 167 | 168 | /** 169 | * Compile a pattern into a regexp. 170 | * supports perl-like formats 171 | * match-string 172 | * /match-string/flags 173 | * s/match-string/replacement-string/flags 174 | * Intended to support more perl-like stuff as and when round tuits happen 175 | * match-string is anything supported by ap_regcomp 176 | * replacement-string is a substitution string as supported in ap_pregsub 177 | * flags should correspond with perl syntax: treat failure to do so as a bug 178 | * (documentation TBD) 179 | * @param pool Pool to allocate from 180 | * @param pattern Pattern to compile 181 | * @return Compiled regexp, or NULL in case of compile/syntax error 182 | */ 183 | AP_DECLARE(ap_rxplus_t*) ap_rxplus_compile(apr_pool_t *pool, const char *pattern); 184 | /** 185 | * Apply a regexp operation to a string. 186 | * @param pool Pool to allocate from 187 | * @param rx The regex match to apply 188 | * @param pattern The string to apply it to 189 | * NOTE: This MUST be kept in scope to use regexp memory 190 | * @param newpattern The modified string (ignored if the operation doesn't 191 | * modify the string) 192 | * @return Number of times a match happens. Normally 0 (no match) or 1 193 | * (match found), but may be greater if a transforming pattern 194 | * is applied with the 'g' flag. 195 | */ 196 | AP_DECLARE(int) ap_rxplus_exec(apr_pool_t *pool, ap_rxplus_t *rx, 197 | const char *pattern, char **newpattern); 198 | #ifdef DOXYGEN 199 | /** 200 | * Number of matches in the regexp operation's memory 201 | * This may be 0 if no match is in memory, or up to nmatch from compilation 202 | * @param rx The regexp 203 | * @return Number of matches in memory 204 | */ 205 | AP_DECLARE(int) ap_rxplus_nmatch(ap_rxplus_t *rx); 206 | #else 207 | #define ap_rxplus_nmatch(rx) (((rx)->match != NULL) ? (rx)->nmatch : 0) 208 | #endif 209 | /** 210 | * Get a pointer to a match from regex memory 211 | * NOTE: this relies on the match pattern from the last call to 212 | * ap_rxplus_exec still being valid (i.e. not freed or out-of-scope) 213 | * @param rx The regexp 214 | * @param n The match number to retrieve (must be between 0 and nmatch) 215 | * @param len Returns the length of the match. 216 | * @param match Returns the match pattern 217 | */ 218 | AP_DECLARE(void) ap_rxplus_match(ap_rxplus_t *rx, int n, int *len, 219 | const char **match); 220 | /** 221 | * Get a match from regex memory in a string copy 222 | * NOTE: this relies on the match pattern from the last call to 223 | * ap_rxplus_exec still being valid (i.e. not freed or out-of-scope) 224 | * @param pool Pool to allocate from 225 | * @param rx The regexp 226 | * @param n The match number to retrieve (must be between 0 and nmatch) 227 | * @return The matched string 228 | */ 229 | AP_DECLARE(char*) ap_rxplus_pmatch(apr_pool_t *pool, ap_rxplus_t *rx, int n); 230 | 231 | #ifdef __cplusplus 232 | } /* extern "C" */ 233 | #endif 234 | 235 | #endif /* AP_REGEX_T */ 236 | 237 | -------------------------------------------------------------------------------- /include/ap_socache.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_socache.h 19 | * @brief Small object cache provider interface. 20 | * 21 | * @defgroup AP_SOCACHE ap_socache 22 | * @ingroup APACHE_MODS 23 | * @{ 24 | */ 25 | 26 | #ifndef AP_SOCACHE_H 27 | #define AP_SOCACHE_H 28 | 29 | #include "httpd.h" 30 | #include "ap_provider.h" 31 | #include "apr_pools.h" 32 | #include "apr_time.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /** If this flag is set, the store/retrieve/remove/status interfaces 39 | * of the provider are NOT safe to be called concurrently from 40 | * multiple processes or threads, and an external global mutex must be 41 | * used to serialize access to the provider. 42 | */ 43 | /* XXX: Even if store/retrieve/remove is atomic, isn't it useful to note 44 | * independently that status and iterate may or may not be? 45 | */ 46 | #define AP_SOCACHE_FLAG_NOTMPSAFE (0x0001) 47 | 48 | /** A cache instance. */ 49 | typedef struct ap_socache_instance_t ap_socache_instance_t; 50 | 51 | /** Hints which may be passed to the init function; providers may 52 | * ignore some or all of these hints. */ 53 | struct ap_socache_hints { 54 | /** Approximate average length of IDs: */ 55 | apr_size_t avg_id_len; 56 | /** Approximate average size of objects: */ 57 | apr_size_t avg_obj_size; 58 | /** Suggested interval between expiry cleanup runs; */ 59 | apr_interval_time_t expiry_interval; 60 | }; 61 | 62 | /** 63 | * Iterator callback prototype for the ap_socache_provider_t->iterate() method 64 | * @param instance The cache instance 65 | * @param s Associated server context (for logging) 66 | * @param userctx User defined pointer passed from the iterator call 67 | * @param id Unique ID for the object (binary blob) 68 | * with a trailing null char for convenience 69 | * @param idlen Length of id blob 70 | * @param data Output buffer to place retrieved data (binary blob) 71 | * with a trailing null char for convenience 72 | * @param datalen Length of data buffer 73 | * @param pool Pool for temporary allocations 74 | * @return APR status value; return APR_SUCCESS or the iteration will halt; 75 | * this value is returned to the ap_socache_provider_t->iterate() caller 76 | */ 77 | typedef apr_status_t (ap_socache_iterator_t)(ap_socache_instance_t *instance, 78 | server_rec *s, 79 | void *userctx, 80 | const unsigned char *id, 81 | unsigned int idlen, 82 | const unsigned char *data, 83 | unsigned int datalen, 84 | apr_pool_t *pool); 85 | 86 | /** A socache provider structure. socache providers are registered 87 | * with the ap_provider.h interface using the AP_SOCACHE_PROVIDER_* 88 | * constants. */ 89 | typedef struct ap_socache_provider_t { 90 | /** Canonical provider name. */ 91 | const char *name; 92 | 93 | /** Bitmask of AP_SOCACHE_FLAG_* flags. */ 94 | unsigned int flags; 95 | 96 | /** 97 | * Create a session cache based on the given configuration string. 98 | * The instance pointer returned in the instance parameter will be 99 | * passed as the first argument to subsequent invocations. 100 | * 101 | * @param instance Output parameter to which instance object is written. 102 | * @param arg User-specified configuration string. May be NULL to 103 | * force use of defaults. 104 | * @param tmp Pool to be used for any temporary allocations 105 | * @param p Pool to be use for any allocations lasting as long as 106 | * the created instance 107 | * @return NULL on success, or an error string on failure. 108 | */ 109 | const char *(*create)(ap_socache_instance_t **instance, const char *arg, 110 | apr_pool_t *tmp, apr_pool_t *p); 111 | 112 | /** 113 | * Initialize the cache. The cname must be of maximum length 16 114 | * characters, and uniquely identifies the consumer of the cache 115 | * within the server; using the module name is recommended, e.g. 116 | * "mod_ssl-sess". This string may be used within a filesystem 117 | * path so use of only alphanumeric [a-z0-9_-] characters is 118 | * recommended. If hints is non-NULL, it gives a set of hints for 119 | * the provider. Returns APR error code. 120 | * 121 | * @param instance The cache instance 122 | * @param cname A unique string identifying the consumer of this API 123 | * @param hints Optional hints argument describing expected cache use 124 | * @param s Server structure to which the cache is associated 125 | * @param pool Pool for long-lived allocations 126 | * @return APR status value indicating success. 127 | */ 128 | apr_status_t (*init)(ap_socache_instance_t *instance, const char *cname, 129 | const struct ap_socache_hints *hints, 130 | server_rec *s, apr_pool_t *pool); 131 | 132 | /** 133 | * Destroy a given cache instance object. 134 | * @param instance The cache instance to destroy. 135 | * @param s Associated server structure (for logging purposes) 136 | */ 137 | void (*destroy)(ap_socache_instance_t *instance, server_rec *s); 138 | 139 | /** 140 | * Store an object in a cache instance. 141 | * @param instance The cache instance 142 | * @param s Associated server structure (for logging purposes) 143 | * @param id Unique ID for the object; binary blob 144 | * @param idlen Length of id blob 145 | * @param expiry Absolute time at which the object expires 146 | * @param data Data to store; binary blob 147 | * @param datalen Length of data blob 148 | * @param pool Pool for temporary allocations. 149 | * @return APR status value. 150 | */ 151 | apr_status_t (*store)(ap_socache_instance_t *instance, server_rec *s, 152 | const unsigned char *id, unsigned int idlen, 153 | apr_time_t expiry, 154 | unsigned char *data, unsigned int datalen, 155 | apr_pool_t *pool); 156 | 157 | /** 158 | * Retrieve a cached object. 159 | * 160 | * @param instance The cache instance 161 | * @param s Associated server structure (for logging purposes) 162 | * @param id Unique ID for the object; binary blob 163 | * @param idlen Length of id blob 164 | * @param data Output buffer to place retrievd data (binary blob) 165 | * @param datalen On entry, length of data buffer; on exit, the 166 | * number of bytes written to the data buffer. 167 | * @param pool Pool for temporary allocations. 168 | * @return APR status value; APR_NOTFOUND if the object was not 169 | * found 170 | */ 171 | apr_status_t (*retrieve)(ap_socache_instance_t *instance, server_rec *s, 172 | const unsigned char *id, unsigned int idlen, 173 | unsigned char *data, unsigned int *datalen, 174 | apr_pool_t *pool); 175 | 176 | /** 177 | * Remove an object from the cache 178 | * 179 | * @param instance The cache instance 180 | * @param s Associated server structure (for logging purposes) 181 | * @param id Unique ID for the object; binary blob 182 | * @param idlen Length of id blob 183 | * @param pool Pool for temporary allocations. 184 | */ 185 | apr_status_t (*remove)(ap_socache_instance_t *instance, server_rec *s, 186 | const unsigned char *id, unsigned int idlen, 187 | apr_pool_t *pool); 188 | 189 | /** 190 | * Dump the status of a cache instance for mod_status. Will use 191 | * the ap_r* interfaces to produce appropriate status output. 192 | * XXX: ap_r* are deprecated, bad dogfood 193 | * 194 | * @param instance The cache instance 195 | * @param r The request structure 196 | * @param flags The AP_STATUS_* constants used (see mod_status.h) 197 | */ 198 | void (*status)(ap_socache_instance_t *instance, request_rec *r, int flags); 199 | 200 | /** 201 | * Dump all cached objects through an iterator callback. 202 | * @param instance The cache instance 203 | * @param s Associated server context (for processing and logging) 204 | * @param userctx User defined pointer passed through to the iterator 205 | * @param iterator The user provided callback function which will receive 206 | * individual calls for each unexpired id/data pair 207 | * @param pool Pool for temporary allocations. 208 | * @return APR status value; APR_NOTFOUND if the object was not 209 | * found 210 | */ 211 | apr_status_t (*iterate)(ap_socache_instance_t *instance, server_rec *s, 212 | void *userctx, ap_socache_iterator_t *iterator, 213 | apr_pool_t *pool); 214 | 215 | } ap_socache_provider_t; 216 | 217 | /** The provider group used to register socache providers. */ 218 | #define AP_SOCACHE_PROVIDER_GROUP "socache" 219 | /** The provider version used to register socache providers. */ 220 | #define AP_SOCACHE_PROVIDER_VERSION "0" 221 | 222 | /** Default provider name. */ 223 | #define AP_SOCACHE_DEFAULT_PROVIDER "default" 224 | 225 | #ifdef __cplusplus 226 | } 227 | #endif 228 | 229 | #endif /* AP_SOCACHE_H */ 230 | /** @} */ 231 | -------------------------------------------------------------------------------- /include/util_script.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file util_script.h 19 | * @brief Apache script tools 20 | * 21 | * @defgroup APACHE_CORE_SCRIPT Script Tools 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef APACHE_UTIL_SCRIPT_H 27 | #define APACHE_UTIL_SCRIPT_H 28 | 29 | #include "apr_buckets.h" 30 | #include "ap_config.h" 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | #ifndef APACHE_ARG_MAX 37 | #ifdef _POSIX_ARG_MAX 38 | #define APACHE_ARG_MAX _POSIX_ARG_MAX 39 | #else 40 | #define APACHE_ARG_MAX 512 41 | #endif 42 | #endif 43 | 44 | /** 45 | * Create an environment variable out of an Apache table of key-value pairs 46 | * @param p pool to allocate out of 47 | * @param t Apache table of key-value pairs 48 | * @return An array containing the same key-value pairs suitable for 49 | * use with an exec call. 50 | * @fn char **ap_create_environment(apr_pool_t *p, apr_table_t *t) 51 | */ 52 | AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t); 53 | 54 | /** 55 | * This "cute" little function comes about because the path info on 56 | * filenames and URLs aren't always the same. So we take the two, 57 | * and find as much of the two that match as possible. 58 | * @param uri The uri we are currently parsing 59 | * @param path_info The current path info 60 | * @return The length of the path info 61 | * @fn int ap_find_path_info(const char *uri, const char *path_info) 62 | */ 63 | AP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info); 64 | 65 | /** 66 | * Add CGI environment variables required by HTTP/1.1 to the request's 67 | * environment table 68 | * @param r the current request 69 | * @fn void ap_add_cgi_vars(request_rec *r) 70 | */ 71 | AP_DECLARE(void) ap_add_cgi_vars(request_rec *r); 72 | 73 | /** 74 | * Add common CGI environment variables to the requests environment table 75 | * @param r The current request 76 | * @fn void ap_add_common_vars(request_rec *r) 77 | */ 78 | AP_DECLARE(void) ap_add_common_vars(request_rec *r); 79 | 80 | /** 81 | * Read headers output from a script, ensuring that the output is valid. If 82 | * the output is valid, then the headers are added to the headers out of the 83 | * current request 84 | * @param r The current request 85 | * @param f The file to read from 86 | * @param buffer Empty when calling the function. On output, if there was an 87 | * error, the string that cause the error is stored here. 88 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 89 | * @fn int ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer) 90 | */ 91 | AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f, char *buffer); 92 | 93 | /** 94 | * Read headers output from a script, ensuring that the output is valid. If 95 | * the output is valid, then the headers are added to the headers out of the 96 | * current request 97 | * @param r The current request 98 | * @param f The file to read from 99 | * @param buffer Empty when calling the function. On output, if there was an 100 | * error, the string that cause the error is stored here. 101 | * @param module_index The module index to be used for logging 102 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 103 | */ 104 | AP_DECLARE(int) ap_scan_script_header_err_ex(request_rec *r, apr_file_t *f, 105 | char *buffer, int module_index); 106 | 107 | 108 | /** 109 | * Read headers output from a script, ensuring that the output is valid. If 110 | * the output is valid, then the headers are added to the headers out of the 111 | * current request 112 | * @param r The current request 113 | * @param bb The brigade from which to read 114 | * @param buffer Empty when calling the function. On output, if there was an 115 | * error, the string that cause the error is stored here. 116 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 117 | * @fn int ap_scan_script_header_err_brigade(request_rec *r, apr_bucket_brigade *bb, char *buffer) 118 | */ 119 | AP_DECLARE(int) ap_scan_script_header_err_brigade(request_rec *r, 120 | apr_bucket_brigade *bb, 121 | char *buffer); 122 | 123 | /** 124 | * Read headers output from a script, ensuring that the output is valid. If 125 | * the output is valid, then the headers are added to the headers out of the 126 | * current request 127 | * @param r The current request 128 | * @param bb The brigade from which to read 129 | * @param buffer Empty when calling the function. On output, if there was an 130 | * error, the string that cause the error is stored here. 131 | * @param module_index The module index to be used for logging 132 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 133 | */ 134 | AP_DECLARE(int) ap_scan_script_header_err_brigade_ex(request_rec *r, 135 | apr_bucket_brigade *bb, 136 | char *buffer, 137 | int module_index); 138 | 139 | /** 140 | * Read headers strings from a script, ensuring that the output is valid. If 141 | * the output is valid, then the headers are added to the headers out of the 142 | * current request 143 | * @param r The current request 144 | * @param buffer Empty when calling the function. On output, if there was an 145 | * error, the string that cause the error is stored here. 146 | * @param termch Pointer to the last character parsed. 147 | * @param termarg Pointer to an int to capture the last argument parsed. 148 | * 149 | * The varargs are string arguments to parse consecutively for headers, 150 | * with a NULL argument to terminate the list. 151 | * 152 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 153 | */ 154 | AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r, 155 | char *buffer, 156 | const char **termch, 157 | int *termarg, ...) 158 | AP_FN_ATTR_SENTINEL; 159 | 160 | /** 161 | * Read headers strings from a script, ensuring that the output is valid. If 162 | * the output is valid, then the headers are added to the headers out of the 163 | * current request 164 | * @param r The current request 165 | * @param buffer Empty when calling the function. On output, if there was an 166 | * error, the string that cause the error is stored here. 167 | * @param module_index The module index to be used for logging 168 | * @param termch Pointer to the last character parsed. 169 | * @param termarg Pointer to an int to capture the last argument parsed. 170 | * 171 | * The varargs are string arguments to parse consecutively for headers, 172 | * with a NULL argument to terminate the list. 173 | * 174 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 175 | */ 176 | AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs_ex(request_rec *r, 177 | char *buffer, 178 | int module_index, 179 | const char **termch, 180 | int *termarg, ...) 181 | AP_FN_ATTR_SENTINEL; 182 | 183 | 184 | /** 185 | * Read headers output from a script, ensuring that the output is valid. If 186 | * the output is valid, then the headers are added to the headers out of the 187 | * current request 188 | * @param r The current request 189 | * @param buffer Empty when calling the function. On output, if there was an 190 | * error, the string that cause the error is stored here. 191 | * @param getsfunc Function to read the headers from. This function should 192 | act like gets() 193 | * @param getsfunc_data The place to read from 194 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 195 | */ 196 | AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer, 197 | int (*getsfunc) (char *, int, void *), 198 | void *getsfunc_data); 199 | 200 | /** 201 | * Read headers output from a script, ensuring that the output is valid. If 202 | * the output is valid, then the headers are added to the headers out of the 203 | * current request 204 | * @param r The current request 205 | * @param buffer Empty when calling the function. On output, if there was an 206 | * error, the string that cause the error is stored here. 207 | * @param getsfunc Function to read the headers from. This function should 208 | act like gets() 209 | * @param getsfunc_data The place to read from 210 | * @param module_index The module index to be used for logging 211 | * @return HTTP_OK on success, HTTP_INTERNAL_SERVER_ERROR otherwise 212 | */ 213 | AP_DECLARE(int) ap_scan_script_header_err_core_ex(request_rec *r, char *buffer, 214 | int (*getsfunc) (char *, int, void *), 215 | void *getsfunc_data, int module_index); 216 | 217 | 218 | /** 219 | * Parse query args for the request and store in a new table allocated 220 | * from the request pool. 221 | * For args with no value, "1" will be used instead. 222 | * If no query args were specified, the table will be empty. 223 | * @param r The current request 224 | * @param table A new table on output. 225 | */ 226 | AP_DECLARE(void) ap_args_to_table(request_rec *r, apr_table_t **table); 227 | 228 | #ifdef __cplusplus 229 | } 230 | #endif 231 | 232 | #endif /* !APACHE_UTIL_SCRIPT_H */ 233 | /** @} */ 234 | -------------------------------------------------------------------------------- /include/ap_mpm.h: -------------------------------------------------------------------------------- 1 | /* Licensed to the Apache Software Foundation (ASF) under one or more 2 | * contributor license agreements. See the NOTICE file distributed with 3 | * this work for additional information regarding copyright ownership. 4 | * The ASF licenses this file to You under the Apache License, Version 2.0 5 | * (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file ap_mpm.h 19 | * @brief Apache Multi-Processing Module library 20 | * 21 | * @defgroup APACHE_CORE_MPM Multi-Processing Module library 22 | * @ingroup APACHE_CORE 23 | * @{ 24 | */ 25 | 26 | #ifndef AP_MPM_H 27 | #define AP_MPM_H 28 | 29 | #include "apr_thread_proc.h" 30 | #include "httpd.h" 31 | #include "scoreboard.h" 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | /* 38 | The MPM, "multi-processing model" provides an abstraction of the 39 | interface with the OS for distributing incoming connections to 40 | threads/process for processing. http_main invokes the MPM, and 41 | the MPM runs until a shutdown/restart has been indicated. 42 | The MPM calls out to the apache core via the ap_process_connection 43 | function when a connection arrives. 44 | 45 | The MPM may or may not be multithreaded. In the event that it is 46 | multithreaded, at any instant it guarantees a 1:1 mapping of threads 47 | ap_process_connection invocations. 48 | 49 | Note: In the future it will be possible for ap_process_connection 50 | to return to the MPM prior to finishing the entire connection; and 51 | the MPM will proceed with asynchronous handling for the connection; 52 | in the future the MPM may call ap_process_connection again -- but 53 | does not guarantee it will occur on the same thread as the first call. 54 | 55 | The MPM further guarantees that no asynchronous behaviour such as 56 | longjmps and signals will interfere with the user code that is 57 | invoked through ap_process_connection. The MPM may reserve some 58 | signals for its use (i.e. SIGUSR1), but guarantees that these signals 59 | are ignored when executing outside the MPM code itself. (This 60 | allows broken user code that does not handle EINTR to function 61 | properly.) 62 | 63 | The suggested server restart and stop behaviour will be "graceful". 64 | However the MPM may choose to terminate processes when the user 65 | requests a non-graceful restart/stop. When this occurs, the MPM kills 66 | all threads with extreme prejudice, and destroys the pchild pool. 67 | User cleanups registered in the pchild apr_pool_t will be invoked at 68 | this point. (This can pose some complications, the user cleanups 69 | are asynchronous behaviour not unlike longjmp/signal... but if the 70 | admin is asking for a non-graceful shutdown, how much effort should 71 | we put into doing it in a nice way?) 72 | 73 | unix/posix notes: 74 | - The MPM does not set a SIGALRM handler, user code may use SIGALRM. 75 | But the preferred method of handling timeouts is to use the 76 | timeouts provided by the BUFF abstraction. 77 | - The proper setting for SIGPIPE is SIG_IGN, if user code changes it 78 | for any of their own processing, it must be restored to SIG_IGN 79 | prior to executing or returning to any apache code. 80 | TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN 81 | */ 82 | 83 | /** 84 | * Pass control to the MPM for steady-state processing. It is responsible 85 | * for controlling the parent and child processes. It will run until a 86 | * restart/shutdown is indicated. 87 | * @param pconf the configuration pool, reset before the config file is read 88 | * @param plog the log pool, reset after the config file is read 89 | * @param server_conf the global server config. 90 | * @return DONE for shutdown OK otherwise. 91 | */ 92 | AP_DECLARE_HOOK(int, mpm, (apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf)) 93 | 94 | /** 95 | * Spawn a process with privileges that another module has requested 96 | * @param r The request_rec of the current request 97 | * @param newproc The resulting process handle. 98 | * @param progname The program to run 99 | * @param args the arguments to pass to the new program. The first 100 | * one should be the program name. 101 | * @param env The new environment apr_table_t for the new process. This 102 | * should be a list of NULL-terminated strings. 103 | * @param attr the procattr we should use to determine how to create the new 104 | * process 105 | * @param p The pool to use. 106 | */ 107 | AP_DECLARE(apr_status_t) ap_os_create_privileged_process( 108 | const request_rec *r, 109 | apr_proc_t *newproc, 110 | const char *progname, 111 | const char * const *args, 112 | const char * const *env, 113 | apr_procattr_t *attr, 114 | apr_pool_t *p); 115 | 116 | /* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED */ 117 | #define AP_MPMQ_NOT_SUPPORTED 0 /* This value specifies that an */ 118 | /* MPM is not capable of */ 119 | /* threading or forking. */ 120 | #define AP_MPMQ_STATIC 1 /* This value specifies that */ 121 | /* an MPM is using a static */ 122 | /* number of threads or daemons */ 123 | #define AP_MPMQ_DYNAMIC 2 /* This value specifies that */ 124 | /* an MPM is using a dynamic */ 125 | /* number of threads or daemons */ 126 | 127 | /* Values returned for AP_MPMQ_MPM_STATE */ 128 | #define AP_MPMQ_STARTING 0 129 | #define AP_MPMQ_RUNNING 1 130 | #define AP_MPMQ_STOPPING 2 131 | 132 | #define AP_MPMQ_MAX_DAEMON_USED 1 /* Max # of daemons used so far */ 133 | #define AP_MPMQ_IS_THREADED 2 /* MPM can do threading */ 134 | #define AP_MPMQ_IS_FORKED 3 /* MPM can do forking */ 135 | #define AP_MPMQ_HARD_LIMIT_DAEMONS 4 /* The compiled max # daemons */ 136 | #define AP_MPMQ_HARD_LIMIT_THREADS 5 /* The compiled max # threads */ 137 | #define AP_MPMQ_MAX_THREADS 6 /* # of threads/child by config */ 138 | #define AP_MPMQ_MIN_SPARE_DAEMONS 7 /* Min # of spare daemons */ 139 | #define AP_MPMQ_MIN_SPARE_THREADS 8 /* Min # of spare threads */ 140 | #define AP_MPMQ_MAX_SPARE_DAEMONS 9 /* Max # of spare daemons */ 141 | #define AP_MPMQ_MAX_SPARE_THREADS 10 /* Max # of spare threads */ 142 | #define AP_MPMQ_MAX_REQUESTS_DAEMON 11 /* Max # of requests per daemon */ 143 | #define AP_MPMQ_MAX_DAEMONS 12 /* Max # of daemons by config */ 144 | #define AP_MPMQ_MPM_STATE 13 /* starting, running, stopping */ 145 | #define AP_MPMQ_IS_ASYNC 14 /* MPM can process async connections */ 146 | #define AP_MPMQ_GENERATION 15 /* MPM generation */ 147 | #define AP_MPMQ_HAS_SERF 16 /* MPM can drive serf internally */ 148 | 149 | /** 150 | * Query a property of the current MPM. 151 | * @param query_code One of APM_MPMQ_* 152 | * @param result A location to place the result of the query 153 | * @return APR_EGENERAL if an mpm-query hook has not been registered; 154 | * APR_SUCCESS or APR_ENOTIMPL otherwise 155 | * @remark The MPM doesn't register the implementing hook until the 156 | * register_hooks hook is called, so modules cannot use ap_mpm_query() 157 | * until after that point. 158 | * @fn int ap_mpm_query(int query_code, int *result) 159 | */ 160 | AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result); 161 | 162 | 163 | typedef void (ap_mpm_callback_fn_t)(void *baton); 164 | 165 | /* only added support in the Event MPM.... check for APR_ENOTIMPL */ 166 | AP_DECLARE(apr_status_t) ap_mpm_register_timed_callback(apr_time_t t, 167 | ap_mpm_callback_fn_t *cbfn, 168 | void *baton); 169 | 170 | typedef enum mpm_child_status { 171 | MPM_CHILD_STARTED, 172 | MPM_CHILD_EXITED, 173 | MPM_CHILD_LOST_SLOT 174 | } mpm_child_status; 175 | 176 | /** 177 | * Allow a module to remain aware of MPM child process state changes, 178 | * along with the generation and scoreboard slot of the process changing 179 | * state. 180 | * 181 | * With some MPMs (event and worker), an active MPM child process may lose 182 | * its scoreboard slot if the child process is exiting and the scoreboard 183 | * slot is needed by other processes. When this occurs, the hook will be 184 | * called with the MPM_CHILD_LOST_SLOT state. 185 | * 186 | * @param s The main server_rec. 187 | * @param pid The id of the MPM child process. 188 | * @param gen The server generation of that child process. 189 | * @param slot The scoreboard slot number, or -1. It will be -1 when an 190 | * MPM child process exits, and that child had previously lost its 191 | * scoreboard slot. 192 | * @param state One of the mpm_child_status values. Modules should ignore 193 | * unrecognized values. 194 | */ 195 | AP_DECLARE_HOOK(void,child_status,(server_rec *s, pid_t pid, ap_generation_t gen, 196 | int slot, mpm_child_status state)) 197 | 198 | /** 199 | * Allow a module to be notified when the last child process of a generation 200 | * exits. 201 | * 202 | * @param s The main server_rec. 203 | * @param gen The server generation which is now completely finished. 204 | */ 205 | AP_DECLARE_HOOK(void,end_generation,(server_rec *s, ap_generation_t gen)) 206 | 207 | /* Defining GPROF when compiling uses the moncontrol() function to 208 | * disable gprof profiling in the parent, and enable it only for 209 | * request processing in children (or in one_process mode). It's 210 | * absolutely required to get useful gprof results under linux 211 | * because the profile itimers and such are disabled across a 212 | * fork(). It's probably useful elsewhere as well. 213 | */ 214 | #ifdef GPROF 215 | extern void moncontrol(int); 216 | #define AP_MONCONTROL(x) moncontrol(x) 217 | #else 218 | #define AP_MONCONTROL(x) 219 | #endif 220 | 221 | #ifdef AP_ENABLE_EXCEPTION_HOOK 222 | typedef struct ap_exception_info_t { 223 | int sig; 224 | pid_t pid; 225 | } ap_exception_info_t; 226 | 227 | AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei)) 228 | #endif /*AP_ENABLE_EXCEPTION_HOOK*/ 229 | 230 | #ifdef __cplusplus 231 | } 232 | #endif 233 | 234 | #endif 235 | /** @} */ 236 | --------------------------------------------------------------------------------