Browse code

pua: convert to PKG/SHM memory logging helper functions

* remove trailing spaces

Victor Seva authored on 29/07/2020 08:53:48
Showing 8 changed files
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 17
  *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  *
22 22
  */
... ...
@@ -35,7 +35,7 @@ extern int dlginfo_increase_version;
35 35
 int pua_add_events(void)
36 36
 {
37 37
 	/* add presence */
38
-	if(add_pua_event(PRESENCE_EVENT, "presence", "application/pidf+xml", 
38
+	if(add_pua_event(PRESENCE_EVENT, "presence", "application/pidf+xml",
39 39
 				pres_process_body)< 0)
40 40
 	{
41 41
 		LM_ERR("while adding event presence\n");
... ...
@@ -68,20 +68,20 @@ int pua_add_events(void)
68 68
 	}
69 69
 
70 70
 	/* add message-summary*/
71
-	if(add_pua_event(MSGSUM_EVENT, "message-summary", 
71
+	if(add_pua_event(MSGSUM_EVENT, "message-summary",
72 72
 				"application/simple-message-summary", mwi_process_body)< 0)
73 73
 	{
74 74
 		LM_ERR("while adding event message-summary\n");
75 75
 		return -1;
76 76
 	}
77
-	
77
+
78 78
 	/* add presence;winfo */
79 79
 	if(add_pua_event(PWINFO_EVENT, "presence.winfo", NULL, NULL)< 0)
80 80
 	{
81 81
 		LM_ERR("while adding event presence.winfo\n");
82 82
 		return -1;
83 83
 	}
84
-	
84
+
85 85
 	/* add application/reginfo+xml */
86 86
 	if (dlginfo_increase_version) {
87 87
 		if(add_pua_event(REGINFO_EVENT, "reg", "application/reginfo+xml", reginfo_process_body)< 0) {
... ...
@@ -94,7 +94,7 @@ int pua_add_events(void)
94 94
 			return -1;
95 95
 		}
96 96
 	}
97
-	
97
+
98 98
 	/* add xcap-diff */
99 99
 	if(add_pua_event(XCAPDIFF_EVENT, "xcap-diff",
100 100
 				"application/xcap-diff+xml", 0)< 0)
... ...
@@ -105,7 +105,7 @@ int pua_add_events(void)
105 105
 
106 106
 	return 0;
107 107
 
108
-}	
108
+}
109 109
 
110 110
 int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_param)
111 111
 {
... ...
@@ -142,19 +142,19 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
142 142
 		{
143 143
 			tuple_id= buf;
144 144
 			tuple_id_len= sprintf(tuple_id, "%p", publ);
145
-			tuple_id[tuple_id_len]= '\0'; 
145
+			tuple_id[tuple_id_len]= '\0';
146 146
 
147 147
 			tuple=(str*)pkg_malloc(sizeof(str));
148 148
 			if(tuple== NULL)
149 149
 			{
150
-				LM_ERR("No more memory\n");
150
+				PKG_MEM_ERROR;
151 151
 				goto error;
152 152
 			}
153 153
 			alloc_tuple = 1;
154 154
 			tuple->s= (char*)pkg_malloc(tuple_id_len* sizeof(char));
155 155
 			if(tuple->s== NULL)
156 156
 			{
157
-				LM_ERR("NO more memory\n");
157
+				PKG_MEM_ERROR;
158 158
 				goto error;
159 159
 			}
160 160
 			memcpy(tuple->s, tuple_id, tuple_id_len);
... ...
@@ -191,18 +191,18 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
191 191
 			xmlFree(tuple_id);
192 192
 			tuple_id= buf;
193 193
 			tuple_id_len= strlen(tuple_id);
194
-		
194
+
195 195
 			tuple=(str*)pkg_malloc(sizeof(str));
196 196
 			if(tuple== NULL)
197 197
 			{
198
-				LM_ERR("No more memory\n");
198
+				PKG_MEM_ERROR;
199 199
 				goto error;
200 200
 			}
201 201
 			alloc_tuple= 1;
202 202
 			tuple->s= (char*)pkg_malloc(tuple_id_len* sizeof(char));
203 203
 			if(tuple->s== NULL)
204 204
 			{
205
-				LM_ERR("NO more memory\n");
205
+				PKG_MEM_ERROR;
206 206
 				goto error;
207 207
 			}
208 208
 			memcpy(tuple->s, tuple_id, tuple_id_len);
... ...
@@ -217,7 +217,7 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
217 217
 		LM_DBG("found person node\n");
218 218
 		person_id= xmlNodeGetAttrContentByName(node, "id");
219 219
 		if(person_id== NULL)
220
-		{	
220
+		{
221 221
 			if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id))
222 222
 			{
223 223
 				LM_ERR("while extracting xml"
... ...
@@ -229,23 +229,23 @@ int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple_pa
229 229
 		{
230 230
 			xmlFree(person_id);
231 231
 		}
232
-	}	
232
+	}
233 233
 	body= (str*)pkg_malloc(sizeof(str));
234 234
 	if(body== NULL)
235 235
 	{
236
-		LM_ERR("NO more memory left\n");
236
+		PKG_MEM_ERROR;
237 237
 		goto error;
238 238
 	}
239 239
 	memset(body, 0, sizeof(str));
240
-	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, &body->len, 1);	
240
+	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, &body->len, 1);
241 241
 	if(body->s== NULL || body->len== 0)
242 242
 	{
243 243
 		LM_ERR("while dumping xml format\n");
244 244
 		goto error;
245
-	}	
245
+	}
246 246
 	xmlFreeDoc(doc);
247 247
 	doc= NULL;
248
-	
248
+
249 249
 	*fin_body= body;
250 250
 	xmlMemoryDump();
251 251
 	xmlCleanupParser();
... ...
@@ -263,7 +263,7 @@ error:
263 263
 	}
264 264
 	return -1;
265 265
 
266
-}	
266
+}
267 267
 
268 268
 int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple)
269 269
 {
... ...
@@ -295,20 +295,20 @@ int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple)
295 295
 	if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL)
296 296
 	{
297 297
 		LM_ERR("while setting version attribute\n");
298
-		goto error;	
298
+		goto error;
299 299
 	}
300 300
 	body= (str*)pkg_malloc(sizeof(str));
301 301
 	if(body== NULL)
302 302
 	{
303
-		LM_ERR("NO more memory left\n");
303
+		PKG_MEM_ERROR;
304 304
 		goto error;
305 305
 	}
306 306
 	memset(body, 0, sizeof(str));
307
-	xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);	
307
+	xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);
308 308
 
309 309
 	xmlFreeDoc(doc);
310 310
 	doc= NULL;
311
-	*fin_body= body;	
311
+	*fin_body= body;
312 312
 	if(*fin_body== NULL)
313 313
 		LM_DBG("NULL fin_body\n");
314 314
 
... ...
@@ -322,7 +322,7 @@ error:
322 322
 		xmlFreeDoc(doc);
323 323
 	if(body)
324 324
 		pkg_free(body);
325
-	
325
+
326 326
 	xmlMemoryDump();
327 327
 	xmlCleanupParser();
328 328
 	return -1;
... ...
@@ -355,19 +355,19 @@ int reginfo_process_body(publ_info_t* publ, str** fin_body, int ver, str** tuple
355 355
 
356 356
 	if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL) {
357 357
 		LM_ERR("while setting version attribute\n");
358
-		goto error;	
358
+		goto error;
359 359
 	}
360 360
 	body= (str*)pkg_malloc(sizeof(str));
361 361
 	if(body== NULL) {
362
-		LM_ERR("NO more memory left\n");
362
+		PKG_MEM_ERROR;
363 363
 		goto error;
364 364
 	}
365 365
 	memset(body, 0, sizeof(str));
366
-	xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);	
366
+	xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);
367 367
 
368 368
 	xmlFreeDoc(doc);
369 369
 	doc= NULL;
370
-	*fin_body= body;	
370
+	*fin_body= body;
371 371
 	if(*fin_body== NULL)
372 372
 		LM_DBG("NULL fin_body\n");
373 373
 
... ...
@@ -381,7 +381,7 @@ error:
381 381
 		xmlFreeDoc(doc);
382 382
 	if(body)
383 383
 		pkg_free(body);
384
-	
384
+
385 385
 	xmlMemoryDump();
386 386
 	xmlCleanupParser();
387 387
 	return -1;
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 17
  *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  *
22 22
  */
... ...
@@ -36,11 +36,11 @@ pua_event_t* init_pua_evlist(void)
36 36
 	list= (pua_event_t*)shm_malloc(sizeof(pua_event_t));
37 37
 	if(list== NULL)
