Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/roadmap/phase-0/stage-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ Now that `buff` has the reversed string, it is time to send it to the client. We

---

The final code should look like this.
The final code should look like this. {#tcp-server-c}


<a id="tcp-server-c"></a>
::: details expserver/phase_0/tcp_server.c


Expand Down
1 change: 0 additions & 1 deletion docs/roadmap/phase-0/stage-4.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ event flags indicating which I/O conditions to monitor (`EPOLLIN`, `EPOLLOUT`, e

<!--since nested block is not possible this is a workaround using HTML code-->
<div class="custom-block danger">
<p class="custom-block-title">NOTE</p>
<p>
In this project, the results of <code>epoll_wait()</code> are kept in an array
named <code>events</code>, so the event flags naturally appear in the code as
Expand Down
25 changes: 13 additions & 12 deletions docs/roadmap/phase-1/stage-11.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ The below is the code for the header file `xps_upstream.h`. Have a look at it an
::: details **expserver/src/network/xps_upstream.h**

```c
#ifndef XPS_UPSTREAM_H
#define XPS_UPSTREAM_H
#include "../xps.h"
xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int port);
#endif
#ifndef XPS_UPSTREAM_H
#define XPS_UPSTREAM_H

#include "../xps.h"

xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int port);

#endif
```
:::

Expand All @@ -57,9 +57,7 @@ The below is the code for the header file `xps_upstream.h`. Have a look at it an
xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int port) {
/* validate parameter */

/* create a socket and connect to host and port to upstream using xps_getaddrinfo and connect function */


/* create a socket and connect to host and port to upstream using xps_getaddrinfo and connect function */

if (!(connect_error == 0 || errno == EINPROGRESS)) {
logger(LOG_ERROR, "xps_upstream_create()", "connect() failed");
Expand All @@ -74,6 +72,9 @@ xps_connection_t *xps_upstream_create(xps_core_t *core, const char *host, u_int
return connection;
}
```
:::warning
Dont forget to free allocated struct addrinfo
:::

## Modifications to listener module

Expand Down Expand Up @@ -105,7 +106,7 @@ void listener_connection_handler(void *ptr) {

/* create upstream connection */
/*create pipe connection to client source and upstream sink for the listener*/
/*create pipe a connection to upstream source and client sink for the listener*/
/*create pipe connection to upstream source and client sink for the listener*/
} else {
/* same as previous stages*/

Expand Down
12 changes: 6 additions & 6 deletions docs/roadmap/phase-1/stage-12.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Create a new folder disk in src, this would be used for adding necessary modules

The code below has the contents of the header file for `xps_mime`. Have a look at it and make a copy of it in your codebase.

:::details **expserver/src/disc/xps_mime.h**
:::details **expserver/src/disk/xps_mime.h**

```c
#ifndef XPS_MIME_H
Expand All @@ -52,7 +52,7 @@ const char *xps_get_mime(const char *file_path);

The function `xps_get_mime()` returns the MIME type of a file based on its extension. A MIME type lookup table (`mime_types`) maps file extensions (e.g., ".html", ".jpg") to their corresponding MIME types (e.g., "text/html", "image/jpeg"). This tells the browser how to display or interact with the file. For example, an HTML file is rendered as a web page, while an image is displayed as a picture. We won’t be using this functionality in the present stage but would be looking into in later stages.

:::details **expserver/src/disc/xps_mime.c**
:::details **expserver/src/disk/xps_mime.c**

```c
#include "../xps.h"
Expand Down Expand Up @@ -88,7 +88,7 @@ const char *xps_get_mime(const char *file_path) {
```
:::

As we are mapping the MIME type based on the file extension, a function for finding the file extension is added in `xps_utility`. Add the below given function in utility.c
As we are mapping the MIME type based on the file extension, a function for finding the file extension is added in `xps_utils.h`. Add the below given function in `xps_utils.c`

```c
const char *get_file_ext(const char *file_path) {
Expand All @@ -108,7 +108,7 @@ Also declare the newly created function in utility.h

The code below has the contents of the header file for `xps_file`. Have a look at it and make a copy of it in your codebase.

:::details **expserver/src/disc/xps_file.h**
:::details **expserver/src/disk/xps_file.h**

```c
#ifndef XPS_FILE_H
Expand Down Expand Up @@ -157,7 +157,7 @@ Several file system-related C standard library functions are used to handle file
FILE *fopen(const char *filename, const char *mode);
```

Opens a file specified by filename and returns a pointer to a FILE structure that represents the file stream. If mode given as “rb”, it opens the file in binary read mode. **Returns**: A pointer to a FILE structure if successful, or NULL if the file cannot be opened .
Opens a file specified by filename and returns a pointer to a FILE structure that represents the file stream. If mode given as “rb”, it opens the file in binary read mode. **Returns**: A pointer to a FILE structure if successful, or NULL if the file cannot be opened.

- `fclose()`

Expand Down Expand Up @@ -241,7 +241,7 @@ The functions in xps_file.c are given below:
FILE *file_struct = fopen(file_path, "rb");
/*handle EACCES,ENOENT or any other error*/
if (file_struct == NULL) {
/*logs EACCES,ENOENT or any other error*/
/*logs EACCES,ENOENT or any other error*/
return NULL;
}

Expand Down
28 changes: 21 additions & 7 deletions docs/roadmap/phase-1/stage-13.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ xps_session_t *xps_session_create(xps_core_t *core, xps_connection_t *client) {
// Alloc memory for session instance
xps_session_t *session = /* fill this */
if (session == NULL) {
logger(LOG_ERROR, "xps_session_create()", "malloc() failed fro 'session'");
logger(LOG_ERROR, "xps_session_create()", "malloc() failed for 'session'");
return NULL;
}

Expand Down Expand Up @@ -190,14 +190,28 @@ xps_session_t *xps_session_create(xps_core_t *core, xps_connection_t *client) {

if (client->listener->port == 8001) {
xps_connection_t *upstream = /* fill this */
xps_pipe_create(/* fill this */)
xps_pipe_create(/* fill this */)
if (upstream == NULL) {
logger(LOG_ERROR, "xps_session_create()", "xps_upstream_create() failed");
perror("Error message");
/* destroy session */
return NULL;
}
session->upstream = /* fill this */;
xps_pipe_create(/* fill this */);
xps_pipe_create(/* fill this */);
}

else if (client->listener->port == 8002) {
int error;
xps_file_t *file = xps_file_create(/* fill this */)
xps_pipe_create(/* fill this */)
xps_file_t *file = xps_file_create(/* fill this */);
if (file == NULL) {
logger(LOG_ERROR, "xps_session_create()", "xps_file_create() failed");
perror("Error message");
/*destory session*/
return NULL;
}
/* assign to the file member */
xps_pipe_create(/* fill this */);
}

return session;
Expand Down Expand Up @@ -491,12 +505,12 @@ void listener_connection_handler(void *ptr) {
continue;
}
client->listener = listener;

// TEMP

xps_session_t *session = /* fill this */ ;
if (session == NULL) {
logger(LOG_ERROR, "listener_connection_handler()", "xps_session_create() failed");
xps_connection_destroy(client);
return;
}

logger(LOG_INFO, "listener_connection_handler()", "new connection");
Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap/phase-1/stage-6.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ In Stage 5, we had three types of events that could occur in epoll:
Since this stage involves receiving a message from the client, reversing it and sending it back, we won’t not be needing upstream. We will work on the first two types of events:

::: tip NOTE
Upstream will have its own module (`xps_upstream`) and will be implemented in Stage 9.
Upstream will have its own module (`xps_upstream`) and will be implemented in Stage 11.
:::

- **Read event on listening socket:**
Expand Down
2 changes: 1 addition & 1 deletion docs/roadmap/phase-1/stage-7.md
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ Since we did not modify the functionality of the server, this milestone will is
return -1;
}

if (connect(sock, (struct sockaddr \*)&serv_addr, sizeof(serv_addr)) < 0) {
if (connect(sock, (struct sockaddr* )&serv_addr, sizeof(serv_addr)) < 0) {
perror("Connection failed");
return -1;
}
Expand Down
Loading