obsolete/pa/presentity.h
fdeceea5
 /*
  * Presence Agent, presentity structure and related functions
  *
  * $Id$
  *
95072403
  * Copyright (C) 2001-2003 FhG Fokus
2e54789d
  * Copyright (C) 2004 Jamey Hicks
fdeceea5
  *
  * This file is part of ser, a free SIP server.
  *
  * ser is free software; you can redistribute it and/or modify
  * 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
  *
  * For a license to use the ser software under conditions
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
  * ser is distributed in the hope that it will be useful,
  * 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.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #ifndef PRESENTITY_H
 #define PRESENTITY_H
 
 #include "../../str.h"
7a7f1a7b
 #include "../../modules/tm/dlg.h"
fdeceea5
 #include "watcher.h"
 #include "hslot.h"
2a385f88
 #include "trace.h"
5d58dfb2
 #include "pdomain.h"
fdeceea5
 
55218f16
 #include <xcap/pres_rules.h>
541e1786
 #include <cds/msg_queue.h>
5d58dfb2
 #include <cds/list.h>
541e1786
 #include <presence/notifier.h>
1b1ffb43
 #include <presence/subscriber.h>
8bd640d0
 #include <presence/pres_doc.h>
5d58dfb2
 #include <cds/dbid.h>
9009f7db
 
6a50c251
 typedef struct presence_tuple {
5d58dfb2
 	presence_tuple_info_t data;
 	/* Contact is constant for non-published tuples and it is allocated
 	 * together with whole structure. For published tuples is contact 
 	 * allocated separately in shared memory and can change. */
 	
541e1786
 	int is_published;	/* 1 for published tuples - these are stored into DB */
5d58dfb2
 	str etag;	/* etag for published tuples -> constant for tuple life */
 	time_t expires; /* tuple expires on ... */
 	str published_id;	/* tuple id used for publish -> constant for tuple life */
6a50c251
 } presence_tuple_t;
 
5d58dfb2
 typedef struct {
 	presence_note_t data;
 	
 	str etag; /* published via this etag -> constant for note life */
8bd640d0
 	time_t expires; /* note expires on ... */
5d58dfb2
 	str dbid; /* id for database ops - needed for removing expired notes -> constant for note life */
8bd640d0
 } pa_presence_note_t;
 
018409d0
 typedef struct _pa_extension_element_t {
 	extension_element_t data;
5d58dfb2
 
 	str etag; /* published via this etag -> constant for structure life */
ae9e1746
 	time_t expires; /* expires on ... */
5d58dfb2
 	str dbid; /* id for database ops - needed for removing expired  -> constant for structure life */
018409d0
 } pa_extension_element_t;
ae9e1746
 
284e5638
 typedef struct {
 	str user;
 	str contact;
018409d0
 	basic_tuple_status_t state;
284e5638
 } tuple_change_info_t;
 
6a50c251
 struct pdomain;
 
04847d67
 typedef enum pflag {
 	PFLAG_PRESENCE_CHANGED=1,
f7372307
 	PFLAG_WATCHERINFO_CHANGED=2
04847d67
 } pflag_t;
 
8516e9d9
 typedef struct _internal_pa_subscription_t {
541e1786
 	struct _internal_pa_subscription_t *prev, *next;
 	watcher_status_t status;
33364921
 	qsa_subscription_t *subscription;
541e1786
 	/* msg_queue_t *dst;
 	 * str_t package; 
 	 * str_t watcher_uri; */
8516e9d9
 } internal_pa_subscription_t;
 
541e1786
 
