Browse code

- restructured the reply callback system for Publish to make it simetric with the one for Subscribe - updated the pua_xmpp and pua_mi to the changes - enabled calling registered callback functions for FAKED_REPLY also - updated the presence_mwi module to a previous change made in presence

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

Anca Vamanu authored on 13/08/2007 12:40:27
Showing 16 changed files
... ...
@@ -118,13 +118,14 @@ int mwi_add_events()
118 118
     event.content_type.s = "application/simple-message-summary";
119 119
     event.content_type.len = 34;
120 120
 
121
+	event.default_expires= 3600;
121 122
     event.type = PUBL_TYPE;
122
-    event.req_auth = 0;
123
+	event.req_auth = 0;
123 124
     event.apply_auth_nbody = 0;
124 125
     event.is_watcher_allowed = mwi_watcher_allowed;
125 126
     event.agg_nbody = 0;
126 127
     event.evs_publ_handl = mwi_publ_handl;
127
-
128
+	
128 129
     if (pres_add_event(&event) < 0) {
129 130
 	LOG(L_ERR, "presence_mwi: ERROR while adding event "
130 131
 	    "\"message-summary\"\n");
... ...
@@ -46,7 +46,7 @@ void print_ua_pres(ua_pres_t* p)
46 46
 	}	
47 47
 	else
48 48
 		DBG("\tetag= %.*s - len= %d\n", p->etag.len, p->etag.s, p->etag.len);
49
-	DBG("\texpires= %ld\n", p->expires- (int)time(NULL));
49
+	DBG("\texpires= %d\n", p->expires- (int)time(NULL));
50 50
 }	
51 51
 htable_t* new_htable()
