Update to the new event parser in the sip-router core.
authorJan Janak <jan@iptel.org>
Tue, 17 Mar 2009 17:46:13 +0000 (18:46 +0100)
committerJan Janak <jan@iptel.org>
Wed, 15 Apr 2009 12:35:22 +0000 (14:35 +0200)
List of changes:
 * Variable parsed in the event structure has been renamed to type
 * Variable text in the event structure has been renamed to name
 * Linked list of parameters is now in event->params.list
 * There is a new macro EVENT_DIALOG_SLA in util_func.h
 * Use macro EVENT_DIALOG_SLA to if the Event header contains
   "dialog;sla"

modules_k/presence/event_list.c
modules_k/presence/hash.c
modules_k/presence/notify.c
modules_k/presence/presentity.c
modules_k/presence/publish.c
modules_k/presence/subscribe.c
modules_k/presence/utils_func.h

index abf1a71..83ebc09 100644 (file)
@@ -61,15 +61,15 @@ event_t* shm_copy_event(event_t* e)
        }
        memset(ev, 0, sizeof(event_t));
 
-       ev->text.s= (char*)shm_malloc(e->text.len* sizeof(char));
-       if(ev->text.s== NULL)
+       ev->name.s= (char*)shm_malloc(e->name.len* sizeof(char));
+       if(ev->name.s== NULL)
        {
                ERR_MEM(SHARE_MEM);
        }
-       memcpy(ev->text.s, e->text.s, e->text.len);
-       ev->text.len= e->text.len;
+       memcpy(ev->name.s, e->name.s, e->name.len);
+       ev->name.len= e->name.len;
 
-       p1= e->params;
+       p1= e->params.list;
        while(p1)
        {
                size= sizeof(param_t)+ (p1->name.len+ p1->body.len)* sizeof(char);
@@ -84,11 +84,11 @@ event_t* shm_copy_event(event_t* e)
                CONT_COPY(p2, p2->name, p1->name);
                if(p1->body.s && p1->body.len)
                        CONT_COPY(p2, p2->body, p1->body);
-               p2->next= ev->params;
-               ev->params= p2;
+               p2->next= ev->params.list;
+               ev->params.list= p2;
                p1= p1->next;
        }
-       ev->parsed= e->parsed;
+       ev->type= e->type;
 
        return ev;
 
@@ -102,10 +102,10 @@ void shm_free_event(event_t* ev)
        if(ev== NULL)
                return;
        
-       if(ev->text.s)
-               shm_free(ev->text.s);
+       if(ev->name.s)
+               shm_free(ev->name.s);
 
-       free_event_params(ev->params, SHM_MEM_TYPE);
+       free_event_params(ev->params.list, SHM_MEM_TYPE);
 
        shm_free(ev);
 }
@@ -141,14 +141,14 @@ int add_event(pres_ev_t* event)
                ev= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t));
                if(ev== NULL)
                {
-                       free_event_params(parsed_event.params, PKG_MEM_TYPE);
+                       free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
                        ERR_MEM(SHARE_MEM);
                }
                memset(ev, 0, sizeof(pres_ev_t));
                ev->name.s= (char*)shm_malloc(event->name.len* sizeof(char));
                if(ev->name.s== NULL)
                {
-                       free_event_params(parsed_event.params, PKG_MEM_TYPE);
+                       free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
                        ERR_MEM(SHARE_MEM);
                }
                memcpy(ev->name.s, event->name.s, event->name.len);
@@ -158,14 +158,14 @@ int add_event(pres_ev_t* event)
                if(ev->evp== NULL)
                {
                        LM_ERR("copying event_t structure\n");
-                       free_event_params(parsed_event.params, PKG_MEM_TYPE);
+                       free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
                        goto error;
                }
