Browse code

XJAB module - new presence status code: terminated -- used when the connection with Jabber server is closed - code cleaning

Daniel-Constantin Mierla authored on 09/05/2003 11:23:40
Showing 6 changed files
... ...
@@ -592,41 +592,13 @@ int xjab_manage_sipmsg(struct sip_msg *msg, int type)
592 592
 		goto error;
593 593
 	}
594 594
 	
595
-	/** skip 'sip:' in destination address */
596
-	if(dst.s[0]=='s' && dst.s[1]=='i' && dst.s[2]=='p')
597
-	{
598
-		dst.s += 3;
599
-		dst.len -= 3;
600
-		fl = 1;
601
-		while(*dst.s == ' ' || *dst.s == '\t' || *dst.s == ':')
602
-		{
603
-			dst.s++;
604
-			dst.len--;
605
-			fl = 0;
606
-		}
607
-		if(fl)
608
-		{
609
-			dst.s -= 3;
610
-			dst.len += 3;
611
-		}
612
-#ifdef XJ_EXTRA_DEBUG
613
-		DBG("XJAB:xjab_manage_sipmsg: DESTINATION corrected [%.*s].\n", 
614
-				dst.len, dst.s);
615
-#endif
616
-	}
617
-	// check for parameters
618
-	pc = dst.s;
619
-	while(pc < dst.s + dst.len && *pc!=';')
620
-		pc++;
621
-	if(pc < dst.s+dst.len)
622
-	{
623
-		dst.len = pc - dst.s;
595
+	/** skip 'sip:' and parameters in destination address */
596
+	_XJ_ADJUST_SIPADDR(dst.s,dst.len,pc, fl);
624 597
 #ifdef XJ_EXTRA_DEBUG
625
-		DBG("XJAB:xjab_manage_sipmsg: DESTINATION corrected again [%.*s].\n", 
598
+	DBG("XJAB:xjab_manage_sipmsg: DESTINATION after correction [%.*s].\n",
626 599
 				dst.len, dst.s);
627 600
 #endif
628
-	}
629
-
601
+	
630 602
 prepare_job:
631 603
 	//putting the SIP message parts in share memory to be accessible by workers
632 604
     jsmsg = (xj_sipmsg)shm_malloc(sizeof(t_xj_sipmsg));
... ...
@@ -741,8 +713,8 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
741 741
 {
742 742
 	xj_sipmsg jsmsg = NULL;
743 743
 	t_xj_jkey jkey, *jp;
744
-	int pipe, fl;
745
-
744
+	int pipe, fl, f;
745
+	char *p, *p0;
746 746
 	if(!to || !from || !cbf)
747 747
 		return;
748 748
 
... ...
@@ -768,7 +740,16 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
768 768
 	jsmsg->msg.len = 0;
769 769
 	jsmsg->msg.s = NULL;
770 770
 	
771
-	jsmsg->to.len = to->len;
771
+	p = to->s;
772
+	fl = to->len;
773
+	/** skip 'sip:' and parameters in destination address */
774
+	_XJ_ADJUST_SIPADDR(p, fl, p0, f);
775
+#ifdef XJ_EXTRA_DEBUG
776
+	DBG("XJAB:xj_register_watcher: DESTINATION after correction [%.*s].\n",
777
+				fl, p);
778
+#endif
779
+
780
+	jsmsg->to.len = fl;
772 781
 	if((jsmsg->to.s = (char*)shm_malloc(jsmsg->to.len+1)) == NULL)
773 782
 	{
774 783
 		if(jsmsg->msg.s)
... ...
@@ -776,7 +757,7 @@ void xj_register_watcher(str *from, str *to, void *cbf, void *pp)
776 776
 		shm_free(jsmsg);
777 777
 		goto error;
778 778
 	}
779
-	strncpy(jsmsg->to.s, to->s, jsmsg->to.len);
779
+	strncpy(jsmsg->to.s, p, jsmsg->to.len);
780 780
 
781 781
 	jsmsg->jkey = jp;
782 782
 	jsmsg->type = XJ_REG_WATCHER;
... ...
@@ -26,6 +26,14 @@
26 26
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
27 27
  */ 
28 28
 
29
+/***
30
+ * ---
31
+ *
32
+ * History
33
+ * -------
34
+ * 2003-05-09  added macro for ajusting a SIP address, (dcm)
35
+ */
36
+
29 37
 
30 38
 #ifndef _XJAB_BASE_H_
31 39
 #define _XJAB_BASE_H_
... ...
@@ -44,6 +52,30 @@
44 44
 #define XJ_FLAG_OPEN		0
45 45
 #define XJ_FLAG_CLOSE		1
46 46
 
47
+/** skip 'sip:' and parameters in a SIP address */
48
+#define _XJ_ADJUST_SIPADDR(_s, _l, _p, _f) \
49
+	if((_s)[0]=='s' && (_s)[1]=='i' && (_s)[2]=='p') \
50
+	{ \
51
+		(_s) += 3; \
52
+		(_l) -= 3; \
53
+		(_f) = 1; \
54
+		while(*(_s)==' ' || *(_s)=='\t' || *(_s)==':') \
55
+		{ \
56
+			(_s)++; \
57
+			(_l)--; \
58
+			(_f)=0; \
59
+		} \
60
+		if((_f)) \
61
+		{ \
62
+			(_s) -= 3; \
63
+			(_l) += 3; \
64
+		} \
65
+	} \
66
+	(_p) = (_s); \
67
+	while((_p)<(_s)+(_l) && *(_p)!=';' && *(_p)!=' ') \
68
+		(_p)++; \
69
+	if((_p) < (_s)+(_l)) \
70
+		(_l) = (_p) - (_s);
47 71
 
48 72
 typedef void (*pa_callback_f)(str* _user, int _state, void *p);
49 73
 
... ...
@@ -275,7 +275,7 @@ int xj_jcon_user_auth(xj_jcon jbc, char *username, char *passwd,
275 275
 		//sprintf(msg_buff, "%s%s", jbc->stream_id, passwd);
276 276
 		strcpy(msg_buff, jbc->stream_id);
277 277
 		strcat(msg_buff, passwd);
278
-		DBG("XJAB:xj_jcon_user_auth: [%s:%s]\n", jbc->stream_id, passwd);
278
+		//DBG("XJAB:xj_jcon_user_auth: [%s:%s]\n", jbc->stream_id, passwd);
279 279
 		p1 = shahash(msg_buff);
280 280
 
281 281
 		z = xode_insert_tag(y, "digest");
... ...
@@ -49,7 +49,7 @@ xj_pres_cell xj_pres_cell_new()
49 49
 	prc->key = 0;
50 50
 	prc->userid.s = NULL;
51 51
 	prc->userid.len = 0;
52
-	prc->state = XJ_PRES_STATE_OFFLINE;
52
+	prc->state = XJ_PS_OFFLINE;
53 53
 	prc->status = XJ_PRES_STATUS_NULL;
54 54
 	prc->cbf = NULL;
55 55
 	prc->cbp = NULL;
... ...
@@ -241,7 +241,6 @@ xj_pres_cell xj_pres_list_check(xj_pres_list prl, str* uid)
241 241
 
242 242
 	if(!prl || !uid || !uid->s || uid->len<=0 || prl->nr<=0 || prl->clist==NULL)
243 243
 		return NULL;
244
-	
245 244
 	lkey = xj_get_hash(uid, NULL);
246 245
 
247 246
 	p = prl->clist;
... ...
@@ -267,7 +266,7 @@ void xj_pres_list_notifyall(xj_pres_list prl, int s)
267 267
 	while(p)
268 268
 	{
269 269
 		if(p->cbf)
270
-			(*(p->cbf))(&(p->userid),(s==XJ_PRES_STATE_CHECK)?p->state:s,
270
+			(*(p->cbf))(&(p->userid),(s==XJ_PS_CHECK)?p->state:s,
271 271
 					p->cbp);
272 272
 		p = p->next;
273 273
 	}
... ...
@@ -32,10 +32,11 @@
32 32
 #include "../../str.h"
33 33
 #include "xjab_base.h"
34 34
 
35
-#define XJ_PRES_STATE_CHECK		-1
36
-#define XJ_PRES_STATE_OFFLINE	0
37
-#define XJ_PRES_STATE_ONLINE	1
38
-#define XJ_PRES_STATE_REFUSED	2
35
+#define XJ_PS_CHECK			-1
36
+#define XJ_PS_OFFLINE		0
37
+#define XJ_PS_ONLINE		1
38
+#define XJ_PS_TERMINATED	2
39
+#define XJ_PS_REFUSED		3
39 40
 
40 41
 #define XJ_PRES_STATUS_NULL		0
41 42
 #define XJ_PRES_STATUS_SUBS		1
... ...
@@ -31,11 +31,14 @@
31 31
  *
32 32
  * History
33 33
  * -------
34
- * 2003-02-28  send NOTIFYs even the connection is closed by user, (dcm)
35 34
  * 2003-01-20  xj_worker_precess function cleaning - some part of it moved to
36
- *              xj_worker_check_jcons function, (dcm)
37
- * 2003-03-11  major locking changes - uses locking.h (andrei)
38
- *
35
+ *             xj_worker_check_jcons function, (dcm)
36
+ * 2003-02-28  send NOTIFYs even the connection is closed by user, (dcm)
37
+ * 2003-03-11  major locking changes - uses locking.h, (andrei)
38
+ * 2003-05-07  added new presence status - 'terminated' - when connection
39
+ *             with Jabber server is lost or closed, (dcm)
40
+ * 2003-05-09  added new presence status - 'refused' - when the presence
41
+ *             subscription request is refused by target, (dcm)
39 42
  */
40 43
 
41 44
 #include <string.h>
... ...
@@ -563,6 +566,15 @@ step_z:
563 563
 		
564 564
 		if(jsmsg->type == XJ_REG_WATCHER)
565 565
 		{ // register a presence watcher
566
+			if(!jsmsg->cbf)
567
+			{
568
+#ifdef XJ_EXTRA_DEBUG
569
+				DBG("XJAB:xj_worker:%d: NULL PA callback"
570
+					" function\n", _xj_pid);
571
+#endif
572
+				goto step_w;
573
+			}
574
+
566 575
 			if(!xj_jconf_check_addr(&jsmsg->to, jwl->aliases->dlm))
567 576
 			{ // is for a conference - ignore?!?!
568 577
 #ifdef XJ_EXTRA_DEBUG
... ...
@@ -570,7 +582,7 @@ step_z:
570 570
 					_xj_pid);
571 571
 #endif
572 572
 				// set as offline
573
-				(*(jsmsg->cbf))(&jsmsg->to, 0, jsmsg->p);
573
+				(*(jsmsg->cbf))(&jsmsg->to, XJ_PS_OFFLINE, jsmsg->p);
574 574
 				goto step_w;
575 575
 			}
576 576
 			
... ...
@@ -583,6 +595,10 @@ step_z:
583 583
 				prc = xj_pres_list_check(jbc->plist, &sto);
584 584
 				if(!prc)
585 585
 				{
586
+#ifdef XJ_EXTRA_DEBUG
587
+					DBG("XJAB:xj_worker:%d: NEW presence"
588
+						" cell for %.*s.\n", _xj_pid, sto.len, sto.s);
589
+#endif
586 590
 					prc = xj_pres_cell_new();
587 591
 					if(!prc)
588 592
 					{
... ...
@@ -592,6 +608,8 @@ step_z:
592 592
 					}
593 593
 					if(xj_pres_cell_init(prc, &sto, jsmsg->cbf, jsmsg->p)<0)
594 594
 					{
595
+						DBG("XJAB:xj_worker:%d: cannot init the presence"
596
+							" cell for %.*s.\n", _xj_pid, sto.len, sto.s);
595 597
 						xj_pres_cell_free(prc);
596 598
 						goto step_w;
597 599
 					}
... ...
@@ -606,9 +624,15 @@ step_z:
606 606
 						prc->status = XJ_PRES_STATUS_WAIT; 
607 607
 				}
608 608
 				else
609
+				{
609 610
 					xj_pres_cell_update(prc, jsmsg->cbf, jsmsg->p);
610
-				// send presence info to SIP subscriber
611
-				(*(prc->cbf))(&jsmsg->to, prc->state, prc->cbp);
611
+#ifdef XJ_EXTRA_DEBUG
612
+					DBG("XJAB:xj_worker:%d: calling CBF(%.*s,%d)\n", _xj_pid,
613
+						jsmsg->to.len, jsmsg->to.s, prc->state);
614
+#endif
615
+					// send presence info to SIP subscriber
616
+					(*(prc->cbf))(&jsmsg->to, prc->state, prc->cbp);
617
+				}
612 618
 			}
613 619
 			goto step_w;
614 620
 		}
... ...
@@ -848,7 +872,7 @@ step_xx:
848 848
  */
849 849
 int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
850 850
 {
851
-	int i, err=0;
851
+	int j, err=0;
852 852
 	char *p, *to, *from, *msg, *type, *emsg, *ecode, lbuf[4096], fbuf[128];
853 853
 	xj_jconf jcf = NULL;
854 854
 	str ts, tf;
... ...
@@ -860,17 +884,18 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
860 860
 		return -1;
861 861
 
862 862
 	sid = jbc->jkey->id;	
863
-	x = xode_from_strx(buf, len, &err, &i);
863
+	x = xode_from_strx(buf, len, &err, &j);
864 864
 #ifdef XJ_EXTRA_DEBUG
865
-	DBG("XJAB:xj_parse_jab: XODE ret:%d pos:%d\n", err, i);
865
+	DBG("XJAB:xj_parse_jab: XODE ret:%d pos:%d\n", err, j);
866 866
 #endif	
867 867
 	if(err && pos != NULL)
868
-		*pos= i;
868
+		*pos= j;
869 869
 	if(x == NULL)
870 870
 		return -1;
871
-	
872 871
 	lbuf[0] = 0;
873 872
 	ecode = NULL;
873
+
874
+/******************** XMPP 'MESSAGE' HANDLING **********************/
874 875
 	
875 876
 	if(!strncasecmp(xode_get_name(x), "message", 7))
876 877
 	{
... ...
@@ -985,9 +1010,10 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
985 985
 #endif
986 986
 		}
987 987
 		goto ready;
988
-	} // end MESSAGE
988
+	}
989
+/*------------------- END 'MESSAGE' HANDLING ----------------------*/
989 990
 	
990
-	/*** PRESENCE HANDLING ***/
991
+/******************** XMPP 'PRESENCE' HANDLING *********************/
991 992
 	if(!strncasecmp(xode_get_name(x), "presence", 8))
992 993
 	{
993 994
 #ifdef XJ_EXTRA_DEBUG
... ...
@@ -1005,58 +1031,7 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1005 1005
 			ts.len = p - from;
1006 1006
 		else
1007 1007
 			ts.len = strlen(from);
1008
-		if(type!=NULL && !strncasecmp(type, "error", 5))
1009
-		{
1010
-			if((jcf=xj_jcon_check_jconf(jbc, from))!=NULL)
1011
-			{
1012
-				tf.s = from;
1013
-				tf.len = strlen(from);
1014
-				if((y = xode_get_tag(x, "error")) == NULL)
1015
-					goto ready;
1016
-				if ((p = xode_get_attrib(y, "code")) != NULL
1017
-						&& atoi(p) == 409)
1018
-				{
1019
-					xj_send_sip_msgz(als->proxy, sid, &tf,
1020
-							XJ_DMSG_ERR_JCONFNICK, &jbc->jkey->flag);
1021
-					goto ready;
1022
-				}
1023
-				xj_send_sip_msgz(als->proxy,sid,&tf,XJ_DMSG_ERR_JCONFREFUSED,
1024
-						&jbc->jkey->flag);
1025
-			}
1026 1008
 
1027
-			goto ready;
1028
-		}
1029
-		if(type!=NULL && !strncasecmp(type, "subscribe", 9))
1030
-		{
1031
-			xj_jcon_send_presence(jbc, from, "subscribed", NULL, NULL);
1032
-			goto ready;
1033
-		}
1034
-		if(type!=NULL && !strncasecmp(type, "unavailable", 11))
1035
-		{
1036
-#ifdef XJ_EXTRA_DEBUG
1037
-			DBG("XJAB:xj_manage_jab: user <%s> is offline\n", from);
1038
-#endif
1039
-			prc = xj_pres_list_check(jbc->plist, &ts);
1040
-			if(prc)
1041
-			{
1042
-				prc->state = XJ_PRES_STATE_OFFLINE;
1043
-				// call callback function
1044
-				if(prc->cbf)
1045
-				{
1046
-					tf.s = fbuf;
1047
-					tf.len = 0;
1048
-					if(xj_address_translation(&ts,&tf,als,XJ_ADDRTR_B2A)==0)
1049
-					{
1050
-#ifdef XJ_EXTRA_DEBUG
1051
-						DBG("XJAB:xj_manage_jab: calling CBF(%.*s,0)\n",
1052
-							tf.len, tf.s);
1053
-#endif
1054
-						(*(prc->cbf))(&tf, prc->state, prc->cbp);
1055
-					}
1056
-				}
1057
-			}
1058
-			goto ready;
1059
-		}
1060 1009
 		if(type == NULL || !strncasecmp(type, "online", 6)
1061 1010
 			|| !strncasecmp(type, "available", 9))
1062 1011
 		{
... ...
@@ -1101,26 +1076,15 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1101 1101
 			else
1102 1102
 			{
1103 1103
 #ifdef XJ_EXTRA_DEBUG
1104
-				DBG("XJAB:xj_manage_jab: user <%s> is online\n", from);
1104
+				DBG("XJAB:xj_manage_jab: user <%.*s> is online\n",ts.len,ts.s);
1105 1105
 #endif
1106 1106
 				prc = xj_pres_list_check(jbc->plist, &ts);
1107 1107
 				if(prc)
1108 1108
 				{
1109
-					prc->state = XJ_PRES_STATE_ONLINE;
1110
-					// call callback function
1111
-					if(prc->cbf)
1109
+					if(prc->state != XJ_PS_ONLINE)
1112 1110
 					{
1113
-						tf.s = fbuf;
1114
-						tf.len = 0;
1115
-						if(xj_address_translation(&ts,&tf,als,XJ_ADDRTR_B2A)
1116
-							==0)
1117
-						{
1118
-#ifdef XJ_EXTRA_DEBUG
1119
-							DBG("XJAB:xj_manage_jab: calling CBF(%.*s,1)\n",
1120
-								tf.len, tf.s);
1121
-#endif
1122
-							(*(prc->cbf))(&tf, prc->state, prc->cbp);
1123
-						}
1111
+						prc->state = XJ_PS_ONLINE;
1112
+						goto call_pa_cbf;
1124 1113
 					}
1125 1114
 				}
1126 1115
 				else
... ...
@@ -1145,15 +1109,81 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1145 1145
 					}
1146 1146
 					prc = xj_pres_list_add(jbc->plist, prc);
1147 1147
 					if(prc)
1148
-						prc->state = XJ_PRES_STATE_ONLINE;
1148
+					{
1149
+						prc->state = XJ_PS_ONLINE;
1150
+						goto call_pa_cbf;
1151
+					}
1149 1152
 				}
1150 1153
 			}
1154
+			goto ready;
1155
+		}
1156
+		
1157
+		if(strchr(from, '@') == NULL)
1158
+			goto ready;
1159
+	
1160
+		
1161
+		if(!strncasecmp(type, "error", 5))
1162
+		{
1163
+			if((jcf=xj_jcon_check_jconf(jbc, from))!=NULL)
1164
+			{
1165
+				tf.s = from;
1166
+				tf.len = strlen(from);
1167
+				if((y = xode_get_tag(x, "error")) == NULL)
1168
+					goto ready;
1169
+				if ((p = xode_get_attrib(y, "code")) != NULL
1170
+						&& atoi(p) == 409)
1171
+				{
1172
+					xj_send_sip_msgz(als->proxy, sid, &tf,
1173
+							XJ_DMSG_ERR_JCONFNICK, &jbc->jkey->flag);
1174
+					goto ready;
1175
+				}
1176
+				xj_send_sip_msgz(als->proxy,sid,&tf,XJ_DMSG_ERR_JCONFREFUSED,
1177
+						&jbc->jkey->flag);
1178
+			}
1179
+			goto ready;
1180
+		}
1181
+		if(type!=NULL && !strncasecmp(type, "subscribe", 9))
1182
+		{
1183
+			xj_jcon_send_presence(jbc, from, "subscribed", NULL, NULL);
1184
+			goto ready;
1185
+		}
1186
+
1187
+		prc = xj_pres_list_check(jbc->plist, &ts);
1188
+		if(!prc)
1189
+			goto ready;
1151 1190
 
