CS 546: Client/Server Fundamentals
Fall 2000

HW1: CGI Programming


The Creighton University home page includes a search engine for finding a student or faculty member's phone number and email address. This is an example of a Web-based client/server application. Using a Web-browser (the client), you can access a remote database of student/faculty information through a CGI program that works in conjunction with the Web server.

This assignment is the first step in developing a similar, albeit simplified, search engine. You must design and write a C++ program that reads the name (or partial name) of a person and searches for that name in a file of email addresses. Your program should then display the names and email addresses of all people whose names match. Since this program will eventually be connected to a Web server and accessed via a Web page, there are very specific requirements on the form of the input and output of your program.


Input

Input will come from cin and will consist of a single string of the form: "fieldName=fieldValue". For our purposes, the fieldName is unimportant. The fieldValue is the relevant information, representing the text to be searched for. The text in the fieldValue has the odd property that all spaces are replaced by '+' symbols. For example, the following are valid inputs:
"search=Dave" "find=Dave+R"

The first input string specifies that all names containing the letter sequence "Dave" should be reported. Note that the letter sequence may appear anywhere in a name and case is not relevant. Thus, a search for "Dave" might find "Dave Reed", "Davender Malik", and even "Chris Muldavey" (if such a person existed). The second input string requires a match for "Dave R", thus ruling out "Davender Malik" and "Chris Muldavey".


Data file

The data to be searched (names and email addresses) will be stored in a file named email.txt. Each entry in the file will consist of two lines of text, the first containing the person's name and the second containing their email address. For example:
Jim Carlson carlsn@creighton.edu Davender Malik malik@creighton.edu Premchand Nair psnair@creighton.edu Dave Reed davereed@creighton.edu Mark Wierman wierman@creighton.edu


Output

All output should go to cout. The first line of output should be the following:
Content-Type: text/html

There should then be a blank line, followed by one line of output for each matching name (with <BR> at the end). For example, given the email.txt file above, the input string "lookfor=Dave+R" should yield the following output:

Content-Type: text/html Dave Reed: davereed@creighton.edu <BR>

Similarly, the input string "find=RE" should yield the following output:

Content-Type: text/html Premchand Nair: psnair@creighton.edu <BR> Dave Reed: davereed@creighton.edu <BR>

If no name matches the input string, then a message to that effect should be displayed. For example, the input string "name=foo" should yield the following output:

Content-Type: text/html No match found <BR>


Helpful hint

Since this program involves parsing a string of text, ignoring case, and searching a data file, I strongly recommend that you consider using the <string>, <cctype> and <fstream> libraries that are standard in C++. You may refer to a C++ text or online resources for a review of the classes and functions defined in these libraries. For quick tips on these and other useful libraries, see my handout.