aboutsummaryrefslogtreecommitdiffstats
path: root/include/util.hpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--include/util.hpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/include/util.hpp b/include/util.hpp
index 51783a1..d3ba6e1 100644
--- a/include/util.hpp
+++ b/include/util.hpp
@@ -1,8 +1,12 @@
+// Author Name: Matt Strapp
+// Date: 25 April 2022
+// x500: strap012
#ifndef UTIL_H
#define UTIL_H
// Get your libraries here
#include <arpa/inet.h>
+#include <cstddef>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
@@ -15,6 +19,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <string>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/timeb.h>
@@ -23,7 +28,7 @@
#include <unistd.h>
#define NAME "SERVER"
-#define ANON "Anonymous"
+#define ANON "ANON"
#define LINE_SIZE 5000 // overkill
#define BUF_LEN 12000000 // overkill
@@ -32,6 +37,7 @@
#define MAX_USERNAME_LEN 8
#define MIN_PASSWORD_LEN 4
#define MAX_PASSWORD_LEN 8
+#define MAX_COMMAND_LEN 10
enum Command {
REGISTER = 0, // [username] [password] Register a new account
@@ -48,9 +54,9 @@ enum Command {
DELAY = 10, // [N] A special command that delays for N seconds before
// executing the next command in the script
- GETF = 11, // [filename] Server telling clinet to request a file, clinet
- // requesting a file
- PING = 12, // Check that connection is still there (nop)
+ GETF = 11, // [filename] Server telling clinet to request a file, clinet
+ // requesting a file
+ PING = 12, // Check that connection is still there, doesn't do anything else
CONNECT = 13, // [unique id] Allows the server to identify specific users when
// they are logged in multiple times
@@ -63,17 +69,17 @@ typedef unsigned char BYTE;
typedef unsigned int DWORD;
typedef unsigned short WORD;
-enum Command parse_command(char *line);
+Command parse_command(char *line);
bool isValidUsername(char *username);
bool isValidPassword(char *password);
void Error(const char *format, ...);
void Log(const char *format, ...);
-void buf2i(BYTE *buf, int &i);
-void i2buf(int &i, BYTE *buf);
+void BigEndianToLittle(BYTE *buf, int &i);
+void LittleEndianToBig(int &i, BYTE *buf);
-const char *com2str(enum Command command);
+const char *com2str(Command command);
double timeDifference(struct timeb a, struct timeb b);
@@ -99,7 +105,7 @@ public:
enum Flag m_flag;
enum Recipient m_recipient;
enum Trace m_trace;
- enum Command m_command;
+ Command m_command;
BYTE m_name[9];