Commit 0c62ce5a authored by Jan-Michael Brummer's avatar Jan-Michael Brummer
Browse files

faxspooler: Remove fax spooler we will use fax server on all platforms

platform: file url fixes
parent 1d5892de
......@@ -798,7 +798,6 @@ gchar *fritzbox_load_fax(RmProfile *profile, const gchar *filename, gsize *len)
return NULL;
}
rm_file_save("loadfax.xml", msg->response_body->data, -1);
ret = g_malloc0(msg->response_body->length);
memcpy(ret, msg->response_body->data, msg->response_body->length);
*len = msg->response_body->length;
......
......@@ -8,7 +8,6 @@ rm_sources = [
'rmcsv.c',
'rmdevice.c',
'rmfax.c',
'rmfaxspooler.c',
'rmfaxserver.c',
'rmfile.c',
'rmfilter.c',
......@@ -48,7 +47,6 @@ rm_headers = [
'rmfax.h',
'rmdevice.h',
'rmfaxserver.h',
'rmfaxspooler.h',
'rmfile.h',
'rmfilter.h',
'rmftp.h',
......
/*
* The rm project
* Copyright (c) 2012-2017 Jan-Michael Brummer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <glib.h>
#include <string.h>
#include <sys/types.h>
#include <gio/gio.h>
#include <rmconfig.h>
#include <rm/rmobjectemit.h>
#include <rm/rmmain.h>
#include <rm/rmfaxspooler.h>
/**
* SECTION:rmfaxspooler
* @title: RmFaxSpooler
* @short_description: Fax spooler watching a spooler directory for incoming fax transfers
* @stability: Stable
*
* Provides a fax spooler. Watches a selected directory for new files and starts a fax
* transfer if a valid file has been placed. This one is used on most systems (Linux, OSX, ...)
*/
#define SPOOLER_DIR "/var/spool/"
/** translations from event to text for file monitor events */
struct event_translate {
GFileMonitorEvent event;
gchar *text;
};
/** text values of file monitor events */
struct event_translate rm_event_translation_table[] = {
{ G_FILE_MONITOR_EVENT_CHANGED, "file changed" },
{ G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT, "file changes finished" },
{ G_FILE_MONITOR_EVENT_DELETED, "file deleted" },
{ G_FILE_MONITOR_EVENT_CREATED, "file created" },
{ G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED, "file attrbutes changed" },
{ G_FILE_MONITOR_EVENT_PRE_UNMOUNT, "file system about to be unmounted" },
{ G_FILE_MONITOR_EVENT_UNMOUNTED, "file system unmounted" },
{ G_FILE_MONITOR_EVENT_MOVED, "file moved" },
};
/**
* rm_faxspooler_event_to_text:
* @event: a #GFileMonitorEvent
*
* Translates a file monitor event into a human readable string
*
* Returns: a newly created event string
*/
static const char *rm_faxspooler_event_to_text(GFileMonitorEvent event)
{
int index;
for (index = 0; index < G_N_ELEMENTS(rm_event_translation_table); index++) {
if (rm_event_translation_table[index].event == event) {
return rm_event_translation_table[index].text;
}
}
return "Undefined event";
}
/**
* rm_faxspooler_has_file_extension:
* @file: file name
* @ext: file extension
*
* Check if given file name ends with the requested extension.
*
* Returns: %TRUE% if file ends with given extension or %FALSE% if not
*/
gboolean rm_faxspooler_has_file_extension(const char *file, const char *ext)
{
int len, ext_len;
if (!file || *file == '\0' || !ext) {
return FALSE;
}
ext_len = strlen(ext);
len = strlen(file) - ext_len;
if (len < 0) {
return FALSE;
}
return(strncmp(file + len, ext, ext_len) == 0);
}
/**
* rm_faxspooler_changed_cb:
* @monitor: a #GFileMonitor
* @file: a #GFile
* @other_file: a #GFile
* @event_type: a #GFileMonitorEvent
* @user_data: additional user data
*
* Fax spooler callback for the users own spool directory. Monitors the users fax spooler directory
* for changes and if a new final file is created emit fax process signal.
*/
static void rm_faxspooler_changed_cb(GFileMonitor *monitor, GFile *file, GFile *other_file, GFileMonitorEvent event_type, gpointer user_data)
{
GFileType type;
gchar *file_name = NULL;
g_debug("%s(): event type: %d (%s)", __FUNCTION__, event_type, rm_faxspooler_event_to_text(event_type));
if (event_type != G_FILE_MONITOR_EVENT_CREATED) {
return;
}
file_name = g_file_get_path(file);
g_assert(file_name != NULL);
type = g_file_query_file_type(file, G_FILE_QUERY_INFO_NONE, NULL);
if (type != G_FILE_TYPE_REGULAR) {
return;
}
/* Sort out invalid files */
if (rm_faxspooler_has_file_extension(file_name, ".tmp") || rm_faxspooler_has_file_extension(file_name, ".tif") || rm_faxspooler_has_file_extension(file_name, ".sff")) {
/* Skip it */
goto end;
}
g_debug("%s(): Print job received on spooler", __FUNCTION__);
rm_object_emit_fax_process(file_name);
end:
g_free(file_name);
}
/**
* rm_faxspooler_setup_file_monitor:
* @dir_name: directory to monitor
* @error: a #GError
*
* Create file monitor for the users own spooler directory.
*
* Returns: %TRUE% on successful creation, %FALSE% on error.
*/
static gboolean rm_faxspooler_setup_file_monitor(const gchar *dir_name, GError **error)
{
GFileMonitor *file_monitor = NULL;
GFile *file = NULL;
GError *file_error = NULL;
gboolean ret;
const gchar *user_name = g_get_user_name();
g_assert(user_name != NULL);
#ifdef SPOOLER_DEBUG
g_debug("%s(): Setting file monitor to '%s'", __FUNCTION__, dir_name);
#endif
/* Create GFile for GFileMonitor */
file = g_file_new_for_path(dir_name);
/* Create file monitor for spool directory */
file_monitor = g_file_monitor_directory(file, 0, NULL, &file_error);
g_object_unref(file);
if (file_monitor) {
/* Set callback for file monitor */
g_signal_connect(file_monitor, "changed", G_CALLBACK(rm_faxspooler_changed_cb), NULL);
ret = TRUE;
} else {
g_debug("%s(): Error occurred creating new file monitor", __FUNCTION__);
g_debug("%s(): Message: %s\n", __FUNCTION__, file_error->message);
g_set_error(error, RM_ERROR, RM_ERROR_FAX, "%s", file_error->message);
ret = FALSE;
}
return ret;
}
/**
* rm_faxspooler_init:
*
* Initialize new printer spool queue and file monitor
*
* Returns: %TRUE on successful creation, %FALSE on error.
*/
gboolean rm_faxspooler_init(void)
{
GDir *dir;
GError *file_error = NULL;
gchar *spooler_dir = g_build_path(G_DIR_SEPARATOR_S, SPOOLER_DIR, RM_NAME, NULL);
gboolean ret = FALSE;
/* Check if spooler is present */
if (!g_file_test(spooler_dir, G_FILE_TEST_IS_DIR)) {
g_warning("%s(): Spooler directory %s does not exist!", __FUNCTION__, spooler_dir);
g_free(spooler_dir);
return FALSE;
}
dir = g_dir_open(spooler_dir, 0, &file_error);
if (!dir) {
g_warning("%s(): Could not access spooler directory. Is user in group fax?\n%s", __FUNCTION__, file_error ? file_error->message : "");
g_free(spooler_dir);
return FALSE;
}
g_dir_close(dir);
ret = rm_faxspooler_setup_file_monitor(spooler_dir, &file_error);
g_free(spooler_dir);
return ret;
}
/*
* The rm project
* Copyright (c) 2012-2017 Jan-Michael Brummer
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __RMFAXSPOOLER_H__
#define __RMFAXSPOOLER_H__
#if !defined (__RM_H_INSIDE__) && !defined(RM_COMPILATION)
#error "Only <rm/rm.h> can be included directly."
#endif
G_BEGIN_DECLS
gboolean rm_faxspooler_init(void);
G_END_DECLS
#endif
......@@ -64,8 +64,6 @@ static gchar *rm_user_cache_dir = NULL;
static gchar *rm_user_data_dir = NULL;
/** Requested user profile */
static gchar *rm_requested_profile = NULL;
/** Fax server flag */
static gboolean rm_fax_server_active = FALSE;
/**
* rm_print_error_quark:
......@@ -271,17 +269,6 @@ gboolean rm_new(gboolean debug, GError **error)
return TRUE;
}
/**
* rm_use_fax_server:
* @on: flag indicating if fax server should be used
*
* Activate/Deactivate fax server
*/
void rm_use_fax_server(gboolean on)
{
rm_fax_server_active = on;
}
/**
* rm_init:
* @error: a @GError
......@@ -296,11 +283,7 @@ gboolean rm_init(GError **error)
g_info("%s %s", RM_NAME, RM_VERSION);
/* Init fax printer */
if (rm_fax_server_active) {
rm_faxserver_init();
} else {
rm_faxspooler_init();
}
rm_faxserver_init();
/* Initialize network */
rm_network_init();
......
......@@ -83,8 +83,6 @@ gchar *rm_get_user_cache_dir(void);
gchar *rm_get_user_data_dir(void);
gchar *rm_get_user_plugins_dir(void);
void rm_use_fax_server(gboolean on);
G_END_DECLS
#endif
......@@ -737,7 +737,7 @@ GSList *rm_router_load_fax_reports(RmProfile *profile, GSList *journal)
continue;
}
uri = g_strdup_printf("file://%s%s%s", dir_name, G_DIR_SEPARATOR_S, file_name);
uri = g_strdup_printf("file:///%s%s%s", dir_name, G_DIR_SEPARATOR_S, file_name);
date_time = g_strdup_printf("%s.%s.%s %2.2s:%2.2s", split[3], split[4], split[5] + 2, split[6], split[7]);
......@@ -799,7 +799,7 @@ GSList *rm_router_load_voice_records(RmProfile *profile, GSList *journal)
continue;
}
uri = g_strdup_printf("file://%s%s%s", dir_name, G_DIR_SEPARATOR_S, file_name);
uri = g_strdup_printf("file:///%s%s%s", dir_name, G_DIR_SEPARATOR_S, file_name);
num = split[4];
num[strlen(num) - 4] = '\0';
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment