From aa6bcc05d31d3c6cdee4c15eaa058472d875b8dc Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 24 Sep 2013 22:43:43 -0400 Subject: [PATCH 1/4] updated mime functions (match prototypes) --- mime.c | 98 ++++++++++++++++++++++++++++++++------------------------ mime.txt | 9 ++++-- 2 files changed, 63 insertions(+), 44 deletions(-) diff --git a/mime.c b/mime.c index 5386ec6..5ba8c9b 100644 --- a/mime.c +++ b/mime.c @@ -1,19 +1,19 @@ #pragma optimize 79 #pragma noroot +#pragma debug 0x8000 #include +#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; } diff --git a/mime.txt b/mime.txt index 91b2452..45a68bb 100644 --- a/mime.txt +++ b/mime.txt @@ -1,13 +1,17 @@ %% #pragma optimize 79 #pragma noroot +#pragma debug 0x8000 #include +#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; From 09ebb6c84200f6a2cc44088718563baf665bcf02 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 24 Sep 2013 22:44:55 -0400 Subject: [PATCH 2/4] debug names/lint --- dictionary.c | 2 ++ http.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dictionary.c b/dictionary.c index fdf59e5..54f6c60 100644 --- a/dictionary.c +++ b/dictionary.c @@ -1,5 +1,7 @@ #pragma optimize 79 #pragma noroot +#pragma debug 0x8000 +#pragma lint -1 #include "dictionary.h" #include diff --git a/http.c b/http.c index 4becaa7..ef076dd 100644 --- a/http.c +++ b/http.c @@ -16,7 +16,9 @@ #pragma optimize 79 #pragma noroot - +#pragma debug 0x8000 +#pragma lint -1 + #include #include #include From fad3fc48eaf578de900a8c7b8eb4b9224904bd70 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 24 Sep 2013 22:45:23 -0400 Subject: [PATCH 3/4] read_binary_size return value --- http.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http.c b/http.c index ef076dd..b9f30b7 100644 --- a/http.c +++ b/http.c @@ -322,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); @@ -467,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); From 945712032736c398ef13691cad884c625dc10133 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Tue, 24 Sep 2013 22:47:08 -0400 Subject: [PATCH 4/4] read_binary_size return value on read error --- common.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/common.c b/common.c index ffbf488..ff7bbba 100644 --- a/common.c +++ b/common.c @@ -4,6 +4,8 @@ */ #pragma noroot #pragma optimize 79 +#pragma debug 0x8000 +#pragma lint -1 #include #include @@ -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; -} \ No newline at end of file +}