dbt_lib.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * $Id$
  3. *
  4. * DBText library
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. /**
  30. * DBText library
  31. *
  32. * 2003-01-30 created by Daniel
  33. *
  34. */
  35. #ifndef _DBT_LIB_H_
  36. #define _DBT_LIB_H_
  37. #include "../../str.h"
  38. #include "../../db/db_val.h"
  39. #include "../../locking.h"
  40. #define DBT_FLAG_UNSET 0
  41. #define DBT_FLAG_NULL 1
  42. #define DBT_FLAG_AUTO 2
  43. #define DBT_TBFL_ZERO 0
  44. #define DBT_TBFL_MODI 1
  45. #define DBT_FL_IGN -1
  46. #define DBT_FL_SET 0
  47. #define DBT_FL_UNSET 1
  48. #define DBT_DELIM ':'
  49. #define DBT_DELIM_C ' '
  50. #define DBT_DELIM_R '\n'
  51. /***
  52. typedef struct _dbt_val
  53. {
  54. int null;
  55. union
  56. {
  57. int int_val;
  58. double double_val;
  59. str str_val;
  60. } val;
  61. } dbt_val_t, *dbt_val_p;
  62. ***/
  63. typedef db_val_t dbt_val_t, *dbt_val_p;
  64. typedef struct _dbt_row
  65. {
  66. dbt_val_p fields;
  67. struct _dbt_row *prev;
  68. struct _dbt_row *next;
  69. } dbt_row_t, *dbt_row_p;
  70. typedef struct _dbt_column
  71. {
  72. str name;
  73. int type;
  74. int flag;
  75. struct _dbt_column *prev;
  76. struct _dbt_column *next;
  77. } dbt_column_t, *dbt_column_p;
  78. typedef struct _dbt_table
  79. {
  80. str name;
  81. int mark;
  82. int flag;
  83. int auto_col;
  84. int auto_val;
  85. int nrcols;
  86. dbt_column_p cols;
  87. dbt_column_p *colv;
  88. int nrrows;
  89. dbt_row_p rows;
  90. } dbt_table_t, *dbt_table_p;
  91. typedef struct _tbl_cache
  92. {
  93. gen_lock_t sem;
  94. dbt_table_p dtp;
  95. struct _tbl_cache *prev;
  96. struct _tbl_cache *next;
  97. } tbl_cache_t, *tbl_cache_p;
  98. typedef struct _dbt_database
  99. {
  100. str name;
  101. tbl_cache_p tables;
  102. } dbt_db_t, *dbt_db_p;
  103. typedef struct _dbt_cache
  104. {
  105. gen_lock_t sem;
  106. dbt_db_p dbp;
  107. struct _dbt_cache *prev;
  108. struct _dbt_cache *next;
  109. } dbt_cache_t, *dbt_cache_p;
  110. int dbt_init_cache();
  111. int dbt_cache_destroy();
  112. int dbt_cache_print(int);
  113. dbt_cache_p dbt_cache_get_db(str*);
  114. int dbt_cache_check_db(str*);
  115. int dbt_cache_del_db(str*);
  116. tbl_cache_p dbt_db_get_table(dbt_cache_p, str*);
  117. int dbt_db_del_table(dbt_cache_p, str*);
  118. int dbt_db_free(dbt_db_p);
  119. int dbt_cache_free(dbt_cache_p);
  120. dbt_column_p dbt_column_new(char*, int);
  121. dbt_row_p dbt_row_new(int);
  122. dbt_table_p dbt_table_new(char*, int);
  123. tbl_cache_p tbl_cache_new();
  124. int dbt_row_free(dbt_table_p, dbt_row_p);
  125. int dbt_column_free(dbt_column_p);
  126. int dbt_table_free_rows(dbt_table_p);
  127. int dbt_table_free(dbt_table_p);
  128. int tbl_cache_free(tbl_cache_p);
  129. int dbt_row_set_val(dbt_row_p, dbt_val_p, int, int);
  130. int dbt_row_update_val(dbt_row_p, dbt_val_p, int, int);
  131. int dbt_table_add_row(dbt_table_p, dbt_row_p);
  132. int dbt_table_check_row(dbt_table_p, dbt_row_p);
  133. int dbt_table_update_flags(dbt_table_p, int, int, int);
  134. dbt_table_p dbt_load_file(str *, str *);
  135. int dbt_print_table(dbt_table_p, str *);
  136. #endif