Using the example in the previous section, we found that one of the thresholds for Apache plug-in development is to learn about its own set of APIs. Although Apache has a detailed description of these APIs on the web, it is difficult to quickly build a system that can be run with a few scattered instructions on the air. (reprint please indicate CSDN blog for breaksoftware)
In order to achieve the most basic URL parsing and other functions, I took the "Apache Module Development Guide" a book roughly two times, in order to facilitate the rapid understanding of the Apache module programming related knowledge. As for the specific points of knowledge in the book, I do not repeat them here. But in order to make it easy for you to understand the various relevant knowledge points, I will outline a few (from the "Apache Module Development Guide" book):
- AP_ header files typically define lower-level API elements, which are accessed indirectly (although not always) by other header files.
- The HTTP_ header file defines most of the key APIs that app developers are more interested in. These APIs can also be exposed to scripting languages through some modules.
- The Util_ header file defines a higher-level API than AP_, but these APIs are rarely called directly by the application module, although this rule has exceptions to two files: Util_script.h and Util_filter.h. Where util_filter.h defines the filtering API. Then we'll use it when we talk about the filter.
- The mod_ header file defines the APIs that are implemented by the optional module. Using these APIs may raise dependencies. in the subsequent chapters we will use the API exported to the DBD framework in the Mod_dbd.h file.
- the Apr_ header file defines the APR (Apache portable Runtime) API. for Web servers, the APR library is an external library, a basic library, and is required (directly or indirectly) for any important module . This series of heads is very important.
The HTTP_ header file also has the following important header files:
- Http_config.h: Defines the configuration API, including configuration data structures, configuration vectors, and any associated accessors. It also defines its own module data structure, associated accessors, and handler function hooks. This header file is required for most modules.
- Http_core.h: Defines a variety of APIs that are derived from the Apache kernel, such as accessor functions provided by the Request_rec object.
- Http_log.h: The error log API and pipeline logs are defined. The module requires error reporting functions and related macros in this header file.
- Http_protocol.h: Includes a number of high-level function APIs to perform important operations, including all normal I/O to clients, and handling HTTP protocol related aspects such as generating the correct answer header. It also exports some of the required processing hooks that are not within the Http_request range.
We mentioned the APR library in the previous article, "Server Setup notes-compiling Apache and its plugins", which is the Apache portable runtime, the Apache Portable Runtime Library. There's also a library called Apr-util, which, as its name implies, should be based on the APR library package, providing an easy way to use the APR library. These libraries will be used frequently in our later programming. Confined to space, I do not intend to explain these libraries carefully. I also just listed the "Apache Module Development Guide" in some of the knowledge, I believe you will find a useful module in it.
Apr Library
name |
Use |
Apr_allocator |
memory allocation, internal use |
Apr_atomic |
Atomic operation |
Apr_dso |
Dynamically loading the link library |
Apr_env |
Read/Set Environment variables |
Apr_errno |
Define the wrong values, conditions, and macros |
Apr_file_info |
Properties of File system objects and Paths |
Apr_file_io |
File system input/output |
Apr_global_mutex |
Global lock |
Apr_hash |
Hash table |
Apr_inherit |
File Handle Inheritance Helper |
Apr_mmap |
Memory mapping |
Apr_network_io |
Network input/output (socket) |
Apr_proc_mutex |
Process Lock |
Apr_random |
Random number |
Apr_shm |
Shared memory |
Apr_signal |
Signal Processing |
Apr_strings |
String manipulation |
Apr_tables |
Table and Array functions |
Apr_thread_cond |
Thread condition |
Apr_thread_mutex |
Thread Lock |
Apr_thread_proc |
Thread and Process functions |
Apr_thread_rwlock |
Read/write Lock |
Apr_time |
Time/Date function |
Apr_usr |
User and Group ID service |
It can be seen that the APR library is mainly related to the system to do the encapsulation, so as to achieve portable ability.
Let's take a look at the Apr-util Library section module (excerpted from the Apache Module Development Guide):
Apr-util Library
name |
Use |
Apr_anylock |
Transparent, any lock-in package |
Apr_base64 |
BASE64 encoding |
Apr_date |
Time string parsing |
apr_dbd |
Common APIs for SQL databases |
Apr_hooks |
Hook implementation macros |
Apr_md4 |
MD4 encoding |
Apr_md5 |
MD5 encoding |
Apr_queue |
Thread-Safe FIFO queue |
Apr_sha1 |
SHA1 encoding |
Apr_strmatch |
String pattern Matching |
Apr_uri |
URI Parsing/Construction |
Apr_uuid |
User ID |
Apr_xlate |
Character set conversion (i18n) |
Apr_xml |
XML parsing |
We found that the APR and Apr-util libraries provide us with modules related to operating systems, from memory allocation to wire-control, as well as strings and XML and a few simple libraries of coding algorithms. These modules can meet our general needs, as long as we combine these APIs well, using the right, you can write Apache plug-ins.
Finally, we are going to introduce a basic component of the APR library,--APR pool. Pool is the pond, we often in the past programming in contact with the thread pool, memory pool concept. The APR pool is the one that manages the various resources in APR. As a C + + programmer, in programming we often need to deal with a variety of memory allocation and release issues-not to discuss intelligent pointers such knowledge. Without deep foundation and clear logic, memory leaks are commonplace. The APR pool is about freeing the programmer from this tangle. So we later in the Apache module programming, once involved in the application of resources, we should give priority to how to use this pool.
With the above basic knowledge, we can take a small step. I'll show you how to write an HTTP request resolution plugin in the next section.
Server Setup Notes--apache Module Development Basics