modules_s/usrloc/urecord.h

00001 /* 
00002  * $Id$ 
00003  *
00004  * Usrloc record 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  * History:
00030  * ---------
00031  * 2003-03-12 added replication mark support (nils)
00032  */
00033 
00034 
00035 #ifndef URECORD_H
00036 #define URECORD_H
00037 
00038 
00039 #include <stdio.h>
00040 #include <time.h>
00041 #include "hslot.h"
00042 #include "../../str.h"
00043 #include "../../qvalue.h"
00044 #include "ucontact.h"
00045 #include "notify.h"
00046 
00047 
00048 struct hslot;
00049 
00050 
00051 /*
00052  * Basic hash table element
00053  */
00054 typedef struct urecord {
00055         str* domain;                   /* Pointer to domain we belong to */
00056         str uid;                       /* User id */
00057         ucontact_t* contacts;          /* One or more contact fields */
00058         
00059         struct hslot* slot;            /* Collision slot in the hash table array we belong to */
00060         struct {
00061                 struct urecord* prev;  /* Next item in the linked list */
00062                 struct urecord* next;  /* Previous item in the linked list */
00063         } d_ll;
00064         struct {                         /* Linked list of all elements in hash table */
00065                 struct urecord* prev;  /* Previous item in the list */
00066                 struct urecord* next;  /* Next item in the list */
00067         } s_ll;
00068 
00069         struct notify_cb* watchers;         /* List of watchers */
00070 } urecord_t;
00071 
00072 
00073 /* Create a new record */
00074 int new_urecord(str* _dom, str* _uid, urecord_t** _r);
00075 
00076 
00077 /* Free all memory associated with the element */
00078 void free_urecord(urecord_t* _r);
00079 
00080 
00081 /*
00082  * Print an element, for debugging purposes only
00083  */
00084 void print_urecord(FILE* _f, urecord_t* _r);
00085 
00086 
00087 /*
00088  * Add a new contact
00089  */
00090 int mem_insert_ucontact(urecord_t* _r, str* aor, str* _c, time_t _e, qvalue_t _q, str* _cid, int _cs, 
00091                         unsigned int _flags, struct ucontact** _con, str *_ua, str* _recv,
00092                                                 struct socket_info* sock, str* _inst, int sid);
00093 
00094 
00095 
00096 /*
00097  * Remove the contact from lists
00098  */
00099 void mem_remove_ucontact(urecord_t* _r, ucontact_t* _c);
00100 
00101 
00102 /*
00103  * Remove contact from the list and delete 
00104  */
00105 void mem_delete_ucontact(urecord_t* _r, ucontact_t* _c);
00106 
00107 
00108 /*
00109  * Timer handler
00110  */
00111 int timer_urecord(urecord_t* _r);
00112 
00113 
00114 /* ===== Module interface ======== */
00115 
00116 
00117 /*
00118  * Release urecord previously obtained
00119  * through get_urecord
00120  */
00121 typedef void (*release_urecord_t)(urecord_t* _r);
00122 void release_urecord(urecord_t* _r);
00123 
00124 
00125 /*
00126  * Create and insert new contact
00127  * into urecord with additional replication argument
00128  */
00129 typedef int (*insert_ucontact_t)(urecord_t* _r, str* aor, str* _c, time_t _e, qvalue_t _q, str* _cid, int _cs, 
00130                                                                  unsigned int _flags, struct ucontact** _con, str *_ua, str* _recv,
00131                                                                  struct socket_info* sock, str* _inst, int sid);
00132 int insert_ucontact(urecord_t* _r, str* aor, str* _c, time_t _e, qvalue_t _q, str* _cid, int _cs, 
00133                         unsigned int _flags, struct ucontact** _con, str *_ua, str* _recv,
00134                                         struct socket_info* sock, str* _inst, int sid);
00135 
00136 /*
00137  * Delete ucontact from urecord
00138  */
00139 typedef int (*delete_ucontact_t)(urecord_t* _r, struct ucontact* _c);
00140 int delete_ucontact(urecord_t* _r, struct ucontact* _c);
00141 
00142 
00143 /*
00144  * Get pointer to ucontact with given contact
00145  */
00146 typedef int (*get_ucontact_t)(urecord_t* _r, str* _c, struct ucontact** _co);
00147 int get_ucontact(urecord_t* _r, str* _c, struct ucontact** _co);
00148 
00149 typedef int (*get_ucontact_by_inst_t)(urecord_t* _r, str* _c, str* _i, struct ucontact** _co);
00150 int get_ucontact_by_instance(urecord_t* _r, str* _c, str* _i, struct ucontact** _co);
00151 #endif /* URECORD_H */