Repository navigation
Expand file tree
/
Copy pathhttptest.c
More file actions
99 lines (79 loc) · 2.47 KB
/
Copy pathhttptest.c
File metadata and controls
99 lines (79 loc) · 2.47 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
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <tcpip.h>
#include <locator.h>
#include <misctool.h>
#include <memory.h>
#include <orca.h>
#include "http.h"
#include "session.h"
#include "seturl.h"
#include "hostname.h"
#include "tcpconnection.h"
#include "readtcp.h"
char buf[512];
int main(int argc, char **argv) {
TLStartUp();
LoadOneTool(54,0x200);
TCPIPStartUp();
if (TCPIPGetConnectStatus() == FALSE) {
TCPIPConnect(NULL);
if (toolerror())
goto exit;
}
Session sess = {0};
if (argc < 2)
goto exit;
char *url = argv[1];
enum NetDiskError result = SetURL(&sess, url, TRUE, FALSE);
if (result != OPERATION_SUCCESSFUL) {
printf("SetURL error %i\n", (int)result);
goto exit;
}
unsigned long startByte = 0;
if (argc > 2) {
startByte = strtoul(argv[2], NULL, 0);
}
printf("Request:\n");
printf("=========\n");
int i;
for (i = 0; sess.httpRequest[i] != '\0'; i++) {
char ch = sess.httpRequest[i];
if (ch != '\r')
putchar(ch);
}
printf("=========\n");
printf("\n");
enum NetDiskError requestResult;
requestResult = DoHTTPRequest(&sess, startByte, startByte + 511);
printf("RequestResult %i\n", requestResult);
printf("Response code %lu\n", sess.responseCode);
if (requestResult == OPERATION_SUCCESSFUL) {
printf("rangeStart = %lu\n", sess.rangeStart);
printf("rangeEnd = %lu\n", sess.rangeEnd);
printf("totalLength = %lu\n", sess.totalLength);
printf("contentLength = %lu\n", sess.contentLength);
}
InitReadTCP(&sess, sess.rangeEnd - sess.rangeStart + 1, buf);
while (TryReadTCP(&sess) == rsWaiting)
/* keep reading */ ;
LongWord startTime = GetTick();
while (GetTick() - startTime < 70)
/* wait */ ;
printf("Request 2:\n");
requestResult = DoHTTPRequest(&sess, startByte + 512, startByte + 1023);
printf("RequestResult %i\n", requestResult);
printf("Response code %lu\n", sess.responseCode);
if (requestResult == OPERATION_SUCCESSFUL) {
printf("rangeStart = %lu\n", sess.rangeStart);
printf("rangeEnd = %lu\n", sess.rangeEnd);
printf("totalLength = %lu\n", sess.totalLength);
printf("contentLength = %lu\n", sess.contentLength);
}
EndTCPConnection(&sess);
exit:
TCPIPShutDown();
UnloadOneTool(54);
TLShutDown();
}