38 38
 	{
39
-		LM_ERR("no more share memory\n");
39
+		SHM_MEM_ERROR;
40 40
 		return NULL;
41 41
 	}
42 42
 	list->next= NULL;
43
-	
43
+
44 44
 	return list;
45 45
 
46 46
 }
... ...
@@ -48,12 +48,12 @@ pua_event_t* init_pua_evlist(void)
48 48
 int add_pua_event(int ev_flag, char* name, char* content_type,
49 49
 		evs_process_body_t* process_body)
50 50
 {
51
-		
51
+
52 52
 	pua_event_t* event= NULL;
53 53
 	int size;
54 54
 	int name_len;
55 55
 	int ctype_len= 0;
56
-	str str_name;	
56
+	str str_name;
57 57
 
58 58
 	name_len= strlen(name);
59 59
 	str_name.s= name;
... ...
@@ -72,9 +72,9 @@ int add_pua_event(int ev_flag, char* name, char* content_type,
72 72
 	event= (pua_event_t*)shm_malloc(size);
73 73
 	if(event== NULL)
74 74
 	{
75
-		LM_ERR("No more share memory\n");
75
+		SHM_MEM_ERROR;
76 76
 		return -1;
77
-	}	
77
+	}
78 78
 	memset(event, 0, size);
79 79
 	size= sizeof(pua_event_t);
80 80
 
... ...
@@ -82,13 +82,13 @@ int add_pua_event(int ev_flag, char* name, char* content_type,
82 82
 	memcpy(event->name.s, name, name_len);
83 83
 	event->name.len= name_len;
84 84
 	size+= name_len;
85
-			
85
+
86 86
 	if(content_type)
87 87
 	{
88 88
 		event->content_type.s= (char*)event+ size;
89 89
 		memcpy(event->content_type.s, content_type, ctype_len);
90 90
 		event->content_type.len= ctype_len;
91
-		size+= ctype_len;		
91
+		size+= ctype_len;
92 92
 	}
93 93
 
94 94
 	event->process_body= process_body;
... ...
@@ -98,7 +98,7 @@ int add_pua_event(int ev_flag, char* name, char* content_type,
98 98
 	pua_evlist->next= event;
99 99
 
100 100
 	return 0;
101
-}	
101
+}
102 102
 
103 103
 pua_event_t* contains_pua_event(str* name)
104 104
 {
... ...
@@ -110,12 +110,12 @@ pua_event_t* contains_pua_event(str* name)
110 110
 		if(event->name.len== name->len &&
111 111
 				strncmp(event->name.s, name->s, name->len)== 0)
112 112
 		{
113
-			return event;	
113
+			return event;
114 114
 		}
115 115
 		event= event->next;
116
-	}	
116
+	}
117 117
 
118
-	return NULL;	
118
+	return NULL;
119 119
 }
120 120
 
121 121
 pua_event_t* get_event(int ev_flag)
... ...
@@ -127,11 +127,11 @@ pua_event_t* get_event(int ev_flag)
127 127
 	{
128 128
 		if(event->ev_flag== ev_flag)
129 129
 		{
130
-			return event;	
130
+			return event;
131 131
 		}
132 132
 		event= event->next;
133
-	}	
134
-	return NULL;	
133
+	}
134
+	return NULL;
135 135
 }
136 136
 
137 137
 
... ...
@@ -147,8 +147,8 @@ void destroy_pua_evlist(void)
147 147
 			e2= e1->next;
148 148
 			shm_free(e1);
149 149
 			e1= e2;
150
-		}	
150
+		}
151 151
 		shm_free(pua_evlist);
152
-	}	
152
+	}
153 153
 
154
-}	
154
+}
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 17
  *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  */
22 22
 
... ...
@@ -31,7 +31,7 @@
31 31
 #include "../../core/hashes.h"
32 32
 #include "../../core/parser/msg_parser.h"
33 33
 #include "../../core/parser/parse_from.h"
34
-#include "hash.h" 
34
+#include "hash.h"
35 35
 #include "pua.h"
36 36
 #include "pua_db.h"
37 37
 #include "send_publish.h"
... ...
@@ -40,14 +40,14 @@ void print_ua_pres(ua_pres_t* p)
40 40
 {
41 41
 	LM_DBG("\tpres_uri= %.*s   len= %d\n", p->pres_uri->len, p->pres_uri->s, p->pres_uri->len);
42 42
 	if(p->watcher_uri)
43
-	{	
43
+	{
44 44
 		LM_DBG("\twatcher_uri= %.*s  len= %d\n", p->watcher_uri->len, p->watcher_uri->s, p->watcher_uri->len);
45 45
 		LM_DBG("\tcall_id= %.*s   len= %d\n", p->call_id.len, p->call_id.s, p->call_id.len);
46 46
 		LM_DBG("\tfrom_tag= %.*s   len= %d\n", p->from_tag.len, p->from_tag.s, p->from_tag.len);
47 47
 		LM_DBG("\tto_tag= %.*s  len= %d\n", p->to_tag.len, p->to_tag.s, p->to_tag.len);
48 48
 		LM_DBG("\tflag= %d\n", p->flag);
49 49
 		LM_DBG("\tevent= %d\n", p->event);
50
-	}	
50
+	}
51 51
 	else
52 52
 	{
53 53
 		LM_DBG("\tetag= %.*s - len= %d\n", p->etag.len, p->etag.s, p->etag.len);
... ...
@@ -71,7 +71,7 @@ htable_t* new_htable(void)
71 71
 
72 72
 	if(H== NULL)
73 73
 	{
74
-		LM_ERR("No more memory\n");
74
+		SHM_MEM_ERROR;
75 75
 		return NULL;
76 76
 	}
77 77
 	memset(H, 0, sizeof(htable_t));
... ...
@@ -79,8 +79,8 @@ htable_t* new_htable(void)
79 79
 	H->p_records= (hash_entry_t*)shm_malloc(HASH_SIZE* sizeof(hash_entry_t));
80 80
 	if(H->p_records== NULL)
81 81
 	{
82
-		LM_ERR("No more share memory\n");
83
-		goto error;		
82
+		SHM_MEM_ERROR;
83
+		goto error;
84 84
 	}
85 85
 
86 86
 	for(i=0; i<HASH_SIZE; i++)
... ...
@@ -93,9 +93,9 @@ htable_t* new_htable(void)
93 93
 		H->p_records[i].entity= (ua_pres_t*)shm_malloc(sizeof(ua_pres_t));
94 94
 		if(H->p_records[i].entity== NULL)
95 95
 		{
96
-			LM_ERR("No more share memory\n");
97
-			goto error;		
98
-		}	
96
+			SHM_MEM_ERROR;
97
+			goto error;
98
+		}
99 99
 		H->p_records[i].entity->next= NULL;
100 100
 	}
101 101
 	return H;
... ...
@@ -138,12 +138,12 @@ ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code)
138 138
 			if((p->pres_uri->len==pres->pres_uri->len) &&
139 139
 					(strncmp(p->pres_uri->s, pres->pres_uri->s,pres->pres_uri->len)==0))
