obsolete/pa/watcher.h
fdeceea5
 /*
  * Presence Agent, watcher structure and related functions
  *
  * $Id$
  *
95072403
  * Copyright (C) 2001-2003 FhG Fokus
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 WATCHER_H
 #define WATCHER_H
 
 #include "../../str.h"
7a7f1a7b
 #include "../../modules/tm/dlg.h"
 #include "../../lib/srdb2/db.h"
348b543f
 #include "../../parser/parse_content.h"
5d58dfb2
 #include "../../parser/parse_event.h" /* EVENT_PRESENCE, EVENT_PRESENCE_WINFO, ... */
fdeceea5
 #include <stdio.h>
 #include <time.h>
 
1666e93e
 #define DOC_XPIDF        MIMETYPE(APPLICATION,XPIDFXML)
 #define DOC_LPIDF        MIMETYPE(APPLICATION,LPIDFXML)
 #define DOC_PIDF         MIMETYPE(APPLICATION,PIDFXML)
 #define DOC_CPIM_PIDF    MIMETYPE(APPLICATION,CPIM_PIDFXML)
 #define DOC_MSRTC_PIDF   MIMETYPE(APPLICATION,XML_MSRTC_PIDF)
 #define DOC_WINFO        MIMETYPE(APPLICATION,WATCHERINFOXML)
 /*	DOC_XCAP_CHANGE = (1 << 4),
 	DOC_LOCATION = (1 << 5),*/
 #define DOC_MULTIPART_RELATED MIMETYPE(MULTIPART,RELATED),
 #define DOC_RLMI_XML          MIMETYPE(APPLICATION,RLMIXML)
fdeceea5
 
87b386b3
 typedef enum watcher_status {
 	WS_PENDING = 0,
69fd5125
 	WS_ACTIVE = 1,
541e1786
 	WS_REJECTED = 2,
 	WS_TERMINATED = 3,
 	WS_PENDING_TERMINATED = 4
87b386b3
 } watcher_status_t;
 
541e1786
 extern str watcher_status_names[];
8516e9d9
 extern str watcher_event_names[];
541e1786
 
69fd5125
 typedef enum watcher_event {
 	WE_SUBSCRIBE = 0,
 	WE_APPROVED = 1,
 	WE_DEACTIVATED = 2,
 	WE_PROBATION = 3,
 	WE_REJECTED = 4,
 	WE_TIMEOUT = 5,
 	WE_GIVEUP = 6,
 	WE_NORESOURCE = 7
 } watcher_event_t;
 
04847d67
 typedef enum wflags {
69fd5125
 	WFLAG_SUBSCRIPTION_CHANGED=1
04847d67
 } wflags_t;
 
9470206e
 /*
  * Structure representing a watcher
  */
fdeceea5
 typedef struct watcher {
04847d67
 	str display_name;       /* Display Name of watcher */
80d384c3
 	str uri;                /* Uri of the watcher */
b37fbbd0
 	time_t expires;         /* Absolute of the expiration */
49447807
 	int event_package;      /* event package being watched */
541e1786
 	int preferred_mimetype; /* Type of document accepted by the watcher */
 	int document_index;		/* many documents (winfo, ...) requires sequential numbering */
348b543f
  	dlg_t* dialog;          /* Dialog handle */
5d58dfb2
 	str id;                 /* id of this watcher (used for DB and winfo docs) */
4984a9b5
 	str server_contact;		/* used for contact header in NOTIFY messages */
04847d67
 	wflags_t flags;
541e1786
 	watcher_event_t  event;
87b386b3
 	watcher_status_t status; /* status of subscription */
5d58dfb2
 	struct watcher *prev, *next;   /* linking members */
fdeceea5
 } watcher_t;
 
5d58dfb2
 struct presentity;
69fd5125
 
5d58dfb2
 /* Convert watcher status name to enum */
 watcher_status_t watcher_status_from_string(str *wsname);
69fd5125
 
5d58dfb2
 /* Create a new watcher structure */
f7372307
 int new_watcher_no_wb(str* _uri, time_t _e, int event_package, 
1666e93e
 		int doc_type, dlg_t* _dlg, str *display_name, 
5d58dfb2
 		str *server_contact, 
 		str *id, /* database ID or NULL if not loading from DB */
 		watcher_t** _w);
541e1786
 
5d58dfb2
 /* Release a watcher structure */
 void free_watcher(watcher_t* _w);
fdeceea5
 
5d58dfb2
 /** Appends watcher/winfo watcher to presentity. It updates presentity's
  * flags and adds the watcher into DB if requested and use_db set. */
 int append_watcher(struct presentity *_p, watcher_t *_w, int add_to_db);
 	
 /* Remove a watcher/winfo watcher from the watcher list and from database. */
 void remove_watcher(struct presentity* _p, watcher_t* _w);
541e1786
 
5d58dfb2
 /* Find a watcher/winfo watcher in the list/winfo list (according to
  * _et parameter) via dialog identifier */
 int find_watcher_dlg(struct presentity* _p, dlg_id_t *dlg_id, int _et, watcher_t** _w);
fdeceea5
 
5d58dfb2
 /* update watcher in db */
 int db_update_watcher(struct presentity *p, watcher_t* _w);
fdeceea5
 
5d58dfb2
 /* Update expires value of a watcher */
626094a5
 int update_watcher(struct presentity *p, watcher_t* _w, time_t _e, struct sip_msg *m);
fdeceea5
 
5d58dfb2
 /* Read watcherinfo table from database for presentity _p */
541e1786
 int db_read_watcherinfo(struct presentity *_p, db_con_t* db);
49447807
 
5d58dfb2
 /** Returns 1 if given watcher is in one of terminated statuses 
541e1786
  * and should be deleted */
 int is_watcher_terminated(watcher_t *w);
 
 /** Returns 1 if given watcher can receive status documents */
 int is_watcher_authorized(watcher_t *w);
 
 /** Sets status to correct terminated status for this watcher. */
 void set_watcher_terminated_status(watcher_t *w);
 
8516e9d9
 const char *event_package2str(int et);
541e1786
 
fdeceea5
 #endif /* WATCHER_H */