52 52
 {
... ...
@@ -45,8 +45,9 @@
45 45
 #define XMPP_SUBSCRIBE		1<<4
46 46
 #define XMPP_INITIAL_SUBS   1<<5
47 47
 #define MI_PUBLISH			1<<6
48
-#define MI_SUBSCRIBE		1<<7
49
-#define RLS_SUBSCRIBE       1<<8
48
+#define MI_ASYN_PUBLISH     1<<7
49
+#define MI_SUBSCRIBE		1<<8
50
+#define RLS_SUBSCRIBE       1<<9
50 51
 
51 52
 #define NO_UPDATEDB_FLAG    1<<0
52 53
 #define UPDATEDB_FLAG       1<<1
... ...
@@ -58,11 +59,13 @@ typedef struct ua_pres{
58 59
 	str id;
59 60
     str* pres_uri;
60 61
 	int event;
61
-	time_t expires;
62
-	time_t desired_expires;
62
+	unsigned int expires;
63
+	unsigned int desired_expires;
63 64
 	int flag;
64 65
 	int db_flag;
66
+	void* cb_param;
65 67
 	struct ua_pres* next;
68
+	int ua_flag;
66 69
 	
67 70
 	/* publish */
68 71
 	str etag;
... ...
@@ -82,7 +85,8 @@ typedef struct ua_pres{
82 85
 	str* extra_headers;
83 86
 	str record_route;
84 87
 	str contact;
85
- /*?? should this be long? */
88
+
89
+	/*?? should this be long? */
86 90
 }ua_pres_t;
87 91
 
88 92
 typedef struct hash_entry
... ...
@@ -81,8 +81,8 @@ int send_subscribe(subs_info_t*);
81 81
 int send_publish(publ_info_t*);
82 82
 
83 83
 int update_pua(ua_pres_t* p, unsigned int hash_code);
84
-treq_cbparam_t* build_uppubl_cbparam(ua_pres_t* pres);
85 84
 ua_pres_t* build_upsubs_cbparam(ua_pres_t* pres);
85
+ua_pres_t* build_uppubl_cbparam(ua_pres_t* p);
86 86
 
87 87
 int db_store();
88 88
 int db_restore();
... ...
@@ -601,15 +601,17 @@ int update_pua(ua_pres_t* p, unsigned int hash_code)
601 601
 	if(p->watcher_uri== NULL)
602 602
 	{
603 603
 		str met= {"PUBLISH", 7};
604
-		treq_cbparam_t* cb_param;
604
+		ua_pres_t* cb_param;
605 605
 
606
-		str_hdr = publ_build_hdr(expires, get_event(p->event), NULL, &p->etag, NULL, 0);
606
+		str_hdr = publ_build_hdr(expires, get_event(p->event), NULL,
607
+				&p->etag, p->extra_headers, 0);
607 608
 		if(str_hdr == NULL)
608 609
 		{
609 610
 			LOG(L_ERR, "PUA: update_pua: ERROR while building extra_headers\n");
610 611
 			goto error;
611 612
 		}
612 613
 		DBG("PUA: update_pua: str_hdr:\n%.*s\n ", str_hdr->len, str_hdr->s);
614
+		
613 615
 		cb_param= build_uppubl_cbparam(p);
614 616
 		if(cb_param== NULL)
615 617
 		{
... ...
@@ -648,7 +650,7 @@ int update_pua(ua_pres_t* p, unsigned int hash_code)
648 650
 			goto error;
649 651
 		};
650 652
 	
651
-		str_hdr= subs_build_hdr(&p->contact, expires, p->event, p->extra_headers);
653
+		str_hdr= subs_build_hdr(&p->contact, expires,p->event,p->extra_headers);
652 654
 		if(str_hdr== NULL || str_hdr->s== NULL)
653 655
 		{
654 656
 			LOG(L_ERR, "PUA:update_pua: Error while building extra headers\n");
... ...
@@ -976,129 +978,58 @@ void db_update(unsigned int ticks,void *param)
976 978
 	return ;
977 979
 
978 980
 }	
979
-	
980
-treq_cbparam_t* build_uppubl_cbparam(ua_pres_t* pres)
981
-{
982
-	int size;
983
-	treq_cbparam_t* cb_param= NULL;
984
-	
985
-	size= sizeof(treq_cbparam_t)+ sizeof(str)*2+ (pres->pres_uri->len+ 
986
-		+ pres->id.len+ pres->etag.len+ pres->tuple_id.len)*sizeof(char); 
987 981
 
988
-	DBG("PUA: build_uppubl_cbparam: before allocating size= %d\n", size);
989
-	cb_param= (treq_cbparam_t*)shm_malloc(size);
982
+ua_pres_t* build_uppubl_cbparam(ua_pres_t* p)
983
+{
984
+	publ_info_t publ;
985
+	ua_pres_t* cb_param= NULL;
986
+
987
+	memset(&publ, 0, sizeof(publ_info_t));
988
+	publ.pres_uri= p->pres_uri;
989
+	publ.content_type= p->content_type;
990
+	publ.id= p->id;
991
+	publ.expires= (p->desired_expires== 0) ?-1:p->desired_expires- (int)time(NULL);
992
+	publ.flag= UPDATE_TYPE; 
993
+	publ.source_flag= p->flag; 
994
+	publ.event= p->event;
995
+	publ.etag= &p->etag;
996
+	publ.extra_headers= p->extra_headers;
997
+
998
+	cb_param= publish_cbparam(&publ, NULL, &p->tuple_id, REQ_ME);
990 999
 	if(cb_param== NULL)
991 1000
 	{
992
-		LOG(L_ERR, "PUA: build_uppubl_cbparam: ERROR no more share memory while"
993
-				" allocating cb_param - size= %d\n", size);
1001
+		LOG(L_ERR, "PUA:build_uppubl_cbparam:ERROR constructing callback"
1002
+				" parameter\n");
994 1003
 		return NULL;
995 1004
 	}
996
-	memset(cb_param, 0, size);
997
-	memset(&cb_param->publ, 0, sizeof(publ_info_t));
998
-	size =  sizeof(treq_cbparam_t);
999
-	DBG("PUA: build_uppubl_cbparam: size= %d\n", size);
1000
-
1001
-	cb_param->publ.pres_uri = (str*)((char*)cb_param + size);
1002
-	size+= sizeof(str);
1003
-
1004
-	cb_param->publ.pres_uri->s = (char*)cb_param + size;
1005
-	memcpy(cb_param->publ.pres_uri->s, pres->pres_uri->s ,
1006
-			pres->pres_uri->len ) ;
1007
-	cb_param->publ.pres_uri->len= pres->pres_uri->len;
1008
-	size+= pres->pres_uri->len;
1009
-
1010
-	if(pres->id.s && pres->id.len)
1011
-	{	
1012
-		cb_param->publ.id.s = ((char*)cb_param+ size);
1013
-		memcpy(cb_param->publ.id.s, pres->id.s, pres->id.len);
1014
-		cb_param->publ.id.len= pres->id.len;
1015
-		size+= pres->id.len;
1016
-	}
1017
-
1018
-	cb_param->publ.etag = (str*)((char*)cb_param  + size);
1019
-	size+= sizeof(str);
1020
-	cb_param->publ.etag->s = (char*)cb_param + size;
1021
-	memcpy(cb_param->publ.etag->s, pres->etag.s, pres->etag.len ) ;
1022
-	cb_param->publ.etag->len= pres->etag.len;
1023
-	size+= pres->etag.len;
1024
-	
1025
-		
1026
-	cb_param->tuple_id.s = (char*)cb_param+ size;
1027
-	memcpy(cb_param->tuple_id.s, pres->tuple_id.s ,pres->tuple_id.len);
1028
-	cb_param->tuple_id.len= pres->tuple_id.len;
1029
-	size+= pres->tuple_id.len;
1030
-	
1031
-	DBG("PUA:build_uppubl_cbparam: after allocating: size= %d\n", size);
1032
-	cb_param->publ.event= pres->event;
1033
-	cb_param->publ.source_flag|= pres->flag;
1034
-	cb_param->publ.expires= pres->expires;
1035
-
1036 1005
 	return cb_param;
1037 1006
 }
1038 1007
 
1039 1008
 ua_pres_t* build_upsubs_cbparam(ua_pres_t* p)
1040 1009
 {
1041
-	ua_pres_t* hentity;
1042
-	int size;
1043
-
1044
-	size= sizeof(ua_pres_t)+ sizeof(str)*2+ (p->pres_uri->len+ 
1045
-			p->watcher_uri->len+ + p->contact.len+ p->id.len)*sizeof(char);
1046
-
1047
-	if(p->outbound_proxy && p->outbound_proxy->len && p->outbound_proxy->s )
1048
-		size+= sizeof(str)+ p->outbound_proxy->len* sizeof(char);
1049
-
1050
-	hentity= (ua_pres_t*)shm_malloc(size);
1051
-	if(hentity== NULL)
1010
+	subs_info_t subs;
1011
+	ua_pres_t* cb_param= NULL;
1012
+
1013
+	memset(&subs, 0, sizeof(subs_info_t));
1014
+
1015
+	subs.pres_uri= p->pres_uri;
1016
+	subs.id= p->id;
1017
+	subs.watcher_uri= p->watcher_uri;
1018
+	subs.contact= &p->contact;
1019
+	subs.outbound_proxy= p->outbound_proxy;
1020
+	subs.event= p->event;
1021
+	subs.source_flag= p->flag;
1022
+	subs.flag= UPDATE_TYPE;
1023
+	subs.expires= (p->desired_expires== 0) ?-1:p->desired_expires- (int)time(NULL);
1024
+
1025
+	cb_param= subscribe_cbparam(&subs, REQ_ME);
1026
+	if(cb_param== NULL)
1052 1027
 	{
1053
-		LOG(L_ERR, "PUA: update_pua: ERROR no more share memory\n");
1028
+		LOG(L_ERR, "PUA: build_upsubs_cbparam: ERROR constructing"
1029
+				" callback parameter\n");
1054 1030
 		return NULL;
1055 1031
 	}
1056
-	memset(hentity, 0, size);
1057 1032
 
1058
-	size =  sizeof(ua_pres_t);
1059
-
1060
-	hentity->pres_uri = (str*)((char*)hentity + size);
1061
-	size+= sizeof(str);
1062
-
1063
-	hentity->pres_uri->s = (char*)hentity+ size;
1064
-	memcpy(hentity->pres_uri->s, p->pres_uri->s ,
1065
-			p->pres_uri->len ) ;
1066
-	hentity->pres_uri->len= p->pres_uri->len;
1067
-	size+= p->pres_uri->len;
1068
-		
1069
-	hentity->watcher_uri=(str*)((char*)hentity+ size);
1070
-	size+= sizeof(str);
1071
-	hentity->watcher_uri->s= (char*)hentity+ size;
1072
-	memcpy(hentity->watcher_uri->s, p->watcher_uri->s,p->watcher_uri->len);
1073
-	hentity->watcher_uri->len= p->watcher_uri->len;
1074
-	size+= p->watcher_uri->len;
1075
-	
1076
-	hentity->contact.s = (char*)hentity+ size;
1077
-	memcpy(hentity->contact.s, p->contact.s ,
1078
-		p->contact.len );
1079
-	hentity->contact.len= p->contact.len;
1080
-	size+= p->contact.len;
1081
-
1082
-	if(p->outbound_proxy)
1083
-	{
1084
-		hentity->outbound_proxy= (str*)((char*)hentity+ size);
1085
-		size+= sizeof(str);
1086
-		hentity->outbound_proxy->s= (char*)hentity+ size;
1087
-		memcpy(hentity->outbound_proxy->s, p->outbound_proxy->s, p->outbound_proxy->len);
1088
-		hentity->outbound_proxy->len= p->outbound_proxy->len;
1089
-		size+= p->outbound_proxy->len;
1090
-	}	
1091
-	if(p->id.s)
1092
-	{
1093
-		hentity->id.s= (char*)hentity+ size;
1094
-		memcpy(hentity->id.s, p->id.s, p->id.len);
1095
-		hentity->id.len= p->id.len;
1096
-		size+= p->id.len;
1097
-	}
1098
-
1099
-	hentity->event|= p->event;
1100
-	hentity->flag|= p->flag;
1101
-	
1102
-	return hentity;
1103
-	
1033
+	return cb_param;
1104 1034
 }
1035
+
... ...
@@ -28,8 +28,11 @@
28 28
 #include "../../str.h"
29 29
 #include "hash.h"
30 30
 
31
-#define INSERT_TYPE  1<<1
32
-#define UPDATE_TYPE  1<<2
31
+#define INSERT_TYPE      1<<1
32
+#define UPDATE_TYPE      1<<2
33
+
34
+#define REQ_OTHER  0
35
+#define REQ_ME     1
33 36
 
34 37
 extern str default_domain;
35 38
 extern struct tm_binds tmb;
... ...
@@ -28,10 +28,10 @@
28 28
 #include "../../parser/parse_fline.h"
29 29
 #include "../pua/hash.h"
30 30
 
31
-#define PUACB_MAX    		(1<<8)
31
+#define PUACB_MAX    		(1<<9)
32 32
 
33 33
 /* callback function prototype */
34
-typedef void (pua_cb)(ua_pres_t* hentity, struct msg_start * fl);
34
+typedef int (pua_cb)(ua_pres_t* hentity, struct sip_msg*);
35 35
 /* register callback function prototype */
36 36
 typedef int (*register_puacb_t)(int types, pua_cb f, void* param );
37 37
 
... ...
@@ -61,7 +61,7 @@ void destroy_puacb_list();
61 61
 int register_puacb( int types, pua_cb f, void* param );
62 62
 
63 63
 /* run all transaction callbacks for an event type */
64
-static inline void run_pua_callbacks(ua_pres_t* hentity, struct msg_start * fl)
64
+static inline void run_pua_callbacks(ua_pres_t* hentity, struct sip_msg* msg)
65 65
 {
66 66
 	struct pua_callback *cbp;
67 67
 
... ...
@@ -69,8 +69,10 @@ static inline void run_pua_callbacks(ua_pres_t* hentity, struct msg_start * fl)
69 69
 		if(cbp->types & hentity->flag) 
70 70
 		{	
71 71
 			DBG("pua: run_pua_callbacks: found callback\n");
72
-			cbp->callback(hentity, fl);
72
+			cbp->callback(hentity, msg);
73 73
 		}
74 74
 	}
75 75
 }
76
+
77
+/* Q: should I call the registered callback functions when the modules refreshes a request? */
76 78
 #endif
... ...
@@ -141,12 +141,11 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
141 141
 	struct hdr_field* hdr= NULL;
142 142
 	struct sip_msg* msg= NULL;
143 143
 	ua_pres_t* presentity= NULL;
144
-	treq_cbparam_t* hentity= NULL;
144
+	ua_pres_t* hentity= NULL;
145 145
 	int found = 0;
146 146
 	int size= 0;
147 147
 	int lexpire= 0;
148 148
 	str etag;
149
-	int desired_expires;
150 149
 	unsigned int hash_code;
151 150
 
152 151
 	if(ps->param== NULL)
... ...
@@ -164,7 +163,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
164 163
 	if(msg== FAKED_REPLY)
165 164
 	{
166 165
 		DBG("PUA:publ_cback_func: FAKED_REPLY\n");
167
-		goto error;
166
+		goto done;
168 167
 	}
169 168
 
170 169
 	if( ps->code>= 300 )
... ...
@@ -174,17 +173,15 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
174 173
 			DBG("PUA publ_cback_func: NULL callback parameter\n");
175 174
 			return;
176 175
 		}
177
-		hentity= (treq_cbparam_t*)(*ps->param);
176
+		hentity= (ua_pres_t*)(*ps->param);
178 177
 
179
-		hash_code= core_hash(hentity->publ.pres_uri, NULL,
180
-					HASH_SIZE);
178
+		hash_code= core_hash(hentity->pres_uri, NULL,HASH_SIZE);
181 179
 		lock_get(&HashT->p_records[hash_code].lock);
182
-		presentity= search_htable( hentity->publ.pres_uri, NULL, hentity->publ.source_flag,
183
-				hentity->publ.id, hentity->publ.etag, hash_code);
180
+		presentity= search_htable( hentity->pres_uri, NULL, hentity->flag,
181
+			hentity->id,(hentity->etag.s)?&hentity->etag: NULL,hash_code);
184 182
 		if(presentity)
185 183
 		{
186
-			if(ps->code== 412 && hentity->publ.body && 
187
-					hentity->publ.source_flag!= MI_PUBLISH)
184
+			if(ps->code== 412 && hentity->body && hentity->flag!= MI_PUBLISH)
188 185
 			{
189 186
 				/* sent a PUBLISH within a dialog that no longer exists
190 187
 				 * send again an intial PUBLISH */
... ...
@@ -194,14 +191,16 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
194 191
 				lock_release(&HashT->p_records[hash_code].lock);
195 192
 				publ_info_t publ;
196 193
 				memset(&publ, 0, sizeof(publ_info_t));
197
-				publ.pres_uri= hentity->publ.pres_uri; 
198
-				publ.body= hentity->publ.body;
199
-				publ.expires= hentity->publ.expires;
200
-				publ.source_flag|= hentity->publ.source_flag;
201
-				publ.event|= hentity->publ.event;
202
-				publ.content_type= hentity->publ.content_type;	
203
-				publ.id= hentity->publ.id;
204
-				publ.extra_headers= hentity->publ.extra_headers;
194
+				publ.pres_uri= hentity->pres_uri; 
195
+				publ.body= hentity->body;
196
+				publ.expires= (hentity->desired_expires>0)?
197
+					hentity->desired_expires- (int)time(NULL)+ 10:-1;
198
+				publ.source_flag|= hentity->flag;
199
+				publ.event|= hentity->event;
200
+				publ.content_type= hentity->content_type;	
201
+				publ.id= hentity->id;
202
+				publ.extra_headers= hentity->extra_headers;
203
+				publ.cb_param= hentity->cb_param;
205 204
 				if(send_publish(&publ)< 0)
206 205
 				{
207 206
 					LOG(L_ERR, "PUA:publ_cback_func: ERROR when trying to send PUBLISH\n");
... ...
@@ -257,32 +256,22 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
257 256
 	}
258 257
 	etag= hdr->body;
259 258
 
260
-	/* if publish with 0 the callback parameter is NULL*/
261
-	if(lexpire== 0 && *ps->param== NULL )	
262
-	{
263
-		DBG("PUA: publ_cback_func: reply with expires= 0 and entity already"
264
-				" deleted\n");
265
-		return;
266
-	}
267
-
268 259
 	if( *ps->param== NULL ) 
269 260
 	{
270 261
 		DBG("PUA publ_cback_func: Error NULL callback parameter\n");
271 262
 		return;
272 263
 	}
273 264
 		
274
-	hentity= (treq_cbparam_t*)(*ps->param);
265
+	hentity= (ua_pres_t*)(*ps->param);
275 266
 
276 267
 	LOG(L_DBG, "PUA:publ_cback_func: completed with status %d [contact:"
277
-			"%.*s]\n",ps->code, hentity->publ.pres_uri->len, hentity->publ.pres_uri->s);
278
-
279
-	desired_expires= hentity->publ.expires<0?0: hentity->publ.expires+ (int)time(NULL);
268
+			"%.*s]\n",ps->code, hentity->pres_uri->len, hentity->pres_uri->s);
280 269
 
281
-	hash_code= core_hash(hentity->publ.pres_uri, NULL, HASH_SIZE);
270
+	hash_code= core_hash(hentity->pres_uri, NULL, HASH_SIZE);
282 271
 	lock_get(&HashT->p_records[hash_code].lock);
283 272
 	
284
-	presentity= search_htable(hentity->publ.pres_uri, NULL,hentity->publ.source_flag,
285
-			hentity->publ.id, hentity->publ.etag,  hash_code);
273
+	presentity= search_htable(hentity->pres_uri, NULL,hentity->flag,
274
+			hentity->id,(hentity->etag.s)?&hentity->etag: NULL,hash_code);
286 275
 	if(presentity)
287 276
 	{
288 277
 			DBG("PUA:publ_cback_func: update record\n");
... ...
@@ -294,7 +283,7 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
294 283
 				goto done;
295 284
 			}
296 285
 			
297
-			update_htable(presentity, desired_expires,
286
+			update_htable(presentity, hentity->desired_expires,
298 287
 					lexpire, &etag, hash_code);
299 288
 			lock_release(&HashT->p_records[hash_code].lock);
300 289
 			goto done;
... ...
@@ -304,11 +293,14 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
304 293
 	if(lexpire== 0)
305 294
 	{
306 295
 		LOG(L_ERR, "PUA:publ_cback_func:expires= 0: no not insert\n");
307
-		goto error;
296
+		goto done;
308 297
 	}
309 298
 	size= sizeof(ua_pres_t)+ sizeof(str)+ 
310
-		(hentity->publ.pres_uri->len+ hentity->tuple_id.len + 
311
-		 hentity->publ.id.len)* sizeof(char);
299
+		(hentity->pres_uri->len+ hentity->tuple_id.len + 
300
+		 hentity->id.len)* sizeof(char);
301
+	if(hentity->extra_headers)
302
+		size+= sizeof(str)+ hentity->extra_headers->len* sizeof(char);
303
+
312 304
 	presentity= (ua_pres_t*)shm_malloc(size);
313 305
 	if(presentity== NULL)
314 306
 	{
... ...
@@ -323,10 +315,10 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
323 315
 	size+= sizeof(str);
324 316
 
325 317
 	presentity->pres_uri->s= (char*)presentity+ size;
326
-	memcpy(presentity->pres_uri->s, hentity->publ.pres_uri->s, 
327
-			hentity->publ.pres_uri->len);
328
-	presentity->pres_uri->len= hentity->publ.pres_uri->len;
329
-	size+= hentity->publ.pres_uri->len;
318
+	memcpy(presentity->pres_uri->s, hentity->pres_uri->s, 
319
+			hentity->pres_uri->len);
320
+	presentity->pres_uri->len= hentity->pres_uri->len;
321
+	size+= hentity->pres_uri->len;
330 322
 	
331 323
 	presentity->tuple_id.s= (char*)presentity+ size;
332 324
 	memcpy(presentity->tuple_id.s, hentity->tuple_id.s,
... ...
@@ -335,15 +327,26 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
335 327
 	size+= presentity->tuple_id.len;
336 328
 
337 329
 	presentity->id.s=(char*)presentity+ size;
338
-	memcpy(presentity->id.s, hentity->publ.id.s, 
339
-			hentity->publ.id.len);
340
-	presentity->id.len= hentity->publ.id.len; 
330
+	memcpy(presentity->id.s, hentity->id.s, 
331
+			hentity->id.len);
332
+	presentity->id.len= hentity->id.len; 
341 333
 	size+= presentity->id.len;
342 334
 		
343
-	presentity->expires= lexpire +(int)time(NULL);
344
-	presentity->desired_expires= desired_expires;
345
-	presentity->flag|= hentity->publ.source_flag;
346
-	presentity->event|= hentity->publ.event;
335
+	if(hentity->extra_headers)
336
+	{
337
+		presentity->extra_headers= (str*)((char*)presentity+ size);
338
+		size+= sizeof(str);
339
+		presentity->extra_headers->s= (char*)presentity+ size;
340
+		memcpy(presentity->extra_headers->s, hentity->extra_headers->s, 
341
+				hentity->extra_headers->len);
342
+		presentity->extra_headers->len= hentity->extra_headers->len;
343
+		size+= hentity->extra_headers->len;
344
+	}
345
+
346
+	presentity->desired_expires= hentity->desired_expires;
347
+	presentity->expires= lexpire+ (int)time(NULL);
348
+	presentity->flag|= hentity->flag;
349
+	presentity->event|= hentity->event;
347 350
 
348 351
 	presentity->etag.s= (char*)shm_malloc(etag.len* sizeof(char));
349 352
 	if(presentity->etag.s== NULL)
... ...
@@ -358,16 +361,9 @@ void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps)
358 361
 	DBG("PUA: publ_cback_func: ***Inserted in hash table\n");		
359 362
 
360 363
 done:
364
+	if(hentity == REQ_OTHER)
365
+		run_pua_callbacks(hentity, msg);
361 366
 
362
-	if(hentity->publ.cbrpl )
363
-	{
364
-		if( hentity->publ.cbrpl(msg,  hentity->publ.cbparam)< 0)
365
-		{
366
-			LOG(L_ERR,"PUA:publ_cback_func: in callback function ERROR ");
367
-			goto error;
368
-		}	
369
-			
370
-	}	
371 367
 	if(*ps->param)
372 368
 	{
373 369
 		shm_free(*ps->param);
... ...
@@ -383,7 +379,6 @@ error:
383 379
 	}
384 380
 
385 381
 	return;
386
-
387 382
 }	
388 383
 
389 384
 int send_publish( publ_info_t* publ )
... ...
@@ -391,10 +386,9 @@ int send_publish( publ_info_t* publ )
391 386
 	str met = {"PUBLISH", 7};
392 387
 	str* str_hdr = NULL;
393 388
 	ua_pres_t* presentity= NULL;
394
-	unsigned int size= 0;
395 389
 	str* body= NULL;
396 390
 	str* tuple_id= NULL;
397
-	treq_cbparam_t* cb_param= NULL;
391
+	ua_pres_t* cb_param= NULL;
398 392
 	unsigned int hash_code;
399 393
 	str etag= {0, 0};
400 394
 	int ver= 0;
... ...
@@ -414,7 +408,6 @@ int send_publish( publ_info_t* publ )
414 408
 		goto error;
415 409
 	}	
416 410
 
417
-
418 411
 	hash_code= core_hash(publ->pres_uri, NULL, HASH_SIZE);
419 412
 
420 413
 	lock_get(&HashT->p_records[hash_code].lock);
... ...
@@ -491,9 +484,6 @@ insert:
491 484
 		if(publ->expires== 0)
492 485
 		{
493 486
 			DBG("PUA:send_publish: expires= 0- delete from hash table\n");
494
-			delete_htable(presentity, hash_code);
495
-			presentity= NULL;
496
-			lock_release(&HashT->p_records[hash_code].lock);
497 487
 			goto send_publish;
498 488
 		}
499 489
 		presentity->version++;
... ...
@@ -517,105 +507,17 @@ insert:
517 507
 	if(tuple_id)
518 508
 		DBG("\n\nPUA:send_publish: tuple_id= %.*s\n\n", tuple_id->len, tuple_id->s  );
519 509
 	
510
+send_publish:
511
+	
520 512
 	/* construct the callback parameter */
521 513
 
522
-	size= sizeof(treq_cbparam_t)+ sizeof(str)+ (publ->pres_uri->len+ 
523
-		+ publ->content_type.len+ publ->id.len+ 1)*sizeof(char);
524
-	if(body && body->s && body->len)
525
-		size+= sizeof(str)+ body->len* sizeof(char);
526
-	if(publ->etag)
527
-		size+= sizeof(str)+ publ->etag->len* sizeof(char);
528
-	if(publ->extra_headers)
529
-		size+= sizeof(str)+ publ->extra_headers->len* sizeof(char);
530
-	if(tuple_id )
531
-		size+= tuple_id->len* sizeof(char);
532
-
533
-	DBG("PUA: send_publish: before allocating size= %d\n", size);
534
-	cb_param= (treq_cbparam_t*)shm_malloc(size);
514
+	cb_param= publish_cbparam(publ, body, tuple_id, REQ_OTHER);
535 515
 	if(cb_param== NULL)
536 516
 	{
537
-		LOG(L_ERR, "PUA: send_publish: ERROR no more share memory while"
538
-				" allocating cb_param - size= %d\n", size);
517
+		LOG(L_ERR, "PUA:send_publish:ERROR constructing callback parameter\n");
539 518
 		goto error;
540 519
 	}
541
-	memset(cb_param, 0, size);
542
-	memset(&cb_param->publ, 0, sizeof(publ_info_t));
543
-	size =  sizeof(treq_cbparam_t);
544
-	DBG("PUA: send_publish: size= %d\n", size);
545 520
 
546
-	cb_param->publ.pres_uri = (str*)((char*)cb_param + size);
547
-	size+= sizeof(str);
548
-
549
-	cb_param->publ.pres_uri->s = (char*)cb_param + size;
550
-	memcpy(cb_param->publ.pres_uri->s, publ->pres_uri->s ,
551
-			publ->pres_uri->len ) ;
552
-	cb_param->publ.pres_uri->len= publ->pres_uri->len;
553
-	size+= publ->pres_uri->len;
554
-
555
-	if(publ->id.s && publ->id.len)
556
-	{	
557
-		cb_param->publ.id.s = ((char*)cb_param+ size);
558
-		memcpy(cb_param->publ.id.s, publ->id.s, publ->id.len);
559
-		cb_param->publ.id.len= publ->id.len;
560
-		size+= publ->id.len;
561
-	}
562
-
563
-	if(body && body->s && body->len)
564
-	{
565
-		cb_param->publ.body = (str*)((char*)cb_param  + size);
566
-		size+= sizeof(str);
567
-		
568
-		cb_param->publ.body->s = (char*)cb_param + size;
569
-		memcpy(cb_param->publ.body->s, body->s ,
570
-			body->len ) ;
571
-		cb_param->publ.body->len= body->len;
572
-		size+= body->len;
573
-	}
574
-	if(publ->etag)
575
-	{
576
-		cb_param->publ.etag = (str*)((char*)cb_param  + size);
577
-		size+= sizeof(str);
578
-		cb_param->publ.etag->s = (char*)cb_param + size;
579
-		memcpy(cb_param->publ.etag->s, publ->etag->s ,
580
-			publ->etag->len ) ;
581
-		cb_param->publ.etag->len= publ->etag->len;
582
-		size+= publ->etag->len;
583
-	}
584
-	if(publ->extra_headers)
585
-	{
586
-		cb_param->publ.extra_headers = (str*)((char*)cb_param  + size);
587
-		size+= sizeof(str);
588
-		cb_param->publ.extra_headers->s = (char*)cb_param + size;
589
-		memcpy(cb_param->publ.extra_headers->s, publ->extra_headers->s ,
590
-			publ->extra_headers->len ) ;
591
-		cb_param->publ.extra_headers->len= publ->extra_headers->len;
592
-		size+= publ->extra_headers->len;
593
-	}	
594
-
595
-	if(publ->content_type.s && publ->content_type.len)
596
-	{
597
-		cb_param->publ.content_type.s= (char*)cb_param + size;
598
-		memcpy(cb_param->publ.content_type.s, publ->content_type.s, publ->content_type.len);
599
-		cb_param->publ.content_type.len= publ->content_type.len;
600
-		size+= cb_param->publ.content_type.len;
601
-
602
-	}	
603
-	if(tuple_id)
604
-	{	
605
-		cb_param->tuple_id.s = (char*)cb_param+ size;
606
-		memcpy(cb_param->tuple_id.s, tuple_id->s ,tuple_id->len);
607
-		cb_param->tuple_id.len= tuple_id->len;
608
-		size+= tuple_id->len;
609
-	}
610
-	DBG("PUA:send_publish: after allocating: size= %d\n", size);
611
-	cb_param->publ.cbparam= publ->cbparam;
612
-	cb_param->publ.cbrpl= publ->cbrpl;
613
-	cb_param->publ.event= publ->event;
614
-	cb_param->publ.source_flag|= publ->source_flag;
615
-	cb_param->publ.expires= publ->expires;
616
-	
617
-send_publish:
618
-	
619 521
 	if(publ->flag & UPDATE_TYPE)
620 522
 		DBG("PUA:send_publish: etag:%.*s\n", etag.len, etag.s);
621 523
 	str_hdr = publ_build_hdr((publ->expires< 0)?3600:publ->expires, ev, &publ->content_type, 
... ...
@@ -673,9 +575,8 @@ error:
673 575
 		pkg_free(etag.s);
674 576
 
675 577
 	if(cb_param)
676
-	{
677 578
 		shm_free(cb_param);
678
-	}	
579
+
679 580
 	if(body&& ret_code)
680 581
 	{
681 582
 		if(body->s)
... ...
@@ -693,4 +594,106 @@ error:
693 594
 	return -1;
694 595
 }
695 596
 
597
+ua_pres_t* publish_cbparam(publ_info_t* publ,str* body,str* tuple_id,
598
+		int ua_flag)
599
+{
600
+	int size;
601
+	ua_pres_t* cb_param= NULL;
602
+
603
+	size= sizeof(ua_pres_t)+ sizeof(str)+ (publ->pres_uri->len+ 
604
+		+ publ->content_type.len+ publ->id.len+ 1)*sizeof(char);
605
+	if(body && body->s && body->len)
606
+		size+= sizeof(str)+ body->len* sizeof(char);
607
+	if(publ->etag)
608
+		size+= publ->etag->len* sizeof(char);
609
+	if(publ->extra_headers)
610
+		size+= sizeof(str)+ publ->extra_headers->len* sizeof(char);
611
+	if(tuple_id )
612
+		size+= tuple_id->len* sizeof(char);
613
+
614
+	DBG("PUA: send_publish: before allocating size= %d\n", size);
615
+	cb_param= (ua_pres_t*)shm_malloc(size);
616
+	if(cb_param== NULL)
617
+	{
618
+		LOG(L_ERR, "PUA: send_publish: ERROR no more share memory while"
619
+				" allocating cb_param - size= %d\n", size);
620
+		return NULL;
621
+	}
622
+	memset(cb_param, 0, size);
623
+	
624
+	size =  sizeof(ua_pres_t);
625
+	DBG("PUA: send_publish: size= %d\n", size);
696 626
 
627
+	cb_param->pres_uri = (str*)((char*)cb_param + size);
628
+	size+= sizeof(str);
629
+	cb_param->pres_uri->s = (char*)cb_param + size;
630
+	memcpy(cb_param->pres_uri->s, publ->pres_uri->s ,
631
+			publ->pres_uri->len ) ;
632
+	cb_param->pres_uri->len= publ->pres_uri->len;
633
+	size+= publ->pres_uri->len;
634
+
635
+	if(publ->id.s && publ->id.len)
636
+	{	
637
+		cb_param->id.s = ((char*)cb_param+ size);
638
+		memcpy(cb_param->id.s, publ->id.s, publ->id.len);
639
+		cb_param->id.len= publ->id.len;
640
+		size+= publ->id.len;
641
+	}
642
+
643
+	if(body && body->s && body->len)
644
+	{
645
+		cb_param->body = (str*)((char*)cb_param  + size);
646
+		size+= sizeof(str);
647
+		
648
+		cb_param->body->s = (char*)cb_param + size;
649
+		memcpy(cb_param->body->s, body->s ,
650
+			body->len ) ;
651
+		cb_param->body->len= body->len;
652
+		size+= body->len;
653
+	}
654
+	if(publ->etag)
655
+	{
656
+		cb_param->etag.s = (char*)cb_param + size;
657
+		memcpy(cb_param->etag.s, publ->etag->s ,
658
+			publ->etag->len ) ;
659
+		cb_param->etag.len= publ->etag->len;
660
+		size+= publ->etag->len;
661
+	}
662
+	if(publ->extra_headers)
663
+	{
664
+		cb_param->extra_headers = (str*)((char*)cb_param  + size);
665
+		size+= sizeof(str);
666
+		cb_param->extra_headers->s = (char*)cb_param + size;
667
+		memcpy(cb_param->extra_headers->s, publ->extra_headers->s ,
668
+			publ->extra_headers->len ) ;
669
+		cb_param->extra_headers->len= publ->extra_headers->len;
670
+		size+= publ->extra_headers->len;
671
+	}	
672
+
673
+	if(publ->content_type.s && publ->content_type.len)
674
+	{
675
+		cb_param->content_type.s= (char*)cb_param + size;
676
+		memcpy(cb_param->content_type.s, publ->content_type.s, publ->content_type.len);
677
+		cb_param->content_type.len= publ->content_type.len;
678
+		size+=  publ->content_type.len;
679
+	}	
680
+	if(tuple_id)
681
+	{	
682
+		cb_param->tuple_id.s = (char*)cb_param+ size;
683
+		memcpy(cb_param->tuple_id.s, tuple_id->s ,tuple_id->len);
684
+		cb_param->tuple_id.len= tuple_id->len;
685
+		size+= tuple_id->len;
686
+	}
687
+	DBG("PUA:send_publish: after allocating: size= %d\n", size);
688
+	cb_param->event= publ->event;
689
+	cb_param->flag|= publ->source_flag;
690
+	cb_param->cb_param= publ->cb_param;
691
+	cb_param->ua_flag= ua_flag;
692
+
693
+	if(publ->expires< 0)
694
+		cb_param->desired_expires= 0;
695
+	else
696
+		cb_param->desired_expires=publ->expires+ (int)time(NULL);
697
+
698
+	return cb_param;
699
+}
... ...
@@ -31,8 +31,6 @@
31 31
 #include "hash.h"
32 32
 #include "event_list.h"
33 33
 
34
-typedef int (publrpl_cb_t)(struct sip_msg* reply, void*  extra_param);
35
-
36 34
 typedef struct publ_info
37 35
 {
38 36
 	str id;
... ...
@@ -46,21 +44,19 @@ typedef struct publ_info
46 44
 					   *	 same as the default value for that event) */	 
47 45
 	str* etag;
48 46
 	str* extra_headers;
49
-	publrpl_cb_t* cbrpl;
50
-	void* cbparam;
47
+	void* cb_param;   /* the parameter for the function to be called on the callback 
48
+						 for the received reply; it must be allocated in share memory;
49
+						 a reference to it will be found in the cb_param filed of the ua_pres_structure
50
+						 receied as a parameter for the registered function*/
51 51
 }publ_info_t;
52 52
 
53
-typedef struct treq_cbparam
54
-{
55
-	publ_info_t publ;
56
-	str tuple_id;
57
-}treq_cbparam_t;
58
-
59 53
 typedef int (*send_publish_t)(publ_info_t* publ);
60 54
 int send_publish( publ_info_t* publ );
61 55
 
62 56
 void publ_cback_func(struct cell *t, int type, struct tmcb_params *ps);
63 57
 str* publ_build_hdr(int expires, pua_event_t* event, str* content_type, str* etag,
64 58
 		str* extra_headers, int is_body);
59
+ua_pres_t* publish_cbparam(publ_info_t* publ, str* body, str* tuple_id,
60
+		int ua_flag);
65 61
 
66 62
 #endif
... ...
@@ -229,12 +229,30 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps)
229 229
 
230 230
 	/* get dialog information from reply message: callid, to_tag, from_tag */
231 231
 	msg= ps->rpl;
232
-	if(msg == NULL || msg== FAKED_REPLY)
232
+	if(msg == NULL)
233 233
 	{
234 234
 		LOG(L_ERR, "PUA:subs_cback_func: no reply message found\n ");
235 235
 		goto error;
236 236
 	}
237 237
 
238
+	if(msg== FAKED_REPLY)
239
+	{
240
+		/* delete record from hash_table and call registered functions */
241
+		lock_get(&HashT->p_records[hash_code].lock);
242
+
243
+		presentity= get_dialog(hentity, hash_code);
244
+		if(presentity== NULL)
245
+		{
246
+			LOG(L_ERR, "PUA:subs_cback_func: ERROR no record found"
247
+					" in hash table\n");
248
+			goto done;
249
+		}
250
+		delete_htable(presentity, hash_code);
251
+		lock_release(&HashT->p_records[hash_code].lock);
252
+
253
+		goto done;
254
+	}
255
+
238 256
 	if ( parse_headers(msg,HDR_EOH_F, 0)==-1 )
239 257
 	{
240 258
 		LOG(L_ERR, "PUA:subs_cback_func: error parsing headers\n");
... ...
@@ -344,6 +362,7 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps)
344 362
 			subs.id= hentity->id;
345 363
 			subs.outbound_proxy= hentity->outbound_proxy;
346 364
 			subs.extra_headers= hentity->extra_headers;
365
+			subs.cb_param= hentity->cb_param;
347 366
 			if(send_subscribe(&subs)< 0)
348 367
 			{
349 368
 				LOG(L_ERR, "PUA:subs_cback_func: ERROR when trying to send SUBSCRIBE\n");
... ...
@@ -511,8 +530,11 @@ void subs_cback_func(struct cell *t, int cb_type, struct tmcb_params *ps)
511 530
 	insert_htable(presentity);
512 531
 
513 532
 done:
514
-	hentity->flag= flag;
515
-	run_pua_callbacks( hentity, &msg->first_line);
533
+	if(hentity->ua_flag == REQ_OTHER)
534
+	{
535
+		hentity->flag= flag;
536
+		run_pua_callbacks( hentity, msg);
537
+	}
516 538
 error:	
517 539
 	if(hentity)
518 540
 	{	
... ...
@@ -523,7 +545,7 @@ error:
523 545
 
524 546
 }
525 547
 
526
-ua_pres_t* build_cback_param(subs_info_t* subs)
548
+ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag)
527 549
 {	
528 550
 	ua_pres_t* hentity= NULL;
529 551
 	int size;
... ...
@@ -605,7 +627,8 @@ ua_pres_t* build_cback_param(subs_info_t* subs)
605 627
 	}
606 628
 	hentity->flag= subs->source_flag;
607 629
 	hentity->event= subs->event;
608
-	
630
+	hentity->ua_flag= hentity->ua_flag;
631
+	hentity->cb_param= subs->cb_param;
609 632
 	return hentity;
610 633
 
611 634
 }	
... ...
@@ -659,9 +682,7 @@ int send_subscribe(subs_info_t* subs)
659 682
 	if(presentity== NULL )
660 683
 	{
661 684
 insert:
662
-	
663 685
 		lock_release(&HashT->p_records[hash_code].lock); 
664
-
665 686
 		if(subs->flag & UPDATE_TYPE)
666 687
 		{
667 688
 			/*
... ...
@@ -677,7 +698,7 @@ insert:
677 698
 			subs->flag= INSERT_TYPE;
678 699
 
679 700
 		}	
680
-		hentity= build_cback_param(subs);
701
+		hentity= subscribe_cbparam(subs, REQ_OTHER);
681 702
 		if(hentity== NULL)
682 703
 		{
683 704
 			LOG(L_ERR, "PUA:send_subscribe:ERROR while building callback"
... ...
@@ -758,7 +779,7 @@ insert:
758 779
 		}
759 780
 		lock_release(&HashT->p_records[hash_code].lock);
760 781
 		
761
-		hentity= build_cback_param(subs);
782
+		hentity= subscribe_cbparam(subs, REQ_OTHER);
762 783
 		if(hentity== NULL)
763 784
 		{
764 785
 			LOG(L_ERR, "PUA:send_subscribe:ERROR while building callback"
... ...
@@ -43,14 +43,19 @@ typedef struct subs_info
43 43
 	str* extra_headers;
44 44
 	int expires;
45 45
 	int source_flag;
46
-	int flag;         /*  it can be : INSERT_TYPE or UPDATE_TYPE
47
-                      *  not compulsory */
46
+	int flag;         /*  it can be : INSERT_TYPE or UPDATE_TYPE; not compulsory */
47
+	void* cb_param;  /* the parameter for the function to be called on the callback 
48
+						 for the received reply; it must be allocated in share memory;
49
+						 a reference to it will be found in the cb_param filed of the ua_pres_structure
50
+						 receied as a parameter for the registered function*/
48 51
 }subs_info_t;
49 52
 
53
+
50 54
 typedef int (*send_subscribe_t)(subs_info_t* subs);
51 55
 int send_subscribe(subs_info_t* subs);
52 56
 void subs_cback_func(struct cell *t, int type, struct tmcb_params *ps);
53 57
 str* subs_build_hdr(str* watcher_uri, int expires, int event, str* extra_headers);
54 58
 dlg_t* pua_build_dlg_t(ua_pres_t* presentity);
59
+ua_pres_t* subscribe_cbparam(subs_info_t* subs, int ua_flag);
55 60
 
56 61
 #endif
... ...
@@ -46,7 +46,6 @@
46 46
  *		<ETag>             - ETag that publish should match or . if no ETag
47 47
  *		<publish_body>     - may not be present in case of update for expire
48 48
  */
49
-int mi_publ_rpl_cback(struct sip_msg* reply, void* param);
50 49
 
51 50
 struct mi_root* mi_pua_publish(struct mi_root* cmd, void* param)
52 51
 {
... ...
@@ -215,13 +214,14 @@ struct mi_root* mi_pua_publish(struct mi_root* cmd, void* param)
215 214
 		publ.etag= &etag;
216 215
 	}	
217 216
 	publ.expires= exp;
218
-	publ.source_flag|= MI_PUBLISH;
219 217
 	
220 218
 	if (cmd->async_hdl!=NULL)
221 219
 	{
222
-		publ.cbrpl= mi_publ_rpl_cback;
223
-		publ.cbparam= (void*)cmd->async_hdl;
220
+		publ.source_flag= MI_ASYN_PUBLISH;
221
+		publ.cb_param= (void*)cmd->async_hdl;
224 222
 	}	
223
+	else
224
+		publ.source_flag|= MI_PUBLISH;
225 225
 
226 226
 	DBG("DEBUG:pua_mi:mi_pua_publish: send publish\n");
227 227
 
... ...
@@ -246,7 +246,7 @@ error:
246 246
 	return 0;
247 247
 }
248 248
 
249
-int mi_publ_rpl_cback(struct sip_msg* reply, void* param)
249
+int mi_publ_rpl_cback( ua_pres_t* hentity, struct sip_msg* reply)
250 250
 {
251 251
 	struct mi_root *rpl_tree= NULL;
252 252
 	struct mi_handler* mi_hdl= NULL;
... ...
@@ -255,25 +255,33 @@ int mi_publ_rpl_cback(struct sip_msg* reply, void* param)
255 255
 	int lexpire;
256 256
 	int found;
257 257
 	str etag;
258
+	str reason= {0, 0};
258 259
 
259
-	if(reply== NULL || param== NULL)
260
+	if(reply== NULL || hentity== NULL || hentity->cb_param== NULL)
260 261
 	{
261 262
 		LOG(L_ERR, "pua_mi:mi_publ_rpl_cback: ERROR NULL parameter\n");
262 263
 		return -1;
263 264
 	}
264 265
 	if(reply== FAKED_REPLY)
265
-		return 0;
266
+	{
267
+		statuscode= 408;
268
+		reason.s= "Request Timeout";
269
+		reason.len= strlen(reason.s);
270
+	}
271
+	else
272
+	{
273
+		statuscode= reply->first_line.u.reply.statuscode;
274
+		reason= reply->first_line.u.reply.reason;
275
+	}
266 276
 
267
-	mi_hdl = (struct mi_handler *)(param);
268
-	statuscode= reply->first_line.u.reply.statuscode;
277
+	mi_hdl = (struct mi_handler *)(hentity->cb_param);
269 278
 	
270 279
 	rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
271
-		if (rpl_tree==0)
272
-			goto done;
280
+	if (rpl_tree==0)
281
+		goto done;
273 282
 	
274 283
 	addf_mi_node_child( &rpl_tree->node, 0, 0, 0, "%d %.*s",
275
-		statuscode, reply->first_line.u.reply.reason.len,
276
-		reply->first_line.u.reply.reason.s);
284
+		statuscode, reason.len, reason.s);
277 285
 	
278 286
 	
279 287
 	if(statuscode== 200)
... ...
@@ -309,7 +317,6 @@ done:
309 317
 	if ( statuscode >= 200) 
310 318
 	{
311 319
 		mi_hdl->handler_f( rpl_tree, mi_hdl, 1);
312
-		param= 0;
313 320
 	}
314 321
 	else 
315 322
 	{
... ...
@@ -319,7 +326,9 @@ done:
319 326
 
320 327
 error:
321 328
 	return  -1;
322
-}	
329
+}
330
+
331
+
323 332
 /*Command parameters:
324 333
  * pua_subscribe
325 334
  *		<presentity_uri>
... ...
@@ -27,5 +27,6 @@
27 27
 
28 28
 struct mi_root* mi_pua_publish(struct mi_root* cmd, void* param);
29 29
 struct mi_root* mi_pua_subscribe(struct mi_root* cmd, void* param);
30
+int mi_publ_rpl_cback(ua_pres_t* hentity, struct sip_msg* reply);
30 31
 
31 32
 #endif	
... ...
@@ -115,6 +115,12 @@ static int mod_init(void)
115 115
 		return -1;
116 116
 	}
117 117
 	pua_send_subscribe= pua.send_subscribe;
118
+	
119
+	if(pua.register_puacb(MI_ASYN_PUBLISH, mi_publ_rpl_cback, NULL)< 0)
120
+	{
121
+		LOG(L_ERR, "pua_mi:mod_init Could not register callback\n");
122
+		return -1;
123
+	}	
118 124
 
119 125
 	return 0;
120 126
 }
... ...
@@ -87,9 +87,9 @@ static int fixup_pua_xmpp(void** param, int param_no);
87 87
 
88 88
 static cmd_export_t cmds[]=
89 89
 {
90
-	{"pua_xmpp_notify",		 Notify2Xmpp,	       0,		0,		  REQUEST_ROUTE},
91
-	{"pua_xmpp_req_winfo",   request_winfo,	       2,  fixup_pua_xmpp,REQUEST_ROUTE},
92
-	{     0,			       0,		    	   0,		0,			   0	   }
90
+	{"pua_xmpp_notify",		 Notify2Xmpp,	0,		0,		  REQUEST_ROUTE},
91
+	{"pua_xmpp_req_winfo",   request_winfo,	2,  fixup_pua_xmpp,REQUEST_ROUTE},
92
+	{     0,			       0,		    0,		0,			   0	    }
93 93
 };
94 94
 
95 95
 static param_export_t params[]={
... ...
@@ -112,8 +112,6 @@ struct module_exports exports= {
112 112
 	child_init                  /* per-child init function */
113 113
 };
114 114
 
115
-
116
-
117 115
 /**
118 116
  * init module function
119 117
  */
... ...
@@ -156,9 +154,10 @@ static int mod_init(void)
156 154
     XMLNodeGetNodeContentByName= libxml_api.xmlNodeGetNodeContentByName;
157 155
 
158 156
 	if(XMLNodeGetAttrContentByName== NULL || XMLDocGetNodeByName== NULL ||
159
-			XMLNodeGetNodeByName== NULL || XMLNodeGetNodeContentByName== NULL)
157
+		XMLNodeGetNodeByName== NULL || XMLNodeGetNodeContentByName== NULL)
160 158
 	{
161
-		LOG(L_ERR, "PUA:mod_init:ERROR: libxml wrapper functions could not be bound\n");
159
+		LOG(L_ERR, "PUA_XMPP:mod_init:ERROR: libxml wrapper functions could"
160
+				" not be bound\n");
162 161
 		return -1;
163 162
 	}
164 163
 
... ...
@@ -29,6 +29,7 @@
29 29
 #include <stdlib.h>
30 30
 #include <libxml/parser.h>
31 31
 
32
+#include "../../ut.h"
32 33
 #include "../../str.h"
33 34
 #include "../../dprint.h"
34 35
 #include "../../parser/msg_parser.h"
... ...
@@ -793,7 +794,7 @@ char* get_error_reason(int code, str* reason)
793 794
 }	
794 795
 
795 796
 
796
-void Sipreply2Xmpp(ua_pres_t* hentity, struct msg_start * fl) 
797
+int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg) 
797 798
 {
798 799
 	char* uri;
799 800
 	/* named according to the direction of the message in xmpp*/
... ...
@@ -869,9 +870,18 @@ void Sipreply2Xmpp(ua_pres_t* hentity, struct msg_start * fl)
869 870
 		goto error;
870 871
 	}
871 872
 
872
-	code= fl->u.reply.statuscode;
873
-	reason= fl->u.reply.reason;
874
-    
873
+	if(msg== FAKED_REPLY)
874
+	{
875
+		code = 408;
876
+		reason.s= "Request Timeout";
877
+		reason.len= strlen(reason.s)- 1;
878
+	}
879
+	else
880
+	{
881
+		code= msg->first_line.u.reply.statuscode;
882
+		reason= msg->first_line.u.reply.reason;
883
+	}
884
+
875 885
 	DBG("PUA_XMPP: Sipreply2Xmpp: to_uri= %s\n\t from_uri= %s\n",
876 886
 			to_uri.s, from_uri.s);
877 887
 
... ...
@@ -966,7 +976,7 @@ void Sipreply2Xmpp(ua_pres_t* hentity, struct msg_start * fl)
966 976
 		pkg_free(err_reason);
967 977
 	xmlFreeDoc(doc);
968 978
 	
969
-	return ;
979
+	return 0;
970 980
 
971 981
 error:
972 982
 
... ...
@@ -974,7 +984,7 @@ error:
974 984
 		xmlFreeDoc(doc);
975 985
 	if(err_reason)
976 986
 		pkg_free(err_reason);
977
-	return ;
987
+	return -1;
978 988
 
979 989
 }
980 990
 
... ...
@@ -32,6 +32,6 @@
32 32
 #include "../pua/pua_bind.h"
33 33
 
34 34
 int Notify2Xmpp(struct sip_msg* msg, char* s1, char* s2);
35
-void Sipreply2Xmpp(ua_pres_t* hentity, struct msg_start * fl);
35
+int Sipreply2Xmpp(ua_pres_t* hentity, struct sip_msg * msg);
36 36
 
37 37
 #endif