R: get rid of direct "write" system call, when sending messages to the server

This commit is contained in:
2026-03-23 14:13:07 +02:00
parent 0661b0721a
commit f0dfe89483
11 changed files with 59 additions and 70 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ void init_alert(app_t *_app) { app = _app; }
void alert(const char *message) { notification("Alert", dc_alert, message); }
void notification(const char *title, enum d_color_scheme color,
void notification(const char *title, enum dc_color_scheme color,
const char *f_message, ...) {
if (app == NULL)
return;
+1 -1
View File
@@ -4,6 +4,6 @@
#include <stdarg.h>
void init_alert(app_t *app);
void alert(const char *message);
void notification(const char *title, enum d_color_scheme color,
void notification(const char *title, enum dc_color_scheme color,
const char *f_message, ...);
#endif
+2 -1
View File
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <widget.h>
#include "../server.h"
typedef struct {
button_t *element;
@@ -31,7 +32,7 @@ void init_login_credentials_modal_cb(callback_args_t *args) {
app->params->uname[in_name->value_len] = 0;
strncpy(app->params->pass, in_pass->value, in_pass->value_len);
app->params->pass[in_pass->value_len] = 0;
write(app->params->sd, app->params->uname, in_name->value_len);
server_send_string(app->query_args, app->params->uname);
app->query_args->state = S_WAIT_SERVER;
d->needs_destroy = true;
print_bars(app);
+2 -1
View File
@@ -6,6 +6,7 @@
#include <unistd.h>
#include <widget.h>
#include "../server.h"
typedef struct {
button_t *element;
@@ -26,7 +27,7 @@ void login_modal_option_cb(callback_args_t *args) {
d->needs_destroy = true;
app->params->uname = malloc(sizeof "anonymous");
strcpy(app->params->uname, "anonymous");
write(app->params->sd, app->params->uname, sizeof "anonymous" - 1);
server_send_string(app->query_args, app->params->uname);
app->query_args->state = S_WAIT_SERVER;
print_bars(app);
break;
+4 -7
View File
@@ -1,6 +1,5 @@
#include <ncursesw/ncurses.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -9,6 +8,7 @@
#include "alert.h"
#include "group.h"
#include "../server.h"
typedef struct {
button_t *element;
@@ -16,8 +16,6 @@ typedef struct {
} group_bt_t;
void init_register_modal_cb(callback_args_t *args) {
char query[256];
int32_t qlen = 0;
callback_args_t d_args;
app_t *app = args->app;
dialogue_t *d = (dialogue_t *)app->active_widget;
@@ -65,10 +63,9 @@ void init_register_modal_cb(callback_args_t *args) {
app->params->uname[in_name->value_len] = 0;
strncpy(app->params->pass, in_pass->value, in_pass->value_len);
app->params->pass[in_pass->value_len] = 0;
sprintf(query, "register %s %s %*s\n%n", app->params->uname,
app->params->pass, (int)in_email->value_len, in_email->value,
&qlen);
write(app->params->sd, query, qlen);
server_send_string(app->query_args, "register %s %s %*s\n", app->params->uname,
app->params->pass, (int)in_email->value_len, in_email->value
);
app->query_args->state = S_WAIT_REGISTER_CONFIRMATION;
}
}
+18 -14
View File
@@ -3,12 +3,13 @@
#include "widget_core.h"
#include <ncursesw/ncurses.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <widget.h>
#include <utils.h>
#include <widget.h>
#include "../server.h"
void upload_props_dialogue_modal_cb(callback_args_t *args) {
callback_args_t d_args;
@@ -18,30 +19,33 @@ void upload_props_dialogue_modal_cb(callback_args_t *args) {
d_args.app = NULL;
d_args.element = app->active_widget;
dialogue_default_callback(&d_args);
char query[256];
int32_t query_len = 0;
if (d_args.resp_data.code == cbrp_val) {
checkbox_t *reg_cbx = (checkbox_t *)d->g_content->elements[0].element;
checkbox_t *reg_cbx = (checkbox_t *)d->g_content->elements[0].element;
checkbox_t *anon_cbx = (checkbox_t *)d->g_content->elements[1].element;
checkbox_t *comp_cbx = (checkbox_t *)d->g_content->elements[2].element;
int32_t privileges = 0;
if (anon_cbx->value == true) privileges |= 1;
if (reg_cbx->value == true) privileges |= 2;
if (comp_cbx->value == true) privileges |= 4;
if (anon_cbx->value == true)
privileges |= 1;
if (reg_cbx->value == true)
privileges |= 2;
if (comp_cbx->value == true)
privileges |= 4;
switch (d_args.resp_data.val.val.num) {
case 1:
query_len =
sprintf(query, "file upload \"%s\" %zu %d\n",
app->query_args->file->name, app->query_args->file->size, privileges);
server_send_string(app->query_args, "file upload \"%s\" %zu %d\n",
app->query_args->file->name,
app->query_args->file->size, privileges);
/* app->query_args->file->description =
malloc(desc_input->value_len + 9); reserve space for \n:END:\n */
app->query_args->file->description = malloc(sizeof ("[Empty description]\n:END:\n"));
strcpy(app->query_args->file->description, "[Empty description]\n:END:\n");
app->query_args->file->description =
malloc(sizeof("[Empty description]\n:END:\n"));
strcpy(app->query_args->file->description,
"[Empty description]\n:END:\n");
d->needs_destroy = true;
app->query_args->state = S_UPLOAD_REQUESTED;
write(app->query_args->sd, query, query_len);
break;
case 2:
FREE_MLC(app->query_args->file->name);