Skip to content

This is a web server written in pure C with 0 memory leaks.

Notifications You must be signed in to change notification settings

parrwiz/webserver-in-C

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chat Server

Overview

This project is a simple chat server implemented in C. The server supports sending and receiving messages, adding reactions to messages, and editing messages. It uses a Makefile for compilation.

Features

  • Send Chat: Users can send messages to the server.
  • Receive Messages: Users can retrieve all messages from the server.
  • Add Reactions: Users can add reactions to specific messages.
  • Edit Messages: Users can edit their messages.
  • Reset Server: Administrators can reset the server data.

Getting Started

Prerequisites

  • A C compiler (e.g., GCC)
  • Make

Installation

  1. Clone the repository:
    git clone https://github.com/your-username/chat-server.git
    cd chat-server
  2. Compile the server using Make:
  make

Running the server

Start the server by specifying the port number:

./chat-server <port>

For example, to start the server on port 8080:

./chat-server 8080

API Endpoints

Send a Message Endpoint: /post Method: POST

Parameters:

user: The username of the sender. message: The message content. Retrieve Messages Endpoint: /chats Method: GET

Add a Reaction Endpoint: /react Method: POST Parameters: user: The username of the reactor. message: The reaction content. id: The ID of the message to react to.

Edit a Message Endpoint: /edit Method: POST

Parameters: id: The ID of the message to edit. message: The new message content. Reset Server Data Endpoint: /reset Method: GET

Code Structure Data Structures

Reaction: Represents a reaction to a message.

struct Reaction {
    char user[USERNAME_SIZE];
    char message[REACTION_SIZE];
};

Chat: Represents a chat message with reactions.

struct Chat {
    uint32_t id;
    char user[USERNAME_SIZE];
    char message[MESSAGE_SIZE];
    char timestamp[TIMESTAMP_SIZE];
    uint32_t num_reactions;
    Reaction reactions[MAX_REACTIONS];
};

Functions

handle_404: Handles 404 Not Found responses.
url_decode: Decodes URL-encoded strings.
add_chat: Adds a new chat message.
add_reaction: Adds a reaction to a chat message.
reset: Resets the server data.
respond_with_chats: Sends all chat messages to the client.
edit_chat: Edits an existing chat message.
handle_edit: Handles edit requests.
handle_post: Handles new message posts.
handle_reaction: Handles reaction additions.
handle_response: Main request handler.
main: Entry point of the server.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Contact

For any questions or support, please contact [email protected]

About

This is a web server written in pure C with 0 memory leaks.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages