mirror of
https://github.com/ksherlock/gopher.git
synced 2025-01-02 05:30:18 +00:00
Merge branch 'bug1'
This commit is contained in:
commit
103048b2db
18
common.c
18
common.c
@ -4,6 +4,8 @@
|
||||
*/
|
||||
#pragma noroot
|
||||
#pragma optimize 79
|
||||
#pragma debug 0x8000
|
||||
#pragma lint -1
|
||||
|
||||
#include <Memory.h>
|
||||
#include <MiscTool.h>
|
||||
@ -39,6 +41,7 @@ int read_binary(Word ipid, FILE *file, ReadBlock *dcb)
|
||||
DecBusy();
|
||||
|
||||
count = rb.rrBuffCount;
|
||||
|
||||
if (!count)
|
||||
{
|
||||
if (rv) break;
|
||||
@ -48,6 +51,8 @@ int read_binary(Word ipid, FILE *file, ReadBlock *dcb)
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
|
||||
tcount = fwrite(buffer, 1, count, file);
|
||||
if (dcb) dcb->transferCount += tcount;
|
||||
|
||||
@ -89,9 +94,11 @@ int read_binary_size(Word ipid, FILE *file, ReadBlock *dcb)
|
||||
DecBusy();
|
||||
|
||||
count = rb.rrBuffCount;
|
||||
|
||||
|
||||
if (!count)
|
||||
{
|
||||
if (rv) break;
|
||||
if (rv) return -1;
|
||||
IncBusy();
|
||||
TCPIPPoll();
|
||||
DecBusy();
|
||||
@ -109,16 +116,15 @@ int read_binary_size(Word ipid, FILE *file, ReadBlock *dcb)
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int ConnectLoop(char *host, Word port, Connection *connection)
|
||||
{
|
||||
LongWord qtick;
|
||||
LongWord qtick;
|
||||
|
||||
ConnectionInit(connection, MMStartUp(), flags._v ? DisplayCallback : NULL);
|
||||
ConnectionOpenC(connection, host, port);
|
||||
ConnectionInit(connection, MMStartUp(), flags._v ? DisplayCallback : NULL);
|
||||
ConnectionOpenC(connection, host, port);
|
||||
|
||||
// 30 second timeout.
|
||||
qtick = GetTick() + 30 * 60;
|
||||
@ -156,4 +162,4 @@ int CloseLoop(Connection *connection)
|
||||
while (!ConnectionPoll(connection)) ; // wait for it to close.
|
||||
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#pragma optimize 79
|
||||
#pragma noroot
|
||||
#pragma debug 0x8000
|
||||
#pragma lint -1
|
||||
|
||||
#include "dictionary.h"
|
||||
#include <memory.h>
|
||||
|
8
http.c
8
http.c
@ -16,7 +16,9 @@
|
||||
|
||||
#pragma optimize 79
|
||||
#pragma noroot
|
||||
|
||||
#pragma debug 0x8000
|
||||
#pragma lint -1
|
||||
|
||||
#include <TCPIP.h>
|
||||
#include <MiscTool.h>
|
||||
#include <Memory.h>
|
||||
@ -320,6 +322,7 @@ int read_response(Word ipid, FILE *file, Handle dict)
|
||||
|
||||
int haveTime = 0;
|
||||
|
||||
|
||||
contentSize = 0;
|
||||
transferEncoding = -1;
|
||||
value = DictionaryGet(dict, "Content-Length", 14, &valueSize);
|
||||
@ -465,8 +468,7 @@ int read_response(Word ipid, FILE *file, Handle dict)
|
||||
dcb.requestCount = contentSize;
|
||||
ok = read_binary_size(ipid, file, &dcb);
|
||||
|
||||
if (!ok) return -1;
|
||||
if (dcb.transferCount != dcb.requestCount)
|
||||
if (ok < 0 || dcb.transferCount != dcb.requestCount)
|
||||
{
|
||||
fprintf(stderr, "Read error - requested %ld, received %ld\n",
|
||||
dcb.requestCount, dcb.transferCount);
|
||||
|
98
mime.c
98
mime.c
@ -1,19 +1,19 @@
|
||||
#pragma optimize 79
|
||||
#pragma noroot
|
||||
#pragma debug 0x8000
|
||||
|
||||
#include <Types.h>
|
||||
#include "prototypes.h"
|
||||
|
||||
int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||
|
||||
int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
|
||||
{
|
||||
Word size;
|
||||
Word *wp = (Word *)cp;
|
||||
Word h;
|
||||
int i;
|
||||
int semi;
|
||||
int slash;
|
||||
int semi;
|
||||
|
||||
*ftype = 0;
|
||||
*atype = 0;
|
||||
if (!cp || !*cp)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* two pass
|
||||
@ -21,31 +21,43 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||
* 2. type
|
||||
*/
|
||||
|
||||
|
||||
|
||||
if (!cp || !*cp) return 0;
|
||||
|
||||
// find any optional ';'
|
||||
semi = slash = -1;
|
||||
for (i = 0; ; ++i)
|
||||
{
|
||||
char c = cp[i];
|
||||
if (c == 0) break;
|
||||
if (c == '/') slash = i;
|
||||
if (c == ';')
|
||||
if (c == 0 || c == ';') break;
|
||||
|
||||
if (c == '/')
|
||||
{
|
||||
semi = i;
|
||||
break;
|
||||
slash = i;
|
||||
}
|
||||
}
|
||||
size = i;
|
||||
|
||||
for (i = 0; i < 2; ++i)
|
||||
// try type/subtype
|
||||
if (parse_mime(cp, i, ftype, atype));
|
||||
return 1;
|
||||
|
||||
|
||||
// try type
|
||||
if (slash != -1)
|
||||
return parse_mime(cp, slash, ftype, atype);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_mime(const char *cp, Word size, Word *ftype, LongWord *atype)
|
||||
{
|
||||
Word *wp = (Word *)cp;
|
||||
Word h;
|
||||
|
||||
if (!cp || !size) return 0;
|
||||
|
||||
retry:
|
||||
|
||||
h = ((*cp | 0x20) ^ size) & 0x0f;
|
||||
|
||||
switch (h)
|
||||
{
|
||||
h = ((*cp | 0x20) ^ size) & 0x0f;
|
||||
|
||||
switch (h)
|
||||
{
|
||||
case 0x00:
|
||||
// text
|
||||
if (size == 4
|
||||
@ -59,6 +71,20 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||
break;
|
||||
|
||||
case 0x09:
|
||||
// text/x-pascal
|
||||
if (size == 13
|
||||
&& (wp[0] | 0x2020) == 0x6574 // 'te'
|
||||
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
|
||||
&& (wp[2] | 0x2020) == 0x782f // '/x'
|
||||
&& (wp[3] | 0x2020) == 0x702d // '-p'
|
||||
&& (wp[4] | 0x2020) == 0x7361 // 'as'
|
||||
&& (wp[5] | 0x2020) == 0x6163 // 'ca'
|
||||
&& (cp[12] | 0x20) == 0x6c // 'l'
|
||||
) {
|
||||
*ftype = 0xb0;
|
||||
*atype = 0x0005;
|
||||
return 1;
|
||||
}
|
||||
// application/octet-stream
|
||||
if (size == 24
|
||||
&& (wp[0] | 0x2020) == 0x7061 // 'ap'
|
||||
@ -78,20 +104,6 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||
*atype = 0x0000;
|
||||
return 1;
|
||||
}
|
||||
// text/x-pascal
|
||||
if (size == 13
|
||||
&& (wp[0] | 0x2020) == 0x6574 // 'te'
|
||||
&& (wp[1] | 0x2020) == 0x7478 // 'xt'
|
||||
&& (wp[2] | 0x2020) == 0x782f // '/x'
|
||||
&& (wp[3] | 0x2020) == 0x702d // '-p'
|
||||
&& (wp[4] | 0x2020) == 0x7361 // 'as'
|
||||
&& (wp[5] | 0x2020) == 0x6163 // 'ca'
|
||||
&& (cp[12] | 0x20) == 0x6c // 'l'
|
||||
) {
|
||||
*ftype = 0xb0;
|
||||
*atype = 0x0005;
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x0c:
|
||||
@ -108,11 +120,15 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
size = slash;
|
||||
if (size == -1) break;
|
||||
}
|
||||
|
||||
/*
|
||||
// try again as type
|
||||
while (--size)
|
||||
{
|
||||
if (cp[size] == '/') goto retry;
|
||||
}
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
9
mime.txt
9
mime.txt
@ -1,13 +1,17 @@
|
||||
%%
|
||||
#pragma optimize 79
|
||||
#pragma noroot
|
||||
#pragma debug 0x8000
|
||||
|
||||
#include <Types.h>
|
||||
#include "prototypes.h"
|
||||
|
||||
|
||||
int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
|
||||
{
|
||||
int i;
|
||||
int slash;
|
||||
int semi;
|
||||
|
||||
if (!cp || !*cp)
|
||||
return 0;
|
||||
@ -31,20 +35,19 @@ int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
|
||||
}
|
||||
|
||||
// try type/subtype
|
||||
if (parse_mime(cp, i, ftype, atype))
|
||||
if (parse_mime(cp, i, ftype, atype));
|
||||
return 1;
|
||||
|
||||
|
||||
// try type
|
||||
if (slash != -1)
|
||||
return parse_mime(cp, slash, ftype, atype));
|
||||
return parse_mime(cp, slash, ftype, atype);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int parse_mime(const char *cp, Word size, Word *ftype, LongWord *atype)
|
||||
{
|
||||
Word size;
|
||||
Word *wp = (Word *)cp;
|
||||
Word h;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user