- replaced LOG/DBG with LM_
authorAnca Vamanu <anca@voice-system.ro>
Mon, 3 Sep 2007 09:45:29 +0000 (09:45 +0000)
committerAnca Vamanu <anca@voice-system.ro>
Mon, 3 Sep 2007 09:45:29 +0000 (09:45 +0000)
git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2697 689a6050-402a-0410-94f2-e92a70836424

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

index 15f3bad..d765d63 100644 (file)
@@ -36,7 +36,7 @@
 int bind_presence(presence_api_t* api)
 {
        if (!api) {
-               LOG(L_ERR, "PRESENCE:bind_notifier: Invalid parameter value\n");
+               LM_ERR("Invalid parameter value\n");
                return -1;
        }
        
index 53b56f2..981bb5b 100644 (file)
@@ -48,14 +48,14 @@ event_t* shm_copy_event(event_t* e)
        ev= (event_t*)shm_malloc(sizeof(event_t));
        if(ev== NULL)
        {
-               ERR_MEM("PRESENCE","shm_copy_event");
+               ERR_MEM(SHARE_MEM);
        }
        memset(ev, 0, sizeof(event_t));
 
        ev->text.s= (char*)shm_malloc(e->text.len* sizeof(char));
        if(ev->text.s== NULL)
        {
-               ERR_MEM("PRESENCE","shm_copy_event");
+               ERR_MEM(SHARE_MEM);
        }
        memcpy(ev->text.s, e->text.s, e->text.len);
        ev->text.len= e->text.len;
@@ -67,7 +67,7 @@ event_t* shm_copy_event(event_t* e)
                p2= (param_t*)shm_malloc(size);
                if(p2== NULL)
                {
-                       ERR_MEM("PRESENCE","shm_copy_event");
+                       ERR_MEM(SHARE_MEM);
                }
                memset(p2, 0, size);
 
@@ -121,13 +121,13 @@ int add_event(pres_ev_t* event)
 
        if(event->name.s== NULL || event->name.len== 0)
        {
-               LOG(L_ERR, "PRESENCE: add_event: NULL event name\n");
+               LM_ERR("NULL event name\n");
                return -1;
        }
 
        if(event->content_type.s== NULL || event->content_type.len== 0)
        {
-               LOG(L_ERR, "PRESENCE: add_event: NULL content_type param\n");
+               LM_ERR("NULL content_type param\n");
                return -1;
        }
        
@@ -138,13 +138,13 @@ int add_event(pres_ev_t* event)
                ev= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t));
                if(ev== NULL)
                {
-                       ERR_MEM("PRESENCE","add_event");
+                       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)
                {
-                       ERR_MEM("PRESENCE","add_events");
+                       ERR_MEM(SHARE_MEM);
                }
                memcpy(ev->name.s, event->name.s, event->name.len);
                ev->name.len= event->name.len;
@@ -152,7 +152,7 @@ int add_event(pres_ev_t* event)
                ev->evp= shm_copy_event(&parsed_event);
                if(ev->evp== NULL)
                {
-                       LOG(L_ERR, "PRESENCE:add_event:ERROR copying event_t structure\n");
+                       LM_ERR("copying event_t structure\n");
                        goto error;
                }
        }
@@ -160,7 +160,7 @@ int add_event(pres_ev_t* event)
        {
                if(ev->content_type.s)
                {
-                       DBG("PRESENCE: add_event: Event already registered\n");
+                       LM_DBG("Event already registered\n");
                        return 0;
                }
        }
@@ -168,7 +168,7 @@ int add_event(pres_ev_t* event)
        ev->content_type.s=(char*)shm_malloc(event->content_type.len* sizeof(char)) ;
        if(ev->content_type.s== NULL)
        {
-               ERR_MEM("PRESENCE","add_event");
+               ERR_MEM(SHARE_MEM);
        }       
        ev->content_type.len= event->content_type.len;
        memcpy(ev->content_type.s, event->content_type.s, event->content_type.len);
@@ -198,7 +198,7 @@ int add_event(pres_ev_t* event)
        if(event->req_auth && 
                ( event->get_auth_status==0 ||event->get_rules_doc== 0))
        {
-               LOG(L_ERR, "PRESENCE:add_event:ERROR bad event structure\n");
+               LM_ERR("bad event structure\n");
                goto error;
        }
        ev->req_auth= event->req_auth;
@@ -218,8 +218,8 @@ int add_event(pres_ev_t* event)
        }
        EvList->ev_count++;
        
-       DBG("PRESENCE: add_event: succesfully added event: %.*s - len= %d\n", 
-                       ev->name.len, ev->name.s, ev->name.len);
+       LM_DBG("succesfully added event: %.*s - len= %d\n",ev->name.len,
+                       ev->name.s, ev->name.len);
        return 0;
 error:
        if(ev && not_in_list)
@@ -250,7 +250,7 @@ evlist_t* init_evlist(void)
        list= (evlist_t*)shm_malloc(sizeof(evlist_t));
        if(list== NULL)
        {
-               LOG(L_ERR, "PRESENCE: init_evlist: ERROR no more share memory\n");
+               LM_ERR("no more share memory\n");
                return NULL;
        }
        list->ev_count= 0;
@@ -267,7 +267,7 @@ pres_ev_t* contains_event(str* sname, event_t* parsed_event)
        memset(&event, 0, sizeof(event_t));
        if(event_parser(sname->s, sname->len, &event)< 0)
        {
-               LOG(L_ERR, "PRESENCE:contains_event: ERROR parsing event\n");
+               LM_ERR("parsing event\n");
                return NULL;
        }
        if(parsed_event)
@@ -286,7 +286,6 @@ pres_ev_t* search_event(event_t* event)
        param_t* ps, *p;
        int found;
 
