2018-07-30 04:40:03 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <tcpip.h>
|
|
|
|
#include <locator.h>
|
|
|
|
#include <misctool.h>
|
|
|
|
#include <memory.h>
|
2018-07-31 02:35:45 +00:00
|
|
|
#include <orca.h>
|
2018-07-30 04:40:03 +00:00
|
|
|
#include "http.h"
|
|
|
|
#include "session.h"
|
2018-07-31 02:35:45 +00:00
|
|
|
#include "seturl.h"
|
2018-07-30 04:40:03 +00:00
|
|
|
#include "hostname.h"
|
2018-08-01 23:24:43 +00:00
|
|
|
#include "tcpconnection.h"
|
2018-08-04 00:50:59 +00:00
|
|
|
#include "readtcp.h"
|
2018-07-30 04:40:03 +00:00
|
|
|
|
2018-08-04 00:50:59 +00:00
|
|
|
char buf[512];
|
2018-07-31 02:35:45 +00:00
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2018-07-30 04:40:03 +00:00
|
|
|
TLStartUp();
|
|
|
|
|
|
|
|
LoadOneTool(54,0x200);
|
|
|
|
TCPIPStartUp();
|
|
|
|
|
2018-07-31 02:35:45 +00:00
|
|
|
if (TCPIPGetConnectStatus() == FALSE) {
|
|
|
|
TCPIPConnect(NULL);
|
|
|
|
if (toolerror())
|
|
|
|
goto exit;
|
|
|
|
}
|
2018-07-30 04:40:03 +00:00
|
|
|
|
2018-07-31 02:35:45 +00:00
|
|
|
Session sess = {0};
|
|
|
|
|
2018-10-02 23:04:22 +00:00
|
|
|
if (argc < 2)
|
|
|
|
goto exit;
|
|
|
|
|
|
|
|
char *url = argv[1];
|
2018-07-30 04:40:03 +00:00
|
|
|
|
2018-08-11 06:53:53 +00:00
|
|
|
enum NetDiskError result = SetURL(&sess, url, TRUE, FALSE);
|
2018-07-31 02:35:45 +00:00
|
|
|
|
2018-08-11 06:53:53 +00:00
|
|
|
if (result != OPERATION_SUCCESSFUL) {
|
2018-07-31 02:35:45 +00:00
|
|
|
printf("SetURL error %i\n", (int)result);
|
2018-07-30 04:40:03 +00:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2018-07-31 02:35:45 +00:00
|
|
|
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");
|
2018-08-01 23:24:43 +00:00
|
|
|
printf("\n");
|
2018-08-01 06:37:22 +00:00
|
|
|
|
2018-08-11 06:53:53 +00:00
|
|
|
enum NetDiskError requestResult;
|
2018-08-01 06:53:49 +00:00
|
|
|
requestResult = DoHTTPRequest(&sess, startByte, startByte + 511);
|
2018-08-01 05:05:19 +00:00
|
|
|
printf("RequestResult %i\n", requestResult);
|
2018-08-01 06:37:22 +00:00
|
|
|
printf("Response code %lu\n", sess.responseCode);
|
2018-07-30 04:40:03 +00:00
|
|
|
|
2018-08-11 06:53:53 +00:00
|
|
|
if (requestResult == OPERATION_SUCCESSFUL) {
|
2018-08-01 05:05:19 +00:00
|
|
|
printf("rangeStart = %lu\n", sess.rangeStart);
|
|
|
|
printf("rangeEnd = %lu\n", sess.rangeEnd);
|
|
|
|
printf("totalLength = %lu\n", sess.totalLength);
|
|
|
|
printf("contentLength = %lu\n", sess.contentLength);
|
2018-07-30 04:40:03 +00:00
|
|
|
}
|
2018-08-04 00:50:59 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-08-11 06:53:53 +00:00
|
|
|
if (requestResult == OPERATION_SUCCESSFUL) {
|
2018-08-04 00:50:59 +00:00
|
|
|
printf("rangeStart = %lu\n", sess.rangeStart);
|
|
|
|
printf("rangeEnd = %lu\n", sess.rangeEnd);
|
|
|
|
printf("totalLength = %lu\n", sess.totalLength);
|
|
|
|
printf("contentLength = %lu\n", sess.contentLength);
|
|
|
|
}
|
|
|
|
|
2018-08-01 05:05:19 +00:00
|
|
|
|
2018-07-30 04:40:03 +00:00
|
|
|
EndTCPConnection(&sess);
|
|
|
|
|
|
|
|
exit:
|
|
|
|
TCPIPShutDown();
|
|
|
|
UnloadOneTool(54);
|
|
|
|
TLShutDown();
|
|
|
|
}
|