k/presence/hash.h

Go to the documentation of this file.
00001 /*
00002  * $Id: hash.h 2583 2007-08-08 11:33:25Z anca_vamanu $
00003  *
00004  * presence module - presence server implementation
00005  *
00006  * Copyright (C) 2007 Voice Sistem S.R.L.
00007  *
00008  * This file is part of Kamailio, a free SIP server.
00009  *
00010  * Kamailio 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  * Kamailio is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU General Public License 
00021  * along with this program; if not, write to the Free Software 
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00023  *
00024  * History:
00025  * --------
00026  *  2007-08-20  initial version (Anca Vamanu)
00027  */
00028 
00036 #ifndef PS_HASH_H
00037 #define PS_HASH_H
00038 
00039 #include "../../lock_ops.h"
00040 //#include "presentity.h"
00041 
00042 struct presentity;
00043 #define REMOTE_TYPE   1<<1
00044 #define LOCAL_TYPE    1<<2
00045 
00046 #define PKG_MEM_STR       "pkg"
00047 #define SHARE_MEM         "share"
00048 
00049 #define ERR_MEM(mem_type)  LM_ERR("No more %s memory\n",mem_type);\
00050                                                 goto error
00051 
00052 #define CONT_COPY(buf, dest, source)\
00053         do{ \
00054         dest.s= (char*)buf+ size;\
00055         memcpy(dest.s, source.s, source.len);\
00056         dest.len= source.len;\
00057         size+= source.len; \
00058         } while(0);
00059 
00060 #define PKG_MEM_TYPE     1<< 1
00061 #define SHM_MEM_TYPE     1<< 2
00062 
00063 /* subscribe hash entry */
00064 struct subscription;
00065 
00066 typedef struct subs_entry
00067 {
00068         struct subscription* entries;
00069         gen_lock_t lock;
00070 }subs_entry_t;  
00071 
00072 typedef subs_entry_t* shtable_t;
00073 
00074 shtable_t new_shtable(int hash_size);
00075 
00076 struct subscription* search_shtable(shtable_t htable, str callid,str to_tag,str from_tag,
00077                 unsigned int hash_code);
00078 
00079 int insert_shtable(shtable_t htable, unsigned int hash_code, struct subscription* subs);
00080 
00081 int delete_shtable(shtable_t htable, unsigned int hash_code, str to_tag);
00082 
00083 int update_shtable(shtable_t htable, unsigned int hash_code, struct subscription* subs,
00084                 int type);
00085 
00086 struct subscription* mem_copy_subs(struct subscription* s, int mem_type);
00087 
00088 void free_subs_list(struct subscription* s_array, int mem_type, int ic);
00089 
00090 void destroy_shtable(shtable_t htable, int hash_size);
00091 
00092 /* subs htable functions type definitions */
00093 typedef shtable_t (*new_shtable_t)(int hash_size);
00094 
00095 typedef struct subscription* (*search_shtable_t)(shtable_t htable, str callid,str to_tag,
00096                 str from_tag, unsigned int hash_code);
00097 
00098 typedef int (*insert_shtable_t)(shtable_t htable, unsigned int hash_code,
00099                 struct subscription* subs);
00100 
00101 typedef int (*delete_shtable_t)(shtable_t htable, unsigned int hash_code,
00102                 str to_tag);
00103 
00104 typedef int (*update_shtable_t)(shtable_t htable, unsigned int hash_code,
00105                 struct subscription* subs, int type);
00106 
00107 typedef void (*destroy_shtable_t)(shtable_t htable, int hash_size);
00108 
00109 typedef struct subscription* (*mem_copy_subs_t)(struct subscription* s, int mem_type);
00110 
00111 
00112 /* presentity hash table */
00113 typedef struct pres_entry
00114 {
00115         str pres_uri;
00116         int event;
00117         int publ_count;
00118         char* sphere;
00119         struct pres_entry* next;
00120 }pres_entry_t;
00121 
00122 typedef struct pres_htable
00123 {
00124         pres_entry_t* entries;
00125         gen_lock_t lock;
00126 }phtable_t;
00127 
00128 phtable_t* new_phtable(void);
00129 
00130 pres_entry_t* search_phtable(str* pres_uri, int event, unsigned int hash_code);
00131 
00132 int insert_phtable(str* pres_uri, int event, char* sphere);
00133 
00134 int update_phtable(struct presentity* presentity, str pres_uri, str body);
00135 
00136 int delete_phtable(str* pres_uri, int event);
00137 
00138 void destroy_phtable(void);
00139 
00140 #endif
00141