diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-11-02 15:44:27 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-11-02 15:44:27 +0200 |
commit | 38e58d3662ac6c2e53e9ec8b85934e0e23a199c0 (patch) | |
tree | 13eb93e3ff14c94ccdcaa13a0a85ed883ece438a /src/main.c | |
parent | f7ea305fee69c0814a075d01b2b92a153916f093 (diff) | |
download | mailfromd-38e58d3662ac6c2e53e9ec8b85934e0e23a199c0.tar.gz mailfromd-38e58d3662ac6c2e53e9ec8b85934e0e23a199c0.tar.bz2 |
Follow Mailutils commit dc62b399
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 171 |
1 files changed, 139 insertions, 32 deletions
@@ -931,33 +931,62 @@ mf_runtime_param_finish() | |||
931 | 931 | ||
932 | 932 | ||
933 | /* Auxiliary functions */ | 933 | /* Auxiliary functions */ |
934 | unsigned keyword_column = 0; | ||
935 | unsigned header_column = 2; | ||
936 | unsigned value_column = 32; | ||
937 | unsigned right_margin = 79; | ||
938 | |||
939 | static void | ||
940 | set_column(mu_stream_t str, unsigned margin) | ||
941 | { | ||
942 | mu_stream_ioctl(str, MU_IOCTL_WORDWRAPSTREAM, | ||
943 | MU_IOCTL_WORDWRAP_SET_MARGIN, | ||
944 | &margin); | ||
945 | } | ||
934 | 946 | ||
935 | static int | 947 | static int |
936 | db_format_enumerator(struct db_format *fmt, void *data) | 948 | db_format_enumerator(struct db_format *fmt, void *data) |
937 | { | 949 | { |
938 | printf("%s database: %s\n", fmt->name, fmt->dbname); | 950 | mu_stream_t str = data; |
951 | |||
952 | set_column(str, keyword_column); | ||
953 | mu_stream_printf(str, "%s database:", fmt->name); | ||
954 | set_column(str, value_column); | ||
955 | mu_stream_printf(str, "%s\n", fmt->dbname); | ||
956 | |||
957 | set_column(str, keyword_column); | ||
939 | if (strcmp(fmt->name, "cache") == 0) { | 958 | if (strcmp(fmt->name, "cache") == 0) { |
940 | printf("%s positive expiration: %lu\n", fmt->name, | 959 | mu_stream_printf(str, "%s positive expiration:", fmt->name); |
941 | fmt->expire_interval); | 960 | set_column(str, value_column); |
942 | printf("%s negative expiration: %lu\n", fmt->name, | 961 | mu_stream_printf(str, "%lu\n", fmt->expire_interval); |
943 | negative_expire_interval); | 962 | |
944 | } else | 963 | set_column(str, keyword_column); |
945 | printf("%s expiration: %lu\n", fmt->name, | 964 | mu_stream_printf(str, "%s negative expiration:", fmt->name); |
946 | fmt->expire_interval); | 965 | set_column(str, value_column); |
966 | mu_stream_printf(str, "%lu\n", negative_expire_interval); | ||
967 | } else { | ||
968 | mu_stream_printf(str, "%s expiration:", fmt->name); | ||
969 | set_column(str, value_column); | ||
970 | mu_stream_printf(str, "%lu\n", fmt->expire_interval); | ||
971 | } | ||
947 | return 0; | 972 | return 0; |
948 | } | 973 | } |
949 | 974 | ||
950 | static void | 975 | static void |
951 | list_db_formats(const char *pfx) | 976 | list_db_formats(mu_stream_t str, const char *pfx) |
952 | { | 977 | { |
953 | mu_iterator_t itr; | 978 | mu_iterator_t itr; |
954 | int rc; | 979 | int rc; |
955 | const char *defdb = DEFAULT_DB_TYPE; | 980 | const char *defdb = DEFAULT_DB_TYPE; |
956 | printf("%s", pfx); | 981 | |
982 | set_column(str, keyword_column); | ||
983 | mu_stream_printf(str, "%s:", pfx); | ||
984 | |||
985 | set_column(str, value_column); | ||
957 | 986 | ||
958 | rc = mu_dbm_impl_iterator(&itr); | 987 | rc = mu_dbm_impl_iterator(&itr); |
959 | if (rc) { | 988 | if (rc) { |
960 | printf("%s\n", _("unknown")); | 989 | mu_stream_printf(str, "%s\n", _("unknown")); |
961 | mu_error("%s", mu_strerror(rc)); | 990 | mu_error("%s", mu_strerror(rc)); |
962 | } else { | 991 | } else { |
963 | int i; | 992 | int i; |
@@ -967,45 +996,123 @@ list_db_formats(const char *pfx) | |||
967 | 996 | ||
968 | mu_iterator_current(itr, (void**)&impl); | 997 | mu_iterator_current(itr, (void**)&impl); |
969 | if (i) | 998 | if (i) |
970 | printf(", "); | 999 | mu_stream_printf(str, ", "); |
971 | else if (!defdb) | 1000 | else if (!defdb) |
972 | defdb = impl->_dbm_name; | 1001 | defdb = impl->_dbm_name; |
973 | printf("%s", impl->_dbm_name); | 1002 | mu_stream_printf(str, "%s", impl->_dbm_name); |
974 | } | 1003 | } |
975 | putchar('\n'); | 1004 | mu_stream_write(str, "\n", 1, NULL); |
976 | mu_iterator_destroy(&itr); | 1005 | mu_iterator_destroy(&itr); |
977 | } | 1006 | } |
978 | printf("default database type: %s\n", defdb); | 1007 | |
1008 | set_column(str, keyword_column); | ||
1009 | mu_stream_printf(str, "%s:", "default database type"); | ||
1010 | set_column(str, value_column); | ||
1011 | mu_stream_printf(str, "%s\n", defdb); | ||
979 | } | 1012 | } |
980 | 1013 | ||
981 | void | 1014 | struct string_value { |
982 | mailfromd_show_defaults() | 1015 | char const *kw; |
1016 | int type; | ||
1017 | union { | ||
1018 | char *s_const; | ||
1019 | char **s_var; | ||
1020 | char *(*s_func) (void); | ||
1021 | } data; | ||
1022 | }; | ||
1023 | |||
1024 | static char * | ||
1025 | string_preprocessor (void) | ||
983 | { | 1026 | { |
984 | printf("version: %s\n", VERSION); | 1027 | return ext_pp ? ext_pp : "none"; |
985 | printf("script file: %s\n", script_file); | 1028 | } |
986 | printf("preprocessor: %s\n", ext_pp ? ext_pp : "none"); | 1029 | |
987 | printf("user: %s\n", mf_server_user); | ||
988 | printf("statedir: %s\n", mailfromd_state_dir); | ||
989 | printf("socket: %s\n", DEFAULT_SOCKET); | ||
990 | printf("pidfile: %s\n", pidfile); | ||
991 | #ifdef USE_SYSLOG_ASYNC | 1030 | #ifdef USE_SYSLOG_ASYNC |
992 | # if DEFAULT_SYSLOG_ASYNC == 1 | 1031 | # if DEFAULT_SYSLOG_ASYNC == 1 |
993 | printf("default syslog: non-blocking\n"); | 1032 | # define DEFAULT_SYSLOG "non-blocking" |
994 | # else | 1033 | # else |
995 | printf("default syslog: blocking\n"); | 1034 | # define DEFAULT_SYSLOG "blocking" |
996 | # endif | 1035 | # endif |
1036 | #else | ||
1037 | # define DEFAULT_SYSLOG "blocking" | ||
997 | #endif | 1038 | #endif |
998 | list_db_formats("supported databases: "); | 1039 | |
999 | printf("Optional features: "); | 1040 | enum { |
1041 | STRING_CONSTANT, | ||
1042 | STRING_VARIABLE, | ||
1043 | STRING_FUNCTION | ||
1044 | }; | ||
1045 | |||
1046 | static struct string_value string_values[] = { | ||
1047 | { "version", STRING_CONSTANT, { .s_const = VERSION } }, | ||
1048 | { "script file", STRING_VARIABLE, { .s_var = &script_file } }, | ||
1049 | { "preprocessor", STRING_FUNCTION, { .s_func = string_preprocessor } }, | ||
1050 | { "user", STRING_VARIABLE, { .s_var = &mf_server_user } }, | ||
1051 | { "statedir", STRING_VARIABLE, { .s_var = &mailfromd_state_dir } }, | ||
1052 | { "socket", STRING_CONSTANT, { .s_const = DEFAULT_SOCKET } }, | ||
1053 | { "pidfile", STRING_VARIABLE, { .s_var = &pidfile } }, | ||
1054 | { "default syslog", STRING_CONSTANT, { .s_const = DEFAULT_SYSLOG } }, | ||
1055 | { NULL } | ||
1056 | }; | ||
1057 | |||
1058 | static void | ||
1059 | print_string_values(mu_stream_t str) | ||
1060 | { | ||
1061 | struct string_value *p; | ||
1062 | char const *val; | ||
1063 | |||
1064 | for (p = string_values; p->kw; p++) { | ||
1065 | set_column(str, keyword_column); | ||
1066 | mu_stream_printf(str, "%s:", p->kw); | ||
1067 | |||
1068 | switch (p->type) { | ||
1069 | case STRING_CONSTANT: | ||
1070 | val = p->data.s_const; | ||
1071 | break; | ||
1072 | |||
1073 | case STRING_VARIABLE: | ||
1074 | val = *p->data.s_var; | ||
1075 | break; | ||
1076 | |||
1077 | case STRING_FUNCTION: | ||
1078 | val = p->data.s_func (); | ||
1079 | } | ||
1080 | |||
1081 | set_column(str, value_column); | ||
1082 | mu_stream_printf(str, "%s\n", val); | ||
1083 | } | ||
1084 | } | ||
1085 | |||
1086 | void | ||
1087 | mailfromd_show_defaults(void) | ||
1088 | { | ||
1089 | int rc; | ||
1090 | mu_stream_t str; | ||
1091 | |||
1092 | rc = mu_wordwrap_stream_create (&str, mu_strout, 0, right_margin); | ||
1093 | if (rc) { | ||
1094 | str = mu_strout; | ||
1095 | mu_stream_ref(str); | ||
1096 | } | ||
1097 | |||
1098 | print_string_values(str); | ||
1099 | |||
1100 | list_db_formats(str, "supported databases"); | ||
1101 | |||
1102 | set_column(str, keyword_column); | ||
1103 | mu_stream_printf(str, "%s:", "optional features"); | ||
1104 | set_column(str, value_column); | ||
1000 | #if defined WITH_GEOIP | 1105 | #if defined WITH_GEOIP |
1001 | printf(" GeoIP"); | 1106 | mu_stream_printf(str, " %s", "GeoIP"); |
1002 | #endif | 1107 | #endif |
1003 | #if defined WITH_DSPAM | 1108 | #if defined WITH_DSPAM |
1004 | printf(" DSPAM"); | 1109 | mu_stream_printf(str, " %s", "DSPAM"); |
1005 | #endif | 1110 | #endif |
1006 | printf("\n"); | 1111 | mu_stream_write(str, "\n", 1, NULL); |
1112 | |||
1113 | db_format_enumerate(db_format_enumerator, str); | ||
1007 | 1114 | ||
1008 | db_for |