cs3157
spring 2005
homework assignment #3
due tue apr 19, by 6AM (electronic submission)

last updated: Sun Apr 10 19:20:33 EDT 2005 (sklar)

 

assignment description.

This homework assignment is the third part of your four-part homework project. This hw3 will be written in C and will implement users entering reviews for movies and looking at reviews that other users enter. You'll also create a makefile.

NOTE that beginning with this assignment, we will MERGE everyone's movies.dat file. So keep that in mind when you are submitting -- whatever test entries are in your data file may be seen by the whole class...

This assignment is worth 10 points. Distribution of points is indicated below.

IMPORTANT NOTES:

WHAT ARE THOSE FUNKY CGI CHARACTERS?
You may have noticed this already, but when you enter certain characters in an HTML form (like spaces, quotes, and other punctuation marks), these characters are passed into CGI scripts and programs as funky codes. I've posted a table of the codes here. In the lab this week, we'll write some code to handle these, which you should include when you complete this assignment.

 

HERE ARE THE STEPS FOR HW3:

  1. timesheet (0.5 points)

    Download the timesheet and fill in predictions of how long it will take you to do each task associated with this assignment. Then, as you are working on the assignment, keep track of how long it actually takes you.

    You will not lose points for the values you put on this timesheet. It is for your benefit -- so you can see how long you think it will take you to do things, and how long it really takes you. You will not be marked on the content of the timesheet -- only that you have completed and submitted it.

     

  2. streamline C portion of hw2. (1 point)

    In hw2, you created: user.h, login.c and register.c. Because both login.c and register.c use the data structure defined in user.h, it is likely that there are functions that both C programs may use. Instead of repeating code in both login.c and register.c, it is better from a programming standpoint to create a third file, say user.c, that contains any functions which operate on the data structure you've defined in user.h. Then you can link user.c with register.c to create register.cgi, and you can link user.c with login.c to create login.cgi. The header file, user.h, should contain only the data structure definition (i.e., typedef struct...). It should NOT contain any actual function definitions or variable declarations!! It should also contain the function prototypes of all the functions which are in user.c. Thus user.h should be included in all three C files.

    For this step, create user.c and modify login.c, register.c and user.h to conform to the rules stated above.

    ALSO make sure that register.c makes a check that the new user is unique before appending the username to the data file. This was implied in hw2, but not everyone did it. Make sure you do it here (otherwise you'll lose 0.5 points on this section)!

     

  3. makefile (1 point)

    Create a makefile that has several targets:

    • login.cgi
    • register.cgi
    • review.cgi
    • all
    • clean

    Based on what you did in the previous step, make sure that your makefile explicitly defines login.cgi as being dependent on login.c, user.c and user.h and register.cgi as being dependent on register.c, user.c and user.h,

    The review.cgi target is something you'll write in the steps below.

    The all target should build all the C and C++ cgi programs.

    The clean target should remove any object files (*.o).
    WARNING!! Don't clean the *.cgi files!!! Otherwise you'll lose your cgi programs that are written in PERL!!!

     

  4. update your site map (0.5 points)

    In this assignment, you'll be adding two more functions to the web site:

    1. the ability to see any reviews for a movie that have been previously entered.
    2. the ability to enter reviews for a movie, and

    Update the site map in your README file (from hw2) to illustrate how you are fitting these new functionalities into your site.

     

  5. modify list.cgi (1 point)

    Modify your PERL list.cgi, adding two buttons or links (you decide how you want to do this), one for each of the two new functionalities. That is, for each movie, there should be a button or link that says something like "see reviews for this movie" and a button or link that says "enter a review for this movie".

    These buttons or links will each invoke review.cgi, which is described below. You'll find that you will need to pass some information from your list.cgi program into review.cgi (such as the user's name and the ID of the movie associated with the button or link that the user clicked on). You can do this using either GET or POST methods or in the URL -- that design decision is up to you.

    NOTE that the "enter review" button or link should only appear when a user is logged into the site!

     

  6. review.cgi (6 points total)

    Here, you need to write a C program called review.c (to be compiled into review.cgi) which will be the action method activated when the new buttons or links are clicked on the list.cgi indicating that the user wants to enter a review or see the reviews for a particular movie.

    Reviews must be stored as follows:

    • For a given movie, all the reviews will be stored in text files in the local working directory. There will be one review file that corresponds to each movie in the database. The review file must be named the same as the movie's unique identifier. Remember from hw1 that this was specified as follows: Note that the unique identifier is your UNI (CS username) followed by a hyphen (-) followed by a number (1-N), where N is the number of movies you're entered.

    • The format of each review file will be a series of formatted entries that look like this:
      BEGIN REVIEW
      USER=jennifer
      REVIEW=i love this movie!
      END REVIEW
      BEGIN REVIEW
      USER=alex
      REVIEW=i hate this movie!
      END REVIEW
      
      In other words, each entry begins with BEGIN REVIEW on a line by itself. The next line is USER= followed by the username of the user who entered the review. The next line is REVIEW= followed by the review itself. The final line of each entry should say END REVIEW.

    It is VERY IMPORTANT that you follow these formatting instructions -- since we will now be sharing the movies database, using a standard format means that other people will be able to read your reviews and you'll be able to read other peoples'.

    The review program can be invoked in one of three "modes":

    • see: (2 points)
      In the see mode, the review program must open the review data file corresponding to the movie where the user pressed the "see reviews" button or link.
      So you must write a function that will read the review file and parse it into the USER and REVIEW components of each review. Remember that there may be more than one review in the file!
      You must also write a function that will display the reviews in the browser in some friendly and readable way (how is up to you).
      Finally, give the user a button or link to return to the movies list page.

    • enter: (2 points)
      In the enter mode, the review program must let the user enter a review for the movie corresponding to the "enter review" button or link that the user pressed. The review program must display an HTML form with a textarea for the user to enter their review. When the user clicks on the submit button for this form, the review.cgi program will be invoked again -- this time in the save mode.

    • save: (2 points)
      In the save mode, the review program must take the review that was entered on the form (from when the program ran in enter mode) and APPEND the review to the reviews data file for the current movie. Remember, as above, THE REVIEW FILE MUST BE NAMED THE SAME AS THE MOVIE'S UNIQUE IDENTIFIER and YOU MUST FOLLOW THE FORMATTING INSTRUCTIONS FOR THE CONTENT OF THE REVIEW DATA FILE!!

      NOTE that you should handle the funky CGI characters elegantly here (as described at the top of this page). You'll deal with this aspect in lab7 (on april 6), but make sure you also include the functionality here.

    NOTE that my instructions are less explicit than in the past, in terms of what exact functions to write. You're ready to make some of these design decisions on your own :-)

    ALSO NOTE that I expect very clean, commented code. It should be nicely indented in a consistent way. Functions, variables and data structures should have meaningful, descriptive names. Ugly, unreadable, undecipherable code will cost you 1 point of this portion of the assignment. In other words, even if your code is working perfectly, you'll lose 1 point out of the 6 for this step if our code is utterly undecipherable. OUCH!!

     

  7. submit.

    Just like with the labs, you need to submit your homework electronically. Make sure that you have followed the file naming specifications listed above (case included!) Failure to follow do so will result in 10% off the assignment grade -- ouch!

    You need to submit: timesheet.txt, README, user.h, user.c, register.c, login.c, review.c, makefile, users.dat, register.html, login.html, index.c, index.html, about.html, list.cgi, your movies.dat, any review files you've created for the movies in your movies.dat, any image files that your movies.dat file references locally, and any other files we'll need to run your assignment.

    • Log in to a CS cluster machine by running:
      bash# ssh cluster.cs.columbia.edu
      

    • From your hw3 working directory (on cluster), run the submit-hw script:
      bash# ~cs3157/bin/submit-hw 3
      

    • Answer the script's questions as they come up. You will receive an email shortly after the script is done running --- on your CS account!