Browse code

- created an event list, so that new events are added easily (still to do : export the add_event function to be used from other modules)

git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@2136 689a6050-402a-0410-94f2-e92a70836424

Anca Vamanu authored on 03/05/2007 17:34:40
Showing 9 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,282 @@
1
+/*
2
+ * $Id: add_events.c  2007-05-03 15:05:20Z anca_vamanu $
3
+ *
4
+ * pua module - presence user agent module
5
+ *
6
+ * Copyright (C) 2007 Voice Sistem S.R.L.
7
+ *
8
+ * This file is part of openser, a free SIP server.
9
+ *
10
+ * openser is free software; you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation; either version 2 of the License, or
13
+ * (at your option) any later version
14
+ *
15
+ * openser is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License 
21
+ * along with this program; if not, write to the Free Software 
22
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
+ *
24
+ *	initial version 2007-05-03 (anca)
25
+ */
26
+#include <stdio.h>
27
+#include <stdlib.h>
28
+#include <string.h>
29
+#include <libxml/parser.h>
30
+
31
+#include "event_list.h"
32
+#include "add_events.h"
33
+
34
+xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name,
35
+															const char *ns)
36
+{
37
+	xmlNodePtr cur = node;
38
+	while (cur) {
39
+		xmlNodePtr match = NULL;
40
+		if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0) {
41
+			if (!ns || (cur->ns && xmlStrcasecmp(cur->ns->prefix,
42
+							(unsigned char*)ns) == 0))
43
+				return cur;
44
+		}
45
+		match = xmlNodeGetNodeByName(cur->children, name, ns);
46
+		if (match)
47
+			return match;
48
+		cur = cur->next;
49
+	}
50
+	return NULL;
51
+}
52
+xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name)
53
+{
54
+	xmlAttrPtr attr = node->properties;
55
+	while (attr) {
56
+		if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0)
57
+			return attr;
58
+		attr = attr->next;
59
+	}
60
+	return NULL;
61
+}
62
+
63
+char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name)
64
+{
65
+	xmlAttrPtr attr = xmlNodeGetAttrByName(node, name);
66
+	if (attr)
67
+		return (char*)xmlNodeGetContent(attr->children);
68
+	else
69
+		return NULL;
70
+}
71
+
72
+
73
+int pua_add_events()
74
+{
75
+	/* add presence */
76
+	if(add_pua_event(PRESENCE_EVENT, "presence", "application/pidf+xml", 
77
+				pres_process_body)< 0)
78
+	{
79
+		LOG(L_ERR, "PUA: pua_add_events: ERROR while adding event presence\n");
80
+		return -1;
81
+	}
82
+
83
+	/* add dialog;sla */
84
+	if(add_pua_event(BLA_EVENT, "dialog;sla", "application/dialog-info+xml",
85
+				bla_process_body)< 0)
86
+	{
87
+		LOG(L_ERR, "PUA: pua_add_events: ERROR while adding event presence\n");
88
+		return -1;
89
+	}
90
+
91
+	/* add message-summary*/
92
+	if(add_pua_event(MSGSUM_EVENT, "message-summary", 
93
+				"application/simple-message-summary", mwi_process_body)< 0)
94
+	{
95
+		LOG(L_ERR, "PUA: pua_add_events: ERROR while adding event presence\n");
96
+		return -1;
97
+	}
98
+	
99
+	/* add presence;winfo */
100
+	if(add_pua_event(PWINFO_EVENT, "presence;winfo", NULL, NULL)< 0)
101
+	{
102
+		LOG(L_ERR, "PUA: pua_add_events: ERROR while adding event presence\n");
103
+		return -1;
104
+	}
105
+	
106
+	return 0;
107
+
108
+}	
109
+
110
+int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str* tuple)
111
+{
112
+
113
+	xmlDocPtr doc= NULL;
114
+	xmlNodePtr node= NULL;
115
+	char* tuple_id= NULL, *person_id= NULL;
116
+	int tuple_id_len= 0;
117
+	char buf[50];
118
+	str* body= NULL;
119
+
120
+	tuple= NULL;
121
+	doc= xmlParseMemory(publ->body->s, publ->body->len );
122
+	if(doc== NULL)
123
+	{
124
+		LOG(L_ERR, "PUA: pres_process_body: ERROR while parsing xml memory\n");
125
+		goto error;
126
+	}
127
+
128
+	node= xmlNodeGetNodeByName(doc->children, "tuple", NULL);
129
+	if(node == NULL)
130
+	{
131
+		LOG(L_ERR, "PUA: pres_process_body:ERROR while extracting tuple node\n");
132
+		goto error;
133
+	}
134
+	tuple_id= xmlNodeGetAttrContentByName(node, "id");
135
+	if(tuple_id== NULL)
136
+	{	
137
+		tuple_id= buf;
138
+		tuple_id_len= sprintf(tuple_id, "%p", publ);
139
+		tuple_id[tuple_id_len]= '\0'; 
140
+		
141
+		if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id))
142
+		{
143
+			LOG(L_ERR, "PUA: pres_process_body:ERROR while extracting xml"
144
+						" node\n");
145
+			goto error;
146
+		}
147
+	}
148
+	else
149
+	{
150
+		strcpy(buf, tuple_id);
151
+		xmlFree(tuple_id);
152
+		tuple_id= buf;
153
+		tuple_id_len= strlen(tuple_id);
154
+	}	
155
+	node= xmlNodeGetNodeByName(doc->children, "person", NULL);
156
+	if(node)
157
+	{
158
+		DBG("PUA: pres_process_body:found person node\n");
159
+		person_id= xmlNodeGetAttrContentByName(node, "id");
160
+		if(person_id== NULL)
161
+		{	
162
+			if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id))
163
+			{
164
+				LOG(L_ERR, "PUA:pres_process_body:ERROR while extracting xml"
165
+						" node\n");
166
+				goto error;
167
+			}
168
+		}
169
+		else
170
+		{
171
+			xmlFree(person_id);
172
+		}
173
+	}	
174
+	body= (str*)pkg_malloc(sizeof(str));
175
+	if(body== NULL)
176
+	{
177
+		LOG(L_ERR, "PUA:pres_process_body ERROR NO more memory left\n");
178
+		goto error;
179
+	}
180
+	memset(body, 0, sizeof(str));
181
+	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, &body->len, 1);	
182
+	if(body->s== NULL || body->len== 0)
183
+	{
184
+		LOG(L_ERR, "PUA: pres_process_body: ERROR while dumping xml format\n");
185
+		goto error;
186
+	}	
187
+	xmlFreeDoc(doc);
188
+	doc= NULL;
189
+	
190
+	tuple= (str*)pkg_malloc(sizeof(str));
191
+	if(tuple== NULL)
192
+	{
193
+		LOG(L_ERR, "PUA: pres_process_body: ERROR No more memory\n");
194
+		goto error;
195
+	}
196
+	tuple->s= tuple_id;
197
+	tuple->len= tuple_id_len;
198
+	
199
+	*fin_body= body;
200
+	xmlMemoryDump();
201
+	xmlCleanupParser();
202
+	return 1;
203
+
204
+error:
205
+	if(doc)
206
+		xmlFreeDoc(doc);
207
+	if(body)
208
+		pkg_free(body);
209
+	return -1;
210
+
211
+}	
212
+
213
+int bla_process_body(publ_info_t* publ, str** fin_body, int ver, str* tuple)
214
+{
215
+	xmlNodePtr node= NULL;
216
+	xmlDocPtr doc= NULL;
217
+	char* version;
218
+	str* body= NULL;
219
+	int len;
220
+	str* init_body;
221
+
222
+	init_body= publ->body;
223
+
224
+	DBG("PUA: bla_process_body: start\n");
225
+	doc= xmlParseMemory(init_body->s, init_body->len );
226
+	if(doc== NULL)
227
+	{
228
+		LOG(L_ERR, "PUA: bla_process_body: ERROR while parsing xml memory\n");
229
+		goto error;
230
+	}
231
+	/* change version and state*/
232
+	node= xmlNodeGetNodeByName(doc->children, "dialog-info", NULL);
233
+	if(node == NULL)
234
+	{
235
+		LOG(L_ERR, "PUA: bla_process_body: ERROR while extracting dialog-info node\n");
236
+		goto error;
237
+	}
238
+	version= int2str(ver,&len);
239
+	version[len]= '\0';
240
+
241
+	if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL)
242
+	{
243
+		LOG(L_ERR, "PUA: bla_process_body: ERROR while setting version attribute\n");
244
+		goto error;	
245
+	}
246
+	body= (str*)pkg_malloc(sizeof(str));
247
+	if(body== NULL)
248
+	{
249
+		LOG(L_ERR, "PUA: bla_process_body: ERROR NO more memory left\n");
250
+		goto error;
251
+	}
252
+	memset(body, 0, sizeof(str));
253
+	xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);	
254
+
255
+	xmlFreeDoc(doc);
256
+	doc= NULL;
257
+	*fin_body= body;	
258
+	if(*fin_body== NULL)
259
+		DBG("PUA: bla_process_body: NULL fin_body\n");
260
+
261
+	xmlMemoryDump();
262
+	xmlCleanupParser();
263
+	DBG("PUA: bla_process_body: successful\n");
264
+	return 1;
265
+
266
+error:
267
+	if(doc)
268
+		xmlFreeDoc(doc);
269
+	if(body)
270
+		pkg_free(body);
271
+	
272
+	xmlMemoryDump();
273
+	xmlCleanupParser();
274
+	return -1;
275
+}
276
+
277
+int mwi_process_body(publ_info_t* publ, str** fin_body, int ver, str* tuple)
278
+{
279
+	*fin_body= publ->body;
280
+	return 0;
281
+}
282
+
0 283
new file mode 100644
... ...
@@ -0,0 +1,42 @@
1
+/*
2
+ * $Id: add_events.h  2007-05-03 15:05:20Z anca_vamanu $
3
+ *
4
+ * pua module - presence user agent module
5
+ *
6
+ * Copyright (C) 2007 Voice Sistem S.R.L.
7
+ *
8
+ * This file is part of openser, a free SIP server.
9
+ *
10
+ * openser is free software; you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation; either version 2 of the License, or
13
+ * (at your option) any later version
14
+ *
15
+ * openser is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License 
21
+ * along with this program; if not, write to the Free Software 
22
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
+ *
24
+ *	initial version 2007-05-03 (anca)
25
+ */
26
+#ifndef _PUA_ADD_EV_H_
27
+#define _PUA_ADD_EV_H_
28
+
29
+#include "send_publish.h"
30
+#include "../../str.h"
31
+
32
+/*
33
+ *  should return:   0  if not changed ( fin_body points to publ->body)
34
+ *                   1  if changed ( must be freed)	
35
+ * */
36
+int pua_add_events();
37
+
38
+int pres_process_body(struct publ_info* publ, str** fin_body, int ver, str* tuple);
39
+int bla_process_body (struct publ_info* publ, str** fin_body, int ver, str* tuple);
40
+int mwi_process_body (struct publ_info* publ, str** fin_body, int ver, str* tuple);
41
+
42
+#endif
0 43
new file mode 100644
... ...
@@ -0,0 +1,157 @@
1
+/*
2
+ * $Id: event_list.c  2007-05-03 15:05:20Z anca_vamanu $
3
+ *
4
+ * pua module - presence user agent module
5
+ *
6
+ * Copyright (C) 2007 Voice Sistem S.R.L.
7
+ *
8
+ * This file is part of openser, a free SIP server.
9
+ *
10
+ * openser is free software; you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation; either version 2 of the License, or
13
+ * (at your option) any later version
14
+ *
15
+ * openser is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License 
21
+ * along with this program; if not, write to the Free Software 
22
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
+ *
24
+ *	initial version 2007-05-03 (anca)
25
+ */
26
+#include <stdio.h>
27
+#include <stdlib.h>
28
+#include <string.h>
29
+
30
+#include "../../str.h"
31
+#include "send_publish.h"
32
+#include "../../mem/shm_mem.h"
33
+#include "event_list.h"
34
+
35
+pua_event_t* init_pua_evlist()
36
+{
37
+	pua_event_t* list= NULL;
38
+
39
+	list= (pua_event_t*)shm_malloc(sizeof(pua_event_t));
40
+	if(list== NULL)
41
+	{
42
+		LOG(L_ERR, "PUA: init_pua_evlist: ERROR no more share memory\n");
43
+		return NULL;
44
+	}
45
+	list->next= NULL;
46
+	
47
+	return list;
48
+
49
+}
50
+
51
+int add_pua_event(int ev_flag, char* name, char* content_type,
52
+		evs_process_body_t* process_body)
53
+{
54
+		
55
+	pua_event_t* event= NULL;
56
+	int size;
57
+	int name_len;
58
+	int ctype_len= 0;
59
+	str str_name;	
60
+
61
+	name_len= strlen(name);
62
+	str_name.s= name;
63
+	str_name.len= name_len;
64
+
65
+	if(contains_pua_event(&str_name))
66
+	{
67
+		DBG("PUA: add_pua_event: Event already exists\n");
68
+		return 0;
69
+	}
70
+	if(content_type)
71
+		ctype_len= strlen(content_type);
72
+
73
+	size= sizeof(pua_event_t)+ (name_len+ ctype_len)* sizeof(char);
74
+
75
+	event= (pua_event_t*)shm_malloc(size);
76
+	if(event== NULL)
77
+	{
78
+		LOG(L_ERR, "PUA: add_pua_event: ERROR No more share memory\n");
79
+		return -1;
80
+	}	
81
+	memset(event, 0, size);
82
+	size= sizeof(pua_event_t);
83
+
84
+	event->name.s= (char*)event+ size;
85
+	memcpy(event->name.s, name, name_len);
86
+	event->name.len= name_len;
87
+	size+= name_len;
88
+			
89
+	if(content_type)
90
+	{
91
+		event->content_type.s= (char*)event+ size;
92
+		memcpy(event->content_type.s, content_type, ctype_len);
93
+		event->content_type.len= ctype_len;
94
+		size+= ctype_len;		
95
+	}
96
+
97
+	event->process_body= process_body;
98
+	event->ev_flag= ev_flag;
99
+
100
+	event->next= pua_evlist->next;
101
+	pua_evlist->next= event;
102
+
103
+	return 0;
104
+}	
105
+
106
+pua_event_t* contains_pua_event(str* name)
107
+{
108
+	pua_event_t* event;
109
+	event= pua_evlist->next;
110
+
111
+	while(event)
112
+	{
113
+		if(event->name.len== name->len &&
114
+				strncmp(event->name.s, name->s, name->len)== 0)
115
+		{
116
+			return event;	
117
+		}
118
+		event= event->next;
119
+	}	
120
+
121
+	return NULL;	
122
+}
123
+
124
+pua_event_t* get_event(int ev_flag)
125
+{
126
+	pua_event_t* event;
127
+	event= pua_evlist->next;
128
+
129
+	while(event)
130
+	{
131
+		if(event->ev_flag== ev_flag)
132
+		{
133
+			return event;	
134
+		}
135
+		event= event->next;
136
+	}	
137
+	return NULL;	
138
+}
139
+
140
+
141
+void destroy_pua_evlist()
142
+{
143
+	pua_event_t* e1, *e2;
144
+
145
+	if(pua_evlist)
146
+	{
147
+		e1= pua_evlist->next;
148
+		while(e1)
149
+		{
150
+			e2= e1->next;
151
+			shm_free(e1);
152
+			e1= e2;
153
+		}	
154
+		shm_free(pua_evlist);
155
+	}	
156
+
157
+}	
0 158
new file mode 100644
... ...
@@ -0,0 +1,62 @@
1
+/*
2
+ * $Id: event_list.h  2007-05-03 15:05:20Z anca_vamanu $
3
+ *
4
+ * pua module - presence user agent module
5
+ *
6
+ * Copyright (C) 2007 Voice Sistem S.R.L.
7
+ *
8
+ * This file is part of openser, a free SIP server.
9
+ *
10
+ * openser is free software; you can redistribute it and/or modify
11
+ * it under the terms of the GNU General Public License as published by
12
+ * the Free Software Foundation; either version 2 of the License, or
13
+ * (at your option) any later version
14
+ *
15
+ * openser is distributed in the hope that it will be useful,
16
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
+ * GNU General Public License for more details.
19
+ *
20
+ * You should have received a copy of the GNU General Public License 
21
+ * along with this program; if not, write to the Free Software 
22
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
+ *
24
+ *	initial version  2007-05-03 (anca)
25
+ */
26
+
27
+#ifndef _PUA_EVLIST_H_
28
+#define _PUA_EVLIST_H_
29
+
30
+#include "../../str.h"
31
+//#include "send_publish.h"
32
+
33
+struct publ_info;
34
+
35
+typedef int (evs_process_body_t)(struct publ_info* , str** , int , str* );
36
+
37
+typedef struct pua_event
38
+{
39
+	int ev_flag;                   
40
+	str name;
41
+	str content_type;         /* default content type for that event*/	
42
+	evs_process_body_t* process_body;
43
+	struct pua_event* next;
44
+
45
+}pua_event_t;
46
+
47
+extern pua_event_t* pua_evlist;
48
+
49
+pua_event_t* init_pua_evlist();
50
+
51
+int add_pua_event(int ev_flag, char* name, char* content_type,
52
+		evs_process_body_t* process_body);
53
+
54
+typedef int (*add_pua_event_t)(pua_event_t* event);
55
+
56
+pua_event_t* contains_pua_event(str* name);
57
+
58
+pua_event_t* get_event(int ev_flag);
59
+
60
+void destroy_pua_evlist();
61
+
62
+#endif
... ...
@@ -32,6 +32,11 @@
32 32
 #include "../../str.h"
