-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathhttp.cpp
More file actions
154 lines (141 loc) · 3.39 KB
/
http.cpp
File metadata and controls
154 lines (141 loc) · 3.39 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <stdio.h>
#include <stdint.h>
#include "http.h"
#include "colors.h"
#include "tags.h"
#include "shared.h"
void handle_http(QList<QStandardItem *> *row, const char *data, uint16_t size){
int n; //number of characters read
int i = 0; //index into data
printf(CYAN " HTTP:\n" RESET);
row->append(new QStandardItem("HTTP"));
if(size == 0){
printf(" This packet contains no more data\n");
row->append(new QStandardItem("Acknowledgement, No more data"));
return;
}
if(strncmp(data, "GET", 3) == 0 || strncmp(data, "HTTP", 4) == 0){
bool firstLineRead = false;
do{
n = 0;
printf("\t\t");
if(firstLineRead == false){
QString infoString;
while(data[i] != '\r'){
putchar(data[i]);
infoString.append(data[i]);
i++;
n++;
}
row->append(new QStandardItem(infoString));
firstLineRead = true;
}
else{
while(data[i] != '\r'){
putchar(data[i]);
i++;
n++;
}
}
printf("\n");
i += 2;
}while(n > 0);
}
else{
row->append(new QStandardItem("HTTP Data"));
i = 0;
n = 1;
printf("\t\t");
while(i < size){
if(data[i] >= 32 && data[i] <= 126){
putchar(data[i]);
}
else{
putchar('.');
}
//printbyte(data[i]);
if((n & 0x3F) == 0){
printf("\n\t\t");
}
n++;
i++;
}
putchar('\n');
}
}
void handle_http_fill(QString *infoStr, const char *data, uint16_t size){
int n; //number of characters read
int i = 0; //index into data
//printf(CYAN " HTTP:\n" RESET);
infoStr->append(HEADER_TAG_START "HTTP:" HEADER_TAG_END NEWLINE);
if(size == 0){
//printf(" This packet contains no more data\n");
infoStr->append(TAB "This packet contains no more data" NEWLINE);
return;
}
if(strncmp(data, "GET", 3) == 0 || strncmp(data, "HTTP", 4) == 0){
do{
n = 0;
//printf("\t\t");
infoStr->append(TAB);
while(data[i] != '\r'){
//putchar(data[i]);
infoStr->append(IS_PRINTABLE(data[i]) ? data[i] : '.');
i++;
n++;
}
//printf("\n");
infoStr->append(NEWLINE);
i += 2;
}while(n > 0);
}
else{
QHash<char, QString> htmlEntities;
htmlEntities.insert('<', "<");
htmlEntities.insert('>', ">");
i = 0;
n = 1;
//printf("\t\t");
infoStr->append(TAB);
while(i < size){
char c = data[i];
if(IS_PRINTABLE(c)){
if(htmlEntities.contains(c)){
infoStr->append(htmlEntities.value(c));
}
else{
infoStr->append(c);
}
}
else{
infoStr->append('.');
}
/*
if(data[i] >= 32 && data[i] <= 126){
putchar(data[i]);
}
else{
putchar('.');
}
*/
//printbyte(data[i]);
if(n == 32){
//printf("\n\t\t");
infoStr->append(NEWLINE TAB);
n = 0;
}
n++;
i++;
}
//putchar('\n');
}
}
/*
void printbyte(char byte){
uint8_t mask = 128;
while(mask > 0){
printf("%d", ((byte & mask) ? 1 : 0));
mask >>= 1;
}
}
*/