-       DBG("PRESENCE:search_event...\n");
        while(pres_ev)
        {
                if(pres_ev->evp->parsed== event->parsed)
@@ -338,14 +337,14 @@ int get_event_list(str** ev_list)
        list= (str*)pkg_malloc(sizeof(str));
        if(list== NULL)
        {
-               LOG(L_ERR, "PRESENCE: get_event_list: ERROR No more memory\n");
+               LM_ERR("No more memory\n");
                return -1;
        }
        memset(list, 0, sizeof(str));
        list->s= (char*)pkg_malloc(EvList->ev_count* MAX_EVNAME_SIZE);
        if(list->s== NULL)
        {
-               LOG(L_ERR, "PRESENCE: get_event_list: ERROR No more memory\n");
+               LM_ERR("No more memory\n");
                pkg_free(list);
                return -1;
        }
index 157c1dd..c820bb9 100644 (file)
@@ -44,21 +44,20 @@ shtable_t new_shtable(void)
        htable= (subs_entry_t*)shm_malloc(shtable_size* sizeof(subs_entry_t));
        if(htable== NULL)
        {
-               ERR_MEM("PRESENCE","new_shtable");
+               ERR_MEM(SHARE_MEM);
        }
        memset(htable, 0, shtable_size* sizeof(subs_entry_t));
        for(i= 0; i< shtable_size; i++)
        {
                if(lock_init(&htable[i].lock)== 0)
                {
-                       LOG(L_ERR,"PRESENCE:new_shtable: ERROR initializing lock"
-                                       " [%d]\n", i);
+                       LM_ERR("initializing lock [%d]\n", i);
                        goto error;
                }
                htable[i].entries= (subs_t*)shm_malloc(sizeof(subs_t));
                if(htable[i].entries== NULL)
                {
-                       ERR_MEM("PRESENCE","new_shtable");
+                       ERR_MEM(SHARE_MEM);
                }
                memset(htable[i].entries, 0, sizeof(subs_t));
                htable[i].entries->next= NULL;
@@ -138,7 +137,7 @@ subs_t* mem_copy_subs(subs_t* s, int mem_type)
 
        if(dest== NULL)
        {
-               ERR_MEM("PRESENCE","mem_copy_subs");
+               ERR_MEM((mem_type==PKG_MEM_TYPE)?PKG_MEM_STR:SHARE_MEM);
        }
        memset(dest, 0, size);
        size= sizeof(subs_t);
@@ -190,8 +189,7 @@ int insert_shtable(subs_t* subs)
        new_rec= mem_copy_subs(subs, SHM_MEM_TYPE);
        if(new_rec== NULL)
        {
-               LOG(L_ERR, "PRESENCE: insert_shtable: ERROR while copying in"
-                               " share memory a subs_t structure\n");
+               LM_ERR("copying in share memory a subs_t structure\n");
                goto error;
        }
 
@@ -222,7 +220,6 @@ int delete_shtable(str pres_uri, str ev_stored_name, str to_tag)
        subs_t* s= NULL, *ps= NULL;
        int found= -1;
 
-       DBG("PRESENCE: delete_shtable..\n");
        hash_code= core_hash(&pres_uri, &ev_stored_name, shtable_size);
        lock_get(&subs_htable[hash_code].lock);
        
@@ -267,14 +264,13 @@ int update_shtable(subs_t* subs, int type)
        unsigned int hash_code;
        subs_t* s;
 
-       DBG("PRESENCE:update_shtable..\n");
        hash_code= core_hash(&subs->pres_uri, &subs->event->name, shtable_size);
        lock_get(&subs_htable[hash_code].lock);
 
        s= search_shtable(subs->callid, subs->to_tag, subs->from_tag, hash_code);
        if(s== NULL)
        {
-               DBG("PRESENCE:update_shtable: record not found in hash table\n");
+               LM_DBG("record not found in hash table\n");
                lock_release(&subs_htable[hash_code].lock);
                return -1;
        }
@@ -310,7 +306,7 @@ phtable_t* new_phtable(void)
        htable= (phtable_t*)shm_malloc(phtable_size* sizeof(phtable_t));
        if(htable== NULL)
        {
-               ERR_MEM("PRESENCE","new_phtable");
+               ERR_MEM(SHARE_MEM);
        }
        memset(htable, 0, phtable_size* sizeof(phtable_t));
 
@@ -318,14 +314,13 @@ phtable_t* new_phtable(void)
        {
                if(lock_init(&htable[i].lock)== 0)
                {
-                       LOG(L_ERR,"PRESENCE:new_phtable: ERROR initializing lock"
-                                       " [%d]\n", i);
+                       LM_ERR("initializing lock [%d]\n", i);
                        goto error;
                }
                htable[i].entries= (pres_entry_t*)shm_malloc(sizeof(pres_entry_t));
                if(htable[i].entries== NULL)
                {
-                       ERR_MEM("PRESENCE","new_phtable");
+                       ERR_MEM(SHARE_MEM);
                }
                memset(htable[i].entries, 0, sizeof(pres_entry_t));
                htable[i].entries->next= NULL;
@@ -410,7 +405,7 @@ int insert_phtable(str* pres_uri, int event)
        if(p== NULL)
        {
                lock_release(&pres_htable[hash_code].lock);
-               ERR_MEM("PRESENCE","insert_phtable");
+               ERR_MEM(SHARE_MEM);
        }
        memset(p, 0, size);
 
@@ -431,6 +426,7 @@ int insert_phtable(str* pres_uri, int event)
 error:
        return -1;
 }
+
 int delete_phtable(str* pres_uri, int event)
 {
        unsigned int hash_code;
@@ -443,7 +439,7 @@ int delete_phtable(str* pres_uri, int event)
        p= search_phtable(pres_uri, event, hash_code);
        if(p== NULL)
        {
-               DBG("PRESENCE: delete_phtable: record not found\n");
+               LM_DBG("record not found\n");
                lock_release(&pres_htable[hash_code].lock);
                return 0;
        }
@@ -461,8 +457,7 @@ int delete_phtable(str* pres_uri, int event)
                }
                if(prev_p->next== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: delete_phtable: ERROR "
-                                       "previous record not found\n");
+                       LM_ERR("record not found\n");
                        lock_release(&pres_htable[hash_code].lock);
                        return -1;
                }
index ac96c25..ea20884 100644 (file)
 #define REMOTE_TYPE   1<<1
 #define LOCAL_TYPE    1<<2
 
-#define ERR_MEM(module, func)  LOG(L_ERR, "%s:%s:ERROR No more memory\n", module,func);\
+#define PKG_MEM_STR       "pkg"
+#define SHARE_MEM         "share"
+
+#define ERR_MEM(mem_type)  LM_ERR("No more %s memory\n",mem_type);\
                                                goto error
 
 #define CONT_COPY(buf, dest, source)\
index 6bb3634..e5dcaef 100644 (file)
@@ -68,20 +68,18 @@ char* get_status_str(int status_flag)
 
 void printf_subs(subs_t* subs)
 {      
-       DBG("\t[pres_uri]= %.*s - len: %d", 
-               subs->pres_uri.len,  subs->pres_uri.s, subs->pres_uri.len);
-       DBG("\n\t[to_user]= %.*s\t[to_domain]= %.*s\n\t[w_user]= %.*s"
-               "\t[w_domain]= %.*s",subs->to_user.len,subs->to_user.s, 
-               subs->to_domain.len,subs->to_domain.s,subs->from_user.len,
-               subs->from_user.s, subs->from_domain.len,subs->from_domain.s);
-       DBG("\n\t[event]= %.*s\n\t[status]= %s\n\t[expires]= %u",
-               subs->event->name.len, subs->event->name.s,     
-               get_status_str(subs->status), subs->expires );
-       DBG("\n\t[callid]= %.*s\t[local_cseq]=%d", subs->callid.len, subs->callid.s,
-                       subs->local_cseq); 
-       DBG("\n\t[to_tag]= %.*s\n\t[from_tag]= %.*s",subs->to_tag.len, 
-               subs->to_tag.s, subs->from_tag.len, subs->from_tag.s);
-       DBG("\n\t[contact]= %.*s\n",subs->contact.len, subs->contact.s);
+       LM_DBG("\n\t[pres_uri]= %.*s\n\t[to_user]= %.*s\t[to_domain]= %.*s"
+               "\n\t[w_user]= %.*s\t[w_domain]= %.*s\n\t[event]= %.*s\n\t[status]= %s"
+               "\n\t[expires]= %u\n\t[callid]= %.*s\t[local_cseq]=%d"
+               "\n\t[to_tag]= %.*s\t[from_tag]= %.*s""\n\t[contact]= %.*s"
+               "\t[record_route]= %.*s\n",subs->pres_uri.len,subs->pres_uri.s,
+               subs->to_user.len,subs->to_user.s,subs->to_domain.len,
+               subs->to_domain.s,subs->from_user.len,subs->from_user.s,
+               subs->from_domain.len,subs->from_domain.s,subs->event->name.len,
+               subs->event->name.s,get_status_str(subs->status),subs->expires,
+               subs->callid.len,subs->callid.s,subs->local_cseq,subs->to_tag.len,
+               subs->to_tag.s,subs->from_tag.len, subs->from_tag.s,subs->contact.len,
+               subs->contact.s,subs->record_route.len,subs->record_route.s);
 }
 str* create_winfo_xml(watcher_t* watchers, char* version,str resource, int STATE_FLAG );
 
@@ -97,7 +95,7 @@ int build_str_hdr(subs_t* subs, int is_body, str** hdr)
        str_hdr =(str*)pkg_malloc(sizeof(str));
        if(str_hdr== NULL)
        {
-               LOG(L_ERR, "PRESENCE: build_str_hdr:ERROR while allocating memory\n");
+               LM_ERR("while allocating memory\n");
                return -1;
        }
        memset(str_hdr, 0, sizeof(str));
@@ -105,7 +103,7 @@ int build_str_hdr(subs_t* subs, int is_body, str** hdr)
        str_hdr->s = (char*)pkg_malloc(ALLOC_SIZE* sizeof(char));
        if(str_hdr->s== NULL)
        {
-               LOG(L_ERR, "PRESENCE: build_str_hdr:ERROR while allocating memory\n");
+               LM_ERR("while allocating memory\n");
                pkg_free(str_hdr);
                return -1;
        }       
@@ -115,7 +113,7 @@ int build_str_hdr(subs_t* subs, int is_body, str** hdr)
        len= sprintf(str_hdr->s+str_hdr->len, "%d", MAX_FORWARD);
        if(len<= 0)
        {
-               LOG(L_ERR, "PRESENCE: build_str_hdr:ERROR while printing in string\n");
+               LM_ERR("while printing in string\n");
                pkg_free(str_hdr->s);
                pkg_free(str_hdr);
                return -1;
@@ -152,8 +150,7 @@ int build_str_hdr(subs_t* subs, int is_body, str** hdr)
        status= get_status_str(subs->status);
        if(status== NULL)
        {
-               LOG(L_ERR,"PRESENCE: build_str_hdr: ERROR bad status flag= %d\n",
-                               subs->status);
+               LM_ERR("bad status flag= %d\n", subs->status);
                pkg_free(str_hdr->s);
                pkg_free(str_hdr);
                return -1;
@@ -173,7 +170,7 @@ int build_str_hdr(subs_t* subs, int is_body, str** hdr)
        
        if(subs->status== TERMINATED_STATUS)
        {
-               DBG( "PRESENCE: build_str_hdr: state = terminated \n");
+               LM_DBG("state = terminated\n");
                
                strncpy(str_hdr->s+str_hdr->len,";reason=", 8);
                str_hdr->len+= 8;
@@ -191,15 +188,13 @@ int build_str_hdr(subs_t* subs, int is_body, str** hdr)
 
                if(subs_expires == NULL || len == 0)
                {
-                       LOG(L_ERR, "PRESENCE:built_str_hdr: ERROR while converting int "
-                                       " to str\n");
+                       LM_ERR("converting int to str\n");
                        pkg_free(str_hdr->s);
                        pkg_free(str_hdr);
                        return -1;
                }
 
-               DBG("PRESENCE:build_str_hdr: expires = %d\n", expires_t);
-               DBG("PRESENCE:build_str_hdr: subs_expires : %.*s\n", len , subs_expires);
+               LM_DBG("expires = %d\n", expires_t);
 
                strncpy(str_hdr->s+str_hdr->len,subs_expires ,len );
                str_hdr->len += len;
@@ -218,7 +213,7 @@ int build_str_hdr(subs_t* subs, int is_body, str** hdr)
        }
        if(str_hdr->len> ALLOC_SIZE)
        {
-               LOG(L_ERR, "PRESENCE:build_str_hdr:ERROR buffer size overflown\n");
+               LM_ERR("buffer size overflown\n");
                pkg_free(str_hdr->s);
                pkg_free(str_hdr);
                return -1;
@@ -268,28 +263,26 @@ int get_wi_subs_db(subs_t* subs, watcher_t** watchers)
        
        if (pa_dbf.use_table(pa_db, active_watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:get_wi_subs_db: Error in use_table\n");
+               LM_ERR("in use_table\n");
                goto error;
        }
 
        if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
                 result_cols, n_query_cols, n_result_cols, 0,  &result) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:get_wi_subs_db: Error while querying"
-                               " watchers\n");
+               LM_ERR("querying active_watchers db table\n");
                goto error;
        }
 
        if(result== NULL )
        {
-               LOG(L_ERR, "PRESENCE: get_wi_subs_db:The query returned no"
-                               " result\n");
                goto error;
        }
 
        if(result->n <= 0)
        {
-               DBG("PRESENCEget_wi_subs_db:The query in databse returned no result\n");
+               LM_DBG("The query in db table for active subscription"
+                               " returned no result\n");
                pa_dbf.free_result(pa_db, result);
                return 0;
        }
@@ -308,23 +301,21 @@ int get_wi_subs_db(subs_t* subs, watcher_t** watchers)
                w= (watcher_t*)pkg_malloc(sizeof(watcher_t));
                if(w== NULL)
                {
-                       ERR_MEM("PRESENCE","get_wi_subs_db");
+                       ERR_MEM(PKG_MEM_STR);
                }
                w->status= row_vals[status_col].val.int_val;
                if(uandd_to_uri(from_user, from_domain, &w->uri)<0)
                {
                        pkg_free(w);
-                       LOG(L_ERR, "PRESENCE:get_wi_subs_db:ERROR while creating"
-                               " uri\n");
+                       LM_ERR("creating uri\n");
                        goto error;
                }
                w->id.s = (char*)pkg_malloc(w->uri.len*2 +1);
                if(w->id.s== NULL)
                {
-                       LOG(L_ERR,"PRESENCE:get_wi_notify_body: ERROR no more pkg mem\n");
                        pkg_free(w->uri.s);
                        pkg_free(w);
-                       goto error;
+                       ERR_MEM(PKG_MEM_STR);
                }
 
                to64frombits((unsigned char *)w->id.s,
@@ -358,15 +349,14 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
        version_str = int2str(subs->version, &len);
        if(version_str ==NULL)
        {
-               LOG(L_ERR,"PRESENCE:get_wi_notify_body: ERROR while converting int"
-                               " to str\n ");
+               LM_ERR("converting int to str\n ");
                goto error;
        }
 
        watchers= (watcher_t*)pkg_malloc(sizeof(watcher_t));
        if(watchers== NULL)
        {
-               ERR_MEM("PRESENCE","get_wi_notify_body");
+               ERR_MEM(PKG_MEM_STR);
        }
        memset(watchers, 0, sizeof(watcher_t));
 
@@ -375,7 +365,7 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
                w= (watcher_t *)pkg_malloc(sizeof(watcher_t));
                if(w== NULL)
                {
-                       ERR_MEM("PRESENCE","get_wi_notify_body");
+                       ERR_MEM(PKG_MEM_STR);
                }
                memset(w, 0, sizeof(watcher_t));
 
@@ -393,7 +383,7 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
                {
                        pkg_free(w->uri.s);
                        pkg_free(w);
-                       ERR_MEM("PRESENCE","get_wi_notify_body");
+                       ERR_MEM(PKG_MEM_STR);
                }
                to64frombits((unsigned char *)w->id.s,
                                (const unsigned char*)w->uri.s, w->uri.len );
@@ -412,14 +402,12 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
        {
                if(get_wi_subs_db(subs, &watchers)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:get_wi_notify_body: ERROR getting watchers"
-                                       "from database\n");
+                       LM_ERR("getting watchers from database\n");
                        goto error;
                }
        }
 
        hash_code= core_hash(&subs->pres_uri, &subs->event->name, shtable_size);
-       DBG("PRESENCE:get_wi_notify_body:hash_code= %u\n", hash_code);
        lock_get(&subs_htable[hash_code].lock);
 
        s= subs_htable[hash_code].entries;
@@ -430,14 +418,13 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
 
                if(s->expires< (int)time(NULL))
                {       
-                       DBG("PRESENCE:get_wi_notify_body:expired record\n");
+                       LM_DBG("expired record\n");
                        continue;
                }
 
                if(fallback2db && s->db_flag!= INSERTDB_FLAG)
                {
-                       DBG("PRESENCE:get_wi_notify_body:record already taken"
-                                       " from database\n");
+                       LM_DBG("record already found in database\n");
                        continue;
                }
 
@@ -449,25 +436,23 @@ str* get_wi_notify_body(subs_t* subs, subs_t* watcher_subs)
                        if(w== NULL)
                        {
                                lock_release(&subs_htable[hash_code].lock);
-                               ERR_MEM("PRESENCE","get_wi_notify_body");
+                               ERR_MEM(PKG_MEM_STR);
                        }
                        w->status= s->status;
                        if(uandd_to_uri(s->from_user, s->from_domain, &w->uri)<0)
                        {
                                lock_release(&subs_htable[hash_code].lock);
                                pkg_free(w);
-                               LOG(L_ERR, "PRESENCE:get_wi_notify_body:ERROR while creating"
-                                       " uri\n");
+                               LM_ERR("creating uri\n");
                                goto error;
                        }
                        w->id.s = (char*)pkg_malloc(w->uri.len*2 +1);
                        if(w->id.s== NULL)
                        {
-                               LOG(L_ERR,"PRESENCE:get_wi_notify_body: ERROR no more pkg mem\n");
                                lock_release(&subs_htable[hash_code].lock);
                                pkg_free(w->uri.s);
                                pkg_free(w);
-                               goto error;
+                               ERR_MEM(PKG_MEM_STR);
                        }
 
                        to64frombits((unsigned char *)w->id.s,
@@ -490,8 +475,7 @@ done:
 
        if(notify_body== NULL)
        {
-               LOG(L_ERR, "PRESENCE: get_wi_notify_body: Error in function"
-                               " create_winfo_xml\n");
+               LM_ERR("in function create_winfo_xml\n");
                goto error;
        }
        while(watchers)
@@ -550,7 +534,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag)
 
        if(parse_uri(pres_uri.s, pres_uri.len, &uri)< 0)
        {
-               LOG(L_ERR, "PRESENCE: get_p_notify_body: ERROR while parsing uri\n");
+               LM_ERR("while parsing uri\n");
                return NULL;
        }
 
@@ -558,7 +542,7 @@ str* get_p_notify_body(str pres_uri, pres_ev_t* event, str* etag)
        hash_code= core_hash(&pres_uri, NULL, phtable_size);
        if(search_phtable(&pres_uri, event->evp->parsed, hash_code)== NULL)
        {
-               DBG("PRESENCE: get_p_notify_body: No record exists in hash_table\n");
+               LM_DBG("No record exists in hash_table\n");
                if(fallback2db)
                        goto db_query;
 
@@ -598,16 +582,14 @@ db_query:
 
        if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:get_p_notify_body: Error in use_table\n");
+               LM_ERR("in use_table\n");
                return NULL;
        }
 
-       DBG("PRESENCE:get_p_notify_body: querying presentity\n");
        if (pa_dbf.query (pa_db, query_cols, 0, query_vals,
                 result_cols, n_query_cols, n_result_cols, "received_time",  &result) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:get_p_notify_body: Error while querying"
-                               " presentity\n");
+               LM_ERR("querying presentity\n");
                if(result)
                        pa_dbf.free_result(pa_db, result);
                return NULL;
@@ -616,13 +598,11 @@ db_query:
        if(result== NULL)
                return NULL;
 
-
        if (result->n<=0 )
        {
-               DBG("PRESENCE: get_p_notify_body: The query returned no"
-                       " result\n[username]= %.*s\t[domain]= %.*s\t[event]= %.*s\n",
-                       uri.user.len,uri.user.s,uri.host.len,uri.host.s,
-                       event->name.len,event->name.s);
+               LM_DBG("The query returned no result\n[username]= %.*s"
+                       "\t[domain]= %.*s\t[event]= %.*s\n",uri.user.len, uri.user.s,
+                       uri.host.len, uri.host.s, event->name.len, event->name.s);
                
                pa_dbf.free_result(pa_db, result);
                result= NULL;
@@ -640,33 +620,31 @@ db_query:
                n= result->n;
                if(event->agg_nbody== NULL )
                {
-                       DBG("PRESENCE:get_p_notify_body: Event does not require aggregation\n");
+                       LM_DBG("Event does not require aggregation\n");
                        row = &result->rows[n-1];
                        row_vals = ROW_VALUES(row);
                        if(row_vals[body_col].val.string_val== NULL)
                        {
-                               LOG(L_ERR, "PRESENCE:get_p_notify_body:ERROR NULL notify body record\n");
+                               LM_ERR("NULL notify body record\n");
                                goto error;
                        }
                        len= strlen(row_vals[body_col].val.string_val);
                        if(len== 0)
                        {
-                               LOG(L_ERR, "PRESENCE:get_p_notify_body:ERROR Empty notify body record\n");
+                               LM_ERR("Empty notify body record\n");
                                goto error;
                        }
                        notify_body= (str*)pkg_malloc(sizeof(str));
                        if(notify_body== NULL)
                        {
-                               LOG(L_ERR, "PRESENCE:get_p_notify_body: ERROR while allocating memory\n");
-                               goto error;
+                               ERR_MEM(PKG_MEM_STR);   
                        }
                        memset(notify_body, 0, sizeof(str));
                        notify_body->s= (char*)pkg_malloc( len* sizeof(char));
                        if(notify_body->s== NULL)
                        {
-                               LOG(L_ERR, "PRESENCE:get_p_notify_body: ERROR while allocating memory\n");
                                pkg_free(notify_body);
-                               goto error;
+                               ERR_MEM(PKG_MEM_STR);
                        }
                        memcpy(notify_body->s, row_vals[body_col].val.string_val, len);
                        notify_body->len= len;
@@ -675,20 +653,20 @@ db_query:
                        return notify_body;
                }
                
-               DBG("PRESENCE:get_p_notify_body: Event requires aggregation\n");
+               LM_DBG("Event requires aggregation\n");
                
                body_array =(str**)pkg_malloc( (n+2) *sizeof(str*));
                if(body_array == NULL)
                {
-                       ERR_MEM("PRESENCE", "get_p_notify_body");
+                       ERR_MEM(PKG_MEM_STR);
                }
                memset(body_array, 0, (n+2) *sizeof(str*));
 
                if(etag!= NULL)
                {
-                       DBG("PRESENCE:get_p_notify_body:searched etag = %.*s len= %d\n", 
+                       LM_DBG("searched etag = %.*s len= %d\n", 
                                        etag->len, etag->s, etag->len);
-                       DBG( "PRESENCE:get_p_notify_body: etag not NULL\n");
+                       LM_DBG("etag not NULL\n");
                        for(i= 0; i< n; i++)
                        {
                                row = &result->rows[i];
@@ -696,18 +674,17 @@ db_query:
                                etags.s = (char*)row_vals[etag_col].val.string_val;
                                etags.len = strlen(etags.s);
 
-                               DBG("PRESENCE:get_p_notify_body:etag = %.*s len= %d\n", 
-                                               etags.len, etags.s, etags.len);
-                               if( (etags.len == etag->len) && (strncmp(etags.s, etag->s,
-                                                               etags.len)==0 ) )
+                               LM_DBG("etag = %.*s len= %d\n", etags.len, etags.s, etags.len);
+                               if( (etags.len == etag->len) && (strncmp(etags.s,
+                                                               etag->s,etags.len)==0 ) )
                                {
-                                       DBG("PRESENCE:get_p_notify_body found etag  \n");
+                                       LM_DBG("found etag\n");
                                        build_off_n= i;
                                }
                                len= strlen((char*)row_vals[body_col].val.string_val);
                                if(len== 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:get_p_notify_body:ERROR Empty notify body record\n");
+                                       LM_ERR("Empty notify body record\n");
                                        goto error;
                                }
                        
@@ -715,7 +692,7 @@ db_query:
                                body= (str*)pkg_malloc(size);
                                if(body== NULL)
                                {
-                                       ERR_MEM("PRESENCE", "get_p_notify_body");
+                                       ERR_MEM(PKG_MEM_STR);
                                }
                                memset(body, 0, size);
                                size= sizeof(str);
@@ -736,7 +713,7 @@ db_query:
                                len= strlen((char*)row_vals[body_col].val.string_val);
                                if(len== 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:get_p_notify_body:ERROR Empty notify body record\n");
+                                       LM_ERR("Empty notify body record\n");
                                        goto error;
                                }
                                
@@ -744,8 +721,7 @@ db_query:
                                body= (str*)pkg_malloc(size);
                                if(body== NULL)
                                {
-                                       LOG(L_ERR, "PRESENCE:get_p_notify_body: ERROR while allocating memory\n");
-                                       goto error;
+                                       ERR_MEM(PKG_MEM_STR);
                                }
                                memset(body, 0, size);
                                size= sizeof(str);
@@ -759,9 +735,6 @@ db_query:
                pa_dbf.free_result(pa_db, result);
                result= NULL;
                
-               DBG("PRESENCE: get_p_notify_body: [user]= %.*s\t[domain]= %.*s\n",
-                               uri.user.len, uri.user.s, uri.host.len, uri.host.s);
-
                notify_body = event->agg_nbody(&uri.user, &uri.host, body_array, n, build_off_n);
        }
 
@@ -821,8 +794,7 @@ dlg_t* build_dlg_t(subs_t* subs)
        td = (dlg_t*)pkg_malloc(sizeof(dlg_t));
        if(td == NULL)
        {
-               LOG(L_ERR, "PRESENCE:build_dlg_t: No memory left\n");
-               return NULL;
+               ERR_MEM(PKG_MEM_STR);
        }
        memset(td, 0, sizeof(dlg_t));
 
@@ -836,7 +808,7 @@ dlg_t* build_dlg_t(subs_t* subs)
        uandd_to_uri(subs->to_user, subs->to_domain, &td->loc_uri);
        if(td->loc_uri.s== NULL)
        {
-               LOG(L_ERR, "PRESENCE:build_dlg_t :ERROR while creating uri\n");
+               LM_ERR("while creating uri\n");
                goto error;
        }
 
@@ -846,14 +818,14 @@ dlg_t* build_dlg_t(subs_t* subs)
        }
        else
        {
-               DBG("CONTACT = %.*s\n", subs->contact.len , subs->contact.s);
+               LM_DBG("CONTACT = %.*s\n", subs->contact.len , subs->contact.s);
                td->rem_target = subs->contact;
        }
 
        uandd_to_uri(subs->from_user, subs->from_domain, &td->rem_uri);
        if(td->rem_uri.s ==NULL)
        {
-               LOG(L_ERR, "PRESENCE:build_dlg_t :ERROR while creating uri\n");
+               LM_ERR("while creating uri\n");
                goto error;
        }
        
@@ -866,7 +838,7 @@ dlg_t* build_dlg_t(subs_t* subs)
                if(parse_rr_body(subs->record_route.s, subs->record_route.len,
                        &td->route_set)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:build_dlg_t :ERROR in function parse_rr_body\n");
+                       LM_ERR("in function parse_rr_body\n");
                        goto error;
                }
        }       
@@ -878,7 +850,7 @@ dlg_t* build_dlg_t(subs_t* subs)
                if (parse_phostport (
                                subs->sockinfo_str.s,subs->sockinfo_str.len,&host.s,
                                &host.len,&port, &proto )) {
-                       LOG (L_ERR,"PRESENCE:build_dlg_t:bad sockinfo string\n");
+                       LM_ERR("bad sockinfo string\n");
                        goto error;
                }
                td->send_sock = grep_sock_info (
@@ -915,11 +887,11 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
 
        if (pa_dbf.use_table(pa_db, active_watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:get_subs_db: Error in use_table\n");
+               LM_ERR("in use_table\n");
                return -1;
        }
 
-       DBG("PRESENCE:get_subs_db:querying database table = active_watchers\n");
+       LM_DBG("querying database table = active_watchers\n");
        query_cols[n_query_cols] = "pres_uri";
        query_ops[n_query_cols] = OP_EQ;
        query_vals[n_query_cols].type = DB_STR;
@@ -943,8 +915,7 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
 
        if(sender)
        {       
-               DBG("PRESENCE:get_subs_db: Should not send Notify to: [uri]= %.*s\n",
-                                sender->len, sender->s);
+               LM_DBG("Do not send Notify to:[uri]= %.*s\n",sender->len,sender->s);
                query_cols[n_query_cols] = "contact";
                query_ops[n_query_cols] = OP_NEQ;
                query_vals[n_query_cols].type = DB_STR;
@@ -974,7 +945,7 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
        if (pa_dbf.query(pa_db, query_cols, query_ops, query_vals,result_cols,
                                n_query_cols, n_result_cols, 0, &result) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:get_subs_db:Error while querying database\n");
+               LM_ERR("while querying database\n");
                if(result)
                {
                        pa_dbf.free_result(pa_db, result);
@@ -987,13 +958,13 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
 
        if(result->n <=0 )
        {
-               DBG("PRESENCE: get_subs_db:The query for subscribtion for"
-                       " [uri]= %.*s for [event]= %.*s returned no result\n",
-                       pres_uri->len, pres_uri->s, event->name.len, event->name.s);
+               LM_DBG("The query for subscribtion for [uri]= %.*s for [event]= %.*s"
+                       " returned no result\n",pres_uri->len, pres_uri->s,
+                       event->name.len, event->name.s);
                pa_dbf.free_result(pa_db, result);
                return 0;
        }
-       DBG("PRESENCE: get_subs_db:found %d dialogs\n", result->n);
+       LM_DBG("found %d dialogs\n", result->n);
        
        for(i=0; i<result->n; i++)
        {
@@ -1055,8 +1026,7 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
                s_new= mem_copy_subs(&s, PKG_MEM_TYPE);
                if(s_new== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: get_subs_db: ERROR while copying subs_t"
-                                       " structure\n");
+                       LM_ERR("while copying subs_t structure\n");
                        goto error;
                }
                s_new->next= (*s_array);
@@ -1065,7 +1035,6 @@ int get_subs_db(str* pres_uri, pres_ev_t* event, str* sender,
                inc++;
                
        }
-       DBG("PRESENCE: get_subs_db: left function\n");
        pa_dbf.free_result(pa_db, result);
        *n= inc;
 
@@ -1084,7 +1053,7 @@ int update_in_list(subs_t* s, subs_t* s_array, int new_rec_no, int n)
        subs_t* ls;
 
        ls= s_array;
-       DBG("PRESENCE:update_in_list....n= %d\n", n);
+       
        while(i< new_rec_no)
        {
                i++;
@@ -1093,10 +1062,9 @@ int update_in_list(subs_t* s, subs_t* s_array, int new_rec_no, int n)
 
        for(i = 0; i< n; i++)
        {
-               DBG("\t%d subs from list\n", i);
                if(ls== NULL)
                {
-                       LOG(L_ERR, "PRESENCE:update_in_list: ERROR wrong records count\n");
+                       LM_ERR("wrong records count\n");
                        return -1;
                }
                printf_subs(ls);
@@ -1133,7 +1101,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender)
        {
                if(get_subs_db(pres_uri, event, sender, &s_array, &n)< 0)                       
                {
-                       LOG(L_ERR, "PRESENCE:get_subs_dialog: ERROR getting dialogs from database\n");
+                       LM_ERR("getting dialogs from database\n");
                        goto error;
                }
        }
@@ -1151,7 +1119,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender)
                
                if(s->expires< (int)time(NULL))
                {
-                       DBG("PRESENCE:get_subs_dialog: This one is expired\n");
+                       LM_DBG("expired subs\n");
                        continue;
                }
                
@@ -1166,17 +1134,16 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender)
                {
                        if(s->db_flag== NO_UPDATEDB_FLAG)
                        {
-                               DBG("PRESENCE:get_subs_dialog:s->db_flag==NO_UPDATEDB_FLAG\n");
+                               LM_DBG("s->db_flag==NO_UPDATEDB_FLAG\n");
                                continue;
                        }
                        
                        if(s->db_flag== UPDATEDB_FLAG)
                        {
-                               DBG("PRESENCE: get_subs_dialog:s->db_flag== UPDATEDB_FLAG\n");
+                               LM_DBG("s->db_flag== UPDATEDB_FLAG\n");
                                if(n>0 && update_in_list(s, s_array, i, n)< 0)
                                {
-                                       DBG("PRESENCE: get_subs_dialog: dialog not found in list"
-                                                       " fetched from database\n");
+                                       LM_DBG("dialog not found in list fetched from database\n");
                                        /* insert record */
                                }
                                else
@@ -1184,12 +1151,11 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender)
                        }
                }
                
-               DBG("PRESENCE:get_subs_dialog:s->db_flag= INSERTDB_FLAG\n");
+               LM_DBG("s->db_flag= INSERTDB_FLAG\n");
                s_new= mem_copy_subs(s, PKG_MEM_TYPE);
                if(s_new== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: get_subs_dialog: ERROR while copying"
-                                       " subs_t structure\n");
+                       LM_ERR("copying subs_t structure\n");
                        lock_release(&subs_htable[hash_code].lock);
                        goto error;
                }
@@ -1200,8 +1166,7 @@ subs_t* get_subs_dialog(str* pres_uri, pres_ev_t* event, str* sender)
        }
 
        lock_release(&subs_htable[hash_code].lock);
-       DBG("PRESENCE: get_subs_dialog: found %d dialogs( %d in database"
-               " and %d in hash_table)\n", n+i , n, i);
+       LM_DBG("found %d dialogs( %d in database and %d in hash_table)\n",n+i,n,i);
 
        return s_array;
 
@@ -1220,15 +1185,14 @@ int publ_notify(presentity_t* p, str* body, str* offline_etag, str* rules_doc)
 
        if(uandd_to_uri(p->user, p->domain, &pres_uri)< 0)
        {
-               LOG(L_ERR, "PRESENCE:publ_notify:ERROR while constructing uri"
-                               " from user and domain\n");
+               LM_ERR("constructing uri from user and domain\n");
                return -1;
        }
        
        subs_array= get_subs_dialog(&pres_uri, p->event , p->sender);
        if(subs_array == NULL)
        {
-               DBG("PRESENCE:publ_notify:Could not find subs_dialog\n");
+               LM_DBG("Could not find subs_dialog\n");
                ret_code= 0;
                goto done;
        }
@@ -1239,8 +1203,7 @@ int publ_notify(presentity_t* p, str* body, str* offline_etag, str* rules_doc)
                notify_body = get_p_notify_body(pres_uri, p->event , offline_etag);
                if(notify_body == NULL)
                {
-                       DBG( "PRESENCE:publ_notify: Could not get the"
-                                       " notify_body\n");
+                       LM_DBG("Could not get the notify_body\n");
                        /* goto error; */
                }
        }
@@ -1251,8 +1214,8 @@ int publ_notify(presentity_t* p, str* body, str* offline_etag, str* rules_doc)
                s->auth_rules_doc= rules_doc;
                if(notify(s, NULL, notify_body?notify_body:body, 0)< 0 )
                {
-                       LOG(L_ERR, "PRESENCE: publ_notify: Could not send notify for"
-                                       " %.*s\n", p->event->name.len, p->event->name.s);
+                       LM_ERR("Could not send notify for %.*s\n",
+                                       p->event->name.len, p->event->name.s);
                }
                s= s->next;
        }
@@ -1285,7 +1248,7 @@ int query_db_notify(str* pres_uri, pres_ev_t* event, subs_t* watcher_subs )
        subs_array= get_subs_dialog(pres_uri, event , NULL);
        if(subs_array == NULL)
        {
-               DBG("PRESENCE:query_db_notify:Could not get subscription dialog\n");
+               LM_DBG("Could not get subscription dialog\n");
                ret_code= 1;
                goto done;
        }
@@ -1295,7 +1258,7 @@ int query_db_notify(str* pres_uri, pres_ev_t* event, subs_t* watcher_subs )
                notify_body = get_p_notify_body(*pres_uri, event,NULL);
                if(notify_body == NULL)
                {
-                       DBG( "PRESENCE:query_db_notify:Could not get the notify_body\n");
+                       LM_DBG("Could not get the notify_body\n");
                        /* goto error; */
                }
        }       
@@ -1306,8 +1269,8 @@ int query_db_notify(str* pres_uri, pres_ev_t* event, subs_t* watcher_subs )
        {
                if(notify(s, watcher_subs, notify_body, 0)< 0 )
                {
-                       LOG(L_ERR, "PRESENCE:query_db_notify:Could not send notify for"
-                                       "%.*s\n", event->name.len, event->name.s);
+                       LM_ERR("Could not send notify for [event]=%.*s\n",
+                                       event->name.len, event->name.s);
                        goto done;
                }
                s= s->next;
@@ -1346,7 +1309,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
     c_back_param *cb_param= NULL;
        str* final_body= NULL;
        
-       DBG("PRESENCE:send_notify_request:dialog informations:\n");
+       LM_DBG("dialog info:\n");
        printf_subs(subs);
 
     /* getting the status of the subscription */
@@ -1364,8 +1327,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
                        if(subs->auth_rules_doc &&
                                subs->event->apply_auth_nbody(n_body, subs, &notify_body)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:send_notify_request: "
-                                               "ERROR in function apply_auth_nbody\n");
+                               LM_ERR("in function apply_auth_nbody\n");
                                goto error;
                        }
                        if(notify_body== NULL)
@@ -1379,8 +1341,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
                if(subs->status== TERMINATED_STATUS || 
                                subs->status== PENDING_STATUS) 
                {
-                       DBG("PRESENCE:send_notify_request: state terminated or pending-"
-                                       " notify body NULL\n");
+                       LM_DBG("state terminated or pending- notify body NULL\n");
                        notify_body = NULL;
                }
                else  
@@ -1390,8 +1351,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
                                notify_body = get_wi_notify_body(subs, watcher_subs);
                                if(notify_body == NULL)
                                {
-                                       DBG("PRESENCE:send_notify_request: Could not get the "
-                                                       "notify_body\n");
+                                       LM_DBG("Could not get notify_body\n");
                                        goto error;
                                }
                        }
