modules_s/usrloc/udomain.h

00001 /* 
00002  * $Id$ 
00003  *
00004  * Usrloc domain structure
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  *
00008  * This file is part of ser, a free SIP server.
00009  *
00010  * ser is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * For a license to use the ser software under conditions
00016  * other than those described here, or to purchase support for this
00017  * software, please contact iptel.org by e-mail at the following addresses:
00018  *    info@iptel.org
00019  *
00020  * ser is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License 
00026  * along with this program; if not, write to the Free Software 
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  */
00029 /*
00030  * History:
00031  * --------
00032  *  2003-03-11  changed to new locking scheme: locking.h (andrei)
00033  *  2006-11-23 switched to fixed hash size (andrei)
00034  */
00035 
00036 
00037 #ifndef UDOMAIN_H
00038 #define UDOMAIN_H
00039 
00040 
00041 #include <stdio.h>
00042 #include "../../locking.h"
00043 #include "../../str.h"
00044 #include "../../lib/srdb2/db.h"
00045 #include "urecord.h"
00046 #include "hslot.h"
00047 
00048 
00049 /* udomain hash size, for best performance always use a 2^k value
00050  * good values 8192: 9% increase over 4096, 16384: 5% inc. over 8192,
00051  *  32768 4-5% inc over 16384 */
00052 #define UDOMAIN_HASH_SIZE       16384
00053 
00054 struct hslot;   /* Hash table slot */
00055 struct urecord; /* Usrloc record */
00056 
00057 
00058 /*
00059  * The structure represents a usrloc domain
00060  */
00061 typedef struct udomain {
00062         str* name;                     /* Domain name */
00063         int users;                     /* Number of registered users */
00064         int expired;                   /* Number of expired contacts */
00065         int db_cmd_idx;                /* Index into db_cmd arrays */
00066         struct hslot* table;           /* Hash table - array of collision slots */
00067         struct {                       /* Linked list of all elements in the domain */
00068                 int n;                 /* Number of element in the linked list */
00069                 struct urecord* first; /* First element in the list */
00070                 struct urecord* last;  /* Last element in the list */
00071         } d_ll;
00072         gen_lock_t lock;                /* lock variable */
00073 } udomain_t;
00074 
00075 
00076 /*
00077  * Create a new domain structure
00078  * _n is pointer to str representing
00079  * name of the domain, the string is
00080  * not copied, it should point to str
00081  * structure stored in domain list
00082  */
00083 int new_udomain(str* _n, udomain_t** _d);
00084 
00085 
00086 /*
00087  * Free all memory allocated for
00088  * the domain
00089  */
00090 void free_udomain(udomain_t* _d);
00091 
00092 
00093 /*
00094  * Just for debugging
00095  */
00096 void print_udomain(FILE* _f, udomain_t* _d);
00097 
00098 
00099 /*
00100  * Load data from a database
00101  */
00102 int preload_udomain(udomain_t* _d);
00103 
00104 
00105 /*
00106  * Timer handler for given domain
00107  */
00108 int timer_udomain(udomain_t* _d);
00109 
00110 
00111 /*
00112  * Insert record into domain
00113  */
00114 int mem_insert_urecord(udomain_t* _d, str* _uid, struct urecord** _r);
00115 
00116 
00117 /*
00118  * Delete a record
00119  */
00120 void mem_delete_urecord(udomain_t* _d, struct urecord* _r);
00121 
00122 
00123 /*
00124  * Get lock
00125  */
00126 typedef void (*lock_udomain_t)(udomain_t* _d);
00127 void lock_udomain(udomain_t* _d);
00128 
00129 
00130 /*
00131  * Release lock
00132  */
00133 typedef void (*unlock_udomain_t)(udomain_t* _d);
00134 void unlock_udomain(udomain_t* _d);
00135 
00136 
00137 /* ===== module interface ======= */
00138 
00139 
00140 /*
00141  * Create and insert a new record
00142  */
00143 typedef int (*insert_urecord_t)(udomain_t* _d, str* _uid, struct urecord** _r);
00144 int insert_urecord(udomain_t* _d, str* _uid, struct urecord** _r);
00145 
00146 
00147 /*
00148  * Obtain a urecord pointer if the urecord exists in domain
00149  */
00150 typedef int  (*get_urecord_t)(udomain_t* _d, str* _uid, struct urecord** _r);
00151 int get_urecord(udomain_t* _d, str* _uid, struct urecord** _r);
00152 
00153 
00154 /*
00155  * Delete a urecord from domain
00156  */
00157 typedef int  (*delete_urecord_t)(udomain_t* _d, str* _uid);
00158 int delete_urecord(udomain_t* _d, str* _uid);
00159 
00160 
00161 #endif /* UDOMAIN_H */