mirror of
https://github.com/sheumann/DiskBrowser.git
synced 2024-11-25 02:32:44 +00:00
HTTP tweaks and test program.
I switched to using HTTP/1.0 for now to prevent the server from sending chunked transfer-encoding, which this code currently doesn't support.
This commit is contained in:
parent
c0949b2efb
commit
1e1977bc0f
8
Makefile
8
Makefile
@ -4,11 +4,14 @@ CFLAGS = -w-1 -O-1
|
|||||||
JSONTEST_OBJS = jsontest.a json.a jsonutil.a
|
JSONTEST_OBJS = jsontest.a json.a jsonutil.a
|
||||||
JSONTEST_PROG = jsontest
|
JSONTEST_PROG = jsontest
|
||||||
|
|
||||||
|
HTTPTEST_OBJS = httptest.a hostname.a http.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a
|
||||||
|
HTTPTEST_PROG = httptest
|
||||||
|
|
||||||
DISKBROWSER_OBJS = diskbrowser.a hostname.a http.a json.a jsonutil.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a
|
DISKBROWSER_OBJS = diskbrowser.a hostname.a http.a json.a jsonutil.a readtcp.a seturl.a strcasecmp.a tcpconnection.a urlparser.a
|
||||||
DISKBROWSER_RSRC = diskbrowser.rez
|
DISKBROWSER_RSRC = diskbrowser.rez
|
||||||
DISKBROWSER_PROG = DiskBrowser
|
DISKBROWSER_PROG = DiskBrowser
|
||||||
|
|
||||||
PROGS = $(JSONTEST_PROG) $(DISKBROWSER_PROG)
|
PROGS = $(JSONTEST_PROG) $(HTTPTEST_PROG) $(DISKBROWSER_PROG)
|
||||||
|
|
||||||
.PHONY: default
|
.PHONY: default
|
||||||
default: $(PROGS)
|
default: $(PROGS)
|
||||||
@ -16,6 +19,9 @@ default: $(PROGS)
|
|||||||
$(JSONTEST_PROG): $(JSONTEST_OBJS)
|
$(JSONTEST_PROG): $(JSONTEST_OBJS)
|
||||||
$(CC) $(CFLAGS) -o $@ $^
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
|
$(HTTPTEST_PROG): $(HTTPTEST_OBJS)
|
||||||
|
$(CC) $(CFLAGS) -o $@ $^
|
||||||
|
|
||||||
$(DISKBROWSER_PROG): $(DISKBROWSER_OBJS) $(DISKBROWSER_RSRC)
|
$(DISKBROWSER_PROG): $(DISKBROWSER_OBJS) $(DISKBROWSER_RSRC)
|
||||||
$(CC) $(CFLAGS) -o $@ $(DISKBROWSER_OBJS)
|
$(CC) $(CFLAGS) -o $@ $(DISKBROWSER_OBJS)
|
||||||
occ $(DISKBROWSER_RSRC) -o $@
|
occ $(DISKBROWSER_RSRC) -o $@
|
||||||
|
11
http.c
11
http.c
@ -66,12 +66,13 @@ Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
|||||||
sizeNeeded = 0;
|
sizeNeeded = 0;
|
||||||
do {
|
do {
|
||||||
sizeNeeded = snprintf(sess->httpRequest, sizeNeeded,
|
sizeNeeded = snprintf(sess->httpRequest, sizeNeeded,
|
||||||
"GET /%s HTTP/1.1\r\n"
|
"GET /%s HTTP/1.0\r\n"
|
||||||
"Host: %s\r\n"
|
"Host: %s\r\n"
|
||||||
"User-Agent: GS-Disk-Browser/" USER_AGENT_VERSION "\r\n"
|
"User-Agent: GS-Disk-Browser/" USER_AGENT_VERSION "\r\n"
|
||||||
"Accept-Encoding: identity\r\n"
|
"Accept-Encoding: identity\r\n"
|
||||||
//"Accept: */*\r\n" /* default, but some clients send explicitly */
|
//"Accept: */*\r\n" /* default, but some clients send explicitly */
|
||||||
//"Connection: Keep-Alive\r\n" /* same */
|
//"Connection: Keep-Alive\r\n" /* same (in HTTP/1.1) */
|
||||||
|
"Connection: close\r\n"
|
||||||
"\r\n",
|
"\r\n",
|
||||||
resourceStr,
|
resourceStr,
|
||||||
sess->hostName+1);
|
sess->hostName+1);
|
||||||
@ -94,13 +95,15 @@ Boolean BuildHTTPRequest(Session *sess, char *resourceStr) {
|
|||||||
}
|
}
|
||||||
} while (round++ == 0);
|
} while (round++ == 0);
|
||||||
|
|
||||||
|
sess->httpRequestLen = sizeNeeded;
|
||||||
|
|
||||||
free(escapedStr);
|
free(escapedStr);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
enum NetDiskError
|
enum NetDiskError
|
||||||
DoHTTPRequest(Session *sess, unsigned long start, unsigned long end) {
|
DoHTTPRequest(Session *sess) {
|
||||||
top:;
|
top:;
|
||||||
union {
|
union {
|
||||||
srBuff srBuff;
|
srBuff srBuff;
|
||||||
@ -184,7 +187,7 @@ netRetry:
|
|||||||
if (strncmp(response, "HTTP/1.", 7) != 0)
|
if (strncmp(response, "HTTP/1.", 7) != 0)
|
||||||
goto errorReturn;
|
goto errorReturn;
|
||||||
response += 7;
|
response += 7;
|
||||||
if (!(*response >= '1' && *response <= '9'))
|
if (!(*response >= '0' && *response <= '9'))
|
||||||
goto errorReturn;
|
goto errorReturn;
|
||||||
response += 1;
|
response += 1;
|
||||||
if (*response != ' ')
|
if (*response != ' ')
|
||||||
|
2
http.h
2
http.h
@ -6,6 +6,6 @@
|
|||||||
#include "netdiskerror.h"
|
#include "netdiskerror.h"
|
||||||
|
|
||||||
Boolean BuildHTTPRequest(Session *sess, char *resourceStr);
|
Boolean BuildHTTPRequest(Session *sess, char *resourceStr);
|
||||||
enum NetDiskError DoHTTPRequest(Session *sess, unsigned long start, unsigned long end);
|
enum NetDiskError DoHTTPRequest(Session *sess);
|
||||||
|
|
||||||
#endif
|
#endif
|
82
httptest.c
Normal file
82
httptest.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#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("Read %lu bytes\n", sess.contentLength - sess.readCount);
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
EndTCPConnection(&sess);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
TCPIPShutDown();
|
||||||
|
UnloadOneTool(54);
|
||||||
|
TLShutDown();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user