Skip to content

Commit

Permalink
Merge branch 'bug1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ksherlock committed Sep 25, 2013
2 parents b7e9088 + 9457120 commit 103048b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 52 deletions.
18 changes: 12 additions & 6 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
*/
#pragma noroot
#pragma optimize 79
#pragma debug 0x8000
#pragma lint -1

#include <Memory.h>
#include <MiscTool.h>
Expand Down Expand Up @@ -39,6 +41,7 @@ int read_binary(Word ipid, FILE *file, ReadBlock *dcb)
DecBusy();

count = rb.rrBuffCount;

if (!count)
{
if (rv) break;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -156,4 +162,4 @@ int CloseLoop(Connection *connection)
while (!ConnectionPoll(connection)) ; // wait for it to close.

return 1;
}
}
2 changes: 2 additions & 0 deletions dictionary.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma optimize 79
#pragma noroot
#pragma debug 0x8000
#pragma lint -1

#include "dictionary.h"
#include <memory.h>
Expand Down
8 changes: 5 additions & 3 deletions http.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#pragma optimize 79
#pragma noroot

#pragma debug 0x8000
#pragma lint -1

#include <TCPIP.h>
#include <MiscTool.h>
#include <Memory.h>
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
96 changes: 56 additions & 40 deletions mime.c
Original file line number Diff line number Diff line change
@@ -1,51 +1,63 @@
#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
* 1. type/subtype
* 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)
{
h = ((*cp | 0x20) ^ size) & 0x0f;
// try type/subtype
if (parse_mime(cp, i, ftype, atype));
return 1;

switch (h)
{

// 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)
{
case 0x00:
// text
if (size == 4
Expand All @@ -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'
Expand All @@ -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:
Expand All @@ -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 changes: 6 additions & 3 deletions mime.txt
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down

0 comments on commit 103048b

Please sign in to comment.