error.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* ssh-error.c -- Error reporting to Guile.
  2. *
  3. * Copyright (C) 2013, 2014, 2015, 2016, 2017 Artyom V. Poptsov <poptsov.artyom@gmail.com>
  4. *
  5. * This file is part of Guile-SSH.
  6. *
  7. * Guile-SSH is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Guile-SSH is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Guile-SSH. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <libguile.h>
  22. #include <libssh/libssh.h>
  23. #include "error.h"
  24. /* Report an error */
  25. void
  26. guile_ssh_error (const char *proc, const char *msg, SCM args, SCM rest)
  27. {
  28. scm_error (scm_from_locale_symbol (GUILE_SSH_ERROR), proc, msg, args, rest);
  29. }
  30. /* Report an error (shorter version). */
  31. void
  32. guile_ssh_error1 (const char *proc, const char *msg, SCM args)
  33. {
  34. char *c_str;
  35. scm_dynwind_begin (0);
  36. c_str = scm_to_locale_string (scm_object_to_string (args, SCM_UNDEFINED));
  37. scm_dynwind_free (c_str);
  38. _ssh_log (SSH_LOG_RARE, proc, "%s: %s", msg, c_str);
  39. scm_error (scm_from_locale_symbol (GUILE_SSH_ERROR), proc, msg, args,
  40. SCM_BOOL_F);
  41. scm_dynwind_end ();
  42. }
  43. /* Report a session error. */
  44. void
  45. guile_ssh_session_error1 (const char *proc, ssh_session session, SCM args)
  46. {
  47. guile_ssh_error1 (proc, ssh_get_error (session), args);
  48. }
  49. /* ssh-error.c ends here */