udomain.h

Go to the documentation of this file.
00001 /*
00002  * $Id: udomain.h 5272 2008-11-27 12:32:26Z henningw $ 
00003 
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of Kamailio, a free SIP server.
00007  *
00008  * Kamailio is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * Kamailio is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License 
00019  * along with this program; if not, write to the Free Software 
00020  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021  */
00022 /*
00023  * History:
00024  * --------
00025  *  2003-03-11  changed to new locking scheme: locking.h (andrei)
00026  */
00027 
00028 
00029 /*! \file
00030  *  \brief USRLOC - Usrloc domain structure
00031  *  \ingroup usrloc
00032  */
00033 
00034 #ifndef UDOMAIN_H
00035 #define UDOMAIN_H
00036 
00037 
00038 #include <stdio.h>
00039 #include "../../statistics.h"
00040 #include "../../locking.h"
00041 #include "../../str.h"
00042 #include "../../db/db.h"
00043 #include "urecord.h"
00044 #include "hslot.h"
00045 
00046 
00047 struct hslot;   /*!< Hash table slot */
00048 struct urecord; /*!< Usrloc record */
00049 
00050 
00051 /*! \brief
00052  * The structure represents a usrloc domain
00053  */
00054 typedef struct udomain {
00055    str* name;                 /*!< Domain name (NULL terminated) */
00056    int size;                  /*!< Hash table size */
00057    struct hslot* table;       /*!< Hash table - array of collision slots */
00058    /* statistics */
00059    stat_var *users;           /*!< no of registered users */
00060    stat_var *contacts;        /*!< no of registered contacts */
00061    stat_var *expires;         /*!< no of expires */
00062 } udomain_t;
00063 
00064 
00065 /*!
00066  * \brief Create a new domain structure
00067  * \param  _n is pointer to str representing name of the domain, the string is
00068  * not copied, it should point to str structure stored in domain list
00069  * \param _s is hash table size
00070  * \param _d new created domain
00071  * \return 0 on success, -1 on failure
00072  */
00073 int new_udomain(str* _n, int _s, udomain_t** _d);
00074 
00075 
00076 /*!
00077  * \brief Free all memory allocated for the domain
00078  * \param _d freed domain
00079  */
00080 void free_udomain(udomain_t* _d);
00081 
00082 
00083 /*!
00084  * \brief Print udomain, debugging helper function
00085  */
00086 void print_udomain(FILE* _f, udomain_t* _d);
00087 
00088 
00089 /*!
00090  * \brief Load all records from a udomain
00091  *
00092  * Load all records from a udomain, useful to populate the
00093  * memory cache on startup.
00094  * \param _c database connection
00095  * \param _d loaded domain
00096  * \return 0 on success, -1 on failure
00097  */
00098 int preload_udomain(db_con_t* _c, udomain_t* _d);
00099 
00100 
00101 /*!
00102  * \brief performs a dummy query just to see if DB is ok
00103  * \param con database connection
00104  * \param d domain
00105  */
00106 int testdb_udomain(db_con_t* con, udomain_t* d);
00107 
00108 
00109 /*!
00110  * \brief Timer function to cleanup expired contacts, DB_ONLY db_mode
00111  * \param _d cleaned domain
00112  * \return 0 on success, -1 on failure
00113  */
00114 int db_timer_udomain(udomain_t* _d);
00115 
00116 
00117 /*!
00118  * \brief Run timer handler for given domain
00119  * \param _d domain
00120  */
00121 void mem_timer_udomain(udomain_t* _d);
00122 
00123 
00124 /*!
00125  * \brief Insert a new record into domain in memory
00126  * \param _d domain the record belongs to
00127  * \param _aor address of record
00128  * \param _r new created record
00129  * \return 0 on success, -1 on failure
00130  */
00131 int mem_insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
00132 
00133 
00134 /*!
00135  * \brief Remove a record from domain in memory
00136  * \param _d domain the record belongs to
00137  * \param _r deleted record
00138  */
00139 void mem_delete_urecord(udomain_t* _d, struct urecord* _r);
00140 
00141 
00142 /*! \brief
00143  * Timer handler for given domain
00144  */
00145 typedef void (*lock_udomain_t)(udomain_t* _d, str *_aor);
00146 void lock_udomain(udomain_t* _d, str *_aor);
00147 
00148 
00149 /*!
00150  * \brief Release lock for a domain
00151  * \param _d domain
00152  * \param _aor address of record, uses as hash source for the lock slot
00153  */
00154 typedef void (*unlock_udomain_t)(udomain_t* _d, str *_aor);
00155 void unlock_udomain(udomain_t* _d, str *_aor);
00156 
00157 
00158 /*!
00159  * \brief  Get lock for a slot
00160  * \param _d domain
00161  * \param i slot number
00162  */
00163 void lock_ulslot(udomain_t* _d, int i);
00164 
00165 /*!
00166  * \brief Release lock for a slot
00167  * \param _d domain
00168  * \param i slot number
00169  */
00170 void unlock_ulslot(udomain_t* _d, int i);
00171 
00172 /* ===== module interface ======= */
00173 
00174 
00175 /*!
00176  * \brief Create and insert a new record
00177  * \param _d domain to insert the new record
00178  * \param _aor address of the record
00179  * \param _r new created record
00180  * \return return 0 on success, -1 on failure
00181  */
00182 typedef int (*insert_urecord_t)(udomain_t* _d, str* _aor, struct urecord** _r);
00183 int insert_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
00184 
00185 
00186 /*!
00187  * \brief Obtain a urecord pointer if the urecord exists in domain
00188  * \param _d domain to search the record
00189  * \param _aor address of record
00190  * \param _r new created record
00191  * \return 0 if a record was found, 1 if nothing could be found
00192  */
00193 typedef int  (*get_urecord_t)(udomain_t* _d, str* _aor, struct urecord** _r);
00194 int get_urecord(udomain_t* _d, str* _aor, struct urecord** _r);
00195 
00196 
00197 /*!
00198  * \brief Delete a urecord from domain
00199  * \param _d domain where the record should be deleted
00200  * \param _aor address of record
00201  * \param _r deleted record
00202  * \return 0 on success, -1 if the record could not be deleted
00203  */
00204 typedef int  (*delete_urecord_t)(udomain_t* _d, str* _aor, struct urecord* _r);
00205 int delete_urecord(udomain_t* _d, str* _aor, struct urecord* _r);
00206 
00207 
00208 #endif

Generated on Thu May 24 22:00:35 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6