udomain.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * $Id$
  3. *
  4. * Usrloc domain structure
  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. * History:
  31. * --------
  32. * 2003-03-11 changed to new locking scheme: locking.h (andrei)
  33. * 2006-11-23 switched to fixed hash size (andrei)
  34. */
  35. #ifndef UDOMAIN_H
  36. #define UDOMAIN_H
  37. #include <stdio.h>
  38. #include "../../locking.h"
  39. #include "../../str.h"
  40. #include "../../lib/srdb2/db.h"
  41. #include "urecord.h"
  42. #include "hslot.h"
  43. /* udomain hash size, for best performance always use a 2^k value
  44. * good values 8192: 9% increase over 4096, 16384: 5% inc. over 8192,
  45. * 32768 4-5% inc over 16384 */
  46. #define UDOMAIN_HASH_SIZE 16384
  47. struct hslot; /* Hash table slot */
  48. struct urecord; /* Usrloc record */
  49. /*
  50. * The structure represents a usrloc domain
  51. */
  52. typedef struct udomain {
  53. str* name; /* Domain name */
  54. int users; /* Number of registered users */
  55. int expired; /* Number of expired contacts */
  56. int db_cmd_idx; /* Index into db_cmd arrays */
  57. struct hslot* table; /* Hash table - array of collision slots */
  58. struct { /* Linked list of all elements in the domain */
  59. int n; /* Number of element in the linked list */
  60. struct urecord* first; /* First element in the list */
  61. struct urecord* last; /* Last element in the list */
  62. } d_ll;
  63. gen_lock_t lock; /* lock variable */
  64. } udomain_t;
  65. /*
  66. * Create a new domain structure
  67. * _n is pointer to str representing
  68. * name of the domain, the string is
  69. * not copied, it should point to str
  70. * structure stored in domain list
  71. */
  72. int new_udomain(str* _n, udomain_t** _d);
  73. /*
  74. * Free all memory allocated for
  75. * the domain
  76. */
  77. void free_udomain(udomain_t* _d);
  78. /*
  79. * Just for debugging
  80. */
  81. void print_udomain(FILE* _f, udomain_t* _d);
  82. /*
  83. * Load data from a database
  84. */
  85. int preload_udomain(udomain_t* _d);
  86. /*
  87. * Timer handler for given domain
  88. */
  89. int timer_udomain(udomain_t* _d);
  90. /*
  91. * Insert record into domain
  92. */
  93. int mem_insert_urecord(udomain_t* _d, str* _uid, struct urecord** _r);
  94. /*
  95. * Delete a record
  96. */
  97. void mem_delete_urecord(udomain_t* _d, struct urecord* _r);
  98. /*
  99. * Get lock
  100. */
  101. typedef void (*lock_udomain_t)(udomain_t* _d);
  102. void lock_udomain(udomain_t* _d);
  103. /*
  104. * Release lock
  105. */
  106. typedef void (*unlock_udomain_t)(udomain_t* _d);
  107. void unlock_udomain(udomain_t* _d);
  108. /* ===== module interface ======= */
  109. /*
  110. * Create and insert a new record
  111. */
  112. typedef int (*insert_urecord_t)(udomain_t* _d, str* _uid, struct urecord** _r);
  113. int insert_urecord(udomain_t* _d, str* _uid, struct urecord** _r);
  114. /*
  115. * Obtain a urecord pointer if the urecord exists in domain
  116. */
  117. typedef int (*get_urecord_t)(udomain_t* _d, str* _uid, struct urecord** _r);
  118. int get_urecord(udomain_t* _d, str* _uid, struct urecord** _r);
  119. /*
  120. * Delete a urecord from domain
  121. */
  122. typedef int (*delete_urecord_t)(udomain_t* _d, str* _uid);
  123. int delete_urecord(udomain_t* _d, str* _uid);
  124. #endif /* UDOMAIN_H */