urecord.h

Go to the documentation of this file.
00001 /*
00002  * $Id: urecord.h 5241 2008-11-21 12:52:25Z 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 /*! \file
00024  *  \brief USRLOC - Usrloc record structure
00025  *  \ingroup usrloc
00026  */
00027 
00028 
00029 #ifndef URECORD_H
00030 #define URECORD_H
00031 
00032 
00033 #include <stdio.h>
00034 #include <time.h>
00035 #include "hslot.h"
00036 #include "../../str.h"
00037 #include "../../qvalue.h"
00038 #include "ucontact.h"
00039 
00040 
00041 struct hslot; /*!< Hash table slot */
00042 
00043 /*! \brief
00044  * Basic hash table element
00045  */
00046 typedef struct urecord {
00047    str* domain;                   /*!< Pointer to domain we belong to 
00048                                     * ( null terminated string) */
00049    str aor;                       /*!< Address of record */
00050    unsigned int aorhash;          /*!< Hash over address of record */
00051    ucontact_t* contacts;          /*!< One or more contact fields */
00052 
00053    struct hslot* slot;            /*!< Collision slot in the hash table 
00054                                     * array we belong to */
00055    struct urecord* prev;          /*!< Next item in the hash entry */
00056    struct urecord* next;          /*!< Previous item in the hash entry */
00057 } urecord_t;
00058 
00059 
00060 /*!
00061  * \brief Create and initialize new record structure
00062  * \param _dom domain name
00063  * \param _aor address of record
00064  * \param _r pointer to the new record
00065  * \return 0 on success, negative on failure
00066  */
00067 int new_urecord(str* _dom, str* _aor, urecord_t** _r);
00068 
00069 
00070 /*!
00071  * \brief Free all memory used by the given structure
00072  *
00073  * Free all memory used by the given structure.
00074  * The structure must be removed from all linked
00075  * lists first
00076  * \param _r freed record list
00077  */
00078 void free_urecord(urecord_t* _r);
00079 
00080 
00081 /*!
00082  * \brief Print a record, useful for debugging
00083  * \param _f print output
00084  * \param _r printed record
00085  */
00086 void print_urecord(FILE* _f, urecord_t* _r);
00087 
00088 
00089 /*!
00090  * \brief Add a new contact in memory
00091  *
00092  * Add a new contact in memory, contacts are ordered by:
00093  * 1) q value, 2) descending modification time
00094  * \param _r record this contact belongs to
00095  * \param _c contact
00096  * \param _ci contact information
00097  * \return pointer to new created contact on success, 0 on failure
00098  */
00099 ucontact_t* mem_insert_ucontact(urecord_t* _r, str* _c, ucontact_info_t* _ci);
00100 
00101 
00102 /*!
00103  * \brief Remove the contact from lists in memory
00104  * \param _r record this contact belongs to
00105  * \param _c removed contact
00106  */
00107 void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c);
00108 
00109 
00110 /*!
00111  * \brief Remove contact in memory from the list and delete it
00112  * \param _r record this contact belongs to
00113  * \param _c deleted contact
00114  */
00115 void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c);
00116 
00117 
00118 /*!
00119  * \brief Run timer functions depending on the db_mode setting.
00120  *
00121  * Helper function that run the appropriate timer function, depending
00122  * on the db_mode setting.
00123  * \param _r processed record
00124  */
00125 void timer_urecord(urecord_t* _r);
00126 
00127 
00128 /*!
00129  * \brief Delete a record from the database
00130  * \param _r deleted record
00131  * \return 0 on success, -1 on failure
00132  */
00133 int db_delete_urecord(urecord_t* _r);
00134 
00135 
00136 /* ===== Module interface ======== */
00137 
00138 
00139 /*!
00140  * \brief Release urecord previously obtained through get_urecord
00141  * \warning Failing to calls this function after get_urecord will
00142  * result in a memory leak when the DB_ONLY mode is used. When
00143  * the records is later deleted, e.g. with delete_urecord, then
00144  * its not necessary, as this function already releases the record.
00145  * \param _r released record
00146  */
00147 typedef void (*release_urecord_t)(urecord_t* _r);
00148 void release_urecord(urecord_t* _r);
00149 
00150 
00151 /*!
00152  * \brief Create and insert new contact into urecord
00153  * \param _r record into the new contact should be inserted
00154  * \param _contact contact string
00155  * \param _ci contact information
00156  * \param _c new created contact
00157  * \return 0 on success, -1 on failure
00158  */
00159 typedef int (*insert_ucontact_t)(urecord_t* _r, str* _contact,
00160       ucontact_info_t* _ci, ucontact_t** _c);
00161 int insert_ucontact(urecord_t* _r, str* _contact,
00162       ucontact_info_t* _ci, ucontact_t** _c);
00163 
00164 
00165 /*!
00166  * \brief Delete ucontact from urecord
00167  * \param _r record where the contact belongs to
00168  * \param _c deleted contact
00169  * \return 0 on success, -1 on failure
00170  */
00171 typedef int (*delete_ucontact_t)(urecord_t* _r, struct ucontact* _c);
00172 int delete_ucontact(urecord_t* _r, struct ucontact* _c);
00173 
00174 
00175 /*!
00176  * \brief Get pointer to ucontact with given contact
00177  * \param _r record where to search the contacts
00178  * \param _c contact string
00179  * \param _callid callid
00180  * \param _cseq CSEQ number
00181  * \param _co found contact
00182  * \return 0 - found, 1 - not found, -1 - invalid found, 
00183  * -2 - found, but to be skipped (same cseq)
00184  */
00185 typedef int (*get_ucontact_t)(urecord_t* _r, str* _c, str* _callid, int _cseq,
00186       struct ucontact** _co);
00187 int get_ucontact(urecord_t* _r, str* _c, str* _callid, int _cseq,
00188       struct ucontact** _co);
00189 
00190 
00191 #endif

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