33 33
 #include "../../lock_ops.h"
34 34
 
35
+#define PRESENCE_EVENT      1<<0
36
+#define PWINFO_EVENT        1<<1
37
+#define BLA_EVENT			1<<2
38
+#define MSGSUM_EVENT        1<<3
39
+
35 40
 #define UL_PUBLISH					1<<0
36 41
 #define BLA_PUBLISH					1<<1
37 42
 #define BLA_TERM_PUBLISH			1<<2
... ...
@@ -42,12 +47,6 @@
42 47
 #define MI_PUBLISH					1<<7
43 48
 #define MI_SUBSCRIBE				1<<8
44 49
 
45
-
46
-#define PRESENCE_EVENT      1<<0
47
-#define PWINFO_EVENT        1<<1
48
-#define BLA_EVENT			1<<2
49
-#define MSGSUM_EVENT        1<<3
50
-
51 50
 #define NO_UPDATEDB_FLAG	1<<0
52 51
 #define UPDATEDB_FLAG		1<<1
53 52
 #define INSERTDB_FLAG		1<<2
... ...
@@ -111,40 +110,6 @@ ua_pres_t* get_dialog(ua_pres_t* dialog, unsigned int hash_code);
111 110
 
112 111
 typedef int  (*query_dialog_t)(ua_pres_t* presentity);
