Question: Can someone tell me what the functions writeArticle, readArticle, and listArticles do in this C program? Please go into as much detail as possible. Thank













Can someone tell me what the functions writeArticle, readArticle, and listArticles do in this C program? Please go into as much detail as possible. Thank you!
#include #include #include #include #include #include #include #include #include #include #include #include #define PORT 9090 #define USERNAME @x01 #define PASSWORD Ox02 #define BADUSER "\x33\x44 BAD USERNAME!" #define BADPASS "\x33\x45 BAD PASSWORD!" #define READY "\x41\x41 READY!" #define USERPATH"./users/" #define ARTICLEPATH "./articles/" #define LISTCOMMAND "ls ./articles/ > list.txt" #define FILENOTAVAIL "\x33\x31 FILE NOT AVAILABLE!" #define BEGINFILE "\x41\x41 BEGIN FILE: END WITH '!!!'" #define ARTICLEWROTE "\x41\x42 ARTICLE HAS BEEN WRITTEN!" #define LIST_ARTICLES @x22 #define READ_ARTICLE @x23 #define WRITE_ARTICLE 6x24 #define COMMAND @x25 #define ADD_USER 8x26 void logData(FILE *logfile, char *format, ...); int setupSock(FILE *logf, unsigned short port); int writeSock(int sock, char *buf, size_t len); int readSock(int sock, char *buf, size_t len); void mainLoop(FILE *logf, int sock); void handleConnection (FILE *logfile, int sock); int userFunctions (FILE *logfile, int sock, char *user); char *findarg(char *argbuf, char argtype); int authenticate(FILE *logfile, char *user, char *pass); int writesock(int sock, char *buf, size_t len) { ssize_t byteswrote = 0; ssize_t ret = 0; while (byteswrote 0) { printf("circle of life completed for %i ", pid); } int setupsock(FILE *logf, unsigned short port) { int sock = 0; struct sockaddr_in sin; int opt = 0; if (signal(SIGCHLD, spawnhandler)== SIG_ERR) { perror("fork() spawn handler setup failed!"); return -1; } memset((char *)&sin, e, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons (port); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == -1) { logData(logf, "socket() failed"); return -1; } opt = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1) { logData(logf, "setsockopt() failed"); return -1; } == -1) if (bind (sock, (struct sockaddr *)&sin, sizeof(sin)) { logData(logf, "bind failed"); return -1; } if (listen (sock, 10) == -1) { logData(logf, "listen() failed"); return -1; } return sock; } int main(int argc, char *argv[]) { int sock; FILE *logf; /* setup log file */ logf = fopen("logfile.txt", "W"); if (!logf) { perror("unable to open log file "); exit(1); } /* go daemon */ daemon (0,0); /* setup socket / sock = setupsock(logf, PORT); if (sock == -1) { logData(logf, "failed to setup socket, exiting"); exit(1); } logData(logf, "intial socket setup complete"); mainLoop(logf, sock); /* this should never execute */ exit(); } /* printf-style data logging */ void logData(FILE Slogfile, char *format, ...) { char buffer[4096]; va_list arguments; va_start(arguments, format); vsnprintf(buffer, sizeof(buffer)-1, format, arguments); va_end(arguments); fprintf(logfile, "LoggedData [Proccess:%i]: %s ", getpido, buffer); fflush(logfile); } #include #include #include #include #include #include #include #include #include #include #include #include #define PORT 9090 #define USERNAME @x01 #define PASSWORD Ox02 #define BADUSER "\x33\x44 BAD USERNAME!" #define BADPASS "\x33\x45 BAD PASSWORD!" #define READY "\x41\x41 READY!" #define USERPATH"./users/" #define ARTICLEPATH "./articles/" #define LISTCOMMAND "ls ./articles/ > list.txt" #define FILENOTAVAIL "\x33\x31 FILE NOT AVAILABLE!" #define BEGINFILE "\x41\x41 BEGIN FILE: END WITH '!!!'" #define ARTICLEWROTE "\x41\x42 ARTICLE HAS BEEN WRITTEN!" #define LIST_ARTICLES @x22 #define READ_ARTICLE @x23 #define WRITE_ARTICLE 6x24 #define COMMAND @x25 #define ADD_USER 8x26 void logData(FILE *logfile, char *format, ...); int setupSock(FILE *logf, unsigned short port); int writeSock(int sock, char *buf, size_t len); int readSock(int sock, char *buf, size_t len); void mainLoop(FILE *logf, int sock); void handleConnection (FILE *logfile, int sock); int userFunctions (FILE *logfile, int sock, char *user); char *findarg(char *argbuf, char argtype); int authenticate(FILE *logfile, char *user, char *pass); int writesock(int sock, char *buf, size_t len) { ssize_t byteswrote = 0; ssize_t ret = 0; while (byteswrote 0) { printf("circle of life completed for %i ", pid); } int setupsock(FILE *logf, unsigned short port) { int sock = 0; struct sockaddr_in sin; int opt = 0; if (signal(SIGCHLD, spawnhandler)== SIG_ERR) { perror("fork() spawn handler setup failed!"); return -1; } memset((char *)&sin, e, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons (port); sock = socket(AF_INET, SOCK_STREAM, 0); if (sock == -1) { logData(logf, "socket() failed"); return -1; } opt = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1) { logData(logf, "setsockopt() failed"); return -1; } == -1) if (bind (sock, (struct sockaddr *)&sin, sizeof(sin)) { logData(logf, "bind failed"); return -1; } if (listen (sock, 10) == -1) { logData(logf, "listen() failed"); return -1; } return sock; } int main(int argc, char *argv[]) { int sock; FILE *logf; /* setup log file */ logf = fopen("logfile.txt", "W"); if (!logf) { perror("unable to open log file "); exit(1); } /* go daemon */ daemon (0,0); /* setup socket / sock = setupsock(logf, PORT); if (sock == -1) { logData(logf, "failed to setup socket, exiting"); exit(1); } logData(logf, "intial socket setup complete"); mainLoop(logf, sock); /* this should never execute */ exit(); } /* printf-style data logging */ void logData(FILE Slogfile, char *format, ...) { char buffer[4096]; va_list arguments; va_start(arguments, format); vsnprintf(buffer, sizeof(buffer)-1, format, arguments); va_end(arguments); fprintf(logfile, "LoggedData [Proccess:%i]: %s ", getpido, buffer); fflush(logfile); }