-               free_event_params(parsed_event.params, PKG_MEM_TYPE);
+               free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
        }
        else
        {
-               free_event_params(parsed_event.params, PKG_MEM_TYPE);
+               free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
                if(ev->content_type.s)
                {
                        LM_DBG("Event already registered\n");
@@ -296,7 +296,7 @@ pres_ev_t* contains_event(str* sname, event_t* parsed_event)
                *parsed_event= event;
        else
        {
-               free_event_params(event.params, PKG_MEM_TYPE);
+               free_event_params(event.params.list, PKG_MEM_TYPE);
        }
        e= search_event(&event);
 
@@ -325,13 +325,13 @@ pres_ev_t* search_event(event_t* event)
        pres_ev_t* pres_ev;
        pres_ev= EvList->events;
 
-       LM_DBG("start event= [%.*s]\n", event->text.len, event->text.s);
+       LM_DBG("start event= [%.*s]\n", event->name.len, event->name.s);
 
        while(pres_ev)
        {
-               if(pres_ev->evp->parsed== event->parsed)
+               if(pres_ev->evp->type== event->type)
                {
-                       if(event->params== NULL && pres_ev->evp->params== NULL)
+                       if(event->params.list== NULL && pres_ev->evp->params.list== NULL)
                        {
                                return pres_ev;
                        }
@@ -357,11 +357,11 @@ int search_event_params(event_t* ev, event_t* searched_ev)
        param_t* ps, *p;
        int found;
 
-       ps= ev->params;
+       ps= ev->params.list;
 
        while(ps)
        {
-               p= searched_ev->params;
+               p= searched_ev->params.list;
                found= 0;
        
                while(p)
index 72f9f7b..11e5fc9 100644 (file)
@@ -598,7 +598,7 @@ int update_phtable(presentity_t* presentity, str pres_uri, str body)
        
        lock_get(&pres_htable[hash_code].lock);
 
-       p= search_phtable(&pres_uri, presentity->event->evp->parsed, hash_code);
+       p= search_phtable(&pres_uri, presentity->event->evp->type, hash_code);
        if(p== NULL)
        {
                lock_release(&pres_htable[hash_code].lock);
index 6a805cb..289df69 100644 (file)
@@ -638,7 +638,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag,
 
        /* search in hash table if any record exists */
        hash_code= core_hash(&pres_uri, NULL, phtable_size);
-       if(search_phtable(&pres_uri, event->evp->parsed, hash_code)== NULL)
+       if(search_phtable(&pres_uri, event->evp->type, hash_code)== NULL)
        {
                LM_DBG("No record exists in hash_table\n");
                if(fallback2db)
@@ -726,8 +726,7 @@ db_query:
                        
                        /* if event BLA - check if sender is the same as contact */
                        /* if so, send an empty dialog info document */
-                       if( event->evp->parsed == EVENT_DIALOG_SLA && contact )
-                       {
+                       if( EVENT_DIALOG_SLA(event->evp) && contact ) {
                                sender.s = (char*)row_vals[sender_col].val.string_val;
                                if(sender.s== NULL || strlen(sender.s)==0)
                                        goto after_sender_check;
index 749668f..630366f 100644 (file)
@@ -340,7 +340,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
        {
                /* insert new record in hash_table */
        
-               if(insert_phtable(&pres_uri, presentity->event->evp->parsed, sphere)< 0)
+               if(insert_phtable(&pres_uri, presentity->event->evp->type, sphere)< 0)
                {
                        LM_ERR("inserting record in hash table\n");
                        goto error;
@@ -417,7 +417,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                if (result->n > 0)
                {
 
-                       if(presentity->event->evp->parsed == EVENT_DIALOG_SLA)
+                       if(EVENT_DIALOG_SLA(presentity->event->evp))
                        {
                                /* analize if previous body has a dialog */
                                row = &result->rows[0];
@@ -489,7 +489,7 @@ after_dialog_check:
 
                                /* delete from hash table */
        
-                               if(delete_phtable(&pres_uri, presentity->event->evp->parsed)< 0)
+                               if(delete_phtable(&pres_uri, presentity->event->evp->type)< 0)
                                {
                                        LM_ERR("deleting record from hash table\n");
                                        goto error;
@@ -500,7 +500,7 @@ after_dialog_check:
                        n_update_cols= 0;
                        /* if event dialog and is_dialog -> if sender not the same as
                         * old sender do not overwrite */
-                       if( (presentity->event->evp->parsed == EVENT_DIALOG_SLA) &&  bla_update_publish==0)
+                       if( EVENT_DIALOG_SLA(presentity->event->evp) &&  bla_update_publish==0)
                        {
                                LM_DBG("drop Publish for BLA from a different sender that"
                                                " wants to overwrite an existing dialog\n");
@@ -582,7 +582,7 @@ after_dialog_check:
 
                                /* updated stored sphere */
                                if(sphere_enable && 
-                                               presentity->event->evp->parsed== EVENT_PRESENCE)
+                                               presentity->event->evp->type== EVENT_PRESENCE)
                                {
                                        if(update_phtable(presentity, pres_uri, *body)< 0)
                                        {
@@ -742,11 +742,11 @@ int pres_htable_restore(void)
                if(event_parser(ev_str.s, ev_str.len, &ev)< 0)
                {
                        LM_ERR("parsing event\n");
-                       free_event_params(ev.params, PKG_MEM_TYPE);
+                       free_event_params(ev.params.list, PKG_MEM_TYPE);
                        goto error;
                }
-               event= ev.parsed;
-               free_event_params(ev.params, PKG_MEM_TYPE);
+               event= ev.type;
+               free_event_params(ev.params.list, PKG_MEM_TYPE);
 
                if(uandd_to_uri(user, domain, &uri)< 0)
                {
index 3cc7311..bb7c653 100644 (file)
@@ -177,7 +177,7 @@ void msg_presentity_clean(unsigned int ticks,void *param)
                if(pres->event== NULL)
                {
                        LM_ERR("event not found\n");
-                       free_event_params(ev.params, PKG_MEM_TYPE);
+                       free_event_params(ev.params.list, PKG_MEM_TYPE);
                        goto error;
                }       
        
@@ -185,18 +185,18 @@ void msg_presentity_clean(unsigned int ticks,void *param)
                if(uandd_to_uri(user, domain, &p[i].uri)< 0)
                {
                        LM_ERR("constructing uri\n");
-                       free_event_params(ev.params, PKG_MEM_TYPE);
+                       free_event_params(ev.params.list, PKG_MEM_TYPE);
                        goto error;
                }
                
                /* delete from hash table */
-               if(delete_phtable(&p[i].uri, ev.parsed)< 0)
+               if(delete_phtable(&p[i].uri, ev.type)< 0)
                {
                        LM_ERR("deleting from pres hash table\n");
-                       free_event_params(ev.params, PKG_MEM_TYPE);
+                       free_event_params(ev.params.list, PKG_MEM_TYPE);
                        goto error;
                }
-               free_event_params(ev.params, PKG_MEM_TYPE);
+               free_event_params(ev.params.list, PKG_MEM_TYPE);
 
        }
        pa_dbf.free_result(pa_db, result);
@@ -325,7 +325,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
                        reply_str= pu_400a_rpl;
                        goto error;
                }
-               if(((event_t*)msg->event->parsed)->parsed == EVENT_OTHER)
+               if(((event_t*)msg->event->parsed)->type == EVENT_OTHER)
                {       
                        goto unsupported_event;
                }
@@ -334,7 +334,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
                goto unsupported_event;
 
        /* search event in the list */
-       event= search_event((event_t*)msg->event->parsed);
+       event= search_event((event_t*)msg->event->type);
        if(event== NULL)
        {
                goto unsupported_event;
@@ -441,7 +441,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
                }
                body.len= get_content_length( msg );
 
-               if(sphere_enable && event->evp->parsed == EVENT_PRESENCE &&
+               if(sphere_enable && event->evp->type == EVENT_PRESENCE &&
                                get_content_type(msg)== SUBTYPE_PIDFXML)
                {
                        sphere= extract_sphere(body);                   
index bda0d36..50ffcd3 100644 (file)
@@ -541,7 +541,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
                        reply_str= pu_400_rpl;
                        goto error;
                }
-               if(((event_t*)msg->event->parsed)->parsed == EVENT_OTHER)
+               if(((event_t*)msg->event->parsed)->type == EVENT_OTHER)
                {       
                        goto bad_event;
                }
@@ -559,7 +559,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        subs.event= event;
        
        /* extract the id if any*/
-       ev_param= parsed_event->params;
+       ev_param= parsed_event->params.list;
        while(ev_param)
        {
                if(ev_param->name.len== 2 && strncmp(ev_param->name.s, "id", 2)== 0)
@@ -580,7 +580,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        /* getting presentity uri from Request-URI if initial subscribe - or else from database*/
        if(to_tag_gen)
        {
-               if(parsed_event->parsed!= EVENT_DIALOG_SLA)
+               if (!EVENT_DIALOG_SLA(parsed_event))
                {
                        if( parse_sip_msg_uri(msg)< 0)
                        {
@@ -711,8 +711,8 @@ bad_event:
 
        LM_ERR("Missing or unsupported event header field value\n");
                
-       if(parsed_event && parsed_event->text.s)
-               LM_ERR("\tevent= %.*s\n",parsed_event->text.len,parsed_event->text.s);
+       if(parsed_event && parsed_event->name.s)
+               LM_ERR("\tevent= %.*s\n",parsed_event->name.len,parsed_event->name.s);
        
        reply_code= BAD_EVENT_CODE;
        reply_str= pu_489_rpl;
@@ -918,7 +918,7 @@ int extract_sdialog_info(subs_t* subs,struct sip_msg* msg, int mexp,
        LM_DBG("subs->contact= %.*s - len = %d\n",subs->contact.len,
                        subs->contact.s, subs->contact.len);    
 
-    if(subs->event->evp->parsed== EVENT_DIALOG_SLA)
+       if (EVENT_DIALOG_SLA(subs->event->evp))
     {
         /* user_contact@from_domain */
         if(parse_uri(subs->contact.s, subs->contact.len, &uri)< 0)
@@ -1027,7 +1027,7 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* reply_code,
        {
                lock_get(&subs_htable[i].lock);
                s= search_shtable(subs_htable, subs->callid,subs->to_tag,subs->from_tag, i);
-               if(s && s->event->evp->parsed!= EVENT_DIALOG_SLA)
+               if (s && !EVENT_DIALOG_SLA(s->event->evp))
                {
                        pres_uri.s= (char*)pkg_malloc(s->pres_uri.len* sizeof(char));
                        if(pres_uri.s== NULL)
@@ -1059,7 +1059,7 @@ found_rec:
        
        LM_DBG("Record found in hash_table\n");
        
-       if(s->event->evp->parsed!= EVENT_DIALOG_SLA)
+       if(!EVENT_DIALOG_SLA(s->event->evp))
                subs->pres_uri= pres_uri;
        
        subs->version = s->version;
@@ -1260,7 +1260,7 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* reply_code, str* r
        subs->local_cseq= row_vals[local_cseq_col].val.int_val;
        subs->version= row_vals[version_col].val.int_val;
 
-       if(subs->event->evp->parsed!= EVENT_DIALOG_SLA)
+       if(!EVENT_DIALOG_SLA(subs->event->evp))
        {
                pres_uri.s= (char*)row_vals[pres_uri_col].val.string_val;
                pres_uri.len= strlen(pres_uri.s);
@@ -1739,14 +1739,14 @@ int restore_db_subs(void)
                        event= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t));
                        if(event== NULL)
                        {
-                               free_event_params(parsed_event.params, PKG_MEM_TYPE);
+                               free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
                                ERR_MEM(SHM_MEM_STR);
                        }
                        memset(event, 0, sizeof(pres_ev_t));
                        event->name.s= (char*)shm_malloc(ev_sname.len* sizeof(char));
                        if(event->name.s== NULL)
                        {
-                               free_event_params(parsed_event.params, PKG_MEM_TYPE);
+                               free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
                                ERR_MEM(SHM_MEM_STR);
                        }
                        memcpy(event->name.s,ev_sname.s, ev_sname.len);
@@ -1756,14 +1756,14 @@ int restore_db_subs(void)
                        if(event->evp== NULL)
                        {
                                LM_ERR("ERROR copying event_t structure\n");
-                               free_event_params(parsed_event.params, PKG_MEM_TYPE);
+                               free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
                                goto error;
                        }
                        event->next= EvList->events;
                        EvList->events= event;
                }
                        
-               free_event_params(parsed_event.params, PKG_MEM_TYPE);
+               free_event_params(parsed_event.params.list, PKG_MEM_TYPE);
 
                s.event= event;
 
index 19e6917..c6590c8 100644 (file)
 #include "../../dprint.h"
 #include "../../str.h"
 #include "../../parser/msg_parser.h"
+#include "../../parser/parse_event.h"
 
 #define LCONTACT_BUF_SIZE 1024
 #define BAD_EVENT_CODE 489
 
+
+#define EVENT_DIALOG_SLA(ev) \
+       ((ev)->type == EVENT_DIALOG && (ev)->params.dialog.sla)
+
+
 static inline int uandd_to_uri(str user,  str domain, str *out)
 {
        int size;