@@ -1401,8 +1361,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
                                                subs->event, NULL);
                                if(notify_body == NULL || notify_body->s== NULL)
                                {
-                                       DBG("PRESENCE:send_notify_request: Could not get "
-                                                       "the notify_body\n");
+                                       LM_DBG("Could not get the notify_body\n");
                                }
                                else            /* apply authorization rules if exists */
                                if(subs->event->req_auth)
@@ -1411,8 +1370,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs,
                                        if(subs->auth_rules_doc && 
                                        subs->event->apply_auth_nbody(notify_body,subs,&final_body)<0)
                                        {
-                                               LOG(L_ERR, "PRESENCE:send_notify_request: ERROR in function"
-                                                               " apply_auth\n");
+                                               LM_ERR("in function apply_auth\n");
                                                goto error;
                                        }
                                        if(final_body)
@@ -1431,29 +1389,28 @@ jump_over_body:
        /* build extra headers */
        if( build_str_hdr( subs, notify_body?1:0, &str_hdr)< 0 )
        {
-               LOG(L_ERR, "PRESENCE:send_notify_request:ERROR while building headers \n");
+               LM_ERR("while building headers\n");
                goto error;
        }       
-       DBG("PRESENCE:send_notify_request: headers:\n%.*s\n", str_hdr->len, str_hdr->s);
+       LM_DBG("headers:\n%.*s\n", str_hdr->len, str_hdr->s);
 
        /* construct the dlg_t structure */
        td = build_dlg_t(subs);
        if(td ==NULL)
        {
-               LOG(L_ERR, "PRESENCE:send_notify_request:ERROR while building dlg_t structure \n");
+               LM_ERR("while building dlg_t structure\n");
                goto error;     
        }
 
        if(subs->event->type == WINFO_TYPE && watcher_subs )
        {
-               DBG("PRESENCE: :send_notify_requestSend notify for presence on callback\n");
+               LM_DBG("Send notify for presence on callback\n");
                watcher_subs->send_on_cback = 1;                        
        }
        cb_param = shm_dup_cbparam(watcher_subs, subs);
        if(cb_param == NULL)
        {
-               LOG(L_ERR, "PRESENCE:send_notify_request:ERROR while duplicating cb_param in"
-                       " share memory\n");
+               LM_ERR("while duplicating cb_param in share memory\n");
                goto error;     
        }       
 
@@ -1467,7 +1424,7 @@ jump_over_body:
 
        if(result< 0)
        {
-               LOG(L_ERR, "PRESENCE:send_notify_request: ERROR in function tmb.t_request_within\n");
+               LM_ERR("in function tmb.t_request_within\n");
                free_cbparam(cb_param);
                goto error;     
        }
@@ -1533,18 +1490,16 @@ int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body)
                {
                        if(subs->db_flag!= INSERTDB_FLAG && fallback2db)
                        {
-                               DBG("PRESENCE:notify: record not found in subs htable\n");
+                               LM_DBG("record not found in subs htable\n");
                                if(update_subs_db(subs, LOCAL_TYPE)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:notify:ERROR updating subscription"
-                                                       " in database\n");
+                                       LM_ERR("updating subscription in database\n");
                                        return -1;
                                }
                        }
                        else
                        {
-                               LOG(L_ERR, "PRESENCE:notify:ERROR record not found"
-                                               " in subs htable\n");
+                               LM_ERR("record not found in subs htable\n");
                                return -1;
                        }
                }
@@ -1552,7 +1507,7 @@ int notify(subs_t* subs, subs_t * watcher_subs,str* n_body,int force_null_body)
 
        if(send_notify_request(subs, watcher_subs, n_body, force_null_body)< 0)
        {
-               LOG(L_ERR,"PRESENCE:notify: ERROR send Notify not successful\n");
+               LM_ERR("sending Notify not successful\n");
                return -1;
        }
        return 0;       
@@ -1565,13 +1520,13 @@ void p_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
                        ((c_back_param*)(*ps->param))->ev_name.s== NULL ||
                        ((c_back_param*)(*ps->param))->to_tag.s== NULL)
        {
-               DBG("PRESENCE p_tm_callback: message id not received\n");
+               LM_DBG("message id not received\n");
                if(*ps->param !=NULL  )
                        free_cbparam((c_back_param*)(*ps->param));
                return;
        }
        
-       DBG( "PRESENCE:p_tm_callback:completed with status %d [to_tag:%.*s]\n",
+       LM_DBG("completed with status %d [to_tag:%.*s]\n",
                        ps->code,((c_back_param*)(*ps->param))->to_tag.len,
                        ((c_back_param*)(*ps->param))->to_tag.s);
 
@@ -1594,23 +1549,21 @@ void p_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
 
                if(ps->code >= 300)
                {
-                       if(notify( ((c_back_param*)(*ps->param))->wi_subs, NULL, NULL, 1)< 0)
+                       if(notify( ((c_back_param*)(*ps->param))->wi_subs, NULL,NULL,1)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscribtion: Could not send"
-                                       " notify for presence\n");
+                               LM_ERR("Could not send notify for presence\n");
                        }
                }
                else
                {
-                       if(notify( ((c_back_param*)(*ps->param))->wi_subs, NULL, NULL, 0)< 0)
+                       if(notify( ((c_back_param*)(*ps->param))->wi_subs, NULL,NULL,0)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscribtion: Could not send"
-                                       " notify for presence\n");
+                               LM_ERR("Could not send notify for presence\n");
                        }
                }       
        }
        else
-               DBG("PRESENCE:p_tm_callback: Empty wi_subs parameter\n");
+               LM_DBG("Empty wi_subs parameter\n");
 
 done:
        if(*ps->param !=NULL  )
@@ -1643,14 +1596,14 @@ c_back_param* shm_dup_cbparam(subs_t* w_subs, subs_t* subs)
        cb_param= (c_back_param*)shm_malloc(sizeof(c_back_param));
        if(cb_param== NULL)
        {
-               ERR_MEM("PRESENCE","shm_dup_cbparam");
+               ERR_MEM(SHM_MEM_STR);
        }
        memset(cb_param, 0, sizeof(c_back_param));
 
        cb_param->pres_uri.s= (char*)shm_malloc(subs->pres_uri.len* sizeof(char));
        if(cb_param->pres_uri.s== NULL)
        {
-               ERR_MEM("PRESENCE","shm_dup_cbparam");
+               ERR_MEM(SHM_MEM_STR);
        }
        memcpy(cb_param->pres_uri.s, subs->pres_uri.s, subs->pres_uri.len);
        cb_param->pres_uri.len= subs->pres_uri.len;
@@ -1659,7 +1612,7 @@ c_back_param* shm_dup_cbparam(subs_t* w_subs, subs_t* subs)
                        (subs->event->name.len* sizeof(char));
        if(cb_param->ev_name.s== NULL)
        {
-               ERR_MEM("PRESENCE","shm_dup_cbparam");
+               ERR_MEM(SHM_MEM_STR);
        }
        memcpy(cb_param->ev_name.s, subs->event->name.s,
                        subs->event->name.len);
@@ -1668,7 +1621,7 @@ c_back_param* shm_dup_cbparam(subs_t* w_subs, subs_t* subs)
        cb_param->to_tag.s= (char*)shm_malloc(subs->to_tag.len*sizeof(char));
        if(cb_param->to_tag.s== NULL)
        {
-               ERR_MEM("PRESENCE","shm_dup_cbparam");
+               ERR_MEM(SHM_MEM_STR);
        }
        memcpy(cb_param->to_tag.s, subs->to_tag.s ,subs->to_tag.len) ;
        cb_param->to_tag.len= subs->to_tag.len;
@@ -1678,8 +1631,7 @@ c_back_param* shm_dup_cbparam(subs_t* w_subs, subs_t* subs)
                cb_param->wi_subs= mem_copy_subs(w_subs, SHM_MEM_TYPE);
                if(cb_param->wi_subs== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: shm_dup_cbparam: ERROR while copying subs_t"
-                                       " structure\n");
+                       LM_ERR("copying subs_t structure in share memory\n");
                        goto error;
                }
        }
@@ -1717,8 +1669,7 @@ str* create_winfo_xml(watcher_t* watchers, char* version,
        {
                if( xmlNewProp(root_node, BAD_CAST "state", BAD_CAST "full") == NULL)
                {
-                       LOG(L_ERR, "PRESENCE: create_winfo_xml: ERROR while adding new"
-                                       "attribute\n");
+                       LM_ERR("while adding new attribute\n");
                        goto error;
                }
        }
@@ -1727,8 +1678,7 @@ str* create_winfo_xml(watcher_t* watchers, char* version,
                if( xmlNewProp(root_node, BAD_CAST "state", 
                                        BAD_CAST "partial")== NULL) 
                {
-                       LOG(L_ERR, "PRESENCE: create_winfo_xml: ERROR while adding new"
-                                       "attribute\n");
+                       LM_ERR("while adding new attribute\n");
                        goto error;
                }
        }
@@ -1736,13 +1686,13 @@ str* create_winfo_xml(watcher_t* watchers, char* version,
        w_list_node =xmlNewChild(root_node, NULL, BAD_CAST "watcher-list",NULL);
        if( w_list_node == NULL)
        {
-               LOG(L_ERR, "PRESENCE: create_winfo_xml: ERROR while adding child\n");
+               LM_ERR("while adding child\n");
                goto error;
        }
        res= (char*)pkg_malloc(sizeof(char)*(resource.len+ 1));
        if(res== NULL)
        {
-               ERR_MEM("PRESENCE","create_winfo_xml");
+               ERR_MEM(PKG_MEM_STR);
        }
        memcpy(res, resource.s, resource.len);
        res[resource.len]= '\0';
@@ -1761,29 +1711,25 @@ str* create_winfo_xml(watcher_t* watchers, char* version,
                                BAD_CAST content) ;
                if( node ==NULL)
                {
-                       LOG(L_ERR, "PRESENCE: create_winfo_xml: ERROR while adding"
-                                       " child\n");
+                       LM_ERR("while adding child\n");
                        goto error;
                }
                if(xmlNewProp(node, BAD_CAST "id", BAD_CAST w->id.s)== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: create_winfo_xml: ERROR while adding"
-                                       " new attribute\n");
+                       LM_ERR("while adding new attribute\n");
                        goto error;
                }       
                
                if(xmlNewProp(node, BAD_CAST "event", BAD_CAST "subscribe")== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: create_winfo_xml: ERROR while adding new"
-                                       " attribute\n");
+                       LM_ERR("while adding new attribute\n");
                        goto error;
                }       
                
                if(xmlNewProp(node, BAD_CAST "status", 
                                        BAD_CAST get_status_str(w->status) )== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: create_winfo_xml: ERROR while adding"
-                                       " new attribute\n");
+                       LM_ERR("while adding new attribute\n");
                        goto error;
                }
                w= w->next;