140 140
 			{
141
-				if(pres->id.s && pres->id.len) 
142
-				{	
141
+				if(pres->id.s && pres->id.len)
142
+				{
143 143
 					if(!(pres->id.len== p->id.len &&
144 144
 						strncmp(p->id.s, pres->id.s,pres->id.len)==0))
145 145
 							continue;
146
-				}				
146
+				}
147 147
 
148 148
 				if(pres->watcher_uri)
149 149
 				{
... ...
@@ -167,7 +167,7 @@ ua_pres_t* search_htable(ua_pres_t* pres, unsigned int hash_code)
167 167
 					{
168 168
 						if(pres->etag.len== p->etag.len &&
169 169
 							strncmp(p->etag.s, pres->etag.s,pres->etag.len)==0)
170
-							break;		
170
+							break;
171 171
 					}
172 172
 					else
173 173
 					{
... ...
@@ -198,16 +198,20 @@ void update_htable(ua_pres_t* p, time_t desired_expires, int expires,
198 198
 	}
199 199
 
200 200
 	if(etag)
201
-	{	
201
+	{
202 202
 		shm_free(p->etag.s);
203 203
 		p->etag.s= (char*)shm_malloc(etag->len);
204
+		if(p->etag.s == NULL) {
205
+			SHM_MEM_ERROR;
206
+			return;
207
+		}
204 208
 		memcpy(p->etag.s, etag->s, etag->len);
205 209
 		p->etag.len= etag->len;
206 210
 	}
207 211
 
208 212
 	p->expires= expires+ (int)time(NULL);
209 213
 	p->desired_expires= desired_expires;
210
-		
214
+
211 215
 	if(p->db_flag & NO_UPDATEDB_FLAG)
212 216
 		p->db_flag= UPDATEDB_FLAG;
213 217
 
... ...
@@ -216,7 +220,7 @@ void update_htable(ua_pres_t* p, time_t desired_expires, int expires,
216 220
 
217 221
 	if(contact)
218 222
 	{
219
-		if(!(p->remote_contact.len== contact->len && 
223
+		if(!(p->remote_contact.len== contact->len &&
220 224
 				strncmp(p->remote_contact.s, contact->s, contact->len)==0))
221 225
 		{
222 226
 			/* update remote contact */
... ...
@@ -224,7 +228,7 @@ void update_htable(ua_pres_t* p, time_t desired_expires, int expires,
224 228
 			p->remote_contact.s= (char*)shm_malloc(contact->len* sizeof(char));
225 229
 			if(p->remote_contact.s== NULL)
226 230
 			{
227
-				LM_ERR("no more shared memory\n");
231
+				SHM_MEM_ERROR;
228 232
 				return;
229 233
 			}
230 234
 			memcpy(p->remote_contact.s, contact->s, contact->len);
... ...
@@ -247,7 +251,7 @@ void insert_htable(ua_pres_t* presentity, unsigned int hash_code)
247 251
 
248 252
 	presentity->db_flag= INSERTDB_FLAG;
249 253
 	presentity->next= p->next;
250
-	
254
+
251 255
 	p->next= presentity;
252 256
 }
253 257
 
... ...
@@ -256,7 +260,7 @@ void insert_htable(ua_pres_t* presentity, unsigned int hash_code)
256 260
    everywhere it is used it is passed a pointer to the correct
257 261
    hash table entry already...  so let's just delete that */
258 262
 void delete_htable(ua_pres_t* presentity, unsigned int hash_code)
259
-{ 
263
+{
260 264
 	ua_pres_t *q = NULL;
261 265
 
262 266
 	if (dbmode==PUA_DB_ONLY)
... ...
@@ -273,7 +277,7 @@ void delete_htable(ua_pres_t* presentity, unsigned int hash_code)
273 277
 	while (q->next != presentity)
274 278
 		q = q->next;
275 279
 	q->next = presentity->next;
276
-	
280
+
277 281
 	if(presentity->etag.s)
278 282
 		shm_free(presentity->etag.s);
279 283
 	else
... ...
@@ -284,7 +288,7 @@ void delete_htable(ua_pres_t* presentity, unsigned int hash_code)
284 288
 	presentity = NULL;
285 289
 
286 290
 }
287
-	
291
+
288 292
 void destroy_htable(void)
289 293
 {
290 294
 	ua_pres_t* p= NULL,*q= NULL;
... ...
@@ -297,7 +301,7 @@ void destroy_htable(void)
297 301
 	}
298 302
 
299 303
 	for(i=0; i<HASH_SIZE; i++)
300
-	{	
304
+	{
301 305
 		lock_destroy(&HashT->p_records[i].lock);
302 306
 		p=HashT->p_records[i].entity;
303 307
 		while(p->next)
... ...
@@ -317,7 +321,7 @@ void destroy_htable(void)
317 321
 	}
318 322
     shm_free(HashT->p_records);
319 323
 	shm_free(HashT);
320
-  
324
+
321 325
   return;
322 326
 }
323 327
 
... ...
@@ -326,7 +330,7 @@ int convert_temporary_dialog(ua_pres_t *dialog)
326 330
 	ua_pres_t *temp_dialog;
327 331
 	unsigned int hash_code;
328 332
 
329
-	hash_code= core_hash(dialog->pres_uri,dialog->watcher_uri, HASH_SIZE); 
333
+	hash_code= core_hash(dialog->pres_uri,dialog->watcher_uri, HASH_SIZE);
330 334
 	lock_get(&HashT->p_records[hash_code].lock);
331 335
 
332 336
 	temp_dialog = get_temporary_dialog(dialog, hash_code);
... ...
@@ -374,19 +378,19 @@ ua_pres_t* get_dialog(ua_pres_t* dialog, unsigned int hash_code)
374 378
 
375 379
 			LM_DBG("searched to_tag= %.*s\tfrom_tag= %.*s\n",
376 380
 				 p->to_tag.len, p->to_tag.s, p->from_tag.len, p->from_tag.s);
377
-	    
381
+
378 382
 			if( (strncmp(p->call_id.s, dialog->call_id.s, p->call_id.len)== 0) &&
379 383
 				p->to_tag.len > 0 &&
380 384
 				(strncmp(p->to_tag.s, dialog->to_tag.s, p->to_tag.len)== 0) &&
381 385
 				(strncmp(p->from_tag.s, dialog->from_tag.s, p->from_tag.len)== 0) )
382
-				{	
386
+				{
383 387
 					LM_DBG("FOUND dialog\n");
384 388
 					break;
385 389
 				}
386
-		}	
387
-	
390
+		}
391
+
388 392
 	}
389
-		
393
+
390 394
 	return p;
391 395
 }
392 396
 
... ...
@@ -449,14 +453,14 @@ int get_record_id(ua_pres_t* dialog, str** rec_id)
449 453
 	id= (str*)pkg_malloc(sizeof(str));
450 454
 	if(id== NULL)
451 455
 	{
452
-		LM_ERR("No more memory\n");
456
+		PKG_MEM_ERROR;
453 457
 		lock_release(&HashT->p_records[hash_code].lock);
454 458
 		return -1;
455 459
 	}
456 460
 	id->s= (char*)pkg_malloc(rec->id.len* sizeof(char));
457 461
 	if(id->s== NULL)
458 462
 	{
459
-		LM_ERR("No more memory\n");
463
+		PKG_MEM_ERROR;
460 464
 		pkg_free(id);
461 465
 		lock_release(&HashT->p_records[hash_code].lock);
462 466
 		return -1;
... ...
@@ -484,7 +488,7 @@ int is_dialog(ua_pres_t* dialog)
484 488
 	if (dbmode==PUA_DB_ONLY)
485 489
 	{
486 490
 		return( is_dialog_puadb(dialog) );
487
-	}	
491
+	}
488 492
 
489 493
 	hash_code= core_hash(dialog->pres_uri, dialog->watcher_uri, HASH_SIZE);
490 494
 	lock_get(&HashT->p_records[hash_code].lock);
... ...
@@ -499,7 +503,7 @@ int is_dialog(ua_pres_t* dialog)
499 503
 		ret_code= 0;
500 504
 	}
501 505
 	lock_release(&HashT->p_records[hash_code].lock);
502
-	
506
+
503 507
 	return ret_code;
504 508
 
505 509
 }
... ...
@@ -522,8 +526,8 @@ int ki_pua_update_contact(struct sip_msg* msg)
522 526
 	{
523 527
 		LM_ERR("cannot parse callid header\n");
524 528
 		return -1;
525
-	}		
526
-	
529
+	}
530
+
527 531
 	if (!msg->from || !msg->from->body.s)
528 532
 	{
529 533
 		LM_ERR("cannot find 'from' header!\n");
... ...
@@ -531,27 +535,27 @@ int ki_pua_update_contact(struct sip_msg* msg)
531 535
 	}
532 536
 	if (msg->from->parsed == NULL)
533 537
 	{
534
-		if ( parse_from_header( msg )<0 ) 
538
+		if ( parse_from_header( msg )<0 )
535 539
 		{
536 540
 			LM_ERR("cannot parse From header\n");
537 541
 			return -1;
538 542
 		}
539 543
 	}
540
-	
544
+
541 545
 	pfrom = (struct to_body*)msg->from->parsed;
542
-	
546
+
543 547
 	if( pfrom->tag_value.s ==NULL || pfrom->tag_value.len == 0)
544 548
 	{
545 549
 		LM_ERR("no from tag value present\n");
546 550
 		return -1;
547
-	}		
548
-	
551
+	}
552
+
549 553
 	if( msg->to==NULL || msg->to->body.s==NULL)
550 554
 	{
551 555
 		LM_ERR("cannot parse TO header\n");
552 556
 		return -1;
553
-	}			
554
-	
557
+	}
558
+
555 559
 	if(msg->to->parsed != NULL)
556 560
 	{
557 561
 		pto = (struct to_body*)msg->to->parsed;
... ...
@@ -561,24 +565,24 @@ int ki_pua_update_contact(struct sip_msg* msg)
561 565
 	{
562 566
 		parse_to(msg->to->body.s,msg->to->body.s +
563 567
 			msg->to->body.len + 1, &TO);
564
-		if(TO.uri.len <= 0) 
568
+		if(TO.uri.len <= 0)
565 569
 		{
566 570
 			LM_DBG("'To' header NOT parsed\n");
567 571
 			goto error;
568 572
 		}
569 573
 		pto = &TO;
570
-	}			
574
+	}
571 575
 	if( pto->tag_value.s ==NULL || pto->tag_value.len == 0)
572 576
 	{
573 577
 		LM_ERR("no from tag value present\n");
574 578
 		goto error;
575 579
 	}
576 580
 	hentity.watcher_uri= &pto->uri;
577
-	hentity.pres_uri= &pfrom->uri; 
581
+	hentity.pres_uri= &pfrom->uri;
578 582
 	hentity.call_id=  msg->callid->body;
579 583
 	hentity.to_tag= pto->tag_value;
580 584
 	hentity.from_tag= pfrom->tag_value;
581
-	
585
+
582 586
 
583 587
 	/* extract the contact */
584 588
 	if(msg->contact== NULL || msg->contact->body.s== NULL)
... ...
@@ -610,7 +614,7 @@ int ki_pua_update_contact(struct sip_msg* msg)
610 614
 
611 615
 	shm_free(p->remote_contact.s);
612 616
 
613
-	if(!(p->remote_contact.len== contact.len && 
617
+	if(!(p->remote_contact.len== contact.len &&
614 618
 				strncmp(p->remote_contact.s, contact.s, contact.len)==0))
615 619
 	{
616 620
 		/* update remote contact */
... ...
@@ -618,7 +622,7 @@ int ki_pua_update_contact(struct sip_msg* msg)
618 622
 		p->remote_contact.s= (char*)shm_malloc(contact.len* sizeof(char));
619 623
 		if(p->remote_contact.s== NULL)
620 624
 		{
621
-			LM_ERR("no more shared memory\n");
625
+			SHM_MEM_ERROR;
622 626
 			lock_release(&HashT->p_records[hash_code].lock);
623 627
 			goto error;
624 628
 		}
... ...
@@ -665,14 +669,14 @@ list_entry_t *get_subs_list(str *did)
665 669
 			{
666 670
 				if ((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL)
667 671
 				{
668
-					LM_ERR("out of private memory\n");
672
+					PKG_MEM_ERROR;
669 673
 					lock_release(&HashT->p_records[i].lock);
670 674
 					goto done;
671 675
 				}
672 676
 				if ((tmp_str->s = (char *)pkg_malloc(sizeof(char) * dialog->pres_uri->len + 1)) == NULL)
673 677
 				{
674 678
 					pkg_free(tmp_str);
675
-					LM_ERR("out of private memory\n");
679
+					PKG_MEM_ERROR;
676 680
 					lock_release(&HashT->p_records[i].lock);
677 681
 					goto done;
678 682
 				}
... ...
@@ -498,7 +498,7 @@ static int db_restore(void)
498 498
 			p= (ua_pres_t*)shm_malloc(size);
499 499
 			if(p== NULL)
500 500
 			{
501
-				LM_ERR("no more share memmory");
501
+				SHM_MEM_ERROR;
502 502
 				goto error;
503 503
 			}
504 504
 			memset(p, 0, size);
... ...
@@ -568,7 +568,7 @@ static int db_restore(void)
568 568
 				p->remote_contact.s= (char*)shm_malloc(remote_contact.len* sizeof(char));
569 569
 				if(p->remote_contact.s== NULL)
570 570
 				{
571
-					LM_ERR("No more shared memory\n");
571
+					SHM_MEM_ERROR;
572 572
 					goto error;
573 573
 				}
574 574
 				memcpy(p->remote_contact.s, remote_contact.s, remote_contact.len);
... ...
@@ -600,7 +600,7 @@ static int db_restore(void)
600 600
 				p->etag.s= (char*)shm_malloc(etag.len* sizeof(char));
601 601
 				if(p->etag.s==  NULL)
602 602
 				{
603
-					LM_ERR("no more share memory\n");
603
+					SHM_MEM_ERROR;
604 604
 					goto error;
605 605
 				}
606 606
 				memcpy(p->etag.s, etag.s, etag.len);
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 17
  *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  */
22 22
 
... ...
@@ -35,7 +35,7 @@ int init_puacb_list(void)
35 35
 		( sizeof(struct puacb_head_list) );
36 36
 	if (puacb_list==0)
37 37
 	{
38
-		LM_CRIT("no more shared mem\n");
38
+		SHM_MEM_ERROR;
39 39
 		return -1;
40 40
 	}
41 41
 	puacb_list->first = 0;
... ...
@@ -55,7 +55,7 @@ void destroy_puacb_list(void)
55 55
 	{
56 56
 		cbp_tmp = cbp;
57 57
 		cbp = cbp->next;
58
-		if (cbp_tmp->param) 
58
+		if (cbp_tmp->param)
59 59
 			shm_free( cbp_tmp->param );
60 60
 		shm_free( cbp_tmp );
61 61
 	}
... ...
@@ -71,7 +71,7 @@ int register_puacb( int types, pua_cb f, void* param )
71 71
 	struct pua_callback *cbp;
72 72
 
73 73
 	/* are the callback types valid?... */
74
-	if ( types<0 || types>PUACB_MAX ) 
74
+	if ( types<0 || types>PUACB_MAX )
75 75
 	{
76 76
 		LM_CRIT("invalid callback types: mask=%d\n",types);
77 77
 		return E_BUG;
... ...
@@ -84,9 +84,9 @@ int register_puacb( int types, pua_cb f, void* param )
84 84
 	}
85 85
 
86 86
 	/* build a new callback structure */
87
-	if (!(cbp=(struct pua_callback*)shm_malloc(sizeof( struct pua_callback)))) 
87
+	if (!(cbp=(struct pua_callback*)shm_malloc(sizeof( struct pua_callback))))
88 88
 	{
89
-		LM_ERR("out of share mem\n");
89
+		SHM_MEM_ERROR;
90 90
 		return E_OUT_OF_MEM;
91 91
 	}
92 92
 
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- * pua db - presence user agent database support 
2
+ * pua db - presence user agent database support
3 3
  *
4 4
  * Copyright (C) 2011 Crocodile RCS Ltd
5 5
  *
... ...
@@ -15,8 +15,8 @@
15 15
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
  * GNU General Public License for more details.
17 17
  *
18
- * You should have received a copy of the GNU General Public License 
19
- * along with this program; if not, write to the Free Software 
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20 20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21 21
  */
22 22
 
... ...
@@ -62,7 +62,7 @@ static str str_version_col = str_init("version");
62 62
 void free_results_puadb( db1_res_t *res )
63 63
 
64 64
 {
65
-	if (res) 
65
+	if (res)
66 66
 	{
67 67
 		pua_dbf.free_result(pua_db, res);
68 68
 		res = NULL;
... ...
@@ -164,7 +164,7 @@ int clean_puadb( int update_period, int min_expires )
164 164
 	q_vals[0].type = DB1_INT;
165 165
 	q_vals[0].nul = 0;
166 166
 	q_vals[0].val.int_val = now+update_period;
167
-	q_ops[0] = OP_LT; 	
167
+	q_ops[0] = OP_LT;
168 168
 
169 169
 	if (pua_dbf.use_table(pua_db, &db_table) < 0) {
170 170
 	    LM_ERR("error in use_table pua\n");
... ...
@@ -186,7 +186,7 @@ int clean_puadb( int update_period, int min_expires )
186 186
 
187 187
 	if (RES_ROW_N(res) == 0)
188 188
 	{
189
-		/* no match */ 
189
+		/* no match */
190 190
 		LM_DBG( "No records matched for clean\n");
191 191
 		pua_dbf.free_result(pua_db, res);
192 192
 		return(0);
... ...
@@ -202,7 +202,7 @@ int clean_puadb( int update_period, int min_expires )
202 202
 		{
203 203
 			values = ROW_VALUES(rows+i);
204 204
 
205
-			extract_row( values, &p ); 
205
+			extract_row( values, &p );
206 206
 			id = VAL_INT(values);
207 207
 
208 208
 			if((p.desired_expires> p.expires + min_expires) || (p.desired_expires== 0 ))
... ...
@@ -224,8 +224,8 @@ int clean_puadb( int update_period, int min_expires )
224 224
 
225 225
 				if ( pua_dbf.delete(pua_db, q_cols, 0, q_vals, 1) < 0 )
226 226
 				{
227
-					LM_ERR( "Failed to delete from db\n" ); 
228
-				}			
227
+					LM_ERR( "Failed to delete from db\n" );
228
+				}
229 229
 			}
230 230
 
231 231
 		}
... ...
@@ -238,7 +238,7 @@ int clean_puadb( int update_period, int min_expires )
238 238
 
239 239
 /******************************************************************************/
240 240
 
241
-int is_dialog_puadb(ua_pres_t *pres) 
241
+int is_dialog_puadb(ua_pres_t *pres)
242 242
 
243 243
 {
244 244
 	int nr_rows;
... ...
@@ -254,26 +254,26 @@ int is_dialog_puadb(ua_pres_t *pres)
254 254
 	}
255 255
 
256 256
 	/* cols and values used for search query */
257
-	q_cols[n_query_cols] = &str_call_id_col;	
257
+	q_cols[n_query_cols] = &str_call_id_col;
258 258
 	q_vals[n_query_cols].type = DB1_STR;
259 259
 	q_vals[n_query_cols].nul = 0;
260 260
 	q_vals[n_query_cols].val.str_val = pres->call_id;
261 261
 	n_query_cols++;
262 262
 
263
-	q_cols[n_query_cols] = &str_to_tag_col;	
263
+	q_cols[n_query_cols] = &str_to_tag_col;
264 264
 	q_vals[n_query_cols].type = DB1_STR;
265 265
 	q_vals[n_query_cols].nul = 0;
266 266
 	q_vals[n_query_cols].val.str_val = pres->to_tag;
267 267
 	n_query_cols++;
268 268
 
269
-	q_cols[n_query_cols] = &str_from_tag_col;	
269
+	q_cols[n_query_cols] = &str_from_tag_col;
270 270
 	q_vals[n_query_cols].type = DB1_STR;
271 271
 	q_vals[n_query_cols].nul = 0;
272 272
 	q_vals[n_query_cols].val.str_val = pres->from_tag;
273 273
 	n_query_cols++;
274 274
 
275 275
 	/* return the id column, even though don't actually need */
276
-	res_cols[n_res_cols] = &str_id_col;	
276
+	res_cols[n_res_cols] = &str_id_col;
277 277
 	n_res_cols++;
278 278
 
279 279
 	if(pua_db == NULL)
... ...
@@ -306,7 +306,7 @@ int is_dialog_puadb(ua_pres_t *pres)
306 306
 
307 307
 	if (nr_rows == 0)
308 308
 	{
309
-		/* no match */ 
309
+		/* no match */
310 310
 		LM_DBG("No rows found.\n");
311 311
 		return(-1);
312 312
 	}
... ...
@@ -326,7 +326,7 @@ int is_dialog_puadb(ua_pres_t *pres)
326 326
 
327 327
 /******************************************************************************/
328 328
 
329
-int get_record_id_puadb(ua_pres_t *pres, str **rec_id ) 
329
+int get_record_id_puadb(ua_pres_t *pres, str **rec_id )
330 330
 
331 331
 {
332 332
 	int nr_rows;
... ...
@@ -335,7 +335,7 @@ int get_record_id_puadb(ua_pres_t *pres, str **rec_id )
335 335
 	db1_res_t *res= NULL;
336 336
 	db_val_t q_vals[3];
337 337
 	int n_query_cols=0, n_res_cols=0;
338
-	db_val_t *values;	
338
+	db_val_t *values;
339 339
 	str *id;
340 340
 	str to_tag;
341 341
 
... ...
@@ -346,25 +346,25 @@ int get_record_id_puadb(ua_pres_t *pres, str **rec_id )
346 346
 	}
347 347
 
348 348
 	/* cols and values used for search query */
349
-	q_cols[n_query_cols] = &str_call_id_col;	
349
+	q_cols[n_query_cols] = &str_call_id_col;
350 350
 	q_vals[n_query_cols].type = DB1_STR;
351 351
 	q_vals[n_query_cols].nul = 0;
352 352
 	q_vals[n_query_cols].val.str_val = pres->call_id;
353 353
 	n_query_cols++;
354 354
 
355
-	q_cols[n_query_cols] = &str_from_tag_col;	
355
+	q_cols[n_query_cols] = &str_from_tag_col;
356 356
 	q_vals[n_query_cols].type = DB1_STR;
357 357
 	q_vals[n_query_cols].nul = 0;
358 358
 	q_vals[n_query_cols].val.str_val = pres->from_tag;
359 359
 	n_query_cols++;
360 360
 
361
-	q_cols[n_query_cols] = &str_to_tag_col;	
361
+	q_cols[n_query_cols] = &str_to_tag_col;
362 362
 	q_vals[n_query_cols].type = DB1_STR;
363 363
 	q_vals[n_query_cols].nul = 0;
364 364
 	q_vals[n_query_cols].val.str_val = pres->to_tag;
365 365
 	n_query_cols++;
366 366
 
367
-	res_cols[n_res_cols] = &str_pres_id_col;	
367
+	res_cols[n_res_cols] = &str_pres_id_col;
368 368
 	n_res_cols++;
369 369
 
370 370
 	*rec_id = NULL;
... ...
@@ -467,7 +467,7 @@ int get_record_id_puadb(ua_pres_t *pres, str **rec_id )
467 467
 
468 468
 	if(id== NULL)
469 469
 	{
470
-		LM_ERR("No more memory\n");
470
+		PKG_MEM_ERROR;
471 471
 		pua_dbf.free_result(pua_db, res);
472 472
 		return(-1);
473 473
 	}
... ...
@@ -476,7 +476,7 @@ int get_record_id_puadb(ua_pres_t *pres, str **rec_id )
476 476
 
477 477
 	if(id->s== NULL)
478 478
 	{
479
-		LM_ERR("No more memory\n");
479
+		PKG_MEM_ERROR;
480 480
 		pkg_free(id);
481 481
 		pua_dbf.free_result(pua_db, res);
482 482
 		return(-1);
... ...
@@ -519,13 +519,13 @@ int convert_temporary_dialog_puadb(ua_pres_t *pres)
519 519
 	query_vals[n_query_cols].val.str_val.len = pres->pres_uri->len;
520 520
 	n_query_cols++;
521 521
 
522
-	query_cols[n_query_cols] = &str_call_id_col;	
522
+	query_cols[n_query_cols] = &str_call_id_col;
523 523
 	query_vals[n_query_cols].type = DB1_STR;
524 524
 	query_vals[n_query_cols].nul = 0;
525 525
 	query_vals[n_query_cols].val.str_val = pres->call_id;
526 526
 	n_query_cols++;
527 527
 
528
-	query_cols[n_query_cols] = &str_from_tag_col;	
528
+	query_cols[n_query_cols] = &str_from_tag_col;
529 529
 	query_vals[n_query_cols].type = DB1_STR;
530 530
 	query_vals[n_query_cols].nul = 0;
531 531
 	query_vals[n_query_cols].val.str_val = pres->from_tag;
... ...
@@ -601,7 +601,7 @@ int convert_temporary_dialog_puadb(ua_pres_t *pres)
601 601
 	}
602 602
 	n_query_cols++;
603 603
 
604
-	query_cols[n_query_cols] = &str_event_col;	
604
+	query_cols[n_query_cols] = &str_event_col;
605 605
 	query_vals[n_query_cols].type = DB1_INT;
606 606
 	query_vals[n_query_cols].nul = 0;
607 607
 	query_vals[n_query_cols].val.int_val = pres->event;
... ...
@@ -609,21 +609,21 @@ int convert_temporary_dialog_puadb(ua_pres_t *pres)
609 609
 
610 610
 	query_cols[n_query_cols] = &str_watcher_uri_col;
611 611
 	query_vals[n_query_cols].type = DB1_STR;
612
-	query_vals[n_query_cols].nul = 0; 
612
+	query_vals[n_query_cols].nul = 0;
613 613
 	query_vals[n_query_cols].val.str_val.s = pres->watcher_uri->s;
614 614
 	query_vals[n_query_cols].val.str_val.len = pres->watcher_uri->len;
615 615
 	n_query_cols++;
616 616
 
617 617
 	query_cols[n_query_cols] = &str_etag_col;
618 618
 	query_vals[n_query_cols].type = DB1_STR;
619
-	query_vals[n_query_cols].nul = 0; 
619
+	query_vals[n_query_cols].nul = 0;
620 620
 	query_vals[n_query_cols].val.str_val.s = 0;
621 621
 	query_vals[n_query_cols].val.str_val.len = 0;
622 622
 	n_query_cols++;
623 623
 
624 624
 	query_cols[n_query_cols] = &str_tuple_id_col;
625 625
 	query_vals[n_query_cols].type = DB1_STR;
626
-	query_vals[n_query_cols].nul = 0; 
626
+	query_vals[n_query_cols].nul = 0;
627 627
 	query_vals[n_query_cols].val.str_val.s = 0;
628 628
 	query_vals[n_query_cols].val.str_val.len = 0;
629 629
 	n_query_cols++;
... ...
@@ -692,14 +692,14 @@ int insert_record_puadb(ua_pres_t* pres)
692 692
 	db_vals[n_cols].val.str_val.len = pres->pres_uri->len;
693 693
 	n_cols++;
694 694
 
695
-	db_cols[n_cols] = &str_pres_id_col;	
695
+	db_cols[n_cols] = &str_pres_id_col;
696 696
 	db_vals[n_cols].type = DB1_STR;
697 697
 	db_vals[n_cols].nul = 0;
698 698
 	db_vals[n_cols].val.str_val.s = pres->id.s;
699 699
 	db_vals[n_cols].val.str_val.len = pres->id.len;
700 700
 	n_cols++;
701 701
 
702
-	db_cols[n_cols] = &str_event_col;	
702
+	db_cols[n_cols] = &str_event_col;
703 703
 	db_vals[n_cols].type = DB1_INT;
704 704
 	db_vals[n_cols].nul = 0;
705 705
 	db_vals[n_cols].val.int_val = pres->event;
... ...
@@ -725,42 +725,42 @@ int insert_record_puadb(ua_pres_t* pres)
725 725
 
726 726
 	db_cols[n_cols] = &str_etag_col;
727 727
 	db_vals[n_cols].type = DB1_STR;
728
-	db_vals[n_cols].nul = 0; 
728
+	db_vals[n_cols].nul = 0;
729 729
 	db_vals[n_cols].val.str_val.s = pres->etag.s;
730 730
 	db_vals[n_cols].val.str_val.len = pres->etag.len;
731 731
 	n_cols++;
732 732
 
733 733
 	db_cols[n_cols] = &str_tuple_id_col;
734 734
 	db_vals[n_cols].type = DB1_STR;
735
-	db_vals[n_cols].nul = 0; 
735
+	db_vals[n_cols].nul = 0;
736 736
 	db_vals[n_cols].val.str_val.s = pres->tuple_id.s;
737 737
 	db_vals[n_cols].val.str_val.len = pres->tuple_id.len;
738 738
 	n_cols++;
739 739
 
740 740
 	db_cols[n_cols] = &str_watcher_uri_col;
741 741
 	db_vals[n_cols].type = DB1_STR;
742
-	db_vals[n_cols].nul = 0; 
742
+	db_vals[n_cols].nul = 0;
743 743
 	db_vals[n_cols].val.str_val.s = "";
744 744
 	db_vals[n_cols].val.str_val.len = 0;
745 745
 	n_cols++;
746 746
 
747 747
 	db_cols[n_cols] = &str_call_id_col;
748 748
 	db_vals[n_cols].type = DB1_STR;
749
-	db_vals[n_cols].nul = 0; 
749
+	db_vals[n_cols].nul = 0;
750 750
 	db_vals[n_cols].val.str_val.s = "";
751 751
 	db_vals[n_cols].val.str_val.len = 0;
752 752
 	n_cols++;
753 753
 
754 754
 	db_cols[n_cols] = &str_to_tag_col;
755 755
 	db_vals[n_cols].type = DB1_STR;
756
-	db_vals[n_cols].nul = 0; 
756
+	db_vals[n_cols].nul = 0;
757 757
 	db_vals[n_cols].val.str_val.s = "";
758 758
 	db_vals[n_cols].val.str_val.len = 0;
759 759
 	n_cols++;
760 760
 
761 761
 	db_cols[n_cols] = &str_from_tag_col;
762 762
 	db_vals[n_cols].type = DB1_STR;
763
-	db_vals[n_cols].nul = 0; 
763
+	db_vals[n_cols].nul = 0;
764 764
 	db_vals[n_cols].val.str_val.s = "";
765 765
 	db_vals[n_cols].val.str_val.len = 0;
766 766
 	n_cols++;
... ...
@@ -773,21 +773,21 @@ int insert_record_puadb(ua_pres_t* pres)
773 773
 
774 774
 	db_cols[n_cols] = &str_record_route_col;
775 775
 	db_vals[n_cols].type = DB1_STR;
776
-	db_vals[n_cols].nul = 0; 
776
+	db_vals[n_cols].nul = 0;
777 777
 	db_vals[n_cols].val.str_val.s = "";
778 778
 	db_vals[n_cols].val.str_val.len = 0;
779 779
 	n_cols++;
780 780
 
781 781
 	db_cols[n_cols] = &str_contact_col;
782 782
 	db_vals[n_cols].type = DB1_STR;
783
-	db_vals[n_cols].nul = 0; 
783
+	db_vals[n_cols].nul = 0;
784 784
 	db_vals[n_cols].val.str_val.s = "";
785 785
 	db_vals[n_cols].val.str_val.len = 0;
786 786
 	n_cols++;
787 787
 
788 788
 	db_cols[n_cols] = &str_remote_contact_col;
789 789
 	db_vals[n_cols].type = DB1_STR;
790
-	db_vals[n_cols].nul = 0; 
790
+	db_vals[n_cols].nul = 0;
791 791
 	db_vals[n_cols].val.str_val.s = "";
792 792
 	db_vals[n_cols].val.str_val.len = 0;
793 793
 	n_cols++;
... ...
@@ -800,7 +800,7 @@ int insert_record_puadb(ua_pres_t* pres)
800 800
 
801 801
 	db_cols[n_cols] = &str_extra_headers_col;
802 802
 	db_vals[n_cols].type = DB1_STR;
803
-	db_vals[n_cols].nul = 0; 
803
+	db_vals[n_cols].nul = 0;
804 804
 	if (pres->extra_headers)
805 805
 	{
806 806
 		db_vals[n_cols].val.str_val.s = pres->extra_headers->s;
... ...
@@ -819,7 +819,7 @@ int insert_record_puadb(ua_pres_t* pres)
819 819
 		return(-1);
820 820
 	}
821 821
 
822
-	if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0)  
822
+	if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0)
823 823
 	{
824 824
 		LM_ERR("DB insert failed\n");
825 825
 		return(-1);
... ...
@@ -839,7 +839,7 @@ ua_pres_t *get_record_puadb(str pres_id, str *etag, ua_pres_t *result, db1_res_t
839 839
 	int n_query_cols = 0, nr_rows;
840 840
 	db_query_f query_fn = pua_dbf.query_lock ? pua_dbf.query_lock : pua_dbf.query;
841 841
 
842
-	q_cols[n_query_cols] = &str_pres_id_col;	
842
+	q_cols[n_query_cols] = &str_pres_id_col;
843 843
 	q_vals[n_query_cols].type = DB1_STR;
844 844
 	q_vals[n_query_cols].nul = 0;
845 845
 	q_vals[n_query_cols].val.str_val = pres_id;
... ...
@@ -884,7 +884,7 @@ ua_pres_t *get_record_puadb(str pres_id, str *etag, ua_pres_t *result, db1_res_t
884 884
 
885 885
 	if (nr_rows == 0)
886 886
 	{
887
-		/* no match */ 
887
+		/* no match */
888 888
 		LM_DBG("No rows found\n");
889 889
 		pua_dbf.free_result(pua_db, res);
890 890
 		return(NULL);
... ...
@@ -922,7 +922,7 @@ int delete_record_puadb(ua_pres_t *pres)
922 922
 		return(-1);
923 923
 	}
924 924
 
925
-	q_cols[n_query_cols] = &str_pres_id_col;	
925
+	q_cols[n_query_cols] = &str_pres_id_col;
926 926
 	q_vals[n_query_cols].type = DB1_STR;
927 927
 	q_vals[n_query_cols].nul = 0;
928 928
 	q_vals[n_query_cols].val.str_val = pres->id;
... ...
@@ -949,7 +949,7 @@ int delete_record_puadb(ua_pres_t *pres)
949 949
 		return(-1);
950 950
 	}
951 951
 
952
-	if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) 
952
+	if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0)
953 953
 	{
954 954
 		LM_ERR("deleting record\n");
955 955
 		return -1;
... ...
@@ -972,7 +972,7 @@ int update_record_puadb(ua_pres_t *pres, int expires, str *etag)
972 972
 		return(-1);
973 973
 	}
974 974
 
975
-	q_cols[n_query_cols] = &str_pres_id_col;	
975
+	q_cols[n_query_cols] = &str_pres_id_col;
976 976
 	q_vals[n_query_cols].type = DB1_STR;
977 977
 	q_vals[n_query_cols].nul = 0;
978 978
 	q_vals[n_query_cols].val.str_val = pres->id;
... ...
@@ -1056,14 +1056,14 @@ int insert_dialog_puadb(ua_pres_t* pres)
1056 1056
 	db_vals[n_cols].val.str_val.len = pres->pres_uri->len;
1057 1057
 	n_cols++;
1058 1058
 
1059
-	db_cols[n_cols] = &str_pres_id_col;	
1059
+	db_cols[n_cols] = &str_pres_id_col;
1060 1060
 	db_vals[n_cols].type = DB1_STR;
1061 1061
 	db_vals[n_cols].nul = 0;
1062 1062
 	db_vals[n_cols].val.str_val.s = pres->id.s;
1063 1063
 	db_vals[n_cols].val.str_val.len = pres->id.len;
1064 1064
 	n_cols++;
1065 1065
 
1066
-	db_cols[n_cols] = &str_event_col;	
1066
+	db_cols[n_cols] = &str_event_col;
1067 1067
 	db_vals[n_cols].type = DB1_INT;
1068 1068
 	db_vals[n_cols].nul = 0;
1069 1069
 	db_vals[n_cols].val.int_val = pres->event;
... ...
@@ -1089,42 +1089,42 @@ int insert_dialog_puadb(ua_pres_t* pres)
1089 1089
 
1090 1090
 	db_cols[n_cols] = &str_etag_col;
1091 1091
 	db_vals[n_cols].type = DB1_STR;
1092
-	db_vals[n_cols].nul = 0; 
1092
+	db_vals[n_cols].nul = 0;
1093 1093
 	db_vals[n_cols].val.str_val.s = "";
1094 1094
 	db_vals[n_cols].val.str_val.len = 0;
1095 1095
 	n_cols++;
1096 1096
 
1097 1097
 	db_cols[n_cols] = &str_tuple_id_col;
1098 1098
 	db_vals[n_cols].type = DB1_STR;
1099
-	db_vals[n_cols].nul = 0; 
1099
+	db_vals[n_cols].nul = 0;
1100 1100
 	db_vals[n_cols].val.str_val.s = "";
1101 1101
 	db_vals[n_cols].val.str_val.len = 0;
1102 1102
 	n_cols++;
1103 1103
 
1104 1104
 	db_cols[n_cols] = &str_watcher_uri_col;
1105 1105
 	db_vals[n_cols].type = DB1_STR;
1106
-	db_vals[n_cols].nul = 0; 
1106
+	db_vals[n_cols].nul = 0;
1107 1107
 	db_vals[n_cols].val.str_val.s = pres->watcher_uri->s;
1108 1108
 	db_vals[n_cols].val.str_val.len = pres->watcher_uri->len;
1109 1109
 	n_cols++;
1110 1110
 
1111 1111
 	db_cols[n_cols] = &str_call_id_col;
1112 1112
 	db_vals[n_cols].type = DB1_STR;
1113
-	db_vals[n_cols].nul = 0; 
1113
+	db_vals[n_cols].nul = 0;
1114 1114
 	db_vals[n_cols].val.str_val.s = pres->call_id.s;
1115 1115
 	db_vals[n_cols].val.str_val.len = pres->call_id.len;
1116 1116
 	n_cols++;
1117 1117
 
1118 1118
 	db_cols[n_cols] = &str_to_tag_col;
1119 1119
 	db_vals[n_cols].type = DB1_STR;
1120
-	db_vals[n_cols].nul = 0; 
1120
+	db_vals[n_cols].nul = 0;
1121 1121
 	db_vals[n_cols].val.str_val.s = pres->to_tag.s;
1122 1122
 	db_vals[n_cols].val.str_val.len = pres->to_tag.len;
1123 1123
 	n_cols++;
1124 1124
 
1125 1125
 	db_cols[n_cols] = &str_from_tag_col;
1126 1126
 	db_vals[n_cols].type = DB1_STR;
1127
-	db_vals[n_cols].nul = 0; 
1127
+	db_vals[n_cols].nul = 0;
1128 1128
 	db_vals[n_cols].val.str_val.s = pres->from_tag.s;
1129 1129
 	db_vals[n_cols].val.str_val.len = pres->from_tag.len;
1130 1130
 	n_cols++;
... ...
@@ -1137,21 +1137,21 @@ int insert_dialog_puadb(ua_pres_t* pres)
1137 1137
 
1138 1138
 	db_cols[n_cols] = &str_record_route_col;
1139 1139
 	db_vals[n_cols].type = DB1_STR;
1140
-	db_vals[n_cols].nul = 0; 
1140
+	db_vals[n_cols].nul = 0;
1141 1141
 	db_vals[n_cols].val.str_val.s = pres->record_route.s;
1142 1142
 	db_vals[n_cols].val.str_val.len = pres->record_route.len;
1143 1143
 	n_cols++;
1144 1144
 
1145 1145
 	db_cols[n_cols] = &str_contact_col;
1146 1146
 	db_vals[n_cols].type = DB1_STR;
1147
-	db_vals[n_cols].nul = 0; 
1147
+	db_vals[n_cols].nul = 0;
1148 1148
 	db_vals[n_cols].val.str_val.s = pres->contact.s;
1149 1149
 	db_vals[n_cols].val.str_val.len = pres->contact.len;
1150 1150
 	n_cols++;
1151 1151
 
1152 1152
 	db_cols[n_cols] = &str_remote_contact_col;
1153 1153
 	db_vals[n_cols].type = DB1_STR;
1154
-	db_vals[n_cols].nul = 0; 
1154
+	db_vals[n_cols].nul = 0;
1155 1155
 	db_vals[n_cols].val.str_val.s = pres->remote_contact.s;
1156 1156
 	db_vals[n_cols].val.str_val.len = pres->remote_contact.len;
1157 1157
 	n_cols++;
... ...
@@ -1164,7 +1164,7 @@ int insert_dialog_puadb(ua_pres_t* pres)
1164 1164
 
1165 1165
 	db_cols[n_cols] = &str_extra_headers_col;
1166 1166
 	db_vals[n_cols].type = DB1_STR;
1167
-	db_vals[n_cols].nul = 0; 
1167
+	db_vals[n_cols].nul = 0;
1168 1168
 	if (pres->extra_headers)
1169 1169
 	{
1170 1170
 		db_vals[n_cols].val.str_val.s = pres->extra_headers->s;
... ...
@@ -1183,7 +1183,7 @@ int insert_dialog_puadb(ua_pres_t* pres)
1183 1183
 		return(-1);
1184 1184
 	}
1185 1185
 
1186
-	if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0)  
1186
+	if(pua_dbf.insert(pua_db, db_cols, db_vals, n_cols) < 0)
1187 1187
 	{
1188 1188
 		LM_ERR("DB insert failed\n");
1189 1189
 		return(-1);
... ...
@@ -1209,7 +1209,7 @@ ua_pres_t *get_dialog_puadb(str pres_id, str *pres_uri, ua_pres_t *result, db1_r
1209 1209
 		return(NULL);
1210 1210
 	}
1211 1211
 
1212
-	q_cols[n_query_cols] = &str_pres_id_col;	
1212
+	q_cols[n_query_cols] = &str_pres_id_col;
1213 1213
 	q_vals[n_query_cols].type = DB1_STR;
1214 1214
 	q_vals[n_query_cols].nul = 0;
1215 1215
 	q_vals[n_query_cols].val.str_val = pres_id;
... ...
@@ -1251,7 +1251,7 @@ ua_pres_t *get_dialog_puadb(str pres_id, str *pres_uri, ua_pres_t *result, db1_r
1251 1251
 
1252 1252
 	if (nr_rows == 0)
1253 1253
 	{
1254
-		/* no match */ 
1254
+		/* no match */
1255 1255
 		LM_DBG("No rows found\n");
1256 1256
 		pua_dbf.free_result(pua_db, res);
1257 1257
 		return(NULL);
... ...
@@ -1261,7 +1261,7 @@ ua_pres_t *get_dialog_puadb(str pres_id, str *pres_uri, ua_pres_t *result, db1_r
1261 1261
 		LM_ERR("Too many rows found (%d)... deleting\n", nr_rows);
1262 1262
 		pua_dbf.free_result(pua_db, res);
1263 1263
 
1264
-		if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) 
1264
+		if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0)
1265 1265
 			LM_ERR("deleting record(s)\n");
1266 1266
 
1267 1267
 		return(NULL);
... ...
@@ -1293,13 +1293,13 @@ int delete_dialog_puadb(ua_pres_t *pres)
1293 1293
 		return(-1);
1294 1294
 	}
1295 1295
 
1296
-	q_cols[n_query_cols] = &str_call_id_col;	
1296
+	q_cols[n_query_cols] = &str_call_id_col;
1297 1297
 	q_vals[n_query_cols].type = DB1_STR;
1298 1298
 	q_vals[n_query_cols].nul = 0;
1299 1299
 	q_vals[n_query_cols].val.str_val = pres->call_id;
1300 1300
 	n_query_cols++;
1301 1301
 
1302
-	q_cols[n_query_cols] = &str_from_tag_col;	
1302
+	q_cols[n_query_cols] = &str_from_tag_col;
1303 1303
 	q_vals[n_query_cols].type = DB1_STR;
1304 1304
 	q_vals[n_query_cols].nul = 0;
1305 1305
 	q_vals[n_query_cols].val.str_val = pres->from_tag;
... ...
@@ -1307,13 +1307,13 @@ int delete_dialog_puadb(ua_pres_t *pres)
1307 1307
 
1308 1308
 	if (pres->to_tag.len > 0 && pres->to_tag.s != NULL)
1309 1309
 	{
1310
-		q_cols[n_query_cols] = &str_to_tag_col;	
1310
+		q_cols[n_query_cols] = &str_to_tag_col;
1311 1311
 		q_vals[n_query_cols].type = DB1_STR;
1312 1312
 		q_vals[n_query_cols].nul = 0;
1313 1313
 		q_vals[n_query_cols].val.str_val = pres->to_tag;
1314 1314
 		n_query_cols++;
1315 1315
 	}
1316
-	
1316
+
1317 1317
 	if(pua_db == NULL)
1318 1318
 	{
1319 1319
 		LM_ERR("null database connection\n");
... ...
@@ -1326,7 +1326,7 @@ int delete_dialog_puadb(ua_pres_t *pres)
1326 1326
 		return(-1);
1327 1327
 	}
1328 1328
 
1329
-	if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0) 
1329
+	if (pua_dbf.delete(pua_db, q_cols, 0, q_vals, n_query_cols) < 0)
1330 1330
 	{
1331 1331
 		LM_ERR("deleting record\n");
1332 1332
 		return -1;
... ...
@@ -1349,19 +1349,19 @@ int update_dialog_puadb(ua_pres_t *pres, int expires, str *contact)
1349 1349
 		return(-1);
1350 1350
 	}
1351 1351
 
1352
-	q_cols[n_query_cols] = &str_call_id_col;	
1352
+	q_cols[n_query_cols] = &str_call_id_col;
1353 1353
 	q_vals[n_query_cols].type = DB1_STR;
1354 1354
 	q_vals[n_query_cols].nul = 0;
1355 1355
 	q_vals[n_query_cols].val.str_val = pres->call_id;
1356 1356
 	n_query_cols++;
1357 1357
 
1358
-	q_cols[n_query_cols] = &str_from_tag_col;	
1358
+	q_cols[n_query_cols] = &str_from_tag_col;
1359 1359
 	q_vals[n_query_cols].type = DB1_STR;
1360 1360
 	q_vals[n_query_cols].nul = 0;
1361 1361
 	q_vals[n_query_cols].val.str_val = pres->from_tag;
1362 1362
 	n_query_cols++;
1363 1363
 
1364
-	q_cols[n_query_cols] = &str_to_tag_col;	
1364
+	q_cols[n_query_cols] = &str_to_tag_col;
1365 1365
 	q_vals[n_query_cols].type = DB1_STR;
1366 1366
 	q_vals[n_query_cols].nul = 0;
1367 1367
 	q_vals[n_query_cols].val.str_val = pres->to_tag;
... ...
@@ -1416,7 +1416,7 @@ int update_dialog_puadb(ua_pres_t *pres, int expires, str *contact)
1416 1416
 
1417 1417
 /******************************************************************************/
1418 1418
 
1419
-int update_contact_puadb(ua_pres_t *pres, str *contact) 
1419
+int update_contact_puadb(ua_pres_t *pres, str *contact)
1420 1420
 
1421 1421
 {
1422 1422
 	db_key_t q_cols[3], db_cols[1];
... ...
@@ -1430,19 +1430,19 @@ int update_contact_puadb(ua_pres_t *pres, str *contact)
1430 1430
 	}
1431 1431
 
1432 1432
 	/* cols and values used for search query */
1433
-	q_cols[n_query_cols] = &str_call_id_col;	
1433
+	q_cols[n_query_cols] = &str_call_id_col;
1434 1434
 	q_vals[n_query_cols].type = DB1_STR;
1435 1435
 	q_vals[n_query_cols].nul = 0;
1436 1436
 	q_vals[n_query_cols].val.str_val = pres->call_id;
1437 1437
 	n_query_cols++;
1438 1438
 
1439
-	q_cols[n_query_cols] = &str_to_tag_col;	
1439
+	q_cols[n_query_cols] = &str_to_tag_col;
1440 1440
 	q_vals[n_query_cols].type = DB1_STR;
1441 1441
 	q_vals[n_query_cols].nul = 0;
1442 1442
 	q_vals[n_query_cols].val.str_val = pres->to_tag;
1443 1443
 	n_query_cols++;
1444 1444
 
1445
-	q_cols[n_query_cols] = &str_from_tag_col;	
1445
+	q_cols[n_query_cols] = &str_from_tag_col;
1446 1446
 	q_vals[n_query_cols].type = DB1_STR;
1447 1447
 	q_vals[n_query_cols].nul = 0;
1448 1448
 	q_vals[n_query_cols].val.str_val = pres->from_tag;
... ...
@@ -1451,7 +1451,7 @@ int update_contact_puadb(ua_pres_t *pres, str *contact)
1451 1451
 	/* we overwrite contact even if not changed */
1452 1452
 	db_cols[n_update_cols] = &str_remote_contact_col;
1453 1453
 	db_vals[n_update_cols].type = DB1_STR;
1454
-	db_vals[n_update_cols].nul = 0; 
1454
+	db_vals[n_update_cols].nul = 0;
1455 1455
 	db_vals[n_update_cols].val.str_val.s = contact->s;
1456 1456
 	db_vals[n_update_cols].val.str_val.len = contact->len;
1457 1457
 	n_update_cols++;
... ...
@@ -1482,7 +1482,7 @@ int update_contact_puadb(ua_pres_t *pres, str *contact)
1482 1482
 
1483 1483
 /******************************************************************************/
1484 1484
 
1485
-int update_version_puadb(ua_pres_t *pres) 
1485
+int update_version_puadb(ua_pres_t *pres)
1486 1486
 
1487 1487
 {
1488 1488
 	db_key_t q_cols[3], db_cols[1];
... ...
@@ -1496,19 +1496,19 @@ int update_version_puadb(ua_pres_t *pres)
1496 1496
 	}
1497 1497
 
1498 1498
 	/* cols and values used for search query */
1499
-	q_cols[n_query_cols] = &str_call_id_col;	
1499
+	q_cols[n_query_cols] = &str_call_id_col;
1500 1500
 	q_vals[n_query_cols].type = DB1_STR;
1501 1501
 	q_vals[n_query_cols].nul = 0;
1502 1502
 	q_vals[n_query_cols].val.str_val = pres->call_id;
1503 1503
 	n_query_cols++;
1504 1504
 
1505
-	q_cols[n_query_cols] = &str_to_tag_col;	
1505
+	q_cols[n_query_cols] = &str_to_tag_col;
1506 1506
 	q_vals[n_query_cols].type = DB1_STR;
1507 1507
 	q_vals[n_query_cols].nul = 0;
1508 1508
 	q_vals[n_query_cols].val.str_val = pres->to_tag;
1509 1509
 	n_query_cols++;
1510 1510
 
1511
-	q_cols[n_query_cols] = &str_from_tag_col;	
1511
+	q_cols[n_query_cols] = &str_from_tag_col;
1512 1512
 	q_vals[n_query_cols].type = DB1_STR;
1513 1513
 	q_vals[n_query_cols].nul = 0;
1514 1514
 	q_vals[n_query_cols].val.str_val = pres->from_tag;
... ...
@@ -1611,14 +1611,14 @@ list_entry_t *get_subs_list_puadb(str *did)
1611 1611
 
1612 1612
 			if ((tmp_str = (str *)pkg_malloc(sizeof(str))) == NULL)
1613 1613
 			{
1614
-				LM_ERR("out of private memory\n");
1614
+				PKG_MEM_ERROR;
1615 1615
 				pua_dbf.free_result(pua_db, res);
1616 1616
 				return list;
1617 1617
 			}
1618 1618
 			if ((tmp_str->s = (char *)pkg_malloc(sizeof(char) * strng.len + 1)) == NULL)
1619 1619
 			{
1620 1620
 				pkg_free(tmp_str);
1621
-				LM_ERR("out of private memory\n");
1621