events_uac.h

00001 #ifndef __SIP_EVENTS_UAC_H
00002 #define __SIP_EVENTS_UAC_H
00003 
00004 /* SIP UAC able to generate SIP events subscriptions and process NOTIFY */
00005 
00006 #include "../dialog/dlg_mod.h" /* this will be the dialog core in the future */
00007 #include "../../timer.h"
00008 #include "../../timer_ticks.h"
00009 #include <cds/msg_queue.h>
00010 #include <cds/ref_cntr.h>
00011 #include <presence/qsa.h>
00012 
00013 #include "trace.h"
00014 
00015 //typedef enum {
00016 //      subscription_unconfirmed, /* after sent SUBSCRIBE */
00017 //      subscription_confirmed, /* after confirmation with 200 OK (enable NOTIFY for it too!) */
00018 //      subscription_resubscribing, /* after sent SUBSCRIBE */
00019 //      subscription_predestroyed, /* after 200 OK on unSUBSCRIBE */
00020 //      subscription_destroyed /* after last NOTIFY (may arrive in destroying status !) */
00021 //} events_uac_status_t;
00022 
00023 typedef enum {
00024         euac_unconfirmed,           /* 0 */
00025         euac_unconfirmed_destroy,   /* 1 */
00026         euac_confirmed,             /* 2 */
00027         euac_waiting,               /* 3 */
00028         euac_resubscription,        /* 4 */
00029         euac_resubscription_destroy,  /* 5 */
00030         euac_waiting_for_termination, /* 6 */
00031         euac_predestroyed,            /* 7 */
00032         euac_destroyed,               /* 8 */
00033 } events_uac_status_t;
00034 
00035 struct _events_uac_t;
00036 typedef struct _events_uac_t events_uac_t;
00037         
00038 typedef void (*notify_callback_func)(events_uac_t *uac, struct sip_msg *, void *param);
00039 
00040 struct _events_uac_t {
00041         /* SUBSCRIBE-NOTIFY dialog */
00042         dlg_t *dialog;
00043 
00044         /* str aor, local_uri, contact; */
00045 
00046         /* callback function for NOTIFY messages (don't use locking here !!!
00047          * it is always locked using events_uac mutex) */
00048         notify_callback_func cb;
00049 
00050         /* parameter for callback function */
00051         void *cbp;
00052 
00053         /* data needed for resubscriptinos */
00054         str headers;            
00055         str local_uri;
00056         str remote_uri;
00057         str route;
00058         str outbound_proxy;
00059 
00060         struct _events_uac_t *prev, *next; /* linked list ? */
00061 
00062         events_uac_status_t status;
00063         
00064         /* reference counter - needed for freeing memory if
00065          * reference stored on more places */
00066         reference_counter_data_t ref_cntr;
00067 
00068         struct timer_ln timer;
00069         int timer_started;
00070 
00071         /* debugging */
00072         char id[64];
00073 };
00074 
00075 /* creates structure in shm and adds it into internal list */
00076 events_uac_t *create_events_uac(str *remote_uri, str *local_uri, 
00077                 const str *events, 
00078                 notify_callback_func cb, /* callback function for processing NOTIFY messages (parsing, ...) */
00079                 void *cbp, /* parameter for callback function */
00080                 const str *other_headers, str *route,
00081                 str *outbound_proxy);
00082 
00083 void free_events_uac(events_uac_t *uac);
00084 
00085 /* removes structure from memory and from internal lists*/
00086 int destroy_events_uac(events_uac_t *uac);
00087 
00088 /* adds a reference to events_uac_t */
00089 events_uac_t *find_events_uac(dlg_id_t *id);
00090 
00091 /* removes reference created by find_events_uac */
00092 void remove_uac_reference(events_uac_t *uac);
00093 
00094 /* intitialize internal structures */
00095 int events_uac_init();
00096 
00097 /* destroy internal structures */
00098 void events_uac_destroy();
00099 
00100 /* tries to process given notify message */
00101 int process_euac_notify(struct sip_msg* m);
00102 
00103 #endif