1191
+		if(!strncasecmp(type, "unavailable", 11))
1192
+		{
1193
+#ifdef XJ_EXTRA_DEBUG
1194
+			DBG("XJAB:xj_manage_jab: user <%s> is offline\n", from);
1195
+#endif
1196
+			if(prc->state != XJ_PS_OFFLINE)
1197
+			{
1198
+				prc->state = XJ_PS_OFFLINE;
1199
+				goto call_pa_cbf;
1200
+			}
1201
+			goto ready;
1152 1202
 		}
1153 1203
 		
1204
+		if(!strncasecmp(type, "unsubscribed", 12))
1205
+		{
1206
+#ifdef XJ_EXTRA_DEBUG
1207
+			DBG("XJAB:xj_manage_jab: user <%s> does not allow to see his"
1208
+				" presence status\n", from);
1209
+#endif
1210
+			if(prc->state != XJ_PS_REFUSED)
1211
+			{
1212
+				prc->state = XJ_PS_REFUSED;
1213
+				goto call_pa_cbf;
1214
+			}
1215
+		}
1216
+	
1217
+		// ignoring unknown types
1154 1218
 		goto ready;
1155
-	} // end PRESENCE
1219
+	}
1220
+/*------------------- END XMPP 'PRESENCE' HANDLING ----------------*/
1156 1221
 	
