Compare commits

...

15 Commits

27 changed files with 337 additions and 224 deletions

4
.clang-format Normal file
View File

@ -0,0 +1,4 @@
IndentWidth: 4
BreakBeforeBraces: Allman
ColumnLimit: 0
SortIncludes: false

View File

@ -4,7 +4,9 @@ RUN apk add --no-cache build-base
WORKDIR /app
COPY . .
COPY Makefile .
COPY src src/
COPY include include/
RUN make
@ -12,8 +14,8 @@ FROM alpine
WORKDIR /srv
COPY --from=builder /app .
COPY static static/
RUN apk add --no-cache gcompat
COPY --from=builder /app/build/server .
CMD ["build/server", "5000"]
CMD ["./server", "5000"]

View File

@ -8,7 +8,7 @@
#include <dirent.h>
void err_msg(char *msg);
char *concat_to_front(char **str1, char *str2);
char *prepend(char *dest, const char *prefix);
char *get_status_message(int status_code);
char *to_lower(char *str);
char *trim(char *str);

View File

@ -45,7 +45,7 @@ int list_articles(article_info **articles)
else
(*articles)[articles_amount - 1].title = strdup("No title");
(*articles)[articles_amount - 1].content = malloc(0);
(*articles)[articles_amount - 1].content = NULL;
free(tmp);
@ -124,7 +124,7 @@ void free_article_info_arr(article_info **articles, int length)
// /* Only for testing purposes */
// int main()
// {
// article_info *articles = malloc(0);
// article_info *articles = NULL;
// int n = list_articles(&articles);

View File

@ -84,7 +84,7 @@ int gen_html_article_list(article_info *articles, int n, char **out)
// /* Only for testing purposes */
// int main ()
// {
// article_info *articles = malloc(0);
// article_info *articles = NULL;
// int n = list_articles(&articles);

View File

@ -23,7 +23,7 @@ int process_md(article_info article, char **out)
}
else
{
snippet = "<pre><code>\n";
snippet = "<pre><code>";
is_in_code = 1;
}
@ -217,41 +217,41 @@ int process_md(article_info article, char **out)
while (buff[i + 2 + n] != ']')
n++;
if (buff[i + 2 + n + 1] != '(')
continue;
int k = 0;
while (buff[i + 2 + n + 2 + k] != ')')
k++;
char *internal_text = malloc(n + 1);
memcpy(internal_text, buff + i + 2, n);
internal_text[n] = '\0';
char *src = malloc(k + 1);
memcpy(src, buff + i + 2 + n + 2, k);
src[k] = '\0';
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text) + 1;
char *append = malloc(append_line_length);
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
if (append == NULL || tmp_out == NULL)
if (buff[i + 2 + n + 1] == '(')
{
perror("Couldn't allocate memory for new element");
int k = 0;
while (buff[i + 2 + n + 2 + k] != ')')
k++;
char *internal_text = malloc(n + 1);
memcpy(internal_text, buff + i + 2, n);
internal_text[n] = '\0';
char *src = malloc(k + 1);
memcpy(src, buff + i + 2 + n + 2, k);
src[k] = '\0';
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text) + 1;
char *append = malloc(append_line_length);
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
if (append == NULL || tmp_out == NULL)
{
perror("Couldn't allocate memory for new element");
continue;
}
*out = tmp_out;
snprintf(append, append_line_length, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text);
strcat(*out, append);
i += 2 + n + 2 + k;
free(append);
free(src);
free(internal_text);
continue;
}
*out = tmp_out;
snprintf(append, append_line_length, "<a href=\"%s\"><img src=\"%s\" alt=\"%s\"></a>", src, src, internal_text);
strcat(*out, append);
i += 2 + n + 2 + k;
free(append);
free(src);
free(internal_text);
continue;
}
if (buff[i] == '[')
@ -260,41 +260,41 @@ int process_md(article_info article, char **out)
while (buff[i + 1 + n] != ']')
n++;
if (buff[i + 1 + n + 1] != '(')
continue;
int k = 0;
while (buff[i + 1 + n + 2 + k] != ')')
k++;
char *internal_text = malloc(n + 1);
memcpy(internal_text, buff + i + 1, n);
internal_text[n] = '\0';
char *href = malloc(k + 1);
memcpy(href, buff + i + 1 + n + 2, k);
href[k] = '\0';
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\">%s</a>", href, internal_text) + 1;
char *append = malloc(append_line_length);
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
if (append == NULL || tmp_out == NULL)
if (buff[i + 1 + n + 1] == '(')
{
perror("Couldn't allocate memory for new element");
int k = 0;
while (buff[i + 1 + n + 2 + k] != ')')
k++;
char *internal_text = malloc(n + 1);
memcpy(internal_text, buff + i + 1, n);
internal_text[n] = '\0';
char *href = malloc(k + 1);
memcpy(href, buff + i + 1 + n + 2, k);
href[k] = '\0';
size_t append_line_length = snprintf(NULL, 0, "<a href=\"%s\">%s</a>", href, internal_text) + 1;
char *append = malloc(append_line_length);
char *tmp_out = realloc(*out, strlen(*out) + append_line_length);
if (append == NULL || tmp_out == NULL)
{
perror("Couldn't allocate memory for new element");
continue;
}
*out = tmp_out;
snprintf(append, append_line_length, "<a href=\"%s\">%s</a>", href, internal_text);
strcat(*out, append);
i += 1 + n + 2 + k;
free(append);
free(href);
free(internal_text);
continue;
}
*out = tmp_out;
snprintf(append, append_line_length, "<a href=\"%s\">%s</a>", href, internal_text);
strcat(*out, append);
i += 1 + n + 2 + k;
free(append);
free(href);
free(internal_text);
continue;
}
size_t len = strlen(*out);

