diff options
author | Ian C <ianc@noddybox.co.uk> | 2020-03-03 19:35:15 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2020-03-03 19:35:15 +0000 |
commit | 3a5ef7e3652628339d790a0c9a40ae6081ee2770 (patch) | |
tree | 498893e9a4eb35233194a3242b9280d87c364550 | |
parent | 578c14949b6ca1ec83cef75b3c7d8e7c7dc5379a (diff) |
Changed so that the UNIX portion is a server.
-rw-r--r-- | client/Makefile | 5 | ||||
-rw-r--r-- | server/Makefile | 5 | ||||
-rw-r--r-- | server/nfts.c (renamed from client/nft.c) | 109 | ||||
-rw-r--r-- | server/spectrum.tap | bin | 0 -> 107 bytes |
4 files changed, 107 insertions, 12 deletions
diff --git a/client/Makefile b/client/Makefile deleted file mode 100644 index 9869b14..0000000 --- a/client/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -nft: nft.c - $(CC) -o nft nft.c - -clean: - rm -f nft core nft.exe diff --git a/server/Makefile b/server/Makefile new file mode 100644 index 0000000..4be1a08 --- /dev/null +++ b/server/Makefile @@ -0,0 +1,5 @@ +nfts: nfts.c + $(CC) -o nfts nfts.c + +clean: + rm -f nfts core nfts.exe diff --git a/client/nft.c b/server/nfts.c index 9d03295..18ab896 100644 --- a/client/nft.c +++ b/server/nfts.c @@ -175,15 +175,15 @@ static int WriteBlock(int sock, const char *block, size_t len) { char buff[32]; - if (len > 99999) + if (len > 999999) { fprintf(stderr, "%s: length of block %zu too large\n", name, len); return 0; } - snprintf(buff, sizeof buff, "%.5zu", len); + snprintf(buff, sizeof buff, "%.6zu", len); - if (!Write(sock, buff, 5)) + if (!Write(sock, buff, 6)) { return 0; } @@ -201,7 +201,7 @@ static size_t ReadSize(int sock) { char buff[32]; - if (!Read(sock, buff, 5)) + if (!Read(sock, buff, 6)) { return 0; } @@ -268,12 +268,21 @@ static int Put(int sock, const char *path) { printf("Command failed\n"); } + else if (strcmp(status, "OK") == 0) + { + printf("OK\n"); + } + else + { + printf("Unknown status '%s'\n", status); + } } else { quit = 1; } + free(buff); } return quit; @@ -286,7 +295,7 @@ static int Get(int sock, const char *path) char status[3] = {0}; int fd; - if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC)) == -1) + if ((fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { perror(path); return 0; @@ -308,13 +317,17 @@ static int Get(int sock, const char *path) { printf("Command failed\n"); } - else + else if (strcmp(status, "OK") == 0) { size_t len; + printf("OK\n"); + if ((len = ReadSize(sock)) > 0) { - char buff[100000]; + char *buff; + + buff = Malloc(len); if (Read(sock, buff, len)) { @@ -326,6 +339,10 @@ static int Get(int sock, const char *path) } } } + else + { + printf("Unknown status '%s'\n", status); + } } else { @@ -341,6 +358,46 @@ static int Get(int sock, const char *path) static int Cd(int sock, const char *path) { int quit = 0; + char status[3] = {0}; + size_t len; + int fd; + + if (path) + { + if (!Write(sock, "CD", 2)) + { + quit = 1; + } + + if (!quit && !WriteBlock(sock, path, strlen(path))) + { + quit = 1; + } + + if (!quit && Read(sock, status, 2)) + { + if (strcmp(status, "!E") == 0) + { + printf("Command failed\n"); + } + else if (strcmp(status, "OK") == 0) + { + printf("OK\n"); + } + else + { + printf("Unknown status '%s'\n", status); + } + } + else + { + quit = 1; + } + } + else + { + printf("Missing path\n"); + } return quit; } @@ -349,6 +406,44 @@ static int Cd(int sock, const char *path) static int Mkdir(int sock, const char *path) { int quit = 0; + char status[3] = {0}; + + if (path) + { + if (!Write(sock, "MD", 2)) + { + quit = 1; + } + + if (!quit && !WriteBlock(sock, path, strlen(path))) + { + quit = 1; + } + + if (!quit && Read(sock, status, 2)) + { + if (strcmp(status, "!E") == 0) + { + printf("Command failed\n"); + } + else if (strcmp(status, "OK") == 0) + { + printf("OK\n"); + } + else + { + printf("Unknown status '%s'\n", status); + } + } + else + { + quit = 1; + } + } + else + { + printf("Missing path\n"); + } return quit; } diff --git a/server/spectrum.tap b/server/spectrum.tap Binary files differnew file mode 100644 index 0000000..3b5ad43 --- /dev/null +++ b/server/spectrum.tap |