fdeceea5
 typedef struct presentity {
5d58dfb2
 	/* URI of presentity - doesn't change for the presentity's life */
 	presentity_info_t data;
 	str uuid; /* use after usrloc uuid-zation - callbacks are 
 				 registered to this,  - doesn't change for 
 				 the presentity's life  */
 	
 	str pres_id;   /* id of the record in the presentity table (generated!) */
 	int id_cntr; /* variable for generating watcher/tuple/... ids */
 	
 	/* provisional data members */
 	
f7372307
 	int ref_cnt;  /* reference counter - don't remove if > 1 */
04847d67
 	pflag_t flags;
6a50c251
 	struct pdomain *pdomain; 
fdeceea5
 	struct presentity* next; /* Next presentity */
 	struct presentity* prev; /* Previous presentity in list */
 	struct hslot* slot;      /* Hash table collision slot we belong to */
541e1786
 	
5d58dfb2
 	/* watchers/winfo watchers/internal watchers */
 	
 	watcher_t *first_watcher, *last_watcher;     /* List of watchers */
 	watcher_t *first_winfo_watcher, *last_winfo_watcher;  /* Watchers subscribed to winfo */
541e1786
 	internal_pa_subscription_t *first_qsa_subscription, *last_qsa_subscription;
5d58dfb2
 	
 	/* authorization data */
 	
55218f16
 	presence_rules_t *authorization_info;
5d58dfb2
 	xcap_query_params_t xcap_params; /* doesn't change for the presentity's life (FIXME: rewrite) */
f7372307
 	time_t auth_rules_refresh_time;
 	
2e472c6b
 	msg_queue_t mq;	/* message queue supplying direct usrloc callback processing */	
f7372307
 
5d58dfb2
 	/* data for internal subscriptions to presence 
 	 * (reduces memory allocation count) */
1b1ffb43
 	qsa_subscription_data_t presence_subscription_data;
 	qsa_subscription_t *presence_subscription;
fdeceea5
 } presentity_t;
 
 
5d58dfb2
 /* shortcuts for PA structures walking (PA uses derived structures
  * instead of that defined in presence library because it needs
  * to store more information) */
6a50c251
 
5d58dfb2
 #define get_first_tuple(p)	((presence_tuple_t*)(p->data.first_tuple))
 #define get_next_tuple(t)	((presence_tuple_t*)(t->data.next))
541e1786
 
5d58dfb2
 #define get_first_note(p)	((pa_presence_note_t*)(p->data.first_note))
 #define get_next_note(n)	((pa_presence_note_t*)(n->data.next))
6a50c251
 
018409d0
 #define get_first_extension(p)	((pa_extension_element_t*)(p->data.first_unknown_element))
 #define get_next_extension(pe)	((pa_extension_element_t*)(pe->data.next))
6a50c251
 
5d58dfb2
 /** Create a new presentity. */
 int new_presentity(struct pdomain *pdomain, str* _uri, str *uid, 
 		xcap_query_params_t *xcap_params, presentity_t** _p);
6a50c251
 
5d58dfb2
 /** Free all memory associated with a presentity - use only in special
  * cases like freeing memory on module cleanup. Otherwise use
  * release_presentity instead. */
 void free_presentity(presentity_t* _p);
f9e83ff6
 
5d58dfb2
 /* Free all memory associated with a presentity and remove it from DB */
 void release_presentity(presentity_t* _p);
f9e83ff6
 
5d58dfb2
 /** Removes all data for presentity (tuples, watchers, tuple notes, ...)
  * from given database table. 
  * It is possible due to that pres_id is unique identifier
  * common for all tables */
 int db_remove_presentity_data(presentity_t* presentity, const char *table);
fd9fd0da
 
5d58dfb2
 /* set authorization rules for presentity
  * ! call from locked region only ! */
 int set_auth_rules(presentity_t *p, presence_rules_t *new_auth_rules);
f9e83ff6
 
5d58dfb2
 /* Run a timer handler on the presentity - cleanup of expired data, sending
  * notifications when presentity modified, ... */
 int timer_presentity(presentity_t* _p);
49447807
 
5d58dfb2
 /********** UTILITY functions **********/
19ef0e8f
 
5d58dfb2
 /* Gets UID from message (using get_to_uid) 
  * (it never allocates memory !!!) */
19ef0e8f
 int get_presentity_uid(str *uid_dst, struct sip_msg *m);
 
 /* 
  * converts uri to uid (uid is allocated in shm)
  * used by internal subscriptions and fifo commands 
5d58dfb2
  * FIXME: remove (internal subscriptions will be through UID too)
19ef0e8f
  */
 int pres_uri2uid(str_t *uid_dst, const str_t *uri);
6a032821
 
5d58dfb2
 /* FIXME: change to local function within pdomain.c as soon as
  * will be message queue data types solved */
 void free_tuple_change_info_content(tuple_change_info_t *i);
fdeceea5
 
5d58dfb2
 /************ Parameters **********/
f7372307
 
 /* how often refresh authorization rules (xcap change events are 
  * not implemented yet!) */
 extern int auth_rules_refresh_time;
 
5d58dfb2
 int pdomain_load_presentities(struct pdomain *pdomain);
 
f7372307
 #endif /* PRESENTITY_H */