Skip to content

Commit

Permalink
Removed useless arguments around
Browse files Browse the repository at this point in the history
  • Loading branch information
lucabtz committed Nov 6, 2024
1 parent 7e69a4c commit 8071a28
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
2 changes: 1 addition & 1 deletion client/include/fraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ typedef struct {
uint8_t *data;
} fraction_t;

int download_fraction(int sfd, char *url, fraction_t *fraction);
int download_fraction(int sfd, fraction_t *fraction);
int fraction_parse(char *data, size_t size, fraction_t *fraction);
int check_magic(uint32_t data);
void print_fraction(fraction_t fraction);
Expand Down
13 changes: 2 additions & 11 deletions client/src/fraction.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
#include "../include/fraction.h"
#include "../include/crc32.h"

int download_fraction(int sfd, char *url, fraction_t *fraction) {
char *path = NULL;
int download_fraction(int sfd, fraction_t *fraction) {
http_res_t res;
fraction_t downloaded_fraction = {};

// Parse the URL to get the path
path = get_path_from_url(url);
if (!path) {
log_error("Invalid URL: %s", url);
return 1;
}

// Perform the HTTP GET request
if (http_get(sfd, path, &res) != HTTP_SUCCESS) {
log_error("Failed to download: %s", url);
if (http_get(sfd, "/stream", &res) != HTTP_SUCCESS) {
return 1;
}

Expand Down
10 changes: 3 additions & 7 deletions client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,12 @@ static uint8_t *get_aes_key(int sfd, size_t *key_length) {
return aes_key;
}

static fraction_t *fetch_fractions(int sfd, int *fraction_count,
char *ip_address, char *port) {
static fraction_t *fetch_fractions(int sfd, int *fraction_count) {
http_res_t http_fraction_res = {0};

fraction_t *fractions = NULL;
char fraction_url[50];
int i, num_fractions;

snprintf(fraction_url, 50, "http://%s:%s/stream", ip_address, port);

if (http_get(sfd, "/size", &http_fraction_res) != HTTP_SUCCESS) {
log_error("Failed to retrieve fraction links");
}
Expand All @@ -123,7 +119,7 @@ static fraction_t *fetch_fractions(int sfd, int *fraction_count,
for (i = 0; i < num_fractions; i++) {
log_debug("Downloading fraction no.%d", i);

if (download_fraction(sfd, fraction_url, &fractions[i]) != 0) {
if (download_fraction(sfd, &fractions[i]) != 0) {
log_error("Failed to download fraction");

// we have to cleanup only until i because the other fractions have not
Expand Down Expand Up @@ -221,7 +217,7 @@ int main(int argc, char **argv) {
}

/* download and sort the fractions*/
fractions = fetch_fractions(sfd, &fraction_count, ip_address, port);
fractions = fetch_fractions(sfd, &fraction_count);
if (fractions == NULL) {
goto cleanup;
}
Expand Down

0 comments on commit 8071a28

Please sign in to comment.