obsolete/pa/presentity.h

00001 /*
00002  * Presence Agent, presentity structure and related functions
00003  *
00004  * $Id$
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  * Copyright (C) 2004 Jamey Hicks
00008  *
00009  * This file is part of ser, a free SIP server.
00010  *
00011  * ser is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version
00015  *
00016  * For a license to use the ser software under conditions
00017  * other than those described here, or to purchase support for this
00018  * software, please contact iptel.org by e-mail at the following addresses:
00019  *    info@iptel.org
00020  *
00021  * ser is distributed in the hope that it will be useful,
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  * GNU General Public License for more details.
00025  *
00026  * You should have received a copy of the GNU General Public License 
00027  * along with this program; if not, write to the Free Software 
00028  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029  */
00030 
00031 #ifndef PRESENTITY_H
00032 #define PRESENTITY_H
00033 
00034 #include "../../str.h"
00035 #include "../../modules/tm/dlg.h"
00036 #include "watcher.h"
00037 #include "hslot.h"
00038 #include "trace.h"
00039 #include "pdomain.h"
00040 
00041 #include <xcap/pres_rules.h>
00042 #include <cds/msg_queue.h>
00043 #include <cds/list.h>
00044 #include <presence/notifier.h>
00045 #include <presence/subscriber.h>
00046 #include <presence/pres_doc.h>
00047 #include <cds/dbid.h>
00048 
00049 typedef struct presence_tuple {
00050         presence_tuple_info_t data;
00051         /* Contact is constant for non-published tuples and it is allocated
00052          * together with whole structure. For published tuples is contact 
00053          * allocated separately in shared memory and can change. */
00054         
00055         int is_published;       /* 1 for published tuples - these are stored into DB */
00056         str etag;       /* etag for published tuples -> constant for tuple life */
00057         time_t expires; /* tuple expires on ... */
00058         str published_id;       /* tuple id used for publish -> constant for tuple life */
00059 } presence_tuple_t;
00060 
00061 typedef struct {
00062         presence_note_t data;
00063         
00064         str etag; /* published via this etag -> constant for note life */
00065         time_t expires; /* note expires on ... */
00066         str dbid; /* id for database ops - needed for removing expired notes -> constant for note life */
00067 } pa_presence_note_t;
00068 
00069 typedef struct _pa_extension_element_t {
00070         extension_element_t data;
00071 
00072         str etag; /* published via this etag -> constant for structure life */
00073         time_t expires; /* expires on ... */
00074         str dbid; /* id for database ops - needed for removing expired  -> constant for structure life */
00075 } pa_extension_element_t;
00076 
00077 typedef struct {
00078         str user;
00079         str contact;
00080         basic_tuple_status_t state;
00081 } tuple_change_info_t;
00082 
00083 struct pdomain;
00084 
00085 typedef enum pflag {
00086         PFLAG_PRESENCE_CHANGED=1,
00087         PFLAG_WATCHERINFO_CHANGED=2
00088 } pflag_t;
00089 
00090 typedef struct _internal_pa_subscription_t {
00091         struct _internal_pa_subscription_t *prev, *next;
00092         watcher_status_t status;
00093         qsa_subscription_t *subscription;
00094         /* msg_queue_t *dst;
00095          * str_t package; 
00096          * str_t watcher_uri; */
00097 } internal_pa_subscription_t;
00098 
00099 
00100 typedef struct presentity {
00101         /* URI of presentity - doesn't change for the presentity's life */
00102         presentity_info_t data;
00103         str uuid; /* use after usrloc uuid-zation - callbacks are 
00104                                  registered to this,  - doesn't change for 
00105                                  the presentity's life  */
00106         
00107         str pres_id;   /* id of the record in the presentity table (generated!) */
00108         int id_cntr; /* variable for generating watcher/tuple/... ids */
00109         
00110         /* provisional data members */
00111         
00112         int ref_cnt;  /* reference counter - don't remove if > 1 */
00113         pflag_t flags;
00114         struct pdomain *pdomain; 
00115         struct presentity* next; /* Next presentity */
00116         struct presentity* prev; /* Previous presentity in list */
00117         struct hslot* slot;      /* Hash table collision slot we belong to */
00118         
00119         /* watchers/winfo watchers/internal watchers */
00120         
00121         watcher_t *first_watcher, *last_watcher;     /* List of watchers */
00122         watcher_t *first_winfo_watcher, *last_winfo_watcher;  /* Watchers subscribed to winfo */
00123         internal_pa_subscription_t *first_qsa_subscription, *last_qsa_subscription;
00124         
00125         /* authorization data */
00126         
00127         presence_rules_t *authorization_info;
00128         xcap_query_params_t xcap_params; /* doesn't change for the presentity's life (FIXME: rewrite) */
00129         time_t auth_rules_refresh_time;
00130         
00131         msg_queue_t mq; /* message queue supplying direct usrloc callback processing */ 
00132 
00133         /* data for internal subscriptions to presence 
00134          * (reduces memory allocation count) */
00135         qsa_subscription_data_t presence_subscription_data;
00136         qsa_subscription_t *presence_subscription;
00137 } presentity_t;
00138 
00139 
00140 /* shortcuts for PA structures walking (PA uses derived structures
00141  * instead of that defined in presence library because it needs
00142  * to store more information) */
00143 
00144 #define get_first_tuple(p)      ((presence_tuple_t*)(p->data.first_tuple))
00145 #define get_next_tuple(t)       ((presence_tuple_t*)(t->data.next))
00146 
00147 #define get_first_note(p)       ((pa_presence_note_t*)(p->data.first_note))
00148 #define get_next_note(n)        ((pa_presence_note_t*)(n->data.next))
00149 
00150 #define get_first_extension(p)  ((pa_extension_element_t*)(p->data.first_unknown_element))
00151 #define get_next_extension(pe)  ((pa_extension_element_t*)(pe->data.next))
00152 
00154 int new_presentity(struct pdomain *pdomain, str* _uri, str *uid, 
00155                 xcap_query_params_t *xcap_params, presentity_t** _p);
00156 
00160 void free_presentity(presentity_t* _p);
00161 
00162 /* Free all memory associated with a presentity and remove it from DB */
00163 void release_presentity(presentity_t* _p);
00164 
00169 int db_remove_presentity_data(presentity_t* presentity, const char *table);
00170 
00171 /* set authorization rules for presentity
00172  * ! call from locked region only ! */
00173 int set_auth_rules(presentity_t *p, presence_rules_t *new_auth_rules);
00174 
00175 /* Run a timer handler on the presentity - cleanup of expired data, sending
00176  * notifications when presentity modified, ... */
00177 int timer_presentity(presentity_t* _p);
00178 
00179 /********** UTILITY functions **********/
00180 
00181 /* Gets UID from message (using get_to_uid) 
00182  * (it never allocates memory !!!) */
00183 int get_presentity_uid(str *uid_dst, struct sip_msg *m);
00184 
00185 /* 
00186  * converts uri to uid (uid is allocated in shm)
00187  * used by internal subscriptions and fifo commands 
00188  * FIXME: remove (internal subscriptions will be through UID too)
00189  */
00190 int pres_uri2uid(str_t *uid_dst, const str_t *uri);
00191 
00192 /* FIXME: change to local function within pdomain.c as soon as
00193  * will be message queue data types solved */
00194 void free_tuple_change_info_content(tuple_change_info_t *i);
00195 
00196 /************ Parameters **********/
00197 
00198 /* how often refresh authorization rules (xcap change events are 
00199  * not implemented yet!) */
00200 extern int auth_rules_refresh_time;
00201 
00202 int pdomain_load_presentities(struct pdomain *pdomain);
00203 
00204 #endif /* PRESENTITY_H */