CGI Bash Shell Interface
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

error.c 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * @PROJECT CGI Bash Shell Interface
  3. * @COPYRIGHT See COPYING in the top level directory
  4. * @FILE error.c
  5. * @PURPOSE Error handling
  6. * @DEVELOPERS Nathan Angelacos <nangel@users.sourceforge.net>
  7. * Rafal Kupiec <belliash@asiotec.eu.org>
  8. */
  9. #include <stdio.h>
  10. #include <unistd.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <ctype.h>
  14. #include <stdarg.h>
  15. #include "common.h"
  16. #include "buffer.h"
  17. #include "subshell.h"
  18. #include "cbsi.h"
  19. #include "error.h"
  20. char* g_err_msg[] = {
  21. "",
  22. "Memory Allocation Failure",
  23. "Unable to open file %s",
  24. "%c&gt; before &lt;%c",
  25. "Missing %c&gt;",
  26. "Unknown operation",
  27. "Unable to start subshell",
  28. "Unspecified Error",
  29. };
  30. void die_with_error(char* msg) {
  31. fprintf(stderr, "Error: %s\n", msg);
  32. exit(-1);
  33. }
  34. void die_with_message(void* sp, char* where, const char* s, ...) {
  35. script_t* script = sp;
  36. va_list p;
  37. FILE* fo = stderr;
  38. fo = stdout;
  39. fprintf(fo, "HTTP/1.0 500 Server Error\nContent-Type: text/html\n\n<html><body><b><font color=#CC0000>CBSI Error</font></b><br><pre>\n");
  40. va_start(p, s);
  41. vfprintf(fo, s, p);
  42. va_end(p);
  43. if(where && sp) {
  44. fprintf(fo, " near line %d of %s\n",
  45. count_lines(script->buf, script->size, where),
  46. script->name);
  47. }
  48. printf("\n");
  49. fprintf(fo, "</pre></body></html>\n");
  50. exit(-1);
  51. }