CMPS-3350 Software Engineering Lab-3
The components of this lab are:
Log on to your Odin account. Change to your 3350/3 folder. Copy the files to start with for this lab... cp /home/fac/gordon/p/3350/code/lab3/* . Build the program with make. You should see a compile warning.
gordon@odin:~/3350/3$ make gcc httpget.c -Wall -o lab3 httpget.c: In function 'main': httpget.c:127:3: warning: implicit declaration of function 'close'; did you mean 'pclose'? [-Wimplicit-function-declaration] 127 | close(sock); | ^~~~~ | pclose gordon@odin:~/3350/3$
Copy your C source file to a C++ program... cp httpget.c uvlab3.cpp Add an entry in your Makefile to build your new C++ file. Create an executable file named lab3.
You are refactoring a C program into the C++ language. Refactoring means to modify source code without changing program functionality. Build your C++ program with make. Notice the warnings and errors when compiling your C++.
gordon@odin:~/3350/3$ cp httpget.c uvlab3.cpp gordon@odin:~/3350/3$ g++ uvlab3.cpp -Wall uvlab3.cpp: In function 'int main(int, char**)': uvlab3.cpp:35:14: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 35 | #define PAGE "/" | ^~~ uvlab3.cpp:58:12: note: in expansion of macro 'PAGE' 58 | page = PAGE; | ^~~~ uvlab3.cpp:86:14: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare] 86 | while(sent < strlen(get)) | ~~~~~^~~~~~~~~~~~~ uvlab3.cpp:127:3: error: 'close' was not declared in this scope; did you mean 'pclose'? 127 | close(sock); | ^~~~~ | pclose uvlab3.cpp: In function 'char* build_get_query(char*, char*)': uvlab3.cpp:170:15: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] 170 | char *tpl = "GET /%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: %s\r\n\r\n"; | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ gordon@odin:~/3350/3$
Please fix all compile warnings and errors. Enter a comment above the code related to each error or warning that you fix. Include the original code that was fixed, in the comment. For example://--------------------------------------------------------------------- //Fixed warning: deprecated conversion from string constant to 'char*' //Previous code was: // void getHost(char *hostname) //--------------------------------------------------------------------- void getHost(const char *hostname) { ... ... ...Step 4a: . Style this program using the Linux style guide. Main features... . Apply perfect K&R brace, space, and indenting. . No lines will wrap on an 80-character window. . Choose hard-tabs or spaces for indenting. Not both. . One command per LOC (line of code) . Fix all compile warnings and errors.Step 4 note: It is acceptable to fix a compile warning by using type-casting. Such as casting a function call argument.
Run your lab3 program with the following parameters...
Run lab3 with the following parameters...
Run lab3 with the following parameters...
Create a PHP program in your Odin public_html directory... It will have this URL: https://cs.csub.edu/~username/3350/uvlab3.php where username is your own Odin account name. If you have any questions about the path to your uvlab3.php, please ask about it during lab. Here is a PHP program example...
<?php
echo "This is output from my php file.";
?>
Run your lab3 program and contact your PHP file. like this... except insert your own username ./lab3 odin.cs.csub.edu /~username/3350/uvlab3.php This operation will not work because Odin server is running HTTPS. To simulate our program, we will use the curl utility. Try this: curl https://odin.cs.csub.edu/~username/3350/uvlab3.php
Use a web browser to look at your php file like this... https://www.cs.csub.edu/~username/3350/uvlab3.php
Make some minor changes to your uvlab3.php program... Allow the program to accept input: $param = $_GET['param']; Process the $param variable in the PHP file. Your new PHP program will look like this...
<?php
$param = $_GET['param'];
echo "param is: " . $param . "<br>";
if ($param == "hello") {
echo "Hello student!<br>";
} else {
$num = $param*3+4;
echo "number:" . $num . "<br>";
}
echo "<br>";
echo "<img src=\"uvdiagram.gif\"/>";
?>
Required: 1. Create a file named uvdiagram.gif for your diagram below. For image file conversion... You may use GIMP for file conversion. You may also use convert from the Odin command-prompt. example: $ convert image.jpg uvdiagram.gif Inside your <img> tag, apply a style element that will size your diagram to an appropriate size. example: style="width:800px;height:auto;" The <img> tag is in your php file.
Contact and test your PHP file like this... curl odin.cs.csub.edu/~username/3350/uvlab3.php?param=hello Then try this... curl odin.cs.csub.edu/~myname/3350/uvlab3.php?param=345 You should see the appropriate data returned.
Draw a Diagram!
Draw a Diagram to show the components of your system, and how they interact with each other. Think about the flow of data through the system. How would a user interact with the system?
. Create an original diagram.Your diagram may be a flow-chart data-flow-diagram use-case diagram etc.
Files to be collected from Odin server 3350/4/httpget.c 3350/4/uvlab3.cpp 3350/4/Makefile public_html/uvlab3.php public_html/uvdiagram.gif Copy your diagram image file to your web directory, so it will be displayed when your web page (uvlab3.php) is viewed.