Commit d8496bbd authored by Matthew Burket's avatar Matthew Burket

The basics seem to be working

parent cd40899e
......@@ -12,8 +12,12 @@
</component>
<component name="ChangeListManager">
<list default="true" id="36048fb3-fc75-499f-9004-4a458a9d082e" name="Default" comment="">
<change beforePath="$PROJECT_DIR$/buffer.c" beforeDir="false" afterPath="$PROJECT_DIR$/buffer.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/urlParse.c" afterDir="false" />
<change afterPath="$PROJECT_DIR$/urlParse.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/connect.c" beforeDir="false" afterPath="$PROJECT_DIR$/connect.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.c" beforeDir="false" afterPath="$PROJECT_DIR$/main.c" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/cmake-build-debug/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
......@@ -29,8 +33,8 @@
<file leaf-file-name="buffer.c" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/buffer.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="435">
<caret line="41" column="39" selection-start-line="41" selection-start-column="39" selection-end-line="41" selection-end-column="39" />
<state relative-caret-position="180">
<caret line="10" column="20" selection-start-line="10" selection-start-column="20" selection-end-line="10" selection-end-column="20" />
<folding>
<element signature="e#40#59#0" expanded="true" />
</folding>
......@@ -38,11 +42,11 @@
</provider>
</entry>
</file>
<file leaf-file-name="connect.c" pinned="false" current-in-tab="false">
<file leaf-file-name="connect.c" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/connect.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="370">
<caret line="71" column="27" selection-start-line="71" selection-start-column="27" selection-end-line="71" selection-end-column="27" />
<state relative-caret-position="444">
<caret line="75" column="27" selection-start-line="75" selection-start-column="27" selection-end-line="75" selection-end-column="27" />
<folding>
<element signature="e#42#62#0" expanded="true" />
</folding>
......@@ -50,11 +54,11 @@
</provider>
</entry>
</file>
<file leaf-file-name=",gitignore" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/,gitignore">
<file leaf-file-name="urlParse.h" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/urlParse.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="334">
<caret line="84" column="18" selection-start-line="84" selection-start-column="18" selection-end-line="84" selection-end-column="18" />
<state relative-caret-position="108">
<caret line="6" column="15" selection-start-line="6" selection-start-column="4" selection-end-line="6" selection-end-column="15" />
</state>
</provider>
</entry>
......@@ -62,8 +66,8 @@
<file leaf-file-name="main.c" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/main.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="703">
<caret line="57" selection-start-line="57" selection-end-line="57" />
<state relative-caret-position="742">
<caret line="75" column="23" selection-start-line="75" selection-start-column="8" selection-end-line="75" selection-end-column="23" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
......@@ -71,18 +75,6 @@
</provider>
</entry>
</file>
<file leaf-file-name="connect.h" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/connect.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
<caret line="15" column="22" selection-start-line="15" selection-start-column="22" selection-end-line="15" selection-end-column="22" />
<folding>
<element signature="e#124#142#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FindInProjectRecents">
......@@ -105,10 +97,12 @@
<option value="$PROJECT_DIR$/CMakeLists.txt" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/connect.h" />
<option value="$PROJECT_DIR$/main.c" />
<option value="$PROJECT_DIR$/connect.c" />
<option value="$PROJECT_DIR$/buffer.c" />
<option value="$PROJECT_DIR$/,gitignore" />
<option value="$PROJECT_DIR$/urlParse.c" />
<option value="$PROJECT_DIR$/urlParse.h" />
<option value="$PROJECT_DIR$/main.c" />
<option value="$PROJECT_DIR$/connect.c" />
</list>
</option>
</component>
......@@ -166,8 +160,8 @@
</option>
</component>
<component name="RunManager" selected="Application.http_client">
<configuration name="Build All" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="coms352_project2_part1" RUN_TARGET_NAME="coms352_project2_part1" EXPLICIT_BUILD_TARGET_NAME="all" />
<configuration name="http_client" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="www.cs.iastate.edu" PASS_PARENT_ENVS_2="true" PROJECT_NAME="coms352_project2_part1" TARGET_NAME="http_client" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="coms352_project2_part1" RUN_TARGET_NAME="http_client" />
<configuration name="Build All" type="CMakeRunConfiguration" factoryName="Application" PASS_PARENT_ENVS_2="true" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="coms352_project2_part1" RUN_TARGET_NAME="http_client" EXPLICIT_BUILD_TARGET_NAME="all" />
<configuration name="http_client" type="CMakeRunConfiguration" factoryName="Application" PROGRAM_PARAMS="www.google.com" PASS_PARENT_ENVS_2="true" PROJECT_NAME="coms352_project2_part1" TARGET_NAME="http_client" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="coms352_project2_part1" RUN_TARGET_NAME="http_client" />
<list>
<item itemvalue="Application.Build All" />
<item itemvalue="Application.http_client" />
......@@ -186,35 +180,36 @@
<workItem from="1520536552677" duration="1731000" />
<workItem from="1522346739296" duration="3244000" />
<workItem from="1523115745573" duration="9472000" />
<workItem from="1523128673229" duration="3157000" />
<workItem from="1523128673229" duration="5207000" />
<workItem from="1523307294356" duration="902000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="17604000" />
<option name="totallyTimeSpent" value="20556000" />
</component>
<component name="ToolWindowManager">
<frame x="0" y="27" width="2560" height="1573" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.12066246" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.12066246" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Messages" order="7" weight="0.33053222" />
<window_info anchor="bottom" id="CMake" order="7" />
<window_info anchor="bottom" id="Event Log" order="7" side_tool="true" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32843137" />
<window_info anchor="bottom" id="Version Control" order="7" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Terminal" order="7" visible="true" weight="0.32983193" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info active="true" anchor="bottom" id="Terminal" order="7" visible="true" weight="0.33053222" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.39985994" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Find" order="1" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
......@@ -233,31 +228,21 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/connect.c</url>
<line>112</line>
<option name="timeStamp" value="8" />
</line-breakpoint>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/connect.c</url>
<line>105</line>
<option name="timeStamp" value="16" />
<line>93</line>
<option name="timeStamp" value="20" />
</line-breakpoint>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/connect.c</url>
<line>102</line>
<option name="timeStamp" value="17" />
<line>115</line>
<option name="timeStamp" value="22" />
</line-breakpoint>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/connect.c</url>
<line>93</line>
<option name="timeStamp" value="20" />
</line-breakpoint>
<line-breakpoint enabled="true" type="com.jetbrains.cidr.execution.debugger.OCBreakpointType">
<url>file://$PROJECT_DIR$/main.c</url>
<line>57</line>
<option name="timeStamp" value="21" />
<line>103</line>
<option name="timeStamp" value="24" />
</line-breakpoint>
</breakpoints>
<option name="time" value="22" />
<option name="time" value="25" />
</breakpoint-manager>
</component>
<component name="debuggerHistoryManager">
......@@ -280,6 +265,36 @@
</expressions>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/buffer.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="10" column="20" selection-start-line="10" selection-start-column="20" selection-end-line="10" selection-end-column="20" />
<folding>
<element signature="e#40#59#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/connect.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="144">
<caret line="8" column="3" lean-forward="true" selection-start-line="8" selection-start-column="3" selection-end-line="8" selection-end-column="3" />
<folding>
<element signature="e#42#62#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1296">
<caret line="72" column="44" selection-start-line="72" selection-start-column="44" selection-end-line="72" selection-end-column="44" />
<folding>
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/buffer.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="630">
......@@ -423,6 +438,13 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/,gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="334">
<caret line="84" column="18" selection-start-line="84" selection-start-column="18" selection-end-line="84" selection-end-column="18" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/connect.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="270">
......@@ -433,40 +455,50 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.c">
<entry file="file://$PROJECT_DIR$/buffer.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="703">
<caret line="57" selection-start-line="57" selection-end-line="57" />
<state relative-caret-position="180">
<caret line="10" column="20" selection-start-line="10" selection-start-column="20" selection-end-line="10" selection-end-column="20" />
<folding>
<element signature="e#0#19#0" expanded="true" />
<element signature="e#40#59#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/buffer.c">
<entry file="file://$PROJECT_DIR$/urlParse.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="435">
<caret line="41" column="39" selection-start-line="41" selection-start-column="39" selection-end-line="41" selection-end-column="39" />
<state relative-caret-position="288">
<caret line="16" selection-start-line="16" selection-end-line="18" selection-end-column="44" />
<folding>
<element signature="e#40#59#0" expanded="true" />
<element signature="e#40#61#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/connect.c">
<entry file="file://$PROJECT_DIR$/urlParse.h">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="370">
<caret line="71" column="27" selection-start-line="71" selection-start-column="27" selection-end-line="71" selection-end-column="27" />
<state relative-caret-position="108">
<caret line="6" column="15" selection-start-line="6" selection-start-column="4" selection-end-line="6" selection-end-column="15" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="742">
<caret line="75" column="23" selection-start-line="75" selection-start-column="8" selection-end-line="75" selection-end-column="23" />
<folding>
<element signature="e#42#62#0" expanded="true" />
<element signature="e#0#19#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/,gitignore">
<entry file="file://$PROJECT_DIR$/connect.c">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="334">
<caret line="84" column="18" selection-start-line="84" selection-start-column="18" selection-end-line="84" selection-end-column="18" />
<state relative-caret-position="444">
<caret line="75" column="27" selection-start-line="75" selection-start-column="27" selection-end-line="75" selection-end-column="27" />
<folding>
<element signature="e#42#62#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
......
......@@ -3,4 +3,4 @@ project(coms352_project2_part1 C)
set(CMAKE_C_STANDARD 11)
add_executable(http_client main.c connect.c connect.h buffer.c buffer.h)
\ No newline at end of file
add_executable(http_client main.c connect.c connect.h buffer.c buffer.h urlParse.c urlParse.h)
\ No newline at end of file
......@@ -73,9 +73,9 @@ int execate_request(int socketfd, char *hostname, char *path, int head) {
// Figure out the verb
char *firstLine;
if (head) {
firstLine = "HEAD ";
firstLine = "HEAD /";
} else {
firstLine = "GET ";
firstLine = "GET /";
}
// Building verb part
appendBuffer(&request, firstLine, strlen(firstLine));
......@@ -114,7 +114,7 @@ int get_result(int socketfd, GrowthBuffer *recvBuff, int recvBuffSize) {
}
if (bytesRecv < RECV_SIZE) {
return 0;
return 0;
}
}
}
\ No newline at end of file
......@@ -4,12 +4,16 @@
#include <ctype.h>
#include "connect.h"
#include "buffer.h"
#include "urlParse.h"
/// Main method for the program
///
/// \param argc
/// \param argv
/// \return
void show_help_exit(char *argv);
int main (int argc, char **argv) {
int header_only = 0;
int timeDelta = 0;
......@@ -20,6 +24,10 @@ int main (int argc, char **argv) {
opterr = 0;
if (argc < 2) {
show_help_exit(argv[0]);
}
// getopts section based on
// https://www.gnu.org/software/libc/manual/html_node/Example-of-Getopt.html#Example-of-Getopt
while ((c = getopt(argc, argv, "hd:")) != -1)
......@@ -52,12 +60,31 @@ int main (int argc, char **argv) {
for (index = optind; index < argc; index++)
printf("Non-option argument %s\n", argv[index]);
printf("\noptind: %s\n", (argv[optind]));
if (argv[optind] == NULL) {
show_help_exit(argv[0]);
}
init_connection(argv[optind], 80, &addressInfo);
char *host = malloc(sizeof(char) * 256);
int port = 80;
char *page = malloc(sizeof(char) * 256);
getUrlParts(argv[optind], &host, &port, &page);
printf("\nhost: %s\n", host);
init_connection(host, 80, &addressInfo);
int sockfd = establish_connect(addressInfo);
execate_request(sockfd, "www.cs.iastate.edu", "/index.html", 0);
if (header_only == 1) {
execate_request(sockfd, host, page, 1);
} else {
execate_request(sockfd, host, page, 0);
}
GrowthBuffer gp;
initBuffer(&gp, 50);
get_result(sockfd, &gp, RECV_SIZE);
printf("%s", gp.array);
}
void show_help_exit(char *argv) {
fprintf(stderr, "\n%s [–h] [–d <time-interval>] <URL>", argv);
exit(EXIT_FAILURE);
}
\ No newline at end of file
//
// Created by mburket on 4/9/18.
//
#include "urlParse.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/// Gets the parts of a url from a string
///
/// \param url the full string of the url
/// \param rhost return host
/// \param rport return port
/// \param rpage return
/// \return 0 if success
int getUrlParts(char *url, char **rhost, int *rport, char **rpage) {
char *host = malloc(sizeof(char) * 256);
int port = 80;
char *page = malloc(sizeof(char) * 256);
for (int i = 0; i < 100; i++) {
page[0] = '\0';
}
// I know this bad
// But it works somewhat
// Idea from https://stackoverflow.com/a/726214
if (sscanf(url, "http://%99[^:]:%99d/%99[^\n]", host, &port, page) == 3) {
} else {
sscanf(url, "http://%99[^/]/%99[^\n]", host, page);
}
strcpy(*rhost, host);
*rport = port;
strcpy(*rpage, page);
free(page);
free(host);
return 0;
}
//
// Created by mburket on 4/9/18.
//
#ifndef COMS352_PROJECT2_PART1_URLPARSE_H
#define COMS352_PROJECT2_PART1_URLPARSE_H
int getUrlParts(char *url, char **rhost, int *rport, char **rpage);
#endif //COMS352_PROJECT2_PART1_URLPARSE_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment