watcher.h

00001 /*
00002  * Presence Agent, watcher structure and related functions
00003  *
00004  * $Id$
00005  *
00006  * Copyright (C) 2001-2003 FhG Fokus
00007  *
00008  * This file is part of ser, a free SIP server.
00009  *
00010  * ser is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Public License as published by
00012  * the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version
00014  *
00015  * For a license to use the ser software under conditions
00016  * other than those described here, or to purchase support for this
00017  * software, please contact iptel.org by e-mail at the following addresses:
00018  *    info@iptel.org
00019  *
00020  * ser is distributed in the hope that it will be useful,
00021  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  * GNU General Public License for more details.
00024  *
00025  * You should have received a copy of the GNU General Public License 
00026  * along with this program; if not, write to the Free Software 
00027  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028  */
00029 
00030 #ifndef WATCHER_H
00031 #define WATCHER_H
00032 
00033 #include "../../str.h"
00034 #include "../../modules/tm/dlg.h"
00035 #include "../../lib/srdb2/db.h"
00036 #include "../../parser/parse_content.h"
00037 #include "../../parser/parse_event.h" /* EVENT_PRESENCE, EVENT_PRESENCE_WINFO, ... */
00038 #include <stdio.h>
00039 #include <time.h>
00040 
00041 #define DOC_XPIDF        MIMETYPE(APPLICATION,XPIDFXML)
00042 #define DOC_LPIDF        MIMETYPE(APPLICATION,LPIDFXML)
00043 #define DOC_PIDF         MIMETYPE(APPLICATION,PIDFXML)
00044 #define DOC_CPIM_PIDF    MIMETYPE(APPLICATION,CPIM_PIDFXML)
00045 #define DOC_MSRTC_PIDF   MIMETYPE(APPLICATION,XML_MSRTC_PIDF)
00046 #define DOC_WINFO        MIMETYPE(APPLICATION,WATCHERINFOXML)
00047 /*      DOC_XCAP_CHANGE = (1 << 4),
00048         DOC_LOCATION = (1 << 5),*/
00049 #define DOC_MULTIPART_RELATED MIMETYPE(MULTIPART,RELATED),
00050 #define DOC_RLMI_XML          MIMETYPE(APPLICATION,RLMIXML)
00051 
00052 typedef enum watcher_status {
00053         WS_PENDING = 0,
00054         WS_ACTIVE = 1,
00055         WS_REJECTED = 2,
00056         WS_TERMINATED = 3,
00057         WS_PENDING_TERMINATED = 4
00058 } watcher_status_t;
00059 
00060 extern str watcher_status_names[];
00061 extern str watcher_event_names[];
00062 
00063 typedef enum watcher_event {
00064         WE_SUBSCRIBE = 0,
00065         WE_APPROVED = 1,
00066         WE_DEACTIVATED = 2,
00067         WE_PROBATION = 3,
00068         WE_REJECTED = 4,
00069         WE_TIMEOUT = 5,
00070         WE_GIVEUP = 6,
00071         WE_NORESOURCE = 7
00072 } watcher_event_t;
00073 
00074 typedef enum wflags {
00075         WFLAG_SUBSCRIPTION_CHANGED=1
00076 } wflags_t;
00077 
00078 /*
00079  * Structure representing a watcher
00080  */
00081 typedef struct watcher {
00082         str display_name;       /* Display Name of watcher */
00083         str uri;                /* Uri of the watcher */
00084         time_t expires;         /* Absolute of the expiration */
00085         int event_package;      /* event package being watched */
00086         int preferred_mimetype; /* Type of document accepted by the watcher */
00087         int document_index;             /* many documents (winfo, ...) requires sequential numbering */
00088         dlg_t* dialog;          /* Dialog handle */
00089         str id;                 /* id of this watcher (used for DB and winfo docs) */
00090         str server_contact;             /* used for contact header in NOTIFY messages */
00091         wflags_t flags;
00092         watcher_event_t  event;
00093         watcher_status_t status; /* status of subscription */
00094         struct watcher *prev, *next;   /* linking members */
00095 } watcher_t;
00096 
00097 struct presentity;
00098 
00099 /* Convert watcher status name to enum */
00100 watcher_status_t watcher_status_from_string(str *wsname);
00101 
00102 /* Create a new watcher structure */
00103 int new_watcher_no_wb(str* _uri, time_t _e, int event_package, 
00104                 int doc_type, dlg_t* _dlg, str *display_name, 
00105                 str *server_contact, 
00106                 str *id, /* database ID or NULL if not loading from DB */
00107                 watcher_t** _w);
00108 
00109 /* Release a watcher structure */
00110 void free_watcher(watcher_t* _w);
00111 
00114 int append_watcher(struct presentity *_p, watcher_t *_w, int add_to_db);
00115         
00116 /* Remove a watcher/winfo watcher from the watcher list and from database. */
00117 void remove_watcher(struct presentity* _p, watcher_t* _w);
00118 
00119 /* Find a watcher/winfo watcher in the list/winfo list (according to
00120  * _et parameter) via dialog identifier */
00121 int find_watcher_dlg(struct presentity* _p, dlg_id_t *dlg_id, int _et, watcher_t** _w);
00122 
00123 /* update watcher in db */
00124 int db_update_watcher(struct presentity *p, watcher_t* _w);
00125 
00126 /* Update expires value of a watcher */
00127 int update_watcher(struct presentity *p, watcher_t* _w, time_t _e, struct sip_msg *m);
00128 
00129 /* Read watcherinfo table from database for presentity _p */
00130 int db_read_watcherinfo(struct presentity *_p, db_con_t* db);
00131 
00134 int is_watcher_terminated(watcher_t *w);
00135 
00137 int is_watcher_authorized(watcher_t *w);
00138 
00140 void set_watcher_terminated_status(watcher_t *w);
00141 
00142 const char *event_package2str(int et);
00143 
00144 #endif /* WATCHER_H */