mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-26 03:36:21 +00:00
Merge pull request #1450 from wstrm/issue-1449
Cast chat/muc window to correct type and refactor cmd_sendfile
This commit is contained in:
@@ -4889,43 +4889,52 @@ cmd_sendfile(ProfWin* window, const char* const command, gchar** args)
|
|||||||
|
|
||||||
FILE* fh = fdopen(fd, "rb");
|
FILE* fh = fdopen(fd, "rb");
|
||||||
|
|
||||||
|
gboolean omemo_enabled = FALSE;
|
||||||
|
gboolean sendfile_enabled = TRUE;
|
||||||
|
|
||||||
switch (window->type) {
|
switch (window->type) {
|
||||||
case WIN_MUC:
|
case WIN_MUC:
|
||||||
|
{
|
||||||
|
ProfMucWin* mucwin = (ProfMucWin*)window;
|
||||||
|
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||||
|
omemo_enabled = mucwin->is_omemo == TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
case WIN_CHAT:
|
case WIN_CHAT:
|
||||||
{
|
{
|
||||||
ProfChatWin* chatwin = (ProfChatWin*)window;
|
ProfChatWin* chatwin = (ProfChatWin*)window;
|
||||||
|
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||||
#ifdef HAVE_OMEMO
|
omemo_enabled = chatwin->is_omemo == TRUE;
|
||||||
if (chatwin->is_omemo) {
|
sendfile_enabled = !((chatwin->pgp_send == TRUE && !prefs_get_boolean(PREF_PGP_SENDFILE))
|
||||||
char* err = NULL;
|
|| (chatwin->is_otr == TRUE && !prefs_get_boolean(PREF_OTR_SENDFILE)));
|
||||||
alt_scheme = OMEMO_AESGCM_URL_SCHEME;
|
|
||||||
alt_fragment = _add_omemo_stream(&fd, &fh, &err);
|
|
||||||
if (err != NULL) {
|
|
||||||
cons_show_error(err);
|
|
||||||
win_println(window, THEME_ERROR, "-", err);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (window->type == WIN_CHAT) {
|
|
||||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
|
||||||
if ((chatwin->pgp_send && !prefs_get_boolean(PREF_PGP_SENDFILE))
|
|
||||||
|| (chatwin->is_otr && !prefs_get_boolean(PREF_OTR_SENDFILE))) {
|
|
||||||
cons_show_error("Uploading unencrypted files disabled. See /otr sendfile or /pgp sendfile.");
|
|
||||||
win_println(window, THEME_ERROR, "-", "Sending encrypted files via http_upload is not possible yet.");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case WIN_PRIVATE: // We don't support encryption in private MUC windows.
|
case WIN_PRIVATE: // We don't support encryption in private MUC windows.
|
||||||
default:
|
default:
|
||||||
cons_show_error("Unsupported window for file transmission.");
|
cons_show_error("Unsupported window for file transmission.");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!sendfile_enabled) {
|
||||||
|
cons_show_error("Uploading unencrypted files disabled. See /otr sendfile or /pgp sendfile.");
|
||||||
|
win_println(window, THEME_ERROR, "-", "Sending encrypted files via http_upload is not possible yet.");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (omemo_enabled) {
|
||||||
|
#ifdef HAVE_OMEMO
|
||||||
|
char* err = NULL;
|
||||||
|
alt_scheme = OMEMO_AESGCM_URL_SCHEME;
|
||||||
|
alt_fragment = _add_omemo_stream(&fd, &fh, &err);
|
||||||
|
if (err != NULL) {
|
||||||
|
cons_show_error(err);
|
||||||
|
win_println(window, THEME_ERROR, "-", err);
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
HTTPUpload* upload = malloc(sizeof(HTTPUpload));
|
HTTPUpload* upload = malloc(sizeof(HTTPUpload));
|
||||||
upload->window = window;
|
upload->window = window;
|
||||||
|
|
||||||
|
|||||||
12
src/common.c
12
src/common.c
@@ -629,15 +629,15 @@ _basename_from_url(const char* url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
get_expanded_path(const char *path)
|
get_expanded_path(const char* path)
|
||||||
{
|
{
|
||||||
GString* exp_path = g_string_new("");
|
GString* exp_path = g_string_new("");
|
||||||
gchar *result;
|
gchar* result;
|
||||||
|
|
||||||
if (strlen(path) >= 2 && path[0] == '~' && path[1] == '/') {
|
if (strlen(path) >= 2 && path[0] == '~' && path[1] == '/') {
|
||||||
g_string_printf(exp_path, "%s/%s", getenv("HOME"), path+2);
|
g_string_printf(exp_path, "%s/%s", getenv("HOME"), path + 2);
|
||||||
} else {
|
} else {
|
||||||
g_string_printf(exp_path, "%s", path+2);
|
g_string_printf(exp_path, "%s", path);
|
||||||
}
|
}
|
||||||
|
|
||||||
result = exp_path->str;
|
result = exp_path->str;
|
||||||
@@ -649,11 +649,11 @@ get_expanded_path(const char *path)
|
|||||||
gchar*
|
gchar*
|
||||||
unique_filename_from_url(const char* url, const char* path)
|
unique_filename_from_url(const char* url, const char* path)
|
||||||
{
|
{
|
||||||
gchar *realpath;
|
gchar* realpath;
|
||||||
|
|
||||||
// Default to './' as path when none has been provided.
|
// Default to './' as path when none has been provided.
|
||||||
if (path == NULL) {
|
if (path == NULL) {
|
||||||
realpath = strdup("./");
|
realpath = g_strdup("./");
|
||||||
} else {
|
} else {
|
||||||
realpath = get_expanded_path(path);
|
realpath = get_expanded_path(path);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ chatwin_new(const char* const barejid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chatwin->is_omemo = FALSE;
|
||||||
#ifdef HAVE_OMEMO
|
#ifdef HAVE_OMEMO
|
||||||
if (omemo_automatic_start(barejid)) {
|
if (omemo_automatic_start(barejid)) {
|
||||||
omemo_start_session(barejid);
|
omemo_start_session(barejid);
|
||||||
@@ -90,6 +91,7 @@ chatwin_new(const char* const barejid)
|
|||||||
if (prefs_get_boolean(PREF_MAM)) {
|
if (prefs_get_boolean(PREF_MAM)) {
|
||||||
iq_mam_request(chatwin);
|
iq_mam_request(chatwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
// XEP-0373: OpenPGP for XMPP
|
// XEP-0373: OpenPGP for XMPP
|
||||||
chatwin->is_ox = FALSE;
|
chatwin->is_ox = FALSE;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user