@@ -1791,7 +1737,7 @@ str* create_winfo_xml(watcher_t* watchers, char* version,
     body = (str*)pkg_malloc(sizeof(str));
        if(body == NULL)
        {
-               ERR_MEM("PRESENCE","create_winfo_xml"); 
+               ERR_MEM(PKG_MEM_STR);   
        }
        memset(body, 0, sizeof(str));
 
index 511adf7..ec00733 100644 (file)
@@ -170,17 +170,16 @@ static int mod_init(void)
        str _s;
        int ver = 0;
 
-       DBG("PRESENCE: initializing module ...\n");
+       LM_NOTICE("initializing module ...\n");
 
        if(db_url.s== NULL)
        {
                use_db= 0;
-               DBG("PRESENCE:mod_init: presence module used for library"
-                               " purpose only\n");
+               LM_DBG("presence module used for library purpose only\n");
                EvList= init_evlist();
                if(!EvList)
                {
-                       LOG(L_ERR,"PRESENCE:mod_init: ERROR while initializing event list\n");
+                       LM_ERR("unsuccessful initialize event list\n");
                        return -1;
                }
                return 0;
@@ -197,10 +196,7 @@ static int mod_init(void)
                max_expires = 3600;
 
        if(server_address.s== NULL)
-       {
-               DBG("PRESENCE:mod_init: server_address parameter not set in"
-                               " configuration file\n");
-       }
+               LM_DBG("server_address parameter not set in configuration file\n");
        
        if(server_address.s)
                server_address.len= strlen(server_address.s);
@@ -210,39 +206,39 @@ static int mod_init(void)
        /* load SL API */
        if(load_sl_api(&slb)==-1)
        {
-               LOG(L_ERR, "PRESENCE:mod_init:ERROR can't load sl functions\n");
+               LM_ERR("can't load sl functions\n");
                return -1;
        }
 
        /* load all TM stuff */
        if(load_tm_api(&tmb)==-1)
        {
-               LOG(L_ERR, "PRESENCE:mod_init:ERROR can't load tm functions\n");
+               LM_ERR("can't load tm functions\n");
                return -1;
        }
 
        db_url.len = db_url.s ? strlen(db_url.s) : 0;
-       DBG("presence:mod_init: db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len,
-                       db_url.s);
+       LM_DBG("db_url=%s/%d/%p\n", ZSW(db_url.s), db_url.len,db_url.s);
        
        /* binding to mysql module  */
        if (bind_dbmod(db_url.s, &pa_dbf))
        {
-               DBG("PRESENCE:mod_init: ERROR: Database module not found\n");
+               LM_ERR("Database module not found\n");
                return -1;
        }
        
 
-       if (!DB_CAPABILITY(pa_dbf, DB_CAP_ALL)) {
-               LOG(L_ERR,"PRESENCE:mod_init: ERROR Database module does not implement "
-                   "all functions needed by the module\n");
+       if (!DB_CAPABILITY(pa_dbf, DB_CAP_ALL))
+       {
+               LM_ERR("Database module does not implement all functions"
+                               " needed by presence module\n");
                return -1;
        }
 
        pa_db = pa_dbf.init(db_url.s);
        if (!pa_db)
        {
-               LOG(L_ERR,"PRESENCE:mod_init: Error while connecting database\n");
+               LM_ERR("connecting database\n");
                return -1;
        }
        // verify table version 
@@ -251,8 +247,8 @@ static int mod_init(void)
         ver =  table_version(&pa_dbf, pa_db, &_s);
        if(ver!=P_TABLE_VERSION)
        {
-               LOG(L_ERR,"PRESENCE:mod_init: Wrong version v%d for table <%s>,"
-                               " need v%d\n", ver, _s.s, P_TABLE_VERSION);
+               LM_ERR("Wrong version v%d for table <%s>, need v%d\n", 
+                               ver, _s.s, P_TABLE_VERSION);
                return -1;
        }
        
@@ -261,8 +257,8 @@ static int mod_init(void)
         ver =  table_version(&pa_dbf, pa_db, &_s);
        if(ver!=ACTWATCH_TABLE_VERSION)
        {
-               LOG(L_ERR,"PRESENCE:mod_init: Wrong version v%d for table <%s>,"
-                               " need v%d\n", ver, _s.s, ACTWATCH_TABLE_VERSION);
+               LM_ERR("Wrong version v%d for table <%s>, need v%d\n", 
+                               ver, _s.s, ACTWATCH_TABLE_VERSION);
                return -1;
        }
 
@@ -271,21 +267,21 @@ static int mod_init(void)
         ver =  table_version(&pa_dbf, pa_db, &_s);
        if(ver!=S_TABLE_VERSION)
        {
-               LOG(L_ERR,"PRESENCE:mod_init: Wrong version v%d for table <%s>,"
-                               " need v%d\n", ver, _s.s, S_TABLE_VERSION);
+               LM_ERR("Wrong version v%d for table <%s>, need v%d\n",
+                               ver, _s.s, S_TABLE_VERSION);
                return -1;
        }
 
        EvList= init_evlist();
        if(!EvList)
        {
-               LOG(L_ERR,"PRESENCE:mod_init: ERROR while initializing event list\n");
+               LM_ERR("initializing event list\n");
                return -1;
        }       
 
        if(clean_period<=0)
        {
-               DBG("PRESENCE: ERROR: mod_init: wrong clean_period \n");
+               LM_DBG("wrong clean_period \n");
                return -1;
        }
 
@@ -297,14 +293,12 @@ static int mod_init(void)
        subs_htable= new_shtable();
        if(subs_htable== NULL)
        {
-               LOG(L_ERR, "PRESENCE: ERROR: mod_init: ERROR while initializing"
-                               " subscribe hash table\n");
+               LM_ERR(" initializing subscribe hash table\n");
                return -1;
        }
        if(restore_db_subs()< 0)
        {
-               LOG(L_ERR, "PRESENCE: ERROR: mod_init: ERROR while "
-                               "restoring info from database\n");
+               LM_ERR("restoring subscribe info from database\n");
                return -1;
        }
 
@@ -316,14 +310,12 @@ static int mod_init(void)
        pres_htable= new_phtable();
        if(pres_htable== NULL)
        {
-               LOG(L_ERR, "PRESENCE: ERROR: mod_init: ERROR while initializing"
-                               "presentity hash table\n");
+               LM_ERR("initializing presentity hash table\n");
                return -1;
        }
        if(pres_htable_restore()< 0)
        {
-               LOG(L_ERR, "PRESENCE: ERROR: mod_init: ERROR filling in presentity"
-                               " hash table from database\n");
+               LM_ERR("filling in presentity hash table from database\n");
                return -1;
        }
        
@@ -347,7 +339,7 @@ static int mod_init(void)
  */
 static int child_init(int rank)
 {
-       DBG("PRESENCE: init_child [%d]  pid [%d]\n", rank, getpid());
+       LM_NOTICE("init_child [%d]  pid [%d]\n", rank, getpid());
        
        pid = my_pid();
        
@@ -356,35 +348,34 @@ static int child_init(int rank)
 
        if (pa_dbf.init==0)
        {
-               LOG(L_CRIT, "BUG: PRESENCE: child_init: database not bound\n");
+               LM_CRIT("child_init: database not bound\n");
                return -1;
        }
        pa_db = pa_dbf.init(db_url.s);
        if (!pa_db)
        {
-               LOG(L_ERR,"PRESENCE: child %d: Error while connecting database\n",
-                               rank);
+               LM_ERR("child %d: unsuccessful connecting to database\n", rank);
                return -1;
        }
                
        if (pa_dbf.use_table(pa_db, presentity_table) < 0)  
        {
-               LOG(L_ERR, "PRESENCE: child %d: Error in use_table presentity_table\n", rank);
+               LM_ERR( "child %d:unsuccessful use_table presentity_table\n", rank);
                return -1;
        }
        if (pa_dbf.use_table(pa_db, active_watchers_table) < 0)  
        {
-               LOG(L_ERR, "PRESENCE: child %d: Error in use_table active_watchers_table\n",
+               LM_ERR( "child %d:unsuccessful use_table active_watchers_table\n",
                                rank);
                return -1;
        }
        if (pa_dbf.use_table(pa_db, watchers_table) < 0)  
        {
-               LOG(L_ERR, "PRESENCE: child %d: Error in use_table watchers_table\n", rank);
+               LM_ERR( "child %d:unsuccessful use_table watchers_table\n", rank);
                return -1;
        }
 
-       DBG("PRESENCE: child %d: Database connection opened successfully\n", rank);
+       LM_DBG("child %d: Database connection opened successfully\n", rank);
        
        return 0;
 }
@@ -396,35 +387,33 @@ int mi_child_init(void)
 
        if (pa_dbf.init==0)
        {
-               LOG(L_CRIT,"PRESENCE:mi_child_init:ERROR database not bound\n");
+               LM_CRIT("database not bound\n");
                return -1;
        }
        pa_db = pa_dbf.init(db_url.s);
        if (!pa_db)
        {
-               LOG(L_ERR,"PRESENCE:mi_child_init:Error while connecting database\n");
+               LM_ERR("connecting database\n");
                return -1;
        }
        
        if (pa_dbf.use_table(pa_db, presentity_table) < 0)  
        {
-               LOG(L_ERR, "PRESENCE:mi_child_init: Error in use_table"
-                               " presentity_table\n");
+               LM_ERR( "unsuccessful use_table presentity_table\n");
                return -1;
        }
        if (pa_dbf.use_table(pa_db, active_watchers_table) < 0)  
        {
-               LOG(L_ERR, "PRESENCE:mi_child_init: Error in use_table"
-                               " active_watchers_table\n");
+               LM_ERR( "unsuccessful use_table active_watchers_table\n");
                return -1;
        }
        if (pa_dbf.use_table(pa_db, watchers_table) < 0)  
        {
-               LOG(L_ERR, "PRESENCE:mi_child_init: Error in use_table watchers_table\n");
+               LM_ERR( "unsuccessful use_table watchers_table\n");
                return -1;
        }
 
-       DBG("PRESENCE:mi_child_init: Database connection opened successfully\n");
+       LM_DBG("Database connection opened successfully\n");
        return 0;
 }
 
@@ -434,7 +423,7 @@ int mi_child_init(void)
  */
 void destroy(void)
 {
-       DBG("PRESENCE: destroy module ...\n");
+       LM_NOTICE("destroy module ...\n");
 
        if(subs_htable && pa_db)
                timer_db_update(0, 0);
@@ -458,15 +447,14 @@ static int fixup_presence(void** param, int param_no)
        {
                if(xl_parse_format((char*)(*param), &model, XL_DISABLE_COLORS)<0)
                {
-                       LOG(L_ERR, "PRESENCE:fixup_presence: ERROR wrong format[%s]\n",
-                               (char*)(*param));
+                       LM_ERR( "wrong format[%s]\n",(char*)(*param));
                        return E_UNSPEC;
                }
  
                *param = (void*)model;
                return 0;
        }
-       LOG(L_ERR, "PRESENCE:fixup_presence: ERROR null format\n");
+       LM_ERR( "null format\n");
        return E_UNSPEC;
 }
 
@@ -487,7 +475,7 @@ struct mi_root* mi_refreshWatchers(struct mi_root* cmd, void* param)
        str* rules_doc= NULL;
        int result;
 
-       DBG("PRESENCE:mi_refreshWatchers: start\n");
+       LM_DBG("start\n");
        
        node = cmd->node.kids;
        if(node == NULL)
@@ -497,7 +485,7 @@ struct mi_root* mi_refreshWatchers(struct mi_root* cmd, void* param)
        pres_uri = node->value;
        if(pres_uri.s == NULL || pres_uri.len== 0)
        {
-               LOG(L_ERR, "PRESENCE:mi_refreshWatchers: empty uri\n");
+               LM_ERR( "empty uri\n");
                return init_mi_tree(404, "Empty presentity URI", 20);
        }
        
@@ -507,42 +495,40 @@ struct mi_root* mi_refreshWatchers(struct mi_root* cmd, void* param)
        event= node->value;
        if(event.s== NULL || event.len== 0)
        {
-               LOG(L_ERR, "PRESENCE:mi_refreshWatchers: "
-                   "empty event parameter\n");
+               LM_ERR( "empty event parameter\n");
                return init_mi_tree(400, "Empty event parameter", 21);
        }
-       DBG("PRESENCE:mi_refreshWatchers: event '%.*s'\n",
-           event.len, event.s);
+       LM_DBG("event '%.*s'\n",  event.len, event.s);
        
        if(node->next!= NULL)
        {
-               LOG(L_ERR, "PRESENCE:mi_refreshWatchers: Too many parameters\n");
+               LM_ERR( "Too many parameters\n");
                return init_mi_tree(400, "Too many parameters", 19);
        }
 
        if(parse_uri(pres_uri.s, pres_uri.len, &uri)< 0)
        {
-               LOG(L_ERR, "PRESENCE:mi_refreshWatchers: ERROR parsing uri\n");
+               LM_ERR( "parsing uri\n");
                goto error;
        }
 
        ev= contains_event(&event, NULL);
        if(ev== NULL)
        {
-               LOG(L_ERR, "PRESENCE:mi_refreshWatchers: ERROR wrong event parameter\n");
+               LM_ERR( "wrong event parameter\n");
                return 0;
        }
        
        result= ev->get_rules_doc(&uri.user,&uri.host,&rules_doc);
        if(result< 0 || rules_doc==NULL || rules_doc->s== NULL)
        {
-               LOG(L_ERR, "PRESENCE:mi_refreshWatchers:ERROR getting rules doc\n");
+               LM_ERR( "getting rules doc\n");
                goto error;
        }
        
        if(update_watchers(pres_uri, ev, rules_doc)< 0)
        {
-               LOG(L_ERR, "PRESENCE:mi_refreshWatchers:ERROR updating watchers\n");
+               LM_ERR( "updating watchers\n");
                goto error;
        }
 
@@ -580,7 +566,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
                ev= contains_event(&ev->name, NULL);
                if(ev== NULL)
                {
-                       LOG(L_ERR,"PRESENCE:update_watchers:ERROR wrong event parameter\n");
+                       LM_ERR("wrong event parameter\n");
                        return 0;
                }
        }
@@ -619,14 +605,14 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
 
        if (pa_dbf.use_table(pa_db, watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:update_watchers: ERROR in use_table\n");
+               LM_ERR( "in use_table\n");
                goto error;
        }
 
        if(pa_dbf.query(pa_db, query_cols, 0, query_vals, result_cols,n_query_cols,
                                n_result_cols, 0, &result)< 0)
        {
-               LOG(L_ERR, "PRESENCE:update_watchers: ERROR in sql query\n");
+               LM_ERR( "in sql query\n");
                goto error;
        }
        if(result== NULL)
@@ -659,8 +645,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
                memset(&subs.reason, 0, sizeof(str));
                if(ev->get_auth_status(&subs)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:update_watchers: ERROR while getting status"
-                                       " from rules document\n");
+                       LM_ERR( "getting status from rules document\n");
                        lock_release(&subs_htable[hash_code].lock);
                        goto error;
                }
@@ -673,7 +658,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
                        update_vals[u_reason_col].val.str_val= subs.reason;
                        if (pa_dbf.use_table(pa_db, watchers_table) < 0) 
                        {
-                               LOG(L_ERR, "PRESENCE:update_watchers: ERROR in use_table\n");
+                               LM_ERR( "in use_table\n");
                                lock_release(&subs_htable[hash_code].lock);
                                goto error;
                        }
@@ -681,7 +666,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
                        if(pa_dbf.update(pa_db, query_cols, 0, query_vals, update_cols,
                                                update_vals, n_query_cols, n_update_cols)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_watchers: ERROR in sql update\n");
+                               LM_ERR( "in sql update\n");
                                lock_release(&subs_htable[hash_code].lock);
                                goto error;
                        }
@@ -689,10 +674,9 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
                        /* if status switches to terminated -> delete dialog */
                        if(update_pw_dialogs(&subs, hash_code, &subs_array)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_watchers: ERROR extracting dialogs"
-                                               "from [watcher]=%.*s@%.*s to [presentity]=%.*s\n",
-                                               w_user.len, w_user.s, w_domain.len, w_domain.s, 
-                                               pres_uri.len, pres_uri.s);
+                               LM_ERR( "extracting dialogs from [watcher]=%.*s@%.*s to"
+                                       " [presentity]=%.*s\n", w_user.len, w_user.s, w_domain.len,
+                                       w_domain.s, pres_uri.len, pres_uri.s);
                                lock_release(&subs_htable[hash_code].lock);
                                goto error;
                        }
@@ -708,8 +692,7 @@ int update_watchers(str pres_uri, pres_ev_t* ev, str* rules_doc)
        {
                if(notify(s, NULL, NULL, 0)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:update_watchers: ERROR sending"
-                                       " Notify request\n");
+                       LM_ERR( "sending Notify request\n");
                        goto error;
                }
                s= s->next;
@@ -753,8 +736,7 @@ int update_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs_array)
                        cs= mem_copy_subs(s, PKG_MEM_TYPE);
                        if(cs== NULL)
                        {
-                               LOG(L_ERR, "PRESENCE:update_dialogs:ERROR copying subs_t"
-                                               " stucture\n");
+                               LM_ERR( "copying subs_t stucture\n");
                                return -1;
                        }
                        cs->expires-= (int)time(NULL);
@@ -770,7 +752,7 @@ int update_pw_dialogs(subs_t* subs, unsigned int hash_code, subs_t** subs_array)
                }
                ps= ps->next;
        }
-       DBG("PRESENCE:update_dialogs:found %d matching dialogs\n", i);
+       LM_DBG("found %d matching dialogs\n", i);
 
        return 0;
 }
index 1a8deaf..90b248f 100644 (file)
@@ -52,34 +52,40 @@ extern db_func_t pa_dbf;
 static str pu_200_rpl  = str_init("OK");
 static str pu_412_rpl  = str_init("Conditional request failed");
 
+#define ETAG_LEN  128
+
 char* generate_ETag(int publ_count)
 {
-       char* etag;
+       char* etag= NULL;
        int size = 0;
-       etag = (char*)pkg_malloc(128*sizeof(char));
+
+       etag = (char*)pkg_malloc(ETAG_LEN*sizeof(char));
        if(etag ==NULL)
        {
-               LOG(L_ERR, "PRESENCE:generate_ETag:Error while allocating memory \n");
-               return NULL ;
+               ERR_MEM(PKG_MEM_STR);
        }
-       memset(etag, 0, 60*sizeof(char));
+       memset(etag, 0, ETAG_LEN*sizeof(char));
        size = sprintf (etag, "%c.%d.%d.%d.%d",prefix, startup_time, pid, counter, publ_count);
        if( size <0 )
        {
-               LOG(L_ERR, "PRESENCE: generate_ETag: ERROR unsuccessfull sprintf\n ");
+               LM_ERR("unsuccessfull sprintf\n ");
                pkg_free(etag);
                return NULL;
        }
-       if(size> 128)
+       if(size+ 1> ETAG_LEN)
        {
-               LOG(L_ERR, "PRESENCE: generate_ETag: ERROR buffer size overflown\n");
+               LM_ERR("buffer size overflown\n");
                pkg_free(etag);
                return NULL;
        }
 
        etag[size] = '\0';
-       DBG("PRESENCE: generate_ETag: etag= %s / %d\n ",etag, size);
+       LM_DBG("etag= %s / %d\n ",etag, size);
        return etag;
+
+error:
+       return NULL;
+
 }
 
 int publ_send200ok(struct sip_msg *msg, int lexpire, str etag)
