tor_api.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2017, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file tor_api.h
  8. * \brief Public C API for the Tor network service.
  9. *
  10. * This interface is intended for use by programs that need to link Tor as
  11. * a library, and launch it in a separate thread. If you have the ability
  12. * to run Tor as a separate executable, you should probably do that instead
  13. * of embedding it as a library.
  14. **/
  15. #ifndef TOR_API_H
  16. #define TOR_API_H
  17. typedef struct tor_main_configuration_t tor_main_configuration_t;
  18. /**
  19. * Create and return a new tor_main_configuration().
  20. */
  21. tor_main_configuration_t *tor_main_configuration_new(void);
  22. /**
  23. * Set the command-line arguments in <b>cfg</b>.
  24. *
  25. * The <b>argc</b> and <b>argv</b> values here are as for main(). The
  26. * contents of the argv pointer must remain unchanged until tor_run_main() has
  27. * finished and you call tor_main_configuration_free().
  28. *
  29. * Return 0 on success, -1 on failure.
  30. */
  31. int tor_main_configuration_set_command_line(tor_main_configuration_t *cfg,
  32. int argc, char *argv[]);
  33. /**
  34. * Release all storage held in <b>cfg</b>.
  35. *
  36. * Once you have passed a tor_main_configuration_t to tor_run_main(), you
  37. * must not free it until tor_run_main() has finished.
  38. */
  39. void tor_main_configuration_free(tor_main_configuration_t *cfg);
  40. /**
  41. * Run the tor process, as if from the command line.
  42. *
  43. * The command line arguments from tor_main_configuration_set_command_line()
  44. * are taken as if they had been passed to main().
  45. *
  46. * This function will not return until Tor is done running. It returns zero
  47. * on success, and nonzero on failure.
  48. *
  49. * BUG 23848: In many cases, tor_main will call exit() or abort() instead of
  50. * returning. This is not the intended long-term behavior; we are trying to
  51. * fix it.
  52. *
  53. * BUG 23847: You can only call tor_main() once in a single process; if it
  54. * returns and you call it again, you may crash. This is not intended
  55. * long-term behavior; we are trying to fix it.
  56. *
  57. * LIMITATION: You cannot run more than one instance of Tor in the same
  58. * process at the same time. Concurrent calls will cause undefined behavior.
  59. * We do not currently have plans to change this.
  60. */
  61. int tor_run_main(const tor_main_configuration_t *);
  62. /**
  63. * Run the tor process, as if from the command line.
  64. *
  65. * @deprecated Using this function from outside Tor is deprecated; you should
  66. * use use tor_run_main() instead.
  67. *
  68. * BUGS: This function has all the same bugs as tor_run_main().
  69. *
  70. * LIMITATIONS: This function has all the limitations of tor_run_main().
  71. */
  72. int tor_main(int argc, char **argv);
  73. #endif /* !defined(TOR_API_H) */