1222
+/******************** XMPP 'IQ' HANDLING ***************************/
1157 1223
 	if(!strncasecmp(xode_get_name(x), "iq", 2))
1158 1224
 	{
1159 1225
 #ifdef XJ_EXTRA_DEBUG
... ...
@@ -1201,51 +1231,6 @@ int xj_manage_jab(char *buf, int len, int *pos, xj_jalias als, xj_jcon jbc)
1201 1201
 						}
1202 1202
 						goto next_sibling;
1203 1203
 					}
1204
-					/*** else
1205
-					{ // user item
1206
-						ts.s = from;
1207
-						ts.len = strlen(from);
1208
-						DBG("XJAB:xj_manage_jab:%s is in roster\n", from);
1209
-						if(xj_pres_list_check(jbc->plist, &ts))
1210
-						{
1211
-							DBG("XJAB:xj_manage_jab:%s already in presence"
1212
-								" list\n", from);
1213
-							goto next_sibling;
1214
-						}
1215
-
1216
-						prc = xj_pres_cell_new();
1217
-						if(prc == NULL)
1218
-						{
1219
-							DBG("XJAB:xj_manage_jab: cannot create presence"
1220
-								" cell for %s\n", from);
1221
-							goto next_sibling;
1222
-						}
1223
-						if(xj_pres_cell_init(prc, &ts, NULL, NULL)<0)
1224
-						{
1225
-							DBG("XJAB:xj_manage_jab: cannot init presence"
1226
-								" cell for %s\n", from);
1227
-							xj_pres_cell_free(prc);
1228
-							goto next_sibling;
1229
-						}
1230
-						prc = xj_pres_list_add(jbc->plist, prc);
1231
-						if(prc)
1232
-						{
1233
-							p = xode_get_attrib(z, "subscription");
1234
-							if(p && !strncasecmp(p, "none", 4))
1235
-							{
1236
-								DBG("XJAB:xj_manage_jab: wait for permission"
1237
-									" from %s\n", from);
1238
-								prc->status = XJ_PRES_STATUS_WAIT; 
1239
-							}
1240
-							else
1241
-							{
1242
-								DBG("XJAB:xj_manage_jab: permission granted"
1243
-									" from %s\n", from);
1244
-								prc->status = XJ_PRES_STATUS_SUBS;
1245
-							}
1246
-						}
1247
-					} 
1248
-					***/
1249 1204
 				}
