-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from lil-skelly:client-http-post
[REFACTOR] Improved the HTTP library
- Loading branch information
Showing
8 changed files
with
189 additions
and
63 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,45 @@ | ||
#include "utils.h" | ||
|
||
// if this dont work DeLuks is to blame :) - it worked, kinda (skelly) :D | ||
// if this dont work Skelly is to blame ;) | ||
int split_fraction_links(char *data, char *data_arr[], int maxlines) { | ||
int lines_read = 0; | ||
char *line; | ||
|
||
char *tmp_str = strdup(data); | ||
if (tmp_str == NULL) { | ||
fprintf(stderr, "strdup failed to allocate memory\n"); | ||
return -1; | ||
} | ||
|
||
line = strtok(tmp_str, "\n"); | ||
// Use the input `data` directly, no need for strdup | ||
line = strtok(data, "\n"); | ||
while (line != NULL && lines_read < maxlines) { | ||
data_arr[lines_read] = malloc(strlen(line) + 1); | ||
data_arr[lines_read] = strdup(line); | ||
if (data_arr[lines_read] == NULL) { | ||
fprintf(stderr, "malloc failed to allocate memory for data array\n"); | ||
free(tmp_str); | ||
// Free previously allocated memory in case of failure | ||
fprintf(stderr, "strdup failed to allocate memory\n"); | ||
// Free previously allocated lines in case of failure | ||
for (int i = 0; i < lines_read; i++) { | ||
free(data_arr[i]); | ||
} | ||
return -1; | ||
} | ||
|
||
strcpy(data_arr[lines_read], line); | ||
line = strtok(NULL, "\n"); | ||
lines_read++; | ||
line = strtok(NULL, "\n"); | ||
} | ||
|
||
free(tmp_str); | ||
return lines_read; | ||
} | ||
|
||
|
||
char *get_path_from_url(const char *url) { | ||
const char *path_start = strstr(url, "://"); | ||
if (!path_start) { | ||
perror("There was a error with the URL"); | ||
return NULL; | ||
} | ||
|
||
path_start += 3; // Skip past "://" | ||
|
||
// Find the first '/' after the host part | ||
char *path = strchr(path_start, '/'); | ||
if (!path) { | ||
perror("No string found!"); | ||
return ""; | ||
} | ||
|
||
return path; | ||
} |
Oops, something went wrong.