@@ -88,10 +94,8 @@ int publ_send200ok(struct sip_msg *msg, int lexpire, str etag)
        int buf_len= 128, size;
        str hdr_append= {0, 0}, hdr_append2= {0, 0} ;
 
-       DBG("PRESENCE:publ_send200ok: send 200OK reply\n");     
-       DBG("PRESENCE:publ_send200ok: etag= %s - len= %d\n", etag.s, etag.len);
-       
-       /* ??? should we use static allocated buffer */
+       LM_DBG("send 200OK reply\n");   
+       LM_DBG("etag= %s - len= %d\n", etag.s, etag.len);
        
        hdr_append.s = buf;
        hdr_append.s[0]='\0';
@@ -99,19 +103,19 @@ int publ_send200ok(struct sip_msg *msg, int lexpire, str etag)
                        expires_offset);
        if(hdr_append.len < 0)
        {
-               LOG(L_ERR, "PRESENCE:publ_send200ok: ERROR unsuccessful sprintf\n");
+               LM_ERR("unsuccessful sprintf\n");
                goto error;
        }
        if(hdr_append.len > buf_len)
        {
-               LOG(L_ERR, "PRESENCE:publ_send200ok: ERROR buffer size overflown\n");
+               LM_ERR("buffer size overflown\n");
                goto error;
        }
        hdr_append.s[hdr_append.len]= '\0';
                
        if (add_lump_rpl( msg, hdr_append.s, hdr_append.len, LUMP_RPL_HDR)==0 )
        {
-               LOG(L_ERR,"PRESENCE: publ_send200ok:ERROR unable to add lump_rl\n");
+               LM_ERR("unable to add lump_rl\n");
                goto error;
        }
 
@@ -119,32 +123,31 @@ int publ_send200ok(struct sip_msg *msg, int lexpire, str etag)
        hdr_append2.s = (char *)pkg_malloc(size);
        if(hdr_append2.s == NULL)
        {
-               LOG(L_ERR,"PRESENCE:publ_send200ok:ERROR no more memory\n");
-               goto error;
+               ERR_MEM(PKG_MEM_STR);
        }
        hdr_append2.s[0]='\0';
        hdr_append2.len = sprintf(hdr_append2.s, "SIP-ETag: %s\r\n", etag.s);
        if(hdr_append2.len < 0)
        {
-               LOG(L_ERR, "PRESENCE:publ_send200ok:ERROR unsuccessful sprintf\n ");
+               LM_ERR("unsuccessful sprintf\n ");
                goto error;
        }
-       if(hdr_append2.len > size)
+       if(hdr_append2.len+1 > size)
        {
-               LOG(L_ERR, "PRESENCE:publ_send200ok: ERROR buffer size overflown\n");
+               LM_ERR("buffer size overflown\n");
                goto error;
        }
 
        hdr_append2.s[hdr_append2.len]= '\0';
        if (add_lump_rpl(msg, hdr_append2.s, hdr_append2.len, LUMP_RPL_HDR)==0 )
        {
-               LOG(L_ERR,"PRESENCE:publ_send200ok: unable to add lump_rl\n");
+               LM_ERR("unable to add lump_rl\n");
                goto error;
        }
 
        if( slb.reply( msg, 200, &pu_200_rpl)== -1)
        {
-               LOG(L_ERR,"PRESENCE: publ_send200ok: ERORR while sending reply\n");
+               LM_ERR("sending reply\n");
                goto error;
        }
 
@@ -162,7 +165,7 @@ error:
 presentity_t* new_presentity( str* domain,str* user,int expires, 
                pres_ev_t* event, str* etag, str* sender)
 {
-       presentity_t *presentity;
+       presentity_t *presentity= NULL;
        int size, init_len;
        
        /* allocating memory for presentity */
@@ -176,8 +179,7 @@ presentity_t* new_presentity( str* domain,str* user,int expires,
        presentity = (presentity_t*)pkg_malloc(size);
        if(presentity == NULL)
        {
-               LOG(L_ERR, "PRESENCE:new_presentity: No memory left: size=%d\n", size);
-               return NULL;
+               ERR_MEM(PKG_MEM_STR);
        }
        memset(presentity, 0, size);
        size= sizeof(presentity_t);
@@ -211,17 +213,18 @@ presentity_t* new_presentity( str* domain,str* user,int expires,
 
        if(size> init_len)
        {
-               LOG(L_ERR, "PRESENCE: new_presentity: ERROR"
-                       " buffer size overflow init_len= %d, size= %d\n", init_len, size);
-               pkg_free(presentity);
-               return NULL;
+               LM_ERR("buffer size overflow init_len= %d, size= %d\n", init_len, size);
+               goto error;
        }
-       DBG("PRESENCE: new_presentity:init_len= %d size= %d\n", init_len, size);
        presentity->event= event;
        presentity->expires = expires;
        presentity->received_time= (int)time(NULL);
        return presentity;
     
+error:
+       if(presentity)
+               pkg_free(presentity);
+       return NULL;
 }
 
 int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
@@ -244,7 +247,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                if(presentity->event->get_rules_doc(&presentity->user,
                                        &presentity->domain, &rules_doc))
                {
-                       LOG(L_ERR, "PRESENCE:update_presentity: ERROR getting rules doc\n");
+                       LM_ERR("getting rules doc\n");
                        goto error;
                }
        }
@@ -286,8 +289,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                if(insert_phtable(&msg->first_line.u.request.uri, 
                                        presentity->event->evp->parsed)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:update_presentity: ERROR inserting record"
-                                       " in hash table\n");
+                       LM_ERR("inserting record in hash table\n");
                        goto error;
                }
                
@@ -313,24 +315,21 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
 
                if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
                {
-                       LOG(L_ERR, "PRESENCE:update_presentity: Error in use_table\n");
+                       LM_ERR("unsuccessful use_table\n");
                        goto error;
                }
 
-               DBG( "PRESENCE:update_presentity: inserting %d cols into"
-                               " table\n",
-                               n_query_cols);
+               LM_DBG("inserting %d cols into table\n",n_query_cols);
                                
                if (pa_dbf.insert(pa_db, query_cols, query_vals, n_query_cols) < 0) 
                {
-                       LOG(L_ERR, "PRESENCE:update_presentity: Error while"
-                                       " inserting new presentity\n");
+                       LM_ERR("inserting new record in database\n");
                        goto error;
                }
                if( publ_send200ok(msg, presentity->expires, presentity->etag)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:update_presentity: ERROR while sending 200OK\n");
-                       return -1;
+                       LM_ERR("sending 200OK\n");
+                       goto error;
                }
                goto send_notify;
        }
@@ -338,16 +337,14 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
        {
                if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
                {
-                       LOG(L_ERR, "PRESENCE:update_presentity: Error in use_table\n");
+                       LM_ERR("unsuccessful sql use table\n");
                        goto error;
                }
 
-               DBG("PRESENCE:update_presentity: querying presentity  \n");
                if (pa_dbf.query (pa_db, query_cols, query_ops, query_vals,
                         result_cols, n_query_cols, 1, 0, &result) < 0) 
                {
-                       LOG(L_ERR, "PRESENCE:update_presentity: Error while querying"
-                                       " presentity\n");
+                       LM_ERR("unsuccessful sql query\n");
                        goto error;
                }
                if(result== NULL)
@@ -362,37 +359,36 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                        {
                                if( publ_send200ok(msg, presentity->expires, presentity->etag)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:update_presentity: ERROR while sending 200OK\n");
-                                       return -1;
+                                       LM_ERR("sending 200OK reply\n");
+                                       goto error;
                                }
                                if( publ_notify( presentity, body, &presentity->etag, rules_doc)< 0 )
                                {
-                                       LOG(L_ERR,"PRESENCE:update_presentity: ERROR while sending notify\n");
-                                       return -1;
+                                       LM_ERR("while sending notify\n");
+                                       goto error;
                                }
+                               
                                if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
                                {
-                                       LOG(L_ERR, "PRESENCE:update_presentity: Error in use_table\n");
+                                       LM_ERR("unsuccessful sql use table\n");
                                        goto error;
                                }
-                               DBG("PRESENCE:update_presentity: expires =0 -> deleting"
-                                       " from database\n");
-                               if(pa_dbf.delete(pa_db, query_cols, 0 ,query_vals,n_query_cols)< 0 )
+
+                               LM_DBG("expires =0 -> deleting from database\n");
+                               if(pa_dbf.delete(pa_db,query_cols,0,query_vals,n_query_cols)<0)
                                {
-                                       LOG(L_ERR,"PRESENCE:update_presentity:ERROR deleting"
-                                               " expired record from presentity database table\n");
+                                       LM_ERR("unsuccessful sql delete operation");
                                        goto error;
                                }
-                               DBG("PRESENCE:update_presentity:delete from db %.*s\n",
-                                       presentity->user.len,presentity->user.s );
+                               LM_DBG("deleted from db %.*s\n",        presentity->user.len,
+                                               presentity->user.s);
 
                                /* delete from hash table */
        
-                               if(delete_phtable(&msg->first_line.u.request.uri, 
-                                               presentity->event->evp->parsed)< 0)
+                               if(delete_phtable(&msg->first_line.u.request.uri,
+                                                       presentity->event->evp->parsed)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:update_presentity: ERROR deleting record"
-                                               " from hash table\n");
+                                       LM_ERR("deleting record from hash table\n");
                                        goto error;
                                }
                                return 1;
@@ -413,7 +409,7 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                                }
                                if(str_publ_nr.len== presentity->etag.len)
                                {
-                                       LOG(L_ERR, "PRESENCE:update_presentity: ERROR wrong etag\n");
+                                       LM_ERR("wrong etag\n");
                                        return -1;                      
                                }       
                                str_publ_nr.s= dot+1;
@@ -421,18 +417,16 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
        
                                if( str2int(&str_publ_nr, &publ_nr)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE: update_presentity: ERROR while converting string to int\n");
+                                       LM_ERR("converting string to int\n");
                                        goto error;
                                }
                                etag.s = generate_ETag(publ_nr+1);
                                if(etag.s == NULL)
                                {
-                                       LOG(L_ERR,"PRESENCE:update_presentity: ERROR while generating etag\n");
+                                       LM_ERR("while generating etag\n");
                                        return -1;
                                }
                                etag.len=(strlen(etag.s));
-                               DBG("PRESENCE:update_presentity: new etag  = %.*s \n", etag.len,
-                                       etag.s);
                                
                                cur_etag= etag;
 
@@ -449,13 +443,14 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                        update_keys[n_update_cols] = "expires";
                        update_vals[n_update_cols].type = DB_INT;
                        update_vals[n_update_cols].nul = 0;
-                       update_vals[n_update_cols].val.int_val = presentity->expires + (int)time(NULL);
+                       update_vals[n_update_cols].val.int_val= presentity->expires +
+                               (int)time(NULL);
                        n_update_cols++;
 
                        update_keys[n_update_cols] = "received_time";
                        update_vals[n_update_cols].type = DB_INT;
                        update_vals[n_update_cols].nul = 0;
-                       update_vals[n_update_cols].val.int_val = presentity->received_time;
+                       update_vals[n_update_cols].val.int_val= presentity->received_time;
                        n_update_cols++;
 
                        if(body && body->s)
@@ -463,23 +458,21 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                                update_keys[n_update_cols] = "body";
                                update_vals[n_update_cols].type = DB_BLOB;
                                update_vals[n_update_cols].nul = 0;
-                               update_vals[n_update_cols].val.str_val.s = body->s;
-                               update_vals[n_update_cols].val.str_val.len=body->len;
+                               update_vals[n_update_cols].val.str_val = *body;
                                n_update_cols++;
                        }
 
                        if( pa_dbf.update( pa_db,query_cols, query_ops, query_vals,
                        update_keys,update_vals, n_query_cols, n_update_cols )<0) 
                        {
-                               LOG( L_ERR , "PRESENCE:update_presentity: ERROR while"
-                                               " updating presence information\n");
+                               LM_ERR("updating published info in database\n");
                                goto error;
                        }
                        
                        /* send 200OK */
                        if( publ_send200ok(msg, presentity->expires, cur_etag)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_presentity: ERROR while sending 200OK\n");
+                               LM_ERR("sending 200OK reply\n");
                                if(etag.s)
                                        pkg_free(etag.s);
                                return -1;
@@ -497,11 +490,10 @@ int update_presentity(struct sip_msg* msg, presentity_t* presentity, str* body,
                {
                        pa_dbf.free_result(pa_db, result);
                        result= NULL;
-                       LOG(L_DBG, "PRESENCE:update_presentity: No E_Tag match\n");
+                       LM_ERR("No E_Tag match\n");
                        if (slb.reply(msg, 412, &pu_412_rpl) == -1)
                        {
-                               LOG(L_ERR, "PRESENCE:PRESENCE:update_presentity: ERROR while sending"
-                                       "reply\n");
+                               LM_ERR("sending '412 Conditional request failed' reply\n");
                                goto error;
                        }
                }
@@ -512,8 +504,8 @@ send_notify:
        /* send notify with presence information */
        if (publ_notify(presentity, body, NULL, rules_doc)<0)
        {
-               LOG(L_ERR,"PRESENCE:update_presentity: ERROR while sending notify\n");
-               return -1;
+               LM_ERR("while sending Notify requests to watchers\n");
+               goto error;
        }
 
        if(rules_doc)
@@ -526,7 +518,6 @@ send_notify:
        return 0;
 
 error:
-       LOG(L_ERR, "PRESENCE:update_presentity: ERROR occured\n");
        if(result)
                pa_dbf.free_result(pa_db, result);
        if(etag.s)
@@ -563,15 +554,14 @@ int pres_htable_restore(void)
 
        if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:update_presentity: Error in use_table\n");
+               LM_ERR("unsuccessful use table sql operation\n");
                goto error;
        }
 
        if (pa_dbf.query (pa_db, 0, 0, 0,result_cols,0, n_result_cols,
                                "username", &result) < 0)
        {
-               LOG(L_ERR, "PRESENCE:pres_htable_restore: Error while querying"
-                               " presentity\n");
+               LM_ERR("querying presentity\n");
                goto error;
        }
        if(result== NULL)
@@ -600,21 +590,20 @@ int pres_htable_restore(void)
        
                if(event_parser(ev_str.s, ev_str.len, &e)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:pres_htable_restore: ERROR parsing event\n");
+                       LM_ERR("parsing event\n");
                        goto error;
                }
                event= e.parsed;
 
                if(uandd_to_uri(user, domain, &uri)< 0)
                {
-                       LOG(L_ERR,"PRESENCE:pres_htable_restore:ERROR constructing uri\n");
+                       LM_ERR("constructing uri\n");
                        goto error;
                }
                /* insert in hash_table*/
                if(insert_phtable(&uri, event)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:pres_htable_restore: ERROR "
-                               "inserting record in presentity hash table");
+                       LM_ERR("inserting record in presentity hash table");
                        pkg_free(uri.s);
                        goto error;
                }
index 1952c67..5ea295d 100644 (file)
@@ -76,12 +76,11 @@ void msg_presentity_clean(unsigned int ticks,void *param)
 
        if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:msg_presentity_clean: Error in use_table\n");
+               LM_ERR("in use_table\n");
                return ;
        }
        
-       DBG("PRESENCE:msg_presentity_clean:cleaning expired presentity"
-                       " information\n");
+       LM_DBG("cleaning expired presentity information\n");
 
        db_keys[0] ="expires";
        db_ops[0] = OP_LT;
@@ -97,9 +96,7 @@ void msg_presentity_clean(unsigned int ticks,void *param)
        if(pa_dbf.query(pa_db, db_keys, db_ops, db_vals, result_cols,
                                                1, n_result_cols, "username", &result )< 0)
        {
-               LOG(L_ERR,
-                       "PRESENCE:msg_presentity_clean: ERROR while querying database"
-                       " for expired messages\n");
+               LM_ERR("querying database for expired messages\n");
                if(result)
                        pa_dbf.free_result(pa_db, result);
                return;
@@ -112,17 +109,14 @@ void msg_presentity_clean(unsigned int ticks,void *param)
                pa_dbf.free_result(pa_db, result);      
                return;
        }
-       DBG("PRESENCE:msg_presentity_clean: found n= %d expires messages\n ",
-                       result->n);
+       LM_DBG("found n= %d expires messages\n ",result->n);
 
        n= result->n;
        
        p= (presentity_t**)pkg_malloc(n* sizeof(presentity_t*));
        if(p== NULL)
        {
-               LOG(L_ERR, "PRESENCE:msg_presentity_clean:  ERROR while"
-                               " allocating memory\n");
-               goto error;
+               ERR_MEM(PKG_MEM_STR);   
        }
        memset(p, 0, n* sizeof(presentity_t*));
 
@@ -147,8 +141,7 @@ void msg_presentity_clean(unsigned int ticks,void *param)
                pres= (presentity_t*)pkg_malloc(size);
                if(pres== NULL)
                {
-                       LOG(L_ERR, "PRESENCE:msg_presentity_clean:  ERROR while allocating memory\n");
-                       goto error;
+                       ERR_MEM(PKG_MEM_STR);
                }
                memset(pres, 0, size);
                size= sizeof(presentity_t);
@@ -171,8 +164,7 @@ void msg_presentity_clean(unsigned int ticks,void *param)
                pres->event= contains_event(&event, &e);
                if(pres->event== NULL)
                {
-                       LOG(L_ERR, "PRESENCE:msg_presentity_clean: ERROR while searching"
-                                       " for event\n");
+                       LM_ERR("event not found\n");
                        goto error;
                }       
                p[i]= pres;
@@ -180,14 +172,13 @@ void msg_presentity_clean(unsigned int ticks,void *param)
                /* delete from hash table */
                if(uandd_to_uri(user, domain, &pres_uri)< 0)
                {
-                       LOG(L_ERR,"PRESENCE:pres_htable_restore:ERROR constructing uri\n");
+                       LM_ERR("constructing uri\n");
                        goto error;
                }
 
                if(delete_phtable(&pres_uri, e.parsed)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:msg_presentity_clean:  ERROR"
-                                       " deleting from pres hash table\n");
+                       LM_ERR("deleting from pres hash table\n");
                        pkg_free(pres_uri.s);
                        goto error;
                }