1250 1205
 next_sibling:
1251 1206
 				z = xode_get_nextsibling(z);
... ...
@@ -1253,8 +1238,24 @@ next_sibling:
1253 1253
 		}
1254 1254
 		
1255 1255
 		goto ready;
1256
-	} // end IQ
1256
+	}
1257
+/*------------------- END XMPP 'IQ' HANDLING ----------------------*/
1257 1258
 
1259
+call_pa_cbf:
1260
+	if(prc && prc->cbf)
1261
+	{
1262
+		// call the PA callback function
1263
+		tf.s = fbuf;
1264
+		tf.len = 0;
1265
+		if(xj_address_translation(&ts,&tf,als,XJ_ADDRTR_B2A)==0)
1266
+		{
1267
+#ifdef XJ_EXTRA_DEBUG
1268
+			DBG("XJAB:xj_manage_jab: calling CBF(%.*s,%d)\n",
1269
+				tf.len, tf.s, prc->state);
1270
+#endif
1271
+			(*(prc->cbf))(&tf, prc->state, prc->cbp);
1272
+		}
1273
+	}
1258 1274
 ready:
1259 1275
 	xode_free(x);
1260 1276
 	return err;
... ...
@@ -1299,30 +1300,7 @@ int xj_send_sip_msg(str *proxy, str *to, str *from, str *msg, int *cbp)
1299 1299
 		return -1;
