refactor: extract user authentication logic into dedicated service class with dependency injection
This commit is contained in:
+9
-7
@@ -10,6 +10,8 @@
|
||||
#include <regex.h>
|
||||
#include "http.h"
|
||||
#include "url.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void extract_urls(const char *input, char **urls, int *url_count) {
|
||||
const char *pattern = "https?://[^ ]+";
|
||||
@@ -29,18 +31,18 @@ void extract_urls(const char *input, char **urls, int *url_count) {
|
||||
regfree(®ex);
|
||||
}
|
||||
|
||||
void inplace_urls_markdown_style(char *input, char **urls, char **contents, int url_count) {
|
||||
void inplace_urls_markdown_style(char **input, char **urls, char **contents, int url_count) {
|
||||
for (int i = 0; i < url_count; i++) {
|
||||
char *found = strstr(input, urls[i]);
|
||||
char *found = strstr(*input, urls[i]);
|
||||
if (found) {
|
||||
char *new_text = (char *)malloc(strlen(input) + strlen(contents[i]) - strlen(urls[i]) + 1);
|
||||
strncpy(new_text, input, found - input);
|
||||
new_text[found - input] = '\0';
|
||||
char *new_text = (char *)malloc(strlen(*input) + strlen(contents[i]) - strlen(urls[i]) + 1);
|
||||
strncpy(new_text, *input, found - *input);
|
||||
new_text[found - *input] = '\0';
|
||||
strcat(new_text, contents[i]);
|
||||
strcat(new_text, found + strlen(urls[i]));
|
||||
|
||||
free(input);
|
||||
input = new_text;
|
||||
free(*input);
|
||||
*input = new_text;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user