@@ -199,20 +190,20 @@ void msg_presentity_clean(unsigned int ticks,void *param)
        
        for(i= 0; i<n ; i++)
        {
+               LM_DBG("found expired publish for [user]=%.*s  [domanin]=%.*s\n",
+                       p[i]->user.len,p[i]->user.s, p[i]->domain.len, p[i]->domain.s);
+               
                rules_doc= NULL;
-               DBG( "PRESENCE:msg_presentity_clean:found expired publish"
-                               " for [user]=%.*s  [domanin]=%.*s\n",p[i]->user.len,p[i]->user.s,
-                               p[i]->domain.len, p[i]->domain.s);
                
                if(p[i]->event->get_rules_doc && 
                p[i]->event->get_rules_doc(&p[i]->user, &p[i]->domain, &rules_doc)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:msg_presentity_clean:ERROR getting rules doc\n");
+                       LM_ERR("getting rules doc\n");
                        goto error;
                }
                if(publ_notify( p[i], NULL, &p[i]->etag, rules_doc)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:msg_presentity_clean: ERROR while sending Notify\n");
+                       LM_ERR("sending Notify request\n");
                        goto error;
                }
                if(rules_doc)
@@ -226,13 +217,12 @@ void msg_presentity_clean(unsigned int ticks,void *param)
 
        if (pa_dbf.use_table(pa_db, presentity_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:msg_presentity_clean: Error in use_table\n");
+               LM_ERR("in use_table\n");
                goto error;
        }
        
        if (pa_dbf.delete(pa_db, db_keys, db_ops, db_vals, 1) < 0) 
-               LOG(L_ERR,"PRESENCE:msg_presentity_clean: ERROR cleaning expired"
-                               " messages\n");
+               LM_ERR("cleaning expired messages\n");
        
        for(i= 0; i< n; i++)
        {
@@ -280,7 +270,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        struct hdr_field* hdr;
        int found= 0, etag_gen = 0;
        str etag={0, 0};
-       int error_ret = -1; /* error return code */
+       int error_ret = -1; 
        str* sender= NULL;
        static char buf[256];
        int buf_len= 255;
@@ -292,10 +282,9 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        counter++;
        if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
        {
-               LOG(L_ERR, "PRESENCE:handle_publish:ERROR parsing headers\n");
+               LM_ERR("parsing headers\n");
                if (slb.reply(msg, 400, &pu_400a_rpl) == -1)
-                       LOG(L_ERR, "PRESENCE: handle_publish: Error while sending"
-                                               " reply\n");
+                       LM_ERR("Error while sending 400 reply\n");
                else
                        error_ret = 0;
                return error_ret;
@@ -308,8 +297,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        {
                if (!msg->event->parsed && (parse_event(msg->event) < 0))
                {
-                       LOG(L_ERR,
-                               "PRESENCE:handle_publish:ERROR cannot parse Event header\n");
+                       LM_ERR("cannot parse Event header\n");
                        goto error;
                }
                if(((event_t*)msg->event->parsed)->parsed & EVENT_OTHER)
@@ -341,33 +329,29 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        }
        if(found==0 )
        {
-               DBG("PRESENCE:handle_publish: SIP-If-Match not found\n");
+               LM_DBG("SIP-If-Match header not found\n");
                etag.s = generate_ETag(0);
                if(etag.s == NULL)
                {
-                       LOG(L_ERR,
-                               "PRESENCE:handle_publish:ERROR while generating etag\n");
+                       LM_ERR("when generating etag\n");
                        return -1;
                }
                etag.len=(strlen(etag.s));
                etag_gen=1;
-               DBG("PRESENCE:handle_publish: new etag  = %.*s \n", etag.len,
-                               etag.s);
+               LM_DBG("new etag  = %.*s \n", etag.len, etag.s);
        }
        else
        {
-               DBG("PRESENCE:handle_publish: SIP-If-Match found\n");
+               LM_DBG("SIP-If-Match header found\n");
                etag.s = (char*)pkg_malloc((hdr->body.len+ 1)* sizeof(char));
                if(etag.s== NULL)
                {
-                       LOG(L_ERR, "PRESENCE:handle_publish: ERROR No more memory\n");
-                       goto error;
+                       ERR_MEM(PKG_MEM_STR);
                }
                memcpy(etag.s, hdr->body.s, hdr->body.len );
                etag.len = hdr->body.len;        
                etag.s[ etag.len] = '\0';
-               DBG("PRESENCE:handle_publish: existing etag  = %.*s \n", etag.len,
-                               etag.s);
+               LM_DBG("existing etag  = %.*s \n", etag.len, etag.s);
        }
 
        /* examine the expire header field */
@@ -375,19 +359,16 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        {
                if (!msg->expires->parsed && (parse_expires(msg->expires) < 0))
                {
-                       LOG(L_ERR,
-                               "PRESENCE: handle_publish: ERROR cannot parse Expires header\n");
+                       LM_ERR("cannot parse Expires header\n");
                        goto error;
                }
-               DBG("PRESENCE: handle_publish: 'expires' found\n");
                lexpire = ((exp_body_t*)msg->expires->parsed)->val;
-               DBG("PRESENCE: handle_publish: lexpire= %d\n", lexpire);
+               LM_DBG("Expires header found, value= %d\n", lexpire);
 
        }
        else 
        {
-               DBG("PRESENCE: handle_publish: 'expires' not found; default=%d\n",
-                               event->default_expires);
+               LM_DBG("'expires' not found; default=%d\n",     event->default_expires);
                lexpire = event->default_expires;
        }
        if(lexpire > max_expires)
@@ -397,7 +378,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        if( parse_uri(msg->first_line.u.request.uri.s, 
                                msg->first_line.u.request.uri.len, &pres_uri)< 0)
        {
-               LOG(L_ERR, "PRESENCE: handle_publish:error parsing Request URI\n");
+               LM_ERR("parsing Request URI\n");
                goto error;
        }
        pres_user= pres_uri.user;
@@ -405,8 +386,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
 
        if (!msg->content_length) 
        {
-               LOG(L_ERR,"PRESENCE: handle_publish: ERROR no Content-Length"
-                               " header found!\n");
+               LM_ERR("no Content-Length header found!\n");
                goto error;
        }       
 
@@ -416,11 +396,9 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
                body.s = NULL;
                if (etag_gen)
                {
-                       LOG(L_ERR,"PRESENCE:handle_publish:No E-Tag and no body found\n");
+                       LM_ERR("No E-Tag and no body found\n");
                        if (slb.reply(msg, 400, &pu_400b_rpl) == -1)
-                       {
-                               LOG(L_ERR, "PRESENCE:handle_publish:ERROR sending reply\n");
-                       }
+                               LM_ERR("sending 400 Invalid request reply\n");
                        else
                                error_ret = 0;
                        goto error;
@@ -431,7 +409,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
                body.s=get_body(msg);
                if (body.s== NULL) 
                {
-                       LOG(L_ERR,"PRESENCE: handle_publish: ERROR cannot extract body\n");
+                       LM_ERR("cannot extract body\n");
                        goto error;
                }
                body.len= get_content_length( msg );
@@ -442,20 +420,20 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
                sender=(str*)pkg_malloc(sizeof(str));
                if(sender== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: handle_publish: ERROR while allocating memery\n");
-                       goto error;
+                       ERR_MEM(PKG_MEM_STR);
                }       
                if(xl_printf(msg, (xl_elem_t*)sender_uri, buf, &buf_len)<0)
                {
-                       LOG(L_ERR, "PRESENCE: handle_publish:error - cannot print the format\n");
+                       LM_ERR("cannot print the format\n");
                        goto error;
                }
                if(parse_uri(buf, buf_len, &puri)!=0)
                {
-                       LOG(L_ERR, "PRESENCE: handle_publish: bad owner SIP address!\n");
+                       LM_ERR("bad owner SIP address!\n");
                        goto error;
-               } else {
-                       DBG("PRESENCE: handle_publish:using user id [%.*s]\n",buf_len,buf);
+               } else 
+               {
+                       LM_DBG("using user id [%.*s]\n",buf_len,buf);
                }
                sender->s= buf;
                sender->len= buf_len;
@@ -465,8 +443,7 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        {
                if(event->evs_publ_handl(msg)< 0)
                {
-                       LOG(L_ERR, "PRESENCE: handle_publish: ERROR in event specific"
-                                       " publish handling\n");
+                       LM_ERR("in event specific publish handling\n");
                        goto error;
                }
        }
@@ -477,15 +454,14 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        presentity= new_presentity(&pres_domain, &pres_user, lexpire, event, &etag, sender);
        if(presentity== NULL)
        {
-               LOG(L_ERR,"PRESENCE: handle_publish: ERORR creating presentity\n");
+               LM_ERR("creating presentity structure\n");
                goto error;
        }
 
        /* querry the database and update or insert */
        if(update_presentity(msg, presentity, &body, etag_gen) <0)
        {
-               LOG(L_ERR, "PRESENCE:handle_publish: ERROR occured while updating"
-                               " presentity\n");
+               LM_ERR("when updating presentity\n");
                goto error;
        }
 
@@ -499,7 +475,6 @@ int handle_publish(struct sip_msg* msg, char* sender_uri, char* str2)
        return 1;
 
 error:
-       LOG(L_ERR, "PRESENCE: handle_publish: ERROR occured\n");
        
        if(presentity)
                pkg_free(presentity);
@@ -512,12 +487,10 @@ error:
 
 unsupported_event:
        
-       LOG(L_ERR, "PRESENCE: handle_publish:Missing or unsupported event"
-                       " header field value\n");
+       LM_ERR("Missing or unsupported event header field value\n");
                
        if(msg->event && msg->event->body.s && msg->event->body.len>0)
-               LOG(L_ERR, "\tevent=[%.*s]\n", msg->event->body.len,
-                       msg->event->body.s);
+               LM_ERR("\tevent=[%.*s]\n", msg->event->body.len, msg->event->body.s);
        
        if(reply_bad_event(msg)< 0)
                return -1;
index 08be0f6..84c1f3f 100644 (file)
@@ -57,8 +57,7 @@ int send_202ok(struct sip_msg * msg, int lexpire, str *rtag, str* local_contact)
        hdr_append.s = (char *)pkg_malloc( sizeof(char)*(local_contact->len+ 128));
        if(hdr_append.s == NULL)
        {
-               LOG(L_ERR,"PRESENCE: send_202ok:ERROR no more pkg memory\n");
-               return -1;
+               ERR_MEM(PKG_MEM_STR);
        }
        hdr_append.len = sprintf(hdr_append.s, "Expires: %d\r\n", lexpire);     
        
@@ -75,13 +74,13 @@ int send_202ok(struct sip_msg * msg, int lexpire, str *rtag, str* local_contact)
        
        if (add_lump_rpl( msg, hdr_append.s, hdr_append.len, LUMP_RPL_HDR)==0 )
        {
-               LOG(L_ERR,"ERROR:send_202oky : unable to add lump_rl\n");
+               LM_ERR("unable to add lump_rl\n");
                goto error;
        }
 
        if( slb.reply_dlg( msg, 202, &su_200_rpl, rtag)== -1)
        {
-               LOG(L_ERR,"PRESENCE:send_202ok: ERORR while sending reply\n");
+               LM_ERR("sending reply\n");
                goto error;
        }
        
@@ -101,7 +100,7 @@ int send_200ok(struct sip_msg * msg, int lexpire, str *rtag, str* local_contact)
        hdr_append.s = (char *)pkg_malloc( sizeof(char)*(local_contact->len+ 128));
        if(hdr_append.s == NULL)
        {
-               LOG(L_ERR,"ERROR:send_200ok : unable to add lump_rl\n");
+               LM_ERR("unable to add lump_rl\n");
                return -1;
        }
        hdr_append.len = sprintf(hdr_append.s, "Expires: %d\r\n", lexpire);
@@ -118,13 +117,13 @@ int send_200ok(struct sip_msg * msg, int lexpire, str *rtag, str* local_contact)
 
        if (add_lump_rpl( msg, hdr_append.s, hdr_append.len, LUMP_RPL_HDR)==0 )
        {
-               LOG(L_ERR,"ERROR:send_200ok: unable to add lump_rl\n");
+               LM_ERR("unable to add lump_rl\n");
                goto error;
        }
 
        if( slb.reply_dlg( msg, 200, &su_200_rpl, rtag)== -1)
        {
-               LOG(L_ERR,"PRESENCE:send_200ok : ERORR while sending reply\n");
+               LM_ERR("sending 200OK reply\n");
                goto error;
        }
        
@@ -162,15 +161,14 @@ int delete_db_subs(str pres_uri, str ev_stored_name, str to_tag)
        
        if (pa_dbf.use_table(pa_db, active_watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE: delete_db_subs: ERROR in use_table\n");
+               LM_ERR("in use table sql operation\n");
                return -1;
        }
 
        if(pa_dbf.delete(pa_db, query_cols, 0, query_vals,
                                n_query_cols)< 0 )
        {
-               LOG(L_ERR,"PRESENCE: delete_db_subs: ERROR cleaning"
-                               " unsubscribed messages\n");
+               LM_ERR("cleaning unsubscribed messages\n");
                return -1;
        }
 
@@ -277,15 +275,14 @@ int update_subs_db(subs_t* subs, int type)
 
        if (pa_dbf.use_table(pa_db, active_watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:update_subs_db: ERROR in use_table\n");
+               LM_ERR("in use table sql operation\n"); 
                return -1;
        }
                
        if( pa_dbf.update( pa_db,query_cols, 0, query_vals,
                                update_keys, update_vals, n_query_cols,n_update_cols)<0) 
        {
-               LOG( L_ERR , "PRESENCE:update_subs_db:ERROR while updating"
-                               " presence information\n");
+               LM_ERR("updating presence information\n");
                return -1;
        }
        return 0;
@@ -295,21 +292,18 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                int to_tag_gen)
 {      
 
-       DBG("PRESENCE: update_subscription...\n");
        printf_subs(subs);      
        
        if( to_tag_gen ==0) /*if a SUBSCRIBE within a dialog */
        {
                if(subs->expires == 0)
                {
-                       DBG("PRESENCE:update_subscription: expires =0 ->"
-                                       " deleting record\n");
+                       LM_DBG("expires =0 -> deleting record\n");
                
                        if( delete_db_subs(subs->pres_uri, 
                                                subs->event->name, subs->to_tag)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscription: ERROR while deleting"
-                                               "subscription record from database\n");
+                               LM_ERR("deleting subscription record from database\n");
                                goto error;
                        }
                        /* delete record from hash table also */
@@ -321,8 +315,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                        {       
                                if( send_202ok(msg, subs->expires, rtag, &subs->local_contact) <0)
                                {
-                                       LOG(L_ERR, "PRESENCE:update_subscription:ERROR while"
-                                               " sending 202 OK\n");
+                                       LM_ERR("sending 202 OK\n");
                                        goto error;
                                }
                                
@@ -331,8 +324,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                                        if(query_db_notify(&subs->pres_uri,
                                                                subs->event->wipeer, NULL)< 0)
                                        {
-                                               LOG(L_ERR, "PRESENCE:update_subscription:Could not send"
-                                                       " notify for winfo\n");
+                                               LM_ERR("Could not send notify for winfo\n");
                                                goto error;
                                        }
                                }
@@ -342,8 +334,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                        {
                                if( send_200ok(msg, subs->expires, rtag, &subs->local_contact) <0)
                                {
-                                       LOG(L_ERR, "PRESENCE:update_subscription:ERROR while"
-                                               " sending 202 OK\n");
+                                       LM_ERR("sending 202 OK reply\n");
                                        goto error;
                                }
                        }
@@ -353,8 +344,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                        subs->reason.len= 7;
                        if(notify(subs, NULL, NULL, 0)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscription: Could not send"
-                               " notify \n");
+                               LM_ERR("Could not send notify \n");
                                goto error;
                        }
                        return 1;
@@ -367,15 +357,13 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                                /* update in database table */
                                if(update_subs_db(subs, REMOTE_TYPE)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:update_subscription: ERROR updating"
-                                                       "subscription in database table\n");
+                                       LM_ERR("updating subscription in database table\n");
                                        goto error;
                                }
                        }
                        else
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscription: ERROR updating"
-                                       "subscription record in hash table\n");
+                               LM_ERR("updating subscription record in hash table\n");
                                goto error;
                        }
                }
@@ -386,8 +374,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                {       
                        if(insert_shtable(subs)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscription: ERROR when inserting"
-                                               " new record in subs_htable\n");
+                               LM_ERR("inserting new record in subs_htable\n");
                                goto error;
                        }
                }
@@ -401,26 +388,23 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
        {       
                if( send_202ok(msg, subs->expires, rtag, &subs->local_contact) <0)
                {
-                       LOG(L_ERR, "PRESENCE:update_subscription:ERROR while"
-                                       " sending 202 OK\n");
+                       LM_ERR("sending 202 OK reply\n");
                        goto error;
                }
                
                if(subs->expires!= 0 && subs->event->wipeer)
                {       
-                       DBG("PRESENCE:update_subscription: send Notify with winfo\n");
+                       LM_DBG("send Notify with winfo\n");
                        if(query_db_notify(&subs->pres_uri, subs->event->wipeer, subs)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscription:Could not send"
-                                       " notify winfo\n");
+                               LM_ERR("Could not send notify winfo\n");
                                goto error;
                        }       
                        if(subs->send_on_cback== 0)
                        {       
                                if(notify(subs, NULL, NULL, 0)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:update_subscription: Could not send"
-                                       " notify\n");
+                                       LM_ERR("Could not send notify\n");
                                        goto error;
                                }
                        }
@@ -429,8 +413,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
                {
                        if(notify(subs, NULL, NULL, 0)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:update_subscription: Could not send"
-                               " notify\n");
+                               LM_ERR("Could not send notify\n");
                                goto error;
                        }
                }       
@@ -440,14 +423,12 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
        {
                if( send_200ok(msg, subs->expires, rtag, &subs->local_contact) <0)
                {
-                       LOG(L_ERR, "PRESENCE:update_subscription:ERROR while"
-                                       " sending 202 OK\n");
+                       LM_ERR("sending 202 OK reply\n");
                        goto error;
                }               
                if(notify(subs, NULL, NULL, 0 )< 0)
                {
-                       LOG(L_ERR, "PRESENCE:update_subscription: ERROR while"
-                               " sending notify\n");
+                       LM_ERR("sending notify request\n");
                        goto error;
                }
        }
@@ -455,7 +436,7 @@ int update_subscription(struct sip_msg* msg, subs_t* subs, str *rtag,
        
 error:
 
-       LOG(L_ERR, "PRESENCE:update_presentity: ERROR occured\n");
+       LM_ERR("occured\n");
        return -1;
 
 }
@@ -467,7 +448,7 @@ void msg_watchers_clean(unsigned int ticks,void *param)
        db_op_t  db_ops[3] ;
        db_res_t *result= NULL;
 
