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

mod

parent 3591c8ec
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
......@@ -7,13 +7,43 @@
#include <stdlib.h>
#include "client.h"
#include "http_parse.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
/*
int copy(FILE* in, FILE* out){
char* ch;
if(in && out){
while((ch = fgetc(in))!= EOF ){
fputc(ch,out);
}
}else{
//error reading
exit(1);
}
return 0;
}
int get_file_size(int fd){
struct stat sb;
if(fstat(fd,&sb)==-1){
perror("stat");
exit(1);
}
return sb.st_size;
return 0;
}
FILE* check_and_open(const char* target, const char *document_root){
return fopen(target +"/"+document_root,"r");
}
char* rewrite_target(char *target){
char* ret = strchr(target, '?');
char* rep ="";
strncpy(rep,target,atoi(ret)-1);
return rep;
}
}*/
char* fgets_or_exit(char * buffer, int size, FILE *fd){
......@@ -62,6 +92,7 @@ void send_response(FILE *client, int code, const char *reason_phrase, const char
int traitementClient(int socket_client){
/* On peut maintenant dialoguer avec le client */
char *motd="Votre requète est bonne";
printf("test");
char str[8000];
http_request request;
FILE *fd;
......@@ -77,18 +108,27 @@ int traitementClient(int socket_client){
if (request.method == HTTP_UNSUPPORTED){
send_response(fd, 405, "Method Not Allowed", "Method Not Allowed");
}else{
send_response(fd, 400, "Bad Request", "Bad request");
send_response(fd, 400, "Bad Request", "Bad request");
}
}else if (strcmp(request.target, "/") == 0){
send_response(fd, 200, "OK", motd);
}else{
send_response(fd, 404, "Not Found", "Not Found");
}
//partie 7
//partie 7/*
char* absolute_path = rewrite_target(request.target);
fprintf(fd,"test - - - - - - - - \n%s",absolute_path);
//--- les printf ne fonctionnent pas ;(
printf("test - - - - - - - - \n%s",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
}*/
fclose(fd);
return 0;
}
No preview for this file type
No preview for this file type
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