113 112
 
114
-static inline int get_event_name(int ev_flag, str* event)
115
-{
116
-	switch(ev_flag)
117
-	{
118
-		case(PRESENCE_EVENT):{
119
-								event->s= "presence";
120
-								event->len= 8;
121
-								break;
122
-							}
123
-		case(PWINFO_EVENT):{
124
-								event->s= "presence;winfo";
125
-								event->len= 14;
126
-								break;
127
-							}
128
-		case(BLA_EVENT):    {
129
-								event->s= "dialog;sla";
130
-								event->len= 10;
131
-								break;
132
-							}
133
-		case(MSGSUM_EVENT): {
134
-								event->s= "message-summary";
135
-								event->len= 15;
136
-								break;
137
-							}
138
-		default:{
139
-					LOG(L_ERR, "PUA: get_event_name: Unknown event flag\n");
140
-					return -1;
141
-				}	
142
-	}
143
-	return 0;
144
-			 
145
-}	
146
-
147
-
148 113
 static inline int get_event_flag(str* event)
149 114
 {
150 115
     switch (event->len) {
... ...
@@ -48,6 +48,8 @@
48 48
 #include "send_subscribe.h"
49 49
 #include "pua_bind.h"
50 50
 #include "pua_callback.h"
51
+#include "event_list.h"
52
+#include "add_events.h"
51 53
 
52 54
 MODULE_VERSION
53 55
 #define PUA_TABLE_VERSION 3
... ...
@@ -62,6 +64,7 @@ str db_url = {0, 0};
62 64
 char* db_table= "pua";
63 65
 int update_period= 100;
64 66
 int startup_time = 0;
67
+pua_event_t* pua_evlist= NULL;
65 68
 
66 69
 /* database connection */
67 70
 db_con_t *pua_db = NULL;
... ...
@@ -210,6 +213,17 @@ static int mod_init(void)
210 213
 		LOG(L_ERR, "PUA:mod_init: ERROR: callbacks initialization failed\n");
211 214
         return -1;
212 215
     }
216
+	pua_evlist= init_pua_evlist();
217
+	if(pua_evlist< 0)
218
+	{
219
+		LOG(L_ERR, "PUA:mod_init: ERROR when initializing pua_evlist\n");
220
+		return -1;
221
+	}
222
+	if(pua_add_events()< 0)
223
+	{
224
+		LOG(L_ERR, "PUA:mod_init: ERROR while adding events\n");
225
+		return -1;
226
+	}
213 227
 
214 228
 	startup_time = (int) time(NULL);
215 229
 	
... ...
@@ -222,6 +236,8 @@ static int mod_init(void)
222 236
 		pua_dbf.close(pua_db);
223 237
 	pua_db = NULL;
224 238
 
239
+	
240
+
225 241
 	return 0;
226 242
 }