1300 1300
 
1301 1301
 	// from correction
1302
-	/****
1303
-	beg = crt = 0;
1304
-	end = -1;
1305
-	while(crt < from->len && from->s[crt]!='@')
1306
-	{
1307
-		if(from->s[crt]==delim)
1308
-		{
1309
-			beg = end + 1;
1310
-			end = crt;
1311
-		}
1312
-		crt++;
1313
-	}
1314
-	***/
1315 1302
 	tfrom.len = 0;
1316
-	/***
1317
-	if(end > 0)
1318
-	{ // put display name
1319
-		buf[0] = '"';
1320
-		strncpy(buf+1,from->s+beg,end-beg);
1321
-		tfrom.len = end-beg+1;
1322
-		buf[tfrom.len++] = '"';
1323
-		buf[tfrom.len++] = ' ';
1324
-	}
1325
-	***/
1326 1303
 	strncpy(buf+tfrom.len, "<sip:", 5);
1327 1304
 	tfrom.len += 5;
1328 1305
 	strncpy(buf+tfrom.len, from->s, from->len);
... ...
@@ -1337,8 +1315,6 @@ int xj_send_sip_msg(str *proxy, str *to, str *from, str *msg, int *cbp)
1337 1337
 	
1338 1338
 	strncat(buf1,tfrom.s,tfrom.len);
