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

ajout p7 en commentaire

parents ddf5a375 6f6caf9a
No related branches found
No related tags found
No related merge requests found
CFLAGS=-Wall -Wextra -Werror -g
LIB=libhttp_parse.a
SRC=$(wildcard *.c)
OBJS=$(SRC:.c=.o)
HDR=$(wildcard *.h)
$(LIB): $(OBJS)
ar rs $@ $^
ranlib $@
makefile.dep: $(SRC) $(HDR)
$(CC) $(CFLAGS) -MM $(SRC) > $@
.PHONY: clean mrproper
clean:
$(RM) $(OBJS)
mrproper: clean
$(RM) $(LIB)
include makefile.dep
\ No newline at end of file
File added
http_parse.o: http_parse.c http_parse.h
File added
...@@ -39,10 +39,11 @@ FILE* check_and_open(const char* target, const char *document_root){ ...@@ -39,10 +39,11 @@ FILE* check_and_open(const char* target, const char *document_root){
}*/ }*/
char* rewrite_target(char *target){ char* rewrite_target(char *target){
char* ret = strchr(target, '?'); char* ret = strrchr(target, '?');
char* rep =""; char* rep = malloc(strlen(target)*sizeof(char));
if (ret!= NULL){ if (ret!= NULL){
strncpy(rep,target,atoi(ret)-1); size_t i = (int)(strlen(target)-strlen(ret));
rep = strncpy(rep,target,i);
} }
return rep; return rep;
} }
...@@ -81,14 +82,12 @@ void send_status(FILE *client, int code, const char *reason_phrase){ ...@@ -81,14 +82,12 @@ void send_status(FILE *client, int code, const char *reason_phrase){
} }
void send_response(FILE *client, int code, const char *reason_phrase, const char *message_body){ void send_response(FILE *client, int code, const char *reason_phrase, const char *message_body){
fprintf(client, "entree dans send_response\r\n");
send_status(client,code,reason_phrase); send_status(client,code,reason_phrase);
//transmet la réponse complète (la suite) //transmet la réponse complète (la suite)
fprintf(client,"Content-Lenght: %u\r\n",(unsigned int)strlen(message_body)); fprintf(client,"Content-Lenght: %u\r\n",(unsigned int)strlen(message_body));
fprintf(client,"\r\n"); fprintf(client,"\r\n");
fprintf(client,"%s\r\n",message_body); fprintf(client,"%s\r\n",message_body);
fprintf(client, "sortie de send_response\r\n"); fflush(client);
fflush(client);
} }
...@@ -109,25 +108,14 @@ int traitementClient(int socket_client){ ...@@ -109,25 +108,14 @@ int traitementClient(int socket_client){
fgets_or_exit(str,8000,fd); fgets_or_exit(str,8000,fd);
int parse_ret = parse_http_request(str,&request); int parse_ret = parse_http_request(str,&request);
skip_headers(fd); skip_headers(fd);
fprintf(fd, "avant if parse_ret\n");
if (parse_ret == -1) { if (parse_ret == -1) {
if (request.method == HTTP_UNSUPPORTED){ if (request.method == HTTP_UNSUPPORTED){
send_response(fd, 405, "Method Not Allowed", "Method Not Allowed"); send_response(fd, 405, "Method Not Allowed", "Method Not Allowed");
}else{ }else{
send_response(fd, 400, "Bad Request", "Bad request"); send_response(fd, 400, "Bad Request", "Bad request");
} }
}else if (strcmp(request.target, "/") == 0){ }else if (strcmp(request.target, "/test?aled") == 0){
send_response(fd, 200, "OK", motd); send_response(fd, 200, "OK", motd);
fprintf(fd, "fin du else-if\r\n");
}else{
send_response(fd, 404, "Not Found", "Not Found");
}
//partie 7/
char* absolute_path = rewrite_target(request.target);
//--- les printf ne fonctionnent pas ;(
fprintf(fd,"avant test\r\n");
fprintf(fd,"test - - - - - - - - \n%s\r\n",absolute_path);
//--- //---
/* FILE* fichier = check_and_open(absolute_path, "document.txt"); /* FILE* fichier = check_and_open(absolute_path, "document.txt");
...@@ -138,7 +126,13 @@ int traitementClient(int socket_client){ ...@@ -138,7 +126,13 @@ int traitementClient(int socket_client){
if(copy(fichier,fd))==-1){ if(copy(fichier,fd))==-1){
//error //error
}*/ }*/
fflush(fd); }else{
send_response(fd, 404, "Not Found", "Not Found");
}
fflush(fd);
//partie 7
char* absolute_path = rewrite_target(request.target);
printf("test - - - - - - - - %s\n",absolute_path);
fclose(fd); fclose(fd);
return 0; 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.
Please register or to comment