]> jfr.im git - irc/thales.git/commitdiff
Fix bugs in inheritance.
authorDmitry Bogatov <redacted>
Mon, 22 Oct 2012 15:12:20 +0000 (19:12 +0400)
committerDmitry Bogatov <redacted>
Mon, 22 Oct 2012 15:12:20 +0000 (19:12 +0400)
Fix compilation errors in log_worker.
TODO: Implement actual irc message listening.

Makefile.am
configure.ac
src/Makefile.am
src/irc.c
src/log_worker.c
src/main.c
src/worker.h

index 39207806dc88bc22e0e4a35b1e04b8b3107daa02..4d91111e94e62f36308527f2bc638625045afa9c 100644 (file)
@@ -1 +1 @@
-SUBDIRS = src doc
+SUBDIRS = lib src doc
index 34e2a41d170de603210a4f48fbb21c460c09dc83..2b39fbc1180b7161799ac83f9eef864b06bdb671 100644 (file)
@@ -10,7 +10,7 @@ gl_INIT
 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])])
 
@@ -18,6 +18,7 @@ AC_CHECK_LIB([ircclient],[irc_create_session],[],
 
 # Checks for library functions.
 AC_CONFIG_FILES([Makefile
+                                  lib/Makefile
                                   src/Makefile
                                   doc/Makefile])
 AC_OUTPUT
index fcf40ceb69246842f5b81f712b971b8f93b57988..05c10fc36abc7e8f38b9e08951f6cb527d6cf0c5 100644 (file)
@@ -1,2 +1,6 @@
+AM_CFLAGS = -I$(top_srcdir)/lib
+
 bin_PROGRAMS = thales
-thales_SOURCES = main.c cmd.h cmd.c conf.h conf.c
+thales_SOURCES = main.c cmd.h cmd.c conf.h conf.c worker.h \
+       log_worker.h log_worker.c irc.h irc.c
+thales_LDADD = $(top_builddir)/lib/libgnu.a
index 60fe1caa2103e5c1a82df6f6beb6e32971e3774a..9962df8fad10660e30ee7b5548601ecd19f7a41e 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -16,6 +16,8 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "irc.h"
 #include <stdio.h>
 #include <xalloc.h>
+#include <envz.h>
+#include <string.h>
 
 static inline bool
 config_error(const char *msg)
@@ -30,7 +32,7 @@ count_occurences(const char *str, char c)
   int count = 0;
 
   for (const char *p = str; *p; ++p)
-    count += *p = c;
+    count += *p == c;
   return count;
 }
 static char**
index c8d13f8f92f515b3082ef36df1f66eed7ca86f17..4b119aa9627e5617abd67b51a6d2e6148628dc4a 100644 (file)
@@ -14,30 +14,49 @@ General Public License for more details.
 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;
 }
index 6ac9464e44da01329aac6ccec735221f8bfc583d..f8419340a3f49c2a553616dfcd62fd85ec086bec 100644 (file)
@@ -23,6 +23,7 @@ static inline bool
 dummy(const char *type, const char *name,
       const struct envz *env)
 {
+  (void)(&env);
   printf("[%s]{%s}\n", type, name);
   fflush(stdout);
   return true;
index bda6c11d258aaeaad22139a9b432e84f67188b5a..c6c3550751a93f41919e7992026d92f56625055f 100644 (file)
@@ -16,13 +16,18 @@ this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #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