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

ok o ok

parent a279f36e
Branches
Tags
No related merge requests found
File deleted
...@@ -9,16 +9,18 @@ ...@@ -9,16 +9,18 @@
char* testCorrect(char* str){ char* testCorrect(char* str, int first){
char* strRet; char* strRet;
char *correctStr = "GET / HTTP/1.1"; char *correctStr = "GET / HTTP/1.1";
char *incorrectStr = "HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-Length: 17\r\n\r\n400 Bad request"; char *incorrectStr = "HTTP/1.1 400 Bad Request\r\nConnection: close\r\nContent-Length: 17\r\n\r\n400 Bad request";
char *correctStr2 = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 17\r\n\r\n200 OK"; char *correctStr2 = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Length: 17\r\n\r\n200 OK";
if(strstr(str,correctStr) == NULL && !strcmp(str,"\r\n")){ if(strstr(str,correctStr) == NULL && first == 0) {
strRet=incorrectStr; strRet=incorrectStr;
//printf("---\n%s\n---",str); //printf("---\n%s\n---",str);
}else{ }else if(!strcmp(str,"\r\n")) {
strRet = correctStr2; strRet = correctStr2;
}else{
strRet = NULL;
} }
printf("---\n%s\n---",strRet); printf("---\n%s\n---",strRet);
return strRet; return strRet;
...@@ -41,12 +43,15 @@ int traitementClient(int socket_client){ ...@@ -41,12 +43,15 @@ int traitementClient(int socket_client){
exit(1); exit(1);
} }
//printf("test avant while\n"); //printf("test avant while\n");
int first = 0;
while(!feof(fd) && fgets(str,8000,fd) != NULL){ /* writing content to stdout */ while(!feof(fd) && fgets(str,8000,fd) != NULL){
fprintf(fd,"<Notre Serveur> %s\n",testCorrect(str)); char* resTest = testCorrect(str,first);
if(resTest!=NULL)fprintf(fd,"<Notre Serveur> %s\n",resTest);
first=1;
fflush(fd); fflush(fd);
} }
first=0;
//fflush(fd); //fflush(fd);
fclose(fd); fclose(fd);
return 0; return 0;
} }
\ No newline at end of file
No preview for this file type
socket.o: socket.c socket.h client.h
client.o: client.c socket.h client.h client.o: client.c socket.h client.h
main.o: main.c socket.h main.o: main.c socket.h
socket.o: socket.c socket.h client.h
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