gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r2997 - GNUnet/src/include


From: grothoff
Subject: [GNUnet-SVN] r2997 - GNUnet/src/include
Date: Sat, 10 Jun 2006 02:21:08 -0700 (PDT)

Author: grothoff
Date: 2006-06-10 02:21:03 -0700 (Sat, 10 Jun 2006)
New Revision: 2997

Added:
   GNUnet/src/include/gnunet_config.h
   GNUnet/src/include/gnunet_error.h
Modified:
   GNUnet/src/include/Makefile.am
Log:
rfc

Modified: GNUnet/src/include/Makefile.am
===================================================================
--- GNUnet/src/include/Makefile.am      2006-06-10 08:24:21 UTC (rev 2996)
+++ GNUnet/src/include/Makefile.am      2006-06-10 09:21:03 UTC (rev 2997)
@@ -14,6 +14,7 @@
 gnunetinclude_HEADERS = \
   gnunet_blockstore.h \
   gnunet_bootstrap_service.h \
+  gnunet_config.h \
   gnunet_core.h \
   gnunet_datastore_service.h \
   gnunet_dht.h \

Added: GNUnet/src/include/gnunet_config.h
===================================================================
--- GNUnet/src/include/gnunet_config.h  2006-06-10 08:24:21 UTC (rev 2996)
+++ GNUnet/src/include/gnunet_config.h  2006-06-10 09:21:03 UTC (rev 2997)
@@ -0,0 +1,212 @@
+/*
+     This file is part of GNUnet.
+     (C) 2006 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet 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
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file include/gnunet_config.h
+ * @brief configuration API
+ *
+ * @author Christian Grothoff
+ */
+
+#ifndef GNUNET_CONFIG_H
+#define GNUNET_CONFIG_H
+
+#include "gnunet_error.h"
+
+#define GNUNET_CONFIG_VERSION 0x00000000
+
+#ifdef __cplusplus
+extern "C" {
+#if 0 /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+struct GC_Configuration;
+
+struct GC_Configuration * GC_create(void);
+
+void GC_free(struct GC_Configuration * cfg);
+
+/**
+ * Set the context for reporting configuration IO errors
+ * (and errors reported by configuration change notification
+ * callbacks when reading a new configuration).
+ *
+ * Note that for setting options a different context can be
+ * used (since failing to change an option may have to be reported
+ * in a fundamentally different way to the user).
+ * 
+ * @parm ectx maybe NULL, in that case errors will no longer
+ *       be reported
+ */
+void GC_set_error_context(struct GC_Configuration * cfg,
+                         struct GE_Context * ectx);
+
+/**
+ * Parse a configuration file, add all of the options in the
+ * file to the configuration environment.
+ * @return 0 on success, -1 on error
+ */
+int GC_parse_configuration(struct GC_Configuration * cfg,
+                          const char * filename);
+
+/**
+ * Test if there are configuration options that were
+ * changed since the last save.
+ * @return 0 if clean, 1 if dirty, -1 on error (i.e. last save failed)
+ */
+int GC_test_dirty(struct GC_Configuration * cfg);
+
+
+/**
+ * Write configuration file.
+ * @return 0 on success, -1 on error
+ */
+int GC_write_configuration(struct GC_Configuration * cfg,
+                          const char * filename);
+
+/**
+ * Get a configuration value that should be a number.
+ * @param min minimal legal value
+ * @param max maximal legal value
+ * @param default default value (use indicated by return value)
+ * @return 0 on success, -1 on error, 1 for default
+ */
+int GC_get_configuration_value_number(struct GC_Configuration * cfg,
+                                     const char * section,
+                                     const char * option,
+                                     unsigned long long min,
+                                     unsigned long long max,
+                                     unsigned long long default,
+                                     unsigned long long * number);
+
+
+/**
+ * Get a configuration value that should be a string.
+ * @param default default value (use indicated by return value;
+ *        will NOT be aliased, maybe NULL)
+ * @param value will be set to a freshly allocated configuration
+ *        value, or NULL if option is not specified and no default given
+ * @return 0 on success, -1 on error, 1 for default
+ */
+int GC_get_configuration_value_string(struct GC_Configuration * cfg,
+                                     const char * section,
+                                     const char * option,
+                                     const char * default,
+                                     char ** value);
+
+/**
+ * Get a configuration value that should be in a set of
+ * predefined strings
+ * @param choices NULL-terminated list of legal values
+ * @param default default value (use indicated by return value;
+ *        will NOT be aliased, maybe NULL), must be reference
+ *        into set given by choices
+ * @param value will be set to an entry in the legal list,
+ *        or NULL if option is not specified and no default given
+ * @return 0 on success, -1 on error, 1 for default
+ */
+int GC_get_configuration_value_choice(struct GC_Configuration * cfg,
+                                     const char * section,
+                                     const char * option,
+                                     const char ** choices,
+                                     const char * default,
+                                     (const char *)* value);
+
+/**
+ * Set a configuration value that should be a number.
+ * @return 0 on success, -1 on error (i.e. out of memory,
+ *   or update refused by registered callback)
+ */
+int GC_set_configuration_value_number(struct GC_Configuration * cfg,
+                                     struct GE_Context * ectx
+                                     const char * section,
+                                     const char * option,
+                                     unsigned long long number);
+
+
+/**
+ * Set a configuration value that should be a string.
+ * @param value
+ * @return 0 on success, -1 on error (i.e. out of memory,
+ *   or update refused by registered callback)
+ */
+int GC_set_configuration_value_string(struct GC_Configuration * cfg,
+                                     struct GE_Context * ectx
+                                     const char * section,
+                                     const char * option,
+                                     const char * value);
+
+/**
+ * Set a configuration value that should be in a set of
+ * predefined strings.  
+ * @param value
+ * @return 0 on success, -1 on error (i.e. out of memory,
+ *   or update refused by registered callback)
+ */
+int GC_set_configuration_value_choice(struct GC_Configuration * cfg,
+                                     struct GE_Context * ectx
+                                     const char * section,
+                                     const char * option,
+                                     const char * choice);
+
+/**
+ * Callback function that is called if a configuration option
+ * changes.  Note that the new value is not explicitly
+ * communicated, the client must query it.
+ *
+ * @param ectx context to log errors to
+ * @return 0 if the change is ok, -1 if the change must be
+ *         refused
+ */
+typedef int (*GC_ChangeListener)(void * ctx,
+                                struct GC_Configuration * cfg, 
+                                struct GE_Context * ectx,
+                                const char * section,
+                                const char * option);
+
+/**
+ * Attach a callback that is notified whenever a 
+ * configuration option changes.
+ * @return 0 on success, -1 on error
+ */
+int GC_attachChangeListener(struct GC_Configuration * cfg,
+                           GC_ChangeListener callback,
+                           void * ctx);
+
+/**
+ * Attach a callback that is notified whenever a 
+ * configuration option changes.
+ * @return 0 on success, -1 on error, 1 for no such handler registered
+ */
+int GC_detachChangeListener(struct GC_Configuration * cfg,
+                           GC_ChangeListener callback,
+                           void * ctx);
+
+
+#if 0 /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif


Property changes on: GNUnet/src/include/gnunet_config.h
___________________________________________________________________
Name: svn:eol-style
   + native

Added: GNUnet/src/include/gnunet_error.h
===================================================================
--- GNUnet/src/include/gnunet_error.h   2006-06-10 08:24:21 UTC (rev 2996)
+++ GNUnet/src/include/gnunet_error.h   2006-06-10 09:21:03 UTC (rev 2997)
@@ -0,0 +1,173 @@
+/*
+     This file is part of GNUnet.
+     (C) 2006 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet 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
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file include/gnunet_error.h
+ * @brief error handling API
+ *
+ * @author Christian Grothoff
+ */
+
+#ifndef GNUNET_ERROR_H
+#define GNUNET_ERROR_H
+
+#define GNUNET_ERROR_VERSION 0x00000000
+
+#ifdef __cplusplus
+extern "C" {
+#if 0 /* keep Emacsens' auto-indent happy */
+}
+#endif
+#endif
+
+struct GE_Context;
+
+struct GE_Memory;
+
+typedef enum {
+  /* type of event */
+  GE_DEBUG     = 0x00000001, /* DEBUG/CRON/EVERYTHING */
+  GE_STATUS    = 0x00000002, /* INFO/MESSAGE */
+  GE_WARNING   = 0x00000004,
+  GE_ERROR     = 0x00000008,
+  GE_FATAL     = 0x00000010, /* FATAL/FAILURE/NOTHING */
+  GE_EVENTKIND = 0x000000FF, /* bitmask */
+
+  /* who should see the message? */
+  GE_USER      = 0x01000000, /* current user, if possible */
+  GE_ADMIN     = 0x02000000, /* system administrator */
+  GE_USERKIND  = 0x0F000000, /* bitmask */
+
+  /* how event should be routed */
+  GE_REQUEST   = 0x20000000, /* display on request only (i.e. low-priority 
log, user demands verbose events) */
+  GE_BULK      = 0x40000000, /* display in bulk output (i.e. log-file, scroll 
window, console) */
+  GE_IMMEDIATE = 0x80000000, /* display immediately (i.e. pop-up, e-mail) */
+  GE_ROUTEKIND = 0xF0000000, /* bitmask */
+  GE_ALL       = 0xFFFFFFFF, 
+} GE_MASK;
+
+
+void GE_LOG(struct GE_Context * ctx,
+           GE_KIND kind,
+           const char * message,
+           ...);
+
+/**
+ * Create a context that sends events to two other contexts.
+ * Note that the client must stop using ctx1/ctx2 henceforth.
+ */
+struct GE_Context * GE_create_context_multiplexer(struct GE_Context * ctx1,
+                                                 struct GE_Context * ctx2);
+
+
+/**
+ * User-defined handler for Log events.
+ */
+typedef void (*GE_LogHandler)(void * ctx,
+                             GE_MASK kind,
+                             const char * date,
+                             const char * msg);
+
+/**
+ * Create a log context that calls a callback function
+ * for matching events.
+ *
+ * @param mask which events is this handler willing to process?
+ *        an event must be non-zero in all 3 GE_MASK categories
+ *        to be passed to this handler
+ */
+struct GE_Context * GE_create_context_callback(GE_MASK mask,
+                                              GE_LogHandler handler,
+                                              void * ctx);
+                                
+/**
+ * Create a logger that writes events to a file.
+ * 
+ * @param mask which events should be logged?
+ * @param filename which file should we log to?
+ * @param logDate should the context log event dates?
+ * @param logrotate after how many seconds should the log
+ *        files be rotated (use 0 for no rotation)
+ */
+struct GE_Context * GE_create_context_logfile(GE_MASK mask,
+                                             const char * filename,
+                                             int logDate,
+                                             unsigned int logrotate);
+
+/**
+ * Create a logger that keeps events in memory (to be
+ * queried later in bulk).
+ */
+struct GE_Context * GE_create_context_memory(GE_MASK mask,
+                                            struct GE_Memory * memory);
+
+/**
+ * Free a log context.
+ */
+void GE_free_context(GE_Context * ctx);                                        
+
+#if FICTION      
+/**
+ * @param address e-mail address to send the logs to
+ * @param server hostname of SMTP gateway, NULL for using local "mail" command
+ * @param port port to use for SMTP
+ * @param logDate should the date be each of the log lines?
+ * @param bulkSize for GE_BULK messages, how many lines of messages
+ *        should be accumulated before an e-mail is transmitted?
+ */
+struct GE_Context * GE_create_context_email(GE_MASK mask,
+                                           const char * address,
+                                           const char * server,
+                                           unsigned short port,
+                                           int logDate,
+                                           unsigned int bulkSize);
+#endif
+
+/**
+ * Create a context to log messages in memory.
+ * This is useful if we first need to capture all
+ * log messages of an operation to provide the
+ * final error in bulk to the client (i.e. as
+ * a return value, possibly over the network).
+ * 
+ * @param maxSize the maximum number of messages to keep, 0 for unbounded
+ *  (if more than maxSize messages are received, message number maxSize
+ *   will be set to a corresponding warning)
+ */
+struct GE_Memory * GE_create_memory(unsigned int maxSize);
+
+/**
+ * For all messages stored in the memory, call the handler.
+ */
+void GE_poll_memory(struct GE_Memory * memory,
+                   GE_LogHandler handler,
+                   void * ctx);
+
+void GE_free_memory(struct GE_Memory * memory);
+
+
+#if 0 /* keep Emacsens' auto-indent happy */
+{
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+#endif


Property changes on: GNUnet/src/include/gnunet_error.h
___________________________________________________________________
Name: svn:eol-style
   + native





reply via email to

[Prev in Thread] Current Thread [Next in Thread]