mirror of
https://github.com/sheumann/DiskBrowser.git
synced 2024-11-25 02:32:44 +00:00
93 lines
2.0 KiB
C
93 lines
2.0 KiB
C
#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"
|
|
|
|
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;
|
|
}
|
|
|
|
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);
|
|
printf("RequestResult %i\n", requestResult);
|
|
printf("Response code %lu\n", sess.responseCode);
|
|
|
|
if (requestResult == OPERATION_SUCCESSFUL) {
|
|
printf("contentLength = %lu\n", sess.contentLength);
|
|
}
|
|
|
|
if (sess.contentLength == 0)
|
|
sess.contentLength = 0xffff;
|
|
|
|
char *buf = malloc(sess.contentLength);
|
|
if (buf == NULL)
|
|
goto cleanup;
|
|
|
|
InitReadTCP(&sess, sess.contentLength, buf);
|
|
while (TryReadTCP(&sess) == rsWaiting)
|
|
/* keep reading */ ;
|
|
|
|
//printf("sess.contentLength = %lu\n", sess.contentLength);
|
|
//printf("sess.readCount = %lu\n", sess.readCount);
|
|
|
|
sess.contentLength -= sess.readCount;
|
|
|
|
printf("Read %lu bytes:\n", sess.contentLength);
|
|
|
|
for (unsigned long i = 0; i < sess.contentLength; i++) {
|
|
putchar(buf[i]);
|
|
}
|
|
putchar('\n');
|
|
|
|
cleanup:
|
|
EndTCPConnection(&sess);
|
|
|
|
exit:
|
|
TCPIPShutDown();
|
|
UnloadOneTool(54);
|
|
TLShutDown();
|
|
}
|