The Apache Modules Book: Application Development with Apache (Prentice Hall Open Source Software Development Series)

Overview

"Do you learn best by example and experimentation? This book is ideal. Have your favorite editor and compiler ready–you'll encounter example code you'll want to try right away. You've picked the right book–this is sure to become the de facto standard guide to writing Apache modules."

–Rich Bowen, coauthor, Apache Administrators Handbook, Apache Cookbook, and The Definitive Guide to Apache mod_rewrite

"A first-rate guide to getting the most out of Apache as a modular application platform–sure to become a must-read for any Apache programmer, from

... See more details below
Other sellers (Paperback)
  • All (9) from $39.95   
  • New (5) from $44.33   
  • Used (4) from $39.95   
The Apache Modules Book: Application Development with Apache

Available on NOOK devices and apps  
  • NOOK Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK Study

Want a NOOK? Explore Now

NOOK Book (eBook)
$27.49
BN.com price
(Save 42%)$47.99 List Price

Overview

"Do you learn best by example and experimentation? This book is ideal. Have your favorite editor and compiler ready–you'll encounter example code you'll want to try right away. You've picked the right book–this is sure to become the de facto standard guide to writing Apache modules."

–Rich Bowen, coauthor, Apache Administrators Handbook, Apache Cookbook, and The Definitive Guide to Apache mod_rewrite

"A first-rate guide to getting the most out of Apache as a modular application platform–sure to become a must-read for any Apache programmer, from beginner to experienced professional. It builds up carefully and meticulously from the absolute basics, while including chapters on everything from the popular Apache DBD Framework to best practices, security, and debugging."

–Noirin Plunkett, documentation committer to the Apache httpd project, and member of the ASF conference committee

The Only Comprehensive Guide to Developing Apache 2.x Modules and Applications

Apache is more than the world's most popular Web server–it's also an extraordinarily powerful and extensible development platform. Now, ApacheTutor.org's Nick Kew has written The Apache Modules Book, the first start-to-finish, example-rich guide for every developer who wants to make the most of Apache.

Kew begins with detailed, accessible introductions to Apache's architecture and API, then illuminates all the techniques you'll need, from request processing through code security. He brings together the best of both worlds: powerful C-based techniques for accomplishing tasks Perl or PHP can't handle, implemented with tools that deliver all the productivity you'd expect from higher-level languages. Utilizing realistic code samples, Kew introduces techniques documented in no other book-and, often, nowhere else at all.

Coverage includes

  • Using Apache Portable Runtime (APR) to streamline C development and avoid its pitfalls
  • Leveraging Apache DBD to build applications far more scalable than classic LAMP software
  • Working with the latest Apache 2.x features: filter modules, XML support, and smart proxies
  • Mastering best practices, from thread safety to multi-platform development
  • Utilizing the Apache Authentication Framework
  • Tracing and debugging problems in both Apache and your custom modules
Foreword
Preface
Acknowledgments
About the Author
Chapter 1 Applications Development with Apache
Chapter 2 The Apache Platform and Architecture
Chapter 3 The Apache Portable Runtime
Chapter 4 Programming Techniques and Caveats
Chapter 5 Writing a Content Generator
Chapter 6 Request Processing Cycle and Metadata Handlers
Chapter 7 AAA: Access, Authentication, and Authorization
Chapter 8 Filter Modules
Chapter 9 Configuration for Modules
Chapter 10 Extending the API
Chapter 11 The Apache Database Framework
Chapter 12 Module Debugging
Appendix A Apache License
Appendix B Contributor License Agreements
Appendix C Hypertext Transfer Protocol: HTTP/1.1
Index


About the Web Site

ApacheTutor.org contains code examples from the book, all designed for easy use and integration into existing applications.

Read More Show Less

Product Details

Meet the Author

Nick Kew is a leading developer of Apache applications, many of which can be found at his company's site, http://apache.webthing.com. He is a member of the Apache Web server core development team and of the Apache Software Foundation. He is active in both user and developer support, and gives tutorials and presentations at relevant conferences such as ApacheCon. He created and maintains http://www.apachetutor.org, and writes on Apache topics for a range of leading online publications.

Read More Show Less

Read an Excerpt

Introduction

The Apache Web Server (commonly known as "Apache") is, by most measures, the leading server on the Web today. For ten years it has been the unrivaled and unchallenged market leader, with approximately 70 percent of all websites running Apache. It is backed by a vibrant and active development community that operates under the umbrella of the Apache Software Foundation (ASF), and it is supported by a wide range of people and organizations, ranging from giants such as IBM down to individual consultants.

The key characteristics of Apache are its openness and diversity. The source code is completely open: Not only the current version, but also past versions and experimental development versions can be downloaded by anyone from apache.org. The development process is also open, with the exception of a few matters dealing with project management. Apache's diversity is a reflection of its user and developer communities: It is equally at home in an ultra-high-volume site that receives tens of thousands of hits per second, a complex and highly dynamic web application, a bridge to a separate application server, or a simple homepage host. The inclusion of developers from such diverse roles helps ensure that Apache continues to serve all of these widely differing environments successfully.

Yet that doesn't mean Apache follows a one-size-fits-all approach. Its highly modular architecture is built on a small core, which enables every user to tailor it to meet his or her own specific needs. Apache serves equally well as a stand-alone webserver or a component in some other system. Most importantly, it is a highly flexible and extensible applications platform.Audience and Readership

This book is intended for software developers who are working with the Apache Web Server. It is the first such book published since March 1999, and the first and (to date) only developer book that is relevant to Apache 2.

The book's primary purpose is to serve as an in-depth textbook for module developers working with Apache. The narrative and examples deal with development in C, and a working knowledge of C is assumed. However, the Apache architecture and API are shared by major scripting environments such as mod_perl and mod_python, as well as C. With the exception of Chapter 3 (on the Apache Portable Runtime), much of this book should also be relevant to developers working with scripting languages at any level more advanced than standard CGI. The current Apache release—version 2.2—is the primary focus of this book. Version 2.2.0 was released in December 2005 and, given Apache's development cycle, is likely to remain current for some time (the previous stable version 2.0 was released in April 2002). This book is also very relevant to developers who are still working with version 2.0 (the architecture and API are substantially the same across all 2.x versions), and is expected to remain valid for the foreseeable future. Organization and Scope

This book comprises twelve chapters and three appendixes.

The first chapter is a nontechnical overview that sets the scene and introduces the social, cultural, and legal background of Apache. It is followed by an extended technical introduction and overview that is spread over the next three chapters. Chapter 2 is a technical overview of the Apache architecture and API. Chapter 3 introduces the Apache Portable Runtime (APR), a semi-autonomous library that is used throughout Apache and relieves the programmer of many of the traditional burdens of C programming. Chapter 4 discusses general programming techniques appropriate to working with Apache, to ensure that your modules work well across different platforms and environments, remain secure, and don't present difficulties to systems administrators.

The central part of the book moves from the general to the specific. Chapters 5-8 present detailed discussions of various aspects of the core function of a webserver— namely, processing HTTP requests. A number of real-life modules are developed in these chapters. Chapter 5 starts with a "Hello World" example and takes you to the point where you can duplicate the function of a CGI or PHP script as a module. Chapter 6 describes the request processing cycle and working with HTTP metadata. Chapter 7 goes into more detail about identifying users and handling access control. Chapter 8 presents the filter chain and techniques for transforming incoming and outgoing data; it includes a thorough theoretical exposition and several examples. Chapter 9 completes the core topics by describing how to work with configuration data.

Chapters 10 and 11 present more advanced topics that are nevertheless essential reading for serious application developers. Chapter 10 looks at the mechanics of how the API works, and describes how a module can extend it or introduce an entirely new API or service for other modules. Chapter 11 presents the DBD framework for SQL database applications. Chapter 12 briefly discusses troubleshooting and debugging techniques.

The appendixes include Apache legal documents reproduced from the Web. They are extremely relevant to the book but were not written by the author. Appendix A is the Apache License. Appendix B includes the Contributor License Agreements, which cover issues related to intellectual property. Finally, the authoritative Hypertext Transfer Protocol (HTTP/1.1) standard (RFC 2616) is reproduced in full in Appendix C as reference documentation for developers of web applications. What the Book Does Not Cover

