1 /* 2 * Copyright (C) 2006 Voice Sistem S.R.L. 3 * 4 * This file is part of Kamailio, a free SIP server. 5 * 6 * Kamailio is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version 10 * 11 * Kamailio is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * 20 */ 21 22 /*! 23 * \file 24 * \brief Kamailio presence module :: Events 25 * \ingroup presence 26 */ 27 28 29 #ifndef _PRES_EV_LST_H 30 #define _PRES_EV_LST_H 31 32 #include "../../core/parser/msg_parser.h" 33 #include "../../core/parser/parse_event.h" 34 #include "../../core/parser/parse_param.h" 35 #include "../../core/str.h" 36 #include "subscribe.h" 37 38 #define WINFO_TYPE 1 << 0 39 #define PUBL_TYPE 1 << 1 40 41 struct subscription; 42 43 typedef int(apply_auth_t)(str *, struct subscription *, str **); 44 45 typedef int(publ_handling_t)(struct sip_msg *); 46 47 typedef int(subs_handling_t)(struct sip_msg *); 48 49 typedef str *(agg_nbody_t)(str *pres_user, str *pres_domain, str **body_array, 50 int n, int off_index); 51 /* params for agg_body_t 52 * body_array= an array with all the bodies stored for that resource 53 * n= the number of bodies 54 * off_index= the index of the registration(etag) for which a Publish 55 * with Expires: 0 has just been received 56 * */ 57 typedef str *(aux_body_processing_t)(struct subscription *subs, str *body); 58 /* params for agg_body_t 59 * subs= a subscription structure to manipulate the body for a certain watcher 60 * body= the original body 61 * 62 * return value: 0: means that there was no manipulation or the manipulation was 63 * done directly in the original body 64 * pointer: a pointer to str for the "per watcher" body. gets freed by aux_free_body() 65 * */ 66 typedef int(is_allowed_t)(struct subscription *subs); 67 typedef int(get_rules_doc_t)(str *user, str *domain, str **rules_doc); 68 typedef int(get_pidf_doc_t)( 69 str *user, str *domain, str *file_uri, str **rules_doc); 70 /* return code rules for is_allowed_t 71 * < 0 if error occurred 72 * =0 if no change in status(if no xcap document exists) 73 * >0 if change in status 74 * */ 75 76 /* event specific body free function */ 77 typedef void(free_body_t)(char *body); 78 79 struct pres_ev 80 { 81 str name; 82 event_t *evp; 83 str content_type; 84 unsigned int default_expires; 85 int type; /* category type: WINFO_TIPE, PUBL_TYPE, ...*/ 86 int etag_not_new; 87 /* 88 * 0 - the standard mechanism (allocating new etag for each Publish) 89 * 1 - allocating an etag only for an initial Publish 90 * */ 91 /* fileds that deal with authorization rules*/ 92 /* 93 * req_auth -> flag 0 - if not require 94 * is_watcher_allowed - get subscription state from xcap rules 95 * apply_auth_nbody - alter the body according to authorization rules 96 */ 97 int req_auth; 98 get_rules_doc_t *get_rules_doc; 99 get_pidf_doc_t *get_pidf_doc; 100 apply_auth_t *apply_auth_nbody; 101 is_allowed_t *get_auth_status; 102 103 /* an agg_body_t function should be registered if the event permits having 104 * multiple published states and requires an aggregation of the information 105 * otherwise, this field should be NULL and the last published state is taken 106 * when constructing Notify msg 107 * */ 108 agg_nbody_t *agg_nbody; 109 publ_handling_t *evs_publ_handl; 110 subs_handling_t *evs_subs_handl; 111 free_body_t *free_body; 112 /* sometimes it is necessary that a module make changes for a body for each 113 * active watcher (e.g. setting the "version" parameter in an XML document. 114 * If a module registers the aux_body_processing callback, it gets called for 115 * each watcher. It either gets the body received by the PUBLISH, or the body 116 * generated by the agg_nbody function. 117 * The module can deceide if it makes a copy of the original body, which is then 118 * manipulated, or if it works directly in the original body. If the module makes a 119 * copy of the original body, it also has to register the aux_free_body() to 120 * free this "per watcher" body. 121 */ 122 aux_body_processing_t *aux_body_processing; 123 free_body_t *aux_free_body; 124 struct pres_ev *wipeer; 125 struct pres_ev *next; 126 }; 127 typedef struct pres_ev pres_ev_t; 128 129 typedef struct evlist 130 { 131 int ev_count; 132 pres_ev_t *events; 133 } evlist_t; 134 135 evlist_t *init_evlist(void); 136 137 int add_event(pres_ev_t *event); 138 139 typedef int (*add_event_t)(pres_ev_t *event); 140 141 void free_event_params(param_t *params, int mem_type); 142 143 pres_ev_t *contains_event(str *name, event_t *parsed_event); 144 145 typedef pres_ev_t *(*contains_event_t)(str *name, event_t *parsed_event); 146 147 int get_event_list(str **ev_list); 148 149 typedef int (*get_event_list_t)(str **ev_list); 150 151 void destroy_evlist(void); 152 153 extern evlist_t *pres_evlist; 154 155 pres_ev_t *search_event(event_t *event); 156 typedef pres_ev_t *(*search_event_t)(event_t *event); 157 158 event_t *shm_copy_event(event_t *e); 159 160 void shm_free_event(event_t *ev); 161 162 void free_pres_event(pres_ev_t *ev); 163 164 165 #endif 166