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 @@
#include <unistd.h>
/*int copy(FILE* in, FILE* out){
char* ch;
int copy(FILE* in, FILE* out){
int ch;
if(in && out){
while((ch = fgetc(in))!= EOF ){
while((ch =( fgetc(in))!= EOF) ){
fputc(ch,out);
}
}else{
......@@ -35,8 +35,12 @@ int get_file_size(int fd){
}
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* ret = strrchr(target, '?');
......@@ -117,22 +121,23 @@ int traitementClient(int socket_client){
}else if (strcmp(request.target, "/test?aled") == 0){
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{
send_response(fd, 404, "Not Found", "Not Found");
}
fflush(fd);
fflush(fd);
//partie 7
char* absolute_path = rewrite_target(request.target);
char* absolute_path = rewrite_target(request.target);
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);
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.
Finish editing this message first!
Please register or to comment