chanvars.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. #include "asterisk.h"
  25. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  26. #include "asterisk/chanvars.h"
  27. #include "asterisk/strings.h"
  28. #include "asterisk/utils.h"
  29. struct ast_var_t *ast_var_assign(const char *name, const char *value)
  30. {
  31. struct ast_var_t *var;
  32. int name_len = strlen(name) + 1;
  33. int value_len = strlen(value) + 1;
  34. if (!(var = ast_calloc(sizeof(*var) + name_len + value_len, sizeof(char)))) {
  35. return NULL;
  36. }
  37. ast_copy_string(var->name, name, name_len);
  38. var->value = var->name + name_len;
  39. ast_copy_string(var->value, value, value_len);
  40. return var;
  41. }
  42. void ast_var_delete(struct ast_var_t *var)
  43. {
  44. if (var)
  45. ast_free(var);
  46. }
  47. const char *ast_var_name(const struct ast_var_t *var)
  48. {
  49. const char *name;
  50. if (var == NULL || (name = var->name) == NULL)
  51. return NULL;
  52. /* Return the name without the initial underscores */
  53. if (name[0] == '_') {
  54. name++;
  55. if (name[0] == '_')
  56. name++;
  57. }
  58. return name;
  59. }
  60. const char *ast_var_full_name(const struct ast_var_t *var)
  61. {
  62. return (var ? var->name : NULL);
  63. }
  64. const char *ast_var_value(const struct ast_var_t *var)
  65. {
  66. return (var ? var->value : NULL);
  67. }