res_pjsip_cli.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Fairview 5 Engineering, LLC.
  5. *
  6. * George Joseph <george.joseph@fairview5.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. #ifndef RES_PJSIP_CLI_H_
  19. #define RES_PJSIP_CLI_H_
  20. #include "asterisk/cli.h"
  21. #define CLI_HEADER_FILLER ".........................................................................................."
  22. #define CLI_DETAIL_FILLER " "
  23. #define CLI_MAX_WIDTH 90
  24. #define CLI_LAST_TABSTOP 62
  25. #define CLI_MAX_TITLE_NAME 8
  26. #define CLI_INDENT_TO_SPACES(x) ((x * 2) + 1 + CLI_MAX_TITLE_NAME)
  27. /*
  28. * \brief CLI Formatter Context passed to all formatters.
  29. */
  30. struct ast_sip_cli_context {
  31. /*! Buffer used to accumulate cli output. */
  32. struct ast_str *output_buffer;
  33. /*! Used to indicate which direction an auth is used for. "I" or "O" */
  34. char *auth_direction;
  35. /*! Allows formatters to know how far to indent their output. */
  36. int indent_level;
  37. /*! Tells a formatter to dump its object_set. */
  38. unsigned show_details : 1;
  39. /*! Tells a formatter to descend into child objects. */
  40. unsigned recurse : 1;
  41. /*! Tells a formatter to dump it's object_set only if it's the root object. */
  42. unsigned show_details_only_level_0 : 1;
  43. };
  44. /*
  45. * \brief CLI Formatter Registry Entry
  46. */
  47. struct ast_sip_cli_formatter_entry {
  48. /*! A globally unique name for this formatter. If this formatter entry
  49. * is for an existing sorcery object type, then this name must match
  50. * the sorcery object type. Otherwise it can be any string as long as
  51. * it's globally unique.
  52. */
  53. const char *name;
  54. /*! The callback used to print the object's column headers. */
  55. ao2_callback_fn *print_header;
  56. /*! The callback used to print the details of the object. */
  57. ao2_callback_fn *print_body;
  58. /*! The function used to retrieve a container of all objects of this type. */
  59. struct ao2_container *(* get_container)(const char *regex);
  60. /*! The function used to iterate over a container of objects. */
  61. int (* iterate)(void *container, ao2_callback_fn callback, void *args);
  62. /*! The function used to retrieve a specific object from it's container. */
  63. void *(* retrieve_by_id)(const char *id);
  64. /*! The function used to retrieve an id string from an object. */
  65. const char *(* get_id)(const void *obj);
  66. };
  67. /*!
  68. * \brief Registers a CLI formatter.
  69. *
  70. * \param name The name of the formatter, usually the sorcery object type.
  71. * \param formatter An ao2_callback_fn that outputs the formatted data.
  72. * \retval 0 Success, non-zero on failure
  73. */
  74. int ast_sip_register_cli_formatter(struct ast_sip_cli_formatter_entry *formatter);
  75. /*!
  76. * \brief Unregisters a CLI formatter.
  77. *
  78. * \param name The name of the formatter, usually the sorcery object type.
  79. * \retval 0 Success, non-zero on failure
  80. */
  81. int ast_sip_unregister_cli_formatter(struct ast_sip_cli_formatter_entry *formatter);
  82. /*!
  83. * \brief Looks up a CLI formatter by type.
  84. *
  85. * \param name The name of the formatter, usually the sorcery object type.
  86. * \retval Pointer to formatter entry structure
  87. */
  88. struct ast_sip_cli_formatter_entry *ast_sip_lookup_cli_formatter(const char *name);
  89. /*!
  90. * \brief Prints a sorcery object's ast_variable list
  91. *
  92. * \param obj The sorcery object
  93. * \param arg The ast_sip_cli_context.
  94. * \retval 0 Success, non-zero on failure
  95. */
  96. int ast_sip_cli_print_sorcery_objectset(void *obj, void *arg, int flags);
  97. char *ast_sip_cli_traverse_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
  98. #endif /* RES_PJSIP_CLI_H_ */