diff options
Diffstat (limited to 'src/include/gnunet_configuration_lib.h')
-rw-r--r-- | src/include/gnunet_configuration_lib.h | 193 |
1 files changed, 189 insertions, 4 deletions
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index 21a5ab810..570546b68 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h | |||
@@ -113,6 +113,18 @@ GNUNET_CONFIGURATION_default (void); | |||
113 | 113 | ||
114 | 114 | ||
115 | /** | 115 | /** |
116 | * Return the filename of the default configuration filename | ||
117 | * that is used when no explicit configuration entry point | ||
118 | * has been specified. | ||
119 | * | ||
120 | * @returns NULL if no default configuration file can be located, | ||
121 | * a newly allocated string otherwise | ||
122 | */ | ||
123 | char * | ||
124 | GNUNET_CONFIGURATION_default_filename (void); | ||
125 | |||
126 | |||
127 | /** | ||
116 | * Parse a configuration file, add all of the options in the | 128 | * Parse a configuration file, add all of the options in the |
117 | * file to the configuration environment. | 129 | * file to the configuration environment. |
118 | * | 130 | * |
@@ -139,21 +151,33 @@ GNUNET_CONFIGURATION_serialize (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
139 | 151 | ||
140 | 152 | ||
141 | /** | 153 | /** |
154 | * Serializes the given configuration with diagnostics information. | ||
155 | * Diagnostics information will only be available if diagnostics | ||
156 | * have been enabled before parsing. | ||
157 | * | ||
158 | * @param cfg configuration to serialize | ||
159 | * @return the memory block where the serialized configuration is | ||
160 | * present. This memory should be freed by the caller | ||
161 | */ | ||
162 | char * | ||
163 | GNUNET_CONFIGURATION_serialize_diagnostics (const struct | ||
164 | GNUNET_CONFIGURATION_Handle *cfg); | ||
165 | |||
166 | /** | ||
142 | * De-serializes configuration | 167 | * De-serializes configuration |
143 | * | 168 | * |
144 | * @param cfg configuration to update | 169 | * @param cfg configuration to update |
145 | * @param mem the memory block of serialized configuration | 170 | * @param mem the memory block of serialized configuration |
146 | * @param size the size of the memory block | 171 | * @param size the size of the memory block |
147 | * @param allow_inline set to the base directory if we recursively load configuration | 172 | * @param source_filename source filename, will be used |
148 | * from inlined configurations; NULL if not and raise warnings | 173 | * to resolve relative @INLINE@ statements |
149 | * when we come across them | ||
150 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 174 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
151 | */ | 175 | */ |
152 | enum GNUNET_GenericReturnValue | 176 | enum GNUNET_GenericReturnValue |
153 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | 177 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, |
154 | const char *mem, | 178 | const char *mem, |
155 | size_t size, | 179 | size_t size, |
156 | const char *basedir); | 180 | const char *source_filename); |
157 | 181 | ||
158 | 182 | ||
159 | /** | 183 | /** |
@@ -235,6 +259,16 @@ GNUNET_CONFIGURATION_parse_and_run (const char *filename, | |||
235 | GNUNET_CONFIGURATION_Callback cb, | 259 | GNUNET_CONFIGURATION_Callback cb, |
236 | void *cb_cls); | 260 | void *cb_cls); |
237 | 261 | ||
262 | /** | ||
263 | * Enable extra diagnostics. Will produce more log output | ||
264 | * and allocate more memory. | ||
265 | * | ||
266 | * @param cfg configuration handle | ||
267 | */ | ||
268 | void | ||
269 | GNUNET_CONFIGURATION_enable_diagnostics (struct | ||
270 | GNUNET_CONFIGURATION_Handle *cfg); | ||
271 | |||
238 | 272 | ||
239 | /** | 273 | /** |
240 | * Function to iterate over options. | 274 | * Function to iterate over options. |
@@ -598,6 +632,157 @@ GNUNET_CONFIGURATION_append_value_filename (struct | |||
598 | const char *option, | 632 | const char *option, |
599 | const char *value); | 633 | const char *value); |
600 | 634 | ||
635 | |||
636 | /** | ||
637 | * Closure for #GNUNET_CONFIGURATION_config_tool_run() | ||
638 | * with settings for what should be done with the | ||
639 | * configuration. | ||
640 | */ | ||
641 | struct GNUNET_CONFIGURATION_ConfigSettings | ||
642 | { | ||
643 | |||
644 | /** | ||
645 | * Must be set to the API version, i.e. | ||
646 | * #GNUNET_UTIL_VERSION. Used to detect | ||
647 | * which version of the struct the client | ||
648 | * is using. | ||
649 | */ | ||
650 | unsigned int api_version; | ||
651 | |||
652 | /** | ||
653 | * Name of the section | ||
654 | */ | ||
655 | char *section; | ||
656 | |||
657 | /** | ||
658 | * Name of the option | ||
659 | */ | ||
660 | char *option; | ||
661 | |||
662 | /** | ||
663 | * Value to set | ||
664 | */ | ||
665 | char *value; | ||
666 | |||
667 | /** | ||
668 | * Treat option as a filename. | ||
669 | */ | ||
670 | int is_filename; | ||
671 | |||
672 | /** | ||
673 | * Whether to show the sections. | ||
674 | */ | ||
675 | int list_sections; | ||
676 | |||
677 | /** | ||
678 | * Should we write out the configuration file, even if no value was changed? | ||
679 | */ | ||
680 | int rewrite; | ||
681 | |||
682 | /** | ||
683 | * Should we give extra diagnostics? | ||
684 | */ | ||
685 | int diagnostics; | ||
686 | |||
687 | /** | ||
688 | * Should the generated configuration file contain the whole configuration? | ||
689 | */ | ||
690 | int full; | ||
691 | |||
692 | |||
693 | /** | ||
694 | * Return value from the operation, to be returned | ||
695 | * from 'main'. | ||
696 | */ | ||
697 | int global_ret; | ||
698 | |||
699 | }; | ||
700 | |||
701 | |||
702 | /** | ||
703 | * Macro that expands to a set of GNUNET-getopt directives | ||
704 | * to initialize a `struct GNUNET_CONFIGURATION_ConfigSettings` | ||
705 | * from the command line. | ||
706 | * | ||
707 | * @param cs configuration settings to initialize | ||
708 | */ | ||
709 | #define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \ | ||
710 | GNUNET_GETOPT_option_flag ( \ | ||
711 | 'F', \ | ||
712 | "full", \ | ||
713 | gettext_noop ( \ | ||
714 | "write the full configuration file, including default values"), \ | ||
715 | &(cs)->full), \ | ||
716 | GNUNET_GETOPT_option_flag ( \ | ||
717 | 'f', \ | ||
718 | "filename", \ | ||
719 | gettext_noop ("interpret option value as a filename (with $-expansion)"), \ | ||
720 | &(cs)->is_filename), \ | ||
721 | GNUNET_GETOPT_option_string ('o', \ | ||
722 | "option", \ | ||
723 | "OPTION", \ | ||
724 | gettext_noop ("name of the option to access"), \ | ||
725 | &(cs)->option), \ | ||
726 | GNUNET_GETOPT_option_flag ( \ | ||
727 | 'r', \ | ||
728 | "rewrite", \ | ||
729 | gettext_noop ( \ | ||
730 | "rewrite the configuration file, even if nothing changed"), \ | ||
731 | &(cs)->rewrite), \ | ||
732 | GNUNET_GETOPT_option_flag ( \ | ||
733 | 'd', \ | ||
734 | "diagnostics", \ | ||
735 | gettext_noop ( \ | ||
736 | "output extra diagnostics"), \ | ||
737 | &(cs)->diagnostics), \ | ||
738 | GNUNET_GETOPT_option_flag ('S', \ | ||
739 | "list-sections", \ | ||
740 | gettext_noop ( \ | ||
741 | "print available configuration sections"), \ | ||
742 | &(cs)->list_sections), \ | ||
743 | GNUNET_GETOPT_option_string ('s', \ | ||
744 | "section", \ | ||
745 | "SECTION", \ | ||
746 | gettext_noop ( \ | ||
747 | "name of the section to access"), \ | ||
748 | &(cs)->section), \ | ||
749 | GNUNET_GETOPT_option_string ('V', \ | ||
750 | "value", \ | ||
751 | "VALUE", \ | ||
752 | gettext_noop ("value to set"), \ | ||
753 | &(cs)->value) | ||
754 | |||
755 | |||
756 | /** | ||
757 | * Free resources associated with @a cs. | ||
758 | * | ||
759 | * @param[in] cs settings to free (actual memory | ||
760 | * of @a cs itself is not released) | ||
761 | */ | ||
762 | void | ||
763 | GNUNET_CONFIGURATION_config_settings_free ( | ||
764 | struct GNUNET_CONFIGURATION_ConfigSettings *cs); | ||
765 | |||
766 | |||
767 | /** | ||
768 | * Main task to run to perform operations typical for | ||
769 | * gnunet-config as per the configuration settings | ||
770 | * given in @a cls. | ||
771 | * | ||
772 | * @param cls closure with the `struct GNUNET_CONFIGURATION_ConfigSettings` | ||
773 | * @param args remaining command-line arguments | ||
774 | * @param cfgfile name of the configuration file used (for saving, | ||
775 | * can be NULL!) | ||
776 | * @param cfg configuration | ||
777 | */ | ||
778 | void | ||
779 | GNUNET_CONFIGURATION_config_tool_run ( | ||
780 | void *cls, | ||
781 | char *const *args, | ||
782 | const char *cfgfile, | ||
783 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
784 | |||
785 | |||
601 | #if 0 /* keep Emacsens' auto-indent happy */ | 786 | #if 0 /* keep Emacsens' auto-indent happy */ |
602 | { | 787 | { |
603 | #endif | 788 | #endif |