Skip to content

sekharpariga/dlisting

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

92 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

					Directory Listing Server
					------------------------

This is a simple directory listing server, that serves ls, cd, pwd of directory functions.

	Server is implemented using multi-thread pthread library. So, Server has the capability of serving multiple clients parallely.
server keeps the each accepted client session details in the session queue. In each session queue node cantains connected clients path detial.


command and function mappings

commands			function
--------			--------
ls				lsfun
cd				cdfun


client command:
--------------

ls:
--
	when client sends ls to the server, lsfun checks the pwd of client from queue node and list the files under it.

cd:
--
	When client sends "cd <path>" to server, then server updates the clinet session path varable relative to server pwd dir.

pwd:
---
	When server recieves "pwd" form the client, server replies the stored session path variable value. Initial client pwd is
	servers's working dir.

bye:
---
	When server recieves "bye" from the client, server closes connection by removing the respective session data from session queue.


Queue data structure details:
----------------------------

	typedef struct node 
	{
	        int *client_socket;
	        char pwd[PATH_MAX];
	        struct node *next;
	} node_t;

	node *head, *tail;
	void enqueue(int *client_socket, char *pwd);
	node_t *dequeue();

enqueue:
-------
	when client successfully connects to server, this function creates the above queue node into the queue.

dequeue:
-------
	when client sends "bye", server removes the clients queue node and closes the client connection.


Multi-threading:
---------------
	when server successfully starts, it will create thread pool of max THREADPOOL threads.
server uses pthread mutex lock to syn operations on adjusting session queue data.


Instructions to build:
----------------------
make build system is used to compile the entire code.

1. make 	--- will build the server.o and client.o linux executables
2. make clean	--- cleans the previod build cleared (deleted obj files created).

dlisting :make
gcc -g -Wall -Wextra -pedantic  -c common.c -o common.o
gcc -g -Wall -Wextra -pedantic  -c queue.c -o queue.o
gcc -g -Wall -Wextra -pedantic  server.c common.o queue.o -o server.o -lpthread
gcc -g -Wall -Wextra -pedantic  client.c -o client.o

server/client running output:
----------------------------

dlisting :./server.o 
new conn:4
closed conn:4

dlisting :./client.o 

pwd
/root/dlisting

cd ../..

pwd
/
ls -lrt
dir	tmp	Mon Feb  1 09:18:07 2021
dir	proc	Thu Jan  1 00:00:06 1970
dir	boot	Thu Jan  1 00:00:00 1970
dir	lib	Mon Feb  1 08:36:52 2021
dir	dev	Sat Jan 30 12:19:13 2021
dir	bin	Mon Feb  1 08:35:03 2021
dir	srv	Mon Oct 26 17:34:43 2020
dir	opt	Wed Oct 14 18:56:06 2020
dir	etc	Mon Feb  1 08:36:53 2021
dir	run	Sat Jan 30 12:19:20 2021
dir	root	Mon Feb  1 09:18:05 2021
dir	usr	Mon Feb  1 08:36:59 2021
dir	home	Mon Dec 21 15:55:36 2020
dir	sbin	Mon Feb  1 08:35:03 2021
dir	var	Mon Dec 21 03:51:56 2020
dir	sys	Thu Jan  1 00:00:06 1970
dir	mnt	Sat Oct 10 13:22:42 2020

bye
dlisting :

Limitations:
-----------
2. PATH Size is 4096 bytes

Assumptions:
-----------
1. added birthtime macro for handling missing of file birthtime in some OS.

Linux distribution info: 
-----------------------
Distributor ID		: ArchLinux
Description		: Linux Rolling
Release			: 2021.1
gcc version		: gcc (GCC) 10.2.0

configuration settings file : common.h

About

Directory Listing Server/Client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published