-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsing.c
101 lines (82 loc) · 1.94 KB
/
parsing.c
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//meshDNS by rémi Arnaud
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <netinet/in.h>
#include "parsing.h"
#include "meshDNS.h"
#include "config.h"
#include "request.h"
#include "response.h"
mdns *createReq(char* str, enum etype t){
printf("generate request\n");
mdns *req;
int i = 0;
req = malloc(sizeof(mdns));
if (req == NULL){
printf("Error : malloc fail\n");
return NULL;
}
memset(req, 0, sizeof(mdns));
req->infos = IPV6 | IPV4;
req->type = t;
while(str[i]){
req->request[i] = str[i];
++i;
}
req->request[i] = '\0';
//ret-> hash = md5()
return req;
}
mdns *parseBuf(char *buf){
int i = 0;
char *split;
mdns *ret;
if ((split = strchr(buf, ':')) == NULL){
printf("Error : invalid syntax\n");
return NULL;
}
++split;
split[strlen(split) - 1] = '\0';
printf("%s\n", split);
if (strncmp(buf, "ip", 2) == 0)
ret = createReq(split, IPTOKEY);
else if (strncmp(buf, "key", 3) == 0)
ret = createReq(split, KEY);
else if (strncmp(buf, "name", 4) == 0)
ret = createReq(split, NAME);
else{
printf("Error : invalid syntax\n");
return NULL;
}
return ret;
}
void parseResponse(mdns *req, linfo *infos){
if (req->type == NAME)
responseName(req, infos);
else if (req->type == KEY)
responseKey(req, infos);
else if (req->type == IPTOKEY)
responseIpToKey(req, infos);
else if (req->type == IPTONAME)
responseIpToName(req, infos);
return;
}
resp *parseReq(mdns *req, linfo *infos){
//hash verification
printf("parseReq\n");
if (req->infos & RESPOND){
parseResponse(req, infos);
return NULL;
}
if (req->type == NAME)
return requestName(req, infos);
else if (req->type == KEY)
return requestKey(req, infos);
else if (req->type == IPTOKEY)
return requestIpToKey(req, infos);
else if (req->type == IPTONAME)
return requestIpToName(req, infos);
printf("caca la requete\n");
return NULL;
}