Warning: This is not for the current semester.
Note: The next assignment will be given out about a week before this one is due. You should start it early.
In the process, filter sends all of the incoming data to two monitoring file descriptors, one for the data coming from upstream and one for the data coming from downstream. It does this through the header_filter method which looks at the data and and displays some summary information. For the first three parts of the assignment, header_filter just sends everything without any processing. In Part 4, it preprocesses the information.
Input coming from fdupin should be sent to both fddownout and fdupmon. It is sent directly to fddownout, but it is sent to fdupmon with a call to header_filter using fdupmon as a parameter. Input coming from fddownin should be sent both to fdupout and fddownmon. It is sent directly to fdupout, but it is sent to fddownmon with a call to header_filter using fddownmon as a parameter. If an end-of-file is reached on fdupin, then fdupin, fdupout, fddownin, and fddownout should be closed and the message "Close upstream\n" should be sent to fdupmon via header_filter. If an end-of-file is reached on fddownin, then fddownin, fddownout, fdupin, and fdupout should be closed and a message "Close downstream\n" should be sent to fddownmon via header_filter. Do not do any error checking on the close system call. After closing the files the function should return. Do not close the other two file descriptors.
Define two buffers of size 1024, one for the upstream and one for the downstream, and pass these as the info parameter of header_filter. Pass the size of these buffers, 1024, as the last parameter to header_filter. The number 1024 should explicitly appear in your code only once so that it can be easily modified.
In six separate windows, do execute the following commands:
cat > pipe1 cat < pipe2 cat < pipe3 cat > pipe4 cat < pipe5 cat < pipe6Type into the first window. Anything typed should appear in the third and fifth windows.
Type into the fourth window. Anything typed here should appear in the second and sixth windows.
Simple Solution:Have header_filter separate its data into lines, i.e. blocks delimited by a newline. If a block is small and only contains printing characters (including tabs, carriage returns, form feeds and newlines) then output the line. Otherwise ignore the data in that block. Do not output any very long lines.
Complications:What do you do if there is not a newline at the end of the buffer passed to header_filter. One possibility is to postpone processing that data. This requires having a storage area which is persistent between calls to header_filter and which will not be corrupted by calls to header_filter which are processing a different communication.
Implement this using the storage area passed in the last two parameters to header_filter. You should also ignore all long lines even if they contain only printing characters. You must handle the following situations: