chanvars.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2005, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.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. /*! \file
  19. *
  20. * \brief Channel Variables
  21. *
  22. * \author Mark Spencer <markster@digium.com>
  23. */
  24. /*** MODULEINFO
  25. <support_level>core</support_level>
  26. ***/
  27. #include "asterisk.h"
  28. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  29. #include "asterisk/chanvars.h"
  30. #include "asterisk/strings.h"
  31. #include "asterisk/utils.h"
  32. #ifdef MALLOC_DEBUG
  33. struct ast_var_t *_ast_var_assign(const char *name, const char *value, const char *file, int lineno, const char *function)
  34. #else
  35. struct ast_var_t *ast_var_assign(const char *name, const char *value)
  36. #endif
  37. {
  38. struct ast_var_t *var;
  39. int name_len = strlen(name) + 1;
  40. int value_len = strlen(value) + 1;
  41. #ifdef MALLOC_DEBUG
  42. if (!(var = __ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char), file, lineno, function))) {
  43. #else
  44. if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
  45. #endif
  46. return NULL;
  47. }
  48. ast_copy_string(var->name, name, name_len);
  49. var->value = var->name + name_len;
  50. ast_copy_string(var->value, value, value_len);
  51. return var;
  52. }
  53. void ast_var_delete(struct ast_var_t *var)
  54. {
  55. if (var)
  56. ast_free(var);
  57. }
  58. const char *ast_var_name(const struct ast_var_t *var)
  59. {
  60. const char *name;
  61. if (var == NULL || (name = var->name) == NULL)
  62. return NULL;
  63. /* Return the name without the initial underscores */
  64. if (name[0] == '_') {
  65. name++;
  66. if (name[0] == '_')
  67. name++;
  68. }
  69. return name;
  70. }
  71. const char *ast_var_full_name(const struct ast_var_t *var)
  72. {
  73. return (var ? var->name : NULL);
  74. }
  75. const char *ast_var_value(const struct ast_var_t *var)
  76. {
  77. return (var ? var->value : NULL);
  78. }