Initial commit of jimb alpha 3
[jimb.git] / src / services.c
blobba77bcedc93323dbb82ecdfecbe2b44799e590dc
1 /**
2 * JIMCI (Jabber Instant Messaging Connection Interface)
3 * This file is part of JIMB.
5 * JIMCI is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License Version 3
7 * as published by the Free Software Foundation.
9 * JIMCI is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License Version 3
15 * along with JIMCI; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * File: Services
19 * Package: JIMCI
20 * Author: Martin Kelm <martinkelm@idxsolutions.de>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <glib.h>
26 #include "services.h"
28 gchar *services_actions_exec;
29 gchar *services_actions_script;
30 gchar *services_updates_exec;
31 gchar *services_updates_script;
32 extern gchar *services_queue_message;
34 gboolean services_actions_perform(gpointer data) {
35 gchar *command = g_strdup_printf("%s%s", services_actions_exec, services_actions_script);
36 system(command);
37 //g_print("Services actions execution: %s\n", command);
38 return TRUE;
41 gboolean services_updates_perform(gpointer data) {
42 gchar *command = g_strdup_printf("%s%s", services_updates_exec, services_updates_script);
43 system(command);
44 //g_print("Services updates execution: %s\n", command);
45 return TRUE;
48 int services_init(
49 char *actions_exec, char *actions_script, int actions_interval,
50 char *updates_exec, char *updates_script, int updates_interval, char *queue_message
51 ) {
52 if (strlen(queue_message) > 0) {
53 services_queue_message = queue_message;
54 } else {
55 services_queue_message = "";
57 if (strlen(actions_exec) > 0 && actions_interval > 0) {
58 if (strlen(actions_script) > 0) {
59 services_actions_script = g_strdup_printf(" %s", actions_script);
60 } else {
61 services_actions_script = "";
63 services_actions_exec = actions_exec;
64 gint func_ref_actions = g_timeout_add(actions_interval * 1000, services_actions_perform, NULL);
66 if (strlen(updates_exec) > 0 && updates_interval > 0) {
67 if (strlen(updates_script) > 0) {
68 services_updates_script = g_strdup_printf(" %s", updates_script);
69 } else {
70 services_updates_script = "";
72 services_updates_exec = updates_exec;
73 gint func_ref_updates = g_timeout_add(updates_interval * 1000, services_updates_perform, NULL);