chanvars.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. */
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include "asterisk.h"
  26. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  27. #include "asterisk/chanvars.h"
  28. #include "asterisk/logger.h"
  29. #include "asterisk/strings.h"
  30. struct ast_var_t *ast_var_assign(const char *name, const char *value)
  31. {
  32. int i;
  33. struct ast_var_t *var;
  34. var = calloc(sizeof(struct ast_var_t) + strlen(name) + 1 + strlen(value) + 1, sizeof(char));
  35. if (var == NULL) {
  36. ast_log(LOG_WARNING, "Out of memory\n");
  37. return NULL;
  38. }
  39. i = strlen(name) + 1;
  40. ast_copy_string(var->name, name, i);
  41. var->value = var->name + i;
  42. ast_copy_string(var->value, value, strlen(value) + 1);
  43. return var;
  44. }
  45. void ast_var_delete(struct ast_var_t *var)
  46. {
  47. if (var)
  48. free(var);
  49. }
  50. char *ast_var_name(struct ast_var_t *var)
  51. {
  52. char *name;
  53. if (var == NULL)
  54. return NULL;
  55. if (var->name == NULL)
  56. return NULL;
  57. /* Return the name without the initial underscores */
  58. if (var->name[0] == '_') {
  59. if (var->name[1] == '_')
  60. name = (char*)&(var->name[2]);
  61. else
  62. name = (char*)&(var->name[1]);
  63. } else
  64. name = var->name;
  65. return name;
  66. }
  67. char *ast_var_full_name(struct ast_var_t *var)
  68. {
  69. return (var ? var->name : NULL);
  70. }
  71. char *ast_var_value(struct ast_var_t *var)
  72. {
  73. return (var ? var->value : NULL);
  74. }