k/pua/hash.h

00001 /*
00002  * $Id$
00003  *
00004  * pua module - presence user agent module
00005  *
00006  * Copyright (C) 2006 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 
00025 
00026 #ifndef _PU_HASH_H_
00027 #define _PU_HASH_H_
00028 
00029 #include <stdlib.h>
00030 #include <string.h>
00031 #include <stdio.h>
00032 #include "../../str.h"
00033 #include "../../lock_ops.h"
00034 #include "../../dprint.h"
00035 #include "../../parser/msg_parser.h"
00036 #include "../rls/list.h"
00037 
00038 #define PRESENCE_EVENT      1<<0
00039 #define PWINFO_EVENT        1<<1
00040 #define BLA_EVENT           1<<2
00041 #define MSGSUM_EVENT        1<<3
00042 #define CONFERENCE_EVENT    1<<4
00043 #define DIALOG_EVENT        1<<5
00044 #define REGINFO_EVENT       1<<6
00045 
00046 #define UL_PUBLISH          1<<0
00047 #define BLA_PUBLISH         1<<1
00048 #define BLA_SUBSCRIBE       1<<2
00049 #define XMPP_PUBLISH        1<<3
00050 #define XMPP_SUBSCRIBE      1<<4
00051 #define XMPP_INITIAL_SUBS   1<<5
00052 #define MI_PUBLISH          1<<6
00053 #define MI_ASYN_PUBLISH     1<<7
00054 #define MI_SUBSCRIBE        1<<8
00055 #define RLS_SUBSCRIBE       1<<9
00056 #define DIALOG_PUBLISH      1<<10
00057 #define PURPLE_PUBLISH      1<<11
00058 #define REGINFO_PUBLISH     1<<12
00059 #define REGINFO_SUBSCRIBE   1<<13
00060 
00061 #define NO_UPDATEDB_FLAG    1<<0
00062 #define UPDATEDB_FLAG       1<<1
00063 #define INSERTDB_FLAG       1<<2
00064 #define WTHROUGHDB_FLAG     1<<3
00065 
00066 #define MAX_FORWARD  70
00067 
00068 typedef struct ua_pres{
00069  
00070     /* common*/
00071         str id;
00072     str* pres_uri;
00073         int event;
00074         unsigned int expires;
00075         unsigned int desired_expires;
00076         int flag;
00077         int db_flag;
00078         void* cb_param;
00079         struct ua_pres* next;
00080         int ua_flag;
00081         
00082         /* publish */
00083         str etag;
00084         str tuple_id;
00085         str* body;        /* croc-not stored in db_only mode */
00086         str content_type; /* croc-not stored in db_only mode */
00087 
00088         /* subscribe */
00089         str* watcher_uri;
00090         str call_id;
00091         str to_tag;
00092     str from_tag;
00093         int cseq;
00094         int version;
00095 /*  int watcher_count; croc-nolonger used!! */
00096         str* outbound_proxy; /* croc-not sored in db_only mode */
00097         str* extra_headers;
00098         str record_route;
00099         str remote_contact;
00100         str contact;
00101 
00102         /*?? should this be long? */
00103 }ua_pres_t;
00104 
00105 typedef struct hash_entry
00106 {
00107         ua_pres_t* entity;
00108         gen_lock_t lock;
00109 }hash_entry_t;  
00110 
00111 typedef struct htable{
00112     hash_entry_t* p_records;                          
00113 }htable_t;
00114 
00115 htable_t* new_htable(void);
00116 
00117 ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code);
00118 
00119 void insert_htable(ua_pres_t* presentity );
00120 
00121 void update_htable(ua_pres_t* presentity,time_t desired_expires,
00122                 int expires, str* etag, unsigned int hash_code, str* contact);
00123 
00124 void delete_htable(ua_pres_t* presentity, unsigned int hash_code);
00125 
00126 void destroy_htable(void);
00127 int is_dialog(ua_pres_t* dialog);
00128 
00129 ua_pres_t* get_dialog(ua_pres_t* dialog, unsigned int hash_code);
00130 ua_pres_t* get_temporary_dialog(ua_pres_t* dialog, unsigned int hash_code);
00131 int convert_temporary_dialog(ua_pres_t *dialog);
00132 
00133 int get_record_id(ua_pres_t* dialog, str** rec_id);
00134 typedef int (*get_record_id_t)(ua_pres_t* dialog, str** rec_id);
00135 
00136 list_entry_t *get_subs_list(str *did);
00137 typedef list_entry_t * (*get_subs_list_t)(str *did);
00138 
00139 /* for degug */
00140 void print_ua_pres(ua_pres_t* p);
00141 
00142 typedef int  (*query_dialog_t)(ua_pres_t* presentity);
00143 
00144 static inline int get_event_flag(str* event)
00145 {
00146     switch (event->len) 
00147     {
00148         case 3:
00149             if (strncmp(event->s, "reg", 3) == 0)
00150                 return REGINFO_EVENT;
00151             break;
00152         case 6:
00153             if (strncmp(event->s, "dialog", 6) == 0)
00154                 return DIALOG_EVENT;
00155             break;
00156         case 8:
00157             if (strncmp(event->s, "presence", 8) == 0)
00158                 return PRESENCE_EVENT;
00159             break;
00160         case 10:
00161             if (strncmp(event->s, "dialog;sla", 10) == 0)
00162                 return BLA_EVENT;
00163             if (strncmp(event->s, "conference", 10) == 0)
00164                 return CONFERENCE_EVENT;
00165             break;
00166         case 14:
00167             if (strncmp(event->s, "presence;winfo", 14) == 0)
00168                 return PWINFO_EVENT;
00169             break;
00170         case 15:
00171             if (strncmp(event->s, "message-summary", 15) == 0)
00172                 return MSGSUM_EVENT;
00173     }
00174 
00175     LM_ERR("Unknown event string\n");
00176     return -1;
00177 }
00178 
00179 int update_contact(struct sip_msg* msg, char* str1, char* str2);
00180 
00181 #endif