Compare commits
4 Commits
7c17fcadcf
...
5b61ab14c0
Author | SHA1 | Date | |
---|---|---|---|
5b61ab14c0 | |||
f8b64d9afa | |||
2e217aee6d | |||
d50e4c7036 |
2
Makefile
2
Makefile
@@ -1,4 +1,4 @@
|
|||||||
main: main.c
|
main: main.c
|
||||||
gcc main.c -o main -L/usr/lib -lXm -lXt -lX11 -l:libXmHTML.so.1.1.10
|
gcc main.c url_manipulation.c easysock.c -o main -L/usr/lib -lXm -lXt -lX11 -l:libXmHTML.so.1.1.10
|
||||||
|
|
||||||
|
|
||||||
|
11
main.c
11
main.c
@@ -79,12 +79,17 @@ void testFunc(Widget w, XtPointer client_data, XmPushButtonCallbackStruct *callb
|
|||||||
and make the connection for us. It returns the socket, so that the HTTP request can be made.
|
and make the connection for us. It returns the socket, so that the HTTP request can be made.
|
||||||
First parameter is IP version - set to -1 because we don't know yet if the address is IPv4 or IPv6. */
|
First parameter is IP version - set to -1 because we don't know yet if the address is IPv4 or IPv6. */
|
||||||
|
|
||||||
|
char* request = "GET /~fdc/sample.html HTTP/1.1\nHost: www.columbia.edu\n\n"
|
||||||
|
char* response = malloc(sizeof(char) * 5000);
|
||||||
|
|
||||||
struct sockaddr* address_struct;
|
struct sockaddr* address_struct;
|
||||||
int remote_socket = create_remote(-1,'T',url_to_hostname(url),port,address_struct);
|
int remote_socket = create_remote(-1,'T',url_to_hostname(url),port,address_struct);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
XmHTMLTextSetString(result_widget,"");
|
send(remote_socket,request,strlen(request),0);
|
||||||
|
|
||||||
|
recv(remote_socket,response,sizeof(response),0);
|
||||||
|
|
||||||
|
XmHTMLTextSetString(result_widget,response);
|
||||||
// printf("%d\n",val);
|
// printf("%d\n",val);
|
||||||
// exit(2);
|
// exit(2);
|
||||||
}
|
}
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#define DEFAULT_PATH "/index.html"
|
#define DEFAULT_PATH "/"
|
||||||
|
|
||||||
char* url_to_proto(char* url) {
|
char* url_to_proto(char* url) {
|
||||||
size_t length = strlen(url);
|
size_t length = strlen(url);
|
||||||
@@ -20,7 +20,8 @@ char* url_to_proto(char* url) {
|
|||||||
char* url_to_hostname(char* url) {
|
char* url_to_hostname(char* url) {
|
||||||
/* This function relies on a hack-y assumption: that, given a string
|
/* This function relies on a hack-y assumption: that, given a string
|
||||||
that represents a URL (e.g. https://www.example.com/index.html), the length of the host portion
|
that represents a URL (e.g. https://www.example.com/index.html), the length of the host portion
|
||||||
of the address is the distance between the second slash (:/'/') and the third ('/'index.html). */
|
of the address is the distance between the second slash (:/'/') and the third ('/'index.html),
|
||||||
|
or the second slash and the end of the string, if the path isn't present. */
|
||||||
|
|
||||||
size_t length = strlen(url);
|
size_t length = strlen(url);
|
||||||
char* protocol = url_to_proto(url);
|
char* protocol = url_to_proto(url);
|
||||||
@@ -41,6 +42,11 @@ char* url_to_hostname(char* url) {
|
|||||||
sentinel = i;
|
sentinel = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (sentinel == 0) { /* If there are no more slashes */
|
||||||
|
return temp_substring;
|
||||||
|
}
|
||||||
strncpy(to_return,temp_substring,sentinel);
|
strncpy(to_return,temp_substring,sentinel);
|
||||||
free(temp_substring);
|
free(temp_substring);
|
||||||
return to_return;
|
return to_return;
|
||||||
@@ -62,8 +68,12 @@ char* url_to_path(char* url) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sentinel == 0) {
|
if (num_slashes < 3 || sentinel == str_len) { /* If we don't find the requisite number of slashes after
|
||||||
to_return = DEFAULT_PATH;
|
parsing the string OR the third slash is at the end of the string
|
||||||
|
("e.g. www.example.com/")... */
|
||||||
|
|
||||||
|
strcpy(to_return,DEFAULT_PATH); /* ...Then return the default path - "/" */
|
||||||
|
return to_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Copy all bytes of the string, starting from the third slash */
|
/* Copy all bytes of the string, starting from the third slash */
|
||||||
|
Reference in New Issue
Block a user