Skip to content

Repository files navigation

ApacheConfigParser

A simple parser for Apache HTTP server config files.

Build status


This project was ported from Stackify's Java-based apache-config package.


Overview

The parser iterates through the config file and builds out a tree of the various settings.

Usage

The code below parses the httpd.conf file and outputs the contents of the ServerName directive in the main body of the file in addition to the ServerName directives within the VirtualHost tags.

httpd.conf:

Listen 80
ServerName localhost:80
DocumentRoot "C:/xampp/htdocs"
<VirtualHost *:443>
ServerAdmin webmaster@foo.com
ServerName www.foo.com
DocumentRoot /home/www/www.foo.com/htdocs/
# Logfiles
ErrorLog /home/www/www.foo.com/logs/error.log
CustomLog /home/www/www.foo.com/logs/access.log combined
</VirtualHost>
<VirtualHost *>
ServerAdmin webmaster@bar.com
ServerName www.bar.com
DocumentRoot /home/www/www.bar.com/htdocs/
# Logfiles
ErrorLog /home/www/www.bar.com/logs/error.log
CustomLog /home/www/www.bar.com/logs/access.log combined
</VirtualHost>

Code:

varhttpdConfPath=@"C:\xampp\apache\conf\httpd.conf";ConfigParserp=newConfigParser();ConfigNoderoot=p.Parse(httpdConfPath);foreach(varchild1inroot.GetChildren()){if(child1.GetName().Equals("ServerName"))Console.WriteLine(child1.GetContent());if(child1.GetName().Equals("VirtualHost")){foreach(varchild2inchild1.GetChildren()){if(child2.GetName().Equals("ServerName")){Console.WriteLine(child2.GetContent());}}}}

Output:

localhost:80
www.foo.com
www.bar.com

About

A simple parser for Apache HTTP server config files.

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages