src/modules/pua/hash.h
2edef75a
 /*
  * pua module - presence user agent module
  *
  * Copyright (C) 2006 Voice Sistem S.R.L.
  *
27642a08
  * This file is part of Kamailio, a free SIP server.
2edef75a
  *
27642a08
  * Kamailio is free software; you can redistribute it and/or modify
2edef75a
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version
  *
27642a08
  * Kamailio is distributed in the hope that it will be useful,
2edef75a
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
07664979
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
9e1ff448
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
2edef75a
  */
 
 
 #ifndef _PU_HASH_H_
 #define _PU_HASH_H_
 
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
cf83221d
 #include "../../core/str.h"
 #include "../../core/lock_ops.h"
 #include "../../core/dprint.h"
 #include "../../core/parser/msg_parser.h"
5c5e9699
 #include "../rls/list.h"
2edef75a
 
4b79a143
 #define PRESENCE_EVENT      1<<0
 #define PWINFO_EVENT        1<<1
8fec0ddc
 #define BLA_EVENT           1<<2
4b79a143
 #define MSGSUM_EVENT        1<<3
7532d62c
 #define CONFERENCE_EVENT    1<<4
3d69afa8
 #define DIALOG_EVENT        1<<5
552425a4
 #define REGINFO_EVENT       1<<6
ea45a9b0
 #define XCAPDIFF_EVENT      1<<7
4b79a143
 
f58cc3fa
 #define UL_PUBLISH          1<<0
 #define BLA_PUBLISH         1<<1
8fec0ddc
 #define BLA_SUBSCRIBE       1<<2
 #define XMPP_PUBLISH        1<<3
 #define XMPP_SUBSCRIBE      1<<4
f58cc3fa
 #define XMPP_INITIAL_SUBS   1<<5
5c7bc8a3
 #define RPC_PUBLISH         1<<6
 #define RPC_ASYN_PUBLISH    1<<7
 #define RPC_SUBSCRIBE       1<<8
232401de
 #define RLS_SUBSCRIBE       1<<9
3d69afa8
 #define DIALOG_PUBLISH      1<<10
b1588082
 #define PURPLE_PUBLISH      1<<11
552425a4
 #define REGINFO_PUBLISH     1<<12
 #define REGINFO_SUBSCRIBE   1<<13
ea45a9b0
 #define XCAPDIFF_PUBLISH    1<<14
 #define XCAPDIFF_SUBSCRIBE  1<<15
772b6553
 
f58cc3fa
 #define NO_UPDATEDB_FLAG    1<<0
 #define UPDATEDB_FLAG       1<<1
 #define INSERTDB_FLAG       1<<2
ae86ca36
 #define WTHROUGHDB_FLAG     1<<3
2edef75a
 
c3ea4434
 #define MAX_FORWARD  70
 
2edef75a
 typedef struct ua_pres{
  
     /* common*/
 	str id;
fd77ffc1
     str* pres_uri;
772b6553
 	int event;
232401de
 	unsigned int expires;
 	unsigned int desired_expires;
2edef75a
 	int flag;
 	int db_flag;
232401de
 	void* cb_param;
2edef75a
 	struct ua_pres* next;
232401de
 	int ua_flag;
b0d089b6
 	str* outbound_proxy; /* croc-not sored in db_only mode */
5561e875
 	
2edef75a
 	/* publish */
 	str etag;
 	str tuple_id;
90e9d7fc
 	str* body;        /* croc-not stored in db_only mode */
 	str content_type; /* croc-not stored in db_only mode */
a053ac7d
 
2edef75a
 	/* subscribe */
 	str* watcher_uri;
 	str call_id;
 	str to_tag;
     str from_tag;
 	int cseq;
5561e875
 	int version;
90e9d7fc
 /*  int watcher_count; croc-nolonger used!! */
fd77ffc1
 	str* extra_headers;
ca42e1fb
 	str record_route;
0b9ea7e7
 	str remote_contact;
f6db9623
 	str contact;
232401de
 
 	/*?? should this be long? */
2edef75a
 }ua_pres_t;
 
 typedef struct hash_entry
 {
 	ua_pres_t* entity;
 	gen_lock_t lock;
 }hash_entry_t;	
 
 typedef struct htable{
     hash_entry_t* p_records;        	              
 }htable_t;
 
c70d27ce
 htable_t* new_htable(void);
2edef75a
 
8553bad3
 ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code);
2edef75a
 
b0d64201
 void insert_htable(ua_pres_t* presentity, unsigned int hash_code);
 
2edef75a
 
0e29c28e
 void update_htable(ua_pres_t* presentity,time_t desired_expires,
0b9ea7e7
 		int expires, str* etag, unsigned int hash_code, str* contact);
2edef75a
 
5561e875
 void delete_htable(ua_pres_t* presentity, unsigned int hash_code);
2edef75a
 
c70d27ce
 void destroy_htable(void);
5561e875
 int is_dialog(ua_pres_t* dialog);
fd77ffc1
 
5561e875
 ua_pres_t* get_dialog(ua_pres_t* dialog, unsigned int hash_code);
b93149c7
 ua_pres_t* get_temporary_dialog(ua_pres_t* dialog, unsigned int hash_code);
e627bc31
 int convert_temporary_dialog(ua_pres_t *dialog);
2edef75a
 
fd77ffc1
 int get_record_id(ua_pres_t* dialog, str** rec_id);
 typedef int (*get_record_id_t)(ua_pres_t* dialog, str** rec_id);
 
5c5e9699
 list_entry_t *get_subs_list(str *did);
 typedef list_entry_t * (*get_subs_list_t)(str *did);
 
feaff680
 /* for degug */
 void print_ua_pres(ua_pres_t* p);
 
5561e875
 typedef int  (*query_dialog_t)(ua_pres_t* presentity);
d2e93471
 
1ab6e3aa
 static inline int get_event_flag(str* event)
 {
7532d62c
     switch (event->len) 
     {
552425a4
         case 3:
             if (strncmp(event->s, "reg", 3) == 0)
                 return REGINFO_EVENT;
             break;
3d69afa8
         case 6:
             if (strncmp(event->s, "dialog", 6) == 0)
                 return DIALOG_EVENT;
             break;
7532d62c
         case 8:
             if (strncmp(event->s, "presence", 8) == 0)
                 return PRESENCE_EVENT;
             break;
         case 10:
             if (strncmp(event->s, "dialog;sla", 10) == 0)
                 return BLA_EVENT;
             if (strncmp(event->s, "conference", 10) == 0)
                 return CONFERENCE_EVENT;
             break;
         case 14:
48f89ed0
             if (strncmp(event->s, "presence.winfo", 14) == 0)
7532d62c
                 return PWINFO_EVENT;
             break;
         case 15:
             if (strncmp(event->s, "message-summary", 15) == 0)
                 return MSGSUM_EVENT;
1ab6e3aa
     }
7532d62c
 
85a70026
     LM_ERR("Unknown event string\n");
1ab6e3aa
     return -1;
7532d62c
 }
1ab6e3aa
 
5b0449b5
 int w_pua_update_contact(struct sip_msg* msg, char* str1, char* str2);
 int ki_pua_update_contact(struct sip_msg* msg);
1ab6e3aa
 
2edef75a
 #endif