-       DBG("PRESENCE: msg_watchers_clean:cleaning pending subscriptions\n");
+       LM_DBG("cleaning pending subscriptions\n");
        
        db_keys[0] ="inserted_time";
        db_ops[0] = OP_LT;
@@ -484,14 +465,13 @@ void msg_watchers_clean(unsigned int ticks,void *param)
        result_cols[0]= "id";
        if (pa_dbf.use_table(pa_db, watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:msg_watchers_clean: ERROR in use_table\n");
+               LM_ERR("unsuccessful use table sql operation\n");
                return ;
        }
        
        if(pa_dbf.query(pa_db, db_keys, db_ops, db_vals, result_cols, 2, 1, 0, &result )< 0)
        {
-               LOG(L_ERR, "PRESENCE:msg_watchers_clean: ERROR while querying database"
-                               " for expired messages\n");
+               LM_ERR("querying database for expired messages\n");
                if(result)
                        pa_dbf.free_result(pa_db, result);
                return;
@@ -506,8 +486,7 @@ void msg_watchers_clean(unsigned int ticks,void *param)
        pa_dbf.free_result(pa_db, result);
 
        if (pa_dbf.delete(pa_db, db_keys, db_ops, db_vals, 2) < 0) 
-               LOG(L_ERR,"PRESENCE:msg_watchers_clean: ERROR cleaning pending "
-                               " subscriptions\n");
+               LM_ERR("cleaning pending subscriptions\n");
 }
 
 int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
@@ -539,12 +518,11 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
 
        if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe:error parsing headers\n");
+               LM_ERR("parsing headers\n");
 
                if (slb.reply(msg, 400, &pu_400_rpl) == -1)
                {
-                       LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR while sending"
-                                       " 400 reply\n");
+                       LM_ERR("sending 400 reply\n");
                }
                error_ret = 0;
                goto error;
@@ -555,8 +533,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        {
                if (!msg->event->parsed && (parse_event(msg->event) < 0))
                {
-                       LOG(L_ERR,
-                               "PRESENCE: handle_subscribe: ERROR cannot parse Event header\n");
+                       LM_ERR("cannot parse Event header\n");
                        goto error;
                }
                if(((event_t*)msg->event->parsed)->parsed & EVENT_OTHER)
@@ -593,19 +570,16 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        {
                if (!msg->expires->parsed && (parse_expires(msg->expires) < 0))
                {
-                       LOG(L_ERR,
-                               "PRESENCE: handle_subscribe: ERROR cannot parse Expires header\n");
+                       LM_ERR("cannot parse Expires header\n");
                        goto error;
                }
-               DBG("PRESENCE: handle_subscribe: 'expires' found\n");
                lexpire = ((exp_body_t*)msg->expires->parsed)->val;
-               DBG("PRESENCE: handle_subscribe: lexpire= %d\n", lexpire);
+               LM_DBG("'Expires' header found, value= %d\n", lexpire);
 
        }
        else 
        {
-               DBG("PRESENCE: handle_subscribe: 'expires' not found; default=%d\n",
-                               event->default_expires);
+               LM_DBG("'expires' not found; default=%d\n",event->default_expires);
                lexpire = event->default_expires;
        }
        if(lexpire > max_expires)
@@ -615,23 +589,21 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
 
        if( msg->to==NULL || msg->to->body.s==NULL)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR cannot parse TO"
-                               " header\n");
+               LM_ERR("cannot parse TO header\n");
                goto error;
        }
        /* examine the to header */
        if(msg->to->parsed != NULL)
        {
                pto = (struct to_body*)msg->to->parsed;
-               DBG("PRESENCE: handle_subscribe: 'To' header ALREADY PARSED: <%.*s>\n",
-                               pto->uri.len, pto->uri.s );     
+               LM_DBG("'To' header ALREADY PARSED: <%.*s>\n",pto->uri.len,pto->uri.s);
        }
        else
        {
                memset( &TO , 0, sizeof(TO) );
                if( !parse_to(msg->to->body.s,msg->to->body.s + msg->to->body.len + 1, &TO));
                {
-                       DBG("PRESENCE: handle_subscribe: 'To' header NOT parsed\n");
+                       LM_DBG("'To' header NOT parsed\n");
                        goto error;
                }
                pto = &TO;
@@ -639,35 +611,32 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        
        if(parse_uri(pto->uri.s, pto->uri.len, &to_uri)!=0)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: bad R-URI!\n");
+               LM_ERR("bad R-URI!\n");
                goto error;
        }
 
        if(to_uri.user.len<=0 || to_uri.user.s==NULL || to_uri.host.len<=0 ||
                        to_uri.host.s==NULL)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: bad URI in To header!\n");
+               LM_ERR("bad URI in To header!\n");
                goto error;
        }
-       subs.to_user.s = to_uri.user.s;
-       subs.to_user.len = to_uri.user.len;
-
-       subs.to_domain.s = to_uri.host.s;
-       subs.to_domain.len = to_uri.host.len;
+       subs.to_user = to_uri.user;
+       subs.to_domain = to_uri.host;
        
        /* examine the from header */
        if (!msg->from || !msg->from->body.s)
        {
-               DBG("PRESENCE:handle_subscribe: ERROR cannot find 'from' header!\n");
+               LM_DBG("cannot find 'from' header!\n");
                goto error;
        }
        if (msg->from->parsed == NULL)
        {
-               DBG("PRESENCE:handle_subscribe: 'From' header not parsed\n");
+               LM_DBG("'From' header not parsed\n");
                /* parsing from header */
                if ( parse_from_header( msg )<0 ) 
                {
-                       DBG("PRESENCE:handle_subscribe: ERROR cannot parse From header\n");
+                       LM_DBG("cannot parse From header\n");
                        goto error;
                }
        }
@@ -675,27 +644,24 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
 
        if(parse_uri(pfrom->uri.s, pfrom->uri.len, &from_uri)!=0)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: bad R-URI!\n");
+               LM_ERR("bad R-URI!\n");
                goto error;
        }
 
        if(from_uri.user.len<=0 || from_uri.user.s==NULL || from_uri.host.len<=0 ||
                        from_uri.host.s==NULL)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: bad URI in To header!\n");
+               LM_ERR("bad URI in To header!\n");
                goto error;
        }
        
-       subs.from_user.s = from_uri.user.s;
-       subs.from_user.len = from_uri.user.len;
-
-       subs.from_domain.s = from_uri.host.s;
-       subs.from_domain.len = from_uri.host.len;
+       subs.from_user = from_uri.user;
+       subs.from_domain = from_uri.host;
 
        /*generate to_tag if the message does not have a to_tag*/
        if (pto->tag_value.s==NULL || pto->tag_value.len==0 )
        {  
-               DBG("PRESENCE:handle_subscribe: generating to_tag\n");
+               LM_DBG("generating to_tag\n");
                to_tag_gen = 1;
                /*generate to_tag then insert it in avp*/
                
@@ -704,8 +670,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
                                pid, (int)time(NULL), counter);
                if(rtag_value.len<= 0)
                {
-                       LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR while creating"
-                                       " to_tag\n");
+                       LM_ERR("while creating to_tag\n");
                        goto error;
                }
        }
@@ -717,34 +682,29 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
 
        if( msg->callid==NULL || msg->callid->body.s==NULL)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR cannot parse callid"
-                               " header\n");
+               LM_ERR("cannot parse callid header\n");
                goto error;
        }
-       subs.callid.s = msg->callid->body.s;
-       subs.callid.len = msg->callid->body.len;
+       subs.callid = msg->callid->body;
 
        if( msg->cseq==NULL || msg->cseq->body.s==NULL)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR cannot parse cseq"
-                               " header\n");
+               LM_ERR("cannot parse cseq header\n");
                goto error;
        }
        if (str2int( &(get_cseq(msg)->number), &subs.remote_cseq)!=0 )
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR cannot parse cseq"
-                               " number\n");
+               LM_ERR("cannot parse cseq number\n");
                goto error;
        }
        if( msg->contact==NULL || msg->contact->body.s==NULL)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR cannot parse contact"
-                               " header\n");
+               LM_ERR("cannot parse contact header\n");
                goto error;
        }
        if( parse_contact(msg->contact) <0 )
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR cannot parse contact"
+               LM_ERR(" cannot parse contact"
                                " header\n");
                goto error;
        }
@@ -752,15 +712,13 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
 
        if(b == NULL)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR cannot parse contact"
-                               " header\n");
+               LM_ERR("cannot parse contact header\n");
                goto error;
        }
-       subs.contact.s = b->contacts->uri.s;
-       subs.contact.len = b->contacts->uri.len;
+       subs.contact = b->contacts->uri;
 
-       DBG("PRESENCE: handle_subscribe: subs.contact= %.*s - len = %d\n",
-                       subs.contact.len, subs.contact.s, subs.contact.len);    
+       LM_DBG("subs.contact= %.*s - len = %d\n",subs.contact.len,
+                       subs.contact.s, subs.contact.len);      
 
        /*process record route and add it to a string*/
        if (msg->record_route!=NULL)
@@ -768,26 +726,22 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
                rt = print_rr_body(msg->record_route, &rec_route, 0, 0);
                if(rt != 0)
                {
-                       LOG(L_ERR,"PRESENCE:handle_subscribe:error processing the record"
-                                       " route [%d]\n", rt);   
+                       LM_ERR("processing the record route [%d]\n", rt);       
                        rec_route.s=NULL;
                        rec_route.len=0;
                //      goto error;
                }
        }
-       subs.record_route.s = rec_route.s;
-       subs.record_route.len = rec_route.len;
+       subs.record_route = rec_route;
                        
        subs.sockinfo_str= msg->rcv.bind_address->sock_str;
 
        if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0)
        {
-               LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR no from tag value"
-                               " present\n");
+               LM_ERR("no from tag value present\n");
                goto error;
        }
-       subs.from_tag.s = pfrom->tag_value.s;
-       subs.from_tag.len = pfrom->tag_value.len;
+       subs.from_tag = pfrom->tag_value;
 
        subs.version = 0;
        
@@ -796,8 +750,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
                contact= get_local_contact(msg);
                if(contact== NULL)
                {
-                       LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR in function"
-                                       " get_local_contact\n");
+                       LM_ERR("in function get_local_contact\n");
                        goto error;
                }
                subs.local_contact= *contact;
@@ -814,7 +767,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        {
                if(get_stored_info(msg, &subs, &error_ret )< 0)
                {
-                       LOG(L_ERR,"PRESENCE:handle_subscribe:ERROR getting stored info\n");
+                       LM_ERR("getting stored info\n");
                        goto error;
                }
                reason= subs.reason;
@@ -825,8 +778,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
        {
                if(event->evs_subs_handl(msg)< 0)
                {
-                       LOG(L_ERR, "PRESENCE: handle_subscribe: ERROR in event specific"
-                                       " subscription handling\n");
+                       LM_ERR("in event specific subscription handling\n");
                        goto error;
                }
        }       
@@ -850,8 +802,7 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
                        /* query in watchers_table */
                        if(get_db_subs_auth(&subs, &found)< 0)
                        {
-                               LOG(L_ERR, "PRESENCE:handle_subscribe: ERROR getting subscription"
-                                       "status from watchers table\n");
+                               LM_ERR("getting subscription status from watchers table\n");
                                goto error;
                        }
                        if(found== 0)
@@ -864,27 +815,25 @@ int handle_subscribe(struct sip_msg* msg, char* str1, char* str2)
                        
                                if(parse_uri(subs.pres_uri.s, subs.pres_uri.len, &uri)< 0)
                                {
-                                       LOG(L_ERR,"PRESENCE:handle_subscribe:ERROR parsing uri\n");
+                                       LM_ERR("parsing uri\n");
                                        goto error;
 
                                }
                                if(subs.event->get_rules_doc(&uri.user, &uri.host, &subs.auth_rules_doc)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:handle_subscribe:ERROR getting rules doc\n");
+                                       LM_ERR("getting rules doc\n");
                                        goto error;
                                }
                                
                                if(subs.event->get_auth_status(&subs)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:handle_subscribe: ERROR in event specific function"
-                                               " is_watcher_allowed\n");
+                                       LM_ERR("in event specific function is_watcher_allowed\n");
                                        goto error;
                                }
                                
                                if(insert_db_subs_auth(&subs)< 0)
                                {
-                                       LOG(L_ERR, "PRESENCE:handle_subscribe: ERROR while inserting record"
-                                                       " in watchers table\n");
+                                       LM_ERR("while inserting record in watchers table\n");
                                        goto error;
                                }
                        }
@@ -899,13 +848,13 @@ after_status:
        /* check if correct status */
        if(get_status_str(subs.status)== NULL)
        {
-               LOG(L_ERR, "PRESENCE:handle_subscribe: ERROR wrong status\n");
+               LM_ERR("wrong status\n");
                goto error;
        }
        
        if( update_subscription(msg, &subs, &rtag_value, to_tag_gen) <0 )
        {       
-               LOG(L_ERR,"PRESENCE:handle_subscribe: ERROR while updating database\n");
+               LM_ERR("in update_subscription\n");
                goto error;
        }
        if(subs.auth_rules_doc)
@@ -934,13 +883,10 @@ after_status:
 
 bad_event:
 
-       LOG(L_ERR, "PRESENCE: handle_subscribe:Missing or unsupported event"
-               " header field value");
+       LM_ERR("Missing or unsupported event header field value\n");
                
        if(parsed_event)
-               LOG(L_ERR," event= %.*s\n",parsed_event->text.len,parsed_event->text.s);
-       else
-               LOG(L_ERR,"\n");
+               LM_ERR("\tevent= %.*s\n",parsed_event->text.len,parsed_event->text.s);
        
        if(reply_bad_event(msg)< 0)
                goto error;