227 243
 
... ...
@@ -269,6 +285,8 @@ static void destroy(void)
269 285
 
270 286
 	if(pua_db)
271 287
 		pua_dbf.close(pua_db);
288
+	if(pua_evlist)
289
+		destroy_pua_evlist();
272 290
 
273 291
 	return ;
274 292
 }
... ...
@@ -600,7 +618,7 @@ int update_pua(ua_pres_t* p, unsigned int hash_code)
600 618
 	if(p->watcher_uri== NULL)
601 619
 	{
602 620
 		str met= {"PUBLISH", 7};
603
-		str_hdr = publ_build_hdr(expires, p->event, NULL, &p->etag, NULL, 0);
621
+		str_hdr = publ_build_hdr(expires, get_event(p->event), NULL, &p->etag, NULL, 0);
604 622
 		if(str_hdr == NULL)
605 623
 		{
606 624
 			LOG(L_ERR, "PUA: update_pua: ERROR while building extra_headers\n");
... ...
@@ -41,57 +41,10 @@
41 41
 #include "hash.h"
42 42
 #include "send_publish.h"
43 43
 #include "pua_callback.h"
44
+#include "event_list.h"
44 45
 
45 46
 extern struct tm_binds tmb;
46 47
 
47
-int process_body(publ_info_t* publ, str** fin_body, int ver, str* tuple);
48
-/*
49
- *  should return:   0  if not changed ( fin_body points to publ->body)
50
- *                   1  if changed ( must be freed)	
51
- * */
52
-
53
-int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str* tuple);
54
-int bla_process_body (str* init_body, str** fin_body, int ver);
55
-int mwi_process_body (str* init_body, str** fin_body, int ver);
56
-
57
-xmlNodePtr xmlNodeGetNodeByName(xmlNodePtr node, const char *name,
58
-															const char *ns)
59
-{
60
-	xmlNodePtr cur = node;
61
-	while (cur) {
62
-		xmlNodePtr match = NULL;
63
-		if (xmlStrcasecmp(cur->name, (unsigned char*)name) == 0) {
64
-			if (!ns || (cur->ns && xmlStrcasecmp(cur->ns->prefix,
65
-							(unsigned char*)ns) == 0))
66
-				return cur;
67
-		}
68
-		match = xmlNodeGetNodeByName(cur->children, name, ns);
69
-		if (match)
70
-			return match;
71
-		cur = cur->next;
72
-	}
73
-	return NULL;
74
-}
75
-xmlAttrPtr xmlNodeGetAttrByName(xmlNodePtr node, const char *name)
76
-{
77
-	xmlAttrPtr attr = node->properties;
78
-	while (attr) {
79
-		if (xmlStrcasecmp(attr->name, (unsigned char*)name) == 0)
80
-			return attr;
81
-		attr = attr->next;
82
-	}
83
-	return NULL;
84
-}
85
-
86
-char *xmlNodeGetAttrContentByName(xmlNodePtr node, const char *name)
87
-{
88
-	xmlAttrPtr attr = xmlNodeGetAttrByName(node, name);
89
-	if (attr)
90
-		return (char*)xmlNodeGetContent(attr->children);
91
-	else
92
-		return NULL;
93
-}
94
-
95 48
 void print_hentity(ua_pres_t* h)
96 49
 {
97 50
 	DBG("\tpresentity:\n");
... ...
@@ -104,7 +57,7 @@ void print_hentity(ua_pres_t* h)
104 57
 		DBG("\ttuple_id: %.*s\n", h->tuple_id.len, h->tuple_id.s);
105 58
 }	
106 59
 
107
-str* publ_build_hdr(int expires, int ev, str* content_type, str* etag,
60
+str* publ_build_hdr(int expires, pua_event_t* ev, str* content_type, str* etag,
108 61
 		str* extra_headers, int is_body)
109 62
 {
110 63
 	static char buf[3000];
... ...
@@ -112,7 +65,7 @@ str* publ_build_hdr(int expires, int ev, str* content_type, str* etag,
112 65
 	char* expires_s = NULL;
113 66
 	int len = 0;
114 67
 	int t= 0;
115
-	str event= {0, 0};
68
+	str ctype;
116 69
 
117 70
 	DBG("PUA: publ_build_hdr ...\n");
118 71
 	str_hdr =(str*) pkg_malloc(sizeof(str));
... ...
@@ -126,17 +79,10 @@ str* publ_build_hdr(int expires, int ev, str* content_type, str* etag,
126 79
 	str_hdr->s = buf;
127 80
 	str_hdr->len= 0;
128 81
 
129
-	get_event_name(ev, &event);	
130
-	if(event.s== NULL)
131
-	{
132
-		LOG(L_ERR, "PUA: publ_build_hdr:ERROR NULL event parameter\n");
133
-		goto error;
134
-	}
135
-
136 82
 	memcpy(str_hdr->s ,"Event: ", 7);
137 83
 	str_hdr->len = 7;
138
-	memcpy(str_hdr->s+ str_hdr->len, event.s, event.len);
139
-	str_hdr->len+= event.len;
84
+	memcpy(str_hdr->s+ str_hdr->len, ev->name.s, ev->name.len);
85
+	str_hdr->len+= ev->name.len;
140 86
 	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
141 87
 	str_hdr->len += CRLF_LEN;
142 88
 	
... ...
@@ -175,13 +121,18 @@ str* publ_build_hdr(int expires, int ev, str* content_type, str* etag,
175 121
 	{	
176 122
 		if(content_type== NULL || content_type->s== NULL || content_type->len== 0)
177 123
 		{
178
-			LOG(L_ERR, "PUA: publ_build_hdr:ERROR NULL content_type parameter\n");
179
-			goto error;
124
+			ctype= ev->content_type; /* use event default value */ 
180 125
 		}
126
+		else
127
+		{	
128
+			ctype.s=   content_type->s;
129
+			ctype.len= content_type->len;
130
+		}
131
+
181 132
 		memcpy(str_hdr->s+str_hdr->len,"Content-Type: ", 14);
182 133
 		str_hdr->len += 14;
183
-		memcpy(str_hdr->s+str_hdr->len, content_type->s, content_type->len);
184
-		str_hdr->len += content_type->len;
134
+		memcpy(str_hdr->s+str_hdr->len, ctype.s, ctype.len);
135
+		str_hdr->len += ctype.len;
185 136
 		memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
186 137
 		str_hdr->len += CRLF_LEN;
187 138
 	}
... ...
@@ -195,9 +146,6 @@ str* publ_build_hdr(int expires, int ev, str* content_type, str* etag,
195 146
 	
196 147
 	return str_hdr;
197 148
 
198
-error:
199
-	pkg_free(str_hdr);
200
-	return NULL;
201 149
 }
202 150
 
203 151
 void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
... ...
@@ -466,8 +414,9 @@ int send_publish( publ_info_t* publ )
466 414
 	int ver= 0;
467 415
 	int result;
468 416
 	int ret_code= 0;
417
+	pua_event_t* ev= NULL;
469 418
 
470
-	DBG("\n\n\nPUA: send_publish for: uri=%.*s\n", publ->pres_uri->len,
419
+	DBG("PUA: send_publish for: uri=%.*s\n", publ->pres_uri->len,
471 420
 			publ->pres_uri->s );
472 421
 	
473 422
 
... ...
@@ -533,11 +482,20 @@ insert:
533 482
 		lock_release(&HashT->p_records[hash_code].lock);
534 483
 	}
535 484
 
485
+	/* get event from list */
486
+
487
+	ev= get_event(publ->event);
488
+	if(ev== NULL)
489
+	{
490
+		LOG(L_ERR, "PUA:send_publish: ERROR event not found in list\n");
491
+		goto error;
492
+	}	
493
+
536 494
     /* handle body */
537 495
 
538 496
 	if(publ->body && publ->body->s)
539 497
 	{
540
-		ret_code= process_body(publ, &body, ver, tuple_id);
498
+		ret_code= ev->process_body(publ, &body, ver, tuple_id);
541 499
 		if( ret_code< 0 || body== NULL)
542 500
 		{
543 501
 			LOG(L_ERR, "PUA:send_publish: ERROR while processing body\n");
... ...
@@ -647,7 +605,7 @@ send_publish:
647 605
 	
648 606
 	if(publ->flag & UPDATE_TYPE)
649 607
 		DBG("PUA:send_publish: etag:%.*s\n", etag.len, etag.s);
650
-	str_hdr = publ_build_hdr((publ->expires< 0)?3600:publ->expires, publ->event, &publ->content_type, 
608
+	str_hdr = publ_build_hdr((publ->expires< 0)?3600:publ->expires, ev, &publ->content_type, 
651 609
 				(publ->flag & UPDATE_TYPE)?&etag:NULL, publ->extra_headers, (body)?1:0);
652 610
 
653 611
 	if(str_hdr == NULL)
... ...
@@ -722,191 +680,4 @@ error:
722 680
 	return -1;
723 681
 }
724 682
 
725
-int process_body(publ_info_t* publ, str** fin_body, int ver, str* tuple)
726
-{
727
-	tuple= NULL;
728
-	switch(publ->event)
729
-	{
730
-		case(PRESENCE_EVENT): {
731
-			return pres_process_body(publ, fin_body, ver, tuple);
732
-		}  
733
-		case(BLA_EVENT): {
734
-			return bla_process_body(publ->body, fin_body, ver);
735
-		}  
736
-		case(MSGSUM_EVENT): {
737
-			return mwi_process_body(publ->body, fin_body, ver);
738
-		}  
739
-	}
740
-	return -1;
741
-}
742
-
743
-int pres_process_body(publ_info_t* publ, str** fin_body, int ver, str* tuple)
744
-{
745
-
746
-	xmlDocPtr doc= NULL;
747
-	xmlNodePtr node= NULL;
748
-	char* tuple_id= NULL, *person_id= NULL;
749
-	int tuple_id_len= 0;
750
-	char buf[50];
751
-	str* body= NULL;
752
-
753
-	tuple= NULL;
754
-	doc= xmlParseMemory(publ->body->s, publ->body->len );
755
-	if(doc== NULL)
756
-	{
757
-		LOG(L_ERR, "PUA: pres_process_body: ERROR while parsing xml memory\n");
758
-		goto error;
759
-	}
760
-
761
-	node= xmlNodeGetNodeByName(doc->children, "tuple", NULL);
762
-	if(node == NULL)
763
-	{
764
-		LOG(L_ERR, "PUA: pres_process_body:ERROR while extracting tuple node\n");
765
-		goto error;
766
-	}
767
-	tuple_id= xmlNodeGetAttrContentByName(node, "id");
768
-	if(tuple_id== NULL)
769
-	{	
770
-		tuple_id= buf;
771
-		tuple_id_len= sprintf(tuple_id, "%p", publ);
772
-		tuple_id[tuple_id_len]= '\0'; 
773
-		
774
-		if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id))
775
-		{
776
-			LOG(L_ERR, "PUA: pres_process_body:ERROR while extracting xml"
777
-						" node\n");
778
-			goto error;
779
-		}
780
-	}
781
-	else
782
-	{
783
-		strcpy(buf, tuple_id);
784
-		xmlFree(tuple_id);
785
-		tuple_id= buf;
786
-		tuple_id_len= strlen(tuple_id);
787
-	}	
788
-	node= xmlNodeGetNodeByName(doc->children, "person", NULL);
789
-	if(node)
790
-	{
791
-		DBG("PUA: pres_process_body:found person node\n");
792
-		person_id= xmlNodeGetAttrContentByName(node, "id");
793
-		if(person_id== NULL)
794
-		{	
795
-			if(!xmlNewProp(node, BAD_CAST "id", BAD_CAST tuple_id))
796
-			{
797
-				LOG(L_ERR, "PUA:pres_process_body:ERROR while extracting xml"
798
-						" node\n");
799
-				goto error;
800
-			}
801
-		}
802
-		else
803
-		{
804
-			xmlFree(person_id);
805
-		}
806
-	}	
807
-	body= (str*)pkg_malloc(sizeof(str));
808
-	if(body== NULL)
809
-	{
810
-		LOG(L_ERR, "PUA:pres_process_body ERROR NO more memory left\n");
811
-		goto error;
812
-	}
813
-	memset(body, 0, sizeof(str));
814
-	xmlDocDumpFormatMemory(doc,(xmlChar**)(void*)&body->s, &body->len, 1);	
815
-	if(body->s== NULL || body->len== 0)
816
-	{
817
-		LOG(L_ERR, "PUA: pres_process_body: ERROR while dumping xml format\n");
818
-		goto error;
819
-	}	
820
-	xmlFreeDoc(doc);
821
-	doc= NULL;
822
-	
823
-	tuple= (str*)pkg_malloc(sizeof(str));
824
-	if(tuple== NULL)
825
-	{
826
-		LOG(L_ERR, "PUA: pres_process_body: ERROR No more memory\n");
827
-		goto error;
828
-	}
829
-	tuple->s= tuple_id;
830
-	tuple->len= tuple_id_len;
831
-	
832
-	*fin_body= body;
833
-	xmlMemoryDump();
834
-	xmlCleanupParser();
835
-	return 1;
836
-
837
-error:
838
-	if(doc)
839
-		xmlFreeDoc(doc);
840
-	if(body)
841
-		pkg_free(body);
842
-	return -1;
843
-
844
-}	
845
-
846
-int bla_process_body(str* init_body, str** fin_body, int ver)
847
-{
848
-	xmlNodePtr node= NULL;
849
-	xmlDocPtr doc= NULL;
850
-	char* version;
851
-	str* body= NULL;
852
-	int len;
853
-
854
-	DBG("PUA: bla_process_body: start\n");
855
-	doc= xmlParseMemory(init_body->s, init_body->len );
856
-	if(doc== NULL)
857
-	{
858
-		LOG(L_ERR, "PUA: bla_process_body: ERROR while parsing xml memory\n");
859
-		goto error;
860
-	}
861
-	/* change version and state*/
862
-	node= xmlNodeGetNodeByName(doc->children, "dialog-info", NULL);
863
-	if(node == NULL)
864
-	{
865
-		LOG(L_ERR, "PUA: bla_process_body: ERROR while extracting dialog-info node\n");
866
-		goto error;
867
-	}
868
-	version= int2str(ver,&len);
869
-	version[len]= '\0';
870
-
871
-	if( xmlSetProp(node, (const xmlChar *)"version",(const xmlChar*)version)== NULL)
872
-	{
873
-		LOG(L_ERR, "PUA: bla_process_body: ERROR while setting version attribute\n");
874
-		goto error;	
875
-	}
876
-	body= (str*)pkg_malloc(sizeof(str));
877
-	if(body== NULL)
878
-	{
879
-		LOG(L_ERR, "PUA: bla_process_body: ERROR NO more memory left\n");
880
-		goto error;
881
-	}
882
-	memset(body, 0, sizeof(str));
883
-	xmlDocDumpFormatMemory(doc, (xmlChar**)(void*)&body->s, &body->len, 1);	
884
-
885
-	xmlFreeDoc(doc);
886
-	doc= NULL;
887
-	*fin_body= body;	
888
-	if(*fin_body== NULL)
889
-		DBG("PUA: bla_process_body: NULL fin_body\n");
890
-
891
-	xmlMemoryDump();
892
-	xmlCleanupParser();
893
-	DBG("PUA: bla_process_body: successful\n");
894
-	return 1;
895
-
896
-error:
897
-	if(doc)
898
-		xmlFreeDoc(doc);
899
-	if(body)
900
-		pkg_free(body);
901
-	
902
-	xmlMemoryDump();
903
-	xmlCleanupParser();
904
-	return -1;
905
-}
906
-
907
-int mwi_process_body(str* init_body, str** fin_body,  int ver)
908
-{
909
-	*fin_body= init_body;
910
-	return 0;
911
-}
912 683
 
... ...
@@ -29,6 +29,7 @@
29 29
 #include "../tm/tm_load.h"
30 30
 #include "../../str.h"
31 31
 #include "hash.h"
32
+#include "event_list.h"
32 33
 
33 34
 typedef int (publrpl_cb_t)(struct sip_msg* msg, void*  extra_param);
34 35
 
... ...
@@ -41,7 +42,7 @@ typedef struct publ_info
41 42
 	int flag;
42 43
 	int source_flag;
43 44
 	int event;   
44
-	str content_type;   // not needed on update expires (empty body), should be {0, 0}
45
+	str content_type;   /* optional field - only if different from event default */ 
45 46
 	str* etag;
46 47
 	str* extra_headers;
47 48
 	publrpl_cb_t* cbrpl;
... ...
@@ -58,6 +59,7 @@ typedef int (*send_publish_t)(publ_info_t* publ);
58 59
 int send_publish( publ_info_t* publ );
59 60
 void print_ua_pres(ua_pres_t* p);
60 61
 void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps);
61
-str* publ_build_hdr(int expires, int event,str* content_type, str* etag, str* extra_headers, int is_body);
62
+str* publ_build_hdr(int expires, pua_event_t* event, str* content_type, str* etag,
63
+		str* extra_headers, int is_body);
62 64
 
63 65
 #endif
... ...
@@ -41,6 +41,7 @@
41 41
 #include "pua.h"
42 42
 #include "send_subscribe.h"
43 43
 #include "pua_callback.h"
44
+#include "event_list.h"
44 45
 
45 46
 extern int default_expires;
46 47
 extern int min_expires;
... ...
@@ -61,6 +62,7 @@ str* subs_build_hdr(str* contact, int expires, int event)
61 62
 	static char buf[3000];
62 63
 	char* subs_expires= NULL;
63 64
 	int len= 1;
65
+	pua_event_t* ev;	
64 66
 
65 67
 	str_hdr= (str*)pkg_malloc(sizeof(str));
66 68
 	if(str_hdr== NULL)
... ...
@@ -70,31 +72,18 @@ str* subs_build_hdr(str* contact, int expires, int event)
70 72
 	}
71 73
 	memset(str_hdr, 0, sizeof(str));
72 74
 	str_hdr->s= buf;
73
-
74
-	if(event& PRESENCE_EVENT)
75
-	{	
76
-		memcpy(str_hdr->s ,"Event: presence", 15);
77
-		str_hdr->len = 15;
78
-	}
79
-	else
80
-	if(event& PWINFO_EVENT)	
81
-	{	
82
-		memcpy(str_hdr->s ,"Event: presence.winfo", 21);
83
-		str_hdr->len = 21;
84
-	}
85
-	else
86
-	if(event& BLA_EVENT)	
87
-	{	
88
-		memcpy(str_hdr->s ,"Event: dialog;sla", 17);
89
-		str_hdr->len = 17;
90
-	}
91
-	else
75
+	
76
+	ev= get_event(event);	
77
+	if(ev== NULL)
92 78
 	{
93
-		LOG(L_ERR, "PUA:subs_build_hdr:ERROR wrong event parameter: %d\n", event);
94
-		pkg_free(str_hdr);
95
-		return NULL;
79
+		LOG(L_ERR, "PUA: publ_build_hdr:ERROR while getting event from list\n");
80
+		goto error;
96 81
 	}
97 82
 
83
+	memcpy(str_hdr->s ,"Event: ", 7);
84
+	str_hdr->len = 7;
85
+	memcpy(str_hdr->s+ str_hdr->len, ev->name.s, ev->name.len);
86
+	str_hdr->len+= ev->name.len;
98 87
 	memcpy(str_hdr->s+str_hdr->len, CRLF, CRLF_LEN);
99 88
 	str_hdr->len += CRLF_LEN;
100 89
 	
... ...
@@ -131,6 +120,11 @@ str* subs_build_hdr(str* contact, int expires, int event)
131 120
 	str_hdr->s[str_hdr->len]= '\0';
132 121
 
133 122
 	return str_hdr;
123
+
124
+error:
125
+	if(str_hdr)
126
+		pkg_free(str_hdr);
127
+	return NULL;
134 128
 }	
135 129
 
136 130
 dlg_t* pua_build_dlg_t(ua_pres_t* presentity)