Add checks in configure for non-POSIX syslog facilities.
[asterisk/asterisk.git] / main / syslog.c
index 97e5d7c..328ab5e 100644 (file)
@@ -30,73 +30,92 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include <syslog.h>
 
+static const struct {
+       const char *name;
+       int value;
+} facility_map[] = {
+       /* POSIX only specifies USER and LOCAL0 - LOCAL7 */
+       { "USER",     LOG_USER     },
+       { "LOCAL0",   LOG_LOCAL0   },
+       { "LOCAL1",   LOG_LOCAL1   },
+       { "LOCAL2",   LOG_LOCAL2   },
+       { "LOCAL3",   LOG_LOCAL3   },
+       { "LOCAL4",   LOG_LOCAL4   },
+       { "LOCAL5",   LOG_LOCAL5   },
+       { "LOCAL6",   LOG_LOCAL6   },
+       { "LOCAL7",   LOG_LOCAL7   },
+#if defined(HAVE_SYSLOG_FACILITY_LOG_KERN)
+       { "KERN",     LOG_KERN     },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_MAIL)
+       { "MAIL",     LOG_MAIL     },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_DAEMON)
+       { "DAEMON",   LOG_DAEMON   },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTH)
+       { "AUTH",     LOG_AUTH     },
+       { "SECURITY", LOG_AUTH     },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_AUTHPRIV)
+       { "AUTHPRIV", LOG_AUTHPRIV },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_SYSLOG)
+       { "SYSLOG",   LOG_SYSLOG   },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_FTP)
+       { "FTP",      LOG_FTP      },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_LPR)
+       { "LPR",      LOG_LPR      },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_NEWS)
+       { "NEWS",     LOG_NEWS     },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_UUCP)
+       { "UUCP",     LOG_UUCP     },
+#endif
+#if defined(HAVE_SYSLOG_FACILITY_LOG_CRON)
+       { "CRON",     LOG_CRON     },
+#endif
+};
+
 int ast_syslog_facility(const char *facility)
 {
-       if (!strcasecmp(facility, "KERN")) {
-               return LOG_KERN;
-       } else if (!strcasecmp(facility, "USER")) {
-               return LOG_USER;
-       } else if (!strcasecmp(facility, "MAIL")) {
-               return LOG_MAIL;
-       } else if (!strcasecmp(facility, "DAEMON")) {
-               return LOG_DAEMON;
-       } else if (!strcasecmp(facility, "AUTH")) {
-               return LOG_AUTH;
-       } else if (!strcasecmp(facility, "AUTHPRIV")) {
-               return LOG_AUTHPRIV;
-       } else if (!strcasecmp(facility, "SYSLOG")) {
-               return LOG_SYSLOG;
-       } else if (!strcasecmp(facility, "SECURITY")) {
-               return LOG_AUTH;
-       } else if (!strcasecmp(facility, "FTP")) {
-               return LOG_FTP;
-       } else if (!strcasecmp(facility, "LPR")) {
-               return LOG_LPR;
-       } else if (!strcasecmp(facility, "NEWS")) {
-               return LOG_NEWS;
-       } else if (!strcasecmp(facility, "UUCP")) {
-               return LOG_UUCP;
-       } else if (!strcasecmp(facility, "CRON")) {
-               return LOG_CRON;
-       } else if (!strcasecmp(facility, "LOCAL0")) {
-               return LOG_LOCAL0;
-       } else if (!strcasecmp(facility, "LOCAL1")) {
-               return LOG_LOCAL1;
-       } else if (!strcasecmp(facility, "LOCAL2")) {
-               return LOG_LOCAL2;
-       } else if (!strcasecmp(facility, "LOCAL3")) {
-               return LOG_LOCAL3;
-       } else if (!strcasecmp(facility, "LOCAL4")) {
-               return LOG_LOCAL4;
-       } else if (!strcasecmp(facility, "LOCAL5")) {
-               return LOG_LOCAL5;
-       } else if (!strcasecmp(facility, "LOCAL6")) {
-               return LOG_LOCAL6;
-       } else if (!strcasecmp(facility, "LOCAL7")) {
-               return LOG_LOCAL7;
+       int index;
+
+       for (index = 0; index < ARRAY_LEN(facility_map); index++) {
+               if (!strcasecmp(facility_map[index].name, facility)) {
+                       return facility_map[index].value;
+               }
        }
 
        return -1;
 }
 
+static const struct {
+       const char *name;
+       int value;
+} priority_map[] = {
+       { "ALERT",   LOG_ALERT   },
+       { "CRIT",    LOG_CRIT    },
+       { "DEBUG",   LOG_DEBUG   },
+       { "EMERG",   LOG_EMERG   },
+       { "ERR",     LOG_ERR     },
+       { "ERROR",   LOG_ERR     },
+       { "INFO",    LOG_INFO    },
+       { "NOTICE",  LOG_NOTICE  },
+       { "WARNING", LOG_WARNING }
+};
+
 int ast_syslog_priority(const char *priority)
 {
-       if (!strcasecmp(priority, "ALERT")) {
-               return LOG_ALERT;
-       } else if (!strcasecmp(priority, "CRIT")) {
-               return LOG_CRIT;
-       } else if (!strcasecmp(priority, "DEBUG")) {
-               return LOG_DEBUG;
-       } else if (!strcasecmp(priority, "EMERG")) {
-               return LOG_EMERG;
-       } else if (!strcasecmp(priority, "ERR")) {
-               return LOG_ERR;
-       } else if (!strcasecmp(priority, "INFO")) {
-               return LOG_INFO;
-       } else if (!strcasecmp(priority, "NOTICE")) {
-               return LOG_NOTICE;
-       } else if (!strcasecmp(priority, "WARNING")) {
-               return LOG_WARNING;
+       int index;
+
+       for (index = 0; index < ARRAY_LEN(priority_map); index++) {
+               if (!strcasecmp(priority_map[index].name, priority)) {
+                       return priority_map[index].value;
+               }
        }
 
        return -1;