View File

@ -1,5 +1,6 @@
#include "../../include/file_op/file.h"
#include "../../include/utils_op/utils.h"
#include <limits.h>
/**
* @brief Generate file path from request path provided
@ -21,12 +22,31 @@ char *gen_file_path(char *req_path)
path = strcat(path, "index.html");
}
char *webroot = "static";
char webroot[PATH_MAX];
if (getcwd(webroot, PATH_MAX) == NULL)
goto exit_error;
path = realloc(path, strlen(path) + strlen(webroot) + 1);
path = concat_to_front(&path, webroot);
if (PATH_MAX < strlen(webroot) + strlen("/static"))
goto exit_error;
strcat(webroot, "/static");
path = prepend(path, webroot);
char resolved_path[PATH_MAX];
if (realpath(path, resolved_path) == NULL)
goto exit_error;
if (strncmp(resolved_path, webroot, strlen(webroot)) != 0)
{
goto exit_error;
}
return path;
exit_error:
free(path);
return NULL;
}
/**

View File

@ -9,7 +9,7 @@
*/
char *get_mime_type(char *file_path)
{
char *ext = strchr(file_path, '.');
char *ext = strrchr(file_path, '.');
if (ext == NULL)
{

View File

@ -10,9 +10,9 @@
*/
gallery_t *get_album_list()
{
gallery_t *list = NULL, *curr = list;
gallery_t *list = NULL, *curr;
char **albums_titles_list = malloc(0);
char **albums_titles_list = NULL;
ssize_t albums_am = get_dir_list(&albums_titles_list, GALLERY_ROOT);
@ -50,18 +50,18 @@ gallery_t *get_album_list()
*/
void free_albums_list(gallery_t *albums_list)
{
gallery_t *curr_item = albums_list;
while (curr_item != NULL)
while (albums_list != NULL)
{
free(curr_item->title);
for (int i = 0; i < curr_item->img_am; i++)
free_img_item(curr_item->images[i]);
free(curr_item->images);
curr_item = curr_item->next;
}
free(albums_list->title);
for (int i = 0; i < albums_list->img_am; i++)
free_img_item(albums_list->images[i]);
free(albums_list->images);
free(albums_list);
gallery_t *next_item = albums_list->next;
free(albums_list);
albums_list = next_item;
}
}
/**
@ -154,7 +154,17 @@ int get_album_imgs(img_t **images_arr, int *size, char *title)
char *gen_gallery_html()
{
FILE *album_template_fp = fopen("static/gallery/album.html", "r");
if (album_template_fp == NULL)
{
return "500 Internal Error\n";
}
FILE *image_template_fp = fopen("static/gallery/image.html", "r");
if (image_template_fp == NULL)
{
fclose(album_template_fp);
return "500 Internal Error\n";
}
size_t album_file_size = get_file_size(album_template_fp) + 1;
char *album_template = calloc(1, album_file_size);

View File

@ -72,12 +72,13 @@ int get_listener_socket(char *port)
*
* @param {struct sockaddr*} sa
* @return void*
*/
*/
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
if (sa->sa_family == AF_INET)
{
return &(((struct sockaddr_in *)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
return &(((struct sockaddr_in6 *)sa)->sin6_addr);
}

View File

@ -16,6 +16,13 @@
void res_404(int fd, char *path)
{
FILE *fp = fopen("static/404.html", "r");
if (fp == NULL)
{
res_500(fd);
return;
}
const ssize_t fsize = 512;
char *buff = malloc(fsize), *msg = malloc(fsize);
@ -102,6 +109,13 @@ int send_response(int fd, char *req_path)
{
char *file_path = gen_file_path(req_path);
if (file_path == NULL)
{
res_404(fd, req_path);
free(file_path);
return 0;
}
struct file_s *file = get_file_info(file_path);
if (file == NULL)
@ -121,6 +135,8 @@ int send_response(int fd, char *req_path)
return 0;
}
int return_code = 0;
char *mime_type = get_mime_type(file_path);
struct header_s *header = gen_header(200, file->size, mime_type);
@ -130,15 +146,18 @@ int send_response(int fd, char *req_path)
if (rv < 0)
{
err_msg("couldn't send header");
return -1;
return_code = -1;
goto exit_code;
}
if (send_file(fd, file) < 0)
{
err_msg("couldn't send file");
return -1;
return_code = -1;
goto exit_code;
}
exit_code:
close(fd);
free(header->str);
@ -146,7 +165,8 @@ int send_response(int fd, char *req_path)
free(file);
free(file_path);
return 0;
return return_code;
}
/**
@ -187,9 +207,9 @@ void handle_get_request(int fd, char *request)
fread(template, file_size, 1, fp);
fclose(fp);
template[file_size-1] = '\0';
template[file_size - 1] = '\0';
article_info *articles = malloc(0);
article_info *articles = NULL;
int amount = list_articles(&articles);
if (amount < 0)
{
@ -245,7 +265,7 @@ void handle_get_request(int fd, char *request)
}
free(id_str);
article_info *articles = malloc(0);
article_info *articles = NULL;
int amount = list_articles(&articles);
if (amount < 0)
{
@ -255,6 +275,7 @@ void handle_get_request(int fd, char *request)
if (id > amount - 1)
{
free_article_info_arr(&articles, amount);
res_404(fd, path);
return;
}

View File

@ -64,7 +64,7 @@ char *gen_project_html()
fread(template, template_file_size, 1, template_fp);
fclose(template_fp);
project_t *list = malloc(0);
project_t *list = NULL;
size_t length = read_list(&list);
char *content = strdup("");

View File

@ -70,15 +70,15 @@ void handle_process_termination(int signum)
int status;
pid_t pid;
do {
pid = waitpid(-1, &status, WNOHANG);
}
while (pid > 0);
do
{
pid = waitpid(-1, &status, WNOHANG);
} while (pid > 0);
}
/**
* Main
*/
* Main
*/
int main(int argc, char *argv[])
{
int client_fd;

View File

@ -4,7 +4,7 @@
* @brief Prints error
*
* @param {char *} msg
*/
*/
void err_msg(char *msg)
{
fprintf(stderr, "Error: %s\n", msg);
@ -17,16 +17,18 @@ void err_msg(char *msg)
* @param str2
* @return char*
*/
char *concat_to_front(char **str1, char *str2)
char *prepend(char *dest, const char *prefix)
{
char *tmp = strdup(*str1);
size_t orig_len = strlen(dest);
size_t prefix_len = strlen(prefix);
strcpy(*str1, str2);
strcat(*str1, tmp);
dest = realloc(dest, orig_len + prefix_len + 1);
free(tmp);
memmove(dest + prefix_len, dest, orig_len + 1);
return *str1;
memcpy(dest, prefix, prefix_len);
return dest;
}
/**

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>About</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="/style.css">
</head>
@ -19,21 +20,22 @@
<main>
<h1>About me</h1>
<p>
Hello, my name is Dmitriy Shishkov. I am a 17 years old computer programmer. I
also do photography as a hobby. As for autumn 2021, I study radio-engineering
Hello, my name is Dmitriy Shishkov. I am a 17-year-old computer programmer. I
also do photography as a hobby. As for autumn 2021, I study radiotechnics
at "Saint Petersburg Electrotechnical University "LETI".
</p>
<p>
I consider myself a full-stack web developer. All web services and application I
deploy on my home server are powered by Fedora Server. For it, I use Podman,
I consider myself a full-stack web developer. All web services and applications
I deploy on my home server, powered by Fedora Server. For it, I use Podman,
Ansible, and Cockpit. I have also used PaaSes such as <a href="https://vercel.com">
Vercel Now</a> or <a href="https://heroku.com">Heroku</a> for previews or small
projects.
</p>
<p>
I also do some C/C++ development for my workspace tools and to better understand
the way software I use works. In <a href="/projects">projects</a> section, you
can see some. Even this site is powered by a page generator written in C.
I also do some C/C++ development for my workspace tools and to better
understand how the software I use works. You can see some examples in the
<a href="/projects">projects</a> section. Even this site is powered by a page
generator written in C.
</p>
<p>Some of the technologies I have worked with:</p>
<ul>

View File

@ -0,0 +1,35 @@
First, decompile apk file with [apktool](https://apktool.org):
```
apktool d &lt;file_name&gt;.apk
```
Replace assets or edit *Manifest.xml*. [smali2java](https://github.com/AlexeySoshin/smali2java) can be of use for code modifications.
Recompile apk:
```
apktool b &lt;file_name&gt;
```
Alignment is necessary for modern android versions (I believe, 30+ SDK):
```
zipalign -v -f -p 4 &lt;file_name&gt;/dist/&lt;file_name&gt;.apk aligned-&lt;file_name&gt;.apk
```
Create a signing key. Fields values do not matter. Especially for personal use.
```
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 1000
```
Actually sign apk with it:
```
apksigner.jar sign -ks my-release-key.keystore --ks-key-alias alias_name aligned-&lt;file_name&gt;.apk
```
It will overwrite the provided apk with a signed one.
We're awesome!

View File

@ -5,7 +5,7 @@ Firstly, mount your Windows disk C: on Linux. For it, run:
```
sudo pacman -S ntfs-3g
sudo mkdir -p /mnt/c
sudo mount /dev/<Windows partition name> /mnt/c
sudo mount /dev/&lt;Windows partition name> /mnt/c
```
WSL filesystem is stored as .vhdx file, so we will use qemu-nbd to mount it as usual disk drive.
@ -26,16 +26,16 @@ sudo pacman -S qemu
Connect .vhdx file to nbd device:
```
sudo qemu-hbd -c /dev/nbd0 /mnt/c/<path to .vhdx file>
sudo qemu-hbd -c /dev/nbd0 /mnt/c/&lt;path to .vhdx file>
```
By default, path must look like Users/[user]/AppData/Local/Packages/[distro]/LocalState/[distroPackageName]/ext4.vhdx
Finally, mount ndb device:
Finally, mount nbd device:
```
sudo mkdir /mnt/wsl
sudo mount /dev/ndb0 /mnt/wsl
sudo mount /dev/nbd0 /mnt/wsl
```
Now you can transfer files or chroot into it.

View File

@ -11,7 +11,7 @@ sudo dnf install v4l2loopback
Next, after reboot, we're ready to start the stream with ffmpeg:
```bash
sudo ffmpeg -f mjpeg -r 5 -i "http://<Phone IP>:8080/cam.mjpeg?fps=10" -r 10 -pix_fmt yuv420p -f v4l2 /dev/video0
sudo ffmpeg -f mjpeg -r 5 -i "http://&lt;Phone IP>:8080/cam.mjpeg?fps=10" -r 10 -pix_fmt yuv420p -f v4l2 /dev/video0
```
My Wi-Fi connection speed was enough for such stream. But it is still possible to use it with adb port forwarding over usb:

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>%s</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="/style.css">
</head>

View File

@ -1,7 +1,8 @@
1594048366 My_first_article_on_this_site
1594048366000 My_first_article_on_this_site
1606819380000 Ugra_Hantaton
1619034957605 Stack_VM_V1.0
1627839955679 Publite_-_an_Ebook_reader
1646570601234 Mount_WSL_partition_on_Arch_Linux
1653350638050 Use_phone_as_camera_for_linux_desktop
1694581049776 Use_phone_camera_for_linux_desktop_(2023)
1738537323514 APK_modification

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Contacts</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="style.css">
</head>
@ -20,8 +21,9 @@
<h1>Contacts:</h1>
<ul>
<li><a href="https://t.me/dm1sh">Telegram</a></li>
<li><a href="https://vk.com/dm1sh">VK</a></li>
<li><a href="mailto:me@dmitriy.icu">Mail (me@dmitriy.icu)</a></li>
<li><a rel="me" href="https://pub.dm1sh.ru/@dm1sh">Mastodon</a></li>
<li><a href="https://vk.com/dm1sh">VK</a></li>
</ul>
</main>
</body>

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Gallery</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="/style.css">
</head>

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Shishkov Dmitriy</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="style.css">
</head>

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<title>Projects</title>
<link href="https://pub.dm1sh.ru/@dm1sh" rel="me">
<link rel="stylesheet" href="style.css">
</head>

View File

@ -83,6 +83,15 @@ main li {
line-height: 30px;
}
main pre {
font-size: 17px;
overflow-x: auto;
}
main code {
font-family: monospace;
}
main a:hover {
text-decoration: none;
}