ucontact.h

Go to the documentation of this file.
00001 /*
00002  * $Id: ucontact.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  * History:
00023  * ---------
00024  * 2003-03-12 added replication mark and three zombie states (nils)
00025  * 2005-07-11 added FL_NAT_SIPPING for nat pinging with SIP method
00026  *             instead of UDP package (bogdan)
00027  */
00028 
00029 /*! \file
00030  *  \brief USRLOC - Usrloc contact structure
00031  *  \ingroup usrloc
00032  */
00033 
00034 
00035 #ifndef UCONTACT_H
00036 #define UCONTACT_H
00037 
00038 
00039 #include <stdio.h>
00040 #include <time.h>
00041 #include "../../qvalue.h"
00042 #include "../../str.h"
00043 
00044 
00045 /*!
00046  * \brief States for in-memory contacts in regards to contact storage handler (db, in-memory, ldap etc)
00047  */
00048 typedef enum cstate {
00049    CS_NEW,        /*!< New contact - not flushed yet */
00050    CS_SYNC,       /*!< Synchronized contact with the database */
00051    CS_DIRTY       /*!< Update contact - not flushed yet */
00052 } cstate_t;
00053 
00054 
00055 /*! \brief Flags that can be associated with a Contact */
00056 typedef enum flags {
00057    FL_NONE        = 0,          /*!< No flags set */
00058    FL_MEM         = 1 << 0,     /*!< Update memory only */
00059    FL_ALL         = (int)0xFFFFFFFF  /*!< All flags set */
00060 } flags_t;
00061 
00062 
00063 /*! \brief Main structure for handling of registered Contact data */
00064 typedef struct ucontact {
00065    str* domain;            /*!< Pointer to domain name (NULL terminated) */
00066    str* aor;               /*!< Pointer to the AOR string in record structure*/
00067    str c;                  /*!< Contact address */
00068    str received;           /*!< IP+port+protocol we received the REGISTER from */
00069    str path;               /*!< Path header */
00070    time_t expires;         /*!< Expires parameter */
00071    qvalue_t q;             /*!< q parameter */
00072    str callid;             /*!< Call-ID header field of registration */
00073    int cseq;               /*!< CSeq value */
00074    cstate_t state;         /*!< State of the contact (\ref cstate) */
00075    unsigned int flags;     /*!< Various flags (NAT, ping type, etc) */
00076    unsigned int cflags;    /*!< Custom contact flags (from script) */
00077    str user_agent;         /*!< User-Agent header field */
00078    struct socket_info *sock; /*!< received socket */
00079    time_t last_modified;   /*!< When the record was last modified */
00080    unsigned int methods;   /*!< Supported methods */
00081    struct ucontact* next;  /*!< Next contact in the linked list */
00082    struct ucontact* prev;  /*!< Previous contact in the linked list */
00083 } ucontact_t;
00084 
00085 
00086 /*! \brief Informations related to a contact */
00087 typedef struct ucontact_info {
00088    str received;             /*!< Received interface */
00089    str* path;                /*!< Path informations */
00090    time_t expires;           /*!< Contact expires */
00091    qvalue_t q;               /*!< Q-value */
00092    str* callid;              /*!< call-ID */
00093    int cseq;                 /*!< CSEQ number */
00094    unsigned int flags;       /*!< message flags */
00095    unsigned int cflags;      /*!< contact flags */
00096    str *user_agent;          /*!< user agent header */
00097    struct socket_info *sock; /*!< socket informations */
00098    unsigned int methods;     /*!< supported methods */
00099    time_t last_modified;     /*!< last modified */
00100 } ucontact_info_t;
00101 
00102 /*! \brief ancient time used for marking the contacts forced to expired */
00103 #define UL_EXPIRED_TIME 10
00104 
00105 /*! \brief Valid contact is a contact that either didn't expire yet or is permanent */
00106 #define VALID_CONTACT(c, t)   ((c->expires>t) || (c->expires==0))
00107 
00108 
00109 /*!
00110  * \brief Create a new contact structure
00111  * \param _dom domain
00112  * \param _aor address of record
00113  * \param _contact contact string
00114  * \param _ci contact informations
00115  * \return new created contact on success, 0 on failure
00116  */
00117 ucontact_t* new_ucontact(str* _dom, str* _aor, str* _contact,
00118       ucontact_info_t* _ci);
00119 
00120 
00121 /*!
00122  * \brief Free all memory associated with given contact structure
00123  * \param _c freed contact
00124  */
00125 void free_ucontact(ucontact_t* _c);
00126 
00127 
00128 /*!
00129  * \brief Print contact, for debugging purposes only
00130  * \param _f output file
00131  * \param _c printed contact
00132  */
00133 void print_ucontact(FILE* _f, ucontact_t* _c);
00134 
00135 
00136 /*!
00137  * \brief Update existing contact in memory with new values
00138  * \param _c contact
00139  * \param _ci contact informations
00140  * \return 0
00141  */
00142 int mem_update_ucontact(ucontact_t* _c, ucontact_info_t *_ci);
00143 
00144 
00145 /* ===== State transition functions - for write back cache scheme ======== */
00146 
00147 /*!
00148  * \brief Update state of the contact if we are using write-back scheme
00149  * \param _c updated contact
00150  */
00151 void st_update_ucontact(ucontact_t* _c);
00152 
00153 
00154 /*!
00155  * \brief Update state of the contact
00156  * \param _c updated contact
00157  * \return 1 if the contact should be deleted from memory immediately, 0 otherwise
00158  */
00159 int st_delete_ucontact(ucontact_t* _c);
00160 
00161 
00162 /*!
00163  * \brief Called when the timer is about to delete an expired contact
00164  * \param _c expired contact
00165  * \return 1 if the contact should be removed from the database and 0 otherwise
00166  */
00167 int st_expired_ucontact(ucontact_t* _c);
00168 
00169 
00170 /*!
00171  * \brief Called when the timer is about flushing the contact, updates contact state
00172  * \param _c flushed contact
00173  * \return 1 if the contact should be inserted, 2 if update and 0 otherwise
00174  */
00175 int st_flush_ucontact(ucontact_t* _c);
00176 
00177 
00178 /* ==== Database related functions ====== */
00179 
00180 /*!
00181  * \brief Insert contact into the database
00182  * \param _c inserted contact
00183  * \return 0 on success, -1 on failure
00184  */
00185 int db_insert_ucontact(ucontact_t* _c);
00186 
00187 
00188 /*!
00189  * \brief Update contact in the database
00190  * \param _c updated contact
00191  * \return 0 on success, -1 on failure
00192  */
00193 int db_update_ucontact(ucontact_t* _c);
00194 
00195 
00196 /*!
00197  * \brief Delete contact from the database
00198  * \param _c deleted contact
00199  * \return 0 on success, -1 on failure
00200  */
00201 int db_delete_ucontact(ucontact_t* _c);
00202 
00203 
00204 /* ====== Module interface ====== */
00205 
00206 struct urecord;
00207 
00208 /*!
00209  * \brief Update ucontact with new values
00210  * \param _r record the contact belongs to
00211  * \param _c updated contact
00212  * \param _ci new contact informations
00213  * \return 0 on success, -1 on failure
00214  */
00215 typedef int (*update_ucontact_t)(struct urecord* _r, ucontact_t* _c,
00216       ucontact_info_t* _ci);
00217 int update_ucontact(struct urecord* _r, ucontact_t* _c, ucontact_info_t* _ci);
00218 
00219 #endif

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