This book is firmly focused on applications development, so it has very little to say about systems programming for or with Apache. In particular, if your goal is to port Apache to a hitherto-unsupported platform, the book offers no more than a pointer to the areas of code you'll need to work on.

Apart from that, there is one important omission: The book limits itself to considering Apache as a server for HTTP (and HTTPS), the protocol of the Web. Although the server can be used to support other protocols, and implementations already exist for FTP, SMTP, and echo, this book has nothing to say on the subject. Nevertheless, if you are looking to implement or work with another protocol, the overview and the discussion of HTTP protocol handling should help you get oriented. Sources

Some of the modules used as examples are written especially for this book or similar instructional materials:

  • Chapter 5: mod_helloworld
  • Chapter 6: mod_choices (derived from a non-open-source module)
  • Chapter 7: mod_authnz_day
  • Chapter 8: mod_txt (written originally for http://www.apachetutor.org)

These modules can be downloaded from http://www.apachetutor.org.

All of the more substantial modules are taken from real-life sources. Except where otherwise indicated and referenced by URL, all modules are taken from either the Apache standard distribution (http://httpd.apache.org) or the author's company's site (http://apache.webthing.com). Please note that the use of any source code in this book does not imply a license to copy it other than for purely personal use. Please refer to the license terms in the original sources of each module.

Read More Show Less

Table of Contents

Foreword xxi

Preface xxiii

Acknowledgments xxvii

About the Author xxix

Chapter 1 Applications Development with Apache 1

1.1 A Brief History of the Apache Web Server 1

1.2 The Apache Software Foundation 3

1.3 The Apache Development Process 6

1.4 Apache and Intellectual Property 12

1.5 Further Reading 16

1.6 Summary 19

Chapter 2 The Apache Platform and Architecture 21

2.1 Overview 21

2.3 Multi-Processing Modules 26

2.4 Basic Concepts and Structures 29

2.5 Other Key API Components 39

2.6 Apache Configuration Basics 41

2.7 Request Processing in Apache 42

2.8 Summary 51

Chapter 3 The Apache Portable Runtime 53

3.1 APR 54

3.2 APR-UTIL 56

3.3 Basic Conventions 57

3.4 Resource Management: APR Pools 59

3.5 Selected APR Topics 68

3.6 Databases in APR/Apache 79

3.7 Summary 83

Chapter 4 Programming Techniques and Caveats 85

4.1 Apache Coding Conventions 85

4.2 Managing Module Data 88

4.3 Communicating Between Modules 90

4.4 Thread-Safe Programming Issues 92

4.5 Managing Persistent Data 93

4.6 Cross-Platform Programming Issues 99

4.7 Cross-MPM Programming Issues 101

4.8 Secure Programming Issues 106

4.9 External Dependencies and Libraries 114

4.10 Modules Written and Compiled in Other Languages 120

4.11 Summary 122

Chapter 5 Writing a Content Generator 123

5.1 The HelloWorld Module 124

5.2 The Request, the Response, and the Environment 130

5.3 The Default Handler 144

5.4 Summary 148

Chapter 6 Request Processing Cycle and Metadata Handlers 151

6.1 HTTP 152

6.2 Request Processing in Apache 155

6.3 Diverting a Request: The Internal Redirect 161

6.4 Gathering Information: Subrequests 163

6.5 Developing a Module 168

6.6 Summary 174

Chapter 7 AAA: Access, Authentication, and Authorization 177

7.1 Security 177

7.2 An Overview of AAA 180

7.3 AAA in Apache 1.x and 2.0 182

7.4 AAA in Apache 2.1/2.2 182

7.5 AAA Logic 185

7.6 Writing AAA Modules 187

7.7 Implementing a Custom Login Scheme 195

7.8 Summary 199

Chapter 8 Filter Modules 201

8.1 Input and Output Filters 202

8.2 Content, Protocol, and Connection Filters 202

8.3 Anatomy of a Filter 205

8.4 The Filter API and Objects 207

8.5 Filter Objects 208

8.6 Filter I/O 210

8.7 Smart Filtering in Apache 2.2 211

8.8 Example: Filtering Text by Direct Manipulation of Buckets 217

8.9 Complex Parsing 221

8.10 Filtering Through an Existing Parser 225

8.11 stdio-Like Filter I/O 227

8.12 Input Filters and the Pull API 230

8.13 Summary 235

Chapter 9 Configuration for Modules 237

9.1 Configuration Basics 237

9.2 Configuration Data Structs 239

9.3 Managing a Module Configuration 239

9.4 Implementing Configuration Directives 242

9.5 The Configuration Hierarchy 250

9.6 Context in Configuration Functions 255

9.7 Custom Configuration Containers 257

9.8 Alternative Configuration Methods 261

9.9 Summary 262

Chapter 10 Extending the API 263

10.1 Implementing New Functions in Apache 264

10.2 Hooks and Optional Hooks 267

10.3 The Provider API 272

10.4 Providing a Service 277

10.5 Cross-Platform API Builds 284

10.6 Summary 288

Chapter 11 The Apache Database Framework 289

11.1 The Need for a New Framework 290

11.2 The DBD Architecture 292

11.3 The apr_dbd API 292

11.4 The ap_dbd API 302

11.5 An Example Application Module: mod_authn_dbd 303

11.6 Developing a New DBD Driver 306

11.7 Summary 320

Chapter 12 Module Debugging 323

12.1 Logging for Debugging 324

12.2 Running Apache Under a Debugger 327

12.3 Special-Purpose Hooks and Modules 333

12.4 Filter Debugging 338

12.5 Summary 341

Appendix A Apache License 343

Appendix B Contributor License Agreements 349

Appendix C Hypertext Transfer Protocol: HTTP/1.1 357

Index 531

Read More Show Less

Preface

Introduction

The Apache Web Server (commonly known as "Apache") is, by most measures, the leading server on the Web today. For ten years it has been the unrivaled and unchallenged market leader, with approximately 70 percent of all websites running Apache. It is backed by a vibrant and active development community that operates under the umbrella of the Apache Software Foundation (ASF), and it is supported by a wide range of people and organizations, ranging from giants such as IBM down to individual consultants.

The key characteristics of Apache are its openness and diversity. The source code is completely open: Not only the current version, but also past versions and experimental development versions can be downloaded by anyone from apache.org. The development process is also open, with the exception of a few matters dealing with project management. Apache's diversity is a reflection of its user and developer communities: It is equally at home in an ultra-high-volume site that receives tens of thousands of hits per second, a complex and highly dynamic web application, a bridge to a separate application server, or a simple homepage host. The inclusion of developers from such diverse roles helps ensure that Apache continues to serve all of these widely differing environments successfully.

Yet that doesn't mean Apache follows a one-size-fits-all approach. Its highly modular architecture is built on a small core, which enables every user to tailor it to meet his or her own specific needs. Apache serves equally well as a stand-alone webserver or a component in some other system. Most importantly, it is a highly flexible and extensible applications platform.

Audience and Readership

This book is intended for software developers who are working with the Apache Web Server. It is the first such book published since March 1999, and the first and (to date) only developer book that is relevant to Apache 2.

The book's primary purpose is to serve as an in-depth textbook for module developers working with Apache. The narrative and examples deal with development in C, and a working knowledge of C is assumed. However, the Apache architecture and API are shared by major scripting environments such as mod_perl and mod_python, as well as C. With the exception of Chapter 3 (on the Apache Portable Runtime), much of this book should also be relevant to developers working with scripting languages at any level more advanced than standard CGI. The current Apache release—version 2.2—is the primary focus of this book. Version 2.2.0 was released in December 2005 and, given Apache's development cycle, is likely to remain current for some time (the previous stable version 2.0 was released in April 2002). This book is also very relevant to developers who are still working with version 2.0 (the architecture and API are substantially the same across all 2.x versions), and is expected to remain valid for the foreseeable future.

Organization and Scope

This book comprises twelve chapters and three appendixes.

The first chapter is a nontechnical overview that sets the scene and introduces the social, cultural, and legal background of Apache. It is followed by an extended technical introduction and overview that is spread over the next three chapters. Chapter 2 is a technical overview of the Apache architecture and API. Chapter 3 introduces the Apache Portable Runtime (APR), a semi-autonomous library that is used throughout Apache and relieves the programmer of many of the traditional burdens of C programming. Chapter 4 discusses general programming techniques appropriate to working with Apache, to ensure that your modules work well across different platforms and environments, remain secure, and don't present difficulties to systems administrators.

The central part of the book moves from the general to the specific. Chapters 5-8 present detailed discussions of various aspects of the core function of a webserver-- namely, processing HTTP requests. A number of real-life modules are developed in these chapters. Chapter 5 starts with a "Hello World" example and takes you to the point where you can duplicate the function of a CGI or PHP script as a module. Chapter 6 describes the request processing cycle and working with HTTP metadata. Chapter 7 goes into more detail about identifying users and handling access control. Chapter 8 presents the filter chain and techniques for transforming incoming and outgoing data; it includes a thorough theoretical exposition and several examples. Chapter 9 completes the core topics by describing how to work with configuration data.

Chapters 10 and 11 present more advanced topics that are nevertheless essential reading for serious application developers. Chapter 10 looks at the mechanics of how the API works, and describes how a module can extend it or introduce an entirely new API or service for other modules. Chapter 11 presents the DBD framework for SQL database applications. Chapter 12 briefly discusses troubleshooting and debugging techniques.

The appendixes include Apache legal documents reproduced from the Web. They are extremely relevant to the book but were not written by the author. Appendix A is the Apache License. Appendix B includes the Contributor License Agreements, which cover issues related to intellectual property. Finally, the authoritative Hypertext Transfer Protocol (HTTP/1.1) standard (RFC 2616) is reproduced in full in Appendix C as reference documentation for developers of web applications.

What the Book Does Not Cover

This book is firmly focused on applications development, so it has very little to say about systems programming for or with Apache. In particular, if your goal is to port Apache to a hitherto-unsupported platform, the book offers no more than a pointer to the areas of code you'll need to work on.

Apart from that, there is one important omission: The book limits itself to considering Apache as a server for HTTP (and HTTPS), the protocol of the Web. Although the server can be used to support other protocols, and implementations already exist for FTP, SMTP, and echo, this book has nothing to say on the subject. Nevertheless, if you are looking to implement or work with another protocol, the overview and the discussion of HTTP protocol handling should help you get oriented.

Sources

Some of the modules used as examples are written especially for this book or similar instructional materials:

  • Chapter 5: mod_helloworld
  • Chapter 6: mod_choices (derived from a non-open-source module)
  • Chapter 7: mod_authnz_day
  • Chapter 8: mod_txt (written originally for http://www.apachetutor.org)

These modules can be downloaded from http://www.apachetutor.org.

All of the more substantial modules are taken from real-life sources. Except where otherwise indicated and referenced by URL, all modules are taken from either the Apache standard distribution (http://httpd.apache.org) or the author's company's site (http://apache.webthing.com). Please note that the use of any source code in this book does not imply a license to copy it other than for purely personal use. Please refer to the license terms in the original sources of each module.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Anonymous

    Posted February 16, 2007

    good old C programming for Apache

    With all the buzz in recent years about various scripting languages like PHP or Perl, it is refreshing to see a book that takes an unabashed advocacy of plain old C. This is a solidly C programming book, showing how you can change a module or, more ambitiously, add a new module to Apache. It shows the conceptual framework of Apache deliberately designed to permit third party extensions. The text also describes an important practical case, where you are making a module, but want to link to a pre-existing library. In essence, your module extends both Apache and that library. Then there are the usual complications, like several modules linking to different versions of a library. Kew suggests avoiding linking in libraries, because of reasons like this. But he allows that other opinions exist. Some programmers should look at the sections on filter chains. A very useful way to understand and arrange analysis. Decomposing an intricate analysis into different filtering stages can be useful in terms of writing and debugging the code. Apache is well suited to let you take this approach. Of course, those of you programming in C should be well aware that this runs into scaling limits as the source code lengthens. Which is one of the reasons that many C programmers moved to C++ or Java. But so long as your modules are under 100 000 lines [roughly], then using C should be fine.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)