Skip to content
Snippets Groups Projects
Commit 917e5fa2 authored by Romain Gabet's avatar Romain Gabet :speech_balloon:
Browse files

nnnooonnn

parent e5a92126
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
...@@ -12,10 +12,10 @@ ...@@ -12,10 +12,10 @@
#include <unistd.h> #include <unistd.h>
/*int copy(FILE* in, FILE* out){ int copy(FILE* in, FILE* out){
char* ch; int ch;
if(in && out){ if(in && out){
while((ch = fgetc(in))!= EOF ){ while((ch =( fgetc(in))!= EOF) ){
fputc(ch,out); fputc(ch,out);
} }
}else{ }else{
...@@ -35,8 +35,12 @@ int get_file_size(int fd){ ...@@ -35,8 +35,12 @@ int get_file_size(int fd){
} }
FILE* check_and_open(const char* target, const char *document_root){ FILE* check_and_open(const char* target, const char *document_root){
return fopen(target +"/"+document_root,"r"); char*tmp="";
}*/ strcat(tmp,target);
strcat(tmp,"/");
strcat(tmp,document_root);
return fopen(tmp,"r");
}
char* rewrite_target(char *target){ char* rewrite_target(char *target){
char* ret = strrchr(target, '?'); char* ret = strrchr(target, '?');
...@@ -117,15 +121,6 @@ int traitementClient(int socket_client){ ...@@ -117,15 +121,6 @@ int traitementClient(int socket_client){
}else if (strcmp(request.target, "/test?aled") == 0){ }else if (strcmp(request.target, "/test?aled") == 0){
send_response(fd, 200, "OK", motd); send_response(fd, 200, "OK", motd);
//--- //---
/* FILE* fichier = check_and_open(absolute_path, "document.txt");
if(fichier == NULL){
send_response(fd, 404, "Not Found", "Not Found");
}
int size = get_file_size(fileno(fichier));
if(copy(fichier,fd))==-1){
//error
}*/
}else{ }else{
send_response(fd, 404, "Not Found", "Not Found"); send_response(fd, 404, "Not Found", "Not Found");
} }
...@@ -133,6 +128,16 @@ int traitementClient(int socket_client){ ...@@ -133,6 +128,16 @@ int traitementClient(int socket_client){
//partie 7 //partie 7
char* absolute_path = rewrite_target(request.target); char* absolute_path = rewrite_target(request.target);
printf("test - - - - - - - - %s\n",absolute_path); printf("test - - - - - - - - %s\n",absolute_path);
FILE* fichier = check_and_open(absolute_path, "document.txt");
if(fichier == NULL){
send_response(fd, 404, "Not Found", "Not Found");
}
int size = get_file_size(fileno(fichier));
if(copy(fichier,fd)==-1){
//error
}
fprintf(fd,"Size : %d",size);
fclose(fd); fclose(fd);
return 0; return 0;
} }
No preview for this file type
No preview for this file type
testons
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment