presence/event_list.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2006 Voice Sistem S.R.L.
00003  *
00004  * This file is part of Kamailio, a free SIP server.
00005  *
00006  * Kamailio is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version
00010  *
00011  * Kamailio is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License 
00017  * along with this program; if not, write to the Free Software 
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  *
00020  * History:
00021  * --------
00022  *  2007-04-05  initial version (Anca Vamanu)
00023  */
00024 
00032 #ifndef _PRES_EV_LST_H
00033 #define  _PRES_EV_LST_H
00034 
00035 #include "../../parser/msg_parser.h"
00036 #include "../../parser/parse_event.h"
00037 #include "../../parser/parse_param.h"
00038 #include "../../str.h"
00039 #include "subscribe.h"
00040 
00041 #define WINFO_TYPE                      1<< 0
00042 #define PUBL_TYPE                   1<< 1
00043 
00044 struct subscription;
00045 
00046 typedef int (apply_auth_t)(str* , struct subscription*, str** );
00047 
00048 typedef int (publ_handling_t)(struct sip_msg*);
00049 
00050 typedef int (subs_handling_t)(struct sip_msg*);
00051 
00052 typedef str* (agg_nbody_t)(str* pres_user, str* pres_domain, str** body_array, int n, int off_index);
00053 /* params for agg_body_t 
00054  *      body_array= an array with all the bodies stored for that resource
00055  *      n= the number of bodies
00056  *      off_index= the index of the registration(etag) for which a Publish
00057  *                              with Expires: 0 has just been received
00058  *      */
00059 typedef str* (aux_body_processing_t)(struct subscription *subs, str* body);
00060 /* params for agg_body_t 
00061  *      subs= a subscription structure to manipulate the body for a certain watcher
00062  *      body= the original body
00063  *
00064  * return value: 0: means that there was no manipulation or the manipulation was
00065  *                  done directly in the original body
00066  *           pointer: a pointer to str for the "per watcher" body. gets freed by aux_free_body()
00067  *      */
00068 typedef int (is_allowed_t)(struct subscription* subs);
00069 typedef int (get_rules_doc_t)(str* user, str* domain, str** rules_doc);
00070 /* return code rules for is_allowed_t
00071  *      < 0  if error occured
00072  *      =0       if no change in status(if no xcap document exists)
00073  *      >0   if change in status
00074  *      */
00075 
00076 /* event specific body free function */
00077 typedef void(free_body_t)(char* body);
00078 
00079 struct pres_ev
00080 {
00081         str name;
00082         event_t* evp;
00083         str content_type;
00084         int default_expires;
00085         int type;
00086         int etag_not_new;
00087         /*
00088          *  0 - the standard mechanism (allocating new etag for each Publish)
00089          *  1 - allocating an etag only for an initial Publish 
00090          * */
00091         /* fileds that deal with authorization rules*/
00092         /*
00093          *  req_auth -> flag 0  - if not require 
00094          *  is_watcher_allowed  - get subscription state from xcap rules
00095          *  apply_auth_nbody    - alter the body according to authorization rules
00096          */
00097         int req_auth;
00098         get_rules_doc_t* get_rules_doc;
00099         apply_auth_t*  apply_auth_nbody;
00100         is_allowed_t*  get_auth_status;
00101         
00102         /* an agg_body_t function should be registered if the event permits having
00103          * multiple published states and requires an aggregation of the information
00104          * otherwise, this field should be NULL and the last published state is taken 
00105          * when constructing Notify msg 
00106          * */
00107         agg_nbody_t* agg_nbody;
00108         publ_handling_t  * evs_publ_handl;
00109         subs_handling_t  * evs_subs_handl;
00110         free_body_t* free_body;
00111         /* sometimes it is necessary that a module make changes for a body for each 
00112          * active watcher (e.g. setting the "version" parameter in an XML document.
00113          * If a module registers the aux_body_processing callback, it gets called for
00114          * each watcher. It either gets the body received by the PUBLISH, or the body
00115          * generated by the agg_nbody function.
00116          * The module can deceide if it makes a copy of the original body, which is then
00117          * manipulated, or if it works directly in the original body. If the module makes a
00118          * copy of the original body, it also has to register the aux_free_body() to 
00119          * free this "per watcher" body.
00120          */
00121         aux_body_processing_t* aux_body_processing;
00122         free_body_t* aux_free_body;
00123         struct pres_ev* wipeer;                 
00124         struct pres_ev* next;
00125         
00126 };
00127 typedef struct pres_ev pres_ev_t;
00128 
00129 typedef struct evlist
00130 {
00131         int ev_count;
00132         pres_ev_t* events;
00133 }evlist_t;      
00134 
00135 evlist_t* init_evlist(void);
00136 
00137 int add_event(pres_ev_t* event);
00138 
00139 typedef int (*add_event_t)(pres_ev_t* event);
00140 
00141 void free_event_params(param_t* params, int mem_type);
00142 
00143 pres_ev_t* contains_event(str* name, event_t* parsed_event);
00144 
00145 typedef pres_ev_t* (*contains_event_t)(str* name, event_t* parsed_event);
00146 
00147 int get_event_list(str** ev_list);
00148 
00149 typedef int (*get_event_list_t) (str** ev_list);
00150 
00151 void destroy_evlist(void);
00152 
00153 extern evlist_t* EvList;
00154 
00155 pres_ev_t* search_event(event_t* event);
00156 typedef pres_ev_t* (*search_event_t)(event_t* event);
00157 
00158 event_t* shm_copy_event(event_t* e);
00159 
00160 void shm_free_event(event_t* ev);
00161 
00162 void free_pres_event(pres_ev_t* ev);
00163 
00164 
00165 #endif