/contrib/bind9/lib/isc/unix/syslog.c

https://bitbucket.org/freebsd/freebsd-head/ · C · 84 lines · 56 code · 10 blank · 18 comment · 6 complexity · 52f917ebf0825e22caca9a94e70c817a MD5 · raw file

  1. /*
  2. * Copyright (C) 2004, 2005, 2007 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 2001 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: syslog.c,v 1.8 2007/09/13 04:45:18 each Exp $ */
  18. /*! \file */
  19. #include <config.h>
  20. #include <stdlib.h>
  21. #include <syslog.h>
  22. #include <isc/result.h>
  23. #include <isc/string.h>
  24. #include <isc/syslog.h>
  25. #include <isc/util.h>
  26. static struct dsn_c_pvt_sfnt {
  27. int val;
  28. const char *strval;
  29. } facilities[] = {
  30. { LOG_KERN, "kern" },
  31. { LOG_USER, "user" },
  32. { LOG_MAIL, "mail" },
  33. { LOG_DAEMON, "daemon" },
  34. { LOG_AUTH, "auth" },
  35. { LOG_SYSLOG, "syslog" },
  36. { LOG_LPR, "lpr" },
  37. #ifdef LOG_NEWS
  38. { LOG_NEWS, "news" },
  39. #endif
  40. #ifdef LOG_UUCP
  41. { LOG_UUCP, "uucp" },
  42. #endif
  43. #ifdef LOG_CRON
  44. { LOG_CRON, "cron" },
  45. #endif
  46. #ifdef LOG_AUTHPRIV
  47. { LOG_AUTHPRIV, "authpriv" },
  48. #endif
  49. #ifdef LOG_FTP
  50. { LOG_FTP, "ftp" },
  51. #endif
  52. { LOG_LOCAL0, "local0"},
  53. { LOG_LOCAL1, "local1"},
  54. { LOG_LOCAL2, "local2"},
  55. { LOG_LOCAL3, "local3"},
  56. { LOG_LOCAL4, "local4"},
  57. { LOG_LOCAL5, "local5"},
  58. { LOG_LOCAL6, "local6"},
  59. { LOG_LOCAL7, "local7"},
  60. { 0, NULL }
  61. };
  62. isc_result_t
  63. isc_syslog_facilityfromstring(const char *str, int *facilityp) {
  64. int i;
  65. REQUIRE(str != NULL);
  66. REQUIRE(facilityp != NULL);
  67. for (i = 0; facilities[i].strval != NULL; i++) {
  68. if (strcasecmp(facilities[i].strval, str) == 0) {
  69. *facilityp = facilities[i].val;
  70. return (ISC_R_SUCCESS);
  71. }
  72. }
  73. return (ISC_R_NOTFOUND);
  74. }