Merge branch 'bug1'

This commit is contained in:
Kelvin Sherlock 2013-09-24 22:48:17 -04:00
commit 103048b2db
5 changed files with 82 additions and 53 deletions

View File

@ -4,6 +4,8 @@
*/ */
#pragma noroot #pragma noroot
#pragma optimize 79 #pragma optimize 79
#pragma debug 0x8000
#pragma lint -1
#include <Memory.h> #include <Memory.h>
#include <MiscTool.h> #include <MiscTool.h>
@ -39,6 +41,7 @@ int read_binary(Word ipid, FILE *file, ReadBlock *dcb)
DecBusy(); DecBusy();
count = rb.rrBuffCount; count = rb.rrBuffCount;
if (!count) if (!count)
{ {
if (rv) break; if (rv) break;
@ -48,6 +51,8 @@ int read_binary(Word ipid, FILE *file, ReadBlock *dcb)
continue; continue;
} }
tcount = fwrite(buffer, 1, count, file); tcount = fwrite(buffer, 1, count, file);
if (dcb) dcb->transferCount += tcount; if (dcb) dcb->transferCount += tcount;
@ -89,9 +94,11 @@ int read_binary_size(Word ipid, FILE *file, ReadBlock *dcb)
DecBusy(); DecBusy();
count = rb.rrBuffCount; count = rb.rrBuffCount;
if (!count) if (!count)
{ {
if (rv) break; if (rv) return -1;
IncBusy(); IncBusy();
TCPIPPoll(); TCPIPPoll();
DecBusy(); DecBusy();
@ -109,7 +116,6 @@ int read_binary_size(Word ipid, FILE *file, ReadBlock *dcb)
} }
return 0; return 0;
} }

View File

@ -1,5 +1,7 @@
#pragma optimize 79 #pragma optimize 79
#pragma noroot #pragma noroot
#pragma debug 0x8000
#pragma lint -1
#include "dictionary.h" #include "dictionary.h"
#include <memory.h> #include <memory.h>

6
http.c
View File

@ -16,6 +16,8 @@
#pragma optimize 79 #pragma optimize 79
#pragma noroot #pragma noroot
#pragma debug 0x8000
#pragma lint -1
#include <TCPIP.h> #include <TCPIP.h>
#include <MiscTool.h> #include <MiscTool.h>
@ -320,6 +322,7 @@ int read_response(Word ipid, FILE *file, Handle dict)
int haveTime = 0; int haveTime = 0;
contentSize = 0; contentSize = 0;
transferEncoding = -1; transferEncoding = -1;
value = DictionaryGet(dict, "Content-Length", 14, &valueSize); value = DictionaryGet(dict, "Content-Length", 14, &valueSize);
@ -465,8 +468,7 @@ int read_response(Word ipid, FILE *file, Handle dict)
dcb.requestCount = contentSize; dcb.requestCount = contentSize;
ok = read_binary_size(ipid, file, &dcb); ok = read_binary_size(ipid, file, &dcb);
if (!ok) return -1; if (ok < 0 || dcb.transferCount != dcb.requestCount)
if (dcb.transferCount != dcb.requestCount)
{ {
fprintf(stderr, "Read error - requested %ld, received %ld\n", fprintf(stderr, "Read error - requested %ld, received %ld\n",
dcb.requestCount, dcb.transferCount); dcb.requestCount, dcb.transferCount);

92
mime.c
View File

@ -1,19 +1,19 @@
#pragma optimize 79 #pragma optimize 79
#pragma noroot #pragma noroot
#pragma debug 0x8000
#include <Types.h> #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 i;
int semi;
int slash; int slash;
int semi;
*ftype = 0; if (!cp || !*cp)
*atype = 0; return 0;
/* /*
* two pass * two pass
@ -21,27 +21,39 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
* 2. type * 2. type
*/ */
if (!cp || !*cp) return 0;
// find any optional ';'
semi = slash = -1; semi = slash = -1;
for (i = 0; ; ++i) for (i = 0; ; ++i)
{ {
char c = cp[i]; char c = cp[i];
if (c == 0) break; if (c == 0 || c == ';') break;
if (c == '/') slash = i;
if (c == ';')
{
semi = i;
break;
}
}
size = i;
for (i = 0; i < 2; ++i) if (c == '/')
{ {
slash = 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; h = ((*cp | 0x20) ^ size) & 0x0f;
switch (h) switch (h)
@ -59,6 +71,20 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
break; break;
case 0x09: 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 // application/octet-stream
if (size == 24 if (size == 24
&& (wp[0] | 0x2020) == 0x7061 // 'ap' && (wp[0] | 0x2020) == 0x7061 // 'ap'
@ -78,20 +104,6 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
*atype = 0x0000; *atype = 0x0000;
return 1; 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; break;
case 0x0c: case 0x0c:
@ -110,9 +122,13 @@ int parse_mime(const char *cp, Word *ftype, LongWord *atype)
} }
size = slash; /*
if (size == -1) break; // try again as type
while (--size)
{
if (cp[size] == '/') goto retry;
} }
*/
return 0; return 0;
} }

View File

@ -1,13 +1,17 @@
%% %%
#pragma optimize 79 #pragma optimize 79
#pragma noroot #pragma noroot
#pragma debug 0x8000
#include <Types.h> #include <Types.h>
#include "prototypes.h"
int parse_mime_c(const char *cp, Word *ftype, LongWord *atype) int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
{ {
int i; int i;
int slash; int slash;
int semi;
if (!cp || !*cp) if (!cp || !*cp)
return 0; return 0;
@ -31,20 +35,19 @@ int parse_mime_c(const char *cp, Word *ftype, LongWord *atype)
} }
// try type/subtype // try type/subtype
if (parse_mime(cp, i, ftype, atype)) if (parse_mime(cp, i, ftype, atype));
return 1; return 1;
// try type // try type
if (slash != -1) if (slash != -1)
return parse_mime(cp, slash, ftype, atype)); return parse_mime(cp, slash, ftype, atype);
return 0; return 0;
} }
int parse_mime(const char *cp, Word size, Word *ftype, LongWord *atype) int parse_mime(const char *cp, Word size, Word *ftype, LongWord *atype)
{ {
Word size;
Word *wp = (Word *)cp; Word *wp = (Word *)cp;
Word h; Word h;