I created a socket (using C), and made it into a daemon. I now need to read from a config file in order for the program to make a decision on how to handle requests.
How do I read from the below config file, and interpret the configuration? See the config file below. I can only use open(2), read(2), etc.
* Read file char by char until you encounter '\n'. If first char is '#' or '\n', skip to next line.
* Save line to a char pointer.
* Process the line by checking for isspace() to detect the end of each column in config file.
* Save all three columns into a struct.
* Add struct to array of structs.
Problem with this idea:
After saving the first line, how do I read the next line in the config file?
Does my strategy even make sense or is it stupid? Is there maybe a better way?
# Example Configuration File for deflect:
# deflect: Daemon for HTTP Egress, Filtering, Load balancing, and Caching Trivially
# URL-prefix Disposition Host list
http://www.csun.edu/ redirected 126.96.36.199, redwing.csun.edu
http://www.csun.edu/~steve cached www.csun.edu
# Note that any URL that is not covered by any rule is transferred through the system
# without any additional processing.