about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/command/cmd_funcs.c10
-rw-r--r--src/common.c13
-rw-r--r--src/common.h2
-rw-r--r--src/xmpp/avatar.c10
4 files changed, 17 insertions, 18 deletions
diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c
index 9a00bc2f..d0f97810 100644
--- a/src/command/cmd_funcs.c
+++ b/src/command/cmd_funcs.c
@@ -8871,15 +8871,7 @@ cmd_urlopen(ProfWin *window, const char *const command, gchar **args)
             return TRUE;
         }
 
-        //TODO: make function. see src/xmpp/avatar.c
-        GString *cmd = g_string_new("");
-
-        g_string_append_printf(cmd, "%s %s > /dev/null 2>&1", "xdg-open", args[0]);
-        cons_show("Calling: %s", cmd->str);
-        FILE *stream = popen(cmd->str, "r");
-
-        pclose(stream);
-        g_string_free(cmd, TRUE);
+        call_external("xdg-open", args[0]);
     } else {
         cons_show("urlopen not supported in this window");
     }
diff --git a/src/common.c b/src/common.c
index d06307cb..821acd3e 100644
--- a/src/common.c
+++ b/src/common.c
@@ -483,3 +483,16 @@ get_mentions(gboolean whole_word, gboolean case_sensitive, const char *const mes
 
     return mentions;
 }
+
+void
+call_external(const char *const exe, const char *const param)
+{
+    GString *cmd = g_string_new("");
+
+    g_string_append_printf(cmd, "%s %s > /dev/null 2>&1", exe, param);
+    log_debug("Calling external: %s", cmd->str);
+    FILE *stream = popen(cmd->str, "r");
+
+    pclose(stream);
+    g_string_free(cmd, TRUE);
+}
diff --git a/src/common.h b/src/common.h
index 4676a9ac..108536ed 100644
--- a/src/common.h
+++ b/src/common.h
@@ -106,4 +106,6 @@ void get_file_paths_recursive(const char *directory, GSList **contents);
 
 char* get_random_string(int length);
 
+void call_external(const char *const exe, const char *const param);
+
 #endif
diff --git a/src/xmpp/avatar.c b/src/xmpp/avatar.c
index 9d043cb3..701d6cb7 100644
--- a/src/xmpp/avatar.c
+++ b/src/xmpp/avatar.c
@@ -266,15 +266,7 @@ _avatar_request_item_result_handler(xmpp_stanza_t *const stanza, void *const use
 
     // if we shall open it
     if (g_hash_table_contains(shall_open, from_attr)) {
-        GString *cmd = g_string_new("");
-
-        g_string_append_printf(cmd, "%s %s > /dev/null 2>&1", prefs_get_string(PREF_AVATAR_CMD), filename->str);
-        cons_show("Calling: %s", cmd->str);
-        FILE *stream = popen(cmd->str, "r");
-
-        pclose(stream);
-        g_string_free(cmd, TRUE);
-
+        call_external(prefs_get_string(PREF_AVATAR_CMD), filename->str);
         g_hash_table_remove(shall_open, from_attr);
     }