@@ -956,7 +902,7 @@ error:
        {
                if(subs.pres_uri.s)
                        pkg_free(subs.pres_uri.s);
-               }
+       }
        if(contact)
        {       
                if(contact->s)
@@ -985,14 +931,12 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
 
        *error_ret= -1;
 
-       DBG("PRESENCE:get_stored_info ...\n");
        /* first try to_user== pres_user and to_domain== pres_domain */
 
        uandd_to_uri(subs->to_user, subs->to_domain, &pres_uri);
        if(pres_uri.s== NULL)
        {
-               LOG(L_ERR, "PRESENCE: get_stored_info: ERROR when creating uri"
-                               " from user and domain\n");
+               LM_ERR("creating uri from user and domain\n");
                return -1;
        }
        hash_code= core_hash(&pres_uri, &subs->event->name, shtable_size);
@@ -1007,8 +951,7 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
 
        pkg_free(pres_uri.s);
        pres_uri.s= NULL;
-       DBG("PRESENCE: get_stored_info: record not found using R-URI"
-                       "-> search iteratively\n");
+       LM_DBG("record not found using R-URI search iteratively\n");
        /* take one row at a time */
        for(i= 0; i< shtable_size; i++)
        {
@@ -1020,7 +963,7 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
                        if(pres_uri.s== NULL)
                        {
                                lock_release(&subs_htable[i].lock);
-                               ERR_MEM("PRESENCE", "get_stored_info");
+                               ERR_MEM(PKG_MEM_STR);
                        }
                        memcpy(pres_uri.s, s->pres_uri.s, s->pres_uri.len);
                        pres_uri.len= s->pres_uri.len;
@@ -1034,12 +977,10 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
                return get_database_info(msg, subs, error_ret); 
        }
 
-       LOG(L_ERR, "PRESENCE: get_stored_info: ERROR Record not found"
-                       " in hash_table\n");
+       LM_ERR("record not found in hash_table\n");
        if (slb.reply(msg, 481, &pu_481_rpl) == -1)
        {
-               LOG(L_ERR, "PRESENCE: get_stored_info: ERROR while"
-                               " sending reply\n");
+               LM_ERR("sending '481 Subscription does not exist' reply\n");
                return -1;
        }
        *error_ret= 0;
@@ -1047,7 +988,7 @@ int get_stored_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
 
 found_rec:
        
-       DBG("PRESENCE: get_stored_info: Record found in hash_table\n");
+       LM_DBG("Record found in hash_table\n");
        subs->pres_uri= pres_uri;
        subs->status= s->status;
        if(s->reason.s && s->reason.len)
@@ -1056,7 +997,7 @@ found_rec:
                if(reason.s== NULL)
                {
                        lock_release(&subs_htable[i].lock);
-                       ERR_MEM("PRESENCE", "get_stored_info");
+                       ERR_MEM(PKG_MEM_STR);
                }
                memcpy(reason.s, s->reason.s, s->reason.len);
                reason.len= s->reason.len;
@@ -1067,14 +1008,14 @@ found_rec:
        
        if(subs->remote_cseq<= s->remote_cseq)
        {
-               LOG(L_ERR, "PRESENCE: get_stored_info: ERROR wrong sequence number"
-                       " received: %d -  stored: %d\n",subs->remote_cseq, s->remote_cseq);
+               LM_ERR("wrong sequence number;received: %d - stored: %d\n",
+                               subs->remote_cseq, s->remote_cseq);
                if (slb.reply(msg, 400, &pu_400_rpl) == -1)
                {
-                       LOG(L_ERR, "PRESENCE: get_stored_info: ERROR while"
-                                       " sending reply\n");
+                       LM_ERR("sending '400 Bad request' reply\n");
                }
-               *error_ret= 0;
+               else
+                       *error_ret= 0;
                lock_release(&subs_htable[i].lock);
                goto error;
        }       
@@ -1177,16 +1118,14 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
        
        if (pa_dbf.use_table(pa_db, active_watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE: get_database_info: ERROR in use_table\n");
+               LM_ERR("unsuccessful use_table sql operation\n");
                return -1;
        }
        
-       DBG("PRESENCE:get_database_info: querying database  \n");
        if (pa_dbf.query (pa_db, query_cols, 0, query_vals,
                 result_cols, n_query_cols, n_result_cols, 0,  &result) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:get_database_info: ERROR while querying"
-                               " subscription dialog\n");
+               LM_ERR("querying subscription dialog\n");
                if(result)
                        pa_dbf.free_result(pa_db, result);
                return -1;
@@ -1196,13 +1135,11 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
 
        if(result && result->n <=0)
        {
-               LOG(L_ERR, "PRESENCE:get_database_info:ERROR No matching subscription"
-                               " dialog found in database\n");
+               LM_ERR("No matching subscription dialog found in database\n");
                
                if (slb.reply(msg, 481, &pu_481_rpl) == -1)
                {
-                       LOG(L_ERR, "PRESENCE:get_database_info: ERROR while"
-                                       " sending reply\n");
+                       LM_ERR("sending '481 Subscription does not exist' reply\n");
                        pa_dbf.free_result(pa_db, result);
                        return -1;
                }
@@ -1217,15 +1154,15 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
        
        if(subs->remote_cseq<= remote_cseq)
        {
-               LOG(L_ERR, "PRESENCE:get_database_info: ERROR wrong sequence number"
-                               " received: %d -  stored: %d\n",subs->remote_cseq, remote_cseq);
+               LM_ERR("wrong sequence number received: %d - stored: %d\n",
+                               subs->remote_cseq, remote_cseq);
+
                if (slb.reply(msg, 400, &pu_400_rpl) == -1)
-               {
-                       LOG(L_ERR, "PRESENCE:get_database_info: ERROR while"
-                                       " sending reply\n");
-               }
+                       LM_ERR("sending '400 Bad request' reply\n");
+               else
+                       *error_ret= 0;
+
                pa_dbf.free_result(pa_db, result);
-               *error_ret= 0;
                return -1;
        }
        
@@ -1237,7 +1174,7 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
                subs->reason.s= (char*)pkg_malloc(reason.len* sizeof(char));
                if(subs->reason.s== NULL)
                {
-                       ERR_MEM("PRESENCE", "get_database_info");
+                       ERR_MEM(PKG_MEM_STR);
                }
                memcpy(subs->reason.s, reason.s, reason.len);
                subs->reason.len= reason.len;
@@ -1247,12 +1184,12 @@ int get_database_info(struct sip_msg* msg, subs_t* subs, int* error_ret)
        
        pres_uri.s= (char*)row_vals[pres_uri_col].val.string_val;
        pres_uri.len= strlen(pres_uri.s);
-       subs->pres_uri.s= (char*)pkg_malloc(pres_uri.len);
+       subs->pres_uri.s= (char*)pkg_malloc(pres_uri.len* sizeof(char));
        if(subs->pres_uri.s== NULL)
        {
                if(subs->reason.s)
                        pkg_free(subs->reason.s);
-               ERR_MEM("PRESENCE", "get_database_info");
+               ERR_MEM(PKG_MEM_STR);
        }
        memcpy(subs->pres_uri.s, pres_uri.s, pres_uri.len);
        subs->pres_uri.len= pres_uri.len;
@@ -1273,7 +1210,6 @@ error:
 int handle_expired_subs(subs_t* s, subs_t* prev_s)
 {
        /* send Notify with state=terminated;reason=timeout */
-       DBG("PRESENCE:handle_expired_subs ...\n");
        
        s->status= TERMINATED_STATUS;
        s->reason.s= "timeout";
@@ -1282,8 +1218,7 @@ int handle_expired_subs(subs_t* s, subs_t* prev_s)
 
        if(send_notify_request(s, NULL, NULL, 0)< 0)
        {
-               LOG(L_ERR, "PRESENCE:handle_expired_subs:"
-                               "ERROR send Notify not successful\n");
+               LM_ERR("send Notify not successful\n");
                return -1;
        }
        
@@ -1312,7 +1247,6 @@ void timer_db_update(unsigned int ticks,void *param)
        if(ticks== 0 && param == NULL)
                no_lock= 1;
 
-       DBG("PRESENCE: timer_db_update ...\n");
        query_cols[pres_uri_col= n_query_cols] ="pres_uri";
        query_vals[pres_uri_col].type = DB_STR;
        query_vals[pres_uri_col].nul = 0;
@@ -1450,12 +1384,12 @@ void timer_db_update(unsigned int ticks,void *param)
 
        if(pa_db== NULL)
        {
-               LOG(L_ERR,"RLS: timer_db_update:ERROR null database connection\n");
+               LM_ERR("null database connection\n");
                return;
        }
        if(pa_dbf.use_table(pa_db, active_watchers_table)< 0)
        {
-               LOG(L_ERR, "RLS: timer_db_update:ERROR in use table\n");
+               LM_ERR("in use table\n");
                return ;
        }
 
@@ -1472,13 +1406,12 @@ void timer_db_update(unsigned int ticks,void *param)
                        printf_subs(s);
                        if(s->expires < ((int)time(NULL)- 50))  
                        {
-                               DBG("PRESENCE:timer_db_update: Found expired record\n");
+                               LM_DBG("Found expired record\n");
                                if(!no_lock)
                                {
                                        if(handle_expired_subs(s, prev_s)< 0)
                                        {
-                                               LOG(L_ERR, "PRESENCE:timer_db_update: ERROR in function"
-                                                               " handle_expired_record\n");
+                                               LM_ERR("in function handle_expired_record\n");
                                                if(!no_lock)
                                                        lock_release(&subs_htable[i].lock);     
                                                return ;
@@ -1495,12 +1428,12 @@ void timer_db_update(unsigned int ticks,void *param)
                        {
                                case NO_UPDATEDB_FLAG:
                                {
-                                       DBG("PRESENCE:timer_db_update: NO_UPDATEDB_FLAG\n");
+                                       LM_DBG("NO_UPDATEDB_FLAG\n");
                                        break;                    
                                }
                                case UPDATEDB_FLAG:
                                {
-                                       DBG("PRESENCE:timer_db_update: UPDATEDB_FLAG\n");
+                                       LM_DBG("UPDATEDB_FLAG\n");
 
                                        query_vals[pres_uri_col].val.str_val= s->pres_uri;
                                        query_vals[callid_col].val.str_val= s->callid;
@@ -1517,8 +1450,7 @@ void timer_db_update(unsigned int ticks,void *param)
                                        if(pa_dbf.update(pa_db, query_cols, 0, query_vals, update_cols, 
                                                                update_vals, n_query_update, n_update_cols)< 0)
                                        {
-                                               LOG(L_ERR, "PRESENCE:timer_db_update: ERROR while updating"
-                                                               " in database\n");
+                                               LM_ERR("updating in database\n");
                                                if(!no_lock)
                                                        lock_release(&subs_htable[i].lock);     
                                                return ;
@@ -1527,7 +1459,7 @@ void timer_db_update(unsigned int ticks,void *param)
                                }
                                case  INSERTDB_FLAG:
                                {
-                                       DBG("PRESENCE:timer_db_update: INSERTDB_FLAG\n");
+                                       LM_DBG("INSERTDB_FLAG\n");
 
                                        query_vals[pres_uri_col].val.str_val= s->pres_uri;
                                        query_vals[callid_col].val.str_val= s->callid;
@@ -1552,7 +1484,7 @@ void timer_db_update(unsigned int ticks,void *param)
                                
                                        if(pa_dbf.insert(pa_db,query_cols,query_vals,n_query_cols )<0)
                                        {
-                                               LOG(L_ERR, "PRESENCE:timer_db_update: ERROR in sql insert\n");
+                                               LM_ERR("unsuccessful sql insert\n");
                                                if(!no_lock)
                                                        lock_release(&subs_htable[i].lock);
                                                return ;
@@ -1573,8 +1505,7 @@ void timer_db_update(unsigned int ticks,void *param)
        update_ops[0]= OP_LT;
        if(pa_dbf.delete(pa_db, update_cols, update_ops, update_vals, 1) < 0)
        {
-               LOG(L_ERR,"PRESENCE:timer_db_update: ERROR cleaning expired"
-                               " information\n");
+               LM_ERR("deleting expired information from database\n");
        }
 
 }
@@ -1620,18 +1551,18 @@ int restore_db_subs(void)
        
        if(!pa_db)
        {
-               LOG(L_ERR,"PRESENCE:restore_db_subs: ERROR null database connection\n");
+               LM_ERR("null database connection\n");
                return -1;
        }
        if(pa_dbf.use_table(pa_db, active_watchers_table)< 0)
        {
-               LOG(L_ERR, "PRESENCE:restore_db_subs:ERROR in use table\n");
+               LM_ERR("in use table\n");
                return -1;
        }
 
        if(pa_dbf.query(pa_db,0, 0, 0, result_cols,0, n_result_cols, 0,&res)< 0)
        {
-               LOG(L_ERR, "PRESENCE:restore_db_subs:ERROR while querrying table\n");
+               LM_ERR("while querrying table\n");
                if(res)
                {
                        pa_dbf.free_result(pa_db, res);
@@ -1644,13 +1575,13 @@ int restore_db_subs(void)
 
        if(res->n<=0)
        {
-               LOG(L_INFO, "PRESENCE:restore_db_subs:The query returned no result\n");
+               LM_INFO("The query returned no result\n");
                pa_dbf.free_result(pa_db, res);
                res = NULL;
                return 0;
        }
 
-       DBG("PRESENCE:restore_db_subs: found %d db entries\n", res->n);
+       LM_DBG("found %d db entries\n", res->n);
 
        for(i =0 ; i< res->n ; i++)
        {
@@ -1693,19 +1624,20 @@ int restore_db_subs(void)
                event= contains_event(&ev_sname, &parsed_event);
                if(event== NULL)
                {
-                       DBG("PRESENCE:restore_db_subs:insert a new event structure in the "
-                                       "list waiting to be filled in\n");
+                       LM_DBG("insert a new event structure in the list waiting"
+                                       " to be filled in\n");
+       
                        /*insert a new event structure in the list waiting to be filled in*/
                        event= (pres_ev_t*)shm_malloc(sizeof(pres_ev_t));
                        if(event== NULL)
                        {
-                               ERR_MEM("PRESENCE","restore_db_subs");
+                               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)
                        {
-                               ERR_MEM("PRESENCE","restore_db_subs");
+                               ERR_MEM(SHM_MEM_STR);
                        }
                        memcpy(event->name.s,ev_sname.s, ev_sname.len);
                        event->name.len= ev_sname.len;
@@ -1713,11 +1645,9 @@ int restore_db_subs(void)
                        event->evp= shm_copy_event(&parsed_event);
                        if(event->evp== NULL)
                        {
-                               LOG(L_ERR, "PRESENCE:restore_db_subs: ERROR copying event_t"
-                                               " structure\n");
+                               LM_ERR("ERROR copying event_t structure\n");
                                goto error;
                        }
-
                        event->next= EvList->events;
                        EvList->events= event;
                }
@@ -1753,8 +1683,7 @@ int restore_db_subs(void)
 
                if(insert_shtable(&s)< 0)
                {
-                       LOG(L_ERR, "PRESENCE:restore_db_subs: ERROR while" 
-                                       "adding new record in hash table\n");
+                       LM_ERR("adding new record in hash table\n");
                        goto error;
                }
        }
@@ -1764,8 +1693,7 @@ int restore_db_subs(void)
        /* delete all records */
        if(pa_dbf.delete(pa_db, 0,0,0,0)< 0)
        {
-               LOG(L_ERR, "PRESENCE:restore_db_subs:ERROR when deleting all records"
-                               " from rl_presentity table\n");
+               LM_ERR("deleting all records from database table\n");
                return -1;
        }
 
@@ -1791,14 +1719,13 @@ int refresh_watcher(str* pres_uri, str* watcher_uri, str* event,
        ev=     contains_event(event, NULL);
        if(ev== NULL)
        {
-               LOG(L_ERR, "PRESENCE:refresh_watcher: ERROR while searching"
-                               " event in list\n");
+               LM_ERR("while searching event in list\n");
                return -1;
        }
 
        if(parse_uri(watcher_uri->s, watcher_uri->len, &uri)< 0)
        {
-               LOG(L_ERR, "PRESENCE:refresh_watcher: ERROR parsing uri\n");
+               LM_ERR("parsing uri\n");
                return -1;
        }
        user= uri.user;
@@ -1825,14 +1752,14 @@ int refresh_watcher(str* pres_uri, str* watcher_uri, str* event,
                        s_copy= mem_copy_subs(s, PKG_MEM_TYPE);
                        if(s_copy== NULL)
                        {
-                               LOG(L_ERR,"PRESENCE:refresh_watcher:ERROR copying subs_t\n");
+                               LM_ERR("copying subs_t\n");
                                lock_release(&subs_htable[hash_code].lock);
                                return -1;
                        }
                        lock_release(&subs_htable[hash_code].lock);
                        if(notify(s_copy, NULL, NULL, 0)< 0)
                        {
-                               LOG(L_ERR,"PRESENCE:refresh_watcher:ERROR in notify function\n");
+                               LM_ERR("in notify function\n");
                                pkg_free(s_copy);
                                return -1;
                        }
@@ -1883,15 +1810,14 @@ int get_db_subs_auth(subs_t* subs, int* found)
 
        if(pa_dbf.use_table(pa_db, watchers_table)< 0)
        {
-               LOG(L_ERR,"PRESENCE:get_db_subs_status: ERROR in use table\n");
+               LM_ERR("in use table\n");
                return -1;
        }       
 
        if(pa_dbf.query(pa_db, db_keys, 0, db_vals, result_cols,
                                        n_query_cols, 2, 0, &result )< 0)
        {
-               LOG(L_ERR, "PRESENCE:get_db_subs_status:ERROR while querying"
-                               " watchers table\n");
+               LM_ERR("while querying watchers table\n");
                if(result)
                        pa_dbf.free_result(pa_db, result);
                return -1;
@@ -1923,7 +1849,7 @@ int get_db_subs_auth(subs_t* subs, int* found)
                        if(subs->reason.s== NULL)
                        {
                                pa_dbf.free_result(pa_db, result);
-                               ERR_MEM("PRESENCE","get_db_subs_status");
+                               ERR_MEM(PKG_MEM_STR);
                        }               
                        memcpy(subs->reason.s, row_vals[1].val.string_val, subs->reason.len);
                }
@@ -1988,13 +1914,13 @@ int insert_db_subs_auth(subs_t* subs)
        
        if (pa_dbf.use_table(pa_db, watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:insert_db_auth_subs: Error in use_table\n");
+               LM_ERR("in use_table\n");
                return -1;
        }
 
        if(pa_dbf.insert(pa_db, db_keys, db_vals, n_query_cols )< 0)
        {       
-               LOG(L_ERR, "PRESENCE:insert_db_auth_subs:ERROR in sql insert\n");
+               LM_ERR("in sql insert\n");
                return -1;
        }
 
@@ -2051,7 +1977,7 @@ int update_db_subs_auth(subs_t* subs)
 
        if (pa_dbf.use_table(pa_db, watchers_table) < 0) 
        {
-               LOG(L_ERR, "PRESENCE:update_db_subs_auth: Error in use_table\n");
+               LM_ERR("in use_table\n");
                return -1;
        }
 
@@ -2059,8 +1985,7 @@ int update_db_subs_auth(subs_t* subs)
        if(pa_dbf.update(pa_db, db_keys, 0, db_vals, 
                update_keys, update_vals, n_query_cols, n_update_cols)< 0)
        {
-               LOG(L_ERR, "PRESENCE:update_db_subs_auth: ERORR while"
-                               " updating database table\n");
+               LM_ERR("updating database table\n");
                return -1;
        }
        return 0;       
index 1453da2..219142c 100644 (file)
@@ -107,7 +107,7 @@ int reply_bad_event(struct sip_msg * msg)
        hdr_append.len = sprintf(hdr_append.s, "Allow-Events: ");
        if(hdr_append.len < 0)
        {
-               LOG(L_ERR, "PRESENCE:reply_bad_event: ERROR unsuccessful sprintf\n");
+               LM_ERR("unsuccessful sprintf\n");
                return -1;
        }
 
@@ -128,13 +128,13 @@ int reply_bad_event(struct sip_msg * msg)
                
        if (add_lump_rpl( msg, hdr_append.s, hdr_append.len, LUMP_RPL_HDR)==0 )
        {
-               LOG(L_ERR,"PRESENCE: reply_bad_event:ERROR unable to add lump_rl\n");
+               LM_ERR("unable to add lump_rl\n");
                return -1;
        }
 
        if (slb.reply(msg, 489, &pu_489_rpl) == -1)
        {
-               LOG(L_ERR, "PRESENCE: reply_bad_event: Error while sending reply\n");
+               LM_ERR("sending '489 Bad Event' reply\n");
                return -1;
        }
        return 0;
index 6a2bbc4..4db92ed 100644 (file)
@@ -51,7 +51,7 @@ static inline int uandd_to_uri(str user,  str domain, str *out)
        out->s = (char*)pkg_malloc(size*sizeof(char));
        if(out->s == NULL)
        {
-               LOG(L_ERR, "PRESENCE: uandd_to_uri: Error while allocating memory\n");
+               LM_ERR("no more memory\n");
                return -1;
        }
        out->len = 0;
@@ -65,7 +65,6 @@ static inline int uandd_to_uri(str user,  str domain, str *out)
        out->len += domain.len;
 
        out->s[out->len] = 0;
-       DBG("presence:uandd_to_uri: uri=%.*s\n", out->len, out->s);
        
        return 0;
 }
@@ -81,13 +80,13 @@ static inline str* get_local_contact(struct sip_msg* msg)
        contact= (str*)pkg_malloc(sizeof(str));
        if(contact== NULL)
        {
-               LOG(L_ERR, "PRESENCE: get_local_contact: ERROR No more memory\n");
+               LM_ERR("No more memory\n");
                return NULL;
        }
        contact->s= (char*)pkg_malloc(LCONTACT_BUF_SIZE* sizeof(char));
        if(contact->s== NULL)
        {
-               LOG(L_ERR, "PRESENCE: get_local_contact: ERROR No more memory\n");
+               LM_ERR("No more memory\n");
                pkg_free(contact);
                return NULL;
        }
@@ -105,7 +104,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
                proto= "tcp";
        else
        {
-               LOG(L_ERR, "PRESENCE: get_local_contact:ERROR unsupported proto\n");
+               LM_ERR("unsupported proto\n");
                pkg_free(contact->s);
                pkg_free(contact);
                return NULL;
@@ -114,7 +113,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
        ip.s= ip_addr2a(&msg->rcv.dst_ip);
        if(ip.s== NULL)
        {
-               LOG(L_ERR, "PRESENCE: get_local_contact:ERROR while transforming ip_addr to ascii\n");
+               LM_ERR("transforming ip_addr to ascii\n");
                pkg_free(contact->s);
                pkg_free(contact);
                return NULL;
@@ -131,7 +130,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
        contact->len += ip.len;
        if(contact->len> LCONTACT_BUF_SIZE - 21)
        {
-               LOG(L_ERR, "PRESENCE: get_local_contact: ERROR buffer overflow\n");
+               LM_ERR("buffer overflow\n");
                pkg_free(contact->s);
                pkg_free(contact);
                return NULL;
@@ -140,7 +139,7 @@ static inline str* get_local_contact(struct sip_msg* msg)
        len= sprintf(contact->s+contact->len, ":%d;transport=" , port);
        if(len< 0)
        {
-               LOG(L_ERR, "PRESENCE: get_local_contact: ERROR in function sprintf\n");
+               LM_ERR("unsuccessful sprintf\n");
                pkg_free(contact->s);
                pkg_free(contact);
                return NULL;