h_table.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2001-2003 Fhg Fokus
  5. *
  6. * This file is part of ser, a free SIP server.
  7. *
  8. * ser is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version
  12. *
  13. * For a license to use the ser software under conditions
  14. * other than those described here, or to purchase support for this
  15. * software, please contact iptel.org by e-mail at the following addresses:
  16. * [email protected]
  17. *
  18. * ser is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #ifndef _H_TABLE_H
  28. #define _H_TABLE_H
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <pthread.h>
  32. #include <arpa/inet.h>
  33. #include "../../parser/msg_parser.h"
  34. #include "../../types.h"
  35. #include "../../md5utils.h"
  36. #include "config.h"
  37. struct s_table;
  38. struct entry;
  39. struct cell;
  40. struct timer;
  41. struct retr_buf;
  42. #include "../../mem/shm_mem.h"
  43. #include "lock.h"
  44. #include "sip_msg.h"
  45. #include "t_reply.h"
  46. #include "t_hooks.h"
  47. #include "timer.h"
  48. #define LOCK_HASH(_h) lock_hash((_h))
  49. #define UNLOCK_HASH(_h) unlock_hash((_h))
  50. void lock_hash(int i);
  51. void unlock_hash(int i);
  52. #define NO_CANCEL ( (char*) 0 )
  53. #define EXTERNAL_CANCEL ( (char*) -1)
  54. #define TYPE_LOCAL_CANCEL -1
  55. #define TYPE_REQUEST 0
  56. /* to be able to assess whether a script writer forgot to
  57. release a transaction and leave it for ever in memory,
  58. we mark it with operations done over it; if none of these
  59. flags is set and script is being left, it is a sign of
  60. script error and we need to release on writer's
  61. behalf
  62. */
  63. enum kill_reason { REQ_FWDED=1, REQ_RPLD=2, REQ_RLSD=4, REQ_EXIST=8 };
  64. typedef struct retr_buf
  65. {
  66. int activ_type;
  67. /* set to status code if the buffer is a reply,
  68. 0 if request or -1 if local CANCEL */
  69. char *buffer;
  70. int buffer_len;
  71. union sockaddr_union to;
  72. struct socket_info* send_sock;
  73. /* a message can be linked just to retransmission and FR list */
  74. struct timer_link retr_timer;
  75. struct timer_link fr_timer;
  76. enum lists retr_list;
  77. /*the cell that containes this retrans_buff*/
  78. struct cell* my_T;
  79. unsigned int branch;
  80. }retr_buf_type;
  81. /* User Agent Server content */
  82. typedef struct ua_server
  83. {
  84. struct sip_msg *request;
  85. struct retr_buf response;
  86. unsigned int status;
  87. str to_tag;
  88. unsigned int isACKed;
  89. }ua_server_type;
  90. /* User Agent Client content */
  91. typedef struct ua_client
  92. {
  93. struct retr_buf request;
  94. /* we maintain a separate copy of cancel rather than
  95. reuse the strructure for original request; the
  96. original request is no longer needed but its delayed
  97. timer may fire and interfere with whoever tries to
  98. rewrite it
  99. */
  100. struct retr_buf local_cancel;
  101. /* pointer to retransmission buffer where uri is printed;
  102. good for generating ACK/CANCEL */
  103. str uri;
  104. /* if we store a reply (branch picking), this is where it is */
  105. struct sip_msg *reply;
  106. /* if we don't store, we at least want to know the status */
  107. int last_received;
  108. }ua_client_type;
  109. /* transaction context */
  110. typedef struct cell
  111. {
  112. /* linking data */
  113. struct cell* next_cell;
  114. struct cell* prev_cell;
  115. /* needed for generating local ACK/CANCEL for local
  116. transactions; all but cseq_n include the entire
  117. header field value, cseq_n only Cseq number; with
  118. local transactions, pointers point to outbound buffer,
  119. with proxied transactions to inbound request */
  120. str from, callid, cseq_n, to;
  121. /* a short-cut for remember whether this transaction needs
  122. INVITE-special handling (e.g., CANCEL, ACK, FR...)
  123. */
  124. short is_invite;
  125. /* method shortcut -- for local transactions, pointer to
  126. outbound buffer, for proxies transactions pointer to
  127. original message; needed for reply matching
  128. */
  129. str method;
  130. /* callback and parameter on completion of local transactions */
  131. transaction_cb *completion_cb;
  132. /* the parameter stores a pointer to shmem -- it will be released
  133. during freeing transaction too
  134. */
  135. void *cbp;
  136. /* how many processes are currently processing this transaction ;
  137. note that only processes working on a request/reply belonging
  138. to a transaction increase ref_count -- timers don't, since we
  139. rely on transaction state machine to clean-up all but wait timer
  140. when entering WAIT state and the wait timer is the only place
  141. from which a transaction can be deleted (if ref_count==0); good
  142. for protecting from conditions in which wait_timer hits and
  143. tries to delete a transaction whereas at the same time
  144. a delayed message belonging to the transaction is received
  145. */
  146. volatile unsigned int ref_count;
  147. /* tells in which hash table entry the cell lives */
  148. unsigned int hash_index;
  149. /* sequence number within hash collision slot */
  150. unsigned int label;
  151. /* bindings to wait and delete timer */
  152. struct timer_link wait_tl;
  153. struct timer_link dele_tl;
  154. /* number of forks */
  155. int nr_of_outgoings;
  156. /* nr of replied branch */
  157. int relaied_reply_branch;
  158. /* UA Server */
  159. struct ua_server uas;
  160. /* UA Clients */
  161. struct ua_client uac[ MAX_BRANCHES ];
  162. /* protection against concurrent reply processing */
  163. ser_lock_t reply_mutex;
  164. /* the route to take if no final positive reply arrived */
  165. unsigned int on_negative;
  166. /* set to one if you want to disallow silent transaction
  167. dropping when C timer hits
  168. */
  169. int noisy_ctimer;
  170. /* is it a local transaction ? */
  171. int local;
  172. #ifdef _XWAIT
  173. /* protection against reentering WAIT state */
  174. ser_lock_t wait_mutex;
  175. /* has the transaction been put on wait status ? */
  176. int on_wait;
  177. #endif
  178. /* MD5checksum (meaningful only if syn_branch=0 */
  179. char md5[MD5_LEN];
  180. #ifdef EXTRA_DEBUG
  181. /* scheduled for deletion ? */
  182. short damocles;
  183. #endif
  184. /* has the transaction been scheduled to die? */
  185. enum kill_reason kr;
  186. }cell_type;
  187. /* double-linked list of cells with hash synonyms */
  188. typedef struct entry
  189. {
  190. struct cell* first_cell;
  191. struct cell* last_cell;
  192. /* currently highest sequence number in a synonym list */
  193. unsigned int next_label;
  194. /* sync mutex */
  195. ser_lock_t mutex;
  196. unsigned int entries;
  197. }entry_type;
  198. /* transaction table */
  199. struct s_table
  200. {
  201. /* table of hash entries; each of them is a list of synonyms */
  202. struct entry entrys[ TABLE_ENTRIES ];
  203. #ifdef _OBSOLETED
  204. /* table of timer lists */
  205. struct timer timers[ NR_OF_TIMER_LISTS ];
  206. #endif
  207. };
  208. struct s_table* get_tm_table();
  209. struct s_table* init_hash_table();
  210. void free_hash_table( );
  211. void free_cell( struct cell* dead_cell );
  212. struct cell* build_cell( struct sip_msg* p_msg );
  213. void remove_from_hash_table_unsafe( struct cell * p_cell);
  214. void insert_into_hash_table( struct cell * p_cell);
  215. void insert_into_hash_table_unsafe( struct cell * p_cell );
  216. unsigned int transaction_count( void );
  217. #endif