-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.c
More file actions
27 lines (22 loc) · 752 Bytes
/
parser.c
File metadata and controls
27 lines (22 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Wiktor Garbarek 291963
#include<stdio.h>
#include<string.h>
#include "utils.h"
int parse_request(struct request *dst, char *request){
char delim[3] = " \n\r";
char *str, *token;
int flag = NOTHING;
for(str=request;;str = NULL){
token = strtok(str, delim);
if (token == NULL) return -flag;
switch (flag){
case GET: strcpy(dst->endpoint, token); break;
case HOST: strcpy(dst->host, token); break;
case CONNECTION: strcpy(dst->connection, token); break;
}
flag = NOTHING;
if(strcmp(token, "GET") == 0) flag = GET;
if(strcmp(token, "Host:") == 0) flag = HOST;
if(strcmp(token, "Connection:") == 0) flag = CONNECTION;
}
}