1339 1339
 	str_hdr.len += tfrom.len;
1340
-	//strncat(buf1,"sip:193.175.135.68:5060",23);
1341
-	//str_hdr.len += 23;
1342 1340
 	
1343 1341
 	strcat(buf1, CRLF);
1344 1342
 	str_hdr.len += CRLF_LEN;
... ...
@@ -1494,11 +1470,11 @@ void xj_worker_check_jcons(xj_wlist jwl, xj_jcon_pool jcp, int ltime, fd_set *ps
1494 1494
 		if(jcp->ojc[i]->plist)
1495 1495
 		{
1496 1496
 #ifdef XJ_EXTRA_DEBUG
1497
-			DBG("XJAB:xj_worker:%d: sending offline status to SIP"
1497
+			DBG("XJAB:xj_worker:%d: sending 'terminated' status to SIP"
1498 1498
 					"subscriber\n", _xj_pid);
1499 1499
 #endif
1500 1500
 			xj_pres_list_notifyall(jcp->ojc[i]->plist,
1501
-					XJ_PRES_STATE_OFFLINE);
1501
+					XJ_PS_TERMINATED);
1502 1502
 		}
1503 1503
 		FD_CLR(jcp->ojc[i]->sock, pset);
1504 1504
 		xj_jcon_disconnect(jcp->ojc[i]);