Http fetch to file doesn't work for some reason

This commit is contained in:
Ruben Shekspir 2019-05-05 13:58:18 +04:00
parent ab197c6483
commit 6c66d03769
6 changed files with 54 additions and 21 deletions

View file

@ -1,5 +1,11 @@
MODULE FileManager;
IMPORT Files, Out, Logger;
IMPORT Files, Out, Logger, Strings;
PROCEDURE WriteString(VAR r : Files.Rider; str : ARRAY OF CHAR);
BEGIN
Files.WriteBytes(r, str, Strings.Length(str));
Logger.Log(str);
END WriteString;
PROCEDURE Read*(fileName: ARRAY OF CHAR; VAR returnString: ARRAY OF CHAR): BOOLEAN;
VAR
@ -29,9 +35,32 @@ BEGIN
RETURN TRUE;
END Read;
PROCEDURE Write*();
PROCEDURE Write*(fileName, content: ARRAY OF CHAR): BOOLEAN;
VAR
f: Files.File;
r: Files.Rider;
i: LONGINT;
BEGIN
f := Files.New(fileName);
IF f = NIL THEN
Logger.Log("-------------------");
Logger.Log("File Name");
Logger.Log(fileName);
Logger.Log("File not found");
Logger.Log("-------------------");
RETURN FALSE
END;
Files.Set(r, f, 0);
Logger.Log("Writing to file");
Logger.Log(fileName);
Logger.Log("-------------------");
WriteString(r, content);
Files.Register(f);
RETURN TRUE;
END Write;
END FileManager.

View file

@ -186,7 +186,7 @@ BEGIN
END Create;
BEGIN
NEW(jsonRecord);
(* NEW(jsonRecord);
jsonRecord := Create("{'foo': 'bar', 'test': 'test1', 'test2': {'sub': 'dub'}}");
keyFound := jsonRecord.GetTerminal(jsonRecord, "foo", testValue);
@ -194,6 +194,5 @@ BEGIN
IF keyFound THEN
Logger.Log('found KEY');
Logger.Log(testValue);
ELSE Logger.Log('Value for the Key is not found') END;
ELSE Logger.Log('Value for the Key is not found') END; *)
END JsonParser.

View file

@ -2,21 +2,28 @@ MODULE PackageFileParser;
IMPORT
JsonParser,
FileManager,
http,
Logger;
CONST
MAXARRAYNUMBER = 1000;
MAXARRAYNUMBER = 1000000;
PROCEDURE install*;
VAR
fileData: ARRAY MAXARRAYNUMBER OF CHAR;
successfullyParsed: BOOLEAN;
fileData, buff, buff2: ARRAY MAXARRAYNUMBER OF CHAR;
success: BOOLEAN;
BEGIN
Logger.Log("Starting install process");
successfullyParsed := FileManager.Read("VersionFile.json", fileData);
success := FileManager.Read("VersionFile.json", fileData);
IF ~successfullyParsed THEN Logger.Log("Some ERROR occured while reading VERSIONFILE") END;
ASSERT(successfullyParsed);
IF ~success THEN Logger.Log("Some ERROR occured while reading VERSIONFILE") END;
ASSERT(success);
Logger.Log(fileData);
http.get("norayr.am", "/tmp/", "80", buff);
http.getClean(buff, buff2);
success := FileManager.Write("index.html", buff2);
IF ~success THEN Logger.Log("Some ERROR occured while writing to test gile") END;
ASSERT(success)
END install;
BEGIN

View file

@ -10,7 +10,7 @@ TYPE
VAR
buff, buff2: ARRAY MAXARRAYNUMBEREXTENDED OF CHAR;
PROCEDURE getClean(buff: ARRAY OF CHAR; VAR clean: ARRAY OF CHAR);
PROCEDURE getClean *(buff: ARRAY OF CHAR; VAR clean: ARRAY OF CHAR);
VAR
i: INTEGER;
newLine: ARRAY 2 OF CHAR;
@ -76,7 +76,7 @@ BEGIN
UNTIL ORD(val[i]) = 10; (* 0DX number(newline)*)
END getHeader;
PROCEDURE get(host, path, port: ARRAY OF CHAR; VAR buff: ARRAY OF CHAR);
PROCEDURE get *(host, path, port: ARRAY OF CHAR; VAR buff: ARRAY OF CHAR);
VAR
socket : Internet.Socket;
connectionFlag: BOOLEAN;
@ -127,7 +127,7 @@ BEGIN
END get;
BEGIN
get("norayr.am", "/tmp/", "80", buff);
(* get("norayr.am", "/tmp/", "80", buff);
getClean(buff, buff2);
Logger.Log(buff2);
Logger.Log(buff2); *)
END http.

View file

@ -7,7 +7,7 @@ test: clean copy-version-file-to-build-dir all run
copy-version-file-to-build-dir:
cp ./$(VERSION_FILE) ./builds/$(VERSION_FILE)
all:
all: http
cd builds && \
$(VOC) -s \
../time.Mod \
@ -35,5 +35,4 @@ http: clean
../sockets.Mod \
../netdb.Mod \
../Internet.Mod \
../http.Mod -m \
&& ./http
../http.Mod

View file

@ -19,13 +19,12 @@ PROCEDURE parseArgs(VAR argument: ARRAY OF CHAR);
BEGIN
COPY("", argument);
IF Args.argc > 1 THEN Args.Get(1, argument) END;
END parseArgs;
BEGIN
parseArgs(command);
IF Strings.Match(command, "") THEN
IF Strings.Match(command, "") OR Strings.Match(command, "--help")THEN
help;
ELSIF Strings.Match(command, "install") THEN
PackageFileParser.install();