AC_GNU_SOURCE
AC_CHECK_HEADER([libircclient/libircclient.h],[],
- [AC_MSG_ERROR([libircclient header not found])])
+ [AC_MSG_ERROR([libircclient header not found])])
AC_CHECK_LIB([ircclient],[irc_create_session],[],
[AC_MSG_ERROR([libircclient library not found])])
# Checks for library functions.
AC_CONFIG_FILES([Makefile
+ lib/Makefile
src/Makefile
doc/Makefile])
AC_OUTPUT
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>. */
#include "log_worker.h"
+#include <stdlib.h>
+
+#include "xalloc.h"
+
+struct log_worker {
+ struct worker worker;
+ FILE *out_stream;
+};
static char *
-log_worker_function(const char *msg, struct irc_meta *meta, void *config)
+log_worker_process_message(const char *msg, struct irc_meta *meta,
+ struct worker *embed, const char *name)
{
- if (!config)
- config = stdout;
+ struct log_worker *logger = worker_entry(embed, struct log_worker, worker);
+ FILE *stream = logger->out_stream ? logger->out_stream : stdout;
- fputs(msg, config);
+ fprintf(stream, "[%s]: %s\n", name, msg);
+ return NULL;
+}
+
+static void
+log_worker_free_worker(struct worker *embed)
+{
+ struct log_worker *logger = worker_entry(embed, struct log_worker, worker);
+
+ if (logger->out_stream)
+ fclose(logger->out_stream);
+ free(logger);
}
struct worker*
create_log_worker(const struct envz *env)
{
- struct log_options *inner_opts;
- struct worker *worker;
+ struct log_worker *logger;
const char *output_filename = envz_get(env->envz, env->envz_len, "output");
- FILE *output_file = NULL;
- if (output_filename && !(output_file = fopen(output_filename, "a"))) {
+ FILE *out_stream = NULL;
+ if (output_filename && !(out_stream = fopen(output_filename, "a"))) {
fprintf(stderr, "log worker: specified file `%s' can not be appended\n",
output_filename);
return NULL;
}
- worker = xmalloc(sizeof *worker);
- worker->config = output_file;
-
+ logger = xmalloc(sizeof *logger);
+ logger->out_stream = out_stream;
+ return &logger->worker;
}
#ifndef MODULES_H
#define MODULES_H
-
+#include <stddef.h>
+#include <envz.h>
+#include <argz.h>
struct irc_meta {
};
-#define worker_entry(ptr,type,name) (type)((char *)ptr - offsetof(type,name))
+
+#define worker_entry(ptr,type,name) (type*)((char *)ptr - offsetof(type,name))
struct worker {
- char *(*func)(const char *msg, struct irc_meta *meta, struct worker *self);
+ char *(*process_command)(const char *msg, struct irc_meta *meta,
+ struct worker *self, char *name);
+ void (*free